source: flexpart.git/src/getfields.f90 @ c0884a8

univie
Last change on this file since c0884a8 was c0884a8, checked in by pesei <petra seibert at univie ac at>, 6 years ago

replace CTBTO code for checking type of GRIB

  • Property mode set to 100644
File size: 9.7 KB
Line 
1!**********************************************************************
2! Copyright 1998,1999,2000,2001,2002,2005,2007,2008,2009,2010         *
3! Andreas Stohl, Petra Seibert, A. Frank, Gerhard Wotawa,             *
4! Caroline Forster, Sabine Eckhardt, John Burkhart, Harald Sodemann   *
5!                                                                     *
6! This file is part of FLEXPART.                                      *
7!                                                                     *
8! FLEXPART is free software: you can redistribute it and/or modify    *
9! it under the terms of the GNU General Public License as published by*
10! the Free Software Foundation, either version 3 of the License, or   *
11! (at your option) any later version.                                 *
12!                                                                     *
13! FLEXPART is distributed in the hope that it will be useful,         *
14! but WITHOUT ANY WARRANTY; without even the implied warranty of      *
15! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
16! GNU General Public License for more details.                        *
17!                                                                     *
18! You should have received a copy of the GNU General Public License   *
19! along with FLEXPART.  If not, see <http://www.gnu.org/licenses/>.   *
20!**********************************************************************
21
22subroutine getfields(itime,nstop,id_centre)
23!                       i     o
24!*****************************************************************************
25!                                                                            *
26!  This subroutine manages the 3 data fields to be kept in memory.           *
27!  During the first time step of petterssen it has to be fulfilled that the  *
28!  first data field must have |wftime|<itime, i.e. the absolute value of     *
29!  wftime must be smaller than the absolute value of the current time in [s].*
30!  The other 2 fields are the next in time after the first one.              *
31!  Pointers (memind) are used, because otherwise one would have to resort the*
32!  wind fields, which costs a lot of computing time. Here only the pointers  *
33!  are resorted.                                                             *
34!                                                                            *
35!     Author: A. Stohl                                                       *
36!                                                                            *
37!     29 April 1994                                                          *
38!                                                                            *
39!*****************************************************************************
40!  Changes, Bernd C. Krueger, Feb. 2001:                                     *
41!   Variables tth,qvh,tthn,qvhn (on eta coordinates) in common block.        *
42!   Function of nstop extended.                                              *
43!                                                                            *
44!   Unified ECMWF and GFS builds                                             *
45!   Marian Harustak, 12.5.2017                                               *
46!     - Added passing of id_centre as it was needed by called routines       *
47!                                                                            *
48!  Petra Seibert, 2018-06-26: simplified version met data format detection   *
49!                                                                            *
50!*****************************************************************************
51!                                                                            *
52! Variables:                                                                 *
53! lwindinterval [s]    time difference between the two wind fields read in   *
54! indj                 indicates the number of the wind field to be read in  *
55! indmin               remembers the number of wind fields already treated   *
56! memind(2)            pointer, on which place the wind fields are stored    *
57! memtime(2) [s]       times of the wind fields, which are kept in memory    *
58! itime [s]            current time since start date of trajectory calcu-    *
59!                      lation                                                *
60! nstop                > 0, if trajectory has to be terminated               *
61! nx,ny,nuvz,nwz       field dimensions in x,y and z direction               *
62! uu(0:nxmax,0:nymax,nuvzmax,2)   wind components in x-direction [m/s]       *
63! vv(0:nxmax,0:nymax,nuvzmax,2)   wind components in y-direction [m/s]       *
64! ww(0:nxmax,0:nymax,nwzmax,2)    wind components in z-direction [deltaeta/s]*
65! tt(0:nxmax,0:nymax,nuvzmax,2)   temperature [K]                            *
66! ps(0:nxmax,0:nymax,2)           surface pressure [Pa]                      *
67! id_centre            format of metdata (ecmwf/gfs)                         *
68!                                                                            *
69! Constants:                                                                 *
70! idiffmax             maximum allowable time difference between 2 wind      *
71!                      fields                                                *
72!                                                                            *
73!*****************************************************************************
74
75  use par_mod
76  use com_mod
77  use check_gribfile_mod
78
79  implicit none
80
81  integer :: indj,itime,nstop,memaux
82  integer :: id_centre
83
84  real :: uuh(0:nxmax-1,0:nymax-1,nuvzmax)
85  real :: vvh(0:nxmax-1,0:nymax-1,nuvzmax)
86  real :: pvh(0:nxmax-1,0:nymax-1,nuvzmax)
87  real :: wwh(0:nxmax-1,0:nymax-1,nwzmax)
88  real :: uuhn(0:nxmaxn-1,0:nymaxn-1,nuvzmax,maxnests)
89  real :: vvhn(0:nxmaxn-1,0:nymaxn-1,nuvzmax,maxnests)
90  real :: pvhn(0:nxmaxn-1,0:nymaxn-1,nuvzmax,maxnests)
91  real :: wwhn(0:nxmaxn-1,0:nymaxn-1,nwzmax,maxnests)
92
93  integer :: indmin = 1
94
95
96! Check, if wind fields are available for the current time step
97!**************************************************************
98
99  nstop=0
100
101  if ((ldirect*wftime(1).gt.ldirect*itime).or. &
102       (ldirect*wftime(numbwf).lt.ldirect*itime)) then
103    write(*,*) 'FLEXPART WARNING: NO WIND FIELDS ARE AVAILABLE.'
104    write(*,*) 'A TRAJECTORY HAS TO BE TERMINATED.'
105    nstop=4
106    return
107  endif
108
109
110  if ((ldirect*memtime(1).le.ldirect*itime).and. &
111       (ldirect*memtime(2).gt.ldirect*itime)) then
112
113! The right wind fields are already in memory -> don't do anything
114!*****************************************************************
115
116    continue
117
118  else if ((ldirect*memtime(2).le.ldirect*itime).and. &
119       (memtime(2).ne.999999999)) then
120
121
122! Current time is after 2nd wind field
123! -> Resort wind field pointers, so that current time is between 1st and 2nd
124!***************************************************************************
125
126    memaux=memind(1)
127    memind(1)=memind(2)
128    memind(2)=memaux
129    memtime(1)=memtime(2)
130
131
132! Read a new wind field and store it on place memind(2)
133!******************************************************
134
135    do indj=indmin,numbwf-1
136      if (ldirect*wftime(indj+1).gt.ldirect*itime) then
137        if (id_centre.eq.icg_id_ecmwf) then
138          call readwind_ecmwf(indj+1,memind(2),uuh,vvh,wwh)
139        else
140          call readwind_gfs(indj+1,memind(2),uuh,vvh,wwh)
141        end if
142        call readwind_nests(indj+1,memind(2),uuhn,vvhn,wwhn)
143        call calcpar(memind(2),uuh,vvh,pvh,id_centre)
144        call calcpar_nests(memind(2),uuhn,vvhn,pvhn,id_centre)
145        if (id_centre.eq.icg_id_ecmwf) then
146          call verttransform_ecmwf(memind(2),uuh,vvh,wwh,pvh)
147        else
148          call verttransform_gfs(memind(2),uuh,vvh,wwh,pvh)
149        end if
150        call verttransform_nests(memind(2),uuhn,vvhn,wwhn,pvhn)
151        memtime(2)=wftime(indj+1)
152        nstop = 1
153        goto 40
154      endif
155    end do
15640  indmin=indj
157
158   if (WETBKDEP) then
159        call writeprecip(itime,memind(1))
160   endif
161
162  else
163
164! No wind fields, which can be used, are currently in memory
165! -> read both wind fields
166!***********************************************************
167
168    do indj=indmin,numbwf-1
169      if ((ldirect*wftime(indj).le.ldirect*itime).and. &
170           (ldirect*wftime(indj+1).gt.ldirect*itime)) then
171        memind(1)=1
172        if (id_centre.eq.icg_id_ecmwf) then
173          call readwind_ecmwf(indj,memind(1),uuh,vvh,wwh)
174        else
175          call readwind_gfs(indj,memind(1),uuh,vvh,wwh)
176        end if
177        call readwind_nests(indj,memind(1),uuhn,vvhn,wwhn)
178        call calcpar(memind(1),uuh,vvh,pvh,id_centre)
179        call calcpar_nests(memind(1),uuhn,vvhn,pvhn,id_centre)
180        if (id_centre.eq.icg_id_ecmwf) then
181          call verttransform_ecmwf(memind(1),uuh,vvh,wwh,pvh)
182        else
183          call verttransform_gfs(memind(1),uuh,vvh,wwh,pvh)
184        end if
185        call verttransform_nests(memind(1),uuhn,vvhn,wwhn,pvhn)
186        memtime(1)=wftime(indj)
187        memind(2)=2
188        if (id_centre.eq.icg_id_ecmwf) then
189          call readwind_ecmwf(indj+1,memind(2),uuh,vvh,wwh)
190        else
191          call readwind_gfs(indj+1,memind(2),uuh,vvh,wwh)
192        end if
193        call readwind_nests(indj+1,memind(2),uuhn,vvhn,wwhn)
194        call calcpar(memind(2),uuh,vvh,pvh,id_centre)
195        call calcpar_nests(memind(2),uuhn,vvhn,pvhn,id_centre)
196        if (id_centre.eq.icg_id_ecmwf) then
197          call verttransform_ecmwf(memind(2),uuh,vvh,wwh,pvh)
198        else
199          call verttransform_gfs(memind(2),uuh,vvh,wwh,pvh)
200        end if
201        call verttransform_nests(memind(2),uuhn,vvhn,wwhn,pvhn)
202        memtime(2)=wftime(indj+1)
203        nstop = 1
204        goto 60
205      endif
206    end do
20760  indmin=indj
208
209   if (WETBKDEP) then
210        call writeprecip(itime,memind(1))
211   endif
212
213  endif
214
215  lwindinterv=abs(memtime(2)-memtime(1))
216
217  if (lwindinterv.gt.idiffmax) nstop=3
218
219end subroutine getfields
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG