Ignore:
Timestamp:
Oct 6, 2025, 11:24:25 AM (3 months ago)
Author:
jmauxion
Message:

Mars PCM:
Adding a slow_diagfi flag to the run.def file for 1D model only. When False, the netcdf
file is opened/closed once, thus saving significant computing time. When true,
the opening frequency is at output frequency (required in debug mode).
JM

File:
1 edited

Legend:

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

    r3870 r3923  
    4141      use surfdat_h, only: phisfi
    4242      use geometry_mod, only: cell_area
    43       use time_phylmdz_mod, only: steps_per_sol, outputs_per_sol
    44       use time_phylmdz_mod, only: day_ini
     43      use time_phylmdz_mod, only: steps_per_sol, outputs_per_sol,
     44     &                            day_end, day_ini, slow_diagfi
    4545      USE mod_phys_lmdz_para, only : is_parallel, is_mpi_root,
    4646     &                               is_master, gather
     
    7979
    8080      integer,save :: zitau=0
     81      integer,save :: lastzitau=0
    8182      character(len=27),save :: firstnom='1234567890'
     83      character(len=27),save :: prevnom='1234567890'
     84      character(len=27),save :: lastnom='1234567890'
    8285!$OMP THREADPRIVATE(zitau,firstnom)
    8386
     
    8689!$OMP THREADPRIVATE(ntime)
    8790      integer :: idim,varid
    88       integer :: nid
     91      integer, save :: nid
    8992      character(len=*),parameter :: fichnom="diagfi.nc"
    9093      integer, dimension(4) :: id
     
    130133         ! Compute the output rate
    131134         isample=steps_per_sol/outputs_per_sol
    132 
     135         lastzitau=(day_end-day_ini)*steps_per_sol-1
    133136!$OMP MASTER
    134137  !      Open diagfi.def definition file if there is one:
     
    254257      endif ! if (firstnom.eq.'1234567890')
    255258
    256 ! Increment time index 'zitau' if it is the "fist call" (at given time level)
     259      ! Find lastnom
     260      if (lastnom.eq.'1234567890') then
     261         if (nom.eq.firstnom) then
     262            if (prevnom.ne.'1234567890') then
     263               lastnom=prevnom
     264            endif
     265         endif
     266         prevnom=nom
     267      endif
     268
     269! Increment time index 'zitau' if it is the "first call" (at given time level)
    257270! to writediagfi
    258271!------------------------------------------------------------------------
     
    264277! Write the variables to output file if it's time to do so
    265278!--------------------------------------------------------
    266 
    267279      if ( MOD(zitau+1,isample) .eq.0.) then
    268280     
     
    273285        if (is_master) then
    274286          ! 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
     287         
     288          ! 1D and slow_diagfi=.false. => open/close once
     289          if ((klon_glo.eq.1).and.(.not.slow_diagfi)) then
     290            ! if the very first time to write, open
     291            if ((nom.eq.firstnom).and.((zitau+1)/isample.eq.1)) then
     292              write(*,*) "Open NETCDF file for firstnom=", firstnom, " and zitau=", zitau
     293              ierr=NF_OPEN(fichnom,NF_WRITE,nid) ! open once in all simu
     294            endif
     295          else ! 3D or slow_diagfi=.true. => open/close at output frequency
     296            ierr=NF_OPEN(fichnom,NF_WRITE,nid)           
     297          endif
     298         
     299          if(nom.eq.firstnom) then
    280300            ! We have identified a "first call" (at given date)
    281301            ntime=ntime+1 ! increment # of stored time steps
     
    613633        endif ! of if (dim.eq.3) elseif(dim.eq.2)...
    614634
     635        ! Only the master do it
    615636        if (is_master) then
    616           ! Close until next variable to dump or next dump iteration
    617           ierr= NF_CLOSE(nid)
     637          ! 1D and slow_diagfi=.false. => open/close once
     638          if ((klon_glo.eq.1).and.(.not.slow_diagfi)) then
     639            ! if the very last time to write, close
     640            if ((nom.eq.lastnom).and.(zitau.eq.lastzitau)) then
     641              write(*,*) "Close NETCDF file for lastnom=",lastnom, "and zitau=", zitau
     642              ierr = NF_CLOSE(nid) ! close once in all simu
     643            endif
     644          else ! 3D or slow_diagfi=.true. => open/close at output frequency
     645            ierr = NF_CLOSE(nid)
     646          endif
    618647        endif
    619648
Note: See TracChangeset for help on using the changeset viewer.