; docformat = 'rst' ; ; NAME: ; voVizier_read ; PURPOSE: ; Read the output of CDS VizieR service ;+ ; :Description: ; Read the output of CDS VizieR service ; ; :Categories: ; Ephemeris, Catalog ; ; :Params: ; src: in, required, type=string ; The results of vizquery (either file or output) ; ; :Keywords: ; mime: in, optional, type=string, default='csv' ; Format of the catalog (csv) ; ; :Returns: A structure containing the catalog ; ; :Uses: ; ; :Author: ; B.Carry (OCA) ; ; :History: ; Change History:: ; Original Version written in May 2014, B. Carry (IMCCE) ; 2017 Mar. - B. Carry (OCA) - Added CSV format, idl2 ; 2017 May - B. Carry (OCA) - Gaia DR1 works ok ; 2018 June - B. Carry (OCA) - Gaia DR2 ;- function voVizieR_read, src, mime=mime, coord=coord COMPILE_OPT hidden, idl2 ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- I -- Initialization And Input Verification -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--I.1-- Input Syntax Verification ---------------------------------------------------- if not keyword_set(src) then begin message, /ioError, 'Syntax: stars = voVizieR_read( src )' return, -1 endif ;--I.2-- Input Source ------------------------------------------------------------ srcDim = size(src) ;--I.2.1-- Stars were Provided in Input if srcDim[0] ne 0 then begin starList = strTrim(src,2) nbLine = srcDim[1] ;--I.2.2-- Ephemeris are in the Input File endif else begin openr, unit, src, /GET_LUN starList=' ' line='' nbLine = -1L while ~EOF(unit) do begin readf, unit, line starList=[starList,strTrim(line,2)] nbLine++ endwhile starList=starList[1:nbLine+1] close, unit free_lun, unit endelse ;--I.3-- Options ----------------------------------------------------------------- if keyword_set(mime) then mime =strTrim(mime ,2) else mime = 'text' if keyword_set(coord) then coord=strMid(coord,0,1) else coord = 'd' case mime of ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- II -- Parse the Catalog: ASCII -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; 'text': begin ;--II.1-- Output Structure ------------------------------------------------------ ;--II.1.1-- Select A Priori Valid Lines firstLetter = strMid(starList,0,1) locStar = where( firstLetter ne '#' and $ firstLetter ne ' ' and $ firstLetter ne '_' and $ valid_num(firstLetter), nbStar ) ;--II.1.2-- Prepare Output Structure empty = {name:'', $ ;-Star Identifier ra: {sex:[0,0,0.], dec:0.}, $ ;-RA: Sexagesimal & Decimal dec:{sex:[0,0,0.], dec:0.}, $ ;-DEC: Sexagesimal & Decimal mag:0. } ;-Star Mag if nbStar eq 0 then return, 0 star=replicate( empty, nbStar ) validLine=intarr(nbStar) case strLowCase(coord) of ;--II.2-- Decimal Coordinates --------------------------------------------------- 'd': begin ;--II.2.1-- Analyze the Catalog for kStar=0, nbStar-1 do begin ;--II.2.1/A-- Split using Spaces split=strSplit(starList[locStar[kStar]], ' ', /Extract, count=nbField ) if nbField eq 4 then begin ;--II.2.1/B-- Coordinates "RA/DEC" for Equatorial star[kStar].ra.dec = float(split[0]) star[kStar].dec.dec = float(split[1]) star[kStar].ra.sex = sixty(star[kStar].ra.dec/15.) star[kStar].dec.sex = sixty(star[kStar].dec.dec) ;--II.2.1/C-- Magnitude & Identifier star[kStar].mag = float(split[2]) star[kStar].name = strTrim(split[3],2) endif else validLine[kStar]=-1 endfor ;--II.2.2-- Select Valid valid = where( validLine ne -1 ) if valid[0] ne -1 then star=star[valid] end ;--II.3-- Sexagesimal Coordinates ----------------------------------------------- 's': begin ;--II.3.1-- Analyze the Catalog for kStar=0, nbStar-1 do begin ;--II.3.1/A-- Split using Spaces split=strSplit(starList[locStar[kStar]], ' ', /EXTRACT, count=nbField ) if nbField eq 4 then begin ;--II.3.1/B-- Coordinates "RA/DEC" for Equatorial star[kStar].ra.sex = [round(float(split[0])), $ round(float(split[1])), $ float(split[2]) ] star[kStar].dec.sex = [round(float(split[3])), $ round(float(split[4])), $ float(split[5]) ] star[kStar].ra.dec = ten(star[kStar].ra.sex)*15. star[kStar].dec.dec = ten(star[kStar].dec.sex) ;--II.3.1/C-- Magnitude & Identifier star[kStar].mag = float(split[6]) star[kStar].name = strTrim(split[7],2) endif else validLine[kStar]=-1 endfor ;--II.3.2-- Select Valid valid = where( validLine ne -1 ) if valid[0] ne -1 then star=star[valid] end else: begin message, /ioError, 'Coordinates keyword only accepts "decimal" or "sexagesimal" values' return, -2 end end end ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- III -- Parse the Catalog: CSV -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; 'csv': begin ;--III.1-- Output Structure ------------------------------------------------------ ;--III.1.1-- Select A Priori Valid Lines firstLetter = strMid(starList,0,1) locStar = where( firstLetter ne '#' and $ firstLetter ne ' ' and $ firstLetter ne '_' and $ valid_num(firstLetter), nbStar ) ;--III.1.2-- Prepare Output Structure empty = {name:'', $ ;-Star Identifier ra: {sex:[0,0,0.], dec:0.}, $ ;-RA: Sexagesimal & Decimal dec:{sex:[0,0,0.], dec:0.}, $ ;-DEC: Sexagesimal & Decimal mag:0. } ;-Star Mag if nbStar eq 0 then return, 0 star=replicate( empty, nbStar ) validLine=intarr(nbStar) case strLowCase(coord) of ;--III.2-- Decimal Coordinates --------------------------------------------------- 'd': begin ;--III.2.1-- Analyze the Catalog for kStar=0, nbStar-1 do begin split=strSplit(starList[locStar[kStar]], ';', /Extract, count=nbField ) ;--III.2.1/A-- General Catalogs if nbField eq 4 and not strCmp( strTrim(split[2],2), '' ) then begin ;--III.2.1/A.1-- Coordinates "RA/DEC" for Equatorial star[kStar].ra.dec = float(split[0]) star[kStar].dec.dec = float(split[1]) star[kStar].ra.sex = sixty(star[kStar].ra.dec/15.) star[kStar].dec.sex = sixty(star[kStar].dec.dec) ;--III.2.1/A.2-- Magnitude & Identifier star[kStar].mag = float(split[2]) star[kStar].name = strTrim(split[3],2) ;--III.2.1/B-- Gaia DR1 Catalog endif else if nbField eq 14 then begin ;--III.2.1/B.1-- Coordinates "RA/DEC" for Equatorial star[kStar].ra.dec = float(split[0]) star[kStar].dec.dec = float(split[2]) star[kStar].ra.sex = sixty(star[kStar].ra.dec/15.) star[kStar].dec.sex = sixty(star[kStar].dec.dec) ;--III.2.1/B.2-- Magnitude & Identifier star[kStar].mag = float(split[12]) star[kStar].name = strTrim(split[4],2) endif else validLine[kStar]=-1 endfor ;--III.2.2-- Select Valid valid = where( validLine ne -1 ) if valid[0] ne -1 then star=star[valid] end ;--III.3-- Sexagesimal Coordinates ----------------------------------------------- 's': begin ;--III.3.1-- Analyze the Catalog for kStar=0, nbStar-1 do begin ;--III.3.1/A-- Split using Spaces split=strSplit(starList[locStar[kStar]], ';', /Extract, count=nbField ) if nbField eq 4 and not strCmp( strTrim(split[2],2), '' ) then begin ;--III.3.1/B-- Coordinates "RA/DEC" for Equatorial sub=strSplit(split[0],' ',/Extract) star[kStar].ra.sex = [round(float(sub[0])), $ round(float(sub[1])), $ float(sub[2]) ] sub=strSplit(split[1],' ',/Extract) star[kStar].dec.sex = [round(float(sub[3])), $ round(float(sub[4])), $ float(sub[5]) ] star[kStar].ra.dec = ten(star[kStar].ra.sex)*15. star[kStar].dec.dec = ten(star[kStar].dec.sex) ;--III.3.1/C-- Magnitude & Identifier star[kStar].mag = float(split[2]) star[kStar].name = strTrim(split[3],2) endif else validLine[kStar]=-1 endfor ;--III.3.2-- Select Valid valid = where( validLine ne -1 ) if valid[0] ne -1 then star=star[valid] end else: begin message, /ioError, 'Coordinates keyword only accepts "decimal" or "sexagesimal" values' return, -2 end end end ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- IV -- Parse the Catalog: VOTABLE -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; 'votable': begin print, 'voVizieR_read - TBD - Code VOTABLE' end endcase ;-- Return the Structure return, star end