Ignore:
Timestamp:
Jan 20, 2026, 10:46:15 AM (2 days ago)
Author:
debatzbr
Message:

Pluto PCM: Adding a slow_diagfi flag for 1D model from Generic PCM (revision 3928).
BBT

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.PLUTO/libf/phypluto/writediagfi.F

    r3749 r4027  
    4242      use geometry_mod, only: cell_area
    4343      use time_phylmdz_mod, only: diagfi_output_rate,dtphys,daysec
    44       use time_phylmdz_mod, only: day_ini
     44      use time_phylmdz_mod, only: day_ini, nday, 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       character(len=40),save :: firstnom='1234567890'
    82 !$OMP THREADPRIVATE(zitau,firstnom)
     81      integer,save :: lastzitau=0
     82      character(len=27),save :: firstnom='1234567890'
     83      character(len=27),save :: prevnom='1234567890'
     84      character(len=27),save :: lastnom='1234567890'
     85!$OMP THREADPRIVATE(zitau,lastzitau,firstnom,prevnom,lastnom)
    8386
    8487! Ajouts
     
    8689!$OMP THREADPRIVATE(ntime)
    8790      integer :: idim,varid
    88       integer :: nid
     91      integer, save :: nid
     92!$OMP THREADPRIVATE(nid)
    8993      character(len=*),parameter :: fichnom="diagfi.nc"
    9094      integer, dimension(4) :: id
     
    132136      IF (firstcall) THEN
    133137         firstcall=.false.
     138
     139         ! Compute the lastzitau (i.e. last timestep-1)
     140               lastzitau=nday*nint(daysec/dtphys)-1
     141               if (MOD(lastzitau+1,diagfi_output_rate).ne.0.) then
     142                 ! If so, output rate is less than once per sol
     143                 ! We must adjust zitau to
     144                 lastzitau=lastzitau-MOD(lastzitau+1,diagfi_output_rate)
     145               endif
    134146
    135147!$OMP MASTER
     
    256268         ENDIF
    257269
     270         ierr= NF_CLOSE(nid) ! Close the NETCDF file once initialized
     271
    258272         endif ! of if (is_master)
    259273
    260       else
    261 
    262          if (is_master) then
    263            ! only the master is required to do this
    264 
    265            ! Open the NetCDF file
    266            ierr = NF_OPEN(fichnom,NF_WRITE,nid)
    267          endif ! of if (is_master)
    268 
    269274      endif ! if (firstnom.eq.'1234567890')
     275
     276      ! Find lastnom
     277            if (lastnom.eq.'1234567890') then
     278               if (nom.eq.firstnom) then
     279                  if (prevnom.ne.'1234567890') then
     280                     lastnom=prevnom
     281                  endif
     282               endif
     283               prevnom=nom
     284            endif
    270285
    271286! Increment time index 'zitau' if it is the "fist call" (at given time level)
     
    288303
    289304        if (is_master) then
    290            ! only the master is required to do this
     305          ! only the master is required to do this
     306
     307                ! 1D and slow_diagfi=.false. => open/close once
     308                if ((klon_glo.eq.1).and.(.not.slow_diagfi)) then
     309                  ! if the very first time to write, open
     310            if ((nom.eq.firstnom).and.
     311     &         (((zitau+1)/diagfi_output_rate).eq.1)) then
     312                    write(*,*) "Open NETCDF file for firstnom=", firstnom
     313                    write(*,*) "zitau=", zitau
     314                    ierr=NF_OPEN(fichnom,NF_WRITE,nid) ! open once in all simu
     315                  endif
     316                else ! 3D or slow_diagfi=.true. => open/close at output frequency
     317                  ierr=NF_OPEN(fichnom,NF_WRITE,nid)           
     318                endif
     319
    291320        if (nom.eq.firstnom) then
    292321        ! We have identified a "first call" (at given date)
     
    625654        endif ! of if (dim.eq.3) elseif(dim.eq.2)...
    626655
     656        ! Only the master do it
     657                    if (is_master) then
     658                      ! 1D and slow_diagfi=.false. => open/close once
     659                      if ((klon_glo.eq.1).and.(.not.slow_diagfi)) then
     660                        ! if the very last time to write, close
     661                        if ((nom.eq.lastnom).and.(zitau.eq.lastzitau)) then
     662                          write(*,*) "Close NETCDF file for lastnom=",lastnom
     663                          write(*,*) "zitau=",zitau
     664                          ierr = NF_CLOSE(nid) ! close once in all simu
     665                        endif
     666                      else ! 3D or slow_diagfi=.true. => open/close at output frequency
     667                        ierr = NF_CLOSE(nid)
     668                      endif
     669                    endif
     670
    627671      endif ! of if ( MOD(zitau+1,isample) .eq.0.)
    628672
    629       if (is_master) then
    630         ierr= NF_CLOSE(nid)
    631       endif
    632 
    633673      end
Note: See TracChangeset for help on using the changeset viewer.