OOPS
qg_tools_mod.F90
Go to the documentation of this file.
1 ! (C) Copyright 2009-2016 ECMWF.
2 !
3 ! This software is licensed under the terms of the Apache Licence Version 2.0
4 ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5 ! In applying this licence, ECMWF does not waive the privileges and immunities
6 ! granted to it by virtue of its status as an intergovernmental organisation nor
7 ! does it submit to any jurisdiction.
8 
10 
11 use fckit_configuration_module, only: fckit_configuration
12 use datetime_mod
13 use duration_mod
14 use iso_c_binding
15 use kinds
16 use netcdf
18 
19 implicit none
20 
21 private
23 ! ------------------------------------------------------------------------------
24 real(kind_real),parameter :: ubot = -2.0_kind_real !< Zonal wind at the surface (m/s)
25 real(kind_real),parameter :: utop = 58.0_kind_real !< Zonal wind at the top (m/s)
26 ! ------------------------------------------------------------------------------
27 contains
28 ! ------------------------------------------------------------------------------
29 !> Generate filename
30 function genfilename(f_conf,length,vdate)
31 use string_utils
32 
33 implicit none
34 
35 ! Passed variables
36 type(fckit_configuration),intent(in) :: f_conf !< FCKIT configuration
37 integer,intent(in) :: length !< Length
38 type(datetime),intent(in) :: vdate !< Date and time
39 
40 ! Result
41 character(len=2*length) :: genfilename
42 
43 ! Local variables
44 integer :: lenfn
45 character(len=length) :: fdbdir,expver,typ,validitydate,referencedate,sstep,mmb
46 character(len=2*length) :: prefix
47 character(len=:),allocatable :: str
48 
49 type(datetime) :: rdate
50 type(duration) :: step
51 
52 ! Get configuration parameters
53 call f_conf%get_or_die("datadir",str)
54 call swap_name_member(f_conf, str)
55 fdbdir = str
56 call f_conf%get_or_die("exp",str)
57 call swap_name_member(f_conf, str)
58 expver = str
59 call f_conf%get_or_die("type",str)
60 typ = str
61 
62 ! Ensemble case
63 if (typ=='ens') then
64  call f_conf%get_or_die("member",str)
65  mmb = str
66  lenfn = len_trim(fdbdir) + 1 + len_trim(expver) + 1 + len_trim(typ) + 1 + len_trim(mmb)
67  prefix = trim(fdbdir) // '/' // trim(expver) // '.' // trim(typ) // '.' // trim(mmb)
68 else
69  lenfn = len_trim(fdbdir) + 1 + len_trim(expver) + 1 + len_trim(typ)
70  prefix = trim(fdbdir) // '/' // trim(expver) // '.' // trim(typ)
71 endif
72 
73 ! Forecast / ensemble cases
74 if ((typ=='fc').or.(typ=='ens')) then
75  call f_conf%get_or_die("date",str)
76  referencedate = str
77  call datetime_to_string(vdate,validitydate)
78  call datetime_create(trim(referencedate),rdate)
79  call datetime_diff(vdate,rdate,step)
80  call duration_to_string(step,sstep)
81  lenfn = lenfn+1+len_trim(referencedate)+1+len_trim(sstep)
82  genfilename = trim(prefix)//'.'//trim(referencedate)//'.'// trim(sstep)//'.nc'
83 endif
84 
85 ! Analysis or increment case
86 if ((typ=='an').or.(typ=='in')) then
87  call datetime_to_string(vdate,validitydate)
88  lenfn = lenfn+1+len_trim(validitydate)
89  genfilename = trim(prefix)//'.'//trim(validitydate)//'.nc'
90 endif
91 
92 ! Check filename length
93 if (lenfn>length) call abor1_ftn('genfilename: filename too long')
94 
95 end function genfilename
96 ! ------------------------------------------------------------------------------
97 !> Check NetCDF status
98 subroutine ncerr(info)
99 
100 implicit none
101 
102 ! Passed variables
103 integer,intent(in) :: info !< Info index
104 
105 ! Check status
106 if (info/=nf90_noerr) call abor1_ftn(trim(nf90_strerror(info)))
107 
108 end subroutine ncerr
109 ! ------------------------------------------------------------------------------
110 !> Generate values for baroclinic instability
111 subroutine baroclinic_instability(x,y,z,var,res)
112 
113 implicit none
114 
115 ! Passed variables
116 real(kind_real),intent(in) :: x !< X value
117 real(kind_real),intent(in) :: y !< Y value
118 real(kind_real),intent(in) :: z !< Z value
119 character(len=1),intent(in) :: var !< Variable
120 real(kind_real),intent(out) :: res !< Results
121 
122 ! Local variable
123 real(kind_real) :: u
124 
125 ! Define zonal wind
126 u = ubot+(utop-ubot)*z/domain_depth
127 
128 select case (var)
129 case ('x')
130  ! Streamfunction
131  res = -u*y
132 case ('q')
133  call abor1_ftn('baroclinic_instability: cannot define q')
134 case ('u')
135  ! Zonal wind
136  res = u
137 case ('v')
138  ! Meridional wind
139  res = 0.0
140 case default
141  call abor1_ftn('baroclinic_instability: wrong variable')
142 end select
143 
144 end subroutine baroclinic_instability
145 ! ------------------------------------------------------------------------------
146 !> Generate values for large vortices
147 subroutine large_vortices(x,y,z,var,res)
148 
149 implicit none
150 
151 ! Passed variables
152 real(kind_real),intent(in) :: x !< X value
153 real(kind_real),intent(in) :: y !< Y value
154 real(kind_real),intent(in) :: z !< Z value
155 character(len=1),intent(in) :: var !< Variable
156 real(kind_real),intent(out) :: res !< Results
157 
158 ! Local variable
159 real(kind_real) :: ff
160 
161 ! Define wind speed
162 ff = ubot+(utop-ubot)*z/domain_depth
163 
164 select case (var)
165 case ('x')
166  ! Streamfunction
167  res = ff*domain_meridional*cos(2.0*pi*x/domain_zonal)*sin(pi*y/domain_meridional)
168 case ('q')
169  call abor1_ftn('large_vortices: cannot define q')
170 case ('u')
171  ! Zonal wind
172  res = -ff*pi*cos(2.0*pi*x/domain_zonal)*cos(pi*y/domain_meridional)
173 case ('v')
174  ! Meridional wind
175  res = -2.0*ff*pi*domain_meridional/domain_zonal*sin(2.0*pi*x/domain_zonal)*sin(pi*y/domain_meridional)
176 case default
177  call abor1_ftn('large_vortices: wrong variable')
178 end select
179 
180 end subroutine large_vortices
181 ! ------------------------------------------------------------------------------
182 end module qg_tools_mod
qg_constants_mod::domain_zonal
real(kind_real), parameter, public domain_zonal
Model domain in zonal direction (m)
Definition: qg_constants_mod.F90:32
qg_tools_mod::large_vortices
subroutine, public large_vortices(x, y, z, var, res)
Generate values for large vortices.
Definition: qg_tools_mod.F90:148
qg_tools_mod::genfilename
character(len=2 *length) function, public genfilename(f_conf, length, vdate)
Generate filename.
Definition: qg_tools_mod.F90:31
qg_tools_mod::ubot
real(kind_real), parameter ubot
Zonal wind at the surface (m/s)
Definition: qg_tools_mod.F90:24
qg_constants_mod
Definition: qg_constants_mod.F90:9
qg_tools_mod::baroclinic_instability
subroutine, public baroclinic_instability(x, y, z, var, res)
Generate values for baroclinic instability.
Definition: qg_tools_mod.F90:112
qg_tools_mod::utop
real(kind_real), parameter utop
Zonal wind at the top (m/s)
Definition: qg_tools_mod.F90:25
qg_constants_mod::domain_depth
real(kind_real), parameter, public domain_depth
Model depth (m)
Definition: qg_constants_mod.F90:34
qg_tools_mod
Definition: qg_tools_mod.F90:9
qg_tools_mod::ncerr
subroutine, public ncerr(info)
Check NetCDF status.
Definition: qg_tools_mod.F90:99
qg_constants_mod::domain_meridional
real(kind_real), parameter, public domain_meridional
Model domain in meridional direction (m)
Definition: qg_constants_mod.F90:33
qg_constants_mod::pi
real(kind_real), parameter, public pi
Pi.
Definition: qg_constants_mod.F90:22