Changeset 4130 for trunk/LMDZ.GENERIC


Ignore:
Timestamp:
Mar 16, 2026, 10:51:10 AM (3 weeks ago)
Author:
emillour
Message:

Generic PCM:
Follow-up of previous commit, cleanup output of soil variables in diagsoil.nc
when not using XIOS. Added logical flag "diagsoil" (default .false.) to trigger
outputs in diagsoil.nc
EM

Location:
trunk/LMDZ.GENERIC
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.GENERIC/changelog.txt

    r4121 r4130  
    22082208== 12/03/2026 == CM
    22092209Added subsurface outputs for XIOS, and outputting tsoil for XIOS.
     2210
     2211== 16/03/2026 == EM
     2212Follow-up of previous commit, cleanup output of soil variables in diagsoil.nc
     2213when not using XIOS. Added logical flag "diagsoil" (default .false.) to trigger
     2214outputs in diagsoil.nc
  • trunk/LMDZ.GENERIC/libf/phygeneric/inifis_mod.F90

    r4126 r4130  
    2525  use callkeys_mod
    2626  use wstats_mod, only: callstats
     27  use writediagsoil_mod, only: diagsoil
    2728  use ioipsl_getin_p_mod, only : getin_p
    2829  use mod_phys_lmdz_para, only : is_parallel, is_master, bcast
     
    259260     call getin_p("callstats",callstats)
    260261     if (is_master) write(*,*) trim(rname)//": callstats = ",callstats
     262
     263     if (is_master) write(*,*) trim(rname)//&
     264       ": Write sub-surface fields in file diagsoil.nc ?"
     265     diagsoil=.false. ! default value
     266     call getin_p("diagsoil",diagsoil)
     267     if (is_master) write(*,*) trim(rname)//": diagsoil = ",diagsoil
    261268
    262269     if (is_master) write(*,*) trim(rname)//&
  • trunk/LMDZ.GENERIC/libf/phygeneric/iniwritesoil.F90

    r1531 r4130  
     1module iniwritesoil_mod
     2
     3implicit none
     4
     5contains
     6
    17subroutine iniwritesoil(nid,ngrid,inertia,area,nbplon,nbplat)
    28
     
    271277
    272278end subroutine iniwritesoil
     279
     280end module iniwritesoil_mod
  • trunk/LMDZ.GENERIC/libf/phygeneric/writediagsoil.F90

    r3893 r4130  
    22
    33implicit none
     4
     5logical,save :: diagsoil ! global flag to trigger generating a diagsoil.nc
     6                         ! file or not. Initialized in inifis()
     7!$OMP THREADPRIVATE(diagsoil)
    48
    59contains
     
    2428use mod_grid_phy_lmdz, only : klon_glo, Grid1Dto2D_glo, &
    2529                              nbp_lon, nbp_lat
     30use mod_grid_phy_lmdz, only: grid_type, unstructured
     31use iniwritesoil_mod, only: iniwritesoil
    2632
    2733implicit none
     
    7985#endif
    8086
     87! 0. Do we ouput a diagsoil.nc file? If not just bail out now.
     88if(.not.diagsoil) return
     89
     90! additional check: one can only output diagsoil.nc files
     91! in lon-lat case (or 1D)
     92if (grid_type==unstructured) then
     93  write(*,*) "writediagsoil: Error !!!"
     94  write(*,*) "diagsoil.nc outputs not possible on unstructured grids!!"
     95  call abort_physic("writediagsoil","impossible on unstructured grid",1)
     96endif
     97
    8198! 1. Initialization step
    8299if (firstname.eq."1234567890") then
     
    100117    call abort_physic("writediagsoil","Unable to crzate output file",1)
    101118   endif
     119  endif ! of if ((is_master)
    102120
    103121#ifdef CPP_PARA
     
    111129#endif
    112130
     131  if (is_master) then
    113132   ! build inertia() and area()
    114133   if (klon_glo>1) then
     
    139158   endif
    140159
     160   ierr= NF_CLOSE(nid) ! Close the NETCDF file once initialized
     161
    141162  endif ! of if (is_master)
    142163
     
    144165  zitau=-1
    145166
    146 else
    147   ! If not an initialization call, simply open the NetCDF file
    148   if (is_master) then
    149    ierr=NF_OPEN(filename,NF_WRITE,nid)
    150   endif
    151167endif ! of if (firstname.eq."1234567890")
    152168
     
    159175! 3. Write data, if the time index matches the sample rate
    160176if (mod(zitau+1,diagfi_output_rate).eq.0) then
     177  if (is_master) then
     178    ! only the master is required to do this
     179
     180    ! Time to write data, open NETCDF file
     181    ierr=NF_OPEN(filename,NF_WRITE,nid)
    161182
    162183! 3.1 If first call at this date, update 'time' variable
     
    164185    ntime=ntime+1
    165186    date=(zitau+1)*(dtphys/daysec)
    166     ! Note: day_step is known from control.h
    167 
    168     if (is_master) then
    169187     ! Get NetCDF ID for "time"
    170188     ierr=NF_INQ_VARID(nid,"time",varid)
     
    173191!     ierr=NF_PUT_VARA_DOUBLE(nid,varid,ntime,1,date)
    174192!#else
    175      ierr=NF_PUT_VARA_REAL(nid,varid,ntime,1,date)
     193     ierr=NF_PUT_VARA_REAL(nid,varid,[ntime],[1],[date])
    176194!#endif
    177195     if (ierr.ne.NF_NOERR) then
    178196      call abort_physic("writediagsoil", "Failed writing date to time variable",1)
     197      call abort_physic("writediagsoil","failed writing time",1)
    179198     endif
    180     endif ! of if (is_master)
    181   endif ! of if (name.eq.firstname)
     199    endif ! of if (name.eq.firstname)
     200  endif ! of if (is_master)
    182201
    183202! 3.2 Write the variable to the NetCDF file
    184203if (dimpx.eq.3) then ! Case of a 3D variable
    185204  ! A. Recast data along 'dynamics' grid
     205  if (klon_glo>1) then ! General case
    186206#ifdef CPP_PARA
    187207  ! gather field on a "global" (without redundant longitude) array
     
    197217!$OMP BARRIER
    198218#else
    199   if (klon_glo>1) then ! General case
    200219   do l=1,nsoilmx
    201220    ! handle the poles
     
    213232    enddo
    214233   enddo
     234#endif
    215235  else ! 1D model case
    216236   data3_1d(1,1:nsoilmx)=px(1,1:nsoilmx)
    217237  endif
    218 #endif
    219238
    220239  ! B. Write (append) the variable to the NetCDF file
     
    270289
    271290  ! A. Recast data along 'dynamics' grid
     291  if (klon_glo>1) then ! General case
    272292#ifdef CPP_PARA
    273293  ! gather field on a "global" (without redundant longitude) array
     
    284304!$OMP BARRIER
    285305#else
    286   if (klon_glo>1) then ! general case
    287306    ! handle the poles
    288307    do i=1,nbp_lon+1
     
    298317      data2(nbp_lon+1,j)=data2(1,j) ! extra (modulo) longitude
    299318    enddo
     319#endif
    300320  else ! 1D model case
    301321    data2_1d=px(1,1)
    302322  endif
    303 #endif
    304323
    305324  ! B. Write (append) the variable to the NetCDF file
     
    340359    ierr=NF_PUT_VARA_REAL(nid,varid,corners,edges,data2)
    341360  else
    342     ierr=NF_PUT_VARA_REAL(nid,varid,corners,edges,data2_1d)
     361    ierr=NF_PUT_VARA_REAL(nid,varid,corners,edges,[data2_1d])
    343362  endif
    344363!#endif
     
    380399!  ierr=NF_PUT_VARA_DOUBLE(nid,varid,corners,edges,data0)
    381400!#else
    382   ierr=NF_PUT_VARA_REAL(nid,varid,corners,edges,data0)
     401  ierr=NF_PUT_VARA_REAL(nid,varid,corners,edges,[data0])
    383402!#endif
    384403  if (ierr.ne.NF_NOERR) then
     
    388407
    389408endif ! of if (dimpx.eq.3) elseif (dimpx.eq.2) ...
     409
     410! 4. Close the NetCDF file
     411  if (is_master) then
     412    ! Close until next variable to dump or next dump iteration
     413    ierr=NF_CLOSE(nid)
     414  endif
     415
    390416endif ! of if (mod(zitau+1,diagfi_output_rate).eq.0)
    391417
    392 ! 4. Close the NetCDF file
    393 if (is_master) then
    394   ierr=NF_CLOSE(nid)
    395 endif
    396 
    397418end subroutine writediagsoil
    398419
Note: See TracChangeset for help on using the changeset viewer.