WAVEWATCH III  beta 0.0.1
scrip_remap_vars.f
Go to the documentation of this file.
1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 !
3 ! this module contains necessary variables for remapping between
4 ! two grids. also routines for resizing and initializing these
5 ! variables.
6 !
7 !-----------------------------------------------------------------------
8 !
9 ! CVS:$Id: remap_vars.f,v 1.5 2000/04/19 21:56:26 pwjones Exp $
10 !
11 ! Copyright (c) 1997, 1998 the Regents of the University of
12 ! California.
13 !
14 ! This software and ancillary information (herein called software)
15 ! called SCRIP is made available under the terms described here.
16 ! The software has been approved for release with associated
17 ! LA-CC Number 98-45.
18 !
19 ! Unless otherwise indicated, this software has been authored
20 ! by an employee or employees of the University of California,
21 ! operator of the Los Alamos National Laboratory under Contract
22 ! No. W-7405-ENG-36 with the U.S. Department of Energy. The U.S.
23 ! Government has rights to use, reproduce, and distribute this
24 ! software. The public may copy and use this software without
25 ! charge, provided that this Notice and any statement of authorship
26 ! are reproduced on all copies. Neither the Government nor the
27 ! University makes any warranty, express or implied, or assumes
28 ! any liability or responsibility for the use of this software.
29 !
30 ! If software is modified to produce derivative works, such modified
31 ! software should be clearly marked, so as not to confuse it with
32 ! the version available from Los Alamos National Laboratory.
33 !
34 ! This code has been modified from the version available from
35 ! Los Alamos National Laboratory, for the purpose of running it
36 ! within WW3.
37 !
38 !***********************************************************************
39 
41 
42  use scrip_kindsmod ! defines common data types
43  use scrip_constants
44  use scrip_grids
45 
46  implicit none
47 
48 !-----------------------------------------------------------------------
49 !
50 ! module variables
51 !
52 !-----------------------------------------------------------------------
53 
54  integer (SCRIP_i4), parameter ::
55  & norm_opt_none = 1
56  &, norm_opt_dstarea = 2
57  &, norm_opt_frcarea = 3
58 
59  integer (SCRIP_i4), parameter ::
60  & map_type_conserv = 1
61  &, map_type_bilinear = 2
62  &, map_type_bicubic = 3
63  &, map_type_distwgt = 4
64  &, map_type_particle = 5
65 
66  integer (SCRIP_i4), save ::
67  & max_links_map1 ! current size of link arrays
68  &, num_links_map1 ! actual number of links for remapping
69  &, max_links_map2 ! current size of link arrays
70  &, num_links_map2 ! actual number of links for remapping
71  &, num_maps ! num of remappings for this grid pair
72  &, num_wts ! num of weights used in remapping
73  &, map_type ! identifier for remapping method
74  &, norm_opt ! option for normalization (conserv only)
75  &, resize_increment ! default amount to increase array size
76 
77  integer (SCRIP_i4), dimension(:), allocatable, save ::
78  & grid1_add_map1, ! grid1 address for each link in mapping 1
79  & grid2_add_map1, ! grid2 address for each link in mapping 1
80  & grid1_add_map2, ! grid1 address for each link in mapping 2
81  & grid2_add_map2 ! grid2 address for each link in mapping 2
82 
83  real (scrip_r8), dimension(:,:), allocatable, save ::
84  & wts_map1, ! map weights for each link (num_wts,max_links)
85  & wts_map2 ! map weights for each link (num_wts,max_links)
86 
88  real (kind = scrip_r8) :: wt_lowest,wt_highest
89 
90 !***********************************************************************
91 
92  contains
93 
94 !***********************************************************************
95 
96  subroutine init_remap_vars
97 
98 !-----------------------------------------------------------------------
99 !
100 ! this routine initializes some variables and provides an initial
101 ! allocation of arrays (fairly large so frequent resizing
102 ! unnecessary).
103 !
104 !-----------------------------------------------------------------------
105 
106 !-----------------------------------------------------------------------
107 !
108 ! determine the number of weights
109 !
110 !-----------------------------------------------------------------------
111 
112  select case (map_type)
113  case(map_type_conserv)
114  num_wts = 3
115  case(map_type_bilinear)
116  num_wts = 1
117  case(map_type_bicubic)
118  num_wts = 4
119  case(map_type_distwgt)
120  num_wts = 1
121  case(map_type_particle)
122  num_wts = 1
123  end select
124 
125 !-----------------------------------------------------------------------
126 !
127 ! initialize num_links and set max_links to four times the largest
128 ! of the destination grid sizes initially (can be changed later).
129 ! set a default resize increment to increase the size of link
130 ! arrays if the number of links exceeds the initial size
131 !
132 !-----------------------------------------------------------------------
133 
134  num_links_map1 = 0
136  if (num_maps > 1) then
137  num_links_map2 = 0
140  endif
141 
143 
144 !-----------------------------------------------------------------------
145 !
146 ! allocate address and weight arrays for mapping 1
147 !
148 !-----------------------------------------------------------------------
149 
150  allocate (grid1_add_map1(max_links_map1),
153 
154 !-----------------------------------------------------------------------
155 !
156 ! allocate address and weight arrays for mapping 2 if necessary
157 !
158 !-----------------------------------------------------------------------
159 
160  if (num_maps > 1) then
161  allocate (grid1_add_map2(max_links_map2),
164  endif
165 
166 !-----------------------------------------------------------------------
167 
168  end subroutine init_remap_vars
169 
170 !***********************************************************************
171 
172  subroutine resize_remap_vars(nmap, increment)
173 
174 !-----------------------------------------------------------------------
175 !
176 ! this routine resizes remapping arrays by increasing(decreasing)
177 ! the max_links by increment
178 !
179 !-----------------------------------------------------------------------
180 
181 !-----------------------------------------------------------------------
182 !
183 ! input variables
184 !
185 !-----------------------------------------------------------------------
186 
187  integer (SCRIP_i4), intent(in) ::
188  & nmap, ! identifies which mapping array to resize
189  & increment ! the number of links to add(subtract) to arrays
190 
191 !-----------------------------------------------------------------------
192 !
193 ! local variables
194 !
195 !-----------------------------------------------------------------------
196 
197  integer (SCRIP_i4) ::
198  & ierr, ! error flag
199  & mxlinks ! size of link arrays
200 
201  integer (SCRIP_i4), dimension(:), allocatable ::
202  & add1_tmp, ! temp array for resizing address arrays
203  & add2_tmp ! temp array for resizing address arrays
204 
205  real (SCRIP_r8), dimension(:,:), allocatable ::
206  & wts_tmp ! temp array for resizing weight arrays
207 
208 !-----------------------------------------------------------------------
209 !
210 ! resize map 1 arrays if required.
211 !
212 !-----------------------------------------------------------------------
213 
214  select case (nmap)
215  case(1)
216 
217  !***
218  !*** allocate temporaries to hold original values
219  !***
220 
221  mxlinks = size(grid1_add_map1)
222  allocate (add1_tmp(mxlinks), add2_tmp(mxlinks),
223  & wts_tmp(num_wts,mxlinks))
224 
225  add1_tmp = grid1_add_map1
226  add2_tmp = grid2_add_map1
227  wts_tmp = wts_map1
228 
229  !***
230  !*** deallocate originals and increment max_links then
231  !*** reallocate arrays at new size
232  !***
233 
234  deallocate (grid1_add_map1, grid2_add_map1, wts_map1)
235  max_links_map1 = mxlinks + increment
236  allocate (grid1_add_map1(max_links_map1),
239 
240  !***
241  !*** restore original values from temp arrays and
242  !*** deallocate temps
243  !***
244 
245  mxlinks = min(mxlinks, max_links_map1)
246  grid1_add_map1(1:mxlinks) = add1_tmp(1:mxlinks)
247  grid2_add_map1(1:mxlinks) = add2_tmp(1:mxlinks)
248  wts_map1(:,1:mxlinks) = wts_tmp(:,1:mxlinks)
249  deallocate(add1_tmp, add2_tmp, wts_tmp)
250 
251 !-----------------------------------------------------------------------
252 !
253 ! resize map 2 arrays if required.
254 !
255 !-----------------------------------------------------------------------
256 
257  case(2)
258 
259  !***
260  !*** allocate temporaries to hold original values
261  !***
262 
263  mxlinks = size(grid1_add_map2)
264  allocate (add1_tmp(mxlinks), add2_tmp(mxlinks),
265  & wts_tmp(num_wts,mxlinks),stat=ierr)
266  if (ierr .ne. 0) then
267  print *,'error allocating temps in resize: ',ierr
268  stop
269  endif
270 
271  add1_tmp = grid1_add_map2
272  add2_tmp = grid2_add_map2
273  wts_tmp = wts_map2
274 
275  !***
276  !*** deallocate originals and increment max_links then
277  !*** reallocate arrays at new size
278  !***
279 
280  deallocate (grid1_add_map2, grid2_add_map2, wts_map2)
281  max_links_map2 = mxlinks + increment
282  allocate (grid1_add_map2(max_links_map2),
284  & wts_map2(num_wts,max_links_map2),stat=ierr)
285  if (ierr .ne. 0) then
286  print *,'error allocating new arrays in resize: ',ierr
287  stop
288  endif
289 
290 
291  !***
292  !*** restore original values from temp arrays and
293  !*** deallocate temps
294  !***
295 
296  mxlinks = min(mxlinks, max_links_map2)
297  grid1_add_map2(1:mxlinks) = add1_tmp(1:mxlinks)
298  grid2_add_map2(1:mxlinks) = add2_tmp(1:mxlinks)
299  wts_map2(:,1:mxlinks) = wts_tmp(:,1:mxlinks)
300  deallocate(add1_tmp, add2_tmp, wts_tmp)
301 
302  end select
303 
304 !-----------------------------------------------------------------------
305 
306  end subroutine resize_remap_vars
307 
308 !***********************************************************************
309 
310  end module scrip_remap_vars
311 
312 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
scrip_remap_vars::norm_opt_none
integer(scrip_i4), parameter norm_opt_none
Definition: scrip_remap_vars.f:54
scrip_remap_vars::grid1_add_map1
integer(scrip_i4), dimension(:), allocatable, save grid1_add_map1
Definition: scrip_remap_vars.f:77
scrip_remap_vars::map_type_bilinear
integer(scrip_i4), parameter map_type_bilinear
Definition: scrip_remap_vars.f:59
scrip_remap_vars::wt_lowest
real(kind=scrip_r8) wt_lowest
Definition: scrip_remap_vars.f:88
scrip_remap_vars::num_maps
integer(scrip_i4), save num_maps
Definition: scrip_remap_vars.f:66
scrip_remap_vars::wt_highest
real(kind=scrip_r8) wt_highest
Definition: scrip_remap_vars.f:88
scrip_remap_vars::num_links_map1
integer(scrip_i4), save num_links_map1
Definition: scrip_remap_vars.f:66
scrip_remap_vars::norm_opt
integer(scrip_i4), save norm_opt
Definition: scrip_remap_vars.f:66
scrip_remap_vars::max_links_map2
integer(scrip_i4), save max_links_map2
Definition: scrip_remap_vars.f:66
scrip_remap_vars::num_links_map2
integer(scrip_i4), save num_links_map2
Definition: scrip_remap_vars.f:66
scrip_remap_vars::map_type
integer(scrip_i4), save map_type
Definition: scrip_remap_vars.f:66
scrip_grids
Definition: scrip_grids.f:49
scrip_remap_vars::map_type_particle
integer(scrip_i4), parameter map_type_particle
Definition: scrip_remap_vars.f:59
scrip_kindsmod::scrip_r8
integer, parameter, public scrip_r8
Definition: scrip_kindsmod.f90:38
scrip_remap_vars::grid2_add_map2
integer(scrip_i4), dimension(:), allocatable, save grid2_add_map2
Definition: scrip_remap_vars.f:77
scrip_remap_vars::norm_opt_frcarea
integer(scrip_i4), parameter norm_opt_frcarea
Definition: scrip_remap_vars.f:54
scrip_remap_vars::max_links_map1
integer(scrip_i4), save max_links_map1
Definition: scrip_remap_vars.f:66
scrip_remap_vars::frac_highest
real(kind=scrip_r8) frac_highest
Definition: scrip_remap_vars.f:87
scrip_grids::grid2_size
integer(scrip_i4), save grid2_size
Definition: scrip_grids.f:68
scrip_remap_vars::frac_lowest
real(kind=scrip_r8) frac_lowest
Definition: scrip_remap_vars.f:87
scrip_remap_vars::wts_map1
real(scrip_r8), dimension(:,:), allocatable, save wts_map1
Definition: scrip_remap_vars.f:83
scrip_remap_vars::resize_remap_vars
subroutine resize_remap_vars(nmap, increment)
Definition: scrip_remap_vars.f:173
scrip_constants
Definition: scrip_constants.f:38
scrip_remap_vars::map_type_distwgt
integer(scrip_i4), parameter map_type_distwgt
Definition: scrip_remap_vars.f:59
scrip_remap_vars::init_remap_vars
subroutine init_remap_vars
Definition: scrip_remap_vars.f:97
scrip_kindsmod
Definition: scrip_kindsmod.f90:3
scrip_remap_vars::map_type_conserv
integer(scrip_i4), parameter map_type_conserv
Definition: scrip_remap_vars.f:59
scrip_remap_vars::grid1_add_map2
integer(scrip_i4), dimension(:), allocatable, save grid1_add_map2
Definition: scrip_remap_vars.f:77
scrip_remap_vars::grid2_add_map1
integer(scrip_i4), dimension(:), allocatable, save grid2_add_map1
Definition: scrip_remap_vars.f:77
scrip_grids::grid1_size
integer(scrip_i4), save grid1_size
Definition: scrip_grids.f:68
scrip_remap_vars::map_type_bicubic
integer(scrip_i4), parameter map_type_bicubic
Definition: scrip_remap_vars.f:59
scrip_remap_vars::wts_map2
real(scrip_r8), dimension(:,:), allocatable, save wts_map2
Definition: scrip_remap_vars.f:83
scrip_remap_vars
Definition: scrip_remap_vars.f:40
scrip_remap_vars::norm_opt_dstarea
integer(scrip_i4), parameter norm_opt_dstarea
Definition: scrip_remap_vars.f:54
scrip_remap_vars::num_wts
integer(scrip_i4), save num_wts
Definition: scrip_remap_vars.f:66
scrip_remap_vars::resize_increment
integer(scrip_i4), save resize_increment
Definition: scrip_remap_vars.f:66