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 7577 – NEMO

Changeset 7577


Ignore:
Timestamp:
2017-01-18T18:32:11+01:00 (7 years ago)
Author:
acc
Message:

Branch dev_merge_2016. Tidy iom_getatt routine and add ability to read character attributes. See #1831 for details

Location:
branches/2016/dev_merge_2016/NEMOGCM/NEMO/OPA_SRC/IOM
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2016/dev_merge_2016/NEMOGCM/NEMO/OPA_SRC/IOM/iom.F90

    r7425 r7577  
    6868   END INTERFACE 
    6969   INTERFACE iom_getatt 
    70       MODULE PROCEDURE iom_g0d_intatt, iom_g0d_ratt 
     70      MODULE PROCEDURE iom_g0d_iatt, iom_g0d_ratt, iom_g0d_catt 
    7171   END INTERFACE 
    7272   INTERFACE iom_rstput 
     
    10061006   !!                   INTERFACE iom_getatt 
    10071007   !!---------------------------------------------------------------------- 
    1008    SUBROUTINE iom_g0d_intatt( kiomid, cdatt, pvar ) 
     1008   SUBROUTINE iom_g0d_iatt( kiomid, cdatt, pvar, cdvar ) 
    10091009      INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file 
    10101010      CHARACTER(len=*), INTENT(in   )                 ::   cdatt     ! Name of the attribute 
    10111011      INTEGER         , INTENT(  out)                 ::   pvar      ! read field 
     1012      CHARACTER(len=*), INTENT(in   ), OPTIONAL       ::   cdvar     ! Name of the variable 
    10121013      ! 
    10131014      IF( kiomid > 0 ) THEN 
    10141015         IF( iom_file(kiomid)%nfid > 0 ) THEN 
    10151016            SELECT CASE (iom_file(kiomid)%iolib) 
    1016             CASE (jpnf90   )   ;   CALL iom_nf90_getatt( kiomid, cdatt, pv_i0d=pvar ) 
     1017            CASE (jpnf90   )   ;   IF( PRESENT(cdvar) ) THEN 
     1018                                      CALL iom_nf90_getatt( kiomid, cdatt, pvar, cdvar=cdvar ) 
     1019                                   ELSE 
     1020                                      CALL iom_nf90_getatt( kiomid, cdatt, pvar ) 
     1021                                   ENDIF 
    10171022            CASE DEFAULT 
    1018                CALL ctl_stop( 'iom_g0d_att: accepted IO library is only jpnf90' ) 
     1023               CALL ctl_stop( 'iom_g0d_iatt: accepted IO library is only jpnf90' ) 
    10191024            END SELECT 
    10201025         ENDIF 
    10211026      ENDIF 
    1022    END SUBROUTINE iom_g0d_intatt 
     1027   END SUBROUTINE iom_g0d_iatt 
    10231028 
    10241029   SUBROUTINE iom_g0d_ratt( kiomid, cdatt, pvar, cdvar ) 
     
    10321037            SELECT CASE (iom_file(kiomid)%iolib) 
    10331038            CASE (jpnf90   )   ;   IF( PRESENT(cdvar) ) THEN 
    1034                                       CALL iom_nf90_getatt( kiomid, cdatt, pv_r0d=pvar, cdvar=cdvar ) 
     1039                                      CALL iom_nf90_getatt( kiomid, cdatt, pvar, cdvar=cdvar ) 
    10351040                                   ELSE 
    1036                                       CALL iom_nf90_getatt( kiomid, cdatt, pv_r0d=pvar ) 
     1041                                      CALL iom_nf90_getatt( kiomid, cdatt, pvar ) 
    10371042                                   ENDIF 
    10381043            CASE DEFAULT     
    1039                CALL ctl_stop( 'iom_g0d_att: accepted IO library is only jpnf90' ) 
     1044               CALL ctl_stop( 'iom_g0d_ratt: accepted IO library is only jpnf90' ) 
    10401045            END SELECT 
    10411046         ENDIF 
    10421047      ENDIF 
    10431048   END SUBROUTINE iom_g0d_ratt 
     1049 
     1050   SUBROUTINE iom_g0d_catt( kiomid, cdatt, pvar, cdvar ) 
     1051      INTEGER         , INTENT(in   )                 ::   kiomid    ! Identifier of the file 
     1052      CHARACTER(len=*), INTENT(in   )                 ::   cdatt     ! Name of the attribute 
     1053      CHARACTER(len=*), INTENT(  out)                 ::   pvar      ! written field 
     1054      CHARACTER(len=*), INTENT(in   ), OPTIONAL       ::   cdvar     ! Name of the variable 
     1055      ! 
     1056      IF( kiomid > 0 ) THEN 
     1057         IF( iom_file(kiomid)%nfid > 0 ) THEN 
     1058            SELECT CASE (iom_file(kiomid)%iolib) 
     1059            CASE (jpnf90   )   ;   IF( PRESENT(cdvar) ) THEN 
     1060                                      CALL iom_nf90_getatt( kiomid, cdatt, pvar, cdvar=cdvar ) 
     1061                                   ELSE 
     1062                                      CALL iom_nf90_getatt( kiomid, cdatt, pvar ) 
     1063                                   ENDIF 
     1064            CASE DEFAULT 
     1065               CALL ctl_stop( 'iom_g0d_ratt: accepted IO library is only jpnf90' ) 
     1066            END SELECT 
     1067         ENDIF 
     1068      ENDIF 
     1069   END SUBROUTINE iom_g0d_catt 
    10441070 
    10451071   !!---------------------------------------------------------------------- 
  • branches/2016/dev_merge_2016/NEMOGCM/NEMO/OPA_SRC/IOM/iom_nf90.F90

    r7412 r7577  
    3636   END INTERFACE 
    3737   INTERFACE iom_nf90_getatt 
    38       MODULE PROCEDURE iom_nf90_att 
     38      MODULE PROCEDURE iom_nf90_iatt, iom_nf90_ratt, iom_nf90_catt 
    3939   END INTERFACE 
    4040   INTERFACE iom_nf90_rstput 
     
    313313   END SUBROUTINE iom_nf90_g123d 
    314314 
    315  
    316    SUBROUTINE iom_nf90_att( kiomid, cdatt, pv_i0d, pv_r0d, cdvar) 
    317       !!----------------------------------------------------------------------- 
    318       !!                  ***  ROUTINE  iom_nf90_att  *** 
     315   SUBROUTINE iom_nf90_iatt( kiomid, cdatt, pv_i0d, cdvar) 
     316      !!----------------------------------------------------------------------- 
     317      !!                  ***  ROUTINE  iom_nf90_iatt  *** 
    319318      !! 
    320319      !! ** Purpose : read an integer attribute with NF90 
     320      !!              (either a global attribute (default) or a variable 
     321      !!               attribute if optional variable name is supplied (cdvar)) 
    321322      !!----------------------------------------------------------------------- 
    322323      INTEGER         , INTENT(in   ) ::   kiomid   ! Identifier of the file 
    323324      CHARACTER(len=*), INTENT(in   ) ::   cdatt    ! attribute name 
    324       INTEGER         , INTENT(  out), OPTIONAL       ::   pv_i0d    ! read field 
    325       REAL(wp),         INTENT(  out), OPTIONAL       ::   pv_r0d    ! read field  
    326       CHARACTER(len=*), INTENT(in   ), OPTIONAL       ::   cdvar     ! name of the variable 
     325      INTEGER         , INTENT(  out) ::   pv_i0d   ! read field 
     326      CHARACTER(len=*), INTENT(in   ), OPTIONAL     & 
     327                      &               ::   cdvar    ! name of the variable 
    327328      ! 
    328329      INTEGER                         ::   if90id   ! temporary integer 
    329       INTEGER                         ::   ivarid           ! NetCDF variable Id 
     330      INTEGER                         ::   ivarid   ! NetCDF variable Id 
    330331      LOGICAL                         ::   llok     ! temporary logical 
    331332      CHARACTER(LEN=100)              ::   clinfo   ! info character 
    332333      !--------------------------------------------------------------------- 
    333       !  
     334      ! 
    334335      if90id = iom_file(kiomid)%nfid 
    335336      IF( PRESENT(cdvar) ) THEN 
    336          llok = NF90_INQ_VARID( if90id, TRIM(cdvar), ivarid ) == nf90_noerr   ! does the variable exist in the file 
     337         ! check the variable exists in the file 
     338         llok = NF90_INQ_VARID( if90id, TRIM(cdvar), ivarid ) == nf90_noerr 
    337339         IF( llok ) THEN 
     340            ! check the variable has the attribute required 
    338341            llok = NF90_Inquire_attribute(if90id, ivarid, cdatt) == nf90_noerr 
    339342         ELSE 
     
    342345      ELSE 
    343346         llok = NF90_Inquire_attribute(if90id, NF90_GLOBAL, cdatt) == nf90_noerr 
    344       ENDIF  
     347         ivarid = NF90_GLOBAL 
     348      ENDIF 
    345349! 
    346350      IF( llok) THEN 
    347          clinfo = 'iom_nf90_getatt, file: '//TRIM(iom_file(kiomid)%name)//', att: '//TRIM(cdatt) 
    348          IF(     PRESENT(pv_r0d) ) THEN 
    349             IF( PRESENT(cdvar) ) THEN 
    350                CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, cdatt, values=pv_r0d), clinfo) 
    351             ELSE 
    352                CALL iom_nf90_check(NF90_GET_ATT(if90id, NF90_GLOBAL, cdatt, values=pv_r0d), clinfo) 
    353             ENDIF 
     351         clinfo = 'iom_nf90_getatt, file: '//TRIM(iom_file(kiomid)%name)//', iatt: '//TRIM(cdatt) 
     352         CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, cdatt, values=pv_i0d), clinfo) 
     353      ELSE 
     354         CALL ctl_warn('iom_nf90_getatt: no attribute '//cdatt//' found') 
     355         pv_i0d = -999 
     356      ENDIF 
     357      ! 
     358   END SUBROUTINE iom_nf90_iatt 
     359 
     360   SUBROUTINE iom_nf90_ratt( kiomid, cdatt, pv_r0d, cdvar) 
     361      !!----------------------------------------------------------------------- 
     362      !!                  ***  ROUTINE  iom_nf90_iatt  *** 
     363      !! 
     364      !! ** Purpose : read a real attribute with NF90 
     365      !!              (either a global attribute (default) or a variable 
     366      !!               attribute if optional variable name is supplied (cdvar)) 
     367      !!----------------------------------------------------------------------- 
     368      INTEGER         , INTENT(in   ) ::   kiomid   ! Identifier of the file 
     369      CHARACTER(len=*), INTENT(in   ) ::   cdatt    ! attribute name 
     370      REAL(wp)        , INTENT(  out) ::   pv_r0d   ! read field 
     371      CHARACTER(len=*), INTENT(in   ), OPTIONAL     & 
     372                      &               ::   cdvar    ! name of the variable 
     373      ! 
     374      INTEGER                         ::   if90id   ! temporary integer 
     375      INTEGER                         ::   ivarid   ! NetCDF variable Id 
     376      LOGICAL                         ::   llok     ! temporary logical 
     377      CHARACTER(LEN=100)              ::   clinfo   ! info character 
     378      !--------------------------------------------------------------------- 
     379      ! 
     380      if90id = iom_file(kiomid)%nfid 
     381      IF( PRESENT(cdvar) ) THEN 
     382         ! check the variable exists in the file 
     383         llok = NF90_INQ_VARID( if90id, TRIM(cdvar), ivarid ) == nf90_noerr 
     384         IF( llok ) THEN 
     385            ! check the variable has the attribute required 
     386            llok = NF90_Inquire_attribute(if90id, ivarid, cdatt) == nf90_noerr 
    354387         ELSE 
    355             IF( PRESENT(cdvar) ) THEN 
    356                CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, cdatt, values=pv_i0d), clinfo) 
    357             ELSE 
    358                CALL iom_nf90_check(NF90_GET_ATT(if90id, NF90_GLOBAL, cdatt, values=pv_i0d), clinfo) 
    359             ENDIF 
    360          ENDIF 
     388            CALL ctl_warn('iom_nf90_getatt: no variable '//cdvar//' found') 
     389         ENDIF 
     390      ELSE 
     391         llok = NF90_Inquire_attribute(if90id, NF90_GLOBAL, cdatt) == nf90_noerr 
     392         ivarid = NF90_GLOBAL 
     393      ENDIF 
     394! 
     395      IF( llok) THEN 
     396         clinfo = 'iom_nf90_getatt, file: '//TRIM(iom_file(kiomid)%name)//', ratt: '//TRIM(cdatt) 
     397         CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, cdatt, values=pv_r0d), clinfo) 
    361398      ELSE 
    362399         CALL ctl_warn('iom_nf90_getatt: no attribute '//cdatt//' found') 
    363          IF(     PRESENT(pv_r0d) ) THEN 
    364             pv_r0d = -999._wp 
     400         pv_r0d = -999._wp 
     401      ENDIF 
     402      ! 
     403   END SUBROUTINE iom_nf90_ratt 
     404 
     405   SUBROUTINE iom_nf90_catt( kiomid, cdatt, pv_c0d, cdvar) 
     406      !!----------------------------------------------------------------------- 
     407      !!                  ***  ROUTINE  iom_nf90_iatt  *** 
     408      !! 
     409      !! ** Purpose : read an integer attribute with NF90 
     410      !!              (either a global attribute (default) or a variable 
     411      !!               attribute if optional variable name is supplied (cdvar)) 
     412      !!----------------------------------------------------------------------- 
     413      INTEGER         , INTENT(in   ) ::   kiomid   ! Identifier of the file 
     414      CHARACTER(len=*), INTENT(in   ) ::   cdatt    ! attribute name 
     415      CHARACTER(len=*), INTENT(  out) ::   pv_c0d   ! read field 
     416      CHARACTER(len=*), INTENT(in   ), OPTIONAL     & 
     417                      &               ::   cdvar    ! name of the variable 
     418      ! 
     419      INTEGER                         ::   if90id   ! temporary integer 
     420      INTEGER                         ::   ivarid   ! NetCDF variable Id 
     421      LOGICAL                         ::   llok     ! temporary logical 
     422      CHARACTER(LEN=100)              ::   clinfo   ! info character 
     423      !--------------------------------------------------------------------- 
     424      ! 
     425      if90id = iom_file(kiomid)%nfid 
     426      IF( PRESENT(cdvar) ) THEN 
     427         ! check the variable exists in the file 
     428         llok = NF90_INQ_VARID( if90id, TRIM(cdvar), ivarid ) == nf90_noerr 
     429         IF( llok ) THEN 
     430            ! check the variable has the attribute required 
     431            llok = NF90_Inquire_attribute(if90id, ivarid, cdatt) == nf90_noerr 
    365432         ELSE 
    366             pv_i0d = -999 
    367          ENDIF 
    368       ENDIF 
    369       !  
    370    END SUBROUTINE iom_nf90_att 
    371  
     433            CALL ctl_warn('iom_nf90_getatt: no variable '//cdvar//' found') 
     434         ENDIF 
     435      ELSE 
     436         llok = NF90_Inquire_attribute(if90id, NF90_GLOBAL, cdatt) == nf90_noerr 
     437         ivarid = NF90_GLOBAL 
     438      ENDIF 
     439! 
     440      IF( llok) THEN 
     441         clinfo = 'iom_nf90_getatt, file: '//TRIM(iom_file(kiomid)%name)//', catt: '//TRIM(cdatt) 
     442         CALL iom_nf90_check(NF90_GET_ATT(if90id, ivarid, cdatt, values=pv_c0d), clinfo) 
     443      ELSE 
     444         CALL ctl_warn('iom_nf90_getatt: no attribute '//cdatt//' found') 
     445         pv_c0d = '!' 
     446      ENDIF 
     447      ! 
     448   END SUBROUTINE iom_nf90_catt 
    372449 
    373450   SUBROUTINE iom_nf90_gettime( kiomid, kvid, ptime, cdunits, cdcalendar ) 
Note: See TracChangeset for help on using the changeset viewer.