Changeset 279 for trunk


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

bugfix when using double precision calendar

Location:
trunk/SRC
Files:
5 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 
  • trunk/SRC/ToBeReviewed/WIDGET/AUTOUR_de_XXX/buildreadcmd.pro

    r262 r279  
    111111    date2 = date2jul(date2) - fakecal 
    112112  ENDIF 
    113   sdate1 = strtrim(date1, 1) & sdate2 = strtrim(date2, 1) 
     113  IF size(date1, /type) EQ 5 THEN sdate1 = string(date1, format='(f15.6)')+'d' $ 
     114  ELSE sdate1 = string(date1, format='(i10)')+'L' 
     115  IF size(date2, /type) EQ 5 THEN sdate2 = string(date2, format='(f15.6)')+'d' $ 
     116  ELSE sdate2 = string(date2, format='(i10)')+'L' 
    114117;--------------- 
    115118; find boxzoom 
  • trunk/SRC/ToBeReviewed/WIDGET/COMPOUND_WIDGET/cw_calendar.pro

    r271 r279  
    6868; 
    6969@cm_4cal 
    70  
    7170; get back the calendar and its related informations 
    7271  winfo_id = widget_info(id, find_by_uname = 'infocal') 
    7372  widget_control, winfo_id, get_uvalue = infowid 
    7473  key_caltype = infowid.caltype 
    75  
    7674; high freqeuncy calendar 
    7775  IF keyword_set(infowid.fakecal) THEN BEGIN 
     
    8482    ENDIF 
    8583  ENDIF ELSE BEGIN 
    86 ; 
    87     value = long(value[0]) 
    88 ; make sure the value correspond 
    89     value = jul2date(date2jul(value)) 
    90 ; define year month day 
    91     year = value/10000l 
    92     month = (value MOD 10000L)/100L 
    93     day = value MOD 100L 
     84    jdval = date2jul(value) 
    9485; check that the date exists in the calendar 
    95   if (where(abs(infowid.calendar - julday(month, day, year)) LT 1./86400.))[0] EQ - 1 then return 
     86    if (where(abs(infowid.calendar - jdval) LT 1.d/86400.d))[0] EQ - 1 then return 
    9687; update the value of infocal 
    9788    infowid.date = value 
     
    181172  if wid_id NE 0 then BEGIN 
    182173    widget_control, wid_id, get_value = wid_value 
    183     date = long(wid_value.combobox_gettext) 
     174    widget_control, wid_id, get_uvalue = wid_uvalue 
     175    date = double(wid_value.combobox_gettext) + wid_uvalue.hms[wid_value.combobox_index] 
    184176  ENDIF ELSE date = oldate MOD 100L 
    185177;-------------month--------------- 
     
    224216; @uses 
    225217; 
    226 ; @restrictions 
     218; @restrictions< 
    227219; 
    228220; @examples 
     
    242234  winfo_id = widget_info(event.handler, find_by_uname = 'infocal') 
    243235  widget_control, winfo_id, get_uvalue = infowid 
    244   caldat, infowid.calendar, monthcal, daycal, yearcal 
     236  caldat, infowid.calendar, monthcal, daycal, yearcal, hourcal, mincal, seccal 
    245237; ... and the current date 
    246238  IF n_elements(date0) EQ 0 then date0 = get_cal_value(event.handler) 
    247   year0 = date0/10000L 
    248   month0 = (date0 MOD 10000L)/100L 
    249   day0 = date0 MOD 100L 
     239  jdate0 = date2jul(date0, month = month0, day = day0, year = year0) 
    250240; index of days/months/years according to date0 
    251241  case casename of 
     
    254244      index = where(monthcal EQ month0 AND yearcal EQ year0) 
    255245      current = daycal[index] 
     246      hms = hourcal[index] / 24.0d0 + mincal[index]/1440.0d0 + seccal[index] / 86400.0d0 
    256247    END 
    257248    'month':BEGIN 
     
    271262  ENDCASE 
    272263; we update the uvalue of the widget 
    273   widget_control, wid_id, set_uvalue = {name:casename} 
     264  IF casename EQ 'day' THEN widget_control, wid_id, set_uvalue = {name:casename, hms:hms} 
    274265; for event.out = 0, we store the previous position of the combobox to use 
    275266; it as the default position. 
     
    334325; $Id$ 
    335326;- 
    336 PRO move, event, casename 
     327PRO cw_cal_move, event, casename 
    337328; 
    338329  compile_opt strictarr, strictarrsubs 
     
    354345         widget_control, id, set_value = {combobox_select:selected} 
    355346; we call move for the next combobox 
    356       ENDIF ELSE move, event, possiblecase[whichcase+1] 
     347      ENDIF ELSE cw_cal_move, event, possiblecase[whichcase+1] 
    357348; it is possible to move from +/- 1 
    358349   ENDIF ELSE widget_control, id, set_value = {combobox_select:wvalue.combobox_index+event.out} 
     
    410401        selected = (widvalue.combobox_number-1)*(event.out EQ -1) 
    411402        widget_control, event.id, set_value = {combobox_select:selected} 
    412       ENDIF ELSE move, event, possiblecase[whichcase+1] 
     403      ENDIF ELSE cw_cal_move, event, possiblecase[whichcase+1] 
    413404    ENDIF 
    414405; if we changed month(year), we need to update the day (and month) list 
     
    484475  if keyword_set(caltype) then key_caltype = caltype 
    485476; months days years found in the calendar 
    486   caldat, calendar, monthcal, daycal, yearcal, hourcal, mincal, scdcal 
     477  caldat, calendar, monthcal, daycal, yearcal, hourcal, mincal, seccal 
     478  hmscal = hourcal / 24.0d0 + mincal/1440.0d0 + seccal / 86400.0d0 
    487479; starting date 
    488480  if n_elements(jdate0) EQ 0 then jdate0 = calendar[0] 
     
    523515      currentday = daycal[dayindex] 
    524516      currentday = strtrim(currentday, 1) 
    525       cmbbid = cw_combobox_pm(base, UVALUE = {name:'day'}, UNAME = 'day', value = currentday) 
     517      hms = hmscal[dayindex] 
     518      cmbbid = cw_combobox_pm(base, UVALUE = {name:'day', hms:hms}, UNAME = 'day', value = currentday) 
    526519      widget_control, cmbbid, set_value = {combobox_select:(where(long(currentday) EQ day0))[0]} 
    527520    endif 
Note: See TracChangeset for help on using the changeset viewer.