;---------------------------------------------------------------------------- ; $Id: ymdh_to_julday.pro,v 1.2 2002/09/09 21:47:35 johnny Exp $ ;+ ; NAME: ; YMDH_TO_JULDAY ; ; PURPOSE: ; Given Year/Month/Day/Hour long integer (expressed as 4-digit year ; yyyymmddhh) convert to Julian Day. Year must be between 1000 and ; 9999, inclusive. Hour is calculated using the conventions in CALDAT. ; ; Note: This function is not an exact inverse of JULDAY_TO_YMDH since ; JULDAY_TO_YMDH can output 2-digit years and has an option to round ; up minute 59 to the nearest hour. ; ; CATEGORY: ; Date and Time. ; ; CALLING SEQUENCE: ; Result = YMDH_TO_JULDAY(in_ymdh) ; ; INPUTS: ; in_ymdh: Year/Month/Day/Hour long integer. Scalar or array. ; Variable unchanged by routine. ; ; KEYWORD PARAMETERS: ; None. ; ; OUTPUTS: ; Result: Date as Julian Day. Double floating. Same dimensions ; as in_ymdh. Created by function. ; ; FILE DEVICE I/O: ; None. ; ; COMMON BLOCKS: ; None. ; ; EXAMPLE: ; Test on a simple data sequence: ; ymdh = [1998010123, 1999022302] ; Result = YMDH_TO_JULDAY(ymdh) ; PRINT, Result, Format='(2f20.8)' ; CALDAT, Result, mo, dy, yr, hr ; PRINT, mo, dy, yr, hr ; IDL prints: ; 2450815.45833333 2451232.58333333 ; 1 2 ; 1 23 ; 1998 1999 ; 23 2 ; ; MODIFICATION HISTORY: ; - 9 Sep 2002: Orig. ver. Johnny Lin, CIRES/University of Colorado. ; Email: air_jlin@yahoo.com. Passed moderately adequate tests. ; ; NOTES: ; - Written for IDL 5.5. ; - All keyword parameters are optional unless otherwise stated. ; - No procedures called with _Extra keyword invoked. ; - No user-written procedures called. ;- ; Copyright (c) 2002 Johnny Lin. For licensing, distribution conditions, ; and contact information, see http://www.johnny-lin.com/lib.html. ;---------------------------------------------------------------------------- FUNCTION YMDH_TO_JULDAY, in_ymdh $ , _EXTRA = extra ; -------------------- Error Check and Parameter Setting -------------------- COMPILE_OPT IDL2 ON_ERROR, 0 if (SIZE(in_ymdh, /Type) ne 3) then $ ;- error check MESSAGE, 'error--input must be long' ; ---------------- Split Year/Month/Day/Hour Into Components ---------------- yr = in_ymdh / 1000000 mo = (in_ymdh - (yr*1000000)) / 10000 dy = (in_ymdh - (yr*1000000) - (mo*10000)) / 100 hr = in_ymdh - (yr*1000000) - (mo*10000) - (dy*100) max_yr = MAX(yr, Min=min_yr) ;- error check year if ((max_yr gt 9999) or (min_yr lt 1000)) then $ ; to be in range MESSAGE, 'error--yr outside of range' ; ------------------------- Convert Into Julian Day ------------------------- jday = JULDAY(mo, dy, yr, hr, 0, 0) ; ----------------------------- Prepare Output ------------------------------ Result = TEMPORARY(jday) ;- return ymdh RETURN, Result END ;=== end of function === ; ========== end file ==========