; docformat = 'rst' ; ; NAME: ; plotVNIR_read ; PURPOSE: ; Read an individual configuration file for plotVNIR and return it as a structure ; ;+ ; :Description: ; Read an individual configuration file for plotVNIR and return it as a structure ; ; :Categories: ; Disk I/O ; ; :Params: ; file: in, required, type=string ; Path to the configuration file to load ; config: in, optional, type=structure ; A pre-existing structure to complete with configuration data ; ; :Returns: A structure containing the configuration information. If a ; structure was provided upon input, the result are merged ; ; :Uses: ; ; :Author: ; B. Carry (OCA) ; ; :History: ; Change History:: ; Original Version written in March 2017, B. Carry (OCA) ; 2014 xxx. - A.Bcdef (Lab) - What ;- function plotVNIR_read, file COMPILE_OPT hidden, idl2 ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- I -- Initialization And Input Verification -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--I.1-- Presence of Arguments --------------------------------------------------------------- if N_params() LT 1 then begin message, /Info, ' Syntax - CONFIG = plotVNIR_read( PATH_TO_FILE )' return, -1 endif ;--I.2-- Input Configuration File ------------------------------------------------------------ if not file_test(file,/Read) then begin message, /Info, ' Configuration file cannot be read: '+strtrim(file,2) return, -2 endif ;--I.3-- Misc. ------------------------------------------------------------------------------- NMAX=10 ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- II -- Create Configuration Structure for Output -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--II.1-- General Graphic Parameters --------------------------------------------------------- label= '' ;-Label for the Spectrum ;--II.2-- General Graphic Parameters --------------------------------------------------------- empty = {label:'', $ ;-Label for the Spectrum src:'', $ ;-Source data:'', $ ;-Path to data offset:{show:1, $ ;-Apply a vertical offset? val: 0.}, $ ;-Vertical (reflectance) offset to apply fmt:'ascii', $ ;-File format color:'Black', $ ;-Color for data symbol:'OpenCircle' } ;-Symbol for data spec=replicate(empty,NMAX) kSpec=-1 ;--II.3-- Spectral Classification ------------------------------------------------------------ class = replicate( {label:'', chi2:0.}, 24 ) kClass=0 slope=0. PCs=fltarr(40) ;--II.4-- SDSS Photometry -------------------------------------------------------------------- sdss = {YN: 0, $ ;-Use SDSS Boolean data: '' } ;-Path to data ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- III -- Read Input Configuration File -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--III.1-- Open File and Loop over Lines ----------------------------------------------------- openR, inputFile, file, /GET_LUN line = ' ' section = ' ' kLine=0L while ~EOF(inputFile) do begin ;--III.2-- Read Current Line --------------------------------------------------------------- readf, inputFile, line kLine++ ;--III.3-- Selection of Section ------------------------------------------------------------ if strTrim(strMid(line,0,1),2) eq '[' then begin split = strSplit(line, '[]', /EXTRACT ) section = strLowCase(split[0]) ;--III.4-- Analysis of Section ------------------------------------------------------------- endif else begin split=strSplit(line, '=;', /EXTRACT, count=nbField ) key = strLowCase(strTrim(split[0],2)) CASE section OF ;--III.4.1-- Plot information 'information': BEGIN CASE key OF 'label': label = strTrim(split[1],2) ELSE: ENDCASE END ;--III.4.2-- Target spectrum 'spectrum': BEGIN ;--III.4.2.1-- New model definition if nbField eq 1 then begin sub = strsplit( line, '{:}', /Extract ) if strCmp(strTrim(sub[1],2),'Source',/Fold) then begin kSpec++ spec[kSpec].src = strTrim(sub[2],2) endif ;--III.4.2.2-- Parsing the model definition endif else begin CASE key OF 'label' : spec[kSpec].label = strTrim(split[1],2) 'data' : spec[kSpec].data = strTrim(split[1],2) 'format': spec[kSpec].fmt = strTrim(split[1],2) 'color' : spec[kSpec].color = strTrim(split[1],2) 'symbol': spec[kSpec].symbol= strTrim(split[1],2) 'offset': begin sub=strSplit( split[1],',',/Extract, count=nbSub ) spec[kSpec].offset.val = float(sub[0]) if nbSub ge 2 then spec[kSpec].offset.show = strCmp('Y', strTrim(sub[1],2), /Fold) end ELSE: ENDCASE endelse END ;--III.4.3-- Classification 'classification': BEGIN CASE key OF 'class': begin sub=strSplit( split[1],',',/Extract, count=nbSub ) class[kClass].label = strTrim(sub[0],2) if nbSub ge 2 then class[kClass].chi2 = float(sub[1]) kClass++ end 'slope': slope = float(split[1]) 'pcs': begin sub=strSplit( split[1],',',/Extract, count=nbSub ) for kPC=0, nbSub-1 do PCs[kPC] = float(sub[kPC]) PCs=PCs[0:nbSub-1] end ELSE: ENDCASE END ;--III.4.4-- SDSS Photometry 'sdss': BEGIN CASE key OF 'use?': sdss.yn = round(float(split[1])) 'data': sdss.data = strTrim(split[1],2) ELSE: ENDCASE END ;--III.4.x-- ELSE ELSE: ENDCASE endelse endwhile free_lun, inputFile ;--III.5- Trim Structure to Appropriate Length ----------------------------------------------- if kClass eq 0 then class=0 else class = class[0:kClass-1] spec = spec[0:kSpec] return, {label:label, spec:spec, sdss:sdss, class:class, PCA:{slope:slope, pc:PCs}} end