; docformat = 'rst' ; ; NAME: ; epRead ; PURPOSE: ; Read and interpret an input epoch into JD or ISO format. ;+ ; :Description: ; Read and interpret an input epoch into JD or ISO format. ; ; :Categories: ; Time ; ; :Params: ; ep: in, required, type=double/string ; The starting epoch of the ephemeris. Can be JD, ISO, packed ; (MPC) with arithmetic (+/- time in d,h,m, or s) ; ; :Returns: The epoch in JD or ISO, as per requested. ; ; :Keywords: ; ISO: in, optional, type=boolean, default=0 ; Epoch is returned as ISO date. ; JD: in, optional, type=boolean, default=1 ; Epoch is returned as decimal Julian day. ; Julian: in, optional, type=boolean, default=1 ; A synonym to JD ; ; :Uses: ; date_conv ; ; :Examples: ; Various usages of epRead:: ; IDL> print, epRead('J9611') ; IDL> print, epRead('now') ; IDL> print, epRead('now',/iso) ; IDL> print, epRead('2014-09-01+10d',/iso) ; IDL> print, epRead('2014-09-01+3.5h',/iso) ; IDL> print, epRead('J9611-10h',/JD) ; IDL> print, epRead('J9611+1m',/iso) ; ; :Author: ; B.Carry (OCA) ; ; :History: ; Change History:: ; Original Version written in June 2014, B. Carry (IMCCE) ; 2014 Sep. - B. Carry (IMCCE) - Interpretation of Packed date added ; 2015 Oct. - B. Carry (OCA) - Added compile option idl2 ; 2015 Nov. - B. Carry (OCA) - Corrected a bug linked with idl2 option ; 2018 Mar. - B. Carry (OCA) - Added Julian keyword ;- function epRead, ep, ISO=ISO, JD=JD, Julian=Julian COMPILE_OPT hidden, idl2 ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- I -- Initialization And Input Verification -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--I.1-- Input Verification ----------------------------------------------------- if not keyword_set(ep) then begin message, /IOERROR, ' Syntax - DATE = epRead(ep [,/ISO, /JD, /Julian])' return, -1 endif ;--I.2-- Output Format ---------------------------------------------------------- format=0 if keyword_set(ISO) then format=1 ;--I.3-- Packed to Number Conversion -------------------------------------------- hexa =['1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V'] ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- II -- Epoch Interpretation -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--II.1-- Epoch Format ----------------------------------------------------------- epDim = size(ep) ;--II.2-- Epoch is a Double ------------------------------------------------------ if epDim[epDim[0]+1] ne 7 then begin if format eq 0 then epX = date_conv(ep,'JULIAN') $ else epX = date_conv(ep,'FITS') ;--II.3-- Epoch is a String ------------------------------------------------------ endif else begin ;--II.3.1-- Input EP is Arithmetic? ------------------------------------------------ splitP = strsplit(ep,'+', /extract, count=nbMore) splitM = strsplit(ep,'-', /extract, count=nbLess) arithm=0 if nbMore gt 1 or (nbLess mod 2) eq 0 then arithm=1 ;--II.3.2-- Input EP is an Epoch --------------------------------------------------- if arithm eq 0 then begin ;--II.3.2/A-- Input EP is Now -------------------------------------------------------- if strcmp(ep,'now',/fold) then begin ep = systime(/UTC,/JULIAN) if format eq 0 then epX = date_conv(ep,'JULIAN') $ else epX = date_conv(ep,'FITS') ;--II.3.2/B-- Input EP is an Epoch (ISO, JD, or Packed) ------------------------------ endif else begin ;--II.3.2/B.1-- Ep is a Year if strlen(ep) eq 4 then ep+='-01-01' ;--II.3.2/B.2-- Ep is a JD if valid_num(ep) then ep=double(ep) $ ;--II.3.2/B.3-- Ep is Packed else if strlen(ep) eq 5 then begin case strmid(ep,0,1) of 'K': yy='20'+strmid(ep,1,2) 'J': yy='19'+strmid(ep,1,2) 'I': yy='18'+strmid(ep,1,2) endcase mm=string(where( strcmp(strmid(ep,3,1),hexa))+1,format='(I02)') dd=string(where( strcmp(strmid(ep,4,1),hexa))+1,format='(I02)') ep = yy+'-'+mm+'-'+dd+'T00:00:00.00' endif ;--II.3.2/B.4-- Convert to ISO or JD if format eq 0 then epX = date_conv(ep,'JULIAN') $ else epX = date_conv(ep,'FITS') endelse ;--II.3.3-- Input EP is Arithmetic ------------------------------------------------- endif else begin ;--II.3.3/A-- Input EP is Now -------------------------------------------------------- if strcmp(ep,'now',/fold,3) then begin ;--II.3.3/A.1-- Find Time Addition sign = float(strmid(ep,3,1)+'1') len = strlen(ep) unit = strmid(ep,len-1,1) val = strmid(ep,4,len-5) ;--II.3.3/A.2-- Convertion to JD ep = systime(/UTC,/JULIAN) case unit of 'd': add = sign * val 'h': add = sign * val/24. 'm': add = sign * val/24./60 's': add = sign * val/24./3600 endcase ;--II.3.3/A.3-- Convertion for Output if format eq 0 then epX = date_conv(ep+add,'JULIAN') $ else epX = date_conv(ep+add,'FITS') ;--II.3.3/B-- Input EP is an Epoch (ISO, JD, or Packed) ------------------------------ endif else begin ;--II.3.3/B.1-- Find Time Addition split = strsplit(ep,'+-', count=N) len = strlen(ep) unit = strmid(ep,len-1,1) val = strmid(ep,split[N-1], len-split[N-1]-1) sign = float(strmid(ep,split[N-1]-1,1)+'1') ;--II.3.3/B.2-- Convertion to JD case unit of 'd': add = sign * val 'h': add = sign * val/24. 'm': add = sign * val/24./60 's': add = sign * val/24./3600 endcase ;--II.3.3/B.3-- Convertion for Output epIn = strmid(ep,0,split[N-1]-1) if valid_num(epIn) then ep = double(epIn) $ else begin if strlen(epIn) le 10 then begin ;-Packed if strlen(epIn) eq 5 then begin case strmid(ep,0,1) of 'K': yy='20'+strmid(epIn,1,2) 'J': yy='19'+strmid(epIn,1,2) 'I': yy='18'+strmid(epIn,1,2) endcase mm=string(where( strcmp(strmid(epIn,3,1),hexa))+1,format='(I02)') dd=string(where( strcmp(strmid(epIn,4,1),hexa))+1,format='(I02)') epIn = yy+'-'+mm+'-'+dd+'T00:00:00.00' ;-Rounded to Day endif else epIN+='T00:00:00' endif ep = date_conv(epIn,'JULIAN') endelse if format eq 0 then epX = date_conv(ep+add,'JULIAN') $ else epX = date_conv(ep+add,'FITS') endelse endelse endelse ;--II.4-- Return the Epoch ------------------------------------------------------- return, epX end