Changeset 279 for trunk/SRC/Calendar


Ignore:
Timestamp:
09/07/07 15:40:51 (17 years ago)
Author:
smasson
Message:

bugfix when using double precision calendar

Location:
trunk/SRC/Calendar
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/SRC/Calendar/date2jul.pro

    r278 r279  
    77; Calendar 
    88; 
    9 ; @param date {in}{required} {type=string} 
    10 ; date in yyyymmdd format 
     9; @param date {in}{required} {type=long or double, sacalr or array} 
     10; longword integer with yyyymmdd format or double-precision 
     11; floating-point with yyyymmdd.xx where xx is the fraction of the day 
     12; (xx=0 at 0am and 5 at 12am)  
    1113; 
    1214; @keyword GRADS 
     
    1416; if 50 <= year <= 99 --> year = 1900 + year 
    1517; 
     18; @keyword MONTH 
     19; Set this keyword equal to a named variable that will receive a 
     20; longword integer or longword integer array representing the number of 
     21; the desired month (1 = January, ..., 12 = December).  
     22; 
     23; @keyword DAY 
     24; Set this keyword equal to a named variable that will receive a 
     25; longword integer or longword integer array representing the number of 
     26; the day of the month (1-31).   
     27; 
     28; @keyword YEAR 
     29; Set this keyword equal to a named variable that will receive a 
     30; longword integer or longword integer array representing the number of 
     31; the desired year (e.g., 1994).   
     32; 
     33; @keyword HOUR 
     34; Set this keyword equal to a named variable that will receive a 
     35; longword integer or longword integer array representing the number of 
     36; the hour of the day (0-23).   
     37;  
     38; @keyword MINUTE 
     39; Set this keyword equal to a named variable that will receive a 
     40; longword integer or longword integer array representing the number of 
     41; the minute of the hour (0-59).   
     42 
     43; @keyword SECOND 
     44; Set this keyword equal to a named variable that will receive a 
     45; double-precision floating-point value or a double-precision 
     46; floating-point array representing the number of the second of the 
     47; minute (0-59). 
     48; 
    1649; @returns 
    17 ; date in Julian day 
     50; Julian day with the same format (long or double) as the input parameter 
    1851; 
     52; @restrictions 
     53; Input param must be longword integer or double-precision floating-point 
     54;  
    1955; @examples 
    2056; 
     
    2359;       1 
    2460; IDL> print, date2jul(931205,/grads) EQ julday(12,5,1993) 
     61;       1 
     62; IDL> print, date2jul(19931205.5d) EQ julday(12,5,1993,12,0,0) 
     63;       1 
     64; IDL> print, date2jul(19931205.0d) EQ julday(12,5,1993,0,0,0) 
    2565;       1 
    2666; 
     
    3373;- 
    3474; 
    35 function date2jul, date, GRADS = grads 
     75function date2jul, date, GRADS = grads, MONTH = month, DAY = day, YEAR = year $ 
     76                   , HOUR = hour, MINUTE = minute, SECOND = second 
    3677; 
    3778  compile_opt idl2, strictarrsubs 
    3879; 
    39    year = long(date) / 10000 
    40    month = long(abs(date)/100) MOD 100 
    41    day = long(abs(date)) MOD 100 
     80  sztype = size(date, /type) 
     81  IF sztype NE 3 AND sztype NE 5 AND sztype LT 13 THEN BEGIN 
     82    dummy = report('Beware of input type, date must be long or double') 
     83    stop 
     84  ENDIF 
     85; 
     86  year = long(date) / 10000 
     87  month = long(abs(date)/100) MOD 100 
     88  day = long(abs(date)) MOD 100 
    4289;------------------------------------------------------------ 
    43    if keyword_set(grads) then year = year $ 
    44      + 1900 * (year GE 50 AND year LE 99) $ 
    45      + 2000 * (year GE  1 AND year LE 49) 
     90  if keyword_set(grads) then $ 
     91     year = year + 1900L * (year GE 50 AND year LE 99) $ 
     92                 + 2000L * (year GE  1 AND year LE 49) 
    4693;------------------------------------------------------------ 
    47   IF size(date, /type) LE 3 THEN return, julday(month, day, year) 
     94  IF sztype NE 5 THEN return, julday(month, day, year) 
    4895 
    4996  fraction = date - long(date) 
    5097  hour = floor(fraction * 24d) 
    51   fraction = TEMPORARY(fraction) - hour/24d 
     98  fraction = temporary(fraction) - hour/24d 
    5299  minute = floor(fraction*1440d) 
    53   second = (TEMPORARY(fraction) - minute/1440d) * 86400d 
     100  second = (temporary(fraction) - minute/1440d) * 86400d 
    54101 
    55102  return, julday(month, day, year, hour, minute, second) 
  • trunk/SRC/Calendar/jul2date.pro

    r231 r279  
    77; Calendar 
    88; 
    9 ; @param jday {in}{required} {type=double} 
     9; @param jday {in}{required} {type=long or double, sacalr or array} 
    1010; Julian day 
    1111; 
     12; @keyword MONTH 
     13; Set this keyword equal to a named variable that will receive a 
     14; longword integer or longword integer array representing the number of 
     15; the desired month (1 = January, ..., 12 = December).  
     16; 
     17; @keyword DAY 
     18; Set this keyword equal to a named variable that will receive a 
     19; longword integer or longword integer array representing the number of 
     20; the day of the month (1-31).   
     21; 
     22; @keyword YEAR 
     23; Set this keyword equal to a named variable that will receive a 
     24; longword integer or longword integer array representing the number of 
     25; the desired year (e.g., 1994).   
     26; 
     27; @keyword HOUR 
     28; Set this keyword equal to a named variable that will receive a 
     29; longword integer or longword integer array representing the number of 
     30; the hour of the day (0-23).   
     31;  
     32; @keyword MINUTE 
     33; Set this keyword equal to a named variable that will receive a 
     34; longword integer or longword integer array representing the number of 
     35; the minute of the hour (0-59).   
     36 
     37; @keyword SECOND 
     38; Set this keyword equal to a named variable that will receive a 
     39; double-precision floating-point value or a double-precision 
     40; floating-point array representing the number of the second of the 
     41; minute (0-59). 
     42; 
    1243; @returns 
    13 ; date in yyyymmdd format 
     44; the date: longword integer with yyyymmdd format or double-precision 
     45; floating-point with yyyymmdd.xx where xx is the fraction of the day 
     46; (xx=0 at 0am and 5 at 12am)  
    1447; 
     48; @restrictions 
     49; Input param must be longword integer or double-precision floating-point 
     50;  
    1551; @examples 
    1652; 
    1753; IDL> print, jul2date(julday(12,23,1999)) 
    18 ;        19991223 
     54;     19991223 
     55; IDL> print, jul2date(julday(12,23,1999,12,0,0)) 
     56;        19991224. 
     57; IDL> print, jul2date(julday(12,23,1999,12,0,0)), format='(f11.2)' 
     58; 19991223.50 
     59; IDL> print, jul2date(julday(12,23,1999,0,0,0)), format='(f11.2)' 
     60; 19991223.00 
    1961; 
    2062; @history 
     
    2769;- 
    2870; 
    29 function jul2date, jday 
     71function jul2date, jday, MONTH = month, DAY = day, YEAR = year $ 
     72                   , HOUR = hour, MINUTE = minute, SECOND = second 
    3073; 
    3174  compile_opt idl2, strictarrsubs 
    3275; 
    33   caldat, jday, month, day, year, hour, min, sec 
     76  sztype = size(jday, /type) 
     77  IF sztype NE 3 AND sztype NE 5 AND sztype LT 13 THEN BEGIN 
     78    dummy = report('Beware of input type, julian date must be long or double') 
     79    stop 
     80  ENDIF 
     81; 
     82  caldat, jday, month, day, year, hour, minute, second 
    3483; 
    3584  res = (10000L*year + 100L*month + day)*(year GE 0) $ 
    3685        +( 10000L*year - 100L*month - day)*(year LT 0) 
    3786; 
    38   IF total([hour NE 12, min NE 0, abs(sec) GE 1.e-4]) EQ 0 THEN return, long(res) $ 
    39   ELSE return, double(res) + (hour / 24.0d0) + (min/1440.0d0) + (sec / 86400.0d0) 
     87  IF sztype NE 5 THEN return, long(res) $ 
     88  ELSE return, double(res) + (hour / 24.0d0) + (minute/1440.0d0) + (second / 86400.0d0) 
    4089 
    4190end 
  • trunk/SRC/Calendar/julday.pro

    r268 r279  
    9797  zero = where(year EQ 0, cnt) 
    9898  IF cnt NE 0 THEN YEAR[zero] = 654321L 
     99   
     100  NP = n_params() 
     101; Process the input, if all are missing, use todays date. 
     102  IF (np EQ 0) THEN RETURN, SYSTIME(/JULIAN) 
     103  IF (np LT 3) THEN ras = report('Incorrect number of arguments.') 
    99104; 
    100105  CASE key_caltype OF 
     
    105110      GREG = 2299171L           ; incorrect Julian day for Oct. 25, 1582 
    106111 
    107 ; Process the input, if all are missing, use todays date. 
    108       NP = n_params() 
    109       IF (np EQ 0) THEN RETURN, SYSTIME(/JULIAN) 
    110       IF (np LT 3) THEN ras= report('Incorrect number of arguments.') 
    111112 
    112113; Find the dimensions of the Result: 
     
    248249      if n_elements(Second) eq 0 then Second = 0 
    249250 
    250       IF total([hour NE 12, minute NE 0, second NE 0]) EQ 0 THEN return, JUL ELSE $ 
     251      IF (np LE 3) THEN return, JUL ELSE $ 
    251252        return, JUL + (Hour / 24.0d0 - 0.5d) + (Minute/1440.0d0) + (Second / 86400.0d0) 
    252253 
     
    281282      if n_elements(Second) eq 0 then Second = 0 
    282283 
    283         IF total([hour NE 12, minute NE 0, second NE 0]) EQ 0 THEN return, JUL ELSE $ 
     284        IF (np LE 3) THEN return, JUL ELSE $ 
    284285        return, JUL + (Hour / 24.0d0 - 0.5d) + (Minute/1440.0d0) + (Second / 86400.0d0) 
    285286 
Note: See TracChangeset for help on using the changeset viewer.