Ignore:
Timestamp:
Jul 29, 2025, 3:51:19 PM (5 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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.