SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
start_lake_of.F90
Go to the documentation of this file.
1 !SFX_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
2 !SFX_LIC This is part of the SURFEX software governed by the CeCILL-C licence
3 !SFX_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4 !SFX_LIC for details. version 1.
5 ! #######
6 SUBROUTINE start_lake_of(KDAY, KMONTH, PLON, PLAT, PDEPTH, & ! IN
7  pt_snow, pt_ice, pt_mnw, pt_wml, pt_bot, pt_b1, pct, & ! Lake variables
8  ph_snow, ph_ice, ph_ml, ph_b1, pt_sfc) ! OUT
9 ! ###############
10 !
11 ! PURPOSE: Extract the climate lake variables from the climate lake dataset
12 ! for the given date, the given grid box of the atmopheric model grid in lon-lat
13 ! and for the given lake depth;
14 ! this version is for netcdf3 (old-fashioned)
15 ! AUTHOR: Ekaterina Kourzeneva,
16 ! Meteo France, 2010
17 ! INPUT: KDAY - the day number
18 ! KMONTH - the month number
19 ! PLON - longitude of the center of the atmospheric model grid box, deg. dec., -180.0 ... 180.0
20 ! PLAT - latitude of the center of the atmospheric model grid box, deg. dec., -90.0 ... 90.0
21 ! PDEPTH - the lake depth in the grid box, m
22 ! LIBRARIES: NetCDF. Install it and make sure you use right compilation and linkage lines!
23 ! (see the example for details)
24 ! READS FILES: data for the lake climatology (LAKE_LTA.nc)
25 ! Be sure that all necessary files are present and not zipped!!!
26 ! OUTPUT: PT_SNOW - the snow temperature, K (no snow at present, so equal to the ice temperature)
27 ! PT_ICE - the ice temperature, K
28 ! PT_MNW - the mean water temperature, K
29 ! PT_WML - the mixed layer temperature, K
30 ! PT_BOT - the bottom temperature, K
31 ! PT_B1 - the temperature on the outer edge of the active layer of the bottom sediments, K
32 ! (at present the bottom sediments block is not used,
33 ! so eq. to the freshwater maximum density temperature)
34 ! PCT - the shape factor, dimensioneless
35 ! PH_SNOW - the snow depth, m (no snow at present, so equal to zero)
36 ! PH_ICE - the ice depth, m
37 ! PH_ML - the mixed layer depth, m
38 ! PH_B1 - the depth of the active layer if the bottom sediments, m
39 ! (at present the bottom sediments block is not used,
40 ! so eq. to the dummy value)
41 ! PT_SFC - the surface temperature, K (the diagnostic value, so just for information)
42 ! WRITES FILES: no
43 !
44 !------------------------------------------------------------------------------------------------------------
45 ! Modified 07/2012, P. Le Moigne : In case there's a lake but no climatic data
46 ! associated then fill with neighbour existing data
47 ! instead of aborting
48 !------------------------------------------------------------------------------------------------------------
49 !
50 USE modd_data_lake, ONLY : clakelta, nlong, nlatg, xfirstlat, &
51  xc_small, ngraddepth_lta, xcentrgraddepth_lta, &
52  xauxt_snow, xauxt_ice, xauxt_mnw, xauxt_wml, xauxt_bot, &
53  xauxt_b1, xauxct, xauxh_snow, xauxh_ice, xauxh_ml, &
54  xauxh_b1, xauxt_sfc
55 !
56 USE modi_abor1_sfx
57 !
58 USE yomhook ,ONLY : lhook, dr_hook
59 USE parkind1 ,ONLY : jprb
60 !
61 IMPLICIT NONE
62 include 'netcdf.inc'
63 !
64 !* 0.1 declarations of arguments
65 !
66 INTEGER, INTENT(IN) :: kday, & ! The day number
67  kmonth ! The month number
68 REAL, INTENT(IN) :: plon, plat ! Longitude and latitude of the center of the atmospheric model grid box,
69  ! deg. dec. (-180.0 ... 180.0), (-90.0 ... 90.0)
70 REAL, INTENT(IN) :: pdepth ! The depth of the lakes, m
71 REAL, INTENT(OUT) :: pt_snow, & ! the snow temperature, K (no snow at present, so equal to the ice temperature)
72  pt_ice, & ! the ice temperature, K
73  pt_mnw, & ! the mean water temperature, K
74  pt_wml, & ! the mixed layer temperature, K
75  pt_bot, & ! the bottom temperature, K
76  pt_b1, & ! the temperature on the outer edge of the active layer of the bottom sediments, K
77  ! (at present the bottom sediments block is not used,
78  ! so eq. to the freshwater maximum density temperature)
79  pct, & ! the shape factor, dimensioneless
80  ph_snow, & ! the snow depth, m (no snow at present, so equal to zero)
81  ph_ice, & ! the ice depth, m
82  ph_ml, & ! the mixed layer depth, m
83  ph_b1, & ! the depth of the active layer if the bottom sediments, m
84  ! (at present the bottom sediments block is not used,
85  ! so eq. to the dummy value)
86  pt_sfc ! the surface temperature, K (the diagnostic value, so just for information)
87 !
88 !* 0.2 declarations of local variables
89 !
90 REAL, DIMENSION(1,1) :: zwt_snow, zwt_ice, zwt_mnw, zwt_wml, zwt_bot, zwt_b1, zwct, & ! Lake values
91  zwh_snow, zwh_ice, zwh_ml, zwh_b1, zwt_sfc ! to read from NetCDF
92 REAL :: zft_snow, zft_ice, zft_mnw, zft_wml, zft_bot, zft_b1, zfct, &
93  zfh_snow, zfh_ice, zfh_ml, zfh_b1, zft_sfc
94 REAL, DIMENSION(NGRADDEPTH_LTA) :: zdistd
95 REAL :: zwlon, zwlat, zwdepth
96 !
97 LOGICAL :: lexist
98 !
99  INTEGER :: id_lakelta, id_month, & ! IDs for NetCDF
100  id_dec, id_lon, id_lat, id_depth, &
101  id_t_snow, id_t_ice, id_t_mnw, id_t_wml, id_t_bot, id_t_b1, id_ct, &
102  id_h_snow, id_h_ice, id_h_ml, id_h_b1, id_t_sfc
103  INTEGER :: idec, imonth ! Number of the decade and the month
104  INTEGER :: ilon, ilat ! Numbers of the "lake" grid boxes in longitude and latitude
105  INTEGER :: idepth ! Number of the lake class in depth
106  INTEGER, DIMENSION(1) :: iloc_depth
107  INTEGER :: iret
108  INTEGER :: imonthn, idecn, ilonn, ilatn, idepthn
109  INTEGER, DIMENSION(5) :: nindex
110  REAL(KIND=JPRB) :: zhook_handle
111 ! ----------------------------------------------------------------------------------------------
112 !
113 IF (lhook) CALL dr_hook('START_LAKE_OF',0,zhook_handle)
114 !
115 !* 0. Check
116 !
117 IF(kday.LE.0 .OR. kday.GT.31) CALL abor1_sfx("START_LAKE_OF: WRONG DAY NUMBER (!!!!)")
118 IF(kmonth.LE.0 .OR. kmonth.GT.12) CALL abor1_sfx("START_LAKE_OF: WRONG MONTH NUMBER (!!!!)")
119 IF(plon.LT.-180. .OR. plon.GT.180.) CALL abor1_sfx("START_LAKE_OF: WRONG LONGITUDE (!!!!)")
120 IF(plat.LT.-90. .OR. plat.GT.90.) CALL abor1_sfx("START_LAKE_OF: WRONG LATITUDE (!!!!)")
121 !
122 !* 1. Calculate time indexes
123 !
124 imonth = kmonth
125 !
126 SELECT CASE(kday)
127  CASE(1:10)
128  idec=1
129  CASE(11:20)
130  idec=2
131  CASE(21:31)
132  idec=3
133 END SELECT
134 !
135 !* 2. Calculate lon-lat indexes
136 !
137 zwlon = plon
138 zwlat = max(plat,xfirstlat)
139 !
140 ilon = nint(zwlon) + nlong/2 + 1
141 ilat = nint(zwlat) - xfirstlat + 1
142 !
143 !* 3. Check lake depth
144 !
145 IF (pdepth.LT.xc_small) &
146  CALL abor1_sfx("START_LAKE_OF: YOUR LAKE DEPTH IS TOO SMALL TO ACTIVATE CLI_LAKE IN SOME POINTS")
147 !
148 !* 4. Calculate the appropriate index
149 !
150 zwdepth = min(pdepth,50.)
151 zdistd = abs(xcentrgraddepth_lta(:) - zwdepth)
152 iloc_depth = minloc(zdistd)
153 idepth = iloc_depth(1)
154 !
155 !* 5. Open file for reading
156 !
157 iret = nf_open(trim(adjustl(clakelta)),nf_nowrite,id_lakelta)
158 IF (iret.NE.0) CALL abor1_sfx("START_LAKE_OF: WRONG OR NO LAKE DATA FILE")
159 !
160 !* 6. Check data in the lake file
161 !
162 iret = nf_inq_dimid(id_lakelta, "NMonth", id_month)
163 iret = nf_inq_dimlen(id_lakelta, id_month, imonthn)
164 IF (imonthn.NE.12) CALL abor1_sfx("START_LAKE_OF: NUMBER OF MONTHS IN THE LAKE FILE IS NOT 12????")
165 !
166 iret = nf_inq_dimid(id_lakelta, "NDec", id_dec)
167 iret = nf_inq_dimlen(id_lakelta, id_dec, idecn)
168 IF (idecn.NE.3) CALL abor1_sfx("START_LAKE_OF: NUMBER OF DECADES IN MONTH IN THE LAKE FILE IS NOT 3????")
169 !
170 iret = nf_inq_dimid(id_lakelta, "NLon", id_lon)
171 iret = nf_inq_dimlen(id_lakelta, id_lon, ilonn)
172 IF (ilonn.NE.nlong) CALL abor1_sfx("START_LAKE_OF: WRONG NUMBER OF POINTS IN LONGITUDE IN THE LAKE FILE!")
173 !
174 iret = nf_inq_dimid(id_lakelta, "NLat", id_lat)
175 iret = nf_inq_dimlen(id_lakelta, id_lat, ilatn)
176 IF (ilatn.NE.nlatg) CALL abor1_sfx("START_LAKE_OF: WRONG NUMBER OF POINTS IN LONGITUDE IN THE LAKE FILE!")
177 !
178 iret = nf_inq_dimid(id_lakelta, "NDepth", id_depth)
179 iret = nf_inq_dimlen(id_lakelta, id_depth, idepthn)
180 IF (idepthn.NE.ngraddepth_lta) CALL abor1_sfx("START_LAKE_OF: WRONG NUMBER OF GRADATIONS IN DEPTH IN THE LAKE FILE!")
181 !
182 iret = nf_inq_varid(id_lakelta, "T_snow", id_t_snow)
183 iret = nf_inq_varid(id_lakelta, "T_ice", id_t_ice)
184 iret = nf_inq_varid(id_lakelta, "T_mnw", id_t_mnw)
185 iret = nf_inq_varid(id_lakelta, "T_wML", id_t_wml)
186 iret = nf_inq_varid(id_lakelta, "T_bot", id_t_bot)
187 iret = nf_inq_varid(id_lakelta, "T_B1", id_t_b1)
188 iret = nf_inq_varid(id_lakelta, "C_T", id_ct)
189 iret = nf_inq_varid(id_lakelta, "h_snow", id_h_snow)
190 iret = nf_inq_varid(id_lakelta, "h_ice", id_h_ice)
191 iret = nf_inq_varid(id_lakelta, "h_ML", id_h_ml)
192 iret = nf_inq_varid(id_lakelta, "H_B1", id_h_b1)
193 iret = nf_inq_varid(id_lakelta, "T_sfc", id_t_sfc)
194 !
195 !* 7. Reading
196 !
197 nindex(1) = imonth
198 nindex(2) = idec
199 nindex(3) = ilon
200 nindex(4) = ilat
201 nindex(5) = idepth
202 !
203 iret = nf_get_att_double(id_lakelta, id_t_snow, '_FillValue',zft_snow)
204 iret = nf_get_att_double(id_lakelta, id_t_ice, '_FillValue',zft_ice)
205 iret = nf_get_att_double(id_lakelta, id_t_mnw, '_FillValue',zft_mnw)
206 iret = nf_get_att_double(id_lakelta, id_t_wml, '_FillValue',zft_wml)
207 iret = nf_get_att_double(id_lakelta, id_t_bot, '_FillValue',zft_bot)
208 iret = nf_get_att_double(id_lakelta, id_t_b1, '_FillValue',zft_b1)
209 iret = nf_get_att_double(id_lakelta, id_ct, '_FillValue',zfct)
210 iret = nf_get_att_double(id_lakelta, id_h_snow, '_FillValue',zfh_snow)
211 iret = nf_get_att_double(id_lakelta, id_h_ice, '_FillValue',zfh_ice)
212 iret = nf_get_att_double(id_lakelta, id_h_ml, '_FillValue',zfh_ml)
213 iret = nf_get_att_double(id_lakelta, id_h_b1, '_FillValue',zfh_b1)
214 iret = nf_get_att_double(id_lakelta, id_t_snow, '_FillValue',zft_sfc)
215 !
216 iret = nf_get_var1_double(id_lakelta, id_t_snow, nindex, zwt_snow)
217 iret = nf_get_var1_double(id_lakelta, id_t_ice, nindex, zwt_ice)
218 iret = nf_get_var1_double(id_lakelta, id_t_mnw, nindex, zwt_mnw)
219 iret = nf_get_var1_double(id_lakelta, id_t_wml, nindex, zwt_wml)
220 iret = nf_get_var1_double(id_lakelta, id_t_bot, nindex, zwt_bot)
221 iret = nf_get_var1_double(id_lakelta, id_t_b1, nindex, zwt_b1)
222 iret = nf_get_var1_double(id_lakelta, id_ct, nindex, zwct)
223 iret = nf_get_var1_double(id_lakelta, id_h_snow, nindex, zwh_snow)
224 iret = nf_get_var1_double(id_lakelta, id_h_ice, nindex, zwh_ice)
225 iret = nf_get_var1_double(id_lakelta, id_h_ml, nindex, zwh_ml)
226 iret = nf_get_var1_double(id_lakelta, id_h_b1, nindex, zwh_b1)
227 iret = nf_get_var1_double(id_lakelta, id_t_sfc, nindex, zwt_sfc)
228 !
229 !* 8. Close file
230 !
231 iret = nf_close(id_lakelta)
232 !
233 !* 9. Make output
234 !
235 
236 lexist=(zwt_snow(1,1).NE.zft_snow .AND. zwt_ice(1,1).NE.zft_ice .AND. zwt_mnw(1,1).NE.zft_mnw .AND. &
237  zwt_wml(1,1).NE.zft_wml .AND. zwt_bot(1,1).NE.zft_bot .AND. zwt_b1(1,1).NE.zft_b1 .AND. &
238  zwct(1,1).NE.zfct .AND. zwh_snow(1,1).NE.zfh_snow .AND. zwh_ice(1,1).NE.zfh_ice .AND. &
239  zwh_ml(1,1).NE.zfh_ml .AND. zwh_b1(1,1).NE.zfh_b1 .AND. zwt_sfc(1,1).NE.zft_sfc)
240 
241 IF (lexist) THEN
242  !
243  xauxt_snow = zwt_snow(1,1)
244  xauxt_ice = zwt_ice(1,1)
245  xauxt_mnw = zwt_mnw(1,1)
246  xauxt_wml = zwt_wml(1,1)
247  xauxt_bot = zwt_bot(1,1)
248  xauxt_b1 = zwt_b1(1,1)
249  xauxct = zwct(1,1)
250  xauxh_snow = zwh_snow(1,1)
251  xauxh_ice = zwh_ice(1,1)
252  xauxh_ml = zwh_ml(1,1)
253  xauxh_b1 = zwh_b1(1,1)
254  xauxt_sfc = zwt_sfc(1,1)
255  !
256 ENDIF
257 !
258 pt_snow = xauxt_snow
259 pt_ice = xauxt_ice
260 pt_mnw = xauxt_mnw
261 pt_wml = xauxt_wml
262 pt_bot = xauxt_bot
263 pt_b1 = xauxt_b1
264 pct = xauxct
265 ph_snow = xauxh_snow
266 ph_ice = xauxh_ice
267 ph_ml = xauxh_ml
268 ph_b1 = xauxh_b1
269 pt_sfc = xauxt_sfc
270 !
271 IF (lhook) CALL dr_hook('START_LAKE_OF',1,zhook_handle)
272 !
273 END SUBROUTINE start_lake_of
subroutine start_lake_of(KDAY, KMONTH, PLON, PLAT, PDEPTH, PT_SNOW, PT_ICE, PT_MNW, PT_WML, PT_BOT, PT_B1, PCT, PH_SNOW, PH_ICE, PH_ML, PH_B1, PT_SFC)
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6