; docformat = 'rst' ; ; NAME: ; plotVNIR_load ; PURPOSE: ; Read a configuration file for plotVNIR and return it as a structure ; ;+ ; :Description: ; Read a 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_load, 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_load( 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 ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- II -- Create Configuration Structure for Output -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--II.1-- General Graphic Parameters --------------------------------------------------------- graph = {N:{rows: 2, $ ;-Number of rows cols: 5}, $ ;-Number of columns size: {x: 17., $ ;-Figure X size (cm) y: 10 } } ;-Figure Y size (cm) ;--II.2-- Definition of Axes ----------------------------------------------------------------- axes = { range: {x:[0,0.], $ ;-Wavelength range y:[0,0.]}, $ ;-Reflectance range tick: {x:0.4, $ ;-X-Tick Interval y:0.4 }, $ ;-Y-Tick Interval minor: {x:4, $ ;-X-Tick Minor y:4 } } ;-Y-Tick Minor ;--II.3-- Definition of Legend Parameters ---------------------------------------------------- legend={ show:1, $ ;-Boolean Show or Not label: {x:0., y:0.}, $ ;-Graphic name position class: {x:0., y:0., $ ;-Classes label position shift: {x: 0., y:0.}, $ ;-Classes label offsets vec: {x:[0.,0.]} } , $ ;-Classes label lenght of line spec: {x:0., y:0., $ ;-Spectrum label position shift: {x: 0., y:0.}, $ ;-Spectrum label offsets vec: {x:[0.,0.]} } } ;-Spectrum label lenght of line ;--II.4-- Definition of Atmospheric Bands ---------------------------------------------------- atm = replicate( {label:'', show:0, min:0.,max:0.}, 24 ) kAtm=0 ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- 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-- General Graphic Parameters 'graphic': BEGIN CASE key OF 'x.size': graph.size.x = round(float(split[1])) 'y.size': graph.size.y = round(float(split[1])) 'n.rows': graph.N.rows = round(float(split[1])) 'n.cols': graph.N.cols = round(float(split[1])) ELSE: ENDCASE END ;--III.4.2-- Parameters for Plots Axes 'axes': BEGIN CASE key OF 'x.range': begin sub=strSplit( split[1],',',/Extract) axes.range.x = [float(sub[0]), float(sub[1])] end 'y.range': begin sub=strSplit( split[1],',',/Extract) axes.range.y = [float(sub[0]), float(sub[1])] end 'x.ticks': axes.tick.x = float(split[1]) 'y.ticks': axes.tick.y = float(split[1]) 'x.minor': axes.minor.x = round(float(split[1])) 'y.minor': axes.minor.y = round(float(split[1])) ELSE: ENDCASE END ;--III.4.3-- Legend 'legend': BEGIN CASE key OF 'show?': legend.show = round(float(split[1])) 'label.x': legend.label.x = float(split[1]) 'label.y': legend.label.y = float(split[1]) 'class.x': legend.class.x = float(split[1]) 'class.y': legend.class.y = float(split[1]) 'class.x.shift': legend.class.shift.x = float(split[1]) 'class.y.shift': legend.class.shift.y = float(split[1]) 'class.x.vec': begin sub=strSplit( split[1],',',/Extract, count=nbSub ) legend.class.vec.x = [float(sub[0]),float(sub[1])] end 'spec.x': legend.spec.x = float(split[1]) 'spec.y': legend.spec.y = float(split[1]) 'spec.x.shift': legend.spec.shift.x = float(split[1]) 'spec.y.shift': legend.spec.shift.y = float(split[1]) 'spec.x.vec': begin sub=strSplit( split[1],',',/Extract, count=nbSub ) legend.spec.vec.x = [float(sub[0]),float(sub[1])] end ELSE: ENDCASE END ;--III.4.4-- Atmospheric Absorption bands 'atmosphere': BEGIN CASE key OF 'band': begin sub=strSplit( split[1],',',/Extract, count=nbSub ) atm[kAtm].show = round(float(sub[0])) atm[kAtm].min = float(sub[1]) atm[kAtm].max = float(sub[2]) if nbSub ge 4 then atm[kAtm].label = strTrim(sub[3],2) kAtm++ end ELSE: ENDCASE END ;--III.4.x-- ELSE ELSE: ENDCASE endelse endwhile free_lun, inputFile ;--III.5- Trim Structure to Appropriate Length ----------------------------------------------- atm=atm[0:kAtm-1] return, {graph:graph,axes:axes,atm:atm,legend:legend} end