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

Last change on this file since 4076 was 4071, checked in by jbclement, 12 days ago

PEM:

  • Making the computation of ice tendencies more reliable by doing it after 'read_startpem' to know exactly where perennial ice is (no matter if there is a "startpem.nc" or not). Moreover, when there is no "startpem.nc", location of perennial ice depends now on 'watercaptag' and on huge amount of frost. This prevents negative ice tendency while there is no ice which can happen with weird PCM inputs (i.e. 'watercaptag' = F & 'watercap' /= 0 & no "stratpem.nc").
  • Few small safeguards throughout the code.

JBC

File size: 8.4 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, &
[4071]29                          q_h2o_ts,q_co2_ts,minPCM_h2operice,minPCM_co2perice,minPCM_h2ofrost,minPCM_co2frost)
[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
51use display,    only: print_msg
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
[4071]61real(dp), dimension(:,:),     intent(out) :: tsurf_avg, tsurf_avg_yr1, h2o_surfdensity_avg, ps_ts, q_h2o_ts, q_co2_ts
[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
70real(dp), dimension(:,:),     allocatable    :: var_read_2d
71real(dp), dimension(:,:,:),   allocatable    :: var_read_3d
72real(dp), dimension(:,:,:,:), allocatable    :: var_read_4d
73character(:),                 allocatable    :: num ! To read slope variables
74real(dp), dimension(ngrid,nsoil,nslope,nday) :: h2o_soildensity_ts
[3991]75! CODE
76! ----
[3977]77! Initialization
[4071]78minPCM_h2operice(:,:,:) = 0._dp
79minPCM_co2perice(:,:,:) = 0._dp
80minPCM_h2ofrost(:,:,:) = 0._dp
81minPCM_co2frost(:,:,:) = 0._dp
[3977]82if (nslope == 1) then ! No slope
83    allocate(character(0) :: num)
84else ! Using slopes
85    allocate(character(8) :: num)
[4065]86end if
[3977]87
88!~~~~~~~~~~~~~~~~~~~~~~~~ Year 1 - Yearly data ~~~~~~~~~~~~~~~~~~~~~~~~~
[4065]89inquire(file = xios_yr_name1,exist = here)
90if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//xios_yr_name1//'"!',1)
91
[3977]92! Open the NetCDF file of XIOS outputs
[4065]93call print_msg('> Reading "'//xios_yr_name1//'"')
94call open_nc(xios_yr_name1,'read')
[3977]95
96! Allocate and read the variables
97allocate(var_read_2d(nlon,nlat),var_read_3d(nlon,nlat,nsoil_PCM))
98do islope = 1,nslope
99    if (nslope /= 1) then
[4065]100        num = '  '
[3977]101        write(num,'(i2.2)') islope
102        num = '_slope'//num
[4065]103    end if
[4071]104    call get_var_nc('co2ice'//num,var_read_2d)          ; call lonlat2vect(nlon,nlat,ngrid,var_read_2d,minPCM_co2frost(:,islope,1))
105    call get_var_nc('h2o_ice_s'//num,var_read_2d)       ; call lonlat2vect(nlon,nlat,ngrid,var_read_2d,minPCM_h2ofrost(:,islope,1))
106    call get_var_nc('watercap'//num,var_read_2d)        ; call lonlat2vect(nlon,nlat,ngrid,var_read_2d,minPCM_h2operice(:,islope,1))
107    call get_var_nc('perennial_co2ice'//num,var_read_2d); call lonlat2vect(nlon,nlat,ngrid,var_read_2d,minPCM_co2perice(:,islope,1))
[4065]108    call get_var_nc('tsurf'//num,var_read_2d)           ; call lonlat2vect(nlon,nlat,ngrid,var_read_2d,tsurf_avg_yr1(:,islope))
109end do
[3977]110
111! Close the NetCDF file of XIOS outputs
[4065]112call close_nc(xios_yr_name1)
[3977]113
114!~~~~~~~~~~~~~~~~~~~~~~~~ Year 2 - Yearly data ~~~~~~~~~~~~~~~~~~~~~~~~~
[4065]115inquire(file = xios_yr_name2,exist = here)
116if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//xios_yr_name2//'"!',1)
[3977]117! Open the NetCDF file of XIOS outputs
[4065]118call print_msg('> Reading "'//xios_yr_name2//'"')
119call open_nc(xios_yr_name2,'read')
[3977]120
121! Allocate and read the variables
[4065]122call get_var_nc('ps',var_read_2d); call lonlat2vect(nlon,nlat,ngrid,var_read_2d,ps_avg)
[3977]123do islope = 1,nslope
124    if (nslope /= 1) then
125        num='  '
126        write(num,'(i2.2)') islope
127        num = '_slope'//num
[4065]128    end if
129    call get_var_nc('tsurf'//num,var_read_2d)           ; call lonlat2vect(nlon,nlat,ngrid,var_read_2d,tsurf_avg(:,islope))
[4071]130    call get_var_nc('co2ice'//num,var_read_2d)          ; call lonlat2vect(nlon,nlat,ngrid,var_read_2d,minPCM_co2frost(:,islope,2))
131    call get_var_nc('h2o_ice_s'//num,var_read_2d)       ; call lonlat2vect(nlon,nlat,ngrid,var_read_2d,minPCM_h2ofrost(:,islope,2))
132    call get_var_nc('watercap'//num,var_read_2d)        ; call lonlat2vect(nlon,nlat,ngrid,var_read_2d,minPCM_h2operice(:,islope,2))
133    call get_var_nc('perennial_co2ice'//num,var_read_2d); call lonlat2vect(nlon,nlat,ngrid,var_read_2d,minPCM_co2perice(:,islope,2))
[3989]134    if (do_soil) then
[4065]135        call get_var_nc('soiltemp'//num,var_read_3d)
[3977]136        do isoil = 1,nsoil_PCM
137            call lonlat2vect(nlon,nlat,ngrid,var_read_3d(:,:,isoil),tsoil_avg(:,isoil,islope))
[4065]138        end do
139        do isoil = nsoil_PCM + 1,nsoil
140            tsoil_avg(:,isoil,islope) = tsoil_avg(:,nsoil_PCM,islope) ! Explicit initialization because dimension with size nsoil > nsoil_PCM
141        end do
142        call get_var_nc('waterdensity_surface'//num,var_read_2d); call lonlat2vect(nlon,nlat,ngrid,var_read_2d,h2o_surfdensity_avg(:,islope))
143    end if
144end do
[3977]145! Close the NetCDF file of XIOS outputs
[4065]146call close_nc(xios_yr_name2)
[3977]147
148!~~~~~~~~~~~~~~~~~~~~~~~~~ Year 2 - Daily data ~~~~~~~~~~~~~~~~~~~~~~~~~
[4065]149inquire(file = xios_day_name2,exist = here)
150if (.not. here) call stop_clean(__FILE__,__LINE__,'cannot find required file "'//xios_day_name2//'"!',1)
[3977]151! Open the NetCDF file of XIOS outputs
[4065]152call print_msg('> Reading "'//xios_day_name2//'"')
153call open_nc(xios_day_name2,'read')
[3977]154
155! Allocate and read the variables
156deallocate(var_read_2d,var_read_3d)
[4065]157allocate(var_read_3d(nlon,nlat,nday),var_read_4d(nlon,nlat,nsoil_PCM,nday))
158call get_var_nc('ps',var_read_3d)
159do iday = 1,nday
160    call lonlat2vect(nlon,nlat,ngrid,var_read_3d(:,:,iday),ps_ts(:,iday))
161end do
162call get_var_nc('h2o_layer1',var_read_3d)
163do iday = 1,nday
164    call lonlat2vect(nlon,nlat,ngrid,var_read_3d(:,:,iday),q_h2o_ts(:,iday))
165end do
166call get_var_nc('co2_layer1',var_read_3d)
167do iday = 1,nday
168    call lonlat2vect(nlon,nlat,ngrid,var_read_3d(:,:,iday),q_co2_ts(:,iday))
169end do
[3989]170if (do_soil) then
[3977]171    do islope = 1,nslope
172        if (nslope /= 1) then
173            num='  '
174            write(num,'(i2.2)') islope
175            num = '_slope'//num
[4065]176        end if
177        call get_var_nc('soiltemp'//num,var_read_4d)
178        do iday = 1,nday
[3977]179            do isoil = 1,nsoil_PCM
[4065]180                call lonlat2vect(nlon,nlat,ngrid,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'//num,var_read_4d)
187        do iday = 1,nday
[3977]188            do isoil = 1,nsoil_PCM
[4065]189                call lonlat2vect(nlon,nlat,ngrid,var_read_4d(:,:,isoil,iday),h2o_soildensity_ts(:,isoil,islope,iday))
190            end do
191            do isoil = nsoil_PCM + 1,nsoil
192                h2o_soildensity_ts(:,isoil,islope,iday) = h2o_soildensity_ts(:,nsoil_PCM,islope,iday) ! Explicit initialization because dimension with size nsoil > nsoil_PCM
193            end do
194        end do
195    end do
196    h2o_soildensity_avg(:,:,:) = sum(h2o_soildensity_ts,4)/nday
197end if
[3977]198deallocate(var_read_3d,var_read_4d,num)
199
200! Close the NetCDF file of XIOS outputs
[4065]201call close_nc(xios_day_name2)
[3977]202
203!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[3983]204! Compute frost from yearly minima
[4071]205call compute_frost4PCM(minPCM_h2ofrost(:,:,2),minPCM_co2frost(:,:,2))
[3983]206
[3989]207END SUBROUTINE load_xios_data
208!=======================================================================
[3977]209
[3989]210END MODULE xios_data
Note: See TracBrowser for help on using the repository browser.