fvcom_tools  1.5.0
 All Data Structures Files Functions Variables Pages
process_FVCOM.f90
Go to the documentation of this file.
1 
6 
28 
29  use mpi
30  use kinds, only: r_kind, i_kind, r_single
31  use module_ncio, only: ncio
32  use module_nwp, only: fcst_nwp
33 
34  implicit none
35 
36 ! MPI variables
37  integer :: npe, mype, mypelocal,ierror
38 !
39 
40 ! New object-oriented declarations
41 
42  type(ncio) :: geo
43  type(fcst_nwp) :: fcst
44 
45 ! Grid variables
46 
47  character*180 :: geofile
48  character*2 :: workpath
49  character*1 :: char1
50 
51  integer :: map_proj, nlon, nlat
52  integer :: fv3lon, fv3lat, fv3times
53  integer :: lbclon, lbclat, lbctimes
54  integer :: i, j, t1, t2
55  integer :: num_args, ix
56 
57  real :: rad2deg = 180.0/3.1415926
58  real :: userdx, userdy, cen_lat, cen_lon
59  real :: usertruelat1, usertruelat2, moad_cen_lat, stand_lon
60  real :: truelat1, truelat2, stdlon, lat1, lon1, r_earth
61  real :: knowni, knownj, dx
62  real :: one, pi, deg2rad
63 
64  character(len=180) :: fv3file
65  character(len=180) :: fvcomfile
66  character(len=180), dimension(:), allocatable :: args
67 
68  real(r_kind), allocatable :: fv3ice(:,:), fv3sst(:,:)
69  real(r_kind), allocatable :: fv3sfct(:,:), fv3mask(:,:)
70  real(r_kind), allocatable :: fv3icet(:,:)
71  real(r_kind), allocatable :: lbcice(:,:), lbcsst(:,:)
72  real(r_kind), allocatable :: lbcsfct(:,:), lbcmask(:,:)
73  real(r_kind), allocatable :: lbcicet(:,:)
74 
75 ! Declare namelists
76 ! SETUP (general control namelist) :
77 
78  integer :: update_type
79 
80 ! namelist/setup/update_type, t2
81 
82 ! MPI setup
83  call mpi_init(ierror)
84  call mpi_comm_size(mpi_comm_world,npe,ierror)
85  call mpi_comm_rank(mpi_comm_world,mype,ierror)
86 !
87 ! NCEP LSF has to use all cores allocated to run this application
88 ! but this if check can make sure only one core run through the real code.
89 !
90 if(mype==0) then
91 
92 ! Get file names from command line arguements
93  num_args = command_argument_count()
94  allocate(args(num_args))
95 
96  do ix = 1, num_args
97  call get_command_argument(ix,args(ix))
98  end do
99 
100  fv3file=trim(args(1))
101  write(*,*) trim(fv3file)
102  fvcomfile=trim(args(2))
103  write(*,*) trim(fvcomfile)
104 
105  t2 = 1
106 ! Obtain grid parameters
107 
108  workpath='./'
109  write(geofile,'(a,a)') trim(workpath), trim(fv3file)
110  write(*,*) 'sfc data file', trim(geofile)
111  call geo%open(trim(geofile),'r',200)
112  call geo%get_dim("xaxis_1",nlon)
113  call geo%get_dim("yaxis_1",nlat)
114  write(*,*) 'NLON,NLAT:', nlon, nlat
115  call geo%close
116 
117  write(*,*) 'Finished reading sfc_data grid information.'
118  write(*,*) ' '
119 
120 ! Allocate variables for I/O
121 
122  allocate(fv3ice(nlon,nlat))
123  allocate(fv3sfct(nlon,nlat))
124  allocate(fv3sst(nlon,nlat))
125  allocate(fv3mask(nlon,nlat))
126  allocate(fv3icet(nlon,nlat))
127 
128  allocate(lbcice(nlon,nlat))
129  allocate(lbcsfct(nlon,nlat))
130  allocate(lbcsst(nlon,nlat))
131  allocate(lbcmask(nlon,nlat))
132  allocate(lbcicet(nlon,nlat))
133 
134 ! Read fv3 sfc_data.nc before update
135 
136 ! fv3file='sfc_data.nc'
137  t1=1
138 
139  call fcst%initial('FV3LAM')
140  call fcst%list_initial
141  call fcst%read_n(trim(fv3file),'FV3LAM',fv3lon,fv3lat,fv3times,t1,fv3mask,fv3sst,fv3ice,fv3sfct,fv3icet)
142  call fcst%finish
143 
144 
145  write(*,*) 'fv3times: ', fv3times
146  write(*,*) 'time to use: ', t1
147 
148 ! Read FVCOM input datasets
149 
150 ! fvcomfile='fvcom.nc'
151 ! Space infront of ' FVCOM' below is important!!
152  call fcst%initial(' FVCOM')
153  call fcst%list_initial
154  call fcst%read_n(trim(fvcomfile),' FVCOM',lbclon,lbclat,lbctimes,t2,lbcmask,lbcsst,lbcice,lbcsfct,lbcicet)
155  call fcst%finish
156 
157 ! Check that the dimensions match
158 
159  if (lbclon .ne. nlon .or. lbclat .ne. nlat) then
160  write(*,*) 'ERROR: FVCOM/FV3 dimensions do not match:'
161  write(*,*) 'lbclon: ', lbclon
162  write(*,*) 'nlon: ', nlon
163  write(*,*) 'lbclat: ', lbclat
164  write(*,*) 'nlat: ', nlat
165  stop 135
166  endif
167 
168  write(*,*) 'lbctimes: ', lbctimes
169  write(*,*) 'time to use: ', t2
170 
171 ! Update with FVCOM fields and process
172 ! ice cover data. Ice fraction is set
173 ! to a minimum of 15% due to FV3-LAM
174 ! raising any value below 15% to 15%.
175 
176  do j=1,nlat
177  do i=1,nlon
178  if (lbcmask(i,j) > 0. .and. lbcsst(i,j) .ge. -90.0) then
179  !If ice fraction below 15%, set to 0
180  if (lbcice(i,j) < 0.15) then
181  lbcice(i,j) = 0.0
182  endif
183  fv3ice(i,j) = lbcice(i,j)
184  !If ice in FVCOM, but not in FV3-LAM, change to ice
185  if (lbcice(i,j) > 0. .and. fv3mask(i,j) == 0.) then
186  fv3mask(i,j) = 2.
187  endif
188  !If ice in FV3-LAM and not FVCOM, remove it from FV3-LAM
189  if (fv3mask(i,j) == 2. .and. lbcice(i,j) == 0.) then
190  fv3mask(i,j) = 0.
191  endif
192  fv3sst(i,j) = lbcsst(i,j) + 273.15
193  fv3sfct(i,j) = lbcsst(i,j) + 273.15
194  fv3icet(i,j) = lbcsst(i,j) + 273.15
195  !If ice exists in FVCOM, change ice surface temp
196  if (lbcice(i,j) > 0.) then
197  fv3icet(i,j) = lbcicet(i,j) + 273.15
198  end if
199  endif
200  enddo
201  enddo
202 
203 ! Write out sfc file again
204 
205  call geo%open(trim(fv3file),'w',300)
206  call geo%replace_var("tsea",nlon,nlat,fv3sst)
207  call geo%replace_var("fice",nlon,nlat,fv3ice)
208  call geo%replace_var("slmsk",nlon,nlat,fv3mask)
209  call geo%replace_var("tisfc",nlon,nlat,fv3icet)
210 ! Add_New_Var takes names of (Variable,Dim1,Dim2,Dim3,Long_Name,Units)
211  call geo%add_new_var('glmsk','xaxis_1','yaxis_1','Time','glmsk','none')
212  call geo%replace_var('glmsk',nlon,nlat,lbcmask)
213  call geo%close
214 
215  write(6,*) "=== LOWBC UPDATE SUCCESS ==="
216 
217 endif ! mype==0
218 
219 call mpi_finalize(ierror)
220 
221 
222 end program process_fvcom
Module to hold specification kinds for variable declaration.
Definition: kinds.f90:11
Functions to read and write netcdf files.
Definition: module_ncio.f90:7
This module defines FV3LAM and FVCOM forecast data structure and the method to read and write observa...
Definition: module_nwp.f90:15
program process_fvcom
Put lake surface temperature and aerial ice concentration from GLERL-provided FVCOM forecast files (w...