Ignore:
Timestamp:
03/07/12 10:39:55 (12 years ago)
Author:
mafoipsl
Message:

First try to merge libIGCM_MPI_OpenMP branch with libIGCM trunk revision 569. Tested on vargas with PackFrequency?=NONE included into config.card.

Location:
branches/libIGCM_MPI_OpenMP
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/libIGCM_MPI_OpenMP

  • branches/libIGCM_MPI_OpenMP/libIGCM_date/libIGCM_date.ksh

    r435 r571  
    4242function IGCM_date_YearDigit 
    4343{ 
    44     IGCM_debug_PushStack "IGCM_date_YearDigit" $@ 
    45  
    46     NUM=$(( 10#${1} )) 
    47     echo $( gawk "BEGIN { printf \"%0${dY}d\",${NUM} }" ) 
    48  
    49     IGCM_debug_PopStack "IGCM_date_YearDigit" 
     44  IGCM_debug_PushStack "IGCM_date_YearDigit" $@ 
     45 
     46  NUM=$(( 10#${1} )) 
     47  echo $( gawk "BEGIN { printf \"%0${dY}d\",${NUM} }" ) 
     48 
     49  IGCM_debug_PopStack "IGCM_date_YearDigit" 
    5050} 
    5151 
     
    5353function IGCM_date_GregorianDigit 
    5454{ 
    55     IGCM_debug_PushStack "IGCM_date_GregorianDigit" $@ 
    56  
    57     NUM=$(( 10#${1} )) 
    58     echo $( gawk "BEGIN { printf \"%0${pY}d\",${NUM} }" ) 
    59  
    60     IGCM_debug_PopStack "IGCM_date_GregorianDigit" 
     55  IGCM_debug_PushStack "IGCM_date_GregorianDigit" $@ 
     56 
     57  NUM=$(( 10#${1} )) 
     58  echo $( gawk "BEGIN { printf \"%0${pY}d\",${NUM} }" ) 
     59 
     60  IGCM_debug_PopStack "IGCM_date_GregorianDigit" 
    6161} 
    6262 
     
    6464function IGCM_date_HumanDigit 
    6565{ 
    66     IGCM_debug_PushStack "IGCM_date_HumanDigit" $@ 
    67  
    68     echo $( IGCM_date_GregorianDigit $( print ${1} | sed 's/-//g' ) ) \ 
    69         | sed -e "s/\([0-9]\{${dY}\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\1-\2-\3/" 
    70  
    71     IGCM_debug_PopStack "IGCM_date_HumanDigit" 
     66  IGCM_debug_PushStack "IGCM_date_HumanDigit" $@ 
     67 
     68  echo $( IGCM_date_GregorianDigit $( print ${1} | sed 's/-//g' ) ) \ 
     69    | sed -e "s/\([0-9]\{${dY}\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\1-\2-\3/" 
     70 
     71  IGCM_debug_PopStack "IGCM_date_HumanDigit" 
    7272} 
    7373 
     
    7575function IGCM_date_SupressZeros 
    7676{ 
    77     IGCM_debug_PushStack "IGCM_date_SupressZeros" $@ 
    78     echo $( print ${1} | sed -e "s/0*//" ) 
    79     IGCM_debug_PopStack "IGCM_date_SupressZeros" 
     77  IGCM_debug_PushStack "IGCM_date_SupressZeros" $@ 
     78  echo $( print ${1} | sed -e "s/0*//" ) 
     79  IGCM_debug_PopStack "IGCM_date_SupressZeros" 
    8080} 
    8181 
     
    8383function IGCM_date_ConvertFormatToGregorian 
    8484{ 
    85     IGCM_debug_PushStack "IGCM_date_ConvertFormatToGregorian" $@ 
    86  
    87     # from a yyyy-mm-dd date format return  
    88     # a yyymmdd date format 
    89     # usage IGCM_date_ConvertFormat yyyy-mm-dd 
    90  
    91     # if there is no argument on the command line,  
    92     # then assume that a y-m-d formated date is being  
    93     # piped in 
    94     typeset ymd 
    95     if [ $# = 0 ] 
    96         then 
    97         read ymd 
    98     else 
    99         ymd=$1 
    100     fi 
    101  
    102     IGCM_date_GregorianDigit $( print ${ymd} | sed 's/-//g' ) 
    103  
    104     IGCM_debug_PopStack "IGCM_date_ConvertFormatToGregorian" 
     85  IGCM_debug_PushStack "IGCM_date_ConvertFormatToGregorian" $@ 
     86 
     87  # from a yyyy-mm-dd date format return  
     88  # a yyymmdd date format 
     89  # usage IGCM_date_ConvertFormat yyyy-mm-dd 
     90 
     91  # if there is no argument on the command line,  
     92  # then assume that a y-m-d formated date is being  
     93  # piped in 
     94  typeset ymd 
     95  if [ $# = 0 ] 
     96  then 
     97    read ymd 
     98  else 
     99    ymd=$1 
     100  fi 
     101 
     102  IGCM_date_GregorianDigit $( print ${ymd} | sed 's/-//g' ) 
     103 
     104  IGCM_debug_PopStack "IGCM_date_ConvertFormatToGregorian" 
    105105} 
    106106 
     
    108108function IGCM_date_ConvertFormatToHuman 
    109109{ 
    110     IGCM_debug_PushStack "IGCM_date_ConvertFormatToHuman" $@ 
    111  
    112     # from a yyyymmdd date format return  
    113     # a yyyy-mm-dd date format 
    114     # usage IGCM_date_ConvertFormat yyyymmdd 
    115  
    116     # if there is no argument on the command line,  
    117     # then assume that a yyyymmdd formated date is being  
    118     # piped in 
    119     typeset dt 
    120     if [ $# = 0 ] 
    121         then 
    122         read dt 
    123     else 
    124         dt=$1 
    125     fi 
    126  
    127     # break the yyyymmdd into separate parts for year, month and day 
    128     echo $( IGCM_date_GregorianDigit ${dt} ) \ 
    129         | sed -e "s/\([0-9]\{${dY}\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\1-\2-\3/" 
    130  
    131     IGCM_debug_PopStack "IGCM_date_ConvertFormatToHuman" 
     110  IGCM_debug_PushStack "IGCM_date_ConvertFormatToHuman" $@ 
     111 
     112  # from a yyyymmdd date format return  
     113  # a yyyy-mm-dd date format 
     114  # usage IGCM_date_ConvertFormat yyyymmdd 
     115 
     116  # if there is no argument on the command line,  
     117  # then assume that a yyyymmdd formated date is being  
     118  # piped in 
     119  typeset dt 
     120  if [ $# = 0 ] 
     121  then 
     122    read dt 
     123  else 
     124    dt=$1 
     125  fi 
     126 
     127  # break the yyyymmdd into separate parts for year, month and day 
     128  echo $( IGCM_date_GregorianDigit ${dt} ) \ 
     129    | sed -e "s/\([0-9]\{${dY}\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\1-\2-\3/" 
     130 
     131  IGCM_debug_PopStack "IGCM_date_ConvertFormatToHuman" 
    132132} 
    133133 
     
    135135function IGCM_date_GetYearMonth 
    136136{ 
    137     IGCM_debug_PushStack "IGCM_date_GetYearMonth" $@ 
    138  
    139     # from a yyyymmdd date format return  
    140     # a yyyy year and mm month 
    141     # usage IGCM_date_GetYearMonth yyyymmdd year_var month_var 
    142  
    143     # if there is no argument on the command line,  
    144     # then assume that a yyyymmdd formated date is being  
    145     # piped in 
    146     typeset dt 
    147     if [ $# = 0 ] 
    148         then 
    149         read dt 
    150     else 
    151         dt=$1 
    152     fi 
    153  
    154     # break the yyyymmdd into separate parts for year, month and day 
    155     eval $2=$( echo $( IGCM_date_GregorianDigit ${dt} ) \ 
    156         | sed -e "s/\([0-9]\{${dY}\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\1/" ) 
    157     eval $3=$( echo $( IGCM_date_GregorianDigit ${dt} ) \ 
    158         | sed -e "s/\([0-9]\{${dY}\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\2/" ) 
    159  
    160     IGCM_debug_PopStack "IGCM_date_GetYearMonth" 
     137  IGCM_debug_PushStack "IGCM_date_GetYearMonth" $@ 
     138 
     139  # from a yyyymmdd date format return  
     140  # a yyyy year and mm month 
     141  # usage IGCM_date_GetYearMonth yyyymmdd year_var month_var 
     142 
     143  # if there is no argument on the command line,  
     144  # then assume that a yyyymmdd formated date is being  
     145  # piped in 
     146  typeset dt 
     147  if [ $# = 0 ] 
     148  then 
     149    read dt 
     150  else 
     151    dt=$1 
     152  fi 
     153 
     154  # break the yyyymmdd into separate parts for year, month and day 
     155  eval $2=$( echo $( IGCM_date_GregorianDigit ${dt} ) \ 
     156    | sed -e "s/\([0-9]\{${dY}\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\1/" ) 
     157  eval $3=$( echo $( IGCM_date_GregorianDigit ${dt} ) \ 
     158    | sed -e "s/\([0-9]\{${dY}\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\2/" ) 
     159 
     160  IGCM_debug_PopStack "IGCM_date_GetYearMonth" 
     161} 
     162 
     163#================================================================== 
     164function IGCM_date_GetYearMonthDay 
     165{ 
     166  IGCM_debug_PushStack "IGCM_date_GetYearMonthDay" $@ 
     167 
     168  # from a yyyymmdd date format return  
     169  # a yyyy year, mm month and dd day 
     170  # usage IGCM_date_GetYearMonthDay yyyymmdd year_var month_var day_var 
     171 
     172  # if there is no argument on the command line,  
     173  # then assume that a yyyymmdd formated date is being  
     174  # piped in 
     175  typeset dt 
     176  if [ $# = 0 ] 
     177  then 
     178    read dt 
     179  else 
     180    dt=$1 
     181  fi 
     182 
     183  # break the yyyymmdd into separate parts for year, month and day 
     184  eval $2=$( echo $( IGCM_date_GregorianDigit ${dt} ) \ 
     185    | sed -e "s/\([0-9]\{${dY}\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\1/" ) 
     186  eval $3=$( echo $( IGCM_date_GregorianDigit ${dt} ) \ 
     187    | sed -e "s/\([0-9]\{${dY}\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\2/" ) 
     188  eval $4=$( echo $( IGCM_date_GregorianDigit ${dt} ) \ 
     189    | sed -e "s/\([0-9]\{${dY}\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\3/" ) 
     190 
     191  IGCM_debug_PopStack "IGCM_date_GetYearMonthDay" 
    161192} 
    162193 
     
    171202{ 
    172203#    IGCM_debug_PushStack "IGCM_date_DaysInYear" $@ 
    173     # return the number of days in a year 
    174     # usage IGCM_date_DaysInYear yyyy 
    175  
    176     # What is the calendar : 
    177     case ${config_UserChoices_CalendarType} in 
    178         360d|360_day) 
    179             if [ X$2 = X ] ; then 
    180                 echo 360 
    181             else 
    182                 eval $2=360 > /dev/null 2>&1 
    183             fi 
     204  # return the number of days in a year 
     205  # usage IGCM_date_DaysInYear yyyy 
     206 
     207  # What is the calendar : 
     208  case ${config_UserChoices_CalendarType} in 
     209  360d|360_day) 
     210    if [ X$2 = X ] ; then 
     211      echo 360 
     212    else 
     213      eval $2=360 > /dev/null 2>&1 
     214    fi 
    184215#       IGCM_debug_PopStack "IGCM_date_DaysInYear" 
    185             return;; 
    186         noleap|365_day) 
    187             if [ X$2 = X ] ; then 
    188                 echo 365 
    189             else 
    190                 eval $2=365 > /dev/null 2>&1 
    191             fi 
    192  
    193 #           IGCM_debug_PopStack "IGCM_date_DaysInYear" 
    194             return;; 
    195         all_leap|366_day) 
    196             if [ X$2 = X ] ; then 
    197                 echo 366 
    198             else 
    199                 eval $2=366 > /dev/null 2>&1 
    200             fi 
    201  
    202 #               IGCM_debug_PopStack "IGCM_date_DaysInYear" 
    203             return;; 
    204     esac 
    205  
    206     typeset y a 
    207  
    208     # if there is no argument on the command line,  
    209     # then assume that a yyyy is being piped in 
    210     if [ $# = 0 ] 
    211         then 
    212         read y 
    213     else 
    214         y=$(( 10#${1} )) 
    215     fi 
    216  
    217     # a year is a leap year if it is even divisible by 4 
    218     # but not evenly divisible by 100 
    219     # unless it is evenly divisible by 400 
    220  
    221     # if it is evenly divisible by 400 it must be a leap year 
    222     a=$(( $y % 400 )) 
    223     if [ $a = 0 ] 
    224         then 
    225         if [ X$2 = X ] ; then 
    226             echo 366 
    227         else 
    228             eval $2=366 > /dev/null 2>&1 
    229         fi 
     216    return;; 
     217  noleap|365_day) 
     218    if [ X$2 = X ] ; then 
     219      echo 365 
     220    else 
     221      eval $2=365 > /dev/null 2>&1 
     222    fi 
    230223 
    231224#       IGCM_debug_PopStack "IGCM_date_DaysInYear" 
    232         return 
    233     fi 
    234  
    235     #if it is evenly divisible by 100 it must not be a leap year 
    236     a=$(( $y % 100 )) 
    237     if [ $a = 0 ] 
    238         then 
    239         if [ X$2 = X ] ; then 
    240             echo 365 
    241         else 
    242             eval $2=365 > /dev/null 2>&1 
    243         fi 
     225    return;; 
     226  all_leap|366_day) 
     227    if [ X$2 = X ] ; then 
     228      echo 366 
     229    else 
     230      eval $2=366 > /dev/null 2>&1 
     231    fi 
    244232 
    245233#       IGCM_debug_PopStack "IGCM_date_DaysInYear" 
    246         return 
    247     fi 
    248          
    249     # if it is evenly divisible by 4 it must be a leap year 
    250     a=$(( $y % 4 )) 
    251     if [ $a = 0 ] 
    252         then 
    253         if [ X$2 = X ] ; then 
    254             echo 366 
    255         else 
    256             eval $2=366 > /dev/null 2>&1 
    257         fi 
     234    return;; 
     235  esac 
     236 
     237  typeset y a 
     238 
     239  # if there is no argument on the command line,  
     240  # then assume that a yyyy is being piped in 
     241  if [ $# = 0 ] 
     242  then 
     243    read y 
     244  else 
     245    y=$(( 10#${1} )) 
     246  fi 
     247 
     248  # a year is a leap year if it is even divisible by 4 
     249  # but not evenly divisible by 100 
     250  # unless it is evenly divisible by 400 
     251 
     252  # if it is evenly divisible by 400 it must be a leap year 
     253  a=$(( $y % 400 )) 
     254  if [ $a = 0 ] 
     255  then 
     256    if [ X$2 = X ] ; then 
     257      echo 366 
     258    else 
     259      eval $2=366 > /dev/null 2>&1 
     260    fi 
    258261 
    259262#       IGCM_debug_PopStack "IGCM_date_DaysInYear" 
    260         return 
    261     fi 
    262  
    263     # otherwise it is not a leap year 
     263    return 
     264  fi 
     265 
     266  # if it is evenly divisible by 100 it must not be a leap year 
     267  a=$(( $y % 100 )) 
     268  if [ $a = 0 ] 
     269  then 
    264270    if [ X$2 = X ] ; then 
    265         echo 365 
    266     else 
    267         eval $2=365 > /dev/null 2>&1 
    268     fi 
     271      echo 365 
     272    else 
     273      eval $2=365 > /dev/null 2>&1 
     274    fi 
     275 
     276#       IGCM_debug_PopStack "IGCM_date_DaysInYear" 
     277    return 
     278  fi 
     279   
     280  # if it is evenly divisible by 4 it must be a leap year 
     281  a=$(( $y % 4 )) 
     282  if [ $a = 0 ] 
     283  then 
     284    if [ X$2 = X ] ; then 
     285      echo 366 
     286    else 
     287      eval $2=366 > /dev/null 2>&1 
     288    fi 
     289 
     290#       IGCM_debug_PopStack "IGCM_date_DaysInYear" 
     291    return 
     292  fi 
     293 
     294  # otherwise it is not a leap year 
     295  if [ X$2 = X ] ; then 
     296    echo 365 
     297  else 
     298    eval $2=365 > /dev/null 2>&1 
     299  fi 
    269300 
    270301#    IGCM_debug_PopStack "IGCM_date_DaysInYear" 
     
    284315#    IGCM_debug_PushStack "IGCM_date_DaysInMonth" $@ 
    285316 
    286     # calculates the number of days in a month  
    287     # usage IGCM_date_DaysInMonth yyyy mm 
    288     # or IGCM_date_DaysInMonth yyyymmdd 
     317  # calculates the number of days in a month  
     318  # usage IGCM_date_DaysInMonth yyyy mm 
     319  # or IGCM_date_DaysInMonth yyyymmdd 
     320   
     321  # What is the calendar : 
     322  if ( [ "${config_UserChoices_CalendarType}" = "360d" ] || [ "${config_UserChoices_CalendarType}" = "360_day" ] ) ; then 
     323    if [ X$3 = X ] ; then 
     324      echo 30 
     325    else 
     326      eval $3=30 > /dev/null 2>&1 
     327    fi 
     328 
     329#   IGCM_debug_PopStack "IGCM_date_DaysInMonth" 
     330    return 
     331  fi 
     332 
     333  typeset ymd y m 
     334 
     335  # if there are no command line arguments then assume that a yyyymmdd is being 
     336  # piped in and read the value. 
     337  # if there is only one argument assume it is a yyyymmdd on the command line 
     338  # other wise it is a yyyy and mm on the command line 
     339  if [ $# = 0 ] 
     340  then 
     341    read ymd 
     342  elif [ $# = 1 ]  
     343  then 
     344    ymd=$1 
     345  else 
     346    ymd=$(( ( $1 * 10000 ) + ( $2 * 100 ) + 1 )) 
     347  fi 
     348 
     349  # extract the year and the month 
     350  y=$(( $ymd / 10000 )) ; 
     351  m=$(( ( $ymd % 10000 ) / 100 )) ; 
     352 
     353  # 30 days hath september etc. 
     354  case $m in 
     355  1|3|5|7|8|10|12)  
     356    if [ X$3 = X ] ; then 
     357      echo 31 
     358    else 
     359      eval $3=31 > /dev/null 2>&1 
     360    fi 
     361 
     362#           IGCM_debug_PopStack "IGCM_date_DaysInMonth" 
     363    return ;; 
     364  4|6|9|11)  
     365    if [ X$3 = X ] ; then 
     366      echo 30 
     367    else 
     368      eval $3=30 > /dev/null 2>&1 
     369    fi 
    289370     
    290     # What is the calendar : 
    291     if ( [ "${config_UserChoices_CalendarType}" = "360d" ] || [ "${config_UserChoices_CalendarType}" = "360_day" ] ) ; then 
    292         if [ X$3 = X ] ; then 
    293             echo 30 
    294         else 
    295             eval $3=30 > /dev/null 2>&1 
    296         fi 
    297  
    298 #       IGCM_debug_PopStack "IGCM_date_DaysInMonth" 
    299         return 
    300     fi 
    301  
    302     typeset ymd y m 
    303  
    304     # if there are no command line arguments then assume that a yyyymmdd is being 
    305     # piped in and read the value. 
    306     # if there is only one argument assume it is a yyyymmdd on the command line 
    307     # other wise it is a yyyy and mm on the command line 
    308     if [ $# = 0 ] 
    309         then 
    310         read ymd 
    311     elif [ $# = 1 ]  
    312         then 
    313         ymd=$1 
    314     else 
    315         ymd=$(( ( $1 * 10000 ) + ( $2 * 100 ) + 1 )) 
    316     fi 
    317  
    318     # extract the year and the month 
    319     y=$(( $ymd / 10000 )) ; 
    320     m=$(( ( $ymd % 10000 ) / 100 )) ; 
    321  
    322     # 30 days hath september etc. 
    323     case $m in 
    324         1|3|5|7|8|10|12)  
    325             if [ X$3 = X ] ; then 
    326                 echo 31 
    327             else 
    328                 eval $3=31 > /dev/null 2>&1 
    329             fi 
    330  
    331371#           IGCM_debug_PopStack "IGCM_date_DaysInMonth" 
    332             return ;; 
    333         4|6|9|11)  
    334             if [ X$3 = X ] ; then 
    335                 echo 30 
    336             else 
    337                 eval $3=30 > /dev/null 2>&1 
    338             fi 
    339          
    340 #           IGCM_debug_PopStack "IGCM_date_DaysInMonth" 
    341             return ;; 
    342         *) ;; 
    343     esac 
    344  
    345     # except for month 2 which depends on whether the year is a leap year 
    346     # Use IGCM_date_DaysInYear to get the number of days in the year and return a value 
    347     # accordingly. 
    348     IGCM_date_DaysInYear $y diy 
    349     case $diy in 
    350         365)  
    351             if [ X$3 = X ] ; then 
    352                 echo 28 
    353             else 
    354                 eval $3=28 > /dev/null 2>&1 
    355             fi 
    356  
    357 #           IGCM_debug_PopStack "IGCM_date_DaysInMonth" 
    358             return ;; 
    359         366)  
    360             if [ X$3 = X ] ; then 
    361                 echo 29 
    362             else 
    363                 eval $3=29 > /dev/null 2>&1 
    364             fi 
    365  
    366 #           IGCM_debug_PopStack "IGCM_date_DaysInMonth" 
    367             return ;; 
    368     esac 
     372    return ;; 
     373  *) ;; 
     374  esac 
     375 
     376  # except for month 2 which depends on whether the year is a leap year 
     377  # Use IGCM_date_DaysInYear to get the number of days in the year and return a value 
     378  # accordingly. 
     379  IGCM_date_DaysInYear $y diy 
     380  case $diy in 
     381  365)  
     382    if [ X$3 = X ] ; then 
     383      echo 28 
     384    else 
     385      eval $3=28 > /dev/null 2>&1 
     386    fi 
     387 
     388#    IGCM_debug_PopStack "IGCM_date_DaysInMonth" 
     389    return ;; 
     390  366)  
     391    if [ X$3 = X ] ; then 
     392      echo 29 
     393    else 
     394      eval $3=29 > /dev/null 2>&1 
     395    fi 
     396 
     397#    IGCM_debug_PopStack "IGCM_date_DaysInMonth" 
     398    return ;; 
     399  esac 
    369400 
    370401#    IGCM_debug_PopStack "IGCM_date_DaysInMonth" 
     
    380411function IGCM_date_ConvertGregorianDateToJulian 
    381412{ 
    382     IGCM_debug_PushStack "IGCM_date_ConvertGregorianDateToJulian" $@ 
    383  
    384     # IGCM_date_ConvertGregorianDateToJulian converts yyyymmdd to yyyyddd 
    385     # usage IGCM_date_ConvertGregorianDateToJulian 19980429 
    386  
    387     typeset dt y m d x jul 
    388  
    389     # if there is no command line argument, then assume that the date 
    390     # is coming in on a pipe and use read to collect it     
    391     if [ $# = 0 ] 
    392         then 
    393         read dt 
    394     else 
    395         dt=$( IGCM_date_SupressZeros $1 ) 
    396     fi 
    397  
    398     # break the yyyymmdd into separate parts for year, month and day 
    399     y=$(( $dt / 10000 )) 
    400     m=$(( ( $dt % 10000 ) / 100 )) 
    401     d=$(( ( $dt % 100 ) )) 
    402  
    403     # add the days in each month up to (but not including the month itself) 
    404     # into the days. For example if the date is 19980203 then extract the 
    405     # number of days in January and add it to 03. If the date is June 14, 1998 
    406     # then extract the number of days in January, February, March, April and May 
    407     # and add them to 14. 
    408     x=1 
    409     while [ $x -lt $m ] 
    410       do 
    411       IGCM_date_DaysInMonth $y $x md 
    412       d=$(( $d + $md )) 
    413       x=$(( $x + 1 )) 
    414     done 
    415  
    416     # combine the year and day back together again and you have the julian date. 
    417     jul=$(( ( $y * 1000 ) + $d )) 
    418     echo $jul 
    419  
    420     IGCM_debug_PopStack "IGCM_date_ConvertGregorianDateToJulian" 
     413  IGCM_debug_PushStack "IGCM_date_ConvertGregorianDateToJulian" $@ 
     414 
     415  # IGCM_date_ConvertGregorianDateToJulian converts yyyymmdd to yyyyddd 
     416  # usage IGCM_date_ConvertGregorianDateToJulian 19980429 
     417 
     418  typeset dt y m d x jul 
     419 
     420  # 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     
     422  if [ $# = 0 ] 
     423  then 
     424    read dt 
     425  else 
     426    dt=$( IGCM_date_SupressZeros $1 ) 
     427  fi 
     428 
     429  # break the yyyymmdd into separate parts for year, month and day 
     430  y=$(( $dt / 10000 )) 
     431  m=$(( ( $dt % 10000 ) / 100 )) 
     432  d=$(( ( $dt % 100 ) )) 
     433 
     434  # add the days in each month up to (but not including the month itself) 
     435  # into the days. For example if the date is 19980203 then extract the 
     436  # number of days in January and add it to 03. If the date is June 14, 1998 
     437  # then extract the number of days in January, February, March, April and May 
     438  # and add them to 14. 
     439  x=1 
     440  while [ $x -lt $m ] 
     441  do 
     442    IGCM_date_DaysInMonth $y $x md 
     443    d=$(( $d + $md )) 
     444    x=$(( $x + 1 )) 
     445  done 
     446 
     447  # combine the year and day back together again and you have the julian date. 
     448  jul=$(( ( $y * 1000 ) + $d )) 
     449  echo $jul 
     450 
     451  IGCM_debug_PopStack "IGCM_date_ConvertGregorianDateToJulian" 
    421452} 
    422453 
     
    430461function IGCM_date_ConvertJulianDateToGregorian 
    431462{ 
    432     IGCM_debug_PushStack "IGCM_date_ConvertJulianDateToGregorian" $@ 
    433  
    434     # IGCM_date_ConvertJulianDateToGregorian converts yyyyddd to yyyymmdd 
    435     # usage IGCM_date_ConvertJulianDateToGregorian 1998213 
    436  
    437     typeset dt y m d grg 
    438  
    439     # if there is no command line argument, assume one is being  
    440     # piped in and read it 
    441     if [ X$1 = X ] 
    442         then 
    443         read dt 
    444     else 
    445         dt=$1 
    446     fi 
    447          
    448     # break apart the year and the days 
    449     y=$(( $dt / 1000 )) 
    450     d=$(( $dt % 1000 )) 
    451          
    452     # subtract the number of days in each month starting from 1 
    453     # from the days in the date. When the day goes below 1, you 
    454     # have the current month. Add back the number of days in the 
    455     # month to get the correct day of the month 
    456     m=1 
    457     while [ $d -gt 0 ] 
    458       do 
    459       IGCM_date_DaysInMonth $y $m md 
    460       d=$(( $d - $md )) 
    461       m=$(( $m + 1 )) 
    462     done 
    463  
    464     d=$(( $d + $md )) 
    465  
    466     # the loop steps one past the correct month, so back up the month 
    467     m=$(( $m - 1 )) 
    468  
    469     # assemble the results into a gregorian date 
    470     grg=$(( ( $y * 10000 ) + ( $m * 100 ) + $d )) 
    471     echo $( IGCM_date_GregorianDigit $grg ) 
    472  
    473     IGCM_debug_PopStack "IGCM_date_ConvertJulianDateToGregorian" 
     463  IGCM_debug_PushStack "IGCM_date_ConvertJulianDateToGregorian" $@ 
     464 
     465  # IGCM_date_ConvertJulianDateToGregorian converts yyyyddd to yyyymmdd 
     466  # usage IGCM_date_ConvertJulianDateToGregorian 1998213 
     467 
     468  typeset dt y m d grg 
     469 
     470  # if there is no command line argument, assume one is being  
     471  # piped in and read it 
     472  if [ X$1 = X ] 
     473  then 
     474    read dt 
     475  else 
     476    dt=$1 
     477  fi 
     478   
     479  # break apart the year and the days 
     480  y=$(( $dt / 1000 )) 
     481  d=$(( $dt % 1000 )) 
     482   
     483  # subtract the number of days in each month starting from 1 
     484  # from the days in the date. When the day goes below 1, you 
     485  # have the current month. Add back the number of days in the 
     486  # month to get the correct day of the month 
     487  m=1 
     488  while [ $d -gt 0 ] 
     489  do 
     490    IGCM_date_DaysInMonth $y $m md 
     491    d=$(( $d - $md )) 
     492    m=$(( $m + 1 )) 
     493  done 
     494 
     495  d=$(( $d + $md )) 
     496 
     497  # the loop steps one past the correct month, so back up the month 
     498  m=$(( $m - 1 )) 
     499 
     500  # assemble the results into a gregorian date 
     501  grg=$(( ( $y * 10000 ) + ( $m * 100 ) + $d )) 
     502  echo $( IGCM_date_GregorianDigit $grg ) 
     503 
     504  IGCM_debug_PopStack "IGCM_date_ConvertJulianDateToGregorian" 
    474505} 
    475506 
     
    483514function IGCM_date_AddDaysToJulianDate 
    484515{ 
    485     IGCM_debug_PushStack "IGCM_date_AddDaysToJulianDate" $@ 
    486  
    487     # IGCM_date_AddDaysToJulianDate adds days to a yyyyddd formatted date 
    488     # usage IGCM_date_AddDaysToJulianDate 1998312 { ,-}14 
    489  
    490     typeset dif yd d y 
    491  
    492     # Read the difference from the command lines 
    493     # and the date from the command line, or standard input 
    494     if [ X$2 = X ] 
    495         then 
    496         dif=$1 
    497         read yd 
    498     else 
    499         yd=$1 
    500         dif=$2 
    501     fi 
    502  
    503     # Break it into pieces 
    504     d=$(( $yd % 1000 )) 
    505     y=$(( $yd / 1000 )) 
    506  
    507     # Add the number of days (if days is negative this results is 
    508     # a subtraction) 
    509     d=$(( $d + $dif )) 
    510  
    511     # Extract the days in the year 
     516  IGCM_debug_PushStack "IGCM_date_AddDaysToJulianDate" $@ 
     517 
     518  # IGCM_date_AddDaysToJulianDate adds days to a yyyyddd formatted date 
     519  # usage IGCM_date_AddDaysToJulianDate 1998312 { ,-}14 
     520 
     521  typeset dif yd d y 
     522 
     523  # Read the difference from the command lines 
     524  # and the date from the command line, or standard input 
     525  if [ X$2 = X ] 
     526  then 
     527    dif=$1 
     528    read yd 
     529  else 
     530    yd=$1 
     531    dif=$2 
     532  fi 
     533 
     534  # Break it into pieces 
     535  d=$(( $yd % 1000 )) 
     536  y=$(( $yd / 1000 )) 
     537 
     538  # Add the number of days (if days is negative this results is 
     539  # a subtraction) 
     540  d=$(( $d + $dif )) 
     541 
     542  # Extract the days in the year 
     543  IGCM_date_DaysInYear $y diy 
     544 
     545  # If the calculated day exceeds the days in the year,  
     546  # add one year to the year and subtract the days in the year from the 
     547  # calculated days. Extract the days in the new year and repeat 
     548  # test until you end up with a day number that falls within the 
     549  # days of the year 
     550  while [ $d -gt $diy ] 
     551  do 
     552    d=$(( $d - $diy )) 
     553    y=$(( $y + 1 )) 
    512554    IGCM_date_DaysInYear $y diy 
    513  
    514     # If the calculated day exceeds the days in the year,  
    515     # add one year to the year and subtract the days in the year from the 
    516     # calculated days. Extract the days in the new year and repeat 
    517     # test until you end up with a day number that falls within the 
    518     # days of the year 
    519     while [ $d -gt $diy ] 
    520       do 
    521       d=$(( $d - $diy )) 
    522       y=$(( $y + 1 )) 
    523       IGCM_date_DaysInYear $y diy 
    524     done 
    525  
    526     # This is the reverse process. If the calculated number of days 
    527     # is less than 1, move back one year. Extract 
    528     # the days in this year and add the days in the year 
    529     # loop on this test until you end up with a number that 
    530     # falls within the days of the year 
    531     while [ $d -lt 1 ] 
    532       do 
    533       y=$(( $y - 1 )) 
    534       IGCM_date_DaysInYear $y diy 
    535       d=$(( $d + $diy )) 
    536     done 
    537  
    538     # put the year and day back together and echo the result 
    539     yd=$(( ( $y * 1000 ) + $d )) 
    540  
    541     echo $yd 
    542  
    543     IGCM_debug_PopStack "IGCM_date_AddDaysToJulianDate" 
     555  done 
     556 
     557  # This is the reverse process. If the calculated number of days 
     558  # is less than 1, move back one year. Extract 
     559  # the days in this year and add the days in the year 
     560  # loop on this test until you end up with a number that 
     561  # falls within the days of the year 
     562  while [ $d -lt 1 ] 
     563  do 
     564    y=$(( $y - 1 )) 
     565    IGCM_date_DaysInYear $y diy 
     566    d=$(( $d + $diy )) 
     567  done 
     568 
     569  # put the year and day back together and echo the result 
     570  yd=$(( ( $y * 1000 ) + $d )) 
     571 
     572  echo $yd 
     573 
     574  IGCM_debug_PopStack "IGCM_date_AddDaysToJulianDate" 
    544575} 
    545576 
     
    553584function IGCM_date_AddDaysToGregorianDate 
    554585{ 
    555     IGCM_debug_PushStack "IGCM_date_AddDaysToGregorianDate" $@ 
    556  
    557     # IGCM_date_AddDaysToGregorianDate adds days to a yyyymmdd formatted date 
    558     # usage IGCM_date_AddDaysToGregorianDate 19980312 { ,-}14 
    559  
    560     # Read the difference from the command lines 
    561     # and the date from the command line, or standard input 
    562     typeset dif yd tmp res 
    563     if [ X$2 = X ] 
    564         then 
    565         dif=$1 
    566         read yd 
    567     else 
    568         yd=$1 
    569         dif=$2 
    570     fi 
    571  
    572     tmp=$( IGCM_date_ConvertGregorianDateToJulian $yd ) 
    573     tmp=$( IGCM_date_AddDaysToJulianDate $tmp $dif ) 
    574     res=$( IGCM_date_ConvertJulianDateToGregorian $tmp ) 
    575      
    576     echo $res 
    577  
    578     IGCM_debug_PopStack "IGCM_date_AddDaysToGregorianDate" 
     586  IGCM_debug_PushStack "IGCM_date_AddDaysToGregorianDate" $@ 
     587 
     588  # IGCM_date_AddDaysToGregorianDate adds days to a yyyymmdd formatted date 
     589  # usage IGCM_date_AddDaysToGregorianDate 19980312 { ,-}14 
     590 
     591  # Read the difference from the command lines 
     592  # and the date from the command line, or standard input 
     593  typeset dif yd tmp res 
     594  if [ X$2 = X ] 
     595  then 
     596    dif=$1 
     597    read yd 
     598  else 
     599    yd=$1 
     600    dif=$2 
     601  fi 
     602 
     603  tmp=$( IGCM_date_ConvertGregorianDateToJulian $yd ) 
     604  tmp=$( IGCM_date_AddDaysToJulianDate $tmp $dif ) 
     605  res=$( IGCM_date_ConvertJulianDateToGregorian $tmp ) 
     606   
     607  echo $res 
     608 
     609  IGCM_debug_PopStack "IGCM_date_AddDaysToGregorianDate" 
    579610} 
    580611 
     
    588619function IGCM_date_DaysBetweenJulianDate 
    589620{ 
    590     IGCM_debug_PushStack "IGCM_date_DaysBetweenJulianDate" $@ 
    591  
    592     # calculates the days difference between two dates and reports  
    593     # the number days as jul1 - jul2  
    594     # usage IGCM_date_DaysBetweenJulianDate jul1 jul2 
    595     # where julian date is in the form yyyyddd 
    596      
    597     usage () { 
    598         echo "Usage:" 
    599         echo " IGCM_date_DaysBetweenJulianDate jul1 jul2" 
    600         echo "" 
    601         echo " Calculates the day difference between" 
    602         echo " two julian dates (jul1 -jul2)" 
    603         echo " where a julian date is in the form of yyyyddd." 
    604     } 
    605   
    606     if [ $# -lt 2 ]; then 
    607         usage 
    608         IGCM_debug_Exit "IGCM_date_DaysBetweenJulianDate" 
    609     fi 
    610   
    611     # This process subtracts arg2 from arg1. If arg2 is larger 
    612     # then reverse the arguments. The calculations are done, and 
    613     # then the sign is reversed 
    614     if [ $1 -lt $2 ] 
    615         then 
    616         jul1=$2 
    617         jul2=$1 
    618     elif [ $1 -gt $2 ] 
    619         then 
    620         jul1=$1 
    621         jul2=$2 
    622     else 
    623         echo 0 
    624         IGCM_debug_PopStack "IGCM_date_DaysBetweenJulianDate" 
    625         return 
    626     fi 
    627  
    628     # Break the dates in to year and day portions 
    629     yyyy1=$(( $jul1 / 1000 )) 
    630     yyyy2=$(( $jul2 / 1000 )) 
    631     ddd1=$(( $jul1 % 1000 )) 
    632     ddd2=$(( $jul2 % 1000 )) 
    633  
    634     # Subtract days 
    635     res=$(( $ddd1 - $ddd2 )) 
    636  
    637     # Then add days in year until year2 matches year1 
    638  
    639     case ${config_UserChoices_CalendarType} in 
    640         360d|360_day)  
    641             res=$(( ( ( $yyyy1 - $yyyy2 ) * 360 ) + $res )) ;; 
    642         noleap|365_day) 
    643             res=$(( ( ( $yyyy1 - $yyyy2 ) * 365 ) + $res )) ;; 
    644         all_leap|366_day) 
    645             res=$(( ( ( $yyyy1 - $yyyy2 ) * 366 ) + $res )) ;; 
    646         leap|gregorian|standard) 
    647             while [ $yyyy2 -lt $yyyy1 ] 
    648             do 
    649                 IGCM_date_DaysInYear $yyyy2 diy 
    650                 res=$(( $res + $diy )) 
    651                 yyyy2=$(( $yyyy2 + 1 )) 
    652             done 
    653             ;; 
    654     esac 
    655  
    656  
    657     # if argument 2 was larger than argument 1 then  
    658     # the arguments were reversed before calculating 
    659     # adjust by reversing the sign 
    660     if [ $1 -lt $2 ] 
    661         then 
    662         res=$(( $res * -1 )) 
    663     fi 
    664   
    665     # and output the results 
    666     echo $res 
    667  
     621  IGCM_debug_PushStack "IGCM_date_DaysBetweenJulianDate" $@ 
     622 
     623  # calculates the days difference between two dates and reports  
     624  # the number days as jul1 - jul2  
     625  # usage IGCM_date_DaysBetweenJulianDate jul1 jul2 
     626  # where julian date is in the form yyyyddd 
     627   
     628  usage () { 
     629    echo "Usage:" 
     630    echo " IGCM_date_DaysBetweenJulianDate jul1 jul2" 
     631    echo "" 
     632    echo " Calculates the day difference between" 
     633    echo " two julian dates (jul1 -jul2)" 
     634    echo " where a julian date is in the form of yyyyddd." 
     635  } 
     636   
     637  if [ $# -lt 2 ]; then 
     638    usage 
     639    IGCM_debug_Exit "IGCM_date_DaysBetweenJulianDate" 
     640  fi 
     641   
     642  # This process subtracts arg2 from arg1. If arg2 is larger 
     643  # then reverse the arguments. The calculations are done, and 
     644  # then the sign is reversed 
     645  if [ $1 -lt $2 ] 
     646  then 
     647    jul1=$2 
     648    jul2=$1 
     649  elif [ $1 -gt $2 ] 
     650  then 
     651    jul1=$1 
     652    jul2=$2 
     653  else 
     654    echo 0 
    668655    IGCM_debug_PopStack "IGCM_date_DaysBetweenJulianDate" 
     656    return 
     657  fi 
     658 
     659  # Break the dates in to year and day portions 
     660  yyyy1=$(( $jul1 / 1000 )) 
     661  yyyy2=$(( $jul2 / 1000 )) 
     662  ddd1=$(( $jul1 % 1000 )) 
     663  ddd2=$(( $jul2 % 1000 )) 
     664 
     665  # Subtract days 
     666  res=$(( $ddd1 - $ddd2 )) 
     667 
     668  # Then add days in year until year2 matches year1 
     669  case ${config_UserChoices_CalendarType} in 
     670  360d|360_day)  
     671    res=$(( ( ( $yyyy1 - $yyyy2 ) * 360 ) + $res )) ;; 
     672  noleap|365_day) 
     673    res=$(( ( ( $yyyy1 - $yyyy2 ) * 365 ) + $res )) ;; 
     674  all_leap|366_day) 
     675    res=$(( ( ( $yyyy1 - $yyyy2 ) * 366 ) + $res )) ;; 
     676  leap|gregorian|standard) 
     677    while [ $yyyy2 -lt $yyyy1 ] 
     678    do 
     679      IGCM_date_DaysInYear $yyyy2 diy 
     680      res=$(( $res + $diy )) 
     681      yyyy2=$(( $yyyy2 + 1 )) 
     682    done 
     683    ;; 
     684  esac 
     685 
     686 
     687  # if argument 2 was larger than argument 1 then  
     688  # the arguments were reversed before calculating 
     689  # adjust by reversing the sign 
     690  if [ $1 -lt $2 ] 
     691  then 
     692    res=$(( $res * -1 )) 
     693  fi 
     694 
     695  # and output the results 
     696  echo $res 
     697 
     698  IGCM_debug_PopStack "IGCM_date_DaysBetweenJulianDate" 
    669699} 
    670700 
     
    678708function IGCM_date_DaysBetweenGregorianDate 
    679709{ 
    680     IGCM_debug_PushStack "IGCM_date_DaysBetweenGregorianDate" $@ 
    681  
    682     # calculates the days difference between two dates and reports  
    683     # the number days as grg1 - grg2  
    684     # usage IGCM_date_DaysBetweenGregorianDate grg1 grg2 
    685     # where gregorian date is in the form yyyymmdd 
    686  
    687     usage () { 
    688         echo "Usage:" 
    689         echo " IGCM_date_DaysBetweenGregorianDate grg1 grg2" 
    690         echo "" 
    691         echo " Calculate day difference between" 
    692         echo " two gregorian dates (grg1 - grg2)" 
    693         echo " where a gregorian date is in the form of yyyymmdd." 
    694     } 
    695  
    696     if [ $# -lt 2 ]; then 
    697         usage 
    698         IGCM_debug_Exit "IGCM_date_DaysBetweenGregorianDate" 
    699     fi 
    700  
    701     # convert each date to julian 
    702     grg1=$1 
    703     grg2=$2 
    704  
    705     jul1=$( IGCM_date_ConvertGregorianDateToJulian $grg1 ) 
    706     jul2=$( IGCM_date_ConvertGregorianDateToJulian $grg2 ) 
    707  
    708     if [ $jul1 -ne $jul2 ]; then 
     710  IGCM_debug_PushStack "IGCM_date_DaysBetweenGregorianDate" $@ 
     711 
     712  # calculates the days difference between two dates and reports  
     713  # the number days as grg1 - grg2  
     714  # usage IGCM_date_DaysBetweenGregorianDate grg1 grg2 
     715  # where gregorian date is in the form yyyymmdd 
     716 
     717  usage () { 
     718    echo "Usage:" 
     719    echo " IGCM_date_DaysBetweenGregorianDate grg1 grg2" 
     720    echo "" 
     721    echo " Calculate day difference between" 
     722    echo " two gregorian dates (grg1 - grg2)" 
     723    echo " where a gregorian date is in the form of yyyymmdd." 
     724  } 
     725 
     726  if [ $# -lt 2 ]; then 
     727    usage 
     728    IGCM_debug_Exit "IGCM_date_DaysBetweenGregorianDate" 
     729  fi 
     730 
     731  # convert each date to julian 
     732  grg1=$1 
     733  grg2=$2 
     734 
     735  jul1=$( IGCM_date_ConvertGregorianDateToJulian $grg1 ) 
     736  jul2=$( IGCM_date_ConvertGregorianDateToJulian $grg2 ) 
     737 
     738  if [ $jul1 -ne $jul2 ]; then 
    709739    # calculate the answer using IGCM_date_DaysBetweenJulianDate 
    710         res=$( IGCM_date_DaysBetweenJulianDate $jul1 $jul2 ) 
     740    res=$( IGCM_date_DaysBetweenJulianDate $jul1 $jul2 ) 
    711741    # and output the results 
    712         echo $res 
    713     else 
    714         echo 0 
    715     fi 
    716  
    717     IGCM_debug_PopStack "IGCM_date_DaysBetweenGregorianDate" 
     742    echo $res 
     743  else 
     744    echo 0 
     745  fi 
     746 
     747  IGCM_debug_PopStack "IGCM_date_DaysBetweenGregorianDate" 
    718748} 
    719749 
     
    726756function IGCM_date_DaysSinceJC 
    727757{ 
    728     IGCM_debug_PushStack "IGCM_date_DaysSinceJC" $@ 
    729  
    730     # calculates the days difference between a date and 00010101 
    731     # usage IGCM_date_DaysSinceJC grg1 
    732     # where gregorian date is in the form yyyymmdd 
    733  
    734     usage () { 
    735         echo "Usage:" 
    736         echo " IGCM_date_DaysSinceJC grg1" 
    737         echo "" 
    738         echo " Calculate day difference between" 
    739         echo " a gregorian date and 00010101" 
    740         echo " where a gregorian date is in the form of yyyymmdd." 
    741     } 
    742  
    743     if [ $# -lt 1 ]; then 
    744         usage 
    745         IGCM_debug_Exit "IGCM_date_DaysSinceJC" 
    746     fi 
    747      
    748     typeset aux num 
    749  
    750     if   [ ${1} -lt  5000000 ]; then 
    751         case ${config_UserChoices_CalendarType} in 
    752             360d|360_day)  
    753                 aux=-360;; 
    754             noleap|365_day) 
    755                 aux=-365;; 
    756             all_leap|366_day)  
    757                 aux=-366;; 
    758             leap|gregorian|standard) 
    759                 aux=-366;; 
    760         esac 
    761         num=101 
    762     elif [ ${1} -lt 15000000 ]; then 
    763         # To save CPU type we use auxiliary value 
    764         # which is number of days since JC and 10000101 
    765         case ${config_UserChoices_CalendarType} in 
    766             360d|360_day)  
    767                 aux=359640;; 
    768             noleap|365_day) 
    769                 aux=364635;; 
    770             all_leap|366_day)  
    771                 aux=365634;; 
    772             leap|gregorian|standard) 
    773                 aux=364877;; 
    774         esac 
    775         num=10000101 
    776     else 
    777         # To save CPU type we use auxiliary value 
    778         # which is number of days since JC and 19000101 
    779         case ${config_UserChoices_CalendarType} in 
    780             360d|360_day)  
    781                 aux=683640;; 
    782             noleap|365_day) 
    783                 aux=693135;; 
    784             all_leap|366_day)  
    785                 aux=695034;; 
    786             leap|gregorian|standard) 
    787                 aux=693595;; 
    788         esac 
    789         num=19000101 
    790     fi 
    791     echo $(( $( IGCM_date_DaysBetweenGregorianDate $1 ${num} ) + $aux )) 
    792  
    793     IGCM_debug_PopStack "IGCM_date_DaysSinceJC" 
    794 } 
     758  IGCM_debug_PushStack "IGCM_date_DaysSinceJC" $@ 
     759 
     760  # calculates the days difference between a date and 00010101 
     761  # usage IGCM_date_DaysSinceJC grg1 
     762  # where gregorian date is in the form yyyymmdd 
     763 
     764  usage () { 
     765    echo "Usage:" 
     766    echo " IGCM_date_DaysSinceJC grg1" 
     767    echo "" 
     768    echo " Calculate day difference between" 
     769    echo " a gregorian date and 00010101" 
     770    echo " where a gregorian date is in the form of yyyymmdd." 
     771  } 
     772 
     773  if [ $# -lt 1 ]; then 
     774    usage 
     775    IGCM_debug_Exit "IGCM_date_DaysSinceJC" 
     776  fi 
     777   
     778  typeset aux num 
     779 
     780  if   [ ${1} -lt  5000000 ]; then 
     781    case ${config_UserChoices_CalendarType} in 
     782    360d|360_day)  
     783      aux=-360;; 
     784    noleap|365_day) 
     785      aux=-365;; 
     786    all_leap|366_day)  
     787      aux=-366;; 
     788    leap|gregorian|standard) 
     789      aux=-366;; 
     790    esac 
     791    num=101 
     792  elif [ ${1} -lt 15000000 ]; then 
     793    # To save CPU type we use auxiliary value 
     794    # which is number of days since JC and 10000101 
     795    case ${config_UserChoices_CalendarType} in 
     796    360d|360_day)  
     797      aux=359640;; 
     798    noleap|365_day) 
     799      aux=364635;; 
     800    all_leap|366_day)  
     801      aux=365634;; 
     802    leap|gregorian|standard) 
     803      aux=364877;; 
     804    esac 
     805    num=10000101 
     806  else 
     807    # To save CPU type we use auxiliary value 
     808    # which is number of days since JC and 19000101 
     809    case ${config_UserChoices_CalendarType} in 
     810    360d|360_day)  
     811      aux=683640;; 
     812    noleap|365_day) 
     813      aux=693135;; 
     814    all_leap|366_day)  
     815      aux=695034;; 
     816    leap|gregorian|standard) 
     817      aux=693595;; 
     818    esac 
     819    num=19000101 
     820  fi 
     821  echo $(( $( IGCM_date_DaysBetweenGregorianDate $1 ${num} ) + $aux )) 
     822 
     823  IGCM_debug_PopStack "IGCM_date_DaysSinceJC" 
     824} 
     825 
     826#D-#================================================================== 
     827#D-function IGCM_date_DaysInPreviousPeriod () 
     828#D-* Purpose: Give the numbers of days during the previous prd1 period from grg1 date # OLD create_ts_begin_date 
     829#D-* Usage: IGCM_date_DaysInPreviousPeriod grg1 prd1 [end] 
     830#D-         where grg1 gregorian date is in the form yyyymmdd 
     831#D-         where prd1 period is in the form N[Yy], N[Mm], N[Dd]. N integer 
     832#D-         where [end] is an optionnal keyword to specify grg1 is the end of prd1 
     833#D- 
     834function IGCM_date_DaysInPreviousPeriod { 
     835  IGCM_debug_PushStack "IGCM_date_DaysInPreviousPeriod" $@ 
     836  typeset Length Period 
     837  Period=${2} 
     838  case ${Period} in 
     839  *Y|*y) 
     840    PeriodLengthInYears=$( echo ${Period} | awk -F '[yY]' '{print $1}' ) 
     841    IGCM_date_GetYearMonth ${1} year month 
     842    year=$( IGCM_date_SupressZeros ${year} ) 
     843    if [ X${2} = Xend ] ; then 
     844      (( year = year - PeriodLengthInYears + 1)) 
     845    fi 
     846    (( Length=0 )) 
     847    (( i=0 )) 
     848    until [ $i -ge $PeriodLengthInYears ] ; do 
     849      (( Length = Length + $( IGCM_date_DaysInYear $(( year + i )) ) ))  
     850      (( i=i+1 )) 
     851    done 
     852    ;; 
     853  *M|*m) 
     854    PeriodLengthInMonths=$( echo ${Period} | awk -F '[mM]' '{print $1}' ) 
     855    IGCM_date_GetYearMonth ${1} year month 
     856    year=$( IGCM_date_SupressZeros ${year} ) 
     857    if [ X${2} = Xend ] ; then 
     858      (( month = month - PeriodLengthInMonths + 1 )) 
     859    fi       
     860    (( year0 = year )) 
     861    if [ $month -le 0 ] ; then 
     862      (( month = month + 12 )) 
     863      year=$( printf "%04i\n" $(( year - 1 )) ) 
     864    fi 
     865    month=$( printf "%02i\n" ${month} ) 
     866    (( Length=0 )) 
     867    (( i=0 )) 
     868    until [ $i -ge $PeriodLengthInMonths ] ; do 
     869      if [ $(( month + i )) -lt 13 ] ; then 
     870        (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i )) ) )) 
     871      else 
     872        (( year = year0 + 1 )) 
     873        (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i - 12 )) ) )) 
     874      fi 
     875      (( i=i+1 )) 
     876    done 
     877    ;; 
     878  *D|*d) 
     879    Length=$( echo ${Period} | sed -e "s/[dD]//" ) ;; 
     880  *) 
     881    IGCM_debug_Exit "IGCM_date_DaysInPreviousPeriod " ${Period} " invalid PeriodLength : choose in *Y, *M, *D." 
     882    IGCM_debug_Verif_Exit_Post ;; 
     883  esac 
     884  echo ${Length} 
     885 
     886  IGCM_debug_PopStack "IGCM_date_DaysInPreviousPeriod" 
     887} 
     888 
     889#D-#================================================================== 
     890#D-function IGCM_date_DaysInNextPeriod () 
     891#D-* Purpose: Give the numbers of days during the next prd1 period from grg1 date # OLD create_ts_next_date 
     892#D-* Usage: IGCM_date_DaysInNextPeriod grg1 prd1 
     893#D-         where grg1 gregorian date is in the form yyyymmdd 
     894#D-         where prd1 period is in the form N[Yy], N[Mm], N[Dd]. N integer 
     895#D- 
     896function IGCM_date_DaysInNextPeriod { 
     897  IGCM_debug_PushStack "IGCM_date_DaysInNextPeriod" $@ 
     898  typeset Length Period 
     899  Period=${2} 
     900  case ${Period} in 
     901  *Y|*y)  
     902    PeriodLengthInYears=$( echo ${Period} | awk -F '[yY]' '{print $1}' ) 
     903    IGCM_date_GetYearMonth ${1} year month 
     904    year=$( IGCM_date_SupressZeros ${year} ) 
     905    (( Length=0 )) 
     906    (( i=0 )) 
     907    until [ $i -ge $PeriodLengthInYears ] ; do 
     908      (( Length = Length + $( IGCM_date_DaysInYear $(( year + i + 1 )) ) ))  
     909      (( i=i+1 )) 
     910    done 
     911    ;; 
     912  *M|*m)  
     913    PeriodLengthInMonths=$( echo ${Period} | awk -F '[mM]' '{print $1}' ) 
     914    IGCM_date_GetYearMonth ${1} year month 
     915    year=$( IGCM_date_SupressZeros ${year} ) 
     916    (( year0 = year )) 
     917    if [ $(( month + 1 )) -lt 13 ] ; then 
     918      month0=$(( month + 1 )) 
     919    else 
     920      month0=$(( month + 1 - 12 )) 
     921      (( year = year0 + 1 )) 
     922    fi 
     923    (( Length=0 )) 
     924    (( i=0 )) 
     925    until [ $i -ge $PeriodLengthInMonths ] ; do 
     926      if [ $(( month0 + i )) -lt 13 ] ; then 
     927        (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month0 + i )) ) )) 
     928      else 
     929        (( year = year0 + 1 )) 
     930        (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month0 + i - 12 )) ) )) 
     931      fi 
     932      (( i=i+1 )) 
     933    done 
     934    ;; 
     935  *D|*d) 
     936    Length=$( echo ${Period} | sed -e "s/[dD]//" ) ;; 
     937  *) 
     938    IGCM_debug_Exit "IGCM_date_DaysInNextPeriod " ${Period} " invalid PeriodLength : choose in *Y, *M, *D." 
     939    IGCM_debug_Verif_Exit_Post ;; 
     940  esac 
     941  echo ${Length} 
     942 
     943  IGCM_debug_PopStack "IGCM_date_DaysInNextPeriod" 
     944} 
     945 
    795946 
    796947#D-#================================================================== 
     
    799950function IGCM_date_Check 
    800951{ 
    801     IGCM_debug_PushStack "IGCM_date_Check" 
     952  IGCM_debug_PushStack "IGCM_date_Check" 
    802953 
    803954#--------------------- 
    804     if [ ! -n "${libIGCM}" ] ; then 
    805         echo "Check libIGCM_date ...........................................[ FAILED ]" 
    806         echo "--Error--> libIGCM variable is not defined" 
    807         IGCM_debug_Exit "IGCM_date_Check" 
    808     fi 
     955  if [ ! -n "${libIGCM}" ] ; then 
     956    echo "Check libIGCM_date ...........................................[ FAILED ]" 
     957    echo "--Error--> libIGCM variable is not defined" 
     958    IGCM_debug_Exit "IGCM_date_Check" 
     959  fi 
    809960 
    810961#--------------------- 
    811     whence -v gawk > /dev/null 2>&1 
    812     if [ ! $? -eq 0 ] ; then 
    813         echo "Check libIGCM_date ...........................................[ FAILED ]" 
    814         echo "--Error--> gawk command is not defined" 
    815         IGCM_debug_Exit "IGCM_date_Check" 
    816     fi 
     962  whence -v gawk > /dev/null 2>&1 
     963  if [ ! $? -eq 0 ] ; then 
     964    echo "Check libIGCM_date ...........................................[ FAILED ]" 
     965    echo "--Error--> gawk command is not defined" 
     966    IGCM_debug_Exit "IGCM_date_Check" 
     967  fi 
    817968 
    818969#--------------------- 
    819     ${libIGCM}/libIGCM_date/IGCM_date_Test.ksh > IGCM_date_Test.ref.failed 2>&1 
    820      
    821     if diff IGCM_date_Test.ref.failed ${libIGCM}/libIGCM_date/IGCM_date_Test${dY}.ref > /dev/null 2>&1 ; then  
    822         echo "Check libIGCM_date ...............................................[ OK ]" 
    823         rm -f IGCM_date_Test.ref.failed 
    824     else  
    825         echo "Check libIGCM_date ...........................................[ FAILED ]" 
    826         echo "--Error--> Execution of ${libIGCM}/libIGCM_date/IGCM_date_Test.ksh" 
    827         echo "           has produced the file IGCM_date_Test.ref.failed" 
    828         echo "           Please analyse differences with the reference file by typing:" 
    829         echo "           diff IGCM_date_Test.ref.failed ${libIGCM}/libIGCM_date/IGCM_date_Test${dY}.ref" 
    830         echo "           Report errors to the author: Sebastien.Denvil@ipsl.jussieu.fr" 
    831         IGCM_debug_Exit "IGCM_date_Check" 
    832     fi 
     970  ${libIGCM}/libIGCM_date/IGCM_date_Test.ksh > IGCM_date_Test.ref.failed 2>&1 
     971   
     972  if diff IGCM_date_Test.ref.failed ${libIGCM}/libIGCM_date/IGCM_date_Test${dY}.ref > /dev/null 2>&1 ; then  
     973    echo "Check libIGCM_date ...............................................[ OK ]" 
     974    rm -f IGCM_date_Test.ref.failed 
     975  else  
     976    echo "Check libIGCM_date ...........................................[ FAILED ]" 
     977    echo "--Error--> Execution of ${libIGCM}/libIGCM_date/IGCM_date_Test.ksh" 
     978    echo "           has produced the file IGCM_date_Test.ref.failed" 
     979    echo "           Please analyse differences with the reference file by typing:" 
     980    echo "           diff IGCM_date_Test.ref.failed ${libIGCM}/libIGCM_date/IGCM_date_Test${dY}.ref" 
     981    echo "           Report errors to the author: Sebastien.Denvil@ipsl.jussieu.fr" 
     982    IGCM_debug_Exit "IGCM_date_Check" 
     983  fi 
    833984 
    834985#--------------------- 
    835     IGCM_debug_PopStack "IGCM_date_Check" 
     986  IGCM_debug_PopStack "IGCM_date_Check" 
    836987} 
    837988 
Note: See TracChangeset for help on using the changeset viewer.