Changeset 3282 for trunk


Ignore:
Timestamp:
Mar 21, 2024, 7:52:55 AM (8 months ago)
Author:
emillour
Message:

Mars PCM:
Fix a buggy behavior of wstats: it would fail when using a stats.def file and
when the first (at every time step) variable sent to wstats() was not part of
those listed in stats.def
EM

Location:
trunk/LMDZ.MARS
Files:
2 edited

Legend:

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

    r3274 r3282  
    45784578== 20/03/2024 == LL
    45794579Small update of soil properties (porosity) when running soilwater to simulate the evolution of massive water ice
     4580
     4581== 21/03/2024 == EM
     4582Fix a buggy behavior of wstats: it would fail when using a stats.def file and
     4583when the first (at every time step) variable sent to wstats() was not part of
     4584those listed in stats.def
  • trunk/LMDZ.MARS/libf/phymars/wstats_mod.F90

    r2997 r3282  
    2626! Main routine to call to trigger writing a given field to the "stats.nc" file
    2727
    28 use mod_phys_lmdz_para, only : is_mpi_root, is_master, gather, klon_mpi_begin
     28use mod_phys_lmdz_para, only : is_mpi_root, is_master, klon_mpi_begin
     29use mod_phys_lmdz_transfert_para, only: gather, bcast
    2930use mod_grid_phy_lmdz, only : klon_glo, Grid1Dto2D_glo, &
    3031                              nbp_lon, nbp_lat, nbp_lev, &
     
    5354
    5455! Added to read an optional stats.def file to select outputs
     56logical,save :: check_stats_def=.TRUE. ! to keep track of if stats.def was checked
    5557logical,save :: stats_def ! .true. if there is a stats.def file
    5658integer,save :: n_name_def ! number of fields to output in stats.nc
    57 ! NB: stats_def and n_name_def do not need be threadprivate
    5859integer,parameter :: n_name_def_max=199 ! max number of fields to output
    5960character(len=120),save :: name_def(n_name_def_max)
    6061logical :: getout ! to trigger an early exit if variable not in output list
    6162
    62 !$OMP THREADPRIVATE(stats_def,n_name_def,name_def)
     63!$OMP THREADPRIVATE(check_stats_def,stats_def,n_name_def,name_def)
    6364
    6465! Added to work in parallel mode
     
    8990endif
    9091
    91 ! 1. Initialization (creation of stats.nc file)
    92 if (firstcall) then
    93    firstcall=.false.
    94 
    95 !$OMP MASTER
    96   ! open stats.def definition file if there is one
    97   open(99,file="stats.def",status='old',form='formatted',&
    98        iostat=ierr)
    99   if (ierr.eq.0) then
     92if (check_stats_def) then
     93  ! this step only needs be made a single unique time
     94  ! hence the chack_stats_def flag.
     95 
     96  if (is_master) then
     97   ! Only the master reads the file
     98   ! open stats.def definition file if there is one
     99   open(99,file="stats.def",status='old',form='formatted',&
     100        iostat=ierr)
     101   if (ierr.eq.0) then
    100102    stats_def=.true. ! yes there is a stats.def file
    101103    write(*,*) "*****************"
     
    114116    n_name_def=n-1
    115117    close(99)
    116   else
     118   else
    117119    stats_def=.false. ! no stats.def file; output all fields sent to wstats
    118   endif ! of if (ierr.eq.0)
    119 !$OMP END MASTER
    120 !$OMP BARRIER
    121 
    122    firstvar=trim((nom))
     120   endif ! of if (ierr.eq.0)
     121
     122  endif ! of if (is_master)
     123   
     124  ! share the info gathered by master with all other cores
     125  call bcast(stats_def)
     126  call bcast(n_name_def)
     127  do n=1,n_name_def
     128    call bcast(name_def(n))
     129  enddo
     130 
     131  check_stats_def=.false.
     132endif ! of if (check_stats_def)
     133
     134! 1. Initialization (creation of stats.nc file)
     135if (firstcall) then
     136   firstcall=.false.
     137
     138   ! identify the first variable name with which wstats is called in
     139   ! a time step
     140   if (stats_def) then
     141     ! check if "nom" is in the wanted output list. If it is then
     142     ! it is the sought "first variable"; if not then skip all the
     143     ! rest and reset "firstcall" to true
     144     getout=.true.
     145     do n=1,n_name_def
     146       ! look for the variable's name in the list
     147       if (trim(name_def(n)).eq.nom) then
     148         getout=.false.
     149         ! found it, no need to scan the rest of the list exit loop
     150         firstvar=trim((nom))
     151         exit
     152       endif
     153     enddo
     154     if (getout) then
     155       ! variable not in the list so exit routine now
     156       firstcall=.true.
     157       return
     158     endif
     159   else
     160     ! without a stats.def, the very first call to stats contains first
     161     ! variable name
     162     firstvar=trim((nom))
     163   endif ! of if (stats_def)
     164   
     165   ! initialize stats.nc file
    123166   call inistats(ierr)
     167   
     168   ! allocate arrays that will be needed later
    124169   if (klon_glo>1) then ! general case, 3D GCM
    125170     allocate(mean3d(nbp_lon+1,nbp_lat,nbp_lev))
     
    137182     allocate(dx2(1,1))
    138183   endif
     184
    139185endif ! of if (firstcall)
    140186
Note: See TracChangeset for help on using the changeset viewer.