SURFEX v8.1
General documentation of Surfex
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 !
55 !
56 USE modi_abor1_sfx
57 !
58 USE yomhook ,ONLY : lhook, dr_hook
59 USE parkind1 ,ONLY : jprb
60 !
61 USE netcdf
62 !
63 IMPLICIT NONE
64 !
65 !* 0.1 declarations of arguments
66 !
67 INTEGER, INTENT(IN) :: KDAY, & ! The day number
68  KMONTH ! The month number
69 REAL, INTENT(IN) :: PLON, PLAT ! Longitude and latitude of the center of the atmospheric model grid box,
70  ! deg. dec. (-180.0 ... 180.0), (-90.0 ... 90.0)
71 REAL, INTENT(IN) :: PDEPTH ! The depth of the lakes, m
72 REAL, INTENT(OUT) :: PT_SNOW, & ! the snow temperature, K (no snow at present, so equal to the ice temperature)
73  PT_ICE, & ! the ice temperature, K
74  PT_MNW, & ! the mean water temperature, K
75  PT_WML, & ! the mixed layer temperature, K
76  PT_BOT, & ! the bottom temperature, K
77  PT_B1, & ! the temperature on the outer edge of the active layer of the bottom sediments, K
78  ! (at present the bottom sediments block is not used,
79  ! so eq. to the freshwater maximum density temperature)
80  pct, & ! the shape factor, dimensioneless
81  ph_snow, & ! the snow depth, m (no snow at present, so equal to zero)
82  ph_ice, & ! the ice depth, m
83  ph_ml, & ! the mixed layer depth, m
84  ph_b1, & ! the depth of the active layer if the bottom sediments, m
85  ! (at present the bottom sediments block is not used,
86  ! so eq. to the dummy value)
87  pt_sfc ! the surface temperature, K (the diagnostic value, so just for information)
88 !
89 !* 0.2 declarations of local variables
90 !
91 REAL, DIMENSION(1,1) :: ZWT_SNOW, ZWT_ICE, ZWT_MNW, ZWT_WML, ZWT_BOT, ZWT_B1, ZWCT, & ! Lake values
92  ZWH_SNOW, ZWH_ICE, ZWH_ML, ZWH_B1, ZWT_SFC ! to read from NetCDF
93 REAL :: ZFT_SNOW, ZFT_ICE, ZFT_MNW, ZFT_WML, ZFT_BOT, ZFT_B1, ZFCT, &
94  ZFH_SNOW, ZFH_ICE, ZFH_ML, ZFH_B1, ZFT_SFC
95 REAL, DIMENSION(NGRADDEPTH_LTA) :: ZDISTD
96 REAL :: ZWLON, ZWLAT, ZWDEPTH
97 !
98 LOGICAL :: LEXIST
99 !
100  INTEGER :: ID_LAKELTA, ID_MONTH, & ! IDs for NetCDF
101  ID_DEC, ID_LON, ID_LAT, ID_DEPTH, &
102  ID_T_SNOW, ID_T_ICE, ID_T_MNW, ID_T_WML, ID_T_BOT, ID_T_B1, ID_CT, &
103  ID_H_SNOW, ID_H_ICE, ID_H_ML, ID_H_B1, ID_T_SFC
104  INTEGER :: IDEC, IMONTH ! Number of the decade and the month
105  INTEGER :: ILON, ILAT ! Numbers of the "lake" grid boxes in longitude and latitude
106  INTEGER :: IDEPTH ! Number of the lake class in depth
107  INTEGER, DIMENSION(1) :: ILOC_DEPTH
108  INTEGER :: IRET
109  INTEGER :: IMONTHN, IDECN, ILONN, ILATN, IDEPTHN
110  INTEGER, DIMENSION(5) :: NINDEX
111  REAL(KIND=JPRB) :: ZHOOK_HANDLE
112 ! ----------------------------------------------------------------------------------------------
113 !
114 IF (lhook) CALL dr_hook('START_LAKE_OF',0,zhook_handle)
115 !
116 !* 0. Check
117 !
118 IF(kday.LE.0 .OR. kday.GT.31) CALL abor1_sfx("START_LAKE_OF: WRONG DAY NUMBER (!!!!)")
119 IF(kmonth.LE.0 .OR. kmonth.GT.12) CALL abor1_sfx("START_LAKE_OF: WRONG MONTH NUMBER (!!!!)")
120 IF(plon.LT.-180. .OR. plon.GT.180.) CALL abor1_sfx("START_LAKE_OF: WRONG LONGITUDE (!!!!)")
121 IF(plat.LT.-90. .OR. plat.GT.90.) CALL abor1_sfx("START_LAKE_OF: WRONG LATITUDE (!!!!)")
122 !
123 !* 1. Calculate time indexes
124 !
125 imonth = kmonth
126 !
127 SELECT CASE(kday)
128  CASE(1:10)
129  idec=1
130  CASE(11:20)
131  idec=2
132  CASE(21:31)
133  idec=3
134 END SELECT
135 !
136 !* 2. Calculate lon-lat indexes
137 !
138 zwlon = plon
139 zwlat = max(plat,xfirstlat)
140 !
141 ilon = nint(zwlon) + nlong/2 + 1
142 ilat = nint(zwlat) - xfirstlat + 1
143 !
144 !* 3. Check lake depth
145 !
146 IF (pdepth.LT.xc_small) &
147  CALL abor1_sfx("START_LAKE_OF: YOUR LAKE DEPTH IS TOO SMALL TO ACTIVATE CLI_LAKE IN SOME POINTS")
148 !
149 !* 4. Calculate the appropriate index
150 !
151 zwdepth = min(pdepth,50.)
152 zdistd = abs(xcentrgraddepth_lta(:) - zwdepth)
153 iloc_depth = minloc(zdistd)
154 idepth = iloc_depth(1)
155 !
156 !* 5. Open file for reading
157 !
158 iret = nf90_open(trim(adjustl(clakelta)),nf90_nowrite,id_lakelta)
159 IF (iret.NE.0) CALL abor1_sfx("START_LAKE_OF: WRONG OR NO LAKE DATA FILE")
160 !
161 !* 6. Check data in the lake file
162 !
163 iret = nf90_inq_dimid(id_lakelta, "NMonth", id_month)
164 iret = nf90_inquire_dimension(id_lakelta, id_month, len=imonthn)
165 IF (imonthn.NE.12) CALL abor1_sfx("START_LAKE_OF: NUMBER OF MONTHS IN THE LAKE FILE IS NOT 12????")
166 !
167 iret = nf90_inq_dimid(id_lakelta, "NDec", id_dec)
168 iret = nf90_inquire_dimension(id_lakelta, id_dec, len=idecn)
169 IF (idecn.NE.3) CALL abor1_sfx("START_LAKE_OF: NUMBER OF DECADES IN MONTH IN THE LAKE FILE IS NOT 3????")
170 !
171 iret = nf90_inq_dimid(id_lakelta, "NLon", id_lon)
172 iret = nf90_inquire_dimension(id_lakelta, id_lon, len=ilonn)
173 IF (ilonn.NE.nlong) CALL abor1_sfx("START_LAKE_OF: WRONG NUMBER OF POINTS IN LONGITUDE IN THE LAKE FILE!")
174 !
175 iret = nf90_inq_dimid(id_lakelta, "NLat", id_lat)
176 iret = nf90_inquire_dimension(id_lakelta, id_lat, len=ilatn)
177 IF (ilatn.NE.nlatg) CALL abor1_sfx("START_LAKE_OF: WRONG NUMBER OF POINTS IN LONGITUDE IN THE LAKE FILE!")
178 !
179 iret = nf90_inq_dimid(id_lakelta, "NDepth", id_depth)
180 iret = nf90_inquire_dimension(id_lakelta, id_depth, len=idepthn)
181 IF (idepthn.NE.ngraddepth_lta) CALL abor1_sfx("START_LAKE_OF: WRONG NUMBER OF GRADATIONS IN DEPTH IN THE LAKE FILE!")
182 !
183 iret = nf90_inq_varid(id_lakelta, "T_snow", id_t_snow)
184 iret = nf90_inq_varid(id_lakelta, "T_ice", id_t_ice)
185 iret = nf90_inq_varid(id_lakelta, "T_mnw", id_t_mnw)
186 iret = nf90_inq_varid(id_lakelta, "T_wML", id_t_wml)
187 iret = nf90_inq_varid(id_lakelta, "T_bot", id_t_bot)
188 iret = nf90_inq_varid(id_lakelta, "T_B1", id_t_b1)
189 iret = nf90_inq_varid(id_lakelta, "C_T", id_ct)
190 iret = nf90_inq_varid(id_lakelta, "h_snow", id_h_snow)
191 iret = nf90_inq_varid(id_lakelta, "h_ice", id_h_ice)
192 iret = nf90_inq_varid(id_lakelta, "h_ML", id_h_ml)
193 iret = nf90_inq_varid(id_lakelta, "H_B1", id_h_b1)
194 iret = nf90_inq_varid(id_lakelta, "T_sfc", id_t_sfc)
195 !
196 !* 7. Reading
197 !
198 nindex(1) = imonth
199 nindex(2) = idec
200 nindex(3) = ilon
201 nindex(4) = ilat
202 nindex(5) = idepth
203 !
204 iret = nf90_get_att(id_lakelta, id_t_snow, '_FillValue',zft_snow)
205 iret = nf90_get_att(id_lakelta, id_t_ice, '_FillValue',zft_ice)
206 iret = nf90_get_att(id_lakelta, id_t_mnw, '_FillValue',zft_mnw)
207 iret = nf90_get_att(id_lakelta, id_t_wml, '_FillValue',zft_wml)
208 iret = nf90_get_att(id_lakelta, id_t_bot, '_FillValue',zft_bot)
209 iret = nf90_get_att(id_lakelta, id_t_b1, '_FillValue',zft_b1)
210 iret = nf90_get_att(id_lakelta, id_ct, '_FillValue',zfct)
211 iret = nf90_get_att(id_lakelta, id_h_snow, '_FillValue',zfh_snow)
212 iret = nf90_get_att(id_lakelta, id_h_ice, '_FillValue',zfh_ice)
213 iret = nf90_get_att(id_lakelta, id_h_ml, '_FillValue',zfh_ml)
214 iret = nf90_get_att(id_lakelta, id_h_b1, '_FillValue',zfh_b1)
215 iret = nf90_get_att(id_lakelta, id_t_snow, '_FillValue',zft_sfc)
216 !
217 iret = nf90_get_var(id_lakelta, id_t_snow, zwt_snow, nindex)
218 iret = nf90_get_var(id_lakelta, id_t_ice, zwt_ice, nindex)
219 iret = nf90_get_var(id_lakelta, id_t_mnw, zwt_mnw, nindex)
220 iret = nf90_get_var(id_lakelta, id_t_wml, zwt_wml, nindex)
221 iret = nf90_get_var(id_lakelta, id_t_bot, zwt_bot, nindex)
222 iret = nf90_get_var(id_lakelta, id_t_b1, zwt_b1, nindex)
223 iret = nf90_get_var(id_lakelta, id_ct, zwct, nindex)
224 iret = nf90_get_var(id_lakelta, id_h_snow, zwh_snow, nindex)
225 iret = nf90_get_var(id_lakelta, id_h_ice, zwh_ice, nindex)
226 iret = nf90_get_var(id_lakelta, id_h_ml, zwh_ml, nindex)
227 iret = nf90_get_var(id_lakelta, id_h_b1, zwh_b1, nindex)
228 iret = nf90_get_var(id_lakelta, id_t_sfc, zwt_sfc, nindex)
229 !
230 !* 8. Close file
231 !
232 iret = nf90_close(id_lakelta)
233 !
234 !* 9. Make output
235 !
236 
237 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. &
238  zwt_wml(1,1).NE.zft_wml .AND. zwt_bot(1,1).NE.zft_bot .AND. zwt_b1(1,1).NE.zft_b1 .AND. &
239  zwct(1,1).NE.zfct .AND. zwh_snow(1,1).NE.zfh_snow .AND. zwh_ice(1,1).NE.zfh_ice .AND. &
240  zwh_ml(1,1).NE.zfh_ml .AND. zwh_b1(1,1).NE.zfh_b1 .AND. zwt_sfc(1,1).NE.zft_sfc)
241 
242 IF (lexist) THEN
243  !
244  xauxt_snow = zwt_snow(1,1)
245  xauxt_ice = zwt_ice(1,1)
246  xauxt_mnw = zwt_mnw(1,1)
247  xauxt_wml = zwt_wml(1,1)
248  xauxt_bot = zwt_bot(1,1)
249  xauxt_b1 = zwt_b1(1,1)
250  xauxct = zwct(1,1)
251  xauxh_snow = zwh_snow(1,1)
252  xauxh_ice = zwh_ice(1,1)
253  xauxh_ml = zwh_ml(1,1)
254  xauxh_b1 = zwh_b1(1,1)
255  xauxt_sfc = zwt_sfc(1,1)
256  !
257 ENDIF
258 !
259 pt_snow = xauxt_snow
260 pt_ice = xauxt_ice
261 pt_mnw = xauxt_mnw
262 pt_wml = xauxt_wml
263 pt_bot = xauxt_bot
264 pt_b1 = xauxt_b1
265 pct = xauxct
266 ph_snow = xauxh_snow
267 ph_ice = xauxh_ice
268 ph_ml = xauxh_ml
269 ph_b1 = xauxh_b1
270 pt_sfc = xauxt_sfc
271 !
272 IF (lhook) CALL dr_hook('START_LAKE_OF',1,zhook_handle)
273 !
274 END SUBROUTINE start_lake_of
static const char * trim(const char *name, int *n)
Definition: drhook.c:2383
character(len=80), parameter clakelta
integer, parameter nlong
integer, parameter nlatg
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)
real, parameter xc_small
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:7
integer, parameter jprb
Definition: parkind1.F90:32
real, dimension(ngraddepth_lta), parameter xcentrgraddepth_lta
logical lhook
Definition: yomhook.F90:15
integer, parameter ngraddepth_lta
real, parameter xfirstlat