Changeset 722 for trunk


Ignore:
Timestamp:
10/17/12 12:43:43 (12 years ago)
Author:
sdipsl
Message:
  • bugfix : pack not properly created when starting a simulation after february using a leap calendar (also called gregorian) and setting a pack frequency in year. Corrected. see #64
  • it's very likely that time series and seasonal averages will also experience troubles in that case (not yet tested).
  • an overcome is to specify frequencies in month waiting for a fix
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libIGCM/libIGCM_date/libIGCM_date.ksh

    r673 r722  
    8585  IGCM_debug_PushStack "IGCM_date_ConvertFormatToGregorian" $@ 
    8686 
    87   # from a yyyy-mm-dd date format return  
     87  # from a yyyy-mm-dd date format return 
    8888  # a yyymmdd date format 
    8989  # usage IGCM_date_ConvertFormat yyyy-mm-dd 
    9090 
    91   # if there is no argument on the command line,  
    92   # then assume that a y-m-d formated date is being  
     91  # if there is no argument on the command line, 
     92  # then assume that a y-m-d formated date is being 
    9393  # piped in 
    9494  typeset ymd 
     
    110110  IGCM_debug_PushStack "IGCM_date_ConvertFormatToHuman" $@ 
    111111 
    112   # from a yyyymmdd date format return  
     112  # from a yyyymmdd date format return 
    113113  # a yyyy-mm-dd date format 
    114114  # usage IGCM_date_ConvertFormat yyyymmdd 
    115115 
    116   # if there is no argument on the command line,  
    117   # then assume that a yyyymmdd formated date is being  
     116  # if there is no argument on the command line, 
     117  # then assume that a yyyymmdd formated date is being 
    118118  # piped in 
    119119  typeset dt 
     
    137137  IGCM_debug_PushStack "IGCM_date_GetYearMonth" $@ 
    138138 
    139   # from a yyyymmdd date format return  
     139  # from a yyyymmdd date format return 
    140140  # a yyyy year and mm month 
    141141  # usage IGCM_date_GetYearMonth yyyymmdd year_var month_var 
    142142 
    143   # if there is no argument on the command line,  
    144   # then assume that a yyyymmdd formated date is being  
     143  # if there is no argument on the command line, 
     144  # then assume that a yyyymmdd formated date is being 
    145145  # piped in 
    146146  typeset dt 
     
    166166  IGCM_debug_PushStack "IGCM_date_GetYearMonthDay" $@ 
    167167 
    168   # from a yyyymmdd date format return  
     168  # from a yyyymmdd date format return 
    169169  # a yyyy year, mm month and dd day 
    170170  # usage IGCM_date_GetYearMonthDay yyyymmdd year_var month_var day_var 
    171171 
    172   # if there is no argument on the command line,  
    173   # then assume that a yyyymmdd formated date is being  
     172  # if there is no argument on the command line, 
     173  # then assume that a yyyymmdd formated date is being 
    174174  # piped in 
    175175  typeset dt 
     
    196196#D-* Purpose: Return the number of days in a year 
    197197#D-* Usage: IGCM_date_DaysInYear yyyy 
    198 #D-         if there is no argument on the command line,  
     198#D-         if there is no argument on the command line, 
    199199#D-         then assume that a yyyy is being piped in 
    200200#D- 
     
    237237  typeset y a 
    238238 
    239   # if there is no argument on the command line,  
     239  # if there is no argument on the command line, 
    240240  # then assume that a yyyy is being piped in 
    241241  if [ $# = 0 ] 
     
    277277    return 
    278278  fi 
    279    
     279 
    280280  # if it is evenly divisible by 4 it must be a leap year 
    281281  a=$(( $y % 4 )) 
     
    304304#D-#================================================================== 
    305305#D-function IGCM_date_DaysInMonth 
    306 #D-* Purpose: Calculate the number of days in a month  
     306#D-* Purpose: Calculate the number of days in a month 
    307307#D-* Usage: IGCM_date_DaysInMonth yyyy mm 
    308308#D-         or IGCM_date_DaysInMonth yyyymmdd 
    309 #D-         if there are no command line arguments then  
     309#D-         if there are no command line arguments then 
    310310#D-         assume that a yyyymmdd is being piped in and read the value. 
    311311#D-         if there is only one argument assume it is a yyyymmdd on the command line 
     
    315315#    IGCM_debug_PushStack "IGCM_date_DaysInMonth" $@ 
    316316 
    317   # calculates the number of days in a month  
     317  # calculates the number of days in a month 
    318318  # usage IGCM_date_DaysInMonth yyyy mm 
    319319  # or IGCM_date_DaysInMonth yyyymmdd 
    320    
     320 
    321321  # What is the calendar : 
    322322  if ( [ "${config_UserChoices_CalendarType}" = "360d" ] || [ "${config_UserChoices_CalendarType}" = "360_day" ] ) ; then 
     
    340340  then 
    341341    read ymd 
    342   elif [ $# = 1 ]  
     342  elif [ $# = 1 ] 
    343343  then 
    344344    ymd=$1 
     
    353353  # 30 days hath september etc. 
    354354  case $m in 
    355   1|3|5|7|8|10|12)  
     355  1|3|5|7|8|10|12) 
    356356    if [ X$3 = X ] ; then 
    357357      echo 31 
     
    360360    fi 
    361361 
    362 #           IGCM_debug_PopStack "IGCM_date_DaysInMonth" 
     362#           IGCM_debug_PopStack "IGCM_date_DaysInMonth" 
    363363    return ;; 
    364   4|6|9|11)  
     364  4|6|9|11) 
    365365    if [ X$3 = X ] ; then 
    366366      echo 30 
     
    368368      eval $3=30 > /dev/null 2>&1 
    369369    fi 
    370      
    371 #           IGCM_debug_PopStack "IGCM_date_DaysInMonth" 
     370 
     371#           IGCM_debug_PopStack "IGCM_date_DaysInMonth" 
    372372    return ;; 
    373373  *) ;; 
     
    379379  IGCM_date_DaysInYear $y diy 
    380380  case $diy in 
    381   365)  
     381  365) 
    382382    if [ X$3 = X ] ; then 
    383383      echo 28 
     
    388388#    IGCM_debug_PopStack "IGCM_date_DaysInMonth" 
    389389    return ;; 
    390   366)  
     390  366) 
    391391    if [ X$3 = X ] ; then 
    392392      echo 29 
     
    419419 
    420420  # if there is no command line argument, then assume that the date 
    421   # is coming in on a pipe and use read to collect it     
     421  # is coming in on a pipe and use read to collect it 
    422422  if [ $# = 0 ] 
    423423  then 
     
    456456#D-* Purpose: Convert yyyyddd to yyyymmdd 
    457457#D-* Usage: IGCM_date_ConvertJulianDateToGregorian 1998213 
    458 #D-         if there is no command line argument, assume one is being  
     458#D-         if there is no command line argument, assume one is being 
    459459#D-         piped in and read it 
    460460#D- 
     
    468468  typeset dt y m d grg 
    469469 
    470   # if there is no command line argument, assume one is being  
     470  # if there is no command line argument, assume one is being 
    471471  # piped in and read it 
    472472  if [ X$1 = X ] 
     
    476476    dt=$1 
    477477  fi 
    478    
     478 
    479479  # break apart the year and the days 
    480480  y=$(( $dt / 1000 )) 
    481481  d=$(( $dt % 1000 )) 
    482    
     482 
    483483  # subtract the number of days in each month starting from 1 
    484484  # from the days in the date. When the day goes below 1, you 
     
    543543  IGCM_date_DaysInYear $y diy 
    544544 
    545   # If the calculated day exceeds the days in the year,  
     545  # If the calculated day exceeds the days in the year, 
    546546  # add one year to the year and subtract the days in the year from the 
    547547  # calculated days. Extract the days in the new year and repeat 
     
    604604  tmp=$( IGCM_date_AddDaysToJulianDate $tmp $dif ) 
    605605  res=$( IGCM_date_ConvertJulianDateToGregorian $tmp ) 
    606    
     606 
    607607  echo $res 
    608608 
     
    612612#D-#================================================================== 
    613613#D-function IGCM_date_DaysBetweenJulianDate 
    614 #D-* Purpose: Calculate the days difference between two dates and reports  
    615 #D-           the number days as jul1 - jul2  
     614#D-* Purpose: Calculate the days difference between two dates and reports 
     615#D-           the number days as jul1 - jul2 
    616616#D-* Usage: IGCM_date_DaysBetweenJulianDate jul1 jul2 
    617617#D-         where julian date is in the form yyyyddd 
     
    621621  IGCM_debug_PushStack "IGCM_date_DaysBetweenJulianDate" $@ 
    622622 
    623   # calculates the days difference between two dates and reports  
    624   # the number days as jul1 - jul2  
     623  # calculates the days difference between two dates and reports 
     624  # the number days as jul1 - jul2 
    625625  # usage IGCM_date_DaysBetweenJulianDate jul1 jul2 
    626626  # where julian date is in the form yyyyddd 
    627    
     627 
    628628  usage () { 
    629629    echo "Usage:" 
     
    634634    echo " where a julian date is in the form of yyyyddd." 
    635635  } 
    636    
     636 
    637637  if [ $# -lt 2 ]; then 
    638638    usage 
    639639    IGCM_debug_Exit "IGCM_date_DaysBetweenJulianDate" 
    640640  fi 
    641    
     641 
    642642  # This process subtracts arg2 from arg1. If arg2 is larger 
    643643  # then reverse the arguments. The calculations are done, and 
     
    668668  # Then add days in year until year2 matches year1 
    669669  case ${config_UserChoices_CalendarType} in 
    670   360d|360_day)  
     670  360d|360_day) 
    671671    res=$(( ( ( $yyyy1 - $yyyy2 ) * 360 ) + $res )) ;; 
    672672  noleap|365_day) 
     
    685685 
    686686 
    687   # if argument 2 was larger than argument 1 then  
     687  # if argument 2 was larger than argument 1 then 
    688688  # the arguments were reversed before calculating 
    689689  # adjust by reversing the sign 
     
    701701#D-#================================================================== 
    702702#D-function IGCM_date_DaysBetweenGregorianDate () 
    703 #D-* Purpose: Calculate the days difference between two dates and reports  
    704 #D-           the number days as grg1 - grg2  
     703#D-* Purpose: Calculate the days difference between two dates and reports 
     704#D-           the number days as grg1 - grg2 
    705705#D-* Usage: IGCM_date_DaysBetweenGregorianDate grg1 grg2 
    706706#D-         where gregorian date is in the form yyyymmdd 
     
    710710  IGCM_debug_PushStack "IGCM_date_DaysBetweenGregorianDate" $@ 
    711711 
    712   # calculates the days difference between two dates and reports  
    713   # the number days as grg1 - grg2  
     712  # calculates the days difference between two dates and reports 
     713  # the number days as grg1 - grg2 
    714714  # usage IGCM_date_DaysBetweenGregorianDate grg1 grg2 
    715715  # where gregorian date is in the form yyyymmdd 
     
    775775    IGCM_debug_Exit "IGCM_date_DaysSinceJC" 
    776776  fi 
    777    
     777 
    778778  typeset aux num 
    779779 
    780780  if   [ ${1} -lt  5000000 ]; then 
    781781    case ${config_UserChoices_CalendarType} in 
    782     360d|360_day)  
     782    360d|360_day) 
    783783      aux=-360;; 
    784784    noleap|365_day) 
    785785      aux=-365;; 
    786     all_leap|366_day)  
     786    all_leap|366_day) 
    787787      aux=-366;; 
    788788    leap|gregorian|standard) 
     
    794794    # which is number of days since JC and 10000101 
    795795    case ${config_UserChoices_CalendarType} in 
    796     360d|360_day)  
     796    360d|360_day) 
    797797      aux=359640;; 
    798798    noleap|365_day) 
    799799      aux=364635;; 
    800     all_leap|366_day)  
     800    all_leap|366_day) 
    801801      aux=365634;; 
    802802    leap|gregorian|standard) 
     
    808808    # which is number of days since JC and 19000101 
    809809    case ${config_UserChoices_CalendarType} in 
    810     360d|360_day)  
     810    360d|360_day) 
    811811      aux=683640;; 
    812812    noleap|365_day) 
    813813      aux=693135;; 
    814     all_leap|366_day)  
     814    all_leap|366_day) 
    815815      aux=695034;; 
    816816    leap|gregorian|standard) 
     
    844844      (( year = year - PeriodLengthInYears + 1)) 
    845845    fi 
    846     (( Length=0 )) 
    847     (( i=0 )) 
     846    Length=0 
     847    i=0 
    848848    until [ $i -ge $PeriodLengthInYears ] ; do 
    849       (( Length = Length + $( IGCM_date_DaysInYear $(( year + i )) ) ))  
    850       (( i=i+1 )) 
     849      (( Length = Length + $( IGCM_date_DaysInYear $(( year + i )) ) )) 
     850      (( i = i + 1 )) 
    851851    done 
    852852    ;; 
     
    857857    if [ X${3} = Xend ] ; then 
    858858      (( month = month - PeriodLengthInMonths + 1 )) 
    859     fi       
    860     (( year0 = year )) 
     859    fi 
     860    year0=year 
    861861    if [ $month -le 0 ] ; then 
    862862      (( month = month + 12 )) 
     
    864864    fi 
    865865    month=$( printf "%02i\n" ${month} ) 
    866     (( Length=0 )) 
    867     (( i=0 )) 
     866    Length=0 
     867    i=0 
    868868    until [ $i -ge $PeriodLengthInMonths ] ; do 
    869869      if [ $(( month + i )) -lt 13 ] ; then 
    870         (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i )) ) )) 
     870        (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i )) ) )) 
    871871      else 
    872         (( year = year0 + 1 )) 
    873         (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i - 12 )) ) )) 
     872        (( year = year0 + 1 )) 
     873        (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i - 12 )) ) )) 
    874874      fi 
    875       (( i=i+1 )) 
     875      (( i = i + 1 )) 
    876876    done 
    877877    ;; 
     
    899899  Period=${2} 
    900900  case ${Period} in 
    901   *Y|*y)  
     901  *Y|*y) 
    902902    PeriodLengthInYears=$( echo ${Period} | awk -F '[yY]' '{print $1}' ) 
    903903    IGCM_date_GetYearMonth ${1} year month 
    904904    year=$( IGCM_date_SupressZeros ${year} ) 
    905     (( Length=0 )) 
    906     (( i=0 )) 
     905    Length=0 
     906    i=0 
    907907    until [ $i -ge $PeriodLengthInYears ] ; do 
    908       (( Length = Length + $( IGCM_date_DaysInYear $(( year + i + 1 )) ) ))  
    909       (( i=i+1 )) 
     908      (( Length = Length + $( IGCM_date_DaysInYear $(( year + i + 1 )) ) )) 
     909      (( i = i + 1 )) 
    910910    done 
    911911    ;; 
    912   *M|*m)  
     912  *M|*m) 
    913913    PeriodLengthInMonths=$( echo ${Period} | awk -F '[mM]' '{print $1}' ) 
    914914    IGCM_date_GetYearMonth ${1} year month 
    915915    year=$( IGCM_date_SupressZeros ${year} ) 
    916     (( year0 = year )) 
     916    year0=year 
    917917    if [ $(( month + 1 )) -lt 13 ] ; then 
    918918      month0=$(( month + 1 )) 
     
    921921      (( year = year0 + 1 )) 
    922922    fi 
    923     (( Length=0 )) 
    924     (( i=0 )) 
     923    Length=0 
     924    i=0 
    925925    until [ $i -ge $PeriodLengthInMonths ] ; do 
    926926      if [ $(( month0 + i )) -lt 13 ] ; then 
    927         (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month0 + i )) ) )) 
     927        (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month0 + i )) ) )) 
    928928      else 
    929         (( year = year0 + 1 )) 
    930         (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month0 + i - 12 )) ) )) 
     929        (( year = year0 + 1 )) 
     930        (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month0 + i - 12 )) ) )) 
    931931      fi 
    932       (( i=i+1 )) 
     932      (( i = i + 1 )) 
    933933    done 
    934934    ;; 
     
    946946#D-#================================================================== 
    947947#D-function IGCM_date_DaysInCurrentPeriod () 
    948 #D-* Purpose: Give the numbers of days during the Current prd1 period from grg1 date  
     948#D-* Purpose: Give the numbers of days during the Current prd1 period from grg1 date 
    949949#D-* Usage: IGCM_date_DaysInCurrentPeriod grg1 prd1 
    950950#D-         where grg1 gregorian date is in the form yyyymmdd 
     
    953953function IGCM_date_DaysInCurrentPeriod { 
    954954  IGCM_debug_PushStack "IGCM_date_DaysInCurrentPeriod" $@ 
    955   typeset Length Period 
     955  typeset Length Period  
    956956  Period=${2} 
    957957  case ${Period} in 
    958   *Y|*y)  
     958  *Y|*y) 
    959959    PeriodLengthInYears=$( echo ${Period} | awk -F '[yY]' '{print $1}' ) 
    960960    IGCM_date_GetYearMonth ${1} year month 
    961961    year=$( IGCM_date_SupressZeros ${year} ) 
    962     (( Length=0 )) 
    963     (( i=0 )) 
     962    month=$( IGCM_date_SupressZeros ${month} ) 
     963    Length=0 
     964    # if starting after february and using leap calendar 
     965    # we need to add the number of days of the next year (potentially a leap year) 
     966    if [ ${month} -gt 2 ] ; then 
     967      (( year = year + 1 )) 
     968    fi 
     969    i=0 
    964970    until [ $i -ge $PeriodLengthInYears ] ; do 
    965       (( Length = Length + $( IGCM_date_DaysInYear $(( year + i )) ) ))  
    966       (( i=i+1 )) 
     971      (( Length = Length + $( IGCM_date_DaysInYear $(( year + i )) ) )) 
     972      (( i = i + 1 )) 
    967973    done 
    968974    ;; 
    969   *M|*m)  
     975  *M|*m) 
    970976    PeriodLengthInMonths=$( echo ${Period} | awk -F '[mM]' '{print $1}' ) 
    971977    IGCM_date_GetYearMonth ${1} year month 
    972978    year=$( IGCM_date_SupressZeros ${year} ) 
    973     (( year0 = year )) 
    974     (( Length=0 )) 
    975     (( i=0 )) 
     979    year0=year 
     980    Length=0 
     981    i=0 
    976982    until [ $i -ge $PeriodLengthInMonths ] ; do 
    977983      if [ $(( month + i )) -lt 13 ] ; then 
    978         (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i )) ) )) 
     984        (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i )) ) )) 
    979985      else 
    980         (( year = year0 + 1 )) 
    981         (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i - 12 )) ) )) 
     986        (( year = year0 + 1 )) 
     987        (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i - 12 )) ) )) 
    982988      fi 
    983       (( i=i+1 )) 
     989      (( i = i + 1 )) 
    984990    done 
    985991    ;; 
     
    10191025#--------------------- 
    10201026  ${libIGCM}/libIGCM_date/IGCM_date_Test.ksh > IGCM_date_Test.ref.failed 2>&1 
    1021    
    1022   if diff IGCM_date_Test.ref.failed ${libIGCM}/libIGCM_date/IGCM_date_Test${dY}.ref > /dev/null 2>&1 ; then  
     1027 
     1028  if diff IGCM_date_Test.ref.failed ${libIGCM}/libIGCM_date/IGCM_date_Test${dY}.ref > /dev/null 2>&1 ; then 
    10231029    echo "Check libIGCM_date ...............................................[ OK ]" 
    10241030    rm -f IGCM_date_Test.ref.failed 
    1025   else  
     1031  else 
    10261032    echo "Check libIGCM_date ...........................................[ FAILED ]" 
    10271033    echo "--Error--> Execution of ${libIGCM}/libIGCM_date/IGCM_date_Test.ksh" 
Note: See TracChangeset for help on using the changeset viewer.