; docformat = 'rst' ; ; NAME: ; mp3cReadBib ; PURPOSE: ; Read bibliography data in ini-style format and store it in a structure ; ;+ ; :Description: ; Read bibliography data in ini-style format and store it in a structure ; ; :Categories: ; MP3C ; ; :Params: ; file: in, required, type=string ; Path to the file to parse ; ; :Returns: A structure containing the bibliographic data. Fields are:: ; code : Unique bibcode ; ack : Acknowledment text ; xml : VOTable header PARAM line [returned empty here] ; ; :Keywords: ; ; :Uses: ; ; :Author: ; B.Carry (OCA) ; ; :History: ; Change History:: ; Original Version written in November 2016, B. Carry (OCA) ;- function mp3cReadBib, file ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- I -- Variables Declaration and Definition -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; COMPILE_OPT hidden, idl2 ;--I.1-- Valid Input Parameter --------------------------------------------------------------- if not keyword_set(file) then begin message, /ioError, 'syntax: bib = mp3cReadBib( file )' return, -1 endif ;--I.2-- Check if Input File Exists ---------------------------------------------------------- if not file_test(file,/Read) then begin message, /ioError, 'Bib file cannot be read: '+strtrim(file,2) return, -1 endif ;--I.3-- Bibdata Structure ------------------------------------------------------------------ empty={code:'',ack:''} bib=replicate(empty,200) kBib=-1 ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- II -- Parse Input File and Store it Into Structure -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--II.1-- Open the File for Reading ---------------------------------------------------------- openR, idIn, file, /get_lun line = ' ' section = ' ' while ~EoF(idIn) do begin ;--II.2-- Read Current Line ---------------------------------------------------------------- readf, idIn, line ;--II.3-- Update Bib Index ----------------------------------------------------------------- if strMid(line,0,1) eq '[' then begin kBib++ ;--II.4-- Update Biblio Fields ------------------------------------------------------------- endif else begin ;--II.4.1-- Split Line upon Equal Sign split=strSplit(line, '=', /Extract, count=nbField ) key = strTrim(split[0],2) if nbField gt 1 then case key of 'bib': bib[kBib].code = strTrim(split[1],2) 'ack': bib[kBib].ack = strTrim(split[1],2) else: endcase endelse endwhile ;--End of II.1-- Loop over Filelines ;--II.5-- Close File and Return -------------------------------------------------------------- free_lun, idIn bib=bib[0:kBib] return, bib end