- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libIGCM/libIGCM_date/libIGCM_date.ksh
r23 r7 153 153 function IGCM_date_DaysInYear 154 154 { 155 #IGCM_debug_PushStack "IGCM_date_DaysInYear" $@155 IGCM_debug_PushStack "IGCM_date_DaysInYear" $@ 156 156 # return the number of days in a year 157 157 # usage IGCM_date_DaysInYear yyyy … … 159 159 # What is the calendar : 160 160 if [ "${config_UserChoices_CalendarType}" = "360d" ] ; then 161 if [ X$2 = X ] ; then 162 echo 360 163 else 164 eval $2=360 > /dev/null 2>&1 165 fi 166 # IGCM_debug_PopStack "IGCM_date_DaysInYear" 161 echo 360 162 IGCM_debug_PopStack "IGCM_date_DaysInYear" 167 163 return 168 164 else 169 165 if [ "${config_UserChoices_CalendarType}" = "noleap" ] ; then 170 if [ X$2 = X ] ; then 171 echo 365 172 else 173 eval $2=365 > /dev/null 2>&1 174 fi 175 176 # IGCM_debug_PopStack "IGCM_date_DaysInYear" 166 echo 365 167 IGCM_debug_PopStack "IGCM_date_DaysInYear" 177 168 return 178 169 fi 179 170 fi 180 181 typeset y a182 171 183 172 # if there is no argument on the command line, … … 195 184 196 185 # if it is evenly divisible by 400 it must be a leap year 197 a=$( ( $y % 400 ))186 a=$( expr $y \% 400 ) 198 187 if [ $a = 0 ] 199 188 then 200 if [ X$2 = X ] ; then 201 echo 366 202 else 203 eval $2=366 > /dev/null 2>&1 204 fi 205 206 # IGCM_debug_PopStack "IGCM_date_DaysInYear" 189 echo 366 190 IGCM_debug_PopStack "IGCM_date_DaysInYear" 207 191 return 208 192 fi 209 193 210 194 #if it is evenly divisible by 100 it must not be a leap year 211 a=$( ( $y % 100 ))195 a=$( expr $y \% 100 ) 212 196 if [ $a = 0 ] 213 197 then 214 if [ X$2 = X ] ; then 215 echo 365 216 else 217 eval $2=365 > /dev/null 2>&1 218 fi 219 220 # IGCM_debug_PopStack "IGCM_date_DaysInYear" 198 echo 365 199 IGCM_debug_PopStack "IGCM_date_DaysInYear" 221 200 return 222 201 fi 223 202 224 203 # if it is evenly divisible by 4 it must be a leap year 225 a=$( ( $y % 4 ))204 a=$( expr $y \% 4 ) 226 205 if [ $a = 0 ] 227 206 then 228 if [ X$2 = X ] ; then 229 echo 366 230 else 231 eval $2=366 > /dev/null 2>&1 232 fi 233 234 # IGCM_debug_PopStack "IGCM_date_DaysInYear" 207 echo 366 208 IGCM_debug_PopStack "IGCM_date_DaysInYear" 235 209 return 236 210 fi 237 211 238 212 # otherwise it is not a leap year 239 if [ X$2 = X ] ; then 240 echo 365 241 else 242 eval $2=365 > /dev/null 2>&1 243 fi 244 245 # IGCM_debug_PopStack "IGCM_date_DaysInYear" 213 echo 365 214 215 IGCM_debug_PopStack "IGCM_date_DaysInYear" 246 216 } 247 217 … … 257 227 function IGCM_date_DaysInMonth 258 228 { 259 #IGCM_debug_PushStack "IGCM_date_DaysInMonth" $@229 IGCM_debug_PushStack "IGCM_date_DaysInMonth" $@ 260 230 261 231 # calculates the number of days in a month 262 232 # usage IGCM_date_DaysInMonth yyyy mm 263 233 # or IGCM_date_DaysInMonth yyyymmdd 264 234 265 235 # What is the calendar : 266 236 if [ "${config_UserChoices_CalendarType}" = "360d" ] ; then 267 if [ X$3 = X ] ; then 268 echo 30 269 else 270 eval $3=30 > /dev/null 2>&1 271 fi 272 273 # IGCM_debug_PopStack "IGCM_date_DaysInMonth" 237 echo 30 238 IGCM_debug_PopStack "IGCM_date_DaysInMonth" 274 239 return 275 240 fi 276 277 typeset ymd y m diy278 241 279 242 # if there are no command line arguments then assume that a yyyymmdd is being … … 288 251 ymd=$1 289 252 else 290 ymd=$( ( ( $1 * 10000 ) + ( $2 * 100 ) + 1 ))253 ymd=$( expr \( \( $1 \* 10000 \) \+ \( $2 \* 100 \) \+ 1 \) ) 291 254 fi 292 255 293 256 # extract the year and the month 294 y=$( ( $ymd / 10000 )) ;295 m=$( ( ( $ymd % 10000 ) / 100 )) ;257 y=$( expr $ymd / 10000 ) ; 258 m=$( expr \( $ymd \% 10000 \) / 100 ) ; 296 259 297 260 # 30 days hath september etc. 298 261 case $m in 299 262 1|3|5|7|8|10|12) 300 if [ X$3 = X ] ; then 301 echo 31 302 else 303 eval $3=31 > /dev/null 2>&1 304 fi 305 306 # IGCM_debug_PopStack "IGCM_date_DaysInMonth" 263 echo 31 264 IGCM_debug_PopStack "IGCM_date_DaysInMonth" 307 265 return ;; 308 266 4|6|9|11) 309 if [ X$3 = X ] ; then 310 echo 30 311 else 312 eval $3=30 > /dev/null 2>&1 313 fi 314 315 # IGCM_debug_PopStack "IGCM_date_DaysInMonth" 267 echo 30 268 IGCM_debug_PopStack "IGCM_date_DaysInMonth" 316 269 return ;; 317 270 *) ;; … … 321 274 # Use IGCM_date_DaysInYear to get the number of days in the year and return a value 322 275 # accordingly. 323 IGCM_date_DaysInYear $y diy276 diy=$( IGCM_date_DaysInYear $y ) 324 277 case $diy in 325 278 365) 326 if [ X$3 = X ] ; then 327 echo 28 328 else 329 eval $3=28 > /dev/null 2>&1 330 fi 331 332 # IGCM_debug_PopStack "IGCM_date_DaysInMonth" 279 echo 28 280 IGCM_debug_PopStack "IGCM_date_DaysInMonth" 333 281 return ;; 334 282 366) 335 if [ X$3 = X ] ; then 336 echo 29 337 else 338 eval $3=29 > /dev/null 2>&1 339 fi 340 341 # IGCM_debug_PopStack "IGCM_date_DaysInMonth" 283 echo 29 284 IGCM_debug_PopStack "IGCM_date_DaysInMonth" 342 285 return ;; 343 286 esac 344 287 345 #IGCM_debug_PopStack "IGCM_date_DaysInMonth"288 IGCM_debug_PopStack "IGCM_date_DaysInMonth" 346 289 } 347 290 … … 360 303 # usage IGCM_date_ConvertGregorianDateToJulian 19980429 361 304 362 typeset dt y m d x jul363 364 305 # if there is no command line argument, then assume that the date 365 306 # is coming in on a pipe and use read to collect it … … 372 313 373 314 # break the yyyymmdd into separate parts for year, month and day 374 y=$( ( $dt / 10000 ))375 m=$( ( ( $dt % 10000 ) / 100 ))376 d=$( ( ( $dt % 100 ) ))315 y=$( expr $dt / 10000 ) 316 m=$( expr \( $dt \% 10000 \) / 100 ) 317 d=$( expr \( $dt \% 100 \) ) 377 318 378 319 # add the days in each month up to (but not including the month itself) … … 382 323 # and add them to 14. 383 324 x=1 384 while [ $ x -lt $m]325 while [ $( expr $x \< $m ) = 1 ] 385 326 do 386 IGCM_date_DaysInMonth $y $x md387 d=$( ( $d + $md ))388 x=$( ( $x + 1 ))327 md=$( IGCM_date_DaysInMonth $y $x ) 328 d=$( expr \( $d \+ $md \) ) 329 x=$( expr \( $x \+ 1 \) ) 389 330 done 390 331 391 332 # combine the year and day back together again and you have the julian date. 392 jul=$( ( ( $y * 1000 ) + $d ))333 jul=$( expr \( $y \* 1000 \) + $d ) 393 334 echo $jul 394 335 … … 410 351 # usage IGCM_date_ConvertJulianDateToGregorian 1998213 411 352 412 typeset dt y m d md grg413 414 353 # if there is no command line argument, assume one is being 415 354 # piped in and read it … … 422 361 423 362 # break apart the year and the days 424 y=$( ( $dt / 1000 ))425 d=$( ( $dt % 1000 ))363 y=$( expr $dt / 1000 ) 364 d=$( expr $dt \% 1000 ) 426 365 427 366 # subtract the number of days in each month starting from 1 … … 430 369 # month to get the correct day of the month 431 370 m=1 432 while [ $ d -gt 0]371 while [ $( expr $d \> 0 ) = 1 ] 433 372 do 434 IGCM_date_DaysInMonth $y $m md435 d=$( ( $d - $md ))436 m=$( ( $m + 1 ))373 md=$( IGCM_date_DaysInMonth $y $m ) 374 d=$( expr $d \- $md ) 375 m=$( expr $m \+ 1 ) 437 376 done 438 377 439 d=$( ( $d + $md ))378 d=$( expr $d \+ $md ) 440 379 441 380 # the loop steps one past the correct month, so back up the month 442 m=$( ( $m - 1 ))381 m=$( expr $m \- 1 ) 443 382 444 383 # assemble the results into a gregorian date 445 grg=$( ( ( $y * 10000 ) + ( $m * 100 ) + $d ))384 grg=$( expr \( $y \* 10000 \) \+ \( $m \* 100 \) \+ $d ) 446 385 echo $( IGCM_date_GregorianDigit $grg ) 447 386 … … 463 402 # usage IGCM_date_AddDaysToJulianDate 1998312 { ,-}14 464 403 465 typeset dif yd d y diy466 467 404 # Read the difference from the command lines 468 405 # and the date from the command line, or standard input … … 477 414 478 415 # Break it into pieces 479 d=$( ( $yd % 1000 ))480 y=$( ( $yd / 1000 ))416 d=$( expr $yd \% 1000 ) 417 y=$( expr $yd / 1000 ) 481 418 482 419 # Add the number of days (if days is negative this results is 483 420 # a subtraction) 484 d=$( ( $d + $dif ))421 d=$( expr $d \+ $dif ) 485 422 486 423 # Extract the days in the year 487 IGCM_date_DaysInYear $y diy424 diy=$( IGCM_date_DaysInYear $y ) 488 425 489 426 # If the calculated day exceeds the days in the year, … … 492 429 # test until you end up with a day number that falls within the 493 430 # days of the year 494 while [ $ d -gt $diy]431 while [ $( expr $d \> $diy ) = 1 ] 495 432 do 496 d=$( ( $d - $diy ))497 y=$( ( $y + 1 ))498 IGCM_date_DaysInYear $y diy433 d=$( expr $d - $diy ) 434 y=$( expr $y \+ 1 ) 435 diy=$( IGCM_date_DaysInYear $y ) 499 436 done 500 437 … … 504 441 # loop on this test until you end up with a number that 505 442 # falls within the days of the year 506 while [ $ d -lt1 ]443 while [ $( expr $d \< 1 ) = 1 ] 507 444 do 508 y=$( ( $y - 1 ))509 IGCM_date_DaysInYear $y diy510 d=$( ( $d + $diy ))445 y=$( expr $y - 1 ) 446 diy=$( IGCM_date_DaysInYear $y ) 447 d=$( expr $d \+ $diy ) 511 448 done 512 449 513 450 # put the year and day back together and echo the result 514 yd=$( ( ( $y * 1000 ) + $d ))451 yd=$( expr \( $y \* 1000 \) + $d ) 515 452 516 453 echo $yd … … 602 539 603 540 # Break the dates in to year and day portions 604 yyyy1=$( ( $jul1 / 1000 ))605 yyyy2=$( ( $jul2 / 1000 ))606 ddd1=$( ( $jul1 % 1000 ))607 ddd2=$( ( $jul2 % 1000 ))541 yyyy1=$( expr $jul1 / 1000 ) 542 yyyy2=$( expr $jul2 / 1000 ) 543 ddd1=$( expr $jul1 \% 1000 ) 544 ddd2=$( expr $jul2 \% 1000 ) 608 545 609 546 # Subtract days 610 res=$( ( $ddd1 - $ddd2 ))547 res=$( expr $ddd1 - $ddd2 ) 611 548 612 549 # Then add days in year until year2 matches year1 613 550 614 551 if [ "${config_UserChoices_CalendarType}" = "360d" ] ; then 615 res=$( ( ( ( $yyyy1 - $yyyy2 ) * 360 ) + $res ))552 res=$( expr \( \( $yyyy1 \- $yyyy2 \) \* 360 \) \+ $res ) 616 553 elif [ "${config_UserChoices_CalendarType}" = "noleap" ] ; then 617 res=$( ( ( ( $yyyy1 - $yyyy2 ) * 365 ) + $res ))554 res=$( expr \( \( $yyyy1 \- $yyyy2 \) \* 365 \) \+ $res ) 618 555 elif ( [ "${config_UserChoices_CalendarType}" = "leap" ] || [ "${config_UserChoices_CalendarType}" = "gregorian" ] ) ; then 619 556 while [ $yyyy2 -lt $yyyy1 ] 620 557 do 621 IGCM_date_DaysInYear $yyyy2 diy622 res=$( ( $res + $diy ))623 yyyy2=$( ( $yyyy2 + 1 ))558 diy=$( IGCM_date_DaysInYear $yyyy2 ) 559 res=$( expr $res + $diy ) 560 yyyy2=$( expr $yyyy2 + 1 ) 624 561 done 625 562 fi … … 630 567 if [ $1 -lt $2 ] 631 568 then 632 res=$( ( $res * -1 ))569 res=$( expr $res \* -1 ) 633 570 fi 634 571 … … 753 690 num=19000101 754 691 fi 755 echo $( ( $( IGCM_date_DaysBetweenGregorianDate $1 ${num} ) + $aux ))692 echo $( expr \( $( IGCM_date_DaysBetweenGregorianDate $1 ${num} ) \+ $aux \) ) 756 693 757 694 IGCM_debug_PopStack "IGCM_date_DaysSinceJC"
Note: See TracChangeset
for help on using the changeset viewer.