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 951 for branches/dev_001_GM/NEMO/OFF_SRC/IOM/iom_rstdimg.F90 – NEMO

Ignore:
Timestamp:
2008-05-14T18:42:10+02:00 (16 years ago)
Author:
cetlod
Message:

phasing the OFFLINE module to the new version of NEMO, see ticket 146

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/dev_001_GM/NEMO/OFF_SRC/IOM/iom_rstdimg.F90

    r719 r951  
    3131      MODULE PROCEDURE iom_rstdimg_rp0d, iom_rstdimg_rp123d 
    3232   END INTERFACE 
     33 
     34   INTEGER, PARAMETER ::   jpvnl          = 32   ! variable name length 
     35       
    3336   !!---------------------------------------------------------------------- 
    3437   !!  OPA 9.0 , LOCEAN-IPSL (2006) 
    35    !! $Header$ 
     38   !! $Header: /home/opalod/NEMOCVSROOT/NEMO/OPA_SRC/IOM/iom_rstdimg.F90,v 1.9 2007/06/29 14:10:50 opalod Exp $ 
    3639   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt) 
    3740   !!---------------------------------------------------------------------- 
     
    4548      !! ** Purpose :  open an input file read only (return 0 if not found) 
    4649      !!--------------------------------------------------------------------- 
    47       CHARACTER(len=*)       , INTENT(inout) ::   cdname   ! File name 
    48       INTEGER                , INTENT(  out) ::   kiomid   ! iom identifier of the opened file 
    49       LOGICAL                , INTENT(in   ) ::   ldwrt    ! read or write the file? 
    50       LOGICAL                , INTENT(in   ) ::   ldok     ! check the existence  
    51       INTEGER, DIMENSION(2,5), INTENT(in   ) ::   kdompar  ! domain parameters:  
     50      CHARACTER(len=*)       , INTENT(inout)           ::   cdname   ! File name 
     51      INTEGER                , INTENT(  out)           ::   kiomid   ! iom identifier of the opened file 
     52      LOGICAL                , INTENT(in   )           ::   ldwrt    ! read or write the file? 
     53      LOGICAL                , INTENT(in   )           ::   ldok     ! check the existence  
     54      INTEGER, DIMENSION(2,5), INTENT(in   ), OPTIONAL ::   kdompar  ! domain parameters:  
    5255 
    5356      CHARACTER(LEN=100)                      ::   clinfo                     ! info character 
     
    5962      INTEGER                                 ::   irecl8                     ! record length 
    6063      INTEGER                                 ::   ios                        ! IO status 
     64      INTEGER                                 ::   irhd                       ! record of the header infos 
    6165      INTEGER                                 ::   ivnum                      ! number of variables 
    6266      INTEGER                                 ::   ishft                      ! counter shift 
     
    6468      INTEGER                                 ::   in0d, in1d, in2d, in3d     ! number of 0/1/2/3D variables 
    6569      INTEGER                                 ::   ipni, ipnj, ipnij, iarea   ! domain decomposition  
    66       CHARACTER(LEN=8), DIMENSION(jpmax_vars) ::   clna0d, clna1d, clna2d, clna3d     ! name of 0/1/2/3D variables 
     70      INTEGER                                 ::   iiglo, ijglo               ! domain global size  
     71      INTEGER                                 ::   jl                         ! loop variable 
     72      CHARACTER(LEN=jpvnl), DIMENSION(jpmax_vars) ::   clna0d, clna1d, clna2d, clna3d     ! name of 0/1/2/3D variables 
    6773      REAL(wp),         DIMENSION(jpmax_vars) ::   zval0d, zval1d, zval2d, zval3d     ! value of 0d variables or record 
    6874      !                                                                               ! position for 1/2/3D variables 
    6975      !--------------------------------------------------------------------- 
    70  
    7176      clinfo = '                    iom_rstdimg_open ~~~  ' 
    7277      istop = nstop      ! store the actual value of nstop 
     
    99104         iln = INDEX( cdname, '.dimg' ) 
    100105         IF( ldwrt ) THEN  ! the file should be open in readwrite mode so we create it... 
    101             irecl8= kdompar(1,1) * kdompar(2,1) * wp 
     106            irecl8= MAX( kdompar(1,1) * kdompar(2,1) * wp, ( 8*jpnij + 15 ) * 4 ) 
    102107            IF( jpnij > 1 ) THEN 
    103                WRITE(cltmp,'(a,a,i4.4,a)') cdname(1:iln-1), '_', narea-1, '.dimg' 
     108               WRITE(cltmp,'(a,a,i4.4,a)') cdname(1:iln-1), '_', narea, '.dimg' 
    104109               cdname = TRIM(cltmp) 
    105110            ENDIF 
     
    108113               &       , RECL = irecl8, STATUS = 'new', ACTION = 'readwrite', IOSTAT = ios, ERR = 987 ) 
    109114         ELSE              ! the file should be open for read mode so it must exist... 
    110             CALL ctl_stop( TRIM(clinfo), 'File '//cdname(1:iln-1)//'* not found' ) 
     115            CALL ctl_stop( TRIM(clinfo), ' should be impossible case...' ) 
    111116         ENDIF 
    112117      ENDIF 
     
    114119      ! ============= 
    115120      IF( ldok ) THEN      ! old file 
    116          READ( idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8, inx, iny, inz, in0d, in1d, in2d, in3d 
    117          READ( idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8, inx, iny, inz, in0d, in1d, in2d, in3d,   & 
     121         READ( idrst, REC = 1   , IOSTAT = ios, ERR = 987 )              & 
     122              &   irecl8, inx, iny, inz, in0d, in1d, in2d, in3d, irhd,   & 
     123              &   ipni, ipnj, ipnij, iarea, iiglo, ijglo 
     124         READ( idrst, REC = irhd, IOSTAT = ios, ERR = 987 )                       & 
    118125            &   clna0d(1:in0d), zval0d(1:in0d), clna1d(1:in1d), zval1d(1:in1d),   & 
    119             &   clna2d(1:in2d), zval2d(1:in2d), clna3d(1:in3d), zval3d(1:in3d),   & 
    120             &   ipni, ipnj, ipnij, iarea  
     126            &   clna2d(1:in2d), zval2d(1:in2d), clna3d(1:in3d), zval3d(1:in3d) 
    121127         clinfo = TRIM(clinfo)//' file '//TRIM(cdname) 
    122          IF( inx   /= kdompar(1,1) )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in domain size in i direction' ) 
    123          IF( iny   /= kdompar(2,1) )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in domain size in j direction' ) 
     128         IF( iiglo /= jpiglo       )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in global domain size in i direction' ) 
     129         IF( ijglo /= jpjglo       )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in global domain size in j direction' ) 
     130         IF( ldwrt ) THEN 
     131            IF( inx   /= kdompar(1,1) )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in local domain size in i direction' ) 
     132            IF( iny   /= kdompar(2,1) )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in local domain size in j direction' ) 
     133         ENDIF 
    124134         IF( inz   /= jpk          )   CALL ctl_stop( TRIM(clinfo), 'Mismatch in domain size in k direction' ) 
    125135         IF( ipni  /= jpni         )   CALL ctl_stop( TRIM(clinfo), 'Processor splitting changed along I' ) 
     
    131141      ! ============= 
    132142      IF( istop == nstop ) THEN   ! no error within this routine 
    133          kiomid = MINLOC(iom_file(:)%nfid, dim = 1) 
     143!does not work with some compilers         kiomid = MINLOC(iom_file(:)%nfid, dim = 1) 
     144         kiomid = 0 
     145         DO jl = jpmax_files, 1, -1 
     146            IF( iom_file(jl)%nfid == 0 )   kiomid = jl 
     147         ENDDO 
    134148         iom_file(kiomid)%name    = TRIM(cdname) 
    135149         iom_file(kiomid)%nfid    = idrst 
     
    209223      INTEGER                                 ::   irecl8                     ! record length 
    210224      INTEGER                                 ::   ios                        ! IO status 
     225      INTEGER                                 ::   irhd                       ! record of the header infos 
    211226      INTEGER                                 ::   ivnum                      ! number of variables 
    212227      INTEGER                                 ::   idrst                      ! file logical unit 
    213228      INTEGER                                 ::   inx, iny, inz              ! x,y,z dimension of the variable 
    214229      INTEGER                                 ::   in0d, in1d, in2d, in3d     ! number of 0/1/2/3D variables 
    215       CHARACTER(LEN=8), DIMENSION(jpmax_vars) ::   clna0d, clna1d, clna2d, clna3d     ! name of 0/1/2/3D variables 
    216       REAL(wp),         DIMENSION(jpmax_vars) ::   zval0d, zval1d, zval2d, zval3d     ! value of 0d variables or record 
     230      CHARACTER(LEN=jpvnl), DIMENSION(jpmax_vars) ::   clna0d, clna1d, clna2d, clna3d    ! name of 0/1/2/3D variables 
     231      REAL(wp),          DIMENSION(jpmax_vars) ::   zval0d, zval1d, zval2d, zval3d    ! value of 0d variables or record 
    217232      !                                                                               ! position for 1/2/3D variables 
    218233      !--------------------------------------------------------------------- 
     
    226241      IF( ios == 0 ) THEN 
    227242         READ( idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8, inx, iny, inz   ! get back domain size 
     243         irhd = iom_file(kiomid)%irec 
    228244         ivnum = iom_file(kiomid)%nvars 
    229245         in0d = 0   ;   in1d = 0   ;   in2d = 0   ;   in3d = 0 
     
    249265            END SELECT 
    250266         END DO 
    251          ! force to have at least 1 valriable in each list (not necessary (?), but safer) 
     267         ! force to have at least 1 variable in each list (not necessary (?), but safer...) 
    252268         IF( in0d == 0 ) THEN   ;   in0d = 1   ;   clna0d(1) = 'no0d'   ;   zval0d(1) = -1.   ;   ENDIF 
    253269         IF( in1d == 0 ) THEN   ;   in1d = 1   ;   clna1d(1) = 'no1d'   ;   zval1d(1) = -1.   ;   ENDIF 
     
    255271         IF( in3d == 0 ) THEN   ;   in3d = 1   ;   clna3d(1) = 'no3d'   ;   zval3d(1) = -1.   ;   ENDIF 
    256272         ! update the file header before closing it 
    257          WRITE( idrst, REC = 1, IOSTAT = ios, ERR = 987 ) irecl8, inx, iny, inz, in0d, in1d, in2d, in3d,   & 
    258             &   clna0d(1:in0d), zval0d(1:in0d), clna1d(1:in1d), zval1d(1:in1d),   & 
    259             &   clna2d(1:in2d), zval2d(1:in2d), clna3d(1:in3d), zval3d(1:in3d),   & 
    260             &   jpni, jpnj, jpnij, narea, jpiglo, jpjglo, nlcit, nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt 
     273         WRITE( idrst, REC = 1, IOSTAT = ios, ERR = 987 )              & 
     274            &   irecl8, inx, iny, inz, in0d, in1d, in2d, in3d, irhd,   & 
     275            &   jpni, jpnj, jpnij, narea, jpiglo, jpjglo,              & 
     276            &   nlcit, nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt 
     277         IF( (ivnum * (jpvnl + wp)) > irecl8 ) THEN  
     278            CALL ctl_stop( TRIM(clinfo),   & 
     279                 &   'Last record size is too big... You could reduce the value of jpvnl' ) 
     280         ELSE  
     281            WRITE( idrst, REC = irhd, IOSTAT = ios, ERR = 987 )                        & 
     282                 &   clna0d(1:in0d), zval0d(1:in0d), clna1d(1:in1d), zval1d(1:in1d),   & 
     283                 &   clna2d(1:in2d), zval2d(1:in2d), clna3d(1:in3d), zval3d(1:in3d) 
     284         ENDIF 
    261285      ELSE 
    262286         ios = 0   ! we cannot write in the file 
     
    290314 
    291315 
    292    SUBROUTINE iom_rstdimg_rp0d( kiomid, cdvar, pv_r0d ) 
     316   SUBROUTINE iom_rstdimg_rp0d( kiomid, cdvar, kvid, pv_r0d ) 
    293317      !!-------------------------------------------------------------------- 
    294318      !!                   ***  SUBROUTINE  iom_rstdimg_rstput  *** 
     
    298322      INTEGER                   , INTENT(in) ::   kiomid   ! Identifier of the file  
    299323      CHARACTER(len=*)          , INTENT(in) ::   cdvar    ! time axis name 
     324      INTEGER                   , INTENT(in) ::   kvid     ! variable id 
    300325      REAL(wp)                  , INTENT(in) ::   pv_r0d   ! written 0d field 
    301326      ! 
     
    305330      !   
    306331      clinfo = '                    iom_rstdimg_rp0d ~~~  ' 
    307       idvar = iom_file(kiomid)%nvars + 1 
     332      IF( kvid <= 0 ) THEN   !   new variable 
     333         idvar = iom_file(kiomid)%nvars + 1 
     334      ELSE                   !   the variable already exists in the file 
     335         idvar = kvid 
     336      ENDIF 
    308337      IF( idvar <= jpmax_vars ) THEN 
    309338         iom_file(kiomid)%nvars = idvar 
     
    320349 
    321350 
    322    SUBROUTINE iom_rstdimg_g123d( kiomid, kdom  , kvid  , kstart, kcount,    & 
    323          &                          pv_r1d, pv_r2d, pv_r3d ) 
     351   SUBROUTINE iom_rstdimg_g123d( kiomid, kdom  , kvid, kx1, kx2, ky1, ky2,   & 
     352         &                       pv_r1d, pv_r2d, pv_r3d ) 
    324353      !!----------------------------------------------------------------------- 
    325354      !!                  ***  ROUTINE  iom_rstdimg_g123d  *** 
     
    332361      INTEGER                    , INTENT(in   )           ::   kdom       ! Type of domain to be read 
    333362      INTEGER                    , INTENT(in   )           ::   kvid       ! variable id 
    334       INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kstart     ! start position of the reading in each axis  
    335       INTEGER , DIMENSION(:)     , INTENT(in   )           ::   kcount     ! number of points to be read in each axis 
     363      INTEGER ,                    INTENT(inout)           ::   kx1, kx2, ky1, ky2   ! subdomain indexes 
    336364      REAL(wp), DIMENSION(:)     , INTENT(  out), OPTIONAL ::   pv_r1d     ! read field (1D case) 
    337365      REAL(wp), DIMENSION(:,:)   , INTENT(  out), OPTIONAL ::   pv_r2d     ! read field (2D case) 
     
    342370      INTEGER            ::   jk                   ! loop counter 
    343371      INTEGER            ::   idrst                ! logical unit of the restart file 
    344       INTEGER            ::   istop                ! temporary storage of nstop 
    345       INTEGER            ::   ix1, ix2, iy1, iy2   ! subdomain indexes 
    346372      !--------------------------------------------------------------------- 
    347373      clinfo = '                    iom_rstdimg_g123d ~~~  ' 
    348374      ! 
    349       istop = nstop                   ! store the actual value of nstop 
    350       idrst = iom_file(kiomid)%nfid   ! get back the logical unit of the restart file 
    351       IF( kdom == jpdom_data .OR. kdom == jpdom_global )   & 
    352             &   CALL ctl_stop( TRIM(clinfo), TRIM(iom_file(kiomid)%cn_var(kvid))//': case not coded for rstdimg files' ) 
    353       ! 
    354       IF( istop == nstop .AND. kvid > 0 ) THEN 
    355          IF( .NOT. PRESENT(pv_r1d) ) THEN 
    356             SELECT CASE (kdom)   ! find the right index of the array to be read 
    357             CASE (jpdom_local_full)      ;   ix1 = nldi   ;   ix2 = nlei   ;   iy1 = nldj   ;   iy2 = nlej 
    358             CASE (jpdom_local_noextra)   ;   ix1 = 1      ;   ix2 = nlci   ;   iy1 = 1      ;   iy2 = nlcj 
    359             CASE (jpdom_local_noovlap)   ;   ix1 = nldi   ;   ix2 = nlei   ;   iy1 = nldj   ;   iy2 = nlej 
    360             CASE DEFAULT                 ;   CALL ctl_stop( clinfo, 'we should not be there...' ) 
    361             END SELECT 
    362          ENDIF 
     375      IF( kdom == jpdom_data .OR. kdom == jpdom_global ) THEN 
     376         CALL ctl_stop( TRIM(clinfo), TRIM(iom_file(kiomid)%cn_var(kvid))//': case not coded for rstdimg files' ) 
     377      ELSE 
     378      ! 
     379         idrst = iom_file(kiomid)%nfid   ! get back the logical unit of the restart file 
     380         ! modify the subdomain indexes because we cannot directly extract the appropriate subdomaine 
     381         IF(     kdom == jpdom_local_full    ) THEN   ;   kx1 = 1   ;   kx2 = jpi    ;   ky1 = 1 
     382         ELSEIF( kdom == jpdom_local_noextra ) THEN   ;   kx1 = 1   ;   kx2 = nlci   ;   ky1 = 1 
     383         ENDIF 
     384         ! 
    363385         IF(     PRESENT(pv_r1d) ) THEN   ! read 1D variables 
    364             READ( idrst, REC = iom_file(kiomid)%nvid(kvid), IOSTAT = ios, ERR = 987 )   pv_r1d(:) 
     386            READ(    idrst, REC = iom_file(kiomid)%nvid(kvid)         , IOSTAT = ios, ERR = 987 )   pv_r1d(:) 
    365387         ELSEIF( PRESENT(pv_r2d) ) THEN   ! read 2D variables 
    366             READ( idrst, REC = iom_file(kiomid)%nvid(kvid), IOSTAT = ios, ERR = 987 )   pv_r2d(ix1:ix2, iy1:iy2 ) 
    367             SELECT CASE (kdom) 
    368             CASE (jpdom_local_noextra)   !--- Fill extra hallows (mpp)        
    369                pv_r2d(nlci+1:jpi,      :   ) = 1.     
    370                pv_r2d(      :   ,nlcj+1:jpj) = 1.             
    371             CASE (jpdom_local_noovlap)   !--- Fill the overlap areas and extra hallows (mpp) 
    372                CALL lbc_lnk (pv_r2d,'Z',-999.,'no0') 
    373             CASE DEFAULT 
    374             END SELECT 
     388            READ(    idrst, REC = iom_file(kiomid)%nvid(kvid)         , IOSTAT = ios, ERR = 987 )   pv_r2d(kx1:kx2, ky1:ky2    ) 
    375389         ELSEIF( PRESENT(pv_r3d) ) THEN   ! read 3D variables 
    376390            DO jk = 1, iom_file(kiomid)%dimsz(3,kvid)   ! do loop on each level 
    377                READ( idrst, REC = iom_file(kiomid)%nvid(kvid) + jk - 1, IOSTAT = ios, ERR = 987 )   & 
    378                      &      pv_r3d( ix1:ix2, iy1:iy2, jk ) 
    379             END DO 
    380             SELECT CASE (kdom) 
    381             CASE (jpdom_local_noextra)   !--- Fill extra hallows (mpp)        
    382                pv_r3d(nlci+1:jpi,      :   ,:) = 1.     
    383                pv_r3d(      :   ,nlcj+1:jpj,:) = 1.             
    384             CASE (jpdom_local_noovlap)   !--- Fill the overlap areas and extra hallows (mpp) 
    385                ! this if could be simplified with the new lbc_lnk that works with any size of the 3rd dimension 
    386                IF( kcount(3) == jpk ) THEN 
    387                   CALL lbc_lnk( pv_r3d,'Z',-999.,'no0' ) 
    388                ELSE 
    389                   pv_r3d(nlei+1:jpi,      :   ,:) = 1.             
    390                   pv_r3d(      :   ,nlej+1:jpj,:) = 1.             
    391                ENDIF 
    392             CASE DEFAULT 
    393             END SELECT 
    394          ENDIF 
    395       ENDIF 
    396 987   CONTINUE 
    397       IF( ios /= 0 ) THEN 
    398          WRITE(ctmp1,*) '           iostat = ', ios 
    399          CALL ctl_stop( TRIM(clinfo), '   IO error with file '//TRIM(iom_file(kiomid)%name), ctmp1 ) 
     391               READ( idrst, REC = iom_file(kiomid)%nvid(kvid) + jk - 1, IOSTAT = ios, ERR = 987 )   pv_r3d(kx1:kx2, ky1:ky2, jk) 
     392            END DO 
     393         ENDIF 
     394987      CONTINUE 
     395         IF( ios /= 0 ) THEN 
     396            WRITE(ctmp1,*) '           iostat = ', ios 
     397            CALL ctl_stop( TRIM(clinfo), '   IO error with file '//TRIM(iom_file(kiomid)%name), ctmp1 ) 
     398         ENDIF 
    400399      ENDIF 
    401400      ! 
     
    403402 
    404403 
    405    SUBROUTINE iom_rstdimg_rp123d( kiomid, cdvar, pv_r1d, pv_r2d, pv_r3d ) 
     404   SUBROUTINE iom_rstdimg_rp123d( kiomid, cdvar, kvid, pv_r1d, pv_r2d, pv_r3d ) 
    406405      !!-------------------------------------------------------------------- 
    407406      !!                   ***  SUBROUTINE  iom_rstdimg_rstput  *** 
     
    411410      INTEGER                         , INTENT(in)           ::   kiomid   ! Identifier of the file  
    412411      CHARACTER(len=*)                , INTENT(in)           ::   cdvar    ! time axis name 
     412      INTEGER                         , INTENT(in)           ::   kvid     ! variable id 
    413413      REAL(wp), DIMENSION(        jpk), INTENT(in), OPTIONAL ::   pv_r1d   ! written 1d field 
    414414      REAL(wp), DIMENSION(jpi,jpj    ), INTENT(in), OPTIONAL ::   pv_r2d   ! written 2d field 
     
    431431      irec = iom_file(kiomid)%irec    ! get back the record number of the variable 
    432432      idrst = iom_file(kiomid)%nfid   ! get back the logical unit of the restart file 
    433       idvar = iom_file(kiomid)%nvars + 1 
     433      IF( kvid <= 0 ) THEN   !   new variable 
     434         idvar = iom_file(kiomid)%nvars + 1 
     435      ELSE                   !   the variable already exists in the file 
     436         idvar = kvid 
     437      ENDIF 
    434438      IF( idvar > jpmax_vars )   CALL ctl_stop( TRIM(clinfo), 'increase the value of jpmax_vars' ) 
    435439      IF( .NOT. PRESENT(pv_r1d) ) THEN 
Note: See TracChangeset for help on using the changeset viewer.