Ignore:
Timestamp:
Dec 16, 2025, 4:39:24 PM (4 weeks ago)
Author:
jbclement
Message:

PEM:
Apply documentation template everywhere: standardized headers format with short description, separators between functions/subroutines, normalized code sections, aligned dependencies/arguments/variables declaration.
JBC

File:
1 edited

Legend:

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

    r3989 r3991  
    11MODULE xios_data
    2 
     2!-----------------------------------------------------------------------
     3! NAME
     4!     xios_data
     5!
     6! DESCRIPTION
     7!     Read XIOS output data and process it for PEM initialization.
     8!
     9! AUTHORS & DATE
     10!     JB Clement, 2025
     11!
     12! NOTES
     13!
     14!-----------------------------------------------------------------------
     15
     16! DEPENDENCIES
     17! ------------
    318use netcdf, only: nf90_open, nf90_close, nf90_inquire_dimension, nf90_inq_dimid, nf90_noerr, nf90_nowrite, nf90_get_var, nf90_inq_varid
    419
    5 implicit none
    6 
    7 character(19), parameter :: file1_daily  = "Xoutdaily4pem_Y1.nc"
    8 character(19), parameter :: file2_daily  = "Xoutdaily4pem_Y2.nc"
    9 character(20), parameter :: file1_yearly = "Xoutyearly4pem_Y1.nc"
    10 character(20), parameter :: file2_yearly = "Xoutyearly4pem_Y2.nc"
    11 character(256)           :: msg      ! For reading
    12 integer                  :: fID, vID ! For reading
    13 
     20! DECLARATION
     21! -----------
     22implicit none
     23
     24! MODULE VARIABLES
     25! ----------------
     26character(19), parameter :: file1_daily  = "Xoutdaily4pem_Y1.nc"   ! XIOS daily output file, year 1
     27character(19), parameter :: file2_daily  = "Xoutdaily4pem_Y2.nc"   ! XIOS daily output file, year 2
     28character(20), parameter :: file1_yearly = "Xoutyearly4pem_Y1.nc"  ! XIOS yearly output file, year 1
     29character(20), parameter :: file2_yearly = "Xoutyearly4pem_Y2.nc"  ! XIOS yearly output file, year 2
     30character(256)           :: msg                                    ! Message for reading errors
     31integer                  :: fID, vID                               ! File and variable IDs for reading
     32
     33! INTERFACES
     34! ----------
    1435interface get_var
    1536    module procedure get_var_1d, get_var_2d, get_var_3d, get_var_4d
    1637end interface get_var
    1738
    18 !=======================================================================
    1939contains
    20 !=======================================================================
     40!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    2141
    2242!=======================================================================
    2343SUBROUTINE load_xios_data(ngrid,nslope,nsoil_PCM,nsol,h2ofrost_PCM,co2frost_PCM,ps_avg,tsurf_avg,tsurf_avg_y1,tsoil_avg,tsoil_ts,watersurf_density_avg,d_h2oice,d_co2ice, &
    2444                         ps_ts,q_h2o_ts,q_co2_ts,watersoil_density_ts,min_h2oice,min_co2ice)
    25 
     45!-----------------------------------------------------------------------
     46! NAME
     47!     load_xios_data
     48!
     49! DESCRIPTION
     50!     Reads yearly and daily XIOS data, computes frost and ice tendencies.
     51!
     52! AUTHORS & DATE
     53!     JB Clement, 2025
     54!
     55! NOTES
     56!
     57!-----------------------------------------------------------------------
     58
     59! DEPENDENCIES
     60! ------------
    2661use grid_conversion, only: lonlat2vect
    2762use soil,            only: do_soil
     
    2964use metamorphism,    only: compute_frost
    3065
    31 implicit none
    32 
    33 ! Arguments
    34 !----------
    35 integer,                       intent(in) :: ngrid, nslope, nsoil_PCM, nsol
    36 real, dimension(ngrid,nslope), intent(in) :: h2ofrost_PCM, co2frost_PCM
    37 real, dimension(ngrid),                       intent(out) :: ps_avg
    38 real, dimension(ngrid,nslope),                intent(out) :: tsurf_avg, tsurf_avg_y1, watersurf_density_avg, d_h2oice, d_co2ice, min_h2oice, min_co2ice
    39 real, dimension(ngrid,nsoil_PCM,nslope),      intent(out) :: tsoil_avg
    40 real, dimension(ngrid,nsol),                  intent(out) :: ps_ts, q_h2o_ts, q_co2_ts
    41 real, dimension(ngrid,nsoil_PCM,nslope,nsol), intent(out) :: tsoil_ts, watersoil_density_ts
    42 
    43 ! Local variables
    44 !----------------
     66! DECLARATION
     67! -----------
     68implicit none
     69
     70! ARGUMENTS
     71! ---------
     72integer,                                      intent(in)  :: ngrid, nslope, nsoil_PCM, nsol ! Grid dimensions
     73real, dimension(ngrid,nslope),                intent(in)  :: h2ofrost_PCM, co2frost_PCM     ! PCM frost fields
     74real, dimension(ngrid),                       intent(out) :: ps_avg                         ! Average surface pressure
     75real, dimension(ngrid,nslope),                intent(out) :: tsurf_avg, tsurf_avg_y1        ! Surface temperature
     76real, dimension(ngrid,nslope),                intent(out) :: watersurf_density_avg          ! Water density
     77real, dimension(ngrid,nslope),                intent(out) :: d_h2oice, d_co2ice             ! Ice tendencies
     78real, dimension(ngrid,nslope),                intent(out) :: min_h2oice, min_co2ice         ! Ice minima
     79real, dimension(ngrid,nsoil_PCM,nslope),      intent(out) :: tsoil_avg                      ! Soil temperature
     80real, dimension(ngrid,nsol),                  intent(out) :: ps_ts, q_h2o_ts, q_co2_ts      ! Time series
     81real, dimension(ngrid,nsoil_PCM,nslope,nsol), intent(out) :: tsoil_ts, watersoil_density_ts ! Soil time series
     82
     83! LOCAL VARIABLES
     84! ---------------
    4585integer                               :: islope, isoil, isol, nlon, nlat
    4686real, dimension(:,:),     allocatable :: var_read_2d
     
    5090real, dimension(ngrid,nslope,2)       :: min_h2operice, min_co2perice, min_h2ofrost, min_co2frost
    5191
    52 ! Code
    53 !-----
     92! CODE
     93! ----
    5494! Initialization
    5595min_h2operice = 0.
     
    187227!=======================================================================
    188228SUBROUTINE get_timelen(filename,timelen)
    189 
     229!-----------------------------------------------------------------------
     230! NAME
     231!     get_timelen
     232!
     233! DESCRIPTION
     234!     Get time dimension length from a NetCDF file.
     235!
     236! AUTHORS & DATE
     237!     JB Clement, 2025
     238!
     239! NOTES
     240!
     241!-----------------------------------------------------------------------
     242
     243! DEPENDENCIES
     244! ------------
    190245use netcdf
    191246
    192 implicit none
    193 
    194 ! Arguments
    195 ! ---------
    196 character(*), intent(in)  :: filename
    197 integer,      intent(out) :: timelen
    198 
    199 ! Local variables
     247! DECLARATION
     248! -----------
     249implicit none
     250
     251! ARGUMENTS
     252! ---------
     253character(*), intent(in)  :: filename ! NetCDF filename
     254integer,      intent(out) :: timelen  ! Length of time dimension
     255
     256! LOCAL VARIABLES
    200257! ---------------
    201258integer :: ncid  ! File ID
    202259integer :: dimid ! Dimension ID
    203 integer :: ierr  ! Return codes
    204 
    205 ! Code
     260integer :: ierr  ! Return code
     261
     262! CODE
    206263! ----
    207264! Open the NetCDF file
     
    237294
    238295!=======================================================================
    239 SUBROUTINE error_msg(ierr,typ,nam)
    240 
    241 implicit none
    242 
    243 integer,      intent(in) :: ierr !--- NetCDF error code
    244 character(*), intent(in) :: typ  !--- Type of operation
    245 character(*), intent(in) :: nam  !--- Field/File name
     296SUBROUTINE error_msg(ierr,typ,nam)
     297!-----------------------------------------------------------------------
     298! NAME
     299!     error_msg
     300!
     301! DESCRIPTION
     302!     Handle and report NetCDF errors.
     303!
     304! AUTHORS & DATE
     305!     JB Clement, 2025
     306!
     307! NOTES
     308!
     309!-----------------------------------------------------------------------
     310
     311! DECLARATION
     312! -----------
     313implicit none
     314
     315! ARGUMENTS
     316! ---------
     317integer,      intent(in) :: ierr ! NetCDF error code
     318character(*), intent(in) :: typ  ! Type of operation (inq, get, put, open, close)
     319character(*), intent(in) :: nam  ! Field/file name
     320
     321! CODE
     322! ----
    246323
    247324if (ierr == nf90_noerr) return
     
    263340!=======================================================================
    264341SUBROUTINE get_var_1d(var,v)
    265 
    266 implicit none
    267 
    268 character(*), intent(in) :: var
    269 real, dimension(:), intent(out) :: v
    270 
     342!-----------------------------------------------------------------------
     343! NAME
     344!     get_var_1d
     345!
     346! DESCRIPTION
     347!     Read a 1D variable from open NetCDF file.
     348!
     349! AUTHORS & DATE
     350!     JB Clement, 2025
     351!
     352! NOTES
     353!
     354!-----------------------------------------------------------------------
     355
     356! DECLARATION
     357! -----------
     358implicit none
     359
     360! ARGUMENTS
     361! ---------
     362character(*),       intent(in)  :: var ! Variable name
     363real, dimension(:), intent(out) :: v   ! Output array
     364
     365! CODE
     366! ----
    271367call error_msg(nf90_inq_varid(fID,var,vID),"inq",var)
    272368call error_msg(nf90_get_var(fID,vID,v),"get",var)
     
    277373!=======================================================================
    278374SUBROUTINE get_var_2d(var,v)
    279 
    280 implicit none
    281 
    282 character(*), intent(in) :: var
    283 real, dimension(:,:), intent(out) :: v
     375!-----------------------------------------------------------------------
     376! NAME
     377!     get_var_2d
     378!
     379! DESCRIPTION
     380!     Read a 2D variable from open NetCDF file.
     381!
     382! AUTHORS & DATE
     383!     JB Clement, 2025
     384!
     385! NOTES
     386!
     387!-----------------------------------------------------------------------
     388
     389! DECLARATION
     390! -----------
     391implicit none
     392
     393! ARGUMENTS
     394! ---------
     395character(*),         intent(in)  :: var ! Variable name
     396real, dimension(:,:), intent(out) :: v   ! Output array
     397
     398! CODE
     399! ----
    284400
    285401call error_msg(nf90_inq_varid(fID,var,vID),"inq",var)
     
    291407!=======================================================================
    292408SUBROUTINE get_var_3d(var,v)
    293 
    294 implicit none
    295 
    296 character(*), intent(in) :: var
    297 real, dimension(:,:,:), intent(out) :: v
     409!-----------------------------------------------------------------------
     410! NAME
     411!     get_var_3d
     412!
     413! DESCRIPTION
     414!     Read a 3D variable from open NetCDF file.
     415!
     416! AUTHORS & DATE
     417!     JB Clement, 2025
     418!
     419! NOTES
     420!
     421!-----------------------------------------------------------------------
     422
     423! DECLARATION
     424! -----------
     425implicit none
     426
     427! ARGUMENTS
     428! ---------
     429character(*),           intent(in)  ::  var ! Variable name
     430real, dimension(:,:,:), intent(out) ::  v   ! Output array
     431
     432! CODE
     433! ----
    298434
    299435call error_msg(nf90_inq_varid(fID,var,vID),"inq",var)
     
    305441!=======================================================================
    306442SUBROUTINE get_var_4d(var,v)
    307 
    308 implicit none
    309 
    310 character(*), intent(in) :: var
    311 real, dimension(:,:,:,:), intent(out) :: v
    312 
     443!-----------------------------------------------------------------------
     444! NAME
     445!     get_var_4d
     446!
     447! DESCRIPTION
     448!     Read a 4D variable from open NetCDF file.
     449!
     450! AUTHORS & DATE
     451!     JB Clement, 2025
     452!
     453! NOTES
     454!
     455!-----------------------------------------------------------------------
     456
     457! DECLARATION
     458! -----------
     459implicit none
     460
     461! ARGUMENTS
     462! ---------
     463character(*),             intent(in)  ::  var ! Variable name
     464real, dimension(:,:,:,:), intent(out) ::  v   ! Output array
     465
     466! CODE
     467! ----
    313468call error_msg(nf90_inq_varid(fID,var,vID),"inq",var)
    314469call error_msg(nf90_get_var(fID,vID,v),"get",var)
Note: See TracChangeset for help on using the changeset viewer.