Ignore:
Timestamp:
Mar 26, 2026, 4:29:10 PM (12 days ago)
Author:
jbclement
Message:

PEM:

  • Separate variables ownership between the module "planet" for persistent climate state and the program "pem" for transient workflow logic. It provides a meaningful structure.
  • Add lifecycle helpers for clear allocation/deallocation logic.
  • Simplify string suffix for slopes variables.

JBC

File:
1 edited

Legend:

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

    r4147 r4157  
    7272real(dp), dimension(:,:,:),   allocatable    :: var_read_3d
    7373real(dp), dimension(:,:,:,:), allocatable    :: var_read_4d
    74 character(:),                 allocatable    :: num ! To read slope variables
     74character(8)                                 :: num ! Slope suffix to read variables
    7575
    7676! CODE
     
    8181minPCM_h2ofrost(:,:,:) = 0._dp
    8282minPCM_co2frost(:,:,:) = 0._dp
    83 if (nslope == 1) then ! No slope
    84     allocate(character(0) :: num)
    85 else ! Using slopes
    86     allocate(character(8) :: num)
    87 end if
     83num = ''
    8884
    8985!~~~~~~~~~~~~~~~~~~~~~~~~ Year 1 - Yearly data ~~~~~~~~~~~~~~~~~~~~~~~~~
     
    9894allocate(var_read_2d(nlon,nlat),var_read_3d(nlon,nlat,nsoil_PCM))
    9995do islope = 1,nslope
    100     if (nslope /= 1) then
    101         num = '  '
    102         write(num,'(i2.2)') islope
    103         num = '_slope'//num
     96    if (nslope == 1) then
     97        num = ''
     98    else
     99        write(num,'("_slope",i2.2)') islope
    104100    end if
    105     call get_var_nc('co2ice'//num,var_read_2d)          ; call lonlat2vect(var_read_2d,minPCM_co2frost(:,islope,1))
    106     call get_var_nc('h2o_ice_s'//num,var_read_2d)       ; call lonlat2vect(var_read_2d,minPCM_h2ofrost(:,islope,1))
    107     call get_var_nc('watercap'//num,var_read_2d)        ; call lonlat2vect(var_read_2d,minPCM_h2operice(:,islope,1))
    108     call get_var_nc('perennial_co2ice'//num,var_read_2d); call lonlat2vect(var_read_2d,minPCM_co2perice(:,islope,1))
    109     call get_var_nc('tsurf'//num,var_read_2d)           ; call lonlat2vect(var_read_2d,tsurf_avg_yr1(:,islope))
     101    call get_var_nc('co2ice'//trim(num),var_read_2d)          ; call lonlat2vect(var_read_2d,minPCM_co2frost(:,islope,1))
     102    call get_var_nc('h2o_ice_s'//trim(num),var_read_2d)       ; call lonlat2vect(var_read_2d,minPCM_h2ofrost(:,islope,1))
     103    call get_var_nc('watercap'//trim(num),var_read_2d)        ; call lonlat2vect(var_read_2d,minPCM_h2operice(:,islope,1))
     104    call get_var_nc('perennial_co2ice'//trim(num),var_read_2d); call lonlat2vect(var_read_2d,minPCM_co2perice(:,islope,1))
     105    call get_var_nc('tsurf'//trim(num),var_read_2d)           ; call lonlat2vect(var_read_2d,tsurf_avg_yr1(:,islope))
    110106end do
    111107
     
    123119call get_var_nc('ps',var_read_2d); call lonlat2vect(var_read_2d,ps_avg)
    124120do islope = 1,nslope
    125     if (nslope /= 1) then
    126         num='  '
    127         write(num,'(i2.2)') islope
    128         num = '_slope'//num
     121    if (nslope == 1) then
     122        num = ''
     123    else
     124        write(num,'("_slope",i2.2)') islope
    129125    end if
    130     call get_var_nc('tsurf'//num,var_read_2d)           ; call lonlat2vect(var_read_2d,tsurf_avg(:,islope))
    131     call get_var_nc('co2ice'//num,var_read_2d)          ; call lonlat2vect(var_read_2d,minPCM_co2frost(:,islope,2))
    132     call get_var_nc('h2o_ice_s'//num,var_read_2d)       ; call lonlat2vect(var_read_2d,minPCM_h2ofrost(:,islope,2))
    133     call get_var_nc('watercap'//num,var_read_2d)        ; call lonlat2vect(var_read_2d,minPCM_h2operice(:,islope,2))
    134     call get_var_nc('perennial_co2ice'//num,var_read_2d); call lonlat2vect(var_read_2d,minPCM_co2perice(:,islope,2))
     126    call get_var_nc('tsurf'//trim(num),var_read_2d)           ; call lonlat2vect(var_read_2d,tsurf_avg(:,islope))
     127    call get_var_nc('co2ice'//trim(num),var_read_2d)          ; call lonlat2vect(var_read_2d,minPCM_co2frost(:,islope,2))
     128    call get_var_nc('h2o_ice_s'//trim(num),var_read_2d)       ; call lonlat2vect(var_read_2d,minPCM_h2ofrost(:,islope,2))
     129    call get_var_nc('watercap'//trim(num),var_read_2d)        ; call lonlat2vect(var_read_2d,minPCM_h2operice(:,islope,2))
     130    call get_var_nc('perennial_co2ice'//trim(num),var_read_2d); call lonlat2vect(var_read_2d,minPCM_co2perice(:,islope,2))
    135131    if (do_soil) then
    136         call get_var_nc('soiltemp'//num,var_read_3d)
     132        call get_var_nc('soiltemp'//trim(num),var_read_3d)
    137133        do isoil = 1,nsoil_PCM
    138134            call lonlat2vect(var_read_3d(:,:,isoil),tsoil_avg(:,isoil,islope))
     
    141137            tsoil_avg(:,isoil,islope) = tsoil_avg(:,nsoil_PCM,islope) ! Explicit initialization because dimension with size nsoil > nsoil_PCM
    142138        end do
    143         call get_var_nc('waterdensity_surface'//num,var_read_2d); call lonlat2vect(var_read_2d,h2o_surfdensity_avg(:,islope))
     139        call get_var_nc('waterdensity_surface'//trim(num),var_read_2d); call lonlat2vect(var_read_2d,h2o_surfdensity_avg(:,islope))
    144140    end if
    145141end do
     
    173169    h2o_soildensity_avg(:,:,:) = 0._dp
    174170    do islope = 1,nslope
    175         if (nslope /= 1) then
    176             num='  '
    177             write(num,'(i2.2)') islope
    178             num = '_slope'//num
     171        if (nslope == 1) then
     172            num = ''
     173        else
     174            write(num,'("_slope",i2.2)') islope
    179175        end if
    180         call get_var_nc('soiltemp'//num,var_read_4d)
     176        call get_var_nc('soiltemp'//trim(num),var_read_4d)
    181177        do iday = 1,nday
    182178            do isoil = 1,nsoil_PCM
     
    187183            end do
    188184        end do
    189         call get_var_nc('waterdensity_soil'//num,var_read_4d)
     185        call get_var_nc('waterdensity_soil'//trim(num),var_read_4d)
    190186        do iday = 1,nday
    191187            do isoil = 1,nsoil_PCM
     
    200196    h2o_soildensity_avg(:,:,:) = h2o_soildensity_avg(:,:,:)/real(nday,dp)
    201197end if
    202 deallocate(var_read_1d,var_read_3d,var_read_4d,num)
     198deallocate(var_read_1d,var_read_3d,var_read_4d)
    203199
    204200! Close the NetCDF file of XIOS outputs
Note: See TracChangeset for help on using the changeset viewer.