| 1 | ! |
|---|
| 2 | ! $Id $ |
|---|
| 3 | ! |
|---|
| 4 | SUBROUTINE read_data_GCM(fichnom,timelen, iim_input,jjm_input,min_h2o_ice_s,min_co2_ice_s,vmr_co2_gcm,ps_GCM, & |
|---|
| 5 | min_co2_ice_slope,min_h2o_ice_slope,nslope,tsurf_ave,tsoil_ave,tsurf_gcm,tsoil_gcm,TI_ave,q_co2_GCM,q_h2o_GCM,co2_ice_slope, & |
|---|
| 6 | watersurf_density,watersoil_density) |
|---|
| 7 | |
|---|
| 8 | use netcdf, only: nf90_open,NF90_NOWRITE,nf90_noerr,nf90_strerror, & |
|---|
| 9 | nf90_get_var, nf90_inq_varid, nf90_inq_dimid, & |
|---|
| 10 | nf90_inquire_dimension,nf90_close |
|---|
| 11 | use comsoil_h, only: nsoilmx |
|---|
| 12 | USE comsoil_h_PEM, ONLY: soil_pem |
|---|
| 13 | |
|---|
| 14 | IMPLICIT NONE |
|---|
| 15 | |
|---|
| 16 | !======================================================================= |
|---|
| 17 | ! |
|---|
| 18 | ! Purpose: Read initial confitions file from the GCM |
|---|
| 19 | ! |
|---|
| 20 | ! Authors: RV & LL |
|---|
| 21 | !======================================================================= |
|---|
| 22 | |
|---|
| 23 | include "dimensions.h" |
|---|
| 24 | |
|---|
| 25 | !=============================================================================== |
|---|
| 26 | ! Arguments: |
|---|
| 27 | |
|---|
| 28 | CHARACTER(LEN=*), INTENT(IN) :: fichnom !--- FILE NAME |
|---|
| 29 | INTEGER, INTENT(IN) :: timelen ! number of times stored in the file |
|---|
| 30 | INTEGER :: iim_input,jjm_input,nslope ! number of points in the lat x lon dynamical grid, number of subgrid slopes |
|---|
| 31 | |
|---|
| 32 | ! Ouputs |
|---|
| 33 | REAL, INTENT(OUT) :: min_h2o_ice_s(iim_input+1,jjm_input+1) ! Minimum of h2o ice, mesh averaged of the year [kg/m^2] |
|---|
| 34 | REAL, INTENT(OUT) :: min_co2_ice_s(iim_input+1,jjm_input+1) ! Minimum of co2 ice, mesh averaged of the year [kg/m^2] |
|---|
| 35 | REAL, INTENT(OUT) :: min_co2_ice_slope(iim_input+1,jjm_input+1,nslope) ! Minimum of co2 ice per slope of the year [kg/m^2] |
|---|
| 36 | REAL, INTENT(OUT) :: min_h2o_ice_slope(iim_input+1,jjm_input+1,nslope) ! Minimum of h2o ice per slope of the year [kg/m^2] |
|---|
| 37 | REAL, INTENT(OUT) :: vmr_co2_gcm(iim_input+1,jjm_input+1,timelen) ! CO2 volume mixing ratio in the first layer [mol/m^3] |
|---|
| 38 | REAL, INTENT(OUT) :: q_h2o_GCM(iim_input+1,jjm_input+1,timelen) ! H2O mass mixing ratio in the first layer [kg/m^3] |
|---|
| 39 | REAL, INTENT(OUT) :: q_co2_GCM(iim_input+1,jjm_input+1,timelen) ! CO2 mass mixing ratio in the first layer [kg/m^3] |
|---|
| 40 | REAL, INTENT(OUT) :: ps_GCM(iim_input+1,jjm_input+1,timelen) ! Surface Pressure [Pa] |
|---|
| 41 | REAL, INTENT(OUT) :: co2_ice_slope(iim_input+1,jjm_input+1,nslope,timelen) ! co2 ice amount per slope of the year [kg/m^2] |
|---|
| 42 | |
|---|
| 43 | !SOIL |
|---|
| 44 | REAL, INTENT(OUT) :: tsurf_ave(iim_input+1,jjm_input+1,nslope) ! Average surface temperature of the concatenated file [K] |
|---|
| 45 | REAL, INTENT(OUT) :: tsoil_ave(iim_input+1,jjm_input+1,nsoilmx,nslope) ! Average soil temperature of the concatenated file [K] |
|---|
| 46 | REAL ,INTENT(OUT) :: tsurf_gcm(iim_input+1,jjm_input+1,nslope,timelen) ! Surface temperature of the concatenated file, time series [K] |
|---|
| 47 | REAL , INTENT(OUT) :: tsoil_gcm(iim_input+1,jjm_input+1,nsoilmx,nslope,timelen) ! Soil temperature of the concatenated file, time series [K] |
|---|
| 48 | REAL , INTENT(OUT) :: watersurf_density(iim_input+1,jjm_input+1,nslope,timelen) ! Water density at the surface, time series [kg/m^3] |
|---|
| 49 | REAL , INTENT(OUT) :: watersoil_density(iim_input+1,jjm_input+1,nsoilmx,nslope,timelen) ! Water density in the soil layer, time series [kg/m^3] |
|---|
| 50 | REAL :: TI_gcm(iim_input+1,jjm_input+1,nsoilmx,nslope,timelen) ! Thermal Inertia of the concatenated file, times series [SI] |
|---|
| 51 | REAL, INTENT(OUT) :: TI_ave(iim_input+1,jjm_input+1,nsoilmx,nslope) ! Average Thermal Inertia of the concatenated file [SI] |
|---|
| 52 | !=============================================================================== |
|---|
| 53 | ! Local Variables |
|---|
| 54 | CHARACTER(LEN=256) :: msg, var, modname ! for reading |
|---|
| 55 | INTEGER :: iq, fID, vID, idecal ! for reading |
|---|
| 56 | INTEGER :: ierr ! for reading |
|---|
| 57 | CHARACTER(len=12) :: start_file_type="earth" ! default start file type |
|---|
| 58 | |
|---|
| 59 | REAL,ALLOCATABLE :: time(:) ! times stored in start |
|---|
| 60 | INTEGER :: indextime ! index of selected time |
|---|
| 61 | |
|---|
| 62 | INTEGER :: edges(4),corner(4) |
|---|
| 63 | INTEGER :: i,j,t ! loop variables |
|---|
| 64 | real,save :: m_co2, m_noco2, A , B, mmean ! Molar Mass of co2 and no co2, A;B intermediate variables to compute the mean molar mass of the layer |
|---|
| 65 | |
|---|
| 66 | INTEGER :: islope ! loop for variables |
|---|
| 67 | CHARACTER*2 :: num ! for reading sloped variables |
|---|
| 68 | REAL, ALLOCATABLE :: h2o_ice_s(:,:,:) ! h2o ice, mesh averaged, of the concatenated file [kg/m^2] |
|---|
| 69 | REAL, ALLOCATABLE :: co2_ice_s(:,:,:) ! co2 ice, mesh averaged, of the concatenated file [kg/m^2] |
|---|
| 70 | REAL, ALLOCATABLE :: h2o_ice_s_slope(:,:,:,:) ! h2o ice per slope of the concatenated file [kg/m^2] |
|---|
| 71 | |
|---|
| 72 | !----------------------------------------------------------------------- |
|---|
| 73 | modname="read_data_gcm" |
|---|
| 74 | |
|---|
| 75 | m_co2 = 44.01E-3 ! CO2 molecular mass (kg/mol) |
|---|
| 76 | m_noco2 = 33.37E-3 ! Non condensible mol mass (kg/mol) |
|---|
| 77 | A =(1/m_co2 - 1/m_noco2) |
|---|
| 78 | B=1/m_noco2 |
|---|
| 79 | |
|---|
| 80 | allocate(co2_ice_s(iim+1,jjm+1,timelen)) |
|---|
| 81 | allocate(h2o_ice_s_slope(iim+1,jjm+1,nslope,timelen)) |
|---|
| 82 | allocate(h2o_ice_s(iim+1,jjm+1,timelen)) |
|---|
| 83 | |
|---|
| 84 | print *, "Opening ", fichnom, "..." |
|---|
| 85 | |
|---|
| 86 | ! Open initial state NetCDF file |
|---|
| 87 | var=fichnom |
|---|
| 88 | CALL err(NF90_OPEN(var,NF90_NOWRITE,fID),"open",var) |
|---|
| 89 | |
|---|
| 90 | print *, "Downloading data for h2oice ..." |
|---|
| 91 | |
|---|
| 92 | ! Get h2o_ice_s of the concatenated file |
|---|
| 93 | CALL get_var3("h2o_ice_s" ,h2o_ice_s) |
|---|
| 94 | |
|---|
| 95 | print *, "Downloading data for h2oice done" |
|---|
| 96 | print *, "Downloading data for co2ice ..." |
|---|
| 97 | |
|---|
| 98 | CALL get_var3("co2ice" ,co2_ice_s) |
|---|
| 99 | |
|---|
| 100 | print *, "Downloading data for co2ice done" |
|---|
| 101 | print *, "Downloading data for vmr co2..." |
|---|
| 102 | |
|---|
| 103 | CALL get_var3("co2_cropped" ,q_co2_GCM) |
|---|
| 104 | |
|---|
| 105 | print *, "Downloading data for vmr co2 done" |
|---|
| 106 | print *, "Downloading data for vmr h20..." |
|---|
| 107 | |
|---|
| 108 | CALL get_var3("h2o_cropped" ,q_h2o_GCM) |
|---|
| 109 | |
|---|
| 110 | print *, "Downloading data for vmr h2o done" |
|---|
| 111 | print *, "Downloading data for surface pressure ..." |
|---|
| 112 | |
|---|
| 113 | CALL get_var3("ps" ,ps_GCM) |
|---|
| 114 | |
|---|
| 115 | print *, "Downloading data for surface pressure done" |
|---|
| 116 | print *, "nslope=", nslope |
|---|
| 117 | print *, "Downloading data for co2ice_slope ..." |
|---|
| 118 | |
|---|
| 119 | if(nslope.gt.1) then |
|---|
| 120 | |
|---|
| 121 | DO islope=1,nslope |
|---|
| 122 | write(num,fmt='(i2.2)') islope |
|---|
| 123 | call get_var3("co2ice_slope"//num,co2_ice_slope(:,:,islope,:)) |
|---|
| 124 | ENDDO |
|---|
| 125 | |
|---|
| 126 | print *, "Downloading data for co2ice_slope done" |
|---|
| 127 | print *, "Downloading data for h2o_ice_s_slope ..." |
|---|
| 128 | |
|---|
| 129 | DO islope=1,nslope |
|---|
| 130 | write(num,fmt='(i2.2)') islope |
|---|
| 131 | call get_var3("h2o_ice_s_slope"//num,h2o_ice_s_slope(:,:,islope,:)) |
|---|
| 132 | ENDDO |
|---|
| 133 | |
|---|
| 134 | print *, "Downloading data for h2o_ice_s_slope done" |
|---|
| 135 | print *, "Downloading data for tsurf_slope ..." |
|---|
| 136 | |
|---|
| 137 | DO islope=1,nslope |
|---|
| 138 | write(num,fmt='(i2.2)') islope |
|---|
| 139 | call get_var3("tsurf_slope"//num,tsurf_gcm(:,:,islope,:)) |
|---|
| 140 | ENDDO |
|---|
| 141 | |
|---|
| 142 | print *, "Downloading data for tsurf_slope done" |
|---|
| 143 | |
|---|
| 144 | if(soil_pem) then |
|---|
| 145 | |
|---|
| 146 | print *, "Downloading data for tsoil_slope ..." |
|---|
| 147 | |
|---|
| 148 | DO islope=1,nslope |
|---|
| 149 | write(num,fmt='(i2.2)') islope |
|---|
| 150 | call get_var4("tsoil_slope"//num,tsoil_gcm(:,:,:,islope,:)) |
|---|
| 151 | ENDDO |
|---|
| 152 | |
|---|
| 153 | print *, "Downloading data for tsoil_slope done" |
|---|
| 154 | print *, "Downloading data for inertiesoil_slope ..." |
|---|
| 155 | |
|---|
| 156 | DO islope=1,nslope |
|---|
| 157 | write(num,fmt='(i2.2)') islope |
|---|
| 158 | call get_var4("inertiesoil_slope"//num,TI_gcm(:,:,:,islope,:)) |
|---|
| 159 | ENDDO |
|---|
| 160 | |
|---|
| 161 | print *, "Downloading data for inertiesoil_slope done" |
|---|
| 162 | |
|---|
| 163 | print *, "Downloading data for watersoil_density ..." |
|---|
| 164 | |
|---|
| 165 | DO islope=1,nslope |
|---|
| 166 | write(num,fmt='(i2.2)') islope |
|---|
| 167 | call get_var4("Waterdensity_soil_slope"//num,watersoil_density(:,:,:,islope,:)) |
|---|
| 168 | ENDDO |
|---|
| 169 | |
|---|
| 170 | print *, "Downloading data for watersoil_density done" |
|---|
| 171 | |
|---|
| 172 | print *, "Downloading data for watersurf_density ..." |
|---|
| 173 | |
|---|
| 174 | DO islope=1,nslope |
|---|
| 175 | write(num,fmt='(i2.2)') islope |
|---|
| 176 | call get_var3("Waterdensity_surface"//num,watersurf_density(:,:,islope,:)) |
|---|
| 177 | ENDDO |
|---|
| 178 | |
|---|
| 179 | print *, "Downloading data for watersurf_density done" |
|---|
| 180 | |
|---|
| 181 | endif !soil_pem |
|---|
| 182 | |
|---|
| 183 | else !nslope=1 no slope, we copy all the values |
|---|
| 184 | co2_ice_slope(:,:,1,:)=co2_ice_s(:,:,:) |
|---|
| 185 | h2o_ice_s_slope(:,:,1,:)=h2o_ice_s(:,:,:) |
|---|
| 186 | call get_var3("tsurf",tsurf_gcm(:,:,1,:)) |
|---|
| 187 | if(soil_pem) then |
|---|
| 188 | call get_var4("tsoil",tsoil_gcm(:,:,:,1,:)) |
|---|
| 189 | call get_var4("inertiesoil",TI_gcm(:,:,:,1,:)) |
|---|
| 190 | endif !soil_pem |
|---|
| 191 | endif !nslope=1 |
|---|
| 192 | |
|---|
| 193 | ! Compute the minimum over the year for each point |
|---|
| 194 | print *, "Computing the min of h2o_ice" |
|---|
| 195 | min_h2o_ice_s(:,:)=minval(h2o_ice_s,3) |
|---|
| 196 | print *, "Computing the min of co2_ice" |
|---|
| 197 | min_co2_ice_s(:,:)=minval(co2_ice_s,3) |
|---|
| 198 | |
|---|
| 199 | print *, "Computing the min of h2o_ice_slope" |
|---|
| 200 | min_h2o_ice_slope(:,:,:)=minval(h2o_ice_s_slope,4) |
|---|
| 201 | print *, "Computing the min of co2_ice_slope" |
|---|
| 202 | min_co2_ice_slope(:,:,:)=minval(co2_ice_slope,4) |
|---|
| 203 | |
|---|
| 204 | !Compute averages |
|---|
| 205 | |
|---|
| 206 | print *, "Computing average of tsurf" |
|---|
| 207 | tsurf_ave(:,:,:)=SUM(tsurf_gcm(:,:,:,:),4)/timelen |
|---|
| 208 | |
|---|
| 209 | if(soil_pem) then |
|---|
| 210 | print *, "Computing average of tsoil" |
|---|
| 211 | tsoil_ave(:,:,:,:)=SUM(tsoil_gcm(:,:,:,:,:),5)/timelen |
|---|
| 212 | print *, "Computing average of TI" |
|---|
| 213 | TI_ave(:,:,:,:)=SUM(TI_gcm(:,:,:,:,:),5)/timelen |
|---|
| 214 | endif |
|---|
| 215 | |
|---|
| 216 | ! By definition, a density is positive, we get rid of the negative values |
|---|
| 217 | DO i=1,iim+1 |
|---|
| 218 | DO j = 1, jjm+1 |
|---|
| 219 | if (min_co2_ice_s(i,j).LT.0) then |
|---|
| 220 | min_h2o_ice_s(i,j) = 0. |
|---|
| 221 | min_co2_ice_s(i,j) = 0. |
|---|
| 222 | endif |
|---|
| 223 | DO islope=1,nslope |
|---|
| 224 | if (min_co2_ice_slope(i,j,islope).LT.0) then |
|---|
| 225 | min_co2_ice_slope(i,j,islope) = 0. |
|---|
| 226 | endif |
|---|
| 227 | if (min_h2o_ice_slope(i,j,islope).LT.0) then |
|---|
| 228 | min_h2o_ice_slope(i,j,islope) = 0. |
|---|
| 229 | endif |
|---|
| 230 | ENDDO |
|---|
| 231 | ENDDO |
|---|
| 232 | ENDDO |
|---|
| 233 | |
|---|
| 234 | DO i=1,iim+1 |
|---|
| 235 | DO j = 1, jjm+1 |
|---|
| 236 | DO t = 1, timelen |
|---|
| 237 | if (q_co2_GCM(i,j,t).LT.0) then |
|---|
| 238 | q_co2_GCM(i,j,t)=1E-10 |
|---|
| 239 | elseif (q_co2_GCM(i,j,t).GT.1) then |
|---|
| 240 | q_co2_GCM(i,j,t)=1. |
|---|
| 241 | endif |
|---|
| 242 | if (q_h2o_GCM(i,j,t).LT.0) then |
|---|
| 243 | q_h2o_GCM(i,j,t)=1E-30 |
|---|
| 244 | elseif (q_h2o_GCM(i,j,t).GT.1) then |
|---|
| 245 | q_h2o_GCM(i,j,t)=1. |
|---|
| 246 | endif |
|---|
| 247 | mmean=1/(A*q_co2_GCM(i,j,t) +B) |
|---|
| 248 | vmr_co2_gcm(i,j,t) = q_co2_GCM(i,j,t)*mmean/m_co2 |
|---|
| 249 | ENDDO |
|---|
| 250 | ENDDO |
|---|
| 251 | ENDDO |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | deallocate(co2_ice_s) |
|---|
| 255 | deallocate(h2o_ice_s_slope) |
|---|
| 256 | deallocate(h2o_ice_s) |
|---|
| 257 | |
|---|
| 258 | |
|---|
| 259 | CONTAINS |
|---|
| 260 | |
|---|
| 261 | SUBROUTINE check_dim(n1,n2,str1,str2) |
|---|
| 262 | INTEGER, INTENT(IN) :: n1, n2 |
|---|
| 263 | CHARACTER(LEN=*), INTENT(IN) :: str1, str2 |
|---|
| 264 | CHARACTER(LEN=256) :: s1, s2 |
|---|
| 265 | IF(n1/=n2) THEN |
|---|
| 266 | s1='value of '//TRIM(str1)//' =' |
|---|
| 267 | s2=' read in starting file differs from parametrized '//TRIM(str2)//' =' |
|---|
| 268 | WRITE(msg,'(10x,a,i4,2x,a,i4)')TRIM(s1),n1,TRIM(s2),n2 |
|---|
| 269 | CALL ABORT_gcm(TRIM(modname),TRIM(msg),1) |
|---|
| 270 | END IF |
|---|
| 271 | END SUBROUTINE check_dim |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | SUBROUTINE get_var1(var,v) |
|---|
| 275 | CHARACTER(LEN=*), INTENT(IN) :: var |
|---|
| 276 | REAL, INTENT(OUT) :: v(:) |
|---|
| 277 | CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var) |
|---|
| 278 | CALL err(NF90_GET_VAR(fID,vID,v),"get",var) |
|---|
| 279 | END SUBROUTINE get_var1 |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | SUBROUTINE get_var3(var,v) ! on U grid |
|---|
| 283 | CHARACTER(LEN=*), INTENT(IN) :: var |
|---|
| 284 | REAL, INTENT(OUT) :: v(:,:,:) |
|---|
| 285 | CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var) |
|---|
| 286 | CALL err(NF90_GET_VAR(fID,vID,v),"get",var) |
|---|
| 287 | |
|---|
| 288 | END SUBROUTINE get_var3 |
|---|
| 289 | |
|---|
| 290 | SUBROUTINE get_var4(var,v) |
|---|
| 291 | CHARACTER(LEN=*), INTENT(IN) :: var |
|---|
| 292 | REAL, INTENT(OUT) :: v(:,:,:,:) |
|---|
| 293 | CALL err(NF90_INQ_VARID(fID,var,vID),"inq",var) |
|---|
| 294 | CALL err(NF90_GET_VAR(fID,vID,v),"get",var) |
|---|
| 295 | END SUBROUTINE get_var4 |
|---|
| 296 | |
|---|
| 297 | SUBROUTINE err(ierr,typ,nam) |
|---|
| 298 | INTEGER, INTENT(IN) :: ierr !--- NetCDF ERROR CODE |
|---|
| 299 | CHARACTER(LEN=*), INTENT(IN) :: typ !--- TYPE OF OPERATION |
|---|
| 300 | CHARACTER(LEN=*), INTENT(IN) :: nam !--- FIELD/FILE NAME |
|---|
| 301 | IF(ierr==NF90_NoERR) RETURN |
|---|
| 302 | SELECT CASE(typ) |
|---|
| 303 | CASE('inq'); msg="Field <"//TRIM(nam)//"> is missing" |
|---|
| 304 | CASE('get'); msg="Reading failed for <"//TRIM(nam)//">" |
|---|
| 305 | CASE('open'); msg="File opening failed for <"//TRIM(nam)//">" |
|---|
| 306 | CASE('close'); msg="File closing failed for <"//TRIM(nam)//">" |
|---|
| 307 | END SELECT |
|---|
| 308 | CALL ABORT_gcm(TRIM(modname),TRIM(msg),ierr) |
|---|
| 309 | END SUBROUTINE err |
|---|
| 310 | |
|---|
| 311 | END SUBROUTINE read_data_gcm |
|---|