- Timestamp:
- 10/17/12 12:43:43 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libIGCM/libIGCM_date/libIGCM_date.ksh
r673 r722 85 85 IGCM_debug_PushStack "IGCM_date_ConvertFormatToGregorian" $@ 86 86 87 # from a yyyy-mm-dd date format return 87 # from a yyyy-mm-dd date format return 88 88 # a yyymmdd date format 89 89 # usage IGCM_date_ConvertFormat yyyy-mm-dd 90 90 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 93 93 # piped in 94 94 typeset ymd … … 110 110 IGCM_debug_PushStack "IGCM_date_ConvertFormatToHuman" $@ 111 111 112 # from a yyyymmdd date format return 112 # from a yyyymmdd date format return 113 113 # a yyyy-mm-dd date format 114 114 # usage IGCM_date_ConvertFormat yyyymmdd 115 115 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 118 118 # piped in 119 119 typeset dt … … 137 137 IGCM_debug_PushStack "IGCM_date_GetYearMonth" $@ 138 138 139 # from a yyyymmdd date format return 139 # from a yyyymmdd date format return 140 140 # a yyyy year and mm month 141 141 # usage IGCM_date_GetYearMonth yyyymmdd year_var month_var 142 142 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 145 145 # piped in 146 146 typeset dt … … 166 166 IGCM_debug_PushStack "IGCM_date_GetYearMonthDay" $@ 167 167 168 # from a yyyymmdd date format return 168 # from a yyyymmdd date format return 169 169 # a yyyy year, mm month and dd day 170 170 # usage IGCM_date_GetYearMonthDay yyyymmdd year_var month_var day_var 171 171 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 174 174 # piped in 175 175 typeset dt … … 196 196 #D-* Purpose: Return the number of days in a year 197 197 #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, 199 199 #D- then assume that a yyyy is being piped in 200 200 #D- … … 237 237 typeset y a 238 238 239 # if there is no argument on the command line, 239 # if there is no argument on the command line, 240 240 # then assume that a yyyy is being piped in 241 241 if [ $# = 0 ] … … 277 277 return 278 278 fi 279 279 280 280 # if it is evenly divisible by 4 it must be a leap year 281 281 a=$(( $y % 4 )) … … 304 304 #D-#================================================================== 305 305 #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 307 307 #D-* Usage: IGCM_date_DaysInMonth yyyy mm 308 308 #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 310 310 #D- assume that a yyyymmdd is being piped in and read the value. 311 311 #D- if there is only one argument assume it is a yyyymmdd on the command line … … 315 315 # IGCM_debug_PushStack "IGCM_date_DaysInMonth" $@ 316 316 317 # calculates the number of days in a month 317 # calculates the number of days in a month 318 318 # usage IGCM_date_DaysInMonth yyyy mm 319 319 # or IGCM_date_DaysInMonth yyyymmdd 320 320 321 321 # What is the calendar : 322 322 if ( [ "${config_UserChoices_CalendarType}" = "360d" ] || [ "${config_UserChoices_CalendarType}" = "360_day" ] ) ; then … … 340 340 then 341 341 read ymd 342 elif [ $# = 1 ] 342 elif [ $# = 1 ] 343 343 then 344 344 ymd=$1 … … 353 353 # 30 days hath september etc. 354 354 case $m in 355 1|3|5|7|8|10|12) 355 1|3|5|7|8|10|12) 356 356 if [ X$3 = X ] ; then 357 357 echo 31 … … 360 360 fi 361 361 362 # 362 # IGCM_debug_PopStack "IGCM_date_DaysInMonth" 363 363 return ;; 364 4|6|9|11) 364 4|6|9|11) 365 365 if [ X$3 = X ] ; then 366 366 echo 30 … … 368 368 eval $3=30 > /dev/null 2>&1 369 369 fi 370 371 # 370 371 # IGCM_debug_PopStack "IGCM_date_DaysInMonth" 372 372 return ;; 373 373 *) ;; … … 379 379 IGCM_date_DaysInYear $y diy 380 380 case $diy in 381 365) 381 365) 382 382 if [ X$3 = X ] ; then 383 383 echo 28 … … 388 388 # IGCM_debug_PopStack "IGCM_date_DaysInMonth" 389 389 return ;; 390 366) 390 366) 391 391 if [ X$3 = X ] ; then 392 392 echo 29 … … 419 419 420 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 421 # is coming in on a pipe and use read to collect it 422 422 if [ $# = 0 ] 423 423 then … … 456 456 #D-* Purpose: Convert yyyyddd to yyyymmdd 457 457 #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 459 459 #D- piped in and read it 460 460 #D- … … 468 468 typeset dt y m d grg 469 469 470 # if there is no command line argument, assume one is being 470 # if there is no command line argument, assume one is being 471 471 # piped in and read it 472 472 if [ X$1 = X ] … … 476 476 dt=$1 477 477 fi 478 478 479 479 # break apart the year and the days 480 480 y=$(( $dt / 1000 )) 481 481 d=$(( $dt % 1000 )) 482 482 483 483 # subtract the number of days in each month starting from 1 484 484 # from the days in the date. When the day goes below 1, you … … 543 543 IGCM_date_DaysInYear $y diy 544 544 545 # If the calculated day exceeds the days in the year, 545 # If the calculated day exceeds the days in the year, 546 546 # add one year to the year and subtract the days in the year from the 547 547 # calculated days. Extract the days in the new year and repeat … … 604 604 tmp=$( IGCM_date_AddDaysToJulianDate $tmp $dif ) 605 605 res=$( IGCM_date_ConvertJulianDateToGregorian $tmp ) 606 606 607 607 echo $res 608 608 … … 612 612 #D-#================================================================== 613 613 #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 616 616 #D-* Usage: IGCM_date_DaysBetweenJulianDate jul1 jul2 617 617 #D- where julian date is in the form yyyyddd … … 621 621 IGCM_debug_PushStack "IGCM_date_DaysBetweenJulianDate" $@ 622 622 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 625 625 # usage IGCM_date_DaysBetweenJulianDate jul1 jul2 626 626 # where julian date is in the form yyyyddd 627 627 628 628 usage () { 629 629 echo "Usage:" … … 634 634 echo " where a julian date is in the form of yyyyddd." 635 635 } 636 636 637 637 if [ $# -lt 2 ]; then 638 638 usage 639 639 IGCM_debug_Exit "IGCM_date_DaysBetweenJulianDate" 640 640 fi 641 641 642 642 # This process subtracts arg2 from arg1. If arg2 is larger 643 643 # then reverse the arguments. The calculations are done, and … … 668 668 # Then add days in year until year2 matches year1 669 669 case ${config_UserChoices_CalendarType} in 670 360d|360_day) 670 360d|360_day) 671 671 res=$(( ( ( $yyyy1 - $yyyy2 ) * 360 ) + $res )) ;; 672 672 noleap|365_day) … … 685 685 686 686 687 # if argument 2 was larger than argument 1 then 687 # if argument 2 was larger than argument 1 then 688 688 # the arguments were reversed before calculating 689 689 # adjust by reversing the sign … … 701 701 #D-#================================================================== 702 702 #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 705 705 #D-* Usage: IGCM_date_DaysBetweenGregorianDate grg1 grg2 706 706 #D- where gregorian date is in the form yyyymmdd … … 710 710 IGCM_debug_PushStack "IGCM_date_DaysBetweenGregorianDate" $@ 711 711 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 714 714 # usage IGCM_date_DaysBetweenGregorianDate grg1 grg2 715 715 # where gregorian date is in the form yyyymmdd … … 775 775 IGCM_debug_Exit "IGCM_date_DaysSinceJC" 776 776 fi 777 777 778 778 typeset aux num 779 779 780 780 if [ ${1} -lt 5000000 ]; then 781 781 case ${config_UserChoices_CalendarType} in 782 360d|360_day) 782 360d|360_day) 783 783 aux=-360;; 784 784 noleap|365_day) 785 785 aux=-365;; 786 all_leap|366_day) 786 all_leap|366_day) 787 787 aux=-366;; 788 788 leap|gregorian|standard) … … 794 794 # which is number of days since JC and 10000101 795 795 case ${config_UserChoices_CalendarType} in 796 360d|360_day) 796 360d|360_day) 797 797 aux=359640;; 798 798 noleap|365_day) 799 799 aux=364635;; 800 all_leap|366_day) 800 all_leap|366_day) 801 801 aux=365634;; 802 802 leap|gregorian|standard) … … 808 808 # which is number of days since JC and 19000101 809 809 case ${config_UserChoices_CalendarType} in 810 360d|360_day) 810 360d|360_day) 811 811 aux=683640;; 812 812 noleap|365_day) 813 813 aux=693135;; 814 all_leap|366_day) 814 all_leap|366_day) 815 815 aux=695034;; 816 816 leap|gregorian|standard) … … 844 844 (( year = year - PeriodLengthInYears + 1)) 845 845 fi 846 (( Length=0 ))847 (( i=0 ))846 Length=0 847 i=0 848 848 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 )) 851 851 done 852 852 ;; … … 857 857 if [ X${3} = Xend ] ; then 858 858 (( month = month - PeriodLengthInMonths + 1 )) 859 fi 860 (( year0 = year ))859 fi 860 year0=year 861 861 if [ $month -le 0 ] ; then 862 862 (( month = month + 12 )) … … 864 864 fi 865 865 month=$( printf "%02i\n" ${month} ) 866 (( Length=0 ))867 (( i=0 ))866 Length=0 867 i=0 868 868 until [ $i -ge $PeriodLengthInMonths ] ; do 869 869 if [ $(( month + i )) -lt 13 ] ; then 870 870 (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i )) ) )) 871 871 else 872 873 872 (( year = year0 + 1 )) 873 (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i - 12 )) ) )) 874 874 fi 875 (( i =i+1 ))875 (( i = i + 1 )) 876 876 done 877 877 ;; … … 899 899 Period=${2} 900 900 case ${Period} in 901 *Y|*y) 901 *Y|*y) 902 902 PeriodLengthInYears=$( echo ${Period} | awk -F '[yY]' '{print $1}' ) 903 903 IGCM_date_GetYearMonth ${1} year month 904 904 year=$( IGCM_date_SupressZeros ${year} ) 905 (( Length=0 ))906 (( i=0 ))905 Length=0 906 i=0 907 907 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 )) 910 910 done 911 911 ;; 912 *M|*m) 912 *M|*m) 913 913 PeriodLengthInMonths=$( echo ${Period} | awk -F '[mM]' '{print $1}' ) 914 914 IGCM_date_GetYearMonth ${1} year month 915 915 year=$( IGCM_date_SupressZeros ${year} ) 916 (( year0 = year ))916 year0=year 917 917 if [ $(( month + 1 )) -lt 13 ] ; then 918 918 month0=$(( month + 1 )) … … 921 921 (( year = year0 + 1 )) 922 922 fi 923 (( Length=0 ))924 (( i=0 ))923 Length=0 924 i=0 925 925 until [ $i -ge $PeriodLengthInMonths ] ; do 926 926 if [ $(( month0 + i )) -lt 13 ] ; then 927 927 (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month0 + i )) ) )) 928 928 else 929 930 929 (( year = year0 + 1 )) 930 (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month0 + i - 12 )) ) )) 931 931 fi 932 (( i =i+1 ))932 (( i = i + 1 )) 933 933 done 934 934 ;; … … 946 946 #D-#================================================================== 947 947 #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 949 949 #D-* Usage: IGCM_date_DaysInCurrentPeriod grg1 prd1 950 950 #D- where grg1 gregorian date is in the form yyyymmdd … … 953 953 function IGCM_date_DaysInCurrentPeriod { 954 954 IGCM_debug_PushStack "IGCM_date_DaysInCurrentPeriod" $@ 955 typeset Length Period 955 typeset Length Period 956 956 Period=${2} 957 957 case ${Period} in 958 *Y|*y) 958 *Y|*y) 959 959 PeriodLengthInYears=$( echo ${Period} | awk -F '[yY]' '{print $1}' ) 960 960 IGCM_date_GetYearMonth ${1} year month 961 961 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 964 970 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 )) 967 973 done 968 974 ;; 969 *M|*m) 975 *M|*m) 970 976 PeriodLengthInMonths=$( echo ${Period} | awk -F '[mM]' '{print $1}' ) 971 977 IGCM_date_GetYearMonth ${1} year month 972 978 year=$( IGCM_date_SupressZeros ${year} ) 973 (( year0 = year ))974 (( Length=0 ))975 (( i=0 ))979 year0=year 980 Length=0 981 i=0 976 982 until [ $i -ge $PeriodLengthInMonths ] ; do 977 983 if [ $(( month + i )) -lt 13 ] ; then 978 984 (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i )) ) )) 979 985 else 980 981 986 (( year = year0 + 1 )) 987 (( Length = Length + $( IGCM_date_DaysInMonth $year $(( month + i - 12 )) ) )) 982 988 fi 983 (( i =i+1 ))989 (( i = i + 1 )) 984 990 done 985 991 ;; … … 1019 1025 #--------------------- 1020 1026 ${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 1023 1029 echo "Check libIGCM_date ...............................................[ OK ]" 1024 1030 rm -f IGCM_date_Test.ref.failed 1025 else 1031 else 1026 1032 echo "Check libIGCM_date ...........................................[ FAILED ]" 1027 1033 echo "--Error--> Execution of ${libIGCM}/libIGCM_date/IGCM_date_Test.ksh"
Note: See TracChangeset
for help on using the changeset viewer.