UPP  V11.0.0
 All Data Structures Files Functions Pages
getlvls.f
1  subroutine getlvls(param,ithfld,ifld,found_fld,kpv,pv)
2 !
3 ! 03_10_2015 Lin Gan - Using flat file data
4 !
5 
6  use xml_perl_data, only : param_t
7  use ctlblk_mod, only : lsm, spl, nsoil, isf_surface_physics, &
8  me, nfd, htfd, nbnd, petabnd
9  use rqstfld_mod, only : lvls, lvlsxml, mxlvl, lvls, iget, ident, &
10  iavblfld
11  use soil, only : sldpth,sllevel
12  implicit none
13 !
14  type(param_t),intent(in) :: param
15  integer, intent(in) :: ithfld,kpv
16  integer, intent(inout) :: ifld
17  logical, intent(inout) :: found_fld
18  real,intent(in) :: pv(1:kpv)
19 !
20  real,parameter :: small=1.e-5
21  real,parameter :: small1=1.e-3
22  real,parameter :: small2=1
23  integer i,j,nlevel,scalef,lvlcape,lvlcin
24  logical :: lincfld
25 !
26  lincfld=.false.
27  nlevel=size(param%level)
28 !
29  if(trim(param%fixed_sfc1_type)=='isobaric_sfc') then
30  do j=1, nlevel
31  iloop: do i=1, lsm
32 
33  if(abs(param%level(j)-spl(i))<small1)then
34  lvls(i,ifld)=1
35  lvlsxml(i,ifld)=j
36  exit iloop
37  endif
38  enddo iloop
39  enddo
40  endif
41 !
42  if(trim(param%fixed_sfc1_type)=='hybrid_lvl') then
43  do j=1, nlevel
44  iloop1: do i=1, mxlvl
45  if(nint(param%level(j))==i)then
46  lvls(i,ifld)=1
47  lvlsxml(i,ifld)=j
48  exit iloop1
49  endif
50  enddo iloop1
51  enddo
52  endif
53 !
54  if(trim(param%fixed_sfc1_type)=='depth_bel_land_sfc'.and. &
55  trim(param%fixed_sfc2_type)=='depth_bel_land_sfc' ) then
56 ! if(me==0)print *,'nsoil=',nsoil,'iSF_SURFACE_PHYSICS=',iSF_SURFACE_PHYSICS, &
57 ! 'level=',param%level,'sldpth=',SLDPTH(1:nsoil),'sum=',sum(SLDPTH(1:nsoil))*100.
58  do j=1, nlevel
59  iloop2: do i=1, nsoil
60  if(isf_surface_physics ==3) then
61  if(nint(param%level(j))==nint(sllevel(i)*100.)) then
62  lvls(i,ifld)=1
63  lvlsxml(i,ifld)=j
64  exit iloop2
65  endif
66  else
67  if(nint(param%level2(j))==nint(sum(sldpth(1:i))*100.) ) then
68  lvls(i,ifld)=1
69  lvlsxml(i,ifld)=j
70  exit iloop2
71  endif
72  endif
73  enddo iloop2
74  enddo
75  if(trim(param%pname)=='TSOIL') then
76  iget(116)=ifld
77  ident(ifld) = 116
78  iavblfld(ifld)=ithfld
79  found_fld=.true.
80  elseif(trim(param%pname)=='TMP') then
81  iget(574)=ifld
82  ident(ifld) = 574
83  iavblfld(ifld)=ithfld
84  found_fld=.true.
85  endif
86 ! elseif(trim(param%fixed_sfc1_type)=='depth_bel_land_sfc'.and. &
87 ! trim(param%fixed_sfc2_type)==''.and.(trim(param%pname)=='TSOIL' &
88 ! .or.trim(param%pname)=='TMP')) then
89 ! iget(115)=ifld
90 ! IDENT(IFLD) = 115
91 ! IAVBLFLD(IFLD)=ithfld
92 ! FOUND_FLD=.true.
93 ! LVLS(1,ifld)=1
94 ! LVLSXML(1,ifld)=1
95  endif
96 !
97 !for sigma level, need to check iget
98  if(trim(param%pname)=='RH'.and.trim(param%fixed_sfc1_type)=='sigma_lvl'.and. &
99  trim(param%fixed_sfc2_type)=='sigma_lvl') then
100  do j=1, nlevel
101  if(abs(param%level(j)-33)<small.and.abs(param%level2(j)-100)<small)then
102  lvls(1,ifld)=j
103  lvlsxml(1,ifld)=j
104  iget(066)=ifld
105  ident(ifld) = 066
106  iavblfld(ifld)=ithfld
107  found_fld=.true.
108  ifld=ifld+1
109  else if(abs(param%level(j)-67)<small.and.abs(param%level2(j)-100)<small)then
110  lvls(1,ifld)=j
111  lvlsxml(1,ifld)=j
112  iget(081)=ifld
113  ident(ifld) = 081
114  iavblfld(ifld)=ithfld
115  found_fld=.true.
116  ifld=ifld+1
117  else if(abs(param%level(j)-33)<small.and.abs(param%level2(j)-67)<small)then
118  lvls(1,ifld)=j
119  lvlsxml(1,ifld)=j
120  iget(082)=ifld
121  ident(ifld) = 082
122  iavblfld(ifld)=ithfld
123  found_fld=.true.
124  ifld=ifld+1
125  else if(abs(param%level(j)-47)<small.and.abs(param%level2(j)-100)<small)then
126  lvls(1,ifld)=j
127  lvlsxml(1,ifld)=j
128  iget(099)=ifld
129  ident(ifld) = 099
130  iavblfld(ifld)=ithfld
131  found_fld=.true.
132  ifld=ifld+1
133  else if(abs(param%level(j)-47)<small.and.abs(param%level2(j)-96)<small)then
134  lvls(1,ifld)=j
135  lvlsxml(1,ifld)=j
136  iget(100)=ifld
137  ident(ifld) = 100
138  iavblfld(ifld)=ithfld
139  found_fld=.true.
140  ifld=ifld+1
141  else if(abs(param%level(j)-18)<small.and.abs(param%level2(j)-47)<small)then
142  lvls(1,ifld)=j
143  lvlsxml(1,ifld)=j
144  iget(101)=ifld
145  ident(ifld) = 101
146  iavblfld(ifld)=ithfld
147  found_fld=.true.
148  ifld=ifld+1
149  else if(abs(param%level(j)-84)<small.and.abs(param%level2(j)-98)<small)then
150  lvls(1,ifld)=j
151  lvlsxml(1,ifld)=j
152  iget(102)=ifld
153  ident(ifld) = 102
154  iavblfld(ifld)=ithfld
155  found_fld=.true.
156  ifld=ifld+1
157  else if(abs(param%level(j)-44)<small.and.abs(param%level2(j)-100)<small)then
158  lvls(1,ifld)=j
159  lvlsxml(1,ifld)=j
160  iget(318)=ifld
161  ident(ifld) = 318
162  iavblfld(ifld)=ithfld
163  found_fld=.true.
164  ifld=ifld+1
165  else if(abs(param%level(j)-44)<small.and.abs(param%level2(j)-72)<small)then
166  lvls(1,ifld)=j
167  lvlsxml(1,ifld)=j
168  iget(320)=ifld
169  ident(ifld) = 320
170  iavblfld(ifld)=ithfld
171  found_fld=.true.
172  ifld=ifld+1
173  else if(abs(param%level(j)-72)<small.and.abs(param%level2(j)-94)<small)then
174  lvls(1,ifld)=j
175  lvlsxml(1,ifld)=j
176  iget(319)=ifld
177  ident(ifld) = 319
178  iavblfld(ifld)=ithfld
179  found_fld=.true.
180  ifld=ifld+1
181  endif
182 ! print *,'n getlvls,RH_sigma_lvl,ifld=',ifld-1,'ident(ifld)=',IDENT(IFLD-1), &
183 ! 'iget=',iget(IDENT(IFLD-1)),'IAVBLFLD(IFLD-1)=',IAVBLFLD(IFLD-1),'lvl=',lvls(1,ifld-1), &
184 ! 'iget(66)=',iget(66)
185  enddo
186  ifld=ifld-1
187  endif
188 !
189  if(trim(param%pname)=='RH'.and.trim(param%fixed_sfc1_type)=='sigma_lvl'.and. &
190  trim(param%fixed_sfc2_type)=='') then
191  do j=1, nlevel
192  if(abs(param%level(j)-9823)<small)then
193  lvls(1,ifld)=j
194  lvlsxml(1,ifld)=j
195  iget(094)=ifld
196  ident(ifld) = 094
197  iavblfld(ifld)=ithfld
198  found_fld=.true.
199  ifld=ifld+1
200  else if(abs(param%level(j)-9950)<small)then
201  lvls(1,ifld)=j
202  lvlsxml(1,ifld)=j
203  iget(323)=ifld
204  ident(ifld) = 323
205  iavblfld(ifld)=ithfld
206  found_fld=.true.
207  ifld=ifld+1
208  endif
209 ! print *,'in getlvls,RH_sigma_lvl,1 lvl,ifld=',ifld-1,'ident(ifld)=',IDENT(IFLD-1), &
210 ! 'iget=',iget(IDENT(IFLD-1)),'IAVBLFLD(IFLD-1)=',IAVBLFLD(IFLD-1),'lvl=',lvls(1,ifld-1), &
211 ! 'iget(66)=',iget(66)
212  enddo
213  ifld=ifld-1
214  endif
215 !
216  if(trim(param%fixed_sfc1_type)=='sigma_lvl'.and.trim(param%pname)=='PRES') then
217  do j=1, nlevel
218  if(abs(param%level(j)-98230)<small)then
219  lvls(1,ifld)=1
220  lvlsxml(1,ifld)=j
221  iget(091)=ifld
222  ident(ifld) = 091
223  iavblfld(ifld)=ithfld
224  found_fld=.true.
225  endif
226  enddo
227  endif
228 !
229  if(trim(param%fixed_sfc1_type)=='sigma_lvl'.and.trim(param%pname)=='TMP') then
230  do j=1, nlevel
231  if(abs(param%level(j)-9823)<small1)then
232  lvls(1,ifld)=1
233  lvlsxml(1,ifld)=j
234  iget(092)=ifld
235  ident(ifld) = 092
236  iavblfld(ifld)=ithfld
237  found_fld=.true.
238  lincfld=.true.
239  ifld=ifld+1
240  else if(abs(param%level(j)-8967)<small1)then
241  lvls(1,ifld)=1
242  lvlsxml(1,ifld)=j
243  iget(097)=ifld
244  ident(ifld) = 097
245  iavblfld(ifld)=ithfld
246  found_fld=.true.
247  lincfld=.true.
248  ifld=ifld+1
249  else if(abs(param%level(j)-7848)<small1)then
250  if(me==0)print *,'indie tmp sigma 7848'
251  lvls(1,ifld)=1
252  lvlsxml(1,ifld)=j
253  iget(098)=ifld
254  ident(ifld) = 098
255  iavblfld(ifld)=ithfld
256  found_fld=.true.
257  lincfld=.true.
258  ifld=ifld+1
259  else if(abs(param%level(j)-9950)<small1)then
260  lvls(1,ifld)=1
261  lvlsxml(1,ifld)=j
262  iget(321)=ifld
263  ident(ifld) = 321
264  iavblfld(ifld)=ithfld
265  found_fld=.true.
266  lincfld=.true.
267  ifld=ifld+1
268  endif
269  enddo
270  if(lincfld) ifld=ifld-1
271  do j=1, nlevel
272  if(abs(param%level(j)-7000)<small1.or. abs(param%level(j)-7500)<small1 &
273  .or. abs(param%level(j)-8000)<small1 .or. abs(param%level(j)-8500)<small1 &
274  .or. abs(param%level(j)-9000)<small )then
275  iget(296)=ifld
276  ident(ifld) = 296
277  iavblfld(ifld)=ithfld
278  found_fld=.true.
279  if(abs(param%level(j)-7000)<small1)then
280  lvls(1,ifld)=1
281  lvlsxml(1,ifld)=j
282  else if(abs(param%level(j)-7500)<small1)then
283  lvls(2,ifld)=1
284  lvlsxml(2,ifld)=j
285  else if(abs(param%level(j)-8000)<small1)then
286  lvls(3,ifld)=1
287  lvlsxml(3,ifld)=j
288  else if(abs(param%level(j)-8500)<small1)then
289  lvls(4,ifld)=1
290  lvlsxml(4,ifld)=j
291  else if(abs(param%level(j)-9000)<small1)then
292  lvls(5,ifld)=1
293  lvlsxml(5,ifld)=j
294  endif
295  endif
296  enddo
297  endif
298 !
299 !
300  if(trim(param%fixed_sfc1_type)=='sigma_lvl'.and.trim(param%pname)=='SPF_H') then
301  do j=1, nlevel
302  if(abs(param%level(j)-98230)<small)then
303  lvls(1,ifld)=1
304  lvlsxml(1,ifld)=j
305  iget(093)=ifld
306  ident(ifld) = 093
307  iavblfld(ifld)=ithfld
308  found_fld=.true.
309  endif
310  enddo
311  endif
312 !
313  if(trim(param%fixed_sfc1_type)=='sigma_lvl'.and.trim(param%pname)=='U_GRD') then
314  do j=1, nlevel
315  if(abs(param%level(j)-98230)<small)then
316  lvls(1,ifld)=1
317  lvlsxml(1,ifld)=j
318  iget(095)=ifld
319  ident(ifld) = 095
320  iavblfld(ifld)=ithfld
321  found_fld=.true.
322  ifld=ifld+1
323  else if(abs(param%level(j)-9950)<small)then
324  lvls(1,ifld)=1
325  lvlsxml(1,ifld)=j
326  iget(324)=ifld
327  ident(ifld) = 324
328  iavblfld(ifld)=ithfld
329  found_fld=.true.
330  ifld=ifld+1
331  endif
332  enddo
333  ifld=ifld-1
334  endif
335 !
336  if(trim(param%fixed_sfc1_type)=='sigma_lvl'.and.trim(param%pname)=='V_GRD') then
337  do j=1, nlevel
338  if(abs(param%level(j)-98230)<small)then
339  lvls(1,ifld)=1
340  lvlsxml(1,ifld)=j
341  iget(096)=ifld
342  ident(ifld) = 096
343  iavblfld(ifld)=ithfld
344  found_fld=.true.
345  ifld=ifld+1
346  else if(abs(param%level(j)-9950)<small)then
347  lvls(1,ifld)=1
348  lvlsxml(1,ifld)=j
349  iget(325)=ifld
350  ident(ifld) = 325
351  iavblfld(ifld)=ithfld
352  found_fld=.true.
353  ifld=ifld+1
354  endif
355  enddo
356  ifld=ifld-1
357  endif
358 !
359  if(trim(param%fixed_sfc1_type)=='sigma_lvl'.and.trim(param%pname)=='PWAT') then
360  do j=1, nlevel
361  if(abs(param%level(j)-33)<small.and.abs(param%level2(j)-100)<small)then
362  lvls(1,ifld)=1
363  lvlsxml(1,ifld)=j
364  iget(104)=ifld
365  endif
366  enddo
367  endif
368  if(trim(param%fixed_sfc1_type)=='sigma_lvl'.and.trim(param%pname)=='MCONV') then
369  do j=1, nlevel
370  if(abs(param%level(j)-85)<small.and.abs(param%level2(j)-100)<small)then
371  lvls(1,ifld)=1
372  lvlsxml(1,ifld)=j
373  iget(103)=ifld
374  endif
375  enddo
376  endif
377  if(trim(param%fixed_sfc1_type)=='sigma_lvl'.and.trim(param%pname)=='V_VEL') then
378  do j=1, nlevel
379  if(abs(param%level(j)-9950)<small)then
380  lvls(1,ifld)=1
381  lvlsxml(1,ifld)=j
382  iget(326)=ifld
383  endif
384  enddo
385  endif
386 !
387 !for CAPE
388  if(trim(param%pname)=='CAPE') then
389  if(trim(param%fixed_sfc1_type)=='surface') then
390  iget(032)=ifld
391  lvls(1,ifld)=ifld
392  lvlsxml(1,ifld)=j
393  ident(ifld) = 032
394  iavblfld(ifld)=ithfld
395  elseif (trim(param%fixed_sfc1_type)=='spec_pres_above_grnd'.and. &
396  trim(param%fixed_sfc2_type)=='spec_pres_above_grnd' ) then
397  do j=1, nlevel
398  if(abs(param%level(j)-18000.)<small1.and.abs(param%level2(j)-0.)<small1)then
399  iget(566)=ifld
400  lvls(1,ifld)=1
401  lvlsxml(1,ifld)=j
402  ident(ifld) = 566
403  iavblfld(ifld)=ithfld
404 !jw elseif(abs(param%level(j)-9000.)<small1.and.abs(param%level2(j)-0.)<small1)then
405 !jw LVLS(2,IFLD)=1
406 !jw LVLSXML(2,ifld)=j
407 !jw elseif(abs(param%level(j)-25500.)<small1.and.abs(param%level2(j)-0.)<small1)then
408 !jw LVLS(3,IFLD)=1
409 !jw LVLSXML(3,ifld)=j
410  endif
411  enddo
412  endif
413  return
414  endif
415 !
416 !
417 !for CIN
418  if(trim(param%pname)=='CIN') then
419  if(trim(param%fixed_sfc1_type)=='surface') then
420  iget(107)=ifld
421  lvls(1,ifld)=ifld
422  ident(ifld) = 107
423  iavblfld(ifld)=ithfld
424  elseif (trim(param%fixed_sfc1_type)=='spec_pres_above_grnd'.and. &
425  trim(param%fixed_sfc2_type)=='spec_pres_above_grnd' ) then
426  do j=1, nlevel
427  if(abs(param%level(j)-18000.)<small1.and.abs(param%level2(j)-0.)<small1)then
428  iget(567)=ifld
429  lvls(1,ifld)=1
430  lvlsxml(1,ifld)=j
431  ident(ifld) = 567
432  iavblfld(ifld)=ithfld
433  endif
434  enddo
435  endif
436  return
437  endif
438 !
439 !for pv sfc
440  if(trim(param%fixed_sfc1_type)=='pot_vort_sfc') then
441  do j=1, nlevel
442  scalef=param%scale_fact_fixed_sfc1(j)-6
443  if(param%scale_fact_fixed_sfc1(j)<6) scalef=0
444  iloop3: do i=1, kpv
445  if(pv(i)/=0.and.abs(param%level(j)*10.**(-1*scalef)-pv(i))<=1.e-5) then
446  lvls(i,ifld)=1
447  lvlsxml(i,ifld)=j
448  exit iloop3
449  endif
450  enddo iloop3
451  enddo
452 ! print *,'for level type pv,nlevel=',nlevel,'level=', &
453 ! param%level(1:nlevel)*10.**(-1*scalef), &
454 ! 'pv=',pv(1:kpv),lvls1(1:kpv),'ifld=',ifld,'var=',trim(param%pname), &
455 ! 'lvl type=',trim(param%fixed_sfc1_type)
456  endif
457 !
458  if(trim(param%fixed_sfc1_type)=='spec_alt_above_mean_sea_lvl') then
459  do j=1, nlevel
460  iloop4: do i=1, nfd
461  if(nint(param%level(j))==nint(htfd(i)) )then
462  if(htfd(i)>300.) then
463  lvls(i,ifld)=1
464  else
465  lvls(i,ifld)=2
466  endif
467  lvlsxml(i,ifld)=j
468  exit iloop4
469  endif
470  enddo iloop4
471  enddo
472  endif
473 !
474  if(trim(param%fixed_sfc1_type)=='spec_pres_above_grnd') then
475  do j=1, nlevel
476  iloop5: do i=1, nbnd
477  if(nint(param%level(j)/100.)==nint(petabnd(i)+15.))then
478  lvls(i,ifld)=1
479  lvlsxml(i,ifld)=j
480  exit iloop5
481  endif
482  enddo iloop5
483  if(nint(param%level(j)/100.)==255) then
484  lvls(nbnd+1,ifld)=1
485  lvlsxml(nbnd+1,ifld)=j
486  endif
487  enddo
488  endif
489 !
490  if(trim(param%fixed_sfc1_type)=='spec_hgt_lvl_above_grnd') then
491  do j=1, nlevel
492  lvls(j,ifld)=1
493  lvlsxml(j,ifld)=j
494  enddo
495  endif
496 !
497  end
Definition: SOIL_mod.f:1