Changeset 1628
- Timestamp:
- 2009-09-02T09:41:47+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/NEMO/OPA_SRC/SBC/fldread.F90
r1491 r1628 30 30 LOGICAL :: ln_tint ! time interpolation or not (T/F) 31 31 LOGICAL :: ln_clim ! climatology or not (T/F) 32 CHARACTER(len = 7) :: cltype ! type of data file ' monthly' or yearly'32 CHARACTER(len = 7) :: cltype ! type of data file 'daily', 'monthly' or yearly' 33 33 CHARACTER(len = 34) :: wname ! generic name of a NetCDF weights file to be used, blank if not 34 34 CHARACTER(len = 34) :: vcomp ! symbolic component name if a vector that needs rotation … … 44 44 LOGICAL :: ln_tint ! time interpolation or not (T/F) 45 45 LOGICAL :: ln_clim ! climatology or not (T/F) 46 CHARACTER(len = 7) :: cltype ! type of data file ' monthly' or yearly'46 CHARACTER(len = 7) :: cltype ! type of data file 'daily', 'monthly' or yearly' 47 47 INTEGER :: num ! iom id of the jpfld files to be read 48 48 REAL(wp) :: swap_sec ! swapping time in second since Jan. 1st 00h of nit000 year … … 124 124 REAL(wp) :: zreclast ! last record to be read in the current year file 125 125 REAL(wp) :: zsecend ! number of second since Jan. 1st 00h of nit000 year at nitend 126 LOGICAL :: llnxtyr ! open next year file? 127 LOGICAL :: llstop ! stop is the file is not existing 126 LOGICAL :: llnxtyr ! open next year file? 127 LOGICAL :: llnxtmth ! open next month file? 128 LOGICAL :: llstop ! stop is the file does not exist 128 129 REAL(wp) :: ztinta ! ratio applied to after records when doing time interpolation 129 130 REAL(wp) :: ztintb ! ratio applied to before records when doing time interpolation … … 150 151 CALL fld_rec( sd(jf) ) 151 152 152 ! do we have to change the year/month of the forcing field??153 ! do we have to change the year/month/day of the forcing field?? 153 154 IF( sd(jf)%ln_tint ) THEN 154 ! if we do time interpolation we will need to open next year/month file before the end of the current year/month155 ! if it is the case, we are still before the end of the year/month when calling fld_rec so sd(jf)%rec_a(1) will156 ! be larger than the record number that should be read for current year/month(for ex. 13 for monthly mean file)155 ! if we do time interpolation we will need to open next year/month/day file before the end of the current one 156 ! if so, we are still before the end of the year/month/day when calling fld_rec so sd(jf)%rec_a(1) will be 157 ! larger than the record number that should be read for current year/month/day (for ex. 13 for monthly mean file) 157 158 158 159 ! last record to be read in the current file 159 160 IF( sd(jf)%freqh == -1. ) THEN ; zreclast = 12. 160 161 ELSE 161 IF( sd(jf)%cltype == 'monthly' ) THEN ; zreclast = 24. / sd(jf)%freqh * REAL( nmonth_len(nmonth), wp ) 162 ELSE ; zreclast = 24. / sd(jf)%freqh * REAL( nyear_len( 1 ), wp ) 162 IF( sd(jf)%cltype == 'monthly' ) THEN ; zreclast = 24. / sd(jf)%freqh * REAL( nmonth_len(nmonth), wp ) 163 ELSEIF( sd(jf)%cltype == 'daily' ) THEN ; zreclast = 24. / sd(jf)%freqh 164 ELSE ; zreclast = 24. / sd(jf)%freqh * REAL( nyear_len( 1 ), wp ) 163 165 ENDIF 164 166 ENDIF 165 167 166 ! do we need next yeardata?168 ! do we need next file data? 167 169 IF( sd(jf)%rec_a(1) > zreclast ) THEN 168 170 169 sd(jf)%rec_a(1) = 1. ! force to read the first record of the next year171 sd(jf)%rec_a(1) = 1. ! force to read the first record of the next file 170 172 171 173 IF( .NOT. sd(jf)%ln_clim ) THEN ! close the current file and open a new one. 172 173 llnxtyr = sd(jf)%cltype /= 'monthly' .OR. nmonth == 12 ! do we need to open next year file? 174 ! if the run finishes at the end of the current year/month, we do accept that next year/month file does 175 ! not exist. If the run continue farther than the current year/month, next year/month file must exist 174 175 llnxtmth = sd(jf)%cltype == 'monthly' .OR. nday == nmonth_len(nmonth) ! open next month file? 176 llnxtyr = sd(jf)%cltype == 'yearly' .OR. (nmonth == 12 .AND. llnxtmth) ! open next year file? 177 178 ! if the run finishes at the end of the current year/month/day, we will allow next year/month/day file to be 179 ! not present. If the run continue further than the current year/month/day, next year/month/day file must exist 176 180 zsecend = rsec_year + sec1jan000 + REAL(nitend - kt, wp) * rdttra(1) ! second at the end of the run 177 181 llstop = zsecend > sd(jf)%swap_sec ! read more than 1 record of next year 178 182 179 CALL fld_clopn( sd(jf), nyear + COUNT((/llnxtyr/)), nmonth + 1 - 12 * COUNT((/llnxtyr/)), llstop ) 180 181 IF( sd(jf)%num == 0 .AND. .NOT. llstop ) THEN ! next year file is not existing 182 CALL ctl_warn('next year/month file: '//TRIM(sd(jf)%clname)//' not existing -> back to current year/month') 183 CALL fld_clopn( sd(jf), nyear, nmonth ) ! back to the current year/month 183 CALL fld_clopn( sd(jf), nyear + COUNT((/llnxtyr /)) , & 184 & nmonth + COUNT((/llnxtmth/)) - 12 * COUNT((/llnxtyr /)), & 185 & nday + 1 - nmonth_len(nmonth) * COUNT((/llnxtmth/)), llstop ) 186 187 IF( sd(jf)%num == 0 .AND. .NOT. llstop ) THEN ! next year file does not exist 188 CALL ctl_warn('next year/month/day file: '//TRIM(sd(jf)%clname)// & 189 & ' not present -> back to current year/month/day') 190 CALL fld_clopn( sd(jf), nyear, nmonth, nday ) ! back to the current year/month/day 184 191 sd(jf)%rec_a(1) = zreclast ! force to read the last record to be read in the current year file 185 192 ENDIF … … 189 196 190 197 ELSE 191 ! if we are not doing time interpolation, we must change the year/month of the file just afer switching192 ! to the NEW year/month . If it is the case, we are at the beginning of the year/month when calling fld_rec193 ! so sd(jf)%rec_a(1) = 1194 IF( sd(jf)%rec_a(1) == 1 .AND. .NOT. sd(jf)%ln_clim ) CALL fld_clopn( sd(jf), nyear, nmonth )198 ! if we are not doing time interpolation, we must change the year/month/day of the file just after switching 199 ! to the NEW year/month/day. If it is the case, we are at the beginning of the year/month/day when calling 200 ! fld_rec so sd(jf)%rec_a(1) = 1 201 IF( sd(jf)%rec_a(1) == 1 .AND. .NOT. sd(jf)%ln_clim ) CALL fld_clopn( sd(jf), nyear, nmonth, nday ) 195 202 ENDIF 196 203 … … 309 316 LOGICAL :: llprevyr ! are we reading previous year file? 310 317 LOGICAL :: llprevmth ! are we reading previous month file? 311 LOGICAL :: llprev ! llprevyr .OR. llprevmth 318 LOGICAL :: llprevday ! are we reading previous day file? 319 LOGICAL :: llprev ! llprevyr .OR. llprevmth .OR. llprevday 312 320 INTEGER :: idvar ! variable id 313 321 INTEGER :: inrec ! number of record existing for this variable … … 321 329 llprevyr = .FALSE. 322 330 llprevmth = .FALSE. 331 llprevday = .FALSE. 323 332 324 333 ! define record informations … … 329 338 IF( sdjf%rec_b(1) == 0.e0 ) THEN ! we redefine record sdjf%rec_b(1) with the last record of previous year file 330 339 IF( sdjf%freqh == -1. ) THEN ! monthly mean 331 sdjf%rec_b(1) = 12. ! force to read december mean 332 llprevyr = .NOT. sdjf%ln_clim 340 IF( sdjf%cltype == 'monthly' ) THEN ! monthly file 341 sdjf%rec_b(1) = 1. ! force to read the unique record 342 llprevmth = .NOT. sdjf%ln_clim ! use previous month file? 343 llprevyr = llprevmth .AND. nmonth == 1 ! use previous year file? 344 ELSE ! yearly file 345 sdjf%rec_b(1) = 12. ! force to read december mean 346 llprevyr = .NOT. sdjf%ln_clim ! use previous year file? 347 ENDIF 333 348 ELSE 334 349 IF( sdjf%cltype == 'monthly' ) THEN ! monthly file 335 sdjf%rec_b(1) = 24. / sdjf%freqh * REAL( nmonth_len(nmonth-1), wp ) ! last record of previous month 336 llprevmth = .NOT. sdjf%ln_clim ! use previous month file? 337 llprevyr = .NOT. sdjf%ln_clim .AND. nmonth == 1 ! use previous year file? 350 sdjf%rec_b(1) = 24. / sdjf%freqh * REAL( nmonth_len(nmonth-1), wp ) ! last record of previous month 351 llprevmth = .NOT. sdjf%ln_clim ! use previous month file? 352 llprevyr = llprevmth .AND. nmonth == 1 ! use previous year file? 353 ELSEIF( sdjf%cltype == 'daily' ) THEN ! daily file 354 sdjf%rec_b(1) = 24. / sdjf%freqh ! last record of previous day 355 llprevday = .NOT. sdjf%ln_clim ! use previous day file? 356 llprevmth = llprevday .AND. nday == 1 ! use previous month file? 357 llprevyr = llprevmth .AND. nmonth == 1 ! use previous year file? 338 358 ELSE ! yearly file 339 sdjf%rec_b(1) = 24. / sdjf%freqh * REAL( nyear_len(0), wp ) ! last record of year month340 llprevyr = .NOT. sdjf%ln_clim! use previous year file?359 sdjf%rec_b(1) = 24. / sdjf%freqh * REAL( nyear_len(0), wp ) ! last record of year month 360 llprevyr = .NOT. sdjf%ln_clim ! use previous year file? 341 361 ENDIF 342 362 ENDIF 343 363 ENDIF 344 llprev = llprevyr .OR. llprevmth 345 346 CALL fld_clopn( sdjf, nyear - COUNT((/llprevyr/)), nmonth - COUNT((/llprevmth/)) + 12 * COUNT((/llprevyr/)), .NOT. llprev ) 347 348 ! if previous year/month file is not existing, we switch to the current year/month 364 llprev = llprevyr .OR. llprevmth .OR. llprevday 365 366 CALL fld_clopn( sdjf, nyear - COUNT((/llprevyr /)) , & 367 & nmonth - COUNT((/llprevmth/)) + 12 * COUNT((/llprevyr /)), & 368 & nday - COUNT((/llprevday/)) + nmonth_len(nmonth-1) * COUNT((/llprevmth/)), .NOT. llprev ) 369 370 ! if previous year/month/day file does not exist, we switch to the current year/month/day 349 371 IF( llprev .AND. sdjf%num == 0 ) THEN 350 CALL ctl_warn( 'previous year/month file: '//TRIM(sdjf%clname)//' not existing -> back to current year/month')351 ! we force to read the first record of the current year/month instead of last record of previous year/month372 CALL ctl_warn( 'previous year/month/day file: '//TRIM(sdjf%clname)//' not present -> back to current year/month/day') 373 ! we force to read the first record of the current year/month/day instead of last record of previous year/month/day 352 374 llprev = .false. 353 375 sdjf%rec_b(1) = 1. 354 CALL fld_clopn( sdjf, nyear, nmonth )376 CALL fld_clopn( sdjf, nyear, nmonth, nday ) 355 377 ENDIF 356 378 … … 378 400 ENDIF 379 401 380 IF( sdjf%num == 0 ) CALL fld_clopn( sdjf, nyear, nmonth ) ! make sure current year/monthfile is opened402 IF( sdjf%num == 0 ) CALL fld_clopn( sdjf, nyear, nmonth, nday ) ! make sure current year/month/day file is opened 381 403 382 404 sdjf%swap_sec = rsec_year + sec1jan000 - 1. ! force read/update the after data in the following part of fld_read … … 433 455 zfreq_sec = sdjf%freqh * 3600. ! frequency mean (in seconds) 434 456 ! number of second since the beginning of the file 435 IF( sdjf%cltype == 'monthly' ) THEN ; ztmp = rsec_month ! since Jan 1 of the current year 436 ELSE ; ztmp = rsec_year ! since the first day of the current month 457 IF( sdjf%cltype == 'monthly' ) THEN ; ztmp = rsec_month ! since 00h on the first day of the current month 458 ELSEIF( sdjf%cltype == 'daily' ) THEN ; ztmp = rsec_day ! since 00h of the current day 459 ELSE ; ztmp = rsec_year ! since 00h on Jan 1 of the current year 437 460 ENDIF 438 461 IF( sdjf%ln_tint ) THEN ! time interpolation, shift by 1/2 record … … 469 492 ! after record index and second since Jan. 1st 00h of nit000 year 470 493 sdjf%rec_a(:) = (/ zrec, zfreq_sec * ( zrec - 0.5 ) + sec1jan000 /) 471 IF( sdjf%cltype == 'monthly' ) & ! add the number of second betweenJan 1 and the end of previous month494 IF( sdjf%cltype == 'monthly' ) & ! add the number of seconds between 00h Jan 1 and the end of previous month 472 495 sdjf%rec_a(2) = sdjf%rec_a(2) + rday * REAL(SUM(nmonth_len(1:nmonth -1)), wp) ! ok if nmonth=1 496 IF( sdjf%cltype == 'daily' ) & ! add the number of seconds between 00h Jan 1 and the end of previous day 497 sdjf%rec_a(2) = sdjf%rec_a(2) + rday * ( nday_year - 1 ) 473 498 474 499 ! before record index and second since Jan. 1st 00h of nit000 year 475 500 zrec = zrec - 1. ! move back to previous record 476 501 sdjf%rec_b(:) = (/ zrec, zfreq_sec * ( zrec - 0.5 ) + sec1jan000 /) 477 IF( sdjf%cltype == 'monthly' ) & ! add the number of second betweenJan 1 and the end of previous month502 IF( sdjf%cltype == 'monthly' ) & ! add the number of seconds between 00h Jan 1 and the end of previous month 478 503 sdjf%rec_b(2) = sdjf%rec_b(2) + rday * REAL(SUM(nmonth_len(1:nmonth -1)), wp) ! ok if nmonth=1 504 IF( sdjf%cltype == 'daily' ) & ! add the number of seconds between 00h Jan 1 and the end of previous day 505 sdjf%rec_b(2) = sdjf%rec_b(2) + rday * ( nday_year - 1 ) 479 506 480 507 ! swapping time in second since Jan. 1st 00h of nit000 year … … 488 515 489 516 490 SUBROUTINE fld_clopn( sdjf, kyear, kmonth, ldstop )517 SUBROUTINE fld_clopn( sdjf, kyear, kmonth, kday, ldstop ) 491 518 !!--------------------------------------------------------------------- 492 519 !! *** ROUTINE fld_clopn *** … … 499 526 INTEGER , INTENT(in ) :: kyear ! year value 500 527 INTEGER , INTENT(in ) :: kmonth ! month value 528 INTEGER , INTENT(in ) :: kday ! day value 501 529 LOGICAL , INTENT(in ), OPTIONAL :: ldstop ! stop if open to read a non-existing file (default = .TRUE.) 502 530 … … 504 532 ! build the new filename if not climatological data 505 533 IF( .NOT. sdjf%ln_clim ) THEN ; WRITE(sdjf%clname, '(a,"_y",i4.4)' ) TRIM( sdjf%clrootname ), kyear ! add year 506 IF( sdjf%cltype == 'monthly' ) WRITE(sdjf%clname, '(a,"m",i2.2)' ) TRIM( sdjf%clname ), kmonth ! add month 534 IF( sdjf%cltype /= 'yearly' ) WRITE(sdjf%clname, '(a,"m" ,i2.2)' ) TRIM( sdjf%clname ), kmonth ! add month 535 IF( sdjf%cltype == 'daily' ) WRITE(sdjf%clname, '(a,"d" ,i2.2)' ) TRIM( sdjf%clname ), kday ! add day 507 536 ENDIF 508 537 CALL iom_open( sdjf%clname, sdjf%num, ldstop = ldstop, ldiof = LEN(TRIM(sdjf%wgtname)) > 0 ) … … 536 565 sdf(jf)%ln_clim = sdf_n(jf)%ln_clim 537 566 IF( sdf(jf)%freqh == -1. ) THEN ; sdf(jf)%cltype = 'yearly' 538 ELSE 567 ELSE ; sdf(jf)%cltype = sdf_n(jf)%cltype 539 568 ENDIF 540 569 sdf(jf)%wgtname = " "
Note: See TracChangeset
for help on using the changeset viewer.