; docformat = 'rst' ; ; NAME: ; readALCDEF ; PURPOSE: ; Load a lightcurve file in ALCDEF format into a structure ; ;+ ; :Description: ; Load a lightcurve file in ALCDEF format into a structure ; ; :Categories: ; Lightcurve ; ; :Params: ; IN: in, required, type=string ; Path of the input lightcurve ; ; :Keywords: ; ; :Uses: ; ; :Author: ; B.Carry (IMCCE) ; ; :History: ; Change History:: ; Written in December 2014, B. Carry (IMCCE) ; 201x-xxx. - B. Carry (IMCCE) - ;- function readALCDEF, in ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- I -- Initialization And Input Verification -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; COMPILE_OPT hidden ;--I.1-- Input Syntax Verification ---------------------------------------------------- if not keyword_set(in) then begin message, /IOERROR, 'Syntax : LC = readALCDEF( IN )' return, -1 endif ;--I.2-- Check File Exist ------------------------------------------------------------- if not file_test(in) then begin message, /IOERROR, 'File '+strtrim(in,2)+' does not exist' return, -2 endif ;--I.3-- Output Structure ------------------------------------------------------------- emptyLC = { N:0, JD:ptr_new(), M:ptr_new(), dM:ptr_new() } emptyALL = { target: {num:0L, name:''}, $ obs: {name:'', mail:''}, $ tel: {iau:'', lat:0., long:0., filter:''}, $ LTC: {type:'', days:0., app:''} } LC = replicate( {head:emptyAll, data:emptyLC}, 100 ) ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- II -- Read File and Store Values in Structure -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--II.1-- Open File -------------------------------------------------------------------- line = ' ' kLC=-1 openr, unit, in, /get_lun while ~EOF(unit) do begin ;--II.2-- Read Each Line --------------------------------------------------------------- readf, unit, line ;--II.3-- Interprete First Characters -------------------------------------------------- code = strmid(line,0,4) ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- III -- Lightcurve Header Information -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; if ~strcmp(code,'DATA') then begin ;--III.1-- Lightcurve ID Increment ------------------------------------------------------ if strcmp(line,'STARTMETADATA') then begin ;--III.1.1-- Store LC in Structure -------------------------------------------------------- if kLC ge 0 then begin ;--III.1.2-- LC Summary nbPoint = n_elements(jdArr)-1 jdArr = jdArr(1:nbPoint) magArr = magArr(*,1:nbPoint) ;--III.1.3-- Update Pointer Values lc(kLC).data.JD = ptr_new(/ALLOCATE_HEAP) lc(kLC).data.M = ptr_new(/ALLOCATE_HEAP) lc(kLC).data.dM = ptr_new(/ALLOCATE_HEAP) ;--III.1.4-- Set Values lc(kLC).data.N = nbPoint *lc(kLC).data.JD = jdArr *lc(kLC).data.M = magArr(0,*) *lc(kLC).data.dM = magArr(1,*) endif ;--III.1.x-- Reset Variables for Next LC -------------------------------------------------- kLC++ jdArr = 0.d magArr = [0.,0.] ;--III.2-- Header Parsing --------------------------------------------------------------- endif else begin split=strsplit(line,'=',/extract) ;--III.2.1-- Target Information ----------------------------------------------------------- if strcmp(split(0),'OBJECTNUMBER') then LC(kLC).head.target.num = round(float(split(1))) if strcmp(split(0),'OBJECTNAME') then LC(kLC).head.target.name = strtrim(split(1),2) ;--III.2.2-- Observer Information --------------------------------------------------------- if strcmp(split(0),'OBSERVERS') then LC(kLC).head.obs.name = strtrim(split(1),2) if strcmp(split(0),'CONTACTINFO') then LC(kLC).head.obs.mail = strtrim(split(1),2) ;--III.2.3-- Telescope Information -------------------------------------------------------- if strcmp(split(0),'OBSLONGITUDE') then $ if size(split,/N_ELEMENTS) gt 1 then $ LC(kLC).head.tel.long = float(split(1)) if strcmp(split(0),'OBSLATITUDE') then $ if size(split,/N_ELEMENTS) gt 1 then $ LC(kLC).head.tel.lat = float(split(1)) if strcmp(split(0),'MAGBAND') then LC(kLC).head.tel.filter= strtrim(split(1),2) ;--III.2.4-- Light-Time Correction -------------------------------------------------------- if strcmp(split(0),'LTCTYPE') then LC(kLC).head.LTC.type = strtrim(split(1),2) if strcmp(split(0),'LTCDAYS') then LC(kLC).head.LTC.days = float(split(1)) if strcmp(split(0),'LTCAPP') then LC(kLC).head.LTC.app = strtrim(split(1),2) ;--III.2.5-- Miscellaneous ---------------------------------------------------------------- if strcmp(split(0),'DELIMITER') then begin if strcmp(split(1),'PIPE') then delim='|' $ else delim=' ' endif endelse ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- IV -- Lightcurve Data Parsing -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; endif else begin split = strsplit(line,'='+delim,/extract) jdArr = [jdArr, double(split(1)) ] magArr= [ [magArr], [float(split(2)),float(split(3))] ] endelse ;--II.3-- Close Loop and File ---------------------------------------------------------- endwhile close, unit free_lun, unit ;--II.4-- Store Last LC in Structure --------------------------------------------------- ;--II.4.1-- LC Summary nbPoint = n_elements(jdArr)-1 jdArr = jdArr(1:nbPoint) magArr = magArr(*,1:nbPoint) ;--II.4.2-- Update Pointer Values lc(kLC).data.JD = ptr_new(/ALLOCATE_HEAP) lc(kLC).data.M = ptr_new(/ALLOCATE_HEAP) lc(kLC).data.dM = ptr_new(/ALLOCATE_HEAP) ;--II.4.3-- Set Values lc(kLC).data.N = nbPoint *lc(kLC).data.JD = jdArr *lc(kLC).data.M = magArr(0,*) *lc(kLC).data.dM = magArr(1,*) ;--II.4-- Return LC Structure ---------------------------------------------------------- LC=LC(0:kLC) return, LC end