Changeset 23
- Timestamp:
- 10/28/08 18:42:58 (15 years ago)
- Location:
- trunk/libIGCM
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libIGCM/libIGCM_card/IGCM_card_Test.ksh
r5 r23 82 82 83 83 diff ${libIGCM}/libIGCM_card/TestFile.card NewTestFile.card 84 rm -f NewTestFile.card 84 rm -f NewTestFile.card NewTestFile.card.bak 85 85 -
trunk/libIGCM/libIGCM_card/IGCM_card_WriteOption.awk
r5 r23 102 102 END { 103 103 104 if (! exit_value ) {104 if (! exit_value ) { 105 105 106 myprint("###############################") 107 myprint("section ====> " section) 108 myprint("option ====> " option) 109 myprint("value ====> " value) 106 myprint("###############################") 107 myprint("section ====> " section) 108 myprint("option ====> " option) 109 myprint("value ====> " value) 110 111 if (section_found == 0) { 112 print "Error: Section not found", section, option 113 } else if (option_found == 0) { 114 print "Error: Option not found", section, option 115 } 116 117 } else { 110 118 111 if (section_found == 0) { 112 print "Error: Section not found" 113 } else if (option_found == 0) { 114 print "Error: Option not found" 115 } 119 print "Error in with IGCM_WriteOption : ", section, option 116 120 117 }121 } 118 122 119 123 } -
trunk/libIGCM/libIGCM_card/libIGCM_card.ksh
r5 r23 167 167 #D-#================================================================== 168 168 #D-function IGCM_card_WriteOption 169 #D-* Purpose: Write an option froma given file.card and section169 #D-* Purpose: Write an option in a given file.card and section 170 170 #D-* Usage: IGCM_card_WriteOption file.card section newvalue 171 171 #D-* Examples: IGCM_card_WriteOption file.card Recipes Red 150 … … 181 181 typeset tmpfile=tmpfile_$$ 182 182 ( awk -f ${libIGCM}/libIGCM_card/IGCM_card_WriteOption.awk -- "$@" 2> /dev/null ) > ${tmpfile} 183 cp $1 $1.bak 183 184 mv ${tmpfile} $1 184 185 else … … 188 189 fi 189 190 IGCM_debug_PopStack "IGCM_card_WriteOption" 191 } 192 193 #D-#================================================================== 194 #D-function IGCM_card_WriteArrayOption 195 #D-* Purpose: Write an array option a given file.card and section 196 #D-* Usage: IGCM_card_WriteArrayOption file.card section option newarray 197 #D-* Examples: set -A MyArray -- 1 2 3 198 #D- IGCM_card_WriteArrayOption file.card Recipes List MyArray 199 #D- 200 function IGCM_card_WriteArrayOption 201 { 202 IGCM_debug_PushStack "IGCM_card_WriteArrayOption" $@ 203 204 if [ -r "$1" ] && [ -w "$1" ] ; then 205 typeset tmpfile=tmpfile_$$ 206 if [ X"${4}" != X"" ]; then 207 tab=$4 208 IGCM_card_WriteOption $1 $2 $3 '('$( eval echo \${${tab}[@]} | sed -e 's/ /,/g' )')' 209 else 210 IGCM_card_WriteOption $1 $2 $3 '()' 211 fi 212 else 213 echo "--Error--> IGCM_card_WriteArrayOption $@" 214 echo " $1 is not readable or not writable" 215 IGCM_debug_Exit "IGCM_card_WriteArrayOption" 216 fi 217 IGCM_debug_PopStack "IGCM_card_WriteArrayOption" 190 218 } 191 219 -
trunk/libIGCM/libIGCM_date/libIGCM_date.ksh
r7 r23 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 echo 360 162 IGCM_debug_PopStack "IGCM_date_DaysInYear" 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" 163 167 return 164 168 else 165 169 if [ "${config_UserChoices_CalendarType}" = "noleap" ] ; then 166 echo 365 167 IGCM_debug_PopStack "IGCM_date_DaysInYear" 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" 168 177 return 169 178 fi 170 179 fi 180 181 typeset y a 171 182 172 183 # if there is no argument on the command line, … … 184 195 185 196 # if it is evenly divisible by 400 it must be a leap year 186 a=$( expr $y \% 400)197 a=$(( $y % 400 )) 187 198 if [ $a = 0 ] 188 199 then 189 echo 366 190 IGCM_debug_PopStack "IGCM_date_DaysInYear" 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" 191 207 return 192 208 fi 193 209 194 210 #if it is evenly divisible by 100 it must not be a leap year 195 a=$( expr $y \% 100)211 a=$(( $y % 100 )) 196 212 if [ $a = 0 ] 197 213 then 198 echo 365 199 IGCM_debug_PopStack "IGCM_date_DaysInYear" 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" 200 221 return 201 222 fi 202 223 203 224 # if it is evenly divisible by 4 it must be a leap year 204 a=$( expr $y \% 4)225 a=$(( $y % 4 )) 205 226 if [ $a = 0 ] 206 227 then 207 echo 366 208 IGCM_debug_PopStack "IGCM_date_DaysInYear" 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" 209 235 return 210 236 fi 211 237 212 238 # otherwise it is not a leap year 213 echo 365 214 215 IGCM_debug_PopStack "IGCM_date_DaysInYear" 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" 216 246 } 217 247 … … 227 257 function IGCM_date_DaysInMonth 228 258 { 229 IGCM_debug_PushStack "IGCM_date_DaysInMonth" $@259 # IGCM_debug_PushStack "IGCM_date_DaysInMonth" $@ 230 260 231 261 # calculates the number of days in a month 232 262 # usage IGCM_date_DaysInMonth yyyy mm 233 263 # or IGCM_date_DaysInMonth yyyymmdd 234 264 235 265 # What is the calendar : 236 266 if [ "${config_UserChoices_CalendarType}" = "360d" ] ; then 237 echo 30 238 IGCM_debug_PopStack "IGCM_date_DaysInMonth" 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" 239 274 return 240 275 fi 276 277 typeset ymd y m diy 241 278 242 279 # if there are no command line arguments then assume that a yyyymmdd is being … … 251 288 ymd=$1 252 289 else 253 ymd=$( expr \( \( $1 \* 10000 \) \+ \( $2 \* 100 \) \+ 1 \))290 ymd=$(( ( $1 * 10000 ) + ( $2 * 100 ) + 1 )) 254 291 fi 255 292 256 293 # extract the year and the month 257 y=$( expr $ymd / 10000) ;258 m=$( expr \( $ymd \% 10000 \) / 100) ;294 y=$(( $ymd / 10000 )) ; 295 m=$(( ( $ymd % 10000 ) / 100 )) ; 259 296 260 297 # 30 days hath september etc. 261 298 case $m in 262 299 1|3|5|7|8|10|12) 263 echo 31 264 IGCM_debug_PopStack "IGCM_date_DaysInMonth" 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" 265 307 return ;; 266 308 4|6|9|11) 267 echo 30 268 IGCM_debug_PopStack "IGCM_date_DaysInMonth" 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" 269 316 return ;; 270 317 *) ;; … … 274 321 # Use IGCM_date_DaysInYear to get the number of days in the year and return a value 275 322 # accordingly. 276 diy=$( IGCM_date_DaysInYear $y )323 IGCM_date_DaysInYear $y diy 277 324 case $diy in 278 325 365) 279 echo 28 280 IGCM_debug_PopStack "IGCM_date_DaysInMonth" 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" 281 333 return ;; 282 334 366) 283 echo 29 284 IGCM_debug_PopStack "IGCM_date_DaysInMonth" 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" 285 342 return ;; 286 343 esac 287 344 288 IGCM_debug_PopStack "IGCM_date_DaysInMonth"345 # IGCM_debug_PopStack "IGCM_date_DaysInMonth" 289 346 } 290 347 … … 303 360 # usage IGCM_date_ConvertGregorianDateToJulian 19980429 304 361 362 typeset dt y m d x jul 363 305 364 # if there is no command line argument, then assume that the date 306 365 # is coming in on a pipe and use read to collect it … … 313 372 314 373 # break the yyyymmdd into separate parts for year, month and day 315 y=$( expr $dt / 10000)316 m=$( expr \( $dt \% 10000 \) / 100)317 d=$( expr \( $dt \% 100 \))374 y=$(( $dt / 10000 )) 375 m=$(( ( $dt % 10000 ) / 100 )) 376 d=$(( ( $dt % 100 ) )) 318 377 319 378 # add the days in each month up to (but not including the month itself) … … 323 382 # and add them to 14. 324 383 x=1 325 while [ $ ( expr $x \< $m ) = 1]384 while [ $x -lt $m ] 326 385 do 327 md=$( IGCM_date_DaysInMonth $y $x )328 d=$( expr \( $d \+ $md \))329 x=$( expr \( $x \+ 1 \))386 IGCM_date_DaysInMonth $y $x md 387 d=$(( $d + $md )) 388 x=$(( $x + 1 )) 330 389 done 331 390 332 391 # combine the year and day back together again and you have the julian date. 333 jul=$( expr \( $y \* 1000 \) + $d)392 jul=$(( ( $y * 1000 ) + $d )) 334 393 echo $jul 335 394 … … 351 410 # usage IGCM_date_ConvertJulianDateToGregorian 1998213 352 411 412 typeset dt y m d md grg 413 353 414 # if there is no command line argument, assume one is being 354 415 # piped in and read it … … 361 422 362 423 # break apart the year and the days 363 y=$( expr $dt / 1000)364 d=$( expr $dt \% 1000)424 y=$(( $dt / 1000 )) 425 d=$(( $dt % 1000 )) 365 426 366 427 # subtract the number of days in each month starting from 1 … … 369 430 # month to get the correct day of the month 370 431 m=1 371 while [ $ ( expr $d \> 0 ) = 1]432 while [ $d -gt 0 ] 372 433 do 373 md=$( IGCM_date_DaysInMonth $y $m )374 d=$( expr $d \- $md)375 m=$( expr $m \+ 1)434 IGCM_date_DaysInMonth $y $m md 435 d=$(( $d - $md )) 436 m=$(( $m + 1 )) 376 437 done 377 438 378 d=$( expr $d \+ $md)439 d=$(( $d + $md )) 379 440 380 441 # the loop steps one past the correct month, so back up the month 381 m=$( expr $m \- 1)442 m=$(( $m - 1 )) 382 443 383 444 # assemble the results into a gregorian date 384 grg=$( expr \( $y \* 10000 \) \+ \( $m \* 100 \) \+ $d)445 grg=$(( ( $y * 10000 ) + ( $m * 100 ) + $d )) 385 446 echo $( IGCM_date_GregorianDigit $grg ) 386 447 … … 402 463 # usage IGCM_date_AddDaysToJulianDate 1998312 { ,-}14 403 464 465 typeset dif yd d y diy 466 404 467 # Read the difference from the command lines 405 468 # and the date from the command line, or standard input … … 414 477 415 478 # Break it into pieces 416 d=$( expr $yd \% 1000)417 y=$( expr $yd / 1000)479 d=$(( $yd % 1000 )) 480 y=$(( $yd / 1000 )) 418 481 419 482 # Add the number of days (if days is negative this results is 420 483 # a subtraction) 421 d=$( expr $d \+ $dif)484 d=$(( $d + $dif )) 422 485 423 486 # Extract the days in the year 424 diy=$( IGCM_date_DaysInYear $y )487 IGCM_date_DaysInYear $y diy 425 488 426 489 # If the calculated day exceeds the days in the year, … … 429 492 # test until you end up with a day number that falls within the 430 493 # days of the year 431 while [ $ ( expr $d \> $diy ) = 1]494 while [ $d -gt $diy ] 432 495 do 433 d=$( expr $d - $diy)434 y=$( expr $y \+ 1)435 diy=$( IGCM_date_DaysInYear $y )496 d=$(( $d - $diy )) 497 y=$(( $y + 1 )) 498 IGCM_date_DaysInYear $y diy 436 499 done 437 500 … … 441 504 # loop on this test until you end up with a number that 442 505 # falls within the days of the year 443 while [ $ ( expr $d \< 1 ) =1 ]506 while [ $d -lt 1 ] 444 507 do 445 y=$( expr $y - 1)446 diy=$( IGCM_date_DaysInYear $y )447 d=$( expr $d \+ $diy)508 y=$(( $y - 1 )) 509 IGCM_date_DaysInYear $y diy 510 d=$(( $d + $diy )) 448 511 done 449 512 450 513 # put the year and day back together and echo the result 451 yd=$( expr \( $y \* 1000 \) + $d)514 yd=$(( ( $y * 1000 ) + $d )) 452 515 453 516 echo $yd … … 539 602 540 603 # Break the dates in to year and day portions 541 yyyy1=$( expr $jul1 / 1000)542 yyyy2=$( expr $jul2 / 1000)543 ddd1=$( expr $jul1 \% 1000)544 ddd2=$( expr $jul2 \% 1000)604 yyyy1=$(( $jul1 / 1000 )) 605 yyyy2=$(( $jul2 / 1000 )) 606 ddd1=$(( $jul1 % 1000 )) 607 ddd2=$(( $jul2 % 1000 )) 545 608 546 609 # Subtract days 547 res=$( expr $ddd1 - $ddd2)610 res=$(( $ddd1 - $ddd2 )) 548 611 549 612 # Then add days in year until year2 matches year1 550 613 551 614 if [ "${config_UserChoices_CalendarType}" = "360d" ] ; then 552 res=$( expr \( \( $yyyy1 \- $yyyy2 \) \* 360 \) \+ $res)615 res=$(( ( ( $yyyy1 - $yyyy2 ) * 360 ) + $res )) 553 616 elif [ "${config_UserChoices_CalendarType}" = "noleap" ] ; then 554 res=$( expr \( \( $yyyy1 \- $yyyy2 \) \* 365 \) \+ $res)617 res=$(( ( ( $yyyy1 - $yyyy2 ) * 365 ) + $res )) 555 618 elif ( [ "${config_UserChoices_CalendarType}" = "leap" ] || [ "${config_UserChoices_CalendarType}" = "gregorian" ] ) ; then 556 619 while [ $yyyy2 -lt $yyyy1 ] 557 620 do 558 diy=$( IGCM_date_DaysInYear $yyyy2 )559 res=$( expr $res + $diy)560 yyyy2=$( expr $yyyy2 + 1)621 IGCM_date_DaysInYear $yyyy2 diy 622 res=$(( $res + $diy )) 623 yyyy2=$(( $yyyy2 + 1 )) 561 624 done 562 625 fi … … 567 630 if [ $1 -lt $2 ] 568 631 then 569 res=$( expr $res \* -1)632 res=$(( $res * -1 )) 570 633 fi 571 634 … … 690 753 num=19000101 691 754 fi 692 echo $( expr \( $( IGCM_date_DaysBetweenGregorianDate $1 ${num} ) \+ $aux \))755 echo $(( $( IGCM_date_DaysBetweenGregorianDate $1 ${num} ) + $aux )) 693 756 694 757 IGCM_debug_PopStack "IGCM_date_DaysSinceJC"
Note: See TracChangeset
for help on using the changeset viewer.