Ignore:
Timestamp:
Mar 9, 2026, 10:29:53 AM (8 days ago)
Author:
jbclement
Message:

PEM:

  • Introduction of a configurable display/logging system with options 'out2term', 'out2log', 'verbosity_lvl'. All messages now use verbosity levels ('LVL_NFO', 'LVL_WRN', 'LVL_ERR' and 'LVL_DBG').
  • Code encapsulation improvements with systematic privacy/protection of module variables.
  • Addition of workflow safety checks for required executables, dependencies (e.g. 'ncdump'), input files and callphys keys.
  • Renaming of PEM starting and diagnostic files ("startevol.nc" into "startevo.nc", "diagevol.nc" into "diagevo.nc").

JBC

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.COMMON/libf/evolution/config.F90

    r4091 r4110  
    2323implicit none
    2424
    25 character(7),  parameter :: rundef_name = 'run.def'
    26 character(11), parameter :: run_pcmdef_name = 'run_pcm.def'
    27 character(12), parameter :: callphys_name = 'callphys.def'
     25character(7),  parameter, private :: rundef_name = 'run.def'
     26character(11), parameter, private :: runPCMdef_name = 'run_pcm.def'
     27character(12), parameter          :: callphys_name = 'callphys.def'
    2828
    2929contains
     
    6868use atmosphere,       only: set_atmosphere_config
    6969use stoppage,         only: stop_clean
    70 use display,          only: print_msg
     70use display,          only: print_msg, LVL_NFO
    7171
    7272! DECLARATION
     
    7676! LOCAL VARIABLES
    7777! ---------------
    78 logical(k4) :: here, evol_orbit_l, evol_obl_l, evol_ecc_l, evol_lsp_l, do_soil_l, reg_thprop_dependp_l, do_sorption_l, hybrid
     78logical(k4) :: here, evo_orbit_l, evo_obl_l, evo_ecc_l, evo_lsp_l, do_soil_l, reg_thprop_dependp_l, do_sorption_l, hybrid
    7979logical(k4) :: icetable_equilibrium_l, icetable_dynamic_l, h2oice_flow_l, co2ice_flow_l, do_layering_l, impose_dust_ratio_l
    8080integer(di) :: output_rate_l
     
    8787inquire(file = rundef_name,exist = here)
    8888if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//rundef_name//'" (PEM)!',1)
    89 call print_msg('> Reading "'//rundef_name//'"')
    90 
    91 ! Output
    92 ! ~~~~~~
     89call print_msg('> Reading "'//rundef_name//'"',LVL_NFO)
     90
     91! Outputs
     92! ~~~~~~~
    9393output_rate_l = 1_di ! Default value: every year
    9494call getin('output_rate',output_rate_l)
     
    9696! Orbital parameters
    9797! ~~~~~~~~~~~~~~~~~~
    98 evol_orbit_l = .false.
    99 call getin('evol_orbit',evol_orbit_l)
     98evo_orbit_l = .false.
     99call getin('evo_orbit',evo_orbit_l)
    100100
    101101pem_ini_earth_date = 0_di
    102102call getin('pem_ini_earth_date',pem_ini_earth_date)
    103103
    104 evol_obl_l = .true.
    105 call getin('evol_obl',evol_obl_l)
    106 
    107 evol_ecc_l = .true.
    108 call getin('evol_ecc',evol_ecc_l)
    109 
    110 evol_lsp_l = .true.
    111 call getin('evol_lsp',evol_lsp_l)
     104evo_obl_l = .true.
     105call getin('evo_obl',evo_obl_l)
     106
     107evo_ecc_l = .true.
     108call getin('evo_ecc',evo_ecc_l)
     109
     110evo_lsp_l = .true.
     111call getin('evo_lsp',evo_lsp_l)
    112112
    113113dt_l = 1._dp
     
    193193! Setters
    194194call set_output_config(output_rate_l)
    195 call set_orbit_config(evol_orbit_l,evol_obl_l,evol_ecc_l,evol_lsp_l,max_change_obl_l,max_change_ecc_l,max_change_lsp_l)
     195call set_orbit_config(evo_orbit_l,evo_obl_l,evo_ecc_l,evo_lsp_l,max_change_obl_l,max_change_ecc_l,max_change_lsp_l)
    196196call set_evolution_config(pem_ini_earth_date,dt_l,nmax_yr_run_l)
    197197call set_stopping_crit_config(h2oice_crit_l,co2ice_crit_l,ps_crit_l)
     
    235235use soil,      only: do_soil, reg_thprop_dependp, flux_geo
    236236use sorption,  only: do_sorption
    237 use orbit,     only: evol_orbit
     237use orbit,     only: evo_orbit
    238238use evolution, only: pem_ini_date
    239239use ice_table, only: icetable_equilibrium, icetable_dynamic
    240 use display,   only: print_msg
     240use display,   only: print_msg, LVL_WRN
    241241
    242242! DECLARATION
     
    247247! ----
    248248! Warnings (possible incompatibilities)
    249 if (evol_orbit .and. abs(pem_ini_date) < minieps) call print_msg('Warning: evol_orbit = .true. but the initial date of the PEM is set to 0!')
     249if (evo_orbit .and. abs(pem_ini_date) < minieps) call print_msg('''evo_orbit = .true.'' but the initial date of the PEM is set to 0!',LVL_WRN)
    250250
    251251! Errors (true incompatibilities)
     
    286286use ioipsl_getincom, only: getin
    287287#endif
    288 use atmosphere,      only: CO2cond_ps_PCM
    289288use stoppage,        only: stop_clean
    290 use display,         only: print_msg
     289use display,         only: print_msg, LVL_NFO
     290use atmosphere,      only: set_CO2cond_ps_PCM
    291291
    292292! DECLARATION
     
    297297! ---------------
    298298logical(k4) :: here
     299real(dp)    :: CO2cond_ps_PCM_l
    299300
    300301! CODE
     
    302303inquire(file = callphys_name,exist = here)
    303304if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//callphys_name//'"!',1)
    304 call print_msg('> Reading "'//callphys_name//'"')
    305 
    306 CO2cond_ps_PCM = 1._dp ! Default value
    307 call getin("CO2cond_ps",CO2cond_ps_PCM)
    308 if (CO2cond_ps_PCM < 0._dp .or. CO2cond_ps_PCM > 1._dp) call stop_clean(__FILE__,__LINE__,'Value for ''CO2cond_ps'' is not between 0 and 1. Please, specify a correct value in "'//callphys_name//'"!',1)
     305call print_msg('> Reading "'//callphys_name//'"',LVL_NFO)
     306
     307CO2cond_ps_PCM_l = 1._dp
     308call getin("CO2cond_ps",CO2cond_ps_PCM_l)
     309call set_CO2cond_ps_PCM(CO2cond_ps_PCM_l)
    309310
    310311END SUBROUTINE read_callphys
     
    330331! ------------
    331332use stoppage, only: stop_clean
    332 use display,  only: print_msg
     333use display,  only: print_msg, LVL_NFO, LVL_WRN
    333334use utility,  only: bool2str
    334335
     
    350351! CODE
    351352! ----
    352 inquire(file = run_pcmdef_name,exist = here)
    353 if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//run_pcmdef_name//'"!',1)
    354 call print_msg('> Reading "'//run_pcmdef_name//'"')
    355 open(newunit = funit,file = run_pcmdef_name,status = 'old',form = 'formatted',action = 'read',iostat = ierr)
    356 if (ierr /= 0) call stop_clean(__FILE__,__LINE__,'error opening file "'//run_pcmdef_name//'"!',ierr)
     353inquire(file = runPCMdef_name,exist = here)
     354if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//runPCMdef_name//'"!',1)
     355call print_msg('> Reading "'//runPCMdef_name//'"',LVL_NFO)
     356open(newunit = funit,file = runPCMdef_name,status = 'old',form = 'formatted',action = 'read',iostat = ierr)
     357if (ierr /= 0) call stop_clean(__FILE__,__LINE__,'error opening file "'//runPCMdef_name//'"!',ierr)
    357358
    358359found = .false.
     
    385386close(funit)
    386387
    387 if (.not. found) call print_msg('Warning: key ''hybrid'' not found in the file "'//run_pcmdef_name//'"!')
    388 if (hybrid .eqv. hybrid_in) call print_msg('USING DEFAULTS : hybrid = '//bool2str(hybrid_in))
     388if (.not. found) call print_msg('Key ''hybrid'' not found in the file "'//runPCMdef_name//'"!',LVL_WRN)
     389if (hybrid .eqv. hybrid_in) call print_msg('USING DEFAULTS : hybrid = '//bool2str(hybrid_in),LVL_NFO)
    389390
    390391END SUBROUTINE get_hybrid
     
    392393
    393394!=======================================================================
    394 SUBROUTINE read_controldata()
    395 !-----------------------------------------------------------------------
    396 ! NAME
    397 !     read_controldata
     395SUBROUTINE read_control_data()
     396!-----------------------------------------------------------------------
     397! NAME
     398!     read_control_data
    398399!
    399400! DESCRIPTION
     
    414415use soil,      only: volcapa
    415416use stoppage,  only: stop_clean
    416 use display,   only: print_msg
     417use display,   only: print_msg, LVL_NFO
    417418
    418419! DECLARATION
     
    427428! CODE
    428429! ----
    429 call print_msg('> Reading control data ("'//startfi_name//'")')
     430call print_msg('> Reading control data ("'//startfi_name//'")',LVL_NFO)
    430431! Open the "startfi.nc" file
    431432call open_nc(startfi_name,'read')
     
    443444! Initialize physical data
    444445!     Arguments order: rad, g, mugaz, rcp
    445 call print_msg('    > Initializing physical constants')
     446call print_msg('    > Initializing physical constants',LVL_NFO)
    446447call init_physics(controle(5),controle(7),controle(8),controle(9))
    447448
    448449! Initialize soil data
    449 call print_msg('    > Initializing soil parameters')
     450call print_msg('    > Initializing soil parameters',LVL_NFO)
    450451volcapa = controle(35)
    451452if (abs(volcapa) < minieps) call stop_clean(__FILE__,__LINE__,'volcapa is 0 in "'//startfi_name//'"!',1)
     
    453454! Initialize orbital data
    454455!     Arguments order: Obliquity, Perihelion, Aphelion, Date of perihelion, Year length, Sol length
    455 call print_msg('    > Initializing orbital characteristics of the planet')
     456call print_msg('    > Initializing orbital characteristics of the planet',LVL_NFO)
    456457call init_orbit(controle(18),controle(15),controle(16),controle(17),controle(14),controle(10))
    457458
    458459deallocate(controle)
    459460
    460 END SUBROUTINE read_controldata
     461END SUBROUTINE read_control_data
     462!=======================================================================
     463
     464!=======================================================================
     465SUBROUTINE read_display_config()
     466!-----------------------------------------------------------------------
     467! NAME
     468!     read_display_config
     469!
     470! DESCRIPTION
     471!     Read PEM runtime configuration for display from getin keys, then
     472!     set module-scoped parameters accordingly.
     473!
     474! AUTHORS & DATE
     475!     JB Clement, 03/2026
     476!
     477! NOTES
     478!
     479!-----------------------------------------------------------------------
     480
     481! DEPENDENCIES
     482! ------------
     483#ifdef CPP_IOIPSL
     484use IOIPSL,           only: getin
     485#else
     486! If not using IOIPSL, we still need to use (a local version of) getin
     487use ioipsl_getincom,  only: getin
     488#endif
     489use stoppage,         only: stop_clean
     490use display,          only: set_display_config, LVL_NFO
     491
     492! DECLARATION
     493! -----------
     494implicit none
     495
     496! LOCAL VARIABLES
     497! ---------------
     498logical(k4) :: here, out2term_l, out2log_l
     499integer(di) :: verbosity_lvl_l
     500
     501! CODE
     502! ----
     503inquire(file = rundef_name,exist = here)
     504if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//rundef_name//'" (PEM)!',1)
     505
     506! Display
     507! ~~~~~~~
     508out2term_l = .true.
     509call getin('out2term',out2term_l)
     510
     511out2log_l = .false.
     512call getin('out2log',out2log_l)
     513
     514verbosity_lvl_l = LVL_NFO
     515call getin('verbosity_lvl',verbosity_lvl_l)
     516
     517! Setter
     518call set_display_config(out2term_l,out2log_l,verbosity_lvl_l)
     519
     520END SUBROUTINE read_display_config
    461521!=======================================================================
    462522
Note: See TracChangeset for help on using the changeset viewer.