fvcom_tools  1.3.0
 All Data Structures Files Functions Variables Pages
module_nwp.f90
Go to the documentation of this file.
1 
4 
15 module module_nwp
16 
17  use kinds, only: r_kind, r_single, i_short, rmissing
18  use module_nwp_base, only: nwpbase
19 ! use module_map_utils, only: map_util
20  use module_ncio, only: ncio
21 
22  implicit none
23 
24  public :: fcst_nwp
25  public :: nwp_type
26 
27  private
28  type :: nwp_type
29  character(len=6) :: datatype
30  integer :: numvar
31  integer :: xlat
32  integer :: xlon
33  integer :: xtime
34  integer :: i_mask
35  integer :: i_sst
36  integer :: i_ice
37  integer :: i_sfcT
38  integer :: i_iceT
39  character(len=20), allocatable :: varnames(:)
40  character(len=20), allocatable :: latname
41  character(len=20), allocatable :: lonname
42  character(len=20), allocatable :: dimnameEW
43  character(len=20), allocatable :: dimnameNS
44  character(len=20), allocatable :: dimnameTIME
45 
46  real(r_kind), allocatable :: nwp_mask(:,:,:)
47  real(r_kind), allocatable :: nwp_sst(:,:,:)
48  real(r_kind), allocatable :: nwp_ice(:,:,:)
49  real(r_kind), allocatable :: nwp_sfcT(:,:,:)
50  real(r_kind), allocatable :: nwp_iceT(:,:,:)
51  end type nwp_type
52 
53  type, extends(nwp_type) :: fcst_nwp
54  ! The pointers are carryover from when I inherited the code from
55  ! GSL's work with HRRR for a similar use. I am not sure with
56  ! object based coding in Fortran if it needs to have parts
57  ! initialized to gain access to the procedures within it. - D. Wright.
58  type(nwpbase), pointer :: head => NULL()
59  type(nwpbase), pointer :: tail => NULL()
60  contains
61  procedure :: initial => initial_nwp
62  procedure :: list_initial => list_initial_nwp
63  procedure :: read_n => read_nwp
64  procedure :: finish => finish_nwp
65  end type fcst_nwp
66 
67  type(ncio) :: ncdata
68 ! type(map_util) :: map
69 
70  contains
71 
79  subroutine initial_nwp(this,itype)
80  class(fcst_nwp) :: this
81 
82  character(len=6), intent(in) :: itype
83 
84 ! FVCOM grid
85  if (itype==' FVCOM') then
86  this%datatype = itype
87  this%numvar = 4
88 
89  this%i_mask = 1
90  this%i_sst = 2
91  this%i_ice = 3
92  this%i_iceT = 4
93  this%i_sfcT = 0
94 
95  allocate(this%varnames(this%numvar))
96  this%varnames(1) = 'glmask'
97  this%varnames(2) = 'tsfc'
98  this%varnames(3) = 'aice'
99  this%varnames(4) = 'tisfc'
100 
101  allocate(this%latname)
102  allocate(this%lonname)
103  this%latname = 'lat'
104  this%lonname = 'lon'
105 
106  allocate(this%dimnameEW)
107  allocate(this%dimnameNS)
108  allocate(this%dimnameTIME)
109  this%dimnameEW = 'lon'
110  this%dimnameNS = 'lat'
111  this%dimnameTIME = 'Time'
112 
113 ! FV3LAM grid
114 
115  else if (trim(itype)=='FV3LAM') then
116  this%datatype = itype
117  this%numvar = 4
118 
119  this%i_mask = 1
120  this%i_sst = 2
121  this%i_ice = 3
122  this%i_iceT = 4
123  this%i_sfcT = 0
124 
125  allocate(this%varnames(this%numvar))
126  this%varnames(1) = 'slmsk'
127  this%varnames(2) = 'tsea'
128  this%varnames(3) = 'fice'
129  this%varnames(4) = 'tisfc'
130 
131  allocate(this%latname)
132  allocate(this%lonname)
133  this%latname = 'yaxis_1'
134  this%lonname = 'xaxis_1'
135 
136  allocate(this%dimnameEW)
137  allocate(this%dimnameNS)
138  allocate(this%dimnameTIME)
139  this%dimnameEW = 'xaxis_1'
140  this%dimnameNS = 'yaxis_1'
141  this%dimnameTIME = 'Time'
142 
143 ! If the data type does not match one of the known types, exit.
144 
145  else
146  write(*,*) 'Unknown data type:', itype
147  stop 1234
148  end if
149 
150  this%head => null()
151  this%tail => null()
152 
153  write(*,*) 'Finished initial_nwp'
154  write(*,*) ' '
155 
156  end subroutine initial_nwp
157 
163  subroutine list_initial_nwp(this)
164 
165  class(fcst_nwp) :: this
166 
167  integer :: k
168 
169  write(*,*) 'List initial setup for ', this%datatype
170  write(*,*) 'number of variables ', this%numvar
171  write(*,*) 'variable index: mask, sst, ice, sfcT'
172  write(*,'(15x,10I3)') this%i_mask, this%i_sst, this%i_ice, &
173  & this%i_sfcT
174  write(*,*) 'variable name:'
175  do k=1,this%numvar
176  write(*,*) k,trim(this%varnames(k))
177  enddo
178 
179  write(*,*) 'Finished list_initial_nwp'
180  write(*,*) ' '
181 
182  end subroutine list_initial_nwp
183 
201  subroutine read_nwp(this,filename,itype,numlon,numlat,numtimes,time_to_get,mask,sst,ice,sfcT,iceT)
202 
203  class(fcst_nwp) :: this
204 
205  character(len=5), intent(in) :: itype
206  character(len=*), intent(in) :: filename
207 
208  integer, intent(in) :: time_to_get
209  integer, intent(inout) :: numlon, numlat, numtimes
210 ! real(r_single), intent(inout) :: mask(:,:), sst(:,:), ice(:,:), sfcT(:,:)
211  real(r_kind), intent(inout) :: mask(:,:),sst(:,:),ice(:,:),sfct(:,:) &
212  ,icet(:,:)
213 
214 ! Open the file using module_ncio.f90 code, and find the number of
215 ! lat/lon points
216 
217  call ncdata%open(trim(filename),'r',200)
218  call ncdata%get_dim(this%dimnameEW,this%xlon)
219  call ncdata%get_dim(this%dimnameNS,this%xlat)
220  call ncdata%get_dim(this%dimnameTIME,this%xtime)
221 
222  write(*,*) 'number of longitudes for file ', filename, this%xlon
223  numlon = this%xlon
224  write(*,*) 'number of latitudes for file ', filename, this%xlat
225  numlat = this%xlat
226  write(*,*) 'number of times for file ', filename, this%xtime
227  numtimes = this%xtime
228 
229 ! Allocate all the arrays to receive data
230 
231  allocate(this%nwp_mask(this%xlon,this%xlat,this%xtime))
232  allocate(this%nwp_sst(this%xlon,this%xlat,this%xtime))
233  allocate(this%nwp_ice(this%xlon,this%xlat,this%xtime))
234  allocate(this%nwp_sfcT(this%xlon,this%xlat,this%xtime))
235  allocate(this%nwp_iceT(this%xlon,this%xlat,this%xtime))
236 
237 ! Get variables from the data file, but only if the variable is
238 ! defined for that data type.
239 
240  if (this%i_mask .gt. 0) then
241  call ncdata%get_var(this%varnames(this%i_mask),this%xlon, &
242  this%xlat,this%xtime,this%nwp_mask)
243  mask = this%nwp_mask(:,:,1)
244  end if
245  if (this%i_sst .gt. 0) then
246  call ncdata%get_var(this%varnames(this%i_sst),this%xlon, &
247  this%xlat,this%xtime,this%nwp_sst)
248  sst = this%nwp_sst(:,:,time_to_get)
249  end if
250  if (this%i_ice .gt. 0) then
251  call ncdata%get_var(this%varnames(this%i_ice),this%xlon, &
252  this%xlat,this%xtime,this%nwp_ice)
253  ice = this%nwp_ice(:,:,time_to_get)
254  end if
255  if (this%i_sfcT .gt. 0) then
256  call ncdata%get_var(this%varnames(this%i_sfcT),this%xlon, &
257  this%xlat,this%xtime,this%nwp_sfcT)
258  sfct = this%nwp_sfcT(:,:,time_to_get)
259  end if
260  if (this%i_iceT .gt. 0) then
261  call ncdata%get_var(this%varnames(this%i_iceT),this%xlon, &
262  this%xlat,this%xtime,this%nwp_iceT)
263  icet = this%nwp_iceT(:,:,time_to_get)
264  end if
265 
266 ! Close the netCDF file.
267 
268  call ncdata%close
269 
270  write(*,*) 'Finished read_nwp'
271  write(*,*) ' '
272 
273  end subroutine read_nwp
274 
279  subroutine finish_nwp(this)
280 
281  class(fcst_nwp) :: this
282 
283  type(nwpbase), pointer :: thisobs,thisobsnext
284 
285  deallocate(this%varnames)
286  deallocate(this%latname)
287  deallocate(this%lonname)
288  deallocate(this%dimnameEW)
289  deallocate(this%dimnameNS)
290  deallocate(this%dimnameTIME)
291  deallocate(this%nwp_mask)
292  deallocate(this%nwp_sst)
293  deallocate(this%nwp_ice)
294  deallocate(this%nwp_sfcT)
295  deallocate(this%nwp_iceT)
296 
297  thisobs => this%head
298  if(.NOT.associated(thisobs)) then
299  write(*,*) 'No memory to release'
300  return
301  endif
302  do while(associated(thisobs))
303 ! write(*,*) 'destroy ==',thisobs%name
304 
305  thisobsnext => thisobs%next
306  call thisobs%destroy()
307  thisobs => thisobsnext
308  enddo
309 
310  write(*,*) 'Finished finish_nwp'
311  write(*,*) ' '
312 
313  end subroutine finish_nwp
314 
315 end module module_nwp
Module to hold specification kinds for variable declaration.
Definition: kinds.f90:11
This module defines nwp observation data structure and the method to read and write observations from...
Functions to read and write netcdf files.
Definition: module_ncio.f90:7
procedure read_n=> read_nwp
Initialize arrays, get data.
Definition: module_nwp.f90:63
procedure finish=> finish_nwp
Finish and deallocate.
Definition: module_nwp.f90:64
This module defines FV3LAM and FVCOM forecast data structure and the method to read and write observa...
Definition: module_nwp.f90:15
subroutine list_initial_nwp(this)
This subroutine lists the setup for NWP data that was done by the initial_nwp subroutine.
Definition: module_nwp.f90:163
subroutine read_nwp(this, filename, itype, numlon, numlat, numtimes, time_to_get, mask, sst, ice, sfcT, iceT)
This subroutine initializes arrays to receive the NWP data, and opens the file and gets the data...
Definition: module_nwp.f90:201
procedure initial=> initial_nwp
Defines vars and names.
Definition: module_nwp.f90:61
subroutine finish_nwp(this)
Finish and deallocate.
Definition: module_nwp.f90:279
procedure list_initial=> list_initial_nwp
List the setup.
Definition: module_nwp.f90:62
subroutine initial_nwp(this, itype)
This subroutine defines the number of variables and their names for each NWP data type...
Definition: module_nwp.f90:79