source: trunk/LMDZ.COMMON/libf/evolution/xios_data.F90 @ 4175

Last change on this file since 4175 was 4170, checked in by jbclement, 10 days ago

PEM:

  • Deletion of 'flux_ssice' ('zqdsdif_tot') from the "startfi.nc" as it is not needed.
  • Using the yearly average flux for the sublimating subsurface ice instead of the value at last timestep.
  • Keeping a clear separation between the subsurface ice flux and the surface ice tendency.
  • Making sure that subsurface ice depth is well given to the PCM at the end of the PEM (ice table VS layering).

JBC

File size: 8.5 KB
RevLine 
[3989]1MODULE xios_data
[3991]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!-----------------------------------------------------------------------
[3977]15
[3991]16! DEPENDENCIES
17! ------------
[4065]18use numerics, only: dp, di, k4
[3977]19
[3991]20! DECLARATION
21! -----------
[3977]22implicit none
23
24contains
[3991]25!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[3989]26
27!=======================================================================
[4065]28SUBROUTINE load_xios_data(ps_avg,ps_ts,tsurf_avg,tsurf_avg_yr1,tsoil_avg,tsoil_ts,h2o_surfdensity_avg,h2o_soildensity_avg, &
[4170]29                          q_h2o_ts,q_co2_ts,minPCM_h2operice,minPCM_co2perice,minPCM_h2ofrost,minPCM_co2frost,flux_ssice_avg)
[3991]30!-----------------------------------------------------------------------
31! NAME
32!     load_xios_data
33!
34! DESCRIPTION
35!     Reads yearly and daily XIOS data, computes frost and ice tendencies.
36!
37! AUTHORS & DATE
38!     JB Clement, 2025
39!
40! NOTES
41!
42!-----------------------------------------------------------------------
[3977]43
[3991]44! DEPENDENCIES
45! ------------
[4065]46use geometry,   only: ngrid, nslope, nsoil, nsoil_PCM, nday, lonlat2vect, nlon, nlat
47use io_netcdf,  only: xios_day_name2, xios_yr_name1, xios_yr_name2, open_nc, close_nc, get_var_nc, get_dim_nc
48use soil,       only: do_soil
49use frost,      only: compute_frost4PCM
50use stoppage,   only: stop_clean
[4110]51use display,    only: print_msg, LVL_NFO
[4065]52use utility,    only: real2str
[3977]53
[3991]54! DECLARATION
55! -----------
[3977]56implicit none
57
[3991]58! ARGUMENTS
59! ---------
[4065]60real(dp), dimension(:),       intent(out) :: ps_avg
[4170]61real(dp), dimension(:,:),     intent(out) :: tsurf_avg, tsurf_avg_yr1, h2o_surfdensity_avg, ps_ts, q_h2o_ts, q_co2_ts, flux_ssice_avg
[4065]62real(dp), dimension(:,:,:),   intent(out) :: tsoil_avg, h2o_soildensity_avg
63real(dp), dimension(:,:,:,:), intent(out) :: tsoil_ts
[4071]64real(dp), dimension(:,:,:),   intent(out) :: minPCM_h2operice, minPCM_co2perice, minPCM_h2ofrost, minPCM_co2frost
[3977]65
[3991]66! LOCAL VARIABLES
67! ---------------
[4065]68logical(k4)                                  :: here
69integer(di)                                  :: islope, isoil, iday
[4136]70real(dp), dimension(:),       allocatable    :: var_read_1d
[4065]71real(dp), dimension(:,:),     allocatable    :: var_read_2d
72real(dp), dimension(:,:,:),   allocatable    :: var_read_3d
73real(dp), dimension(:,:,:,:), allocatable    :: var_read_4d
[4157]74character(8)                                 :: num ! Slope suffix to read variables
[4090]75
[3991]76! CODE
77! ----
[3977]78! Initialization
[4071]79minPCM_h2operice(:,:,:) = 0._dp
80minPCM_co2perice(:,:,:) = 0._dp
81minPCM_h2ofrost(:,:,:) = 0._dp
82minPCM_co2frost(:,:,:) = 0._dp
[4157]83num = ''
[3977]84
85!~~~~~~~~~~~~~~~~~~~~~~~~ Year 1 - Yearly data ~~~~~~~~~~~~~~~~~~~~~~~~~
[4065]86inquire(file = xios_yr_name1,exist = here)
87if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//xios_yr_name1//'"!',1)
88
[3977]89! Open the NetCDF file of XIOS outputs
[4110]90call print_msg('> Reading "'//xios_yr_name1//'"',LVL_NFO)
[4065]91call open_nc(xios_yr_name1,'read')
[3977]92
93! Allocate and read the variables
94allocate(var_read_2d(nlon,nlat),var_read_3d(nlon,nlat,nsoil_PCM))
95do islope = 1,nslope
[4157]96    if (nslope == 1) then
97        num = ''
98    else
99        write(num,'("_slope",i2.2)') islope
[4065]100    end if
[4157]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))
[4065]106end do
[3977]107
108! Close the NetCDF file of XIOS outputs
[4065]109call close_nc(xios_yr_name1)
[3977]110
111!~~~~~~~~~~~~~~~~~~~~~~~~ Year 2 - Yearly data ~~~~~~~~~~~~~~~~~~~~~~~~~
[4065]112inquire(file = xios_yr_name2,exist = here)
113if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//xios_yr_name2//'"!',1)
[3977]114! Open the NetCDF file of XIOS outputs
[4110]115call print_msg('> Reading "'//xios_yr_name2//'"',LVL_NFO)
[4065]116call open_nc(xios_yr_name2,'read')
[3977]117
118! Allocate and read the variables
[4147]119call get_var_nc('ps',var_read_2d); call lonlat2vect(var_read_2d,ps_avg)
[3977]120do islope = 1,nslope
[4157]121    if (nslope == 1) then
122        num = ''
123    else
124        write(num,'("_slope",i2.2)') islope
[4065]125    end if
[4157]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))
[3989]131    if (do_soil) then
[4170]132        call get_var_nc('flux_ssice'//trim(num),var_read_2d); call lonlat2vect(var_read_2d,flux_ssice_avg(:,islope))
[4157]133        call get_var_nc('soiltemp'//trim(num),var_read_3d)
[3977]134        do isoil = 1,nsoil_PCM
[4147]135            call lonlat2vect(var_read_3d(:,:,isoil),tsoil_avg(:,isoil,islope))
[4065]136        end do
137        do isoil = nsoil_PCM + 1,nsoil
138            tsoil_avg(:,isoil,islope) = tsoil_avg(:,nsoil_PCM,islope) ! Explicit initialization because dimension with size nsoil > nsoil_PCM
139        end do
[4157]140        call get_var_nc('waterdensity_surface'//trim(num),var_read_2d); call lonlat2vect(var_read_2d,h2o_surfdensity_avg(:,islope))
[4065]141    end if
142end do
[4090]143
[3977]144! Close the NetCDF file of XIOS outputs
[4065]145call close_nc(xios_yr_name2)
[3977]146
147!~~~~~~~~~~~~~~~~~~~~~~~~~ Year 2 - Daily data ~~~~~~~~~~~~~~~~~~~~~~~~~
[4065]148inquire(file = xios_day_name2,exist = here)
149if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//xios_day_name2//'"!',1)
[3977]150! Open the NetCDF file of XIOS outputs
[4110]151call print_msg('> Reading "'//xios_day_name2//'"',LVL_NFO)
[4065]152call open_nc(xios_day_name2,'read')
[3977]153
154! Allocate and read the variables
155deallocate(var_read_2d,var_read_3d)
[4136]156allocate(var_read_1d(ngrid),var_read_3d(nlon,nlat,nday),var_read_4d(nlon,nlat,nsoil_PCM,nday))
[4065]157call get_var_nc('ps',var_read_3d)
158do iday = 1,nday
[4147]159    call lonlat2vect(var_read_3d(:,:,iday),ps_ts(:,iday))
[4065]160end do
161call get_var_nc('h2o_layer1',var_read_3d)
162do iday = 1,nday
[4147]163    call lonlat2vect(var_read_3d(:,:,iday),q_h2o_ts(:,iday))
[4065]164end do
165call get_var_nc('co2_layer1',var_read_3d)
166do iday = 1,nday
[4147]167    call lonlat2vect(var_read_3d(:,:,iday),q_co2_ts(:,iday))
[4065]168end do
[3989]169if (do_soil) then
[4136]170    h2o_soildensity_avg(:,:,:) = 0._dp
[3977]171    do islope = 1,nslope
[4157]172        if (nslope == 1) then
173            num = ''
174        else
175            write(num,'("_slope",i2.2)') islope
[4065]176        end if
[4157]177        call get_var_nc('soiltemp'//trim(num),var_read_4d)
[4065]178        do iday = 1,nday
[3977]179            do isoil = 1,nsoil_PCM
[4147]180                call lonlat2vect(var_read_4d(:,:,isoil,iday),tsoil_ts(:,isoil,islope,iday))
[4065]181            end do
182            do isoil = nsoil_PCM + 1,nsoil
183                tsoil_ts(:,isoil,islope,iday) = tsoil_ts(:,nsoil_PCM,islope,iday) ! Explicit initialization because dimension with size nsoil > nsoil_PCM
184            end do
185        end do
[4157]186        call get_var_nc('waterdensity_soil'//trim(num),var_read_4d)
[4065]187        do iday = 1,nday
[3977]188            do isoil = 1,nsoil_PCM
[4147]189                call lonlat2vect(var_read_4d(:,:,isoil,iday),var_read_1d)
[4136]190                h2o_soildensity_avg(:,isoil,islope) = h2o_soildensity_avg(:,isoil,islope) + var_read_1d
[4065]191            end do
192        end do
[4138]193        do isoil = nsoil_PCM + 1,nsoil
194            h2o_soildensity_avg(:,isoil,islope) = h2o_soildensity_avg(:,nsoil_PCM,islope) ! Explicit initialization because dimension with size nsoil > nsoil_PCM
195        end do
[4065]196    end do
[4136]197    h2o_soildensity_avg(:,:,:) = h2o_soildensity_avg(:,:,:)/real(nday,dp)
[4065]198end if
[4157]199deallocate(var_read_1d,var_read_3d,var_read_4d)
[3977]200
201! Close the NetCDF file of XIOS outputs
[4065]202call close_nc(xios_day_name2)
[3977]203
204!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[3983]205! Compute frost from yearly minima
[4147]206where (minPCM_h2ofrost(:,:,:) < 0._dp) minPCM_h2ofrost(:,:,:) = 0._dp ! Enforcing positivity
207where (minPCM_co2frost(:,:,:) < 0._dp) minPCM_co2frost(:,:,:) = 0._dp ! Enforcing positivity
[4071]208call compute_frost4PCM(minPCM_h2ofrost(:,:,2),minPCM_co2frost(:,:,2))
[3983]209
[3989]210END SUBROUTINE load_xios_data
211!=======================================================================
[3977]212
[3989]213END MODULE xios_data
Note: See TracBrowser for help on using the repository browser.