Changeset 919


Ignore:
Timestamp:
08/13/13 14:29:16 (11 years ago)
Author:
sdipsl
Message:

Bugfix IGCM_date_DaysIn*Period. See #159

File:
1 edited

Legend:

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

    r889 r919  
    838838  IGCM_debug_PushStack "IGCM_date_DaysInPreviousPeriod" $@ 
    839839 
    840   typeset Length Period PeriodLengthInYears PeriodLengthInMonths year0 i 
     840  typeset Length Period treatedYear PeriodLengthInYears PeriodLengthInMonths year0 i 
    841841 
    842842  Period=${2} 
     
    869869    fi 
    870870    month=$( printf "%02i\n" ${month} ) 
     871    treatedYear=0 
    871872    Length=0 
    872873    i=0 
    873     until [ $i -ge $PeriodLengthInMonths ] ; do 
    874       if [ $(( month + i )) -lt 13 ] ; then 
    875         (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i )) ) )) 
    876       else 
     874    for ((i = 0; i < ${PeriodLengthInMonths}; i += 1)) ; do 
     875 
     876      (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i - 12 * treatedYear )) ) )) 
     877 
     878      if [ $(( month + i )) -ge $(( 12 * (treatedYear + 1) )) ] ; then 
    877879        (( year = year0 + 1 )) 
    878         (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i - 12 )) ) )) 
     880        (( treatedYear = treatedYear + 1 )) 
    879881      fi 
    880       (( i = i + 1 )) 
    881882    done 
    882883    ;; 
     
    902903  IGCM_debug_PushStack "IGCM_date_DaysInNextPeriod" $@ 
    903904 
    904   typeset Length Period PeriodLengthInYears PeriodLengthInMonths year0 month0 i 
     905  typeset Length Period treatedYear PeriodLengthInYears PeriodLengthInMonths year0 month0 i 
    905906 
    906907  Period=${2} 
     
    928929      (( year = year0 + 1 )) 
    929930    fi 
     931    treatedYear=0 
    930932    Length=0 
    931933    i=0 
    932     until [ $i -ge $PeriodLengthInMonths ] ; do 
    933       if [ $(( month0 + i )) -lt 13 ] ; then 
    934         (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month0 + i )) ) )) 
    935       else 
     934    for ((i = 0; i < ${PeriodLengthInMonths}; i += 1)) ; do 
     935 
     936      (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month0 + i - 12 * treatedYear )) ) )) 
     937 
     938      if [ $(( month0 + i )) -ge $(( 12 * (treatedYear + 1) )) ] ; then 
    936939        (( year = year0 + 1 )) 
    937         (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month0 + i - 12 )) ) )) 
     940        (( treatedYear = treatedYear + 1 )) 
    938941      fi 
    939       (( i = i + 1 )) 
    940942    done 
    941943    ;; 
     
    961963  IGCM_debug_PushStack "IGCM_date_DaysInCurrentPeriod" $@ 
    962964 
    963   typeset Length Period PeriodLengthInYears PeriodLengthInMonths year0 i 
     965  set -vx 
     966 
     967  typeset Length Period treatedYear PeriodLengthInYears PeriodLengthInMonths year0 i 
    964968 
    965969  Period=${2} 
     
    987991    year=$( IGCM_date_SupressZeros ${year} ) 
    988992    year0=year 
     993    treatedYear=0 
    989994    Length=0 
    990995    i=0 
    991     until [ $i -ge $PeriodLengthInMonths ] ; do 
    992       if [ $(( month + i )) -lt 13 ] ; then 
    993         (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i )) ) )) 
    994       else 
     996    for ((i = 0; i < ${PeriodLengthInMonths}; i += 1)) ; do 
     997 
     998      (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i - 12 * treatedYear )) ) )) 
     999 
     1000      if [ $(( month + i )) -ge $(( 12 * (treatedYear + 1) )) ] ; then 
    9951001        (( year = year0 + 1 )) 
    996         (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i - 12 )) ) )) 
     1002        (( treatedYear = treatedYear + 1 )) 
    9971003      fi 
    998       (( i = i + 1 )) 
    9991004    done 
    10001005    ;; 
     
    10071012  echo ${Length} 
    10081013 
     1014  set +vx 
     1015 
    10091016  IGCM_debug_PopStack "IGCM_date_DaysInCurrentPeriod" 
    10101017} 
Note: See TracChangeset for help on using the changeset viewer.