New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Changeset 1628 – NEMO

Changeset 1628


Ignore:
Timestamp:
2009-09-02T09:41:47+02:00 (15 years ago)
Author:
smasson
Message:

add daily type of forcing file, see ticket:377

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/NEMO/OPA_SRC/SBC/fldread.F90

    r1491 r1628  
    3030      LOGICAL             ::   ln_tint     ! time interpolation or not (T/F) 
    3131      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' 
    3333      CHARACTER(len = 34) ::   wname       ! generic name of a NetCDF weights file to be used, blank if not 
    3434      CHARACTER(len = 34) ::   vcomp       ! symbolic component name if a vector that needs rotation 
     
    4444      LOGICAL                         ::   ln_tint      ! time interpolation or not (T/F) 
    4545      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' 
    4747      INTEGER                         ::   num          ! iom id of the jpfld files to be read 
    4848      REAL(wp)                        ::   swap_sec     ! swapping time in second since Jan. 1st 00h of nit000 year 
     
    124124      REAL(wp) ::   zreclast   ! last record to be read in the current year file 
    125125      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 
    128129      REAL(wp) ::   ztinta     ! ratio applied to after  records when doing time interpolation 
    129130      REAL(wp) ::   ztintb     ! ratio applied to before records when doing time interpolation 
     
    150151            CALL fld_rec( sd(jf) ) 
    151152 
    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??  
    153154            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/month 
    155                ! 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) will  
    156                ! 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) 
    157158 
    158159               ! last record to be read in the current file 
    159160               IF( sd(jf)%freqh == -1. ) THEN             ;   zreclast = 12. 
    160161               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 ) 
    163165                  ENDIF 
    164166               ENDIF 
    165167               
    166                ! do we need next year data? 
     168               ! do we need next file data? 
    167169               IF( sd(jf)%rec_a(1) > zreclast ) THEN 
    168170 
    169                   sd(jf)%rec_a(1) = 1.              ! force to read the first record of the next year 
     171                  sd(jf)%rec_a(1) = 1.              ! force to read the first record of the next file 
    170172 
    171173                  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 
    176180                     zsecend = rsec_year + sec1jan000 + REAL(nitend - kt, wp) * rdttra(1)   ! second at the end of the run  
    177181                     llstop = zsecend > sd(jf)%swap_sec                                 ! read more than 1 record of next year 
    178182 
    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 
    184191                        sd(jf)%rec_a(1) = zreclast     ! force to read the last record to be read in the current year file 
    185192                     ENDIF 
     
    189196         
    190197            ELSE 
    191                ! if we are not doing time interpolation, we must change the year/month of the file just afer switching 
    192                ! to the NEW year/month. If it is the case, we are at the beginning of the year/month when calling fld_rec 
    193                ! so sd(jf)%rec_a(1) = 1 
    194                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 ) 
    195202            ENDIF 
    196203 
     
    309316      LOGICAL :: llprevyr       ! are we reading previous year  file? 
    310317      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 
    312320      INTEGER :: idvar          ! variable id  
    313321      INTEGER :: inrec          ! number of record existing for this variable 
     
    321329      llprevyr  = .FALSE. 
    322330      llprevmth = .FALSE. 
     331      llprevday = .FALSE. 
    323332             
    324333      ! define record informations 
     
    329338         IF( sdjf%rec_b(1) == 0.e0 ) THEN   ! we redefine record sdjf%rec_b(1) with the last record of previous year file 
    330339            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 
    333348            ELSE    
    334349               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? 
    338358               ELSE                                  ! yearly file 
    339                   sdjf%rec_b(1) = 24. / sdjf%freqh * REAL( nyear_len(0), wp )           ! last record of year month 
    340                   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? 
    341361               ENDIF 
    342362            ENDIF 
    343363         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 
    349371         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/month 
     372            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 
    352374            llprev = .false. 
    353375            sdjf%rec_b(1) = 1. 
    354             CALL fld_clopn( sdjf, nyear, nmonth ) 
     376            CALL fld_clopn( sdjf, nyear, nmonth, nday ) 
    355377         ENDIF 
    356378          
     
    378400      ENDIF 
    379401 
    380       IF( sdjf%num == 0 )   CALL fld_clopn( sdjf, nyear, nmonth )   ! make sure current year/month file is opened 
     402      IF( sdjf%num == 0 )   CALL fld_clopn( sdjf, nyear, nmonth, nday )   ! make sure current year/month/day file is opened 
    381403 
    382404      sdjf%swap_sec = rsec_year + sec1jan000 - 1.   ! force read/update the after data in the following part of fld_read  
     
    433455         zfreq_sec = sdjf%freqh * 3600.   ! frequency mean (in seconds) 
    434456         ! 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 
    437460         ENDIF 
    438461         IF( sdjf%ln_tint ) THEN                ! time interpolation, shift by 1/2 record 
     
    469492         ! after record index and second since Jan. 1st 00h of nit000 year 
    470493         sdjf%rec_a(:) = (/ zrec, zfreq_sec * ( zrec - 0.5 ) + sec1jan000 /) 
    471          IF( sdjf%cltype == 'monthly' )   &   ! add the number of second between Jan 1 and the end of previous month 
     494         IF( sdjf%cltype == 'monthly' )   &   ! add the number of seconds between 00h Jan 1 and the end of previous month 
    472495            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 ) 
    473498 
    474499         ! before record index and second since Jan. 1st 00h of nit000 year 
    475500         zrec = zrec - 1.                           ! move back to previous record 
    476501         sdjf%rec_b(:) = (/ zrec, zfreq_sec * ( zrec - 0.5 ) + sec1jan000 /) 
    477          IF( sdjf%cltype == 'monthly' )   &   ! add the number of second between Jan 1 and the end of previous month 
     502         IF( sdjf%cltype == 'monthly' )   &   ! add the number of seconds between 00h Jan 1 and the end of previous month 
    478503            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 ) 
    479506 
    480507         ! swapping time in second since Jan. 1st 00h of nit000 year 
     
    488515 
    489516 
    490    SUBROUTINE fld_clopn( sdjf, kyear, kmonth, ldstop ) 
     517   SUBROUTINE fld_clopn( sdjf, kyear, kmonth, kday, ldstop ) 
    491518      !!--------------------------------------------------------------------- 
    492519      !!                    ***  ROUTINE fld_clopn  *** 
     
    499526      INTEGER  , INTENT(in   )           ::   kyear    ! year value 
    500527      INTEGER  , INTENT(in   )           ::   kmonth   ! month value 
     528      INTEGER  , INTENT(in   )           ::   kday     ! day value 
    501529      LOGICAL  , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if open to read a non-existing file (default = .TRUE.) 
    502530 
     
    504532      ! build the new filename if not climatological data 
    505533      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 
    507536      ENDIF 
    508537      CALL iom_open( sdjf%clname, sdjf%num, ldstop = ldstop, ldiof =  LEN(TRIM(sdjf%wgtname)) > 0 ) 
     
    536565         sdf(jf)%ln_clim    = sdf_n(jf)%ln_clim 
    537566         IF( sdf(jf)%freqh == -1. ) THEN   ;    sdf(jf)%cltype = 'yearly' 
    538          ELSE                               ;    sdf(jf)%cltype = sdf_n(jf)%cltype 
     567         ELSE                              ;    sdf(jf)%cltype = sdf_n(jf)%cltype 
    539568         ENDIF 
    540569         sdf(jf)%wgtname = " " 
Note: See TracChangeset for help on using the changeset viewer.