Changeset 3870 for trunk/LMDZ.MARS/libf


Ignore:
Timestamp:
Jul 29, 2025, 3:51:19 PM (6 months ago)
Author:
jmauxion
Message:

Mars PCM:
In writediag* routines, the files are now opened and closed only at dump time instead of every physical step (sensible speed up in 1D mainly).
JM

Location:
trunk/LMDZ.MARS/libf/phymars
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.MARS/libf/phymars/writediagfi.F

    r3369 r3870  
    7474      REAL area((nbp_lon+1),nbp_lat)
    7575
    76       integer isample
     76      integer, save :: isample
    7777      integer ierr,ierr2
    7878      integer i,j,l, ig0
     
    122122
    123123!***************************************************************
    124 ! Compute the output rate
    125 
    126       isample=steps_per_sol/outputs_per_sol
    127 
    128 !***************************************************************
    129124
    130125! At very first call, check if there is a "diagfi.def" to use and read it
     
    132127      IF (firstcall) THEN
    133128         firstcall=.false.
     129
     130         ! Compute the output rate
     131         isample=steps_per_sol/outputs_per_sol
    134132
    135133!$OMP MASTER
     
    251249         ENDIF
    252250
     251         ierr= NF_CLOSE(nid) ! Close the NETCDF file once initialized
     252
    253253         endif ! of if (is_master)
    254 
    255       else
    256 
    257          if (is_master) then
    258            ! only the master is required to do this
    259 
    260            ! Open the NetCDF file
    261            ierr = NF_OPEN(fichnom,NF_WRITE,nid)
    262          endif ! of if (is_master)
    263 
    264254      endif ! if (firstnom.eq.'1234567890')
    265255
     
    276266
    277267      if ( MOD(zitau+1,isample) .eq.0.) then
    278 
     268     
    279269! Compute/write/extend 'Time' coordinate (date given in days)
    280270! (done every "first call" (at given time level) to writediagfi)
    281271! Note: date is incremented as 1 step ahead of physics time
    282272!--------------------------------------------------------
    283 
    284273        if (is_master) then
    285            ! only the master is required to do this
    286         if (nom.eq.firstnom) then
    287         ! We have identified a "first call" (at given date)
    288            ntime=ntime+1 ! increment # of stored time steps
    289            ! compute corresponding date (in days and fractions thereof)
    290            date=(zitau +1.)/steps_per_sol
    291            ! Get NetCDF ID of 'Time' variable
    292            ierr= NF_INQ_VARID(nid,"Time",varid)
    293            ! Write (append) the new date to the 'Time' array
    294 !#ifdef NC_DOUBLE
    295 !           ierr= NF_PUT_VARA_DOUBLE(nid,varid,[ntime],[1],[date])
     274          ! only the master is required to do this
     275
     276          ! Time to write data, open NETCDF file
     277          ierr=NF_OPEN(fichnom,NF_WRITE,nid)
     278
     279          if (nom.eq.firstnom) then
     280            ! We have identified a "first call" (at given date)
     281            ntime=ntime+1 ! increment # of stored time steps
     282            ! compute corresponding date (in days and fractions thereof)
     283            date=(zitau +1.)/steps_per_sol
     284            ! Get NetCDF ID of 'Time' variable
     285            ierr= NF_INQ_VARID(nid,"Time",varid)
     286            ! Write (append) the new date to the 'Time' array
     287      !#ifdef NC_DOUBLE
     288            ! ierr= NF_PUT_VARA_DOUBLE(nid,varid,[ntime],[1],[date])
    296289!#else
    297            ierr= NF_PUT_VARA_REAL(nid,varid,[ntime],[1],[date])
     290            ierr= NF_PUT_VARA_REAL(nid,varid,[ntime],[1],[date])
    298291!#endif
    299            if (ierr.ne.NF_NOERR) then
    300               write(*,*) "***** PUT_VAR matter in writediagfi_nc"
    301               write(*,*) "***** with time"
    302               write(*,*) 'ierr=', ierr,": ",NF_STRERROR(ierr) 
    303 c             call abort
    304            endif
    305 
    306            write(6,*)'WRITEDIAGFI: date= ', date
    307         end if ! of if (nom.eq.firstnom)
    308 
     292            if (ierr.ne.NF_NOERR) then
     293                write(*,*) "***** PUT_VAR matter in writediagfi_nc"
     294                write(*,*) "***** with time"
     295                write(*,*) 'ierr=', ierr,": ",NF_STRERROR(ierr) 
     296c               call abort
     297            endif
     298
     299            write(6,*)'WRITEDIAGFI: date= ', date
     300          end if ! of if (nom.eq.firstnom)
    309301        endif ! of if (is_master)
    310302
     
    621613        endif ! of if (dim.eq.3) elseif(dim.eq.2)...
    622614
     615        if (is_master) then
     616          ! Close until next variable to dump or next dump iteration
     617          ierr= NF_CLOSE(nid)
     618        endif
     619
    623620      endif ! of if ( MOD(zitau+1,isample) .eq.0.)
    624621
    625       if (is_master) then
    626         ierr= NF_CLOSE(nid)
    627       endif
    628 
    629622      end
  • trunk/LMDZ.MARS/libf/phymars/writediagmicrofi.F

    r3369 r3870  
    8181      REAL area((nbp_lon+1),nbp_lat)
    8282
    83       integer isample
     83      integer, save :: isample
    8484      integer ierr,ierr2
    8585      integer i,j,l, ig0
     
    124124#endif
    125125
    126 !***************************************************************
    127 ! Compute the output rate
    128 
    129       isample = steps_per_sol/outputs_per_sol
    130 
    131 !***************************************************************
    132 
    133126! At very first call, check if there is a "diagfi.def" to use and read it
    134127! -----------------------------------------------------------------------
    135128      IF (firstcall) THEN
    136129         firstcall=.false.
     130         
     131         ! Compute the output rate
     132         isample = steps_per_sol/outputs_per_sol
    137133
    138134!$OMP MASTER
     
    264260         ENDIF
    265261
     262         ierr= NF_CLOSE(nid) ! Close the NETCDF file once initialized
     263
    266264         endif ! of if (is_master)
    267 
    268       else
    269 
    270          if (is_master) then
    271            ! only the master is required to do this
    272 
    273            ! Open the NetCDF file
    274            ierr = NF_OPEN(fichnom,NF_WRITE,nid)
    275          endif ! of if (is_master)
    276 
    277265      endif ! if (firstnom.eq.'1234567890')
    278266
     
    297285        if (is_master) then
    298286           ! only the master is required to do this
     287
     288           ! Time to write data, open NETCDF file
     289           ierr=NF_OPEN(fichnom,NF_WRITE,nid)
     290
    299291        if ((nom.eq.firstnom) .and. (microstep.eq.1)) then
    300292        ! We have identified a "first call" (at given date)
     
    669661        endif ! of if (dim.eq.3) elseif(dim.eq.2)...
    670662
     663        if (is_master) then
     664          ! Close until next variable to dump or next dump iteration
     665          ierr= NF_CLOSE(nid)
     666        endif
     667
    671668      endif ! of if ( MOD(zitau+1,isample) .eq.0.)
    672 
    673       if (is_master) then
    674         ierr= NF_CLOSE(nid)
    675       endif
    676 
     669     
    677670      end
  • trunk/LMDZ.MARS/libf/phymars/writediagsoil.F90

    r3369 r3870  
    159159     call iniwritesoil(nid,ngrid,inertiafi_glo(1,:),areafi_glo(1),1,1,nsoilmx,mlayer)
    160160   endif
     161   
     162   ierr= NF_CLOSE(nid) ! Close the NETCDF file once initialized
    161163
    162164  endif ! of if (is_master)
     
    164166  ! set zitau to -1 to be compatible with zitau incrementation step below
    165167  zitau=-1
    166  
    167 else
    168   ! If not an initialization call, simply open the NetCDF file
    169   if (is_master) then
    170    ierr=NF_OPEN(filename,NF_WRITE,nid)
    171   endif
    172168endif ! of if (firstname.eq."1234567890")
    173169
     
    180176! 3. Write data, if the time index matches the sample rate
    181177if (mod(zitau+1,isample).eq.0) then
     178  if (is_master) then
     179    ! only the master is required to do this
     180
     181    ! Time to write data, open NETCDF file
     182    ierr=NF_OPEN(filename,NF_WRITE,nid)
    182183
    183184! 3.1 If first call at this date, update 'time' variable
    184   if (name.eq.firstname) then
    185     ntime=ntime+1
    186     date=float(zitau+1)/float(steps_per_sol)
    187    
    188     if (is_master) then
    189      ! Get NetCDF ID for "time"
    190      ierr=NF_INQ_VARID(nid,"time",varid)
    191      ! Add the current value of date to the "time" array
     185    if (name.eq.firstname) then
     186      ntime=ntime+1
     187      date=float(zitau+1)/float(steps_per_sol)
     188      ! Get NetCDF ID for "time"
     189      ierr=NF_INQ_VARID(nid,"time",varid)
     190      ! Add the current value of date to the "time" array
    192191!#ifdef NC_DOUBLE
    193 !    ierr=NF_PUT_VARA_DOUBLE(nid,varid,ntime,1,date)
     192      ! ierr=NF_PUT_VARA_DOUBLE(nid,varid,ntime,1,date)
    194193!#else
    195      ierr=NF_PUT_VARA_REAL(nid,varid,[ntime],[1],[date])
     194      ierr=NF_PUT_VARA_REAL(nid,varid,[ntime],[1],[date])
    196195!#endif
    197196     if (ierr.ne.NF_NOERR) then
     
    199198      call abort_physic("writediagsoil","failed writing time",1)
    200199     endif
    201     endif ! of if (is_master)
    202   endif ! of if (name.eq.firstname)
     200    endif ! of if (name.eq.firstname)
     201  endif ! of if (is_master)
    203202
    204203! 3.2 Write the variable to the NetCDF file
     
    409408
    410409endif ! of if (dimpx.eq.3) elseif (dimpx.eq.2) ...
     410
     411! 4. Close the NetCDF file
     412  if (is_master) then
     413    ! Close until next variable to dump or next dump iteration
     414    ierr= NF_CLOSE(nid)
     415  endif
     416
    411417endif ! of if (mod(zitau+1,isample).eq.0)
    412418
    413 ! 4. Close the NetCDF file
    414 if (is_master) then
    415   ierr=NF_CLOSE(nid)
    416 endif
    417 
    418419end subroutine writediagsoil
    419420
Note: See TracChangeset for help on using the changeset viewer.