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

Last change on this file since 4175 was 4170, checked in by jbclement, 6 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
Line 
1MODULE xios_data
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! ------------
18use numerics, only: dp, di, k4
19
20! DECLARATION
21! -----------
22implicit none
23
24contains
25!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26
27!=======================================================================
28SUBROUTINE load_xios_data(ps_avg,ps_ts,tsurf_avg,tsurf_avg_yr1,tsoil_avg,tsoil_ts,h2o_surfdensity_avg,h2o_soildensity_avg, &
29                          q_h2o_ts,q_co2_ts,minPCM_h2operice,minPCM_co2perice,minPCM_h2ofrost,minPCM_co2frost,flux_ssice_avg)
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!-----------------------------------------------------------------------
43
44! DEPENDENCIES
45! ------------
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
51use display,    only: print_msg, LVL_NFO
52use utility,    only: real2str
53
54! DECLARATION
55! -----------
56implicit none
57
58! ARGUMENTS
59! ---------
60real(dp), dimension(:),       intent(out) :: ps_avg
61real(dp), dimension(:,:),     intent(out) :: tsurf_avg, tsurf_avg_yr1, h2o_surfdensity_avg, ps_ts, q_h2o_ts, q_co2_ts, flux_ssice_avg
62real(dp), dimension(:,:,:),   intent(out) :: tsoil_avg, h2o_soildensity_avg
63real(dp), dimension(:,:,:,:), intent(out) :: tsoil_ts
64real(dp), dimension(:,:,:),   intent(out) :: minPCM_h2operice, minPCM_co2perice, minPCM_h2ofrost, minPCM_co2frost
65
66! LOCAL VARIABLES
67! ---------------
68logical(k4)                                  :: here
69integer(di)                                  :: islope, isoil, iday
70real(dp), dimension(:),       allocatable    :: var_read_1d
71real(dp), dimension(:,:),     allocatable    :: var_read_2d
72real(dp), dimension(:,:,:),   allocatable    :: var_read_3d
73real(dp), dimension(:,:,:,:), allocatable    :: var_read_4d
74character(8)                                 :: num ! Slope suffix to read variables
75
76! CODE
77! ----
78! Initialization
79minPCM_h2operice(:,:,:) = 0._dp
80minPCM_co2perice(:,:,:) = 0._dp
81minPCM_h2ofrost(:,:,:) = 0._dp
82minPCM_co2frost(:,:,:) = 0._dp
83num = ''
84
85!~~~~~~~~~~~~~~~~~~~~~~~~ Year 1 - Yearly data ~~~~~~~~~~~~~~~~~~~~~~~~~
86inquire(file = xios_yr_name1,exist = here)
87if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//xios_yr_name1//'"!',1)
88
89! Open the NetCDF file of XIOS outputs
90call print_msg('> Reading "'//xios_yr_name1//'"',LVL_NFO)
91call open_nc(xios_yr_name1,'read')
92
93! Allocate and read the variables
94allocate(var_read_2d(nlon,nlat),var_read_3d(nlon,nlat,nsoil_PCM))
95do islope = 1,nslope
96    if (nslope == 1) then
97        num = ''
98    else
99        write(num,'("_slope",i2.2)') islope
100    end if
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))
106end do
107
108! Close the NetCDF file of XIOS outputs
109call close_nc(xios_yr_name1)
110
111!~~~~~~~~~~~~~~~~~~~~~~~~ Year 2 - Yearly data ~~~~~~~~~~~~~~~~~~~~~~~~~
112inquire(file = xios_yr_name2,exist = here)
113if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//xios_yr_name2//'"!',1)
114! Open the NetCDF file of XIOS outputs
115call print_msg('> Reading "'//xios_yr_name2//'"',LVL_NFO)
116call open_nc(xios_yr_name2,'read')
117
118! Allocate and read the variables
119call get_var_nc('ps',var_read_2d); call lonlat2vect(var_read_2d,ps_avg)
120do islope = 1,nslope
121    if (nslope == 1) then
122        num = ''
123    else
124        write(num,'("_slope",i2.2)') islope
125    end if
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))
131    if (do_soil) then
132        call get_var_nc('flux_ssice'//trim(num),var_read_2d); call lonlat2vect(var_read_2d,flux_ssice_avg(:,islope))
133        call get_var_nc('soiltemp'//trim(num),var_read_3d)
134        do isoil = 1,nsoil_PCM
135            call lonlat2vect(var_read_3d(:,:,isoil),tsoil_avg(:,isoil,islope))
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
140        call get_var_nc('waterdensity_surface'//trim(num),var_read_2d); call lonlat2vect(var_read_2d,h2o_surfdensity_avg(:,islope))
141    end if
142end do
143
144! Close the NetCDF file of XIOS outputs
145call close_nc(xios_yr_name2)
146
147!~~~~~~~~~~~~~~~~~~~~~~~~~ Year 2 - Daily data ~~~~~~~~~~~~~~~~~~~~~~~~~
148inquire(file = xios_day_name2,exist = here)
149if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//xios_day_name2//'"!',1)
150! Open the NetCDF file of XIOS outputs
151call print_msg('> Reading "'//xios_day_name2//'"',LVL_NFO)
152call open_nc(xios_day_name2,'read')
153
154! Allocate and read the variables
155deallocate(var_read_2d,var_read_3d)
156allocate(var_read_1d(ngrid),var_read_3d(nlon,nlat,nday),var_read_4d(nlon,nlat,nsoil_PCM,nday))
157call get_var_nc('ps',var_read_3d)
158do iday = 1,nday
159    call lonlat2vect(var_read_3d(:,:,iday),ps_ts(:,iday))
160end do
161call get_var_nc('h2o_layer1',var_read_3d)
162do iday = 1,nday
163    call lonlat2vect(var_read_3d(:,:,iday),q_h2o_ts(:,iday))
164end do
165call get_var_nc('co2_layer1',var_read_3d)
166do iday = 1,nday
167    call lonlat2vect(var_read_3d(:,:,iday),q_co2_ts(:,iday))
168end do
169if (do_soil) then
170    h2o_soildensity_avg(:,:,:) = 0._dp
171    do islope = 1,nslope
172        if (nslope == 1) then
173            num = ''
174        else
175            write(num,'("_slope",i2.2)') islope
176        end if
177        call get_var_nc('soiltemp'//trim(num),var_read_4d)
178        do iday = 1,nday
179            do isoil = 1,nsoil_PCM
180                call lonlat2vect(var_read_4d(:,:,isoil,iday),tsoil_ts(:,isoil,islope,iday))
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
186        call get_var_nc('waterdensity_soil'//trim(num),var_read_4d)
187        do iday = 1,nday
188            do isoil = 1,nsoil_PCM
189                call lonlat2vect(var_read_4d(:,:,isoil,iday),var_read_1d)
190                h2o_soildensity_avg(:,isoil,islope) = h2o_soildensity_avg(:,isoil,islope) + var_read_1d
191            end do
192        end do
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
196    end do
197    h2o_soildensity_avg(:,:,:) = h2o_soildensity_avg(:,:,:)/real(nday,dp)
198end if
199deallocate(var_read_1d,var_read_3d,var_read_4d)
200
201! Close the NetCDF file of XIOS outputs
202call close_nc(xios_day_name2)
203
204!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
205! Compute frost from yearly minima
206where (minPCM_h2ofrost(:,:,:) < 0._dp) minPCM_h2ofrost(:,:,:) = 0._dp ! Enforcing positivity
207where (minPCM_co2frost(:,:,:) < 0._dp) minPCM_co2frost(:,:,:) = 0._dp ! Enforcing positivity
208call compute_frost4PCM(minPCM_h2ofrost(:,:,2),minPCM_co2frost(:,:,2))
209
210END SUBROUTINE load_xios_data
211!=======================================================================
212
213END MODULE xios_data
Note: See TracBrowser for help on using the repository browser.