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 11405 for NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/OCE/SBC/sbcblk.F90 – NEMO

Ignore:
Timestamp:
2019-08-06T15:16:49+02:00 (5 years ago)
Author:
andmirek
Message:

ticket #2195: read weights for blk using XIOS

File:
1 edited

Legend:

Unmodified
Added
Removed
  • NEMO/branches/2019/dev_r11351_fldread_with_XIOS/src/OCE/SBC/sbcblk.F90

    r10535 r11405  
    280280         ! 
    281281      ENDIF 
     282 
     283      IF(lxios_blkw) THEN 
     284         CALL iom_blk_wgt_init( cbwxios_context ) 
     285         CALL iom_swap( cxios_context ) 
     286      ENDIF 
     287       
    282288      ! 
    283289   END SUBROUTINE sbc_blk_init 
     
    681687      ! 
    682688   END FUNCTION L_vap 
     689 
     690   SUBROUTINE iom_blk_wgt_init( cdname, ld_tmppatch )  
     691#if defined key_iomput 
     692      use xios 
     693#endif 
     694      !!---------------------------------------------------------------------- 
     695      !!                     ***  ROUTINE   *** 
     696      !! 
     697      !! ** Purpose :   initialize context for reading weights for surface 
     698      !!                forcing 
     699      !! 
     700      !!---------------------------------------------------------------------- 
     701      CHARACTER(len=*),           INTENT(in)  :: cdname 
     702      LOGICAL         , OPTIONAL, INTENT(in)  :: ld_tmppatch 
     703#if defined key_iomput 
     704      ! 
     705      INTEGER, PARAMETER :: lcname = 26 
     706      CHARACTER(len=lc) :: clname 
     707      INTEGER           :: ji, jkmin 
     708      LOGICAL ::   ll_tmppatch = .TRUE.    !: seb: patch before we remove periodicity 
     709      INTEGER ::   nldi_save, nlei_save    !:      and close boundaries in output files 
     710      INTEGER ::   nldj_save, nlej_save    !: 
     711      LOGICAL ::   ll_global = .FALSE.     !: do we have variable on model grid 
     712      CHARACTER(len=lc), DIMENSION( jpts) :: cg_name(jpts) 
     713      CHARACTER(len=1), DIMENSION(lcname) :: cname 
     714      CHARACTER(len=lc)               :: cfname ! file name without .nc 
     715      TYPE(xios_duration)               :: dtime    = xios_duration(0, 0, 0, 0, 0, 0), & 
     716                                           outp_frq = xios_duration(0, 0, 0, 0, 0, 0) 
     717      TYPE(xios_domaingroup)            :: domaingroup_hdl 
     718      TYPE(xios_domain)                 :: domain_hdl 
     719      TYPE(xios_axisgroup)              :: axisgroup_hdl 
     720      TYPE(xios_axis)                   :: axis_hdl 
     721      TYPE(xios_scalar)                 :: scalar_hdl 
     722      TYPE(xios_scalargroup)            :: scalargroup_hdl 
     723      TYPE(xios_file)                   :: file_hdl 
     724      TYPE(xios_filegroup)              :: filegroup_hdl 
     725      TYPE(xios_field)                  :: field_hdl 
     726      INTEGER                           :: jf, ni, nj, ipos, jfld 
     727      INTEGER, DIMENSION(3)             :: ndims         ! size of each dimension. this is surface  
     728                                                         ! forcing, not more than 3: (x, y, t) 
     729      INTEGER                           :: ndim          ! number if dimensions  
     730      INTEGER                           :: inum          ! file id 
     731      INTEGER                           :: ivid          ! varable id in netcdf file 
     732      CHARACTER (len=5)                 :: aname         !name of the field in wght file 
     733      INTEGER                           :: numwgt        ! 
     734      LOGICAL                           :: lfound 
     735      INTEGER                           :: jg, id, jn 
     736       
     737 
     738      cname(:)= (/'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', & 
     739                  'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', & 
     740                  'u', 'v', 'w', 'x', 'y', 'z'/) 
     741      !!---------------------------------------------------------------------- 
     742      ! 
     743      ! seb: patch before we remove periodicity and close boundaries in output files 
     744      IF ( ll_tmppatch ) THEN 
     745         nldi_save = nldi   ;   nlei_save = nlei 
     746         nldj_save = nldj   ;   nlej_save = nlej 
     747         IF( nimpp           ==      1 ) nldi = 1 
     748         IF( nimpp + jpi - 1 == jpiglo ) nlei = jpi 
     749         IF( njmpp           ==      1 ) nldj = 1 
     750         IF( njmpp + jpj - 1 == jpjglo ) nlej = jpj 
     751      ENDIF 
     752      ! 
     753      jfld = SIZE(sf) 
     754 
     755      IF(jfld > lcname) THEN 
     756      STOP 'lcname number is too small' 
     757      ENDIF 
     758 
     759      clname = cdname 
     760      IF( TRIM(Agrif_CFixed()) /= '0' )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(cdname) 
     761      CALL xios_context_initialize(TRIM(clname), mpi_comm_oce) 
     762      CALL iom_swap( cdname ) 
     763      ! Calendar type is now defined in xml file  
     764      SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL 
     765      CASE ( 1)   ; CALL xios_define_calendar( TYPE = "Gregorian", time_origin = xios_date(1948, 01, 01, 00, 00, 00), & 
     766          &                                    start_date = xios_date(nyear, nmonth, nday,00,00,00) ) 
     767      CASE ( 0)   ; CALL xios_define_calendar( TYPE = "NoLeap"   , time_origin = xios_date(1948, 01, 01, 00, 00, 00), & 
     768          &                                    start_date = xios_date(nyear, nmonth, nday,00,00,00) ) 
     769      CASE (30)   ; CALL xios_define_calendar( TYPE = "D360"     , time_origin = xios_date(1948, 01, 01, 00, 00, 00), & 
     770          &                                    start_date = xios_date(nyear, nmonth, nday, 00, 00, 00) ) 
     771      END SELECT 
     772 
     773 
     774      dtime%month = 1 
     775      CALL xios_set_timestep( dtime ) 
     776 
     777      CALL xios_get_handle("domain_definition",domaingroup_hdl) 
     778      CALL xios_add_child(domaingroup_hdl, domain_hdl, "grid_global") 
     779      ni = nlei-nldi+1 
     780      nj = nlej-nldj+1 
     781      CALL xios_set_domain_attr("grid_global", ni_glo=jpiglo, nj_glo=jpjglo, ibegin=nimpp+nldi-2, jbegin=njmpp+nldj-2, ni=ni, nj=nj) 
     782      CALL xios_set_domain_attr("grid_global", data_dim=2, data_ibegin = 1-nldi, data_ni = jpi, data_jbegin = 1-nldj, data_nj = jpj) 
     783      CALL xios_set_domain_attr("grid_global", type='curvilinear') 
     784 
     785      CALL xios_get_handle("file_definition", filegroup_hdl ) 
     786 
     787      DO jf = 1, jfld 
     788!do we have weights file defined already? 
     789         lfound = .FALSE. 
     790         DO jg = 1, jf-1 
     791            IF(TRIM(sf(jf)%wgtname) == TRIM(sf(jg)%wgtname)) THEN 
     792               IF(lwp) write(numout, *) TRIM(sf(jf)%wgtname),' already defined, skipping ' 
     793               lfound = .TRUE. 
     794               exit 
     795            ENDIF 
     796         ENDDO 
     797         IF(lfound) cycle 
     798!add next weights file 
     799         ipos = index(sf(jf)%wgtname,'.nc') 
     800         cfname(1:lc) = " " 
     801         IF(ipos > 0) THEN 
     802          cfname(1:ipos-1) = sf(jf)%wgtname(1:ipos-1) 
     803         ELSE 
     804          cfname(1:lc) = sf(jf)%wgtname(1:lc) 
     805         ENDIF 
     806 
     807         CALL xios_add_child(filegroup_hdl, file_hdl, cname(jf)) 
     808         CALL xios_set_file_attr( cname(jf), name=TRIM(cfname),           & 
     809                type="one_file", par_access="collective", enabled=.TRUE., & 
     810                output_freq=xios_timestep, mode="read") 
     811 
     812         CALL iom_open ( sf(jf)%wgtname, inum ) 
     813         id = iom_varid(inum, 'src05', ldstop=.FALSE.) 
     814         IF(id <= 0) THEN 
     815             numwgt = 4 
     816         ELSE 
     817             numwgt = 16 
     818         ENDIF 
     819         CALL iom_close ( inum ) 
     820!define variables in weights file. Because all files have the same names src01, 
     821!dst01, ... add filename to the name to uniquely identify variables  
     822         aname = ' ' 
     823         DO jn = 1, numwgt 
     824            WRITE(aname,'(a3,i2.2)') 'src',jn 
     825            CALL xios_add_child(file_hdl, field_hdl, TRIM(aname)//TRIM(sf(jf)%wgtname)) 
     826            CALL xios_set_attr (field_hdl, enabled = .TRUE., & 
     827                          name = TRIM(aname), domain_ref="grid_global", & 
     828                          operation = "instant") 
     829            CALL xios_add_child(file_hdl, field_hdl, TRIM(aname)//TRIM(sf(jf)%wgtname)) 
     830            CALL xios_set_attr (field_hdl, enabled = .TRUE., & 
     831                          name = TRIM(aname), domain_ref="grid_global", & 
     832                          operation = "instant")  
     833         ENDDO  
     834      ENDDO    
     835 
     836 
     837      CALL xios_close_context_definition() 
     838      CALL xios_update_calendar( 0 ) 
     839 
     840      IF ( ll_tmppatch ) THEN 
     841         nldi = nldi_save   ;   nlei = nlei_save 
     842         nldj = nldj_save   ;   nlej = nlej_save 
     843      ENDIF 
     844#endif 
     845      ! 
     846   END SUBROUTINE iom_blk_wgt_init 
     847 
    683848 
    684849#if defined key_si3 
Note: See TracChangeset for help on using the changeset viewer.