PRO jdstr,jd,date,time,old=old,mjd=mjd,no_t=no_t ;+ ; NAME: ; jdstr ; ; ; PURPOSE: ; Convert Julian Date into date and time strings appropriate ; for FITS files ; ; ; CATEGORY: ; Astronomy ; ; ; CALLING SEQUENCE: ; jdstr,jd,date,time,old=old,mjd=mjd,time=time,date=date ; ; ; INPUTS: ; jd: Julian Date to be converted ; ; ; OPTIONAL INPUTS: ; none ; ; ; KEYWORD PARAMETERS: ; old: use old format for date (yy/mm/dd) ; mjd: if set, jd is in MJD (default: jd is Julian date) ; no_t: if set, do NOT append a T before the time string (new ; style only) ; ; ; OUTPUTS: ; date : String in yy/mm/dd form ; time : string in hh:mm:ss form ; ; ; OPTIONAL OUTPUTS: ; none ; ; ; COMMON BLOCKS: ; none ; ; ; SIDE EFFECTS: ; none ; ; ; RESTRICTIONS: ; JD has to be valid and AD only ; ; ; PROCEDURE: ; trivial, needs astrolib's daycnv ; ; ; EXAMPLE: ; ; ; ; MODIFICATION HISTORY: ; $Log: jdstr.pro,v $ ; Revision 1.3 2006/04/06 17:42:53 wilms ; next change (first since 2003): added /no_t keyword ; ; Revision 1.2 2003/04/08 18:56:02 wilms ; First change since 1997! ; Added new FITS date format, which is now the default. ; ; ; Version 1.0, 1997/03/13 J. Wilms (wilms@astro.uni-tuebingen.de) ;- ;; convert to JD if required jdtmp=double(jd) IF (keyword_set(mjd)) THEN jdtmp=jdtmp+2400000.5D0 ;; ;; Find ymsh ;; daycnv,jdtmp,yr,mn,day,hh IF (yr LT 0) THEN BEGIN message,'FITS datestring is only defined for years AD',/info message,'Did you forget the mjd keyword?' ENDIF IF (yr GT 9999.) THEN BEGIN message,'FITS datestring is only defined for years before 9999AD' ENDIF ;; ;; get hms ;; hr=fix(hh) mm=(hh-hr)*60d0 mi=fix(mm) sec=(mm-mi)*60d0 ;; correct for potential roundoff when rounding se to ;; four significant digits ;; the potential consequences of this are pretty scary, ;; looking at the following code... se=long(sec*100d0+0.5d0)/100d0 IF (se GE 60d0) THEN BEGIN se=se-60d0 mi=mi+1 IF (mi EQ 60) THEN BEGIN mi=0 hr=hr+1 IF (hr EQ 24) THEN BEGIN hr=0 day=day+1 ;; check for the legality of the day moday=[31,28,31,30,31,30,31,31,30,31,30,31] ;; check leap year IF (yr MOD 4 EQ 0) THEN BEGIN IF (yr MOD 100 EQ 0) THEN BEGIN ;; ...centuries IF (yr MOD 400 EQ 0) THEN BEGIN moday[1]=29 ENDIF ENDIF ELSE BEGIN ;; ...normal years moday[1]=29 ENDELSE ENDIF IF (day GT moday[mn-1]) THEN BEGIN day=1 mn=mn+1 IF (mn EQ 13) THEN BEGIN mn=1 yr=yr+1 ENDIF ENDIF ENDIF ENDIF ENDIF ;; ;; Piece everything together: ;; String-Formatting for beginners :-) ;; time=string(format='(I2.2,":",I2.2,":")',hr,mi) time=time+strtrim(string(format='(F5.2)',se),2) IF (keyword_set(old)) THEN BEGIN ;; old format for very old FITS files IF (yr GT 2000) THEN yr=yr-2000. ELSE yr=yr-1900. date=string(format='(I2.2,"/",I2.2,"/",I2.2)',yr,mn,day) return ENDIF ;; new format date=string(format='(I4.4,"-",I2.2,"-",I2.2)',yr,mn,day) IF (NOT keyword_set(no_t)) THEN time='T'+time END