; docformat = 'rst' ; ; NAME: ; ssoddLoadConfig ; PURPOSE: ; Read a SSODD configuration file and return it as a structure ; ;+ ; :Description: ; Read a SSODD configuration file and return it as a structure ; ; :Categories: ; SSODD, 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 August 2014, B. Carry (IMCCE) ; 2016 Aug. - B. Carry (OCA) - Added compile option idl2 ;- function ssoddLoadConfig, file, config ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- I -- Initialization And Input Verification -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; COMPILE_OPT hidden, idl2 ;--I.1-- Presence of Arguments -------------------------------------------------- if N_params() LT 1 then begin message, /INFO, ' Syntax - CONFIG = ssoddLoadConfig( PATH_TO_FILE, [CONF])' return, -1 endif ;--I.2-- Input Configuration File ----------------------------------------------- if not file_test(file,/Read) then begin message, /info, ' Configuration file not found: '+strtrim(file,2) return, -1 endif ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- II -- Create Configuration Structure for Output -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--II.1-- DB Cuts and Graphics Variables ---------------------------------------- sso = {histo: 0, $ ;-Show histograms key: 0 } ;-Show symbols key db = {diam: ' ', $ ;-Cuts for diameter ranges dens: ' ', $ ;-Cuts on density precision key: 0, $ ;-Show symbols key met: 0 } ;-Show meteorite ranges ;--II.2-- Symbols for Mass and Diameter Estimates ------------------------------- empty={id: 'ID' , $ ;-Method Identifyer (5 character string) name: 'Name' , $ ;-Method Full Name color: 'black' , $ ;-Line & Symbol Color (Coyote Graphics) symbol: 'circle', $ ;-Symbol label (Coyote Graphics) size: 1. , $ ;-Symbol Size thick: 1. } ;-Line thickness graph = {mass: replicate(empty,50), $ ;-Method of Mass determination diam: replicate(empty,50), $ ;-Method of Diameter determination dens: replicate(empty,50) } ;-Method of Density determination kMass = -1 kDiam = -1 kDens = -1 ;--II.3-- Symbols for Populations ----------------------------------------------- empty= {id: 'ID' , $ ;-Population identifyer name: 'Name' , $ ;-Population Full Name type: '' , $ ;-Type of SSO (aster|comet|satellite|planet) class: '*' , $ ;-Dynamical class (MB|NEA|Trojan|JFC|...) taxo: '*' , $ ;-Associated Taxonomies color: 'black' , $ ;-Line & Symbol Color (Coyote Graphics) symbol: 'circle', $ ;-Symbol label (Coyote Graphics) size: 1. , $ ;-Symbol Size thick: 1. } ;-Line thickness pop=replicate(empty,50) kPop = -1 ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- III -- Read Input Configuration File -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--III.1-- Open File and Loop over Lines ---------------------------------------- openr, inputFile, file, /GET_LUN line = ' ' section = ' ' while ~EOF(inputFile) do begin ;--III.2-- Read Current Line ---------------------------------------------------- readf, inputFile, line ;--III.3-- Selection of Section ------------------------------------------------- if strmid(line,0,1) 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-- SSO Populations: Definition and Symbols 'sso populations': BEGIN ;--II.4.2.1-- New Symbol Definition if nbField eq 1 then begin sub = strsplit( line, '{}', /extract ) kPop++ pop[kPop].name=sub[1] ;--II.4.2.2-- Parsing the Symbol Definition endif else begin CASE key OF 'id' : pop[kPop].id = strtrim(split[1],2) 'type' : pop[kPop].type = strtrim(split[1],2) 'class' : pop[kPop].class = strtrim(split[1],2) 'taxo' : pop[kPop].taxo = strtrim(split[1],2) 'color' : pop[kPop].color = strtrim(split[1],2) 'symbol': pop[kPop].symbol= strtrim(split[1],2) 'size' : pop[kPop].size = float(split[1]) 'thick' : pop[kPop].thick = float(split[1]) ELSE: ENDCASE endelse END ;--III.4.2-- Mass Determination Symbols 'methods of mass determination': BEGIN ;--II.4.2.1-- New Symbol Definition if nbField eq 1 then begin sub = strsplit( line, '{}', /extract ) kMass++ graph.mass[kMass].name=sub[1] ;--II.4.2.2-- Parsing the Symbol Definition endif else begin CASE key OF 'id' : graph.mass[kMass].id = strtrim(split[1],2) 'color' : graph.mass[kMass].color = strtrim(split[1],2) 'symbol': graph.mass[kMass].symbol= strtrim(split[1],2) 'size' : graph.mass[kMass].size = float(split[1]) 'thick' : graph.mass[kMass].thick = float(split[1]) ELSE: ENDCASE endelse END ;--III.4.3-- Diameter Determination Symbols 'methods of diameter determination': BEGIN ;--II.4.3.1-- New Symbol Definition if nbField eq 1 then begin sub = strsplit( line, '{}', /extract ) kDiam++ graph.diam[kDiam].name=sub[1] ;--II.4.3.2-- Parsing the Symbol Definition endif else begin CASE key OF 'id' : graph.diam[kDiam].id = strtrim(split[1],2) 'color': graph.diam[kDiam].color = strtrim(split[1],2) 'symbol': graph.diam[kDiam].symbol= strtrim(split[1],2) 'size': graph.diam[kDiam].size = float(split[1]) 'thick': graph.diam[kDiam].thick = float(split[1]) ELSE: ENDCASE endelse END ;--III.4.4-- Cuts and Graphics 'cuts and graphics variables': BEGIN ;--II.4.4.1-- Definitions for Individual SSO or Whole DB if nbField eq 1 then begin sub = strsplit( line, '{}', /extract, count=nbSub ) if nbSub eq 2 then sub = sub[1] else sub = ' ' ;--II.4.4.2-- Parsing the Symbol Definition endif else begin case sub of 'SSO': CASE key OF 'histogram': if strcmp(strtrim(split[1],2),'y',/fold,1) then sso.histo = 1 'symbol key': if strcmp(strtrim(split[1],2),'y',/fold,1) then sso.key = 1 ELSE: ENDCASE 'DB': CASE key OF 'diameter sets': db.diam = strtrim(split[1],2) 'density sets': db.dens = strtrim(split[1],2) 'symbol key': if strcmp(strtrim(split[1],2),'y',/fold,1) then db.key = 1 'meteorites': if strcmp(strtrim(split[1],2),'y',/fold,1) then db.met = 1 ELSE: ENDCASE endcase endelse END ;--III.4.x-- ELSE ELSE: ENDCASE endelse endwhile ;--III.5-- Analyze Cuts Variables ----------------------------------------------- ;--III.5.1-- Diameter Bounding Boxes if ~strcmp(db.diam,' ') then begin split = strsplit(db.diam,',',/extract, count=nbDiam) diamCut = fltarr(nbDiam) for k=0, nbDiam-1 do diamCut[k]=float(split[k]) endif ;--III.5.2-- Density Precision Levels if ~strcmp(db.dens,' ') then begin split = strsplit(db.dens,',',/extract, count=nbDens) densCut = fltarr(nbDens) for kDens=0, nbDens-1 do begin if valid_num( split[kDens] ) then begin densCut[kDens]=float(split[kDens]) endif else begin pos = strpos(split[kDens],'%') densCut[kDens]=float( strmid(split[kDens], 0, pos) )/100. endelse endfor endif ;--III.6- Trim Structure to Appropriate Length --------------------------------- out = {setup: {sso:sso, $ ;-Setup for SSO plots db: {diam:diamCut, $ ;-Delimiters for diameter boxes dens:densCut, $ ;-Cuts on density key:db.key, $ ;-Show key on DB plots met:db.met}}, $ ;-Show meteorites on DB plots pop: pop[0:kPop], $ ;-List of Populations mass: graph.mass[0:kMass], $ ;-Methods of mass determination diam: graph.diam[0:kDiam] } ;-Methods of diameter determination graph=out ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- IV -- Concatenation with Pre-Existing Structure -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--IV.1-- Complete Input Configuration if Provided ----------------------------- ; if keyword_set(CONFIG) then begin ; config = updateStructure( config, local ) ; endif else config = local ;--IV.2-- Return Configuration Structure --------------------------------------- ; return, config return, graph end