SCRIPusers.tex 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  1. \documentclass[12pt]{report}
  2. \title{A User's Guide for SCRIP: A {\em S}pherical {\em C}oordinate
  3. {\em R}empping and {\em I}nterpolation {\em P}ackage }
  4. \author{Philip W. Jones}
  5. \begin{document}
  6. %\maketitle
  7. \begin{titlepage}
  8. \vspace{1in}
  9. \begin{center}
  10. {\Large{A User's Guide for SCRIP: A {\em S}pherical {\em C}oordinate
  11. {\em R}emapping and {\em I}nterpolation {\em P}ackage }}
  12. \end{center}
  13. \vspace{1in}
  14. \begin{center}
  15. Version 1.4
  16. \end{center}
  17. \vspace{1in}
  18. \begin{center}
  19. Philip W. Jones \\
  20. Theoretical Division \\
  21. Los Alamos National Laboratory
  22. \end{center}
  23. \newpage
  24. \begin{center}
  25. {\bf COPYRIGHT NOTICE}
  26. \end{center}
  27. Copyright \copyright 1997, 1998 the Regents of the University of
  28. California.
  29. \vspace{0.5in}
  30. This software and ancillary information (herein called SOFTWARE) called
  31. SCRIP is made available under the terms described here. The SOFTWARE
  32. has been approved for release with associated LA-CC Number 98-45.
  33. Unless otherwise indicated, this SOFTWARE has been authored by an
  34. employee or employees of the University of California, operator
  35. of Los Alamos National Laboratory under Contract No. W-7405-ENG-36
  36. with the United States Department of Energy. The United States
  37. Government has rights to use, reproduce, and distribute this
  38. SOFTWARE. The public may copy, distribute, prepare derivative
  39. works and publicly display this SOFTWARE without charge, provided
  40. that this Notice and any statement of authorship are reproduced
  41. on all copies. Neither the Government nor the University makes
  42. any warranty, express or implied, or assumes any liability or
  43. responsibility for the use of this SOFTWARE.
  44. If SOFTWARE is modified to produce derivative works, such modified
  45. SOFTWARE should be clearly marked, so as not to confuse it with the
  46. version available from Los Alamos National Laboratory.
  47. \end{titlepage}
  48. \tableofcontents
  49. \chapter{Introduction}
  50. SCRIP is a software package used to generate interpolation weights
  51. for remapping fields from one grid to another in spherical geometry.
  52. The package currently supports four types of remappings. The
  53. first is a conservative remapping scheme that
  54. is ideally suited to a coupled model context where the area-integrated
  55. field (e.g. water or heat flux) must be conserved. The second
  56. type of mapping is a basic bilinear interpolation which has
  57. been slightly generalized to perform a local bilinear interpolation.
  58. A third method is a bicubic interpolation similar to the
  59. bilinear method.
  60. The last type of remapping is a distance-weighted average of
  61. nearest-neighbor points. The bilinear and bicubic schemes can
  62. only be used with logically-rectangular grids; the other two methods
  63. can be used for any grid in spherical coordinates.
  64. SCRIP is available via the web at \newline
  65. http://climate.acl.lanl.gov/software/SCRIP/ \newline
  66. NOTE: This location has changed since the 1.2 release.
  67. The next chapter describes how to compile and run SCRIP, while
  68. the following sections describe the remapping methods in more
  69. detail.
  70. \chapter{Compiling and Running}
  71. The distribution file is a gzipped tarfile, so you must
  72. uncompress the file using ``gunzip'' and then extract SCRIP
  73. from the tar file using ``tar -xvf scrip1.4.tar''. The extraction
  74. process will create a directory called SCRIP with two
  75. subdirectories named ``source'' and ``grids''. The source
  76. directory contains all the source files and the makefile
  77. for building the package. The grids directory contains
  78. some sample grid files and routines for creating or
  79. converting other grid files to the proper format.
  80. \section{Compiling}
  81. In order to compile SCRIP, you need access to a
  82. Fortran 90 compiler and a netCDF library (version 3 or
  83. later). In the source directory, you must edit the
  84. makefile to insert the appropriate compiler and compiler
  85. options for whatever machine you happen to work on. The
  86. makefile currently only has SGI compiler options. In
  87. addition, you must edit the paths in the makefile to
  88. find the proper netCDF library - if netCDF is in your
  89. default path, you may delete the path altogether.
  90. Once the makefile has been edited to reflect your
  91. local environment, type ``make'' and let it
  92. build. By default, the makefile builds two executables
  93. in the main SCRIP directory;
  94. the first executable is called scrip and computes
  95. all the necessary weights for a remapping. The second
  96. executable is a simple test code scrip\_test which will
  97. test the weights output by scrip.
  98. \subsection{Compile-time Parameters}
  99. There are a few compile-time parameters that can
  100. be changed before compiling (see Table~\ref{tab:params}).
  101. For the most part, the
  102. defaults are adequate, but you may wish to change
  103. these at some point. The use of these parameters
  104. will become clear in the chapters describing the
  105. remapping algorithms.
  106. \begin{table}
  107. \caption{Compile-time parameters \label{tab:params}}
  108. \begin{tabular}{|l|l|c|l|} \hline
  109. Routine & Parameter & Default & Description \\
  110. & Name & Value & \\ \hline
  111. remap\_conserv.f & north\_thresh & 1.42 & threshold latitude (in \\
  112. & & & radians) above which a \\
  113. & & & coordinate transformation \\
  114. & & & is used to perform \\
  115. & & & intersection calculation \\ \hline
  116. remap\_conserv.f & south\_thresh & -2.00 & same for south pole \\ \hline
  117. remap\_conserv.f & max\_subseg & 10000 & maximum number of sub- \\
  118. & & & segments allowed (to \\
  119. & & & prevent infinite loop) \\
  120. \hline
  121. remap\_bilinear.f & max\_iter & 100 & max number of iterations \\
  122. & & & to determine local i,j \\ \hline
  123. remap\_bilinear.f & converge & $1\times 10^{-10}$
  124. & convergence criterion \\
  125. & & & for bilinear iteration \\
  126. \hline
  127. remap\_bicubic.f & max\_iter & 100 & max number of iterations \\
  128. & & & to determine local i,j \\ \hline
  129. remap\_bicubic.f & converge & $1\times 10^{-10}$
  130. & convergence criterion \\
  131. & & & for bicubic iteration \\
  132. \hline
  133. remap\_distwgt.f & num\_neighbors & 4 & number of nearest \\
  134. & & & neighbors to use for \\
  135. & & & distance-weighted average\\
  136. \hline
  137. iounits.f & stdin & 5 & I/O unit reserved for \\
  138. & & & standard input \\ \hline
  139. iounits.f & stdout & 6 & I/O unit reserved for \\
  140. & & & standard output \\ \hline
  141. iounits.f & stderr & 6 & I/O unit reserved for \\
  142. & & & standard error output \\
  143. \hline
  144. timers.f & max\_timers & 99 & max number of CPU timers \\
  145. \hline
  146. \end{tabular}
  147. \end{table}
  148. \section{Running}
  149. Once the code is compiled, a few input files are needed.
  150. The first is a namelist input file and the other two
  151. required files are grid description files.
  152. \subsection{Namelist Input}
  153. The namelist input file must be called scrip\_in
  154. and contain a namelist as shown in Fig.~\ref{fig:nml}.
  155. \begin{figure}
  156. \caption{Required input namelist. \label{fig:nml}}
  157. \begin{verbatim}
  158. &remap_inputs
  159. num_maps = 2
  160. grid1_file = 'grid_1_file_name'
  161. grid2_file = 'grid_2_file_name'
  162. interp_file1 = 'map_1_output_file_name'
  163. interp_file2 = 'map_2_output_file_name'
  164. map1_name = 'name_for_mapping_1'
  165. map2_name = 'name_for_mapping_2'
  166. map_method = 'conservative'
  167. normalize_opt = 'frac'
  168. output_opt = 'scrip'
  169. restrict_type = 'latitude'
  170. num_srch_bins = 90
  171. luse_grid1_area = .false.
  172. luse_grid2_area = .false.
  173. /
  174. \end{verbatim}
  175. \end{figure}
  176. The num\_maps variable determines the number of mappings
  177. to be computed. If you'd like mappings only from a source
  178. grid (grid 1) to a destination grid (grid 2), then
  179. num\_maps should be set to one. If you'd also like weights
  180. for a remapping in the opposite direction (grid 2 to grid 1),
  181. then num\_maps should be set to two.
  182. The map\_method variable determines the method to be used
  183. for the mapping. A conservative remapping is map\_method
  184. `conservative'; a bilinear mapping is map\_method `bilinear';
  185. a distance-weighted average is map\_method `distwgt'; a
  186. bicubic mapping is map\_method `bicubic'.
  187. The restrict\_type variable and num\_srch\_bins determines
  188. how the software restricts the range of grid points to search
  189. to avoid a full $N^2$ search. There are currently two options
  190. for restrict\_type: `latitude' and `latlon'. The first was used in
  191. all previous versions of SCRIP and restricts the search by
  192. dividing the grid points into num\_srch\_bins latitude bins.
  193. The `latlon' choice divides the spherical domain into
  194. latitude-longitude boxes and thus provides a way to
  195. restrict the longitude range as well. Note that for the latlon
  196. option, the domain is divided by num\_srch\_bins in
  197. {\em each} direction so that the total number of bins is the
  198. square of num\_srch\_bins. Generally, the larger the number
  199. of bins, the more the search can be restricted. However if
  200. the number of bins is too large, more time will be taken
  201. restricting the search than the search itself. For coarse
  202. grids, choosing the latitude option with 90 bins (one degree
  203. bins) is sufficient.
  204. The normalize\_opt variable is used to choose the normalization
  205. of the remappings for the conservative remapping method.
  206. By default, normalize\_opt is set to be `fracarea' and will
  207. include the destination area fraction in the output weights;
  208. other options are `none' and `destarea' (see chapter on the
  209. conservative remapping method). The latter two are useful when
  210. dealing with masks that are dynamic (e.g. variable ice fraction).
  211. Keep in mind that in such a case, the
  212. area fractions must be computed explicitly by the remapping
  213. routine at the time the remappings are actually computed
  214. (see the example in Fig.~\ref{fig:rmpfort}).
  215. The grid{\em x}\_file are names (with relative paths) of
  216. the grid input files. The first grid file (grid1\_file)
  217. {\em must} be the source grid if num\_maps=1. If this
  218. mapping uses the conservative remapping method, the first
  219. grid file must also be the grid with the master mask
  220. (e.g. a land mask) -- grid fractions on the second grid
  221. will be determined by this mask.
  222. Names of the output files for the remapping weights are
  223. determined by the interp\_file{\em x} filenames (again
  224. with paths). Map 1 refers to a mapping from grid 1 to
  225. grid 2; map 2 is in the opposite direction.
  226. A descriptive name for the remappings are determined by
  227. the map{\em x}\_name variables. These should be
  228. descriptive enough to know exactly which grids and
  229. methods were used.
  230. The output\_opt variable determines the format of the
  231. netCDF output file. The two currently-supported options
  232. are `scrip' and `ncar-csm'. The latter is to generate
  233. files for use in the NCAR CSM Flux Coupler for coupled
  234. climate modeling. The primary difference between the
  235. formats is the choice of variable names.
  236. The two logical flags luse\_grid{\em x}\_area are
  237. for using an input area to normalize the conservative
  238. weights. If these are set to true, the input grid
  239. files must contain the grid areas. This option is
  240. provided primarily for making the weights consistent
  241. with internal model-computed areas (which may differ
  242. somewhat from the SCRIP-computed areas).
  243. \subsection{Grid Input Files}
  244. The grid input files are in netCDF format as shown
  245. by the sample ncdump grid output in Fig.~\ref{fig:ncgrid}.
  246. If you're unfamiliar with ncdump output, it's important to
  247. not that ncdump shows the array dimensions in C ordering.
  248. In Fortran, the order is reversed (e.g. arrays are
  249. dimensioned (grid\_corners,grid\_size).
  250. In the grids subdirectory of the distribution there
  251. are some fortran source codes for creating these
  252. grid files for some special cases. See the README
  253. file in that subdirectory for details.
  254. \begin{figure}
  255. \caption{A sample input grid file. \label{fig:ncgrid}}
  256. \begin{verbatim}
  257. netcdf remap_grid_T42 {
  258. dimensions:
  259. grid_size = 8192 ;
  260. grid_corners = 4 ;
  261. grid_rank = 2 ;
  262. variables:
  263. long grid_dims(grid_rank) ;
  264. double grid_center_lat(grid_size) ;
  265. grid_center_lat:units = "radians" ;
  266. double grid_center_lon(grid_size) ;
  267. grid_center_lon:units = "radians" ;
  268. long grid_imask(grid_size) ;
  269. grid_imask:units = "unitless" ;
  270. double grid_corner_lat(grid_size, grid_corners) ;
  271. grid_corner_lat:units = "radians" ;
  272. double grid_corner_lon(grid_size, grid_corners) ;
  273. grid_corner_lon:units = "radians" ;
  274. // global attributes:
  275. :title = "T42 Gaussian Grid" ;
  276. }
  277. \end{verbatim}
  278. \end{figure}
  279. The name of the grid is given as the title and will be used
  280. to specify the grid name throughout the remapping process.
  281. The grid\_size dimension is the total size of the grid; grid\_rank
  282. refers to the number of dimensions the grid array would have
  283. when used in a model code. The number of corners (vertices) in
  284. each grid cell is given by grid\_corners. Note that if your
  285. grid has a variable number of corners on grid cells, then you
  286. should set grid\_corners to be the highest value and use
  287. redundant points on cells with fewer corners.
  288. The integer array grid\_dims gives the length of each
  289. grid axis when used in a model code. Because the remapping
  290. routines read the grid properties as a linear list of
  291. grid cells, the grid\_dims array is necessary for
  292. reconstructing the grid, particularly for a bilinear mapping
  293. where a logically rectangular structure is needed.
  294. The integer array grid\_imask is used to mask out grid cells
  295. which should not participate in the remapping. The array
  296. should by zero for any points (e.g. land points) that do
  297. not participate in the remapping and one for all other points.
  298. Coordinate arrays provide the latitudes and longitudes of
  299. cell centers and cell corners. Although the above reports
  300. the units as ``radians'', the code happily accepts ``degrees''
  301. as well. The grid corner coordinates {\em must} be
  302. written in an order which traces the outside of a grid
  303. cell in a counterclockwise sense. That is, when moving
  304. from corner 1 to corner 2 to corner 3, etc., the grid
  305. cell interior must always be to the left.
  306. \subsection{Output Files}
  307. The remapping output files are also in netCDF format
  308. and contain some grid information from each grid
  309. as well as the remapping addresses and weights. An example
  310. ncdump of the output files is shown in Fig.~\ref{fig:ncrmp}.
  311. \begin{figure}
  312. \caption{A sample output file for mapping data in scrip format.
  313. \label{fig:ncrmp}}
  314. \begin{verbatim}
  315. netcdf rmp_POP43_to_T42_cnsrv {
  316. dimensions:
  317. src_grid_size = 24576 ; dst_grid_size = 8192 ;
  318. src_grid_corners = 4 ; dst_grid_corners = 4 ;
  319. src_grid_rank = 2 ; dst_grid_rank = 2 ;
  320. num_links = 42461 ; num_wgts = 3 ;
  321. variables:
  322. long src_grid_dims(src_grid_rank) ;
  323. long dst_grid_dims(dst_grid_rank) ;
  324. double src_grid_center_lat(src_grid_size) ;
  325. double dst_grid_center_lat(dst_grid_size) ;
  326. double src_grid_center_lon(src_grid_size) ;
  327. double dst_grid_center_lon(dst_grid_size) ;
  328. long src_grid_imask(src_grid_size) ;
  329. long dst_grid_imask(dst_grid_size) ;
  330. double src_grid_corner_lat(src_grid_size, src_grid_corners) ;
  331. double src_grid_corner_lon(src_grid_size, src_grid_corners) ;
  332. double dst_grid_corner_lat(dst_grid_size, dst_grid_corners) ;
  333. double dst_grid_corner_lon(dst_grid_size, dst_grid_corners) ;
  334. double src_grid_area(src_grid_size) ;
  335. src_grid_area:units = "square radians" ;
  336. double dst_grid_area(dst_grid_size) ;
  337. dst_grid_area:units = "square radians" ;
  338. double src_grid_frac(src_grid_size) ;
  339. double dst_grid_frac(dst_grid_size) ;
  340. long src_address(num_links) ;
  341. long dst_address(num_links) ;
  342. double remap_matrix(num_links, num_wgts) ;
  343. // global attributes:
  344. :title = "POP 4/3 to T42 Conservative Mapping" ;
  345. :normalization = "fracarea" ;
  346. :map_method = "Conservative remapping" ;
  347. :history = "Created: 07-19-1999" ;
  348. :conventions = "SCRIP" ;
  349. :source_grid = "POP 4/3 Displaced-Pole T grid" ;
  350. :dest_grid = "T42 Gaussian Grid" ;
  351. }
  352. \end{verbatim}
  353. \end{figure}
  354. The grid information is simply echoing the input grid file
  355. information and adding grid\_area and grid\_frac arrays.
  356. The grid\_area array currently is {\em only} computed by
  357. the conservative remapping option; the others will write
  358. arrays full of zeros for this field. The grid\_frac array
  359. for the conservative remapping returns the area fraction
  360. of the grid cell which participates in the remapping based
  361. on the source grid mask. For the other two remapping options,
  362. the grid\_frac array is one where the grid point participates
  363. in the remapping and zero otherwise, based again on the
  364. source grid mask (and {\em not} on the grid\_imask for that
  365. grid).
  366. The remapping data itself is written as if for a sparse matrix
  367. multiplication. Again, the Fortran array must be dimensioned
  368. (num\_wgts,num\_links) rather than the C order shown in the
  369. ncdump. The dimension num\_wgts refers to the number
  370. of weights for a given remapping and is one for bilinear and
  371. distance-weighted remappings. For the conservative
  372. remapping, num\_wgts is 3 as it contains two additional
  373. weights for a second-order remapping. The bicubic remappings
  374. require four weights as for gradients in each direction plus
  375. a term for the cross gradient. The dimension num\_links
  376. is the number of unique address pairs in the remapping and is
  377. therefore the number of entries in a sparse matrix for the
  378. remapping. The integer address arrays contain the source
  379. and destination address for each ``link''. So, a Fortran code
  380. to complete the conservative remappings might look like that
  381. shown in Fig.~\ref{fig:rmpfort}.
  382. \begin{figure}
  383. \caption{Sample Fortran code for performing a first-order
  384. conservative remap. \label{fig:rmpfort}}
  385. \begin{verbatim}
  386. dst_array = 0.0
  387. select case (normalize_opt)
  388. case ('fracarea')
  389. do n=1,num_links
  390. dst_array(dst_address(n)) = dst_array(dst_address(n)) +
  391. remap_matrix(1,n)*src_array(src_address(n))
  392. end do
  393. case ('destarea')
  394. do n=1,num_links
  395. dst_array(dst_address(n)) = dst_array(dst_address(n)) +
  396. (remap_matrix(1,n)*src_array(src_address(n)))/
  397. (dst_frac(dst_address(n)))
  398. end do
  399. case ('none')
  400. do n=1,num_links
  401. dst_array(dst_address(n)) = dst_array(dst_address(n)) +
  402. (remap_matrix(1,n)*src_array(src_address(n)))/
  403. (dst_area(dst_address(n))*dst_frac(dst_address(n)))
  404. end do
  405. end select
  406. \end{verbatim}
  407. \end{figure}
  408. The address arrays are sorted by destination address and are
  409. linear addresses that assume standard
  410. Fortran ordering. They can therefore be converted to logical
  411. address space if necessary. For example, a point on a
  412. two-dimensional grid with logical coordinates $(i,j)$ will
  413. have a linear address $n$ given by
  414. $n=(j-1)*{\rm grid\_dims(1)} + i.$ Alternatively, if the
  415. code is run on a serial machine, the multi-dimensional arrays
  416. can be passed into linear dummy arrays and the addresses can
  417. be used directly. Such a storage/sequence association may
  418. not be valid in a distributed-memory context however.
  419. The scrip\_test code shows an example of how the remappings
  420. can be implemented.
  421. \section{Testing}
  422. In order to test the weights computed by the SCRIP package,
  423. a simple test code is provided. This code reads in the
  424. weights and remaps analytic fields. Three choices for the
  425. analytic field are provided. The first is a cosine bell
  426. function $f=2+\cos(\pi r/L)$, where $r$ is the distance from
  427. the center of the hill and $L$ is a length scale. Such a
  428. function is useful for determining the effects of repeated
  429. applications. The other two fields are representative of
  430. spherical harmonic wavefunctions. A relatively smooth function
  431. $f=2+\cos^2\theta\cos(2\phi)$ is similar to a spherical
  432. harmonic with $\ell=2$ and $m=2$, where $\ell$ is the
  433. spherical harmonic order and $m$ is the azimuthal wave number.
  434. The function
  435. $f=2+\sin^{16}(2\theta)\cos(16\phi)$ is similar to a
  436. spherical harmonic with $\ell=32$ and $m=16$ and is useful
  437. for testing a field with relatively high spatial
  438. frequency and rapidly changing gradients. The choice of
  439. which field is remapped in determined by the input namelist
  440. scrip\_test\_in.
  441. For
  442. conservative remappings, the test code tests three different
  443. remappings: the first is a first-order remapping, the second
  444. is a second-order remapping using only latitude gradients,
  445. and the third is a full second-order remapping. The second
  446. is performed in order to determine which weights are
  447. causing problems when errors occur. The code
  448. prints out three diagnostics to standard output and writes
  449. many quantities to a netCDF output file.
  450. First, it prints out the minimum and maximum of the source
  451. and destination (remapped) fields. This is a test for
  452. monotonicity (although only the first-order conservative
  453. remapping is monotone by default).
  454. Second, the test code prints out the maximum and average
  455. relative error $\epsilon =
  456. |(F_{dst} - F_{analytic})/F_{analytic}|$, where
  457. $F_{analytic}$ is the source function evaluated at the
  458. destination grid points and $F_{dst}$ is the destination
  459. (remapped) field. The errors here can sometimes be misleading.
  460. For example, if a conservative remapping is performed from
  461. a fine grid to a coarse grid, the destination array will
  462. contain the field averaged over many source cells, while
  463. $F_{analytic}$ is the analytic field evaluated at the cell
  464. center point. Another instance which leads to relatively
  465. large errors is near mask boundaries where the remapped
  466. field is correctly returning values indicative of the edge
  467. of a grid cell, while $F_{analytic}$ is again computing
  468. cell-center values. To avoid the latter problem, the error is
  469. only computed where the destination grid fraction
  470. is greater than $0.999$.
  471. Lastly, the test code prints out the area-integrated
  472. field on the source and destination grids in order to
  473. test conservation. This diagnostic returns zeros for
  474. all but conservative remappings. For a first-order
  475. conservative remapping, these numbers should agree
  476. to machine accuracy. For a second-order conservative
  477. remapping, they will be very close, but may not exactly
  478. agree due to mask boundary effects where it is not
  479. possible to perform the exact area integral.
  480. The netCDF output file from the test code contains
  481. the source and destination arrays as well as the
  482. error arrays so the error can be examined at every
  483. grid point to pinpoint problems. The arrays in
  484. the netCDF file are written out in arrays with
  485. rank grid\_rank (e.g. two-dimensional grids are
  486. written as proper 2-d arrays rather than vectors
  487. of values). These arrays can then be viewed using
  488. any visualization package.
  489. \chapter{Conservative Remapping}
  490. The SCRIP package implements a conservative remapping
  491. scheme described in detail in a separate paper
  492. (Jones, P.W. 1999 {\em Monthly Weather Review},
  493. {\bf 127}, 2204-2210).
  494. A brief outline will be given here to aid the
  495. user in understanding what this portion of the
  496. package does.
  497. To compute a flux on a new (destination) grid which
  498. results in the same energy or water exchange as a flux $f$ on an
  499. old (source) grid, the destination flux $F$ at a destination grid
  500. cell $k$ must satisfy
  501. \begin{equation}\label{eq:local}
  502. \overline{F}_k = {1\over{A_k}}\int\int_{A_k} fdA,
  503. \end{equation}
  504. where $\overline{F}$ is the area-averaged flux and $A_k$ is
  505. the area of cell $k$.
  506. Because the integral in (\ref{eq:local}) is over the area of
  507. the destination grid cell, only those cells on the source grid
  508. that are covered at least partly by the destination grid cell
  509. contribute to the value of the flux on the destination grid.
  510. If cell $k$ overlaps $N$ cells on the source grid, the
  511. remapping can be written as
  512. \begin{equation}\label{eq:rmpsum}
  513. \overline{F}_k =
  514. {1\over{A_k}} \sum_{n=1}^N \int\int_{A_{nk}} f_ndA,
  515. \end{equation}
  516. where $A_{nk}$ is the
  517. area of the source grid cell $n$ covered by the destination grid
  518. cell $k$, and $f_n$ is the local value of the flux in the source
  519. grid cell (see Figure~\ref{fig:grids}). Note that (\ref{eq:rmpsum})
  520. is normalized by the destination area $A_k$ corresponding to
  521. the normalize\_opt value of `destarea'. The sum of the weights
  522. for a destination cell $k$ in this case would be between 0 and 1
  523. and would be the area fraction if $f_n$ were identically 1
  524. everywhere on the source grid. The normalization option
  525. `fracarea' would actually divide by the area of the source
  526. grid overlapped by cell $k$:
  527. \begin{equation}
  528. \sum_{n=1}^N \int\int_{A_{nk}}dA.
  529. \end{equation}
  530. For this normalization option, remapping a function $f$ which
  531. is 1 everywhere on the source grid would result in a function
  532. $F$ that is exactly one wherever the destination grid overlaps
  533. a non-masked source grid cell and zero otherwise. A normalization
  534. option of `none' would result in the actual angular area
  535. participating in the remapping.
  536. Assuming $f_n$ is constant across a source grid cell,
  537. (\ref{eq:rmpsum})
  538. would lead to the first-order area-weighted schemes used in
  539. current coupled models. A more accurate form of the remapping
  540. is obtained by using
  541. \begin{equation}\label{eq:gradient}
  542. f_n = \overline{f}_n +
  543. \nabla_n f\cdot({\vec{r}} - \vec{r}_n),
  544. \end{equation}
  545. where $\nabla_n f$ is the gradient of the flux in cell $n$ and
  546. $\vec{r}_n$ is the centroid of cell $n$ defined by
  547. \begin{equation}\label{eq:centroid}
  548. \vec{r}_n = {1\over{A_n}}\int\int_{A_n}\vec{r}dA.
  549. \end{equation}
  550. Such a distribution satisfies the conservation constraint and
  551. is equivalent to the first terms of a Taylor series expansion
  552. of $f$ around $\vec{r}_n$. The remapping is thus
  553. second-order accurate if $\nabla_n f$ is at least a
  554. first-order approximation to the gradient.
  555. The remapping can now be expanded in spherical coordinates as
  556. \begin{equation}\label{eq:remap}
  557. \overline{F}_k = \sum_{n=1}^{N} \left[\overline{f}_n w_{1nk} +
  558. \left({{\partial f}\over{\partial \theta}}\right)_n w_{2nk} +
  559. \left({1\over{\cos\theta}}{{\partial f}\over{\partial \phi}}\right)_n w_{3nk}
  560. \right],
  561. \end{equation}
  562. where $\theta$ is latitude, $\phi$ is longitude and the
  563. three remapping weights are
  564. \begin{equation}\label{eq:weights1}
  565. w_{1nk} = {1\over{A_k}}\int\int_{A_{nk}}dA, \\
  566. \end{equation}
  567. \begin{eqnarray}\label{eq:weights2}
  568. w_{2nk} & = & {1\over{A_k}}\int\int_{A_{nk}}(\theta-\theta_n)dA \nonumber \\
  569. & = & {1\over{A_k}}\int\int_{A_{nk}}\theta dA -
  570. {{w_{1nk}}\over{A_n}}\int\int_{A_n}\theta dA,
  571. \end{eqnarray}
  572. and
  573. \begin{eqnarray}\label{eq:weights3}
  574. w_{3nk} & = & {1\over{A_k}}\int\int_{A_{nk}}\cos\theta(\phi-\phi_n)dA \nonumber \\
  575. & = & {1\over{A_k}}\int\int_{A_{nk}}\phi\cos\theta dA -
  576. {{w_{1nk}}\over{A_n}}\int\int_{A_n}\phi\cos\theta dA .
  577. \end{eqnarray}
  578. Again, if the gradient is zero, ({\ref{eq:remap}})
  579. reduces to a first-order area-weighted remapping.
  580. The area integrals in
  581. equations~(\ref{eq:weights1})--(\ref{eq:weights3})
  582. are computed by converting the area integrals into line
  583. integrals using the divergence theorem.
  584. Computing line integrals around the overlap regions
  585. is much simpler; one simply integrates first around every
  586. grid cell on the source grid, keeping track of intersections
  587. with destination grid lines, and then one integrates around every
  588. grid cell on the destination grid in a similar manner. After
  589. the sweep of each grid, all overlap regions have been
  590. integrated.
  591. Choosing appropriate functions for the divergence, the integrals
  592. in equations~(\ref{eq:weights1})--(\ref{eq:weights3}) become
  593. \begin{equation}
  594. \int\int_{A_{nk}}dA = \oint_{C_{nk}} -\sin\theta d\phi,
  595. \end{equation}
  596. \begin{equation}
  597. \int\int_{A_{nk}}\theta dA =
  598. \oint_{C_{nk}} [-\cos\theta-\theta\sin\theta]d\phi,
  599. \end{equation}
  600. \begin{equation}
  601. \int\int_{A_{nk}}\phi\cos\theta dA =
  602. \oint_{C_{nk}} -{\phi\over 2}[\sin\theta\cos\theta + \theta]d\phi,
  603. \end{equation}
  604. where $C_{nk}$ is the counterclockwise path around the region
  605. $A_{nk}$. Computing these three line integrals during the
  606. sweeps of each grid provides all the information necessary
  607. for computing the remapping weights.
  608. \begin{figure}
  609. \caption{An example of a triangular destination grid
  610. cell $k$ overlapping
  611. a quadrilateral source grid. The region $A_{kn}$
  612. is where cell $k$ overlaps the quadrilateral cell $n$.
  613. Vectors
  614. used by search and intersection routines are
  615. also labelled. \label{fig:grids}}
  616. \begin{picture}(400,400)
  617. \put(100,0){\line(2,1){300}}
  618. \put(50,100){\line(2,1){300}}
  619. \put(0,200){\line(2,1){300}}
  620. %\put(0,150){\line(2,1){400}}
  621. \put( 0,200){\line(1,-2){100}}
  622. \put(100,250){\line(1,-2){100}}
  623. \put(200,300){\line(1,-2){100}}
  624. \put(300,350){\line(1,-2){100}}
  625. \put( 50,125){\line(1,0){200}}
  626. \put(250,125){\line(1,4){40}}
  627. {\thicklines
  628. \put(290,285){\vector(-3,-2){240}}
  629. \put(200,300){\vector(1,-2){50}}
  630. %\put(200,300){\vector(6,-1){90}}
  631. \put(200,300){\vector(4,-1){90}}
  632. }
  633. \put(250,295){$\vec{r}_{1b}$}
  634. \put(195,270){$\vec{r}_{12}$}
  635. \put(175,225){$\vec{r}_{be}$}
  636. \put(170,310){$(\theta_1,\phi_1)$}
  637. \put(255,200){$(\theta_2,\phi_2)$}
  638. \put(300,285){$(\theta_b,\phi_b)$}
  639. \put( 10,125){$(\theta_e,\phi_e)$}
  640. \put(200,300){\circle*{4}}
  641. \put(250,200){\circle*{4}}
  642. \put(290,285){\circle*{4}}
  643. \put( 50,125){\circle*{4}}
  644. \put(225,225){Cell $k$}
  645. \put(250,100){Cell $n$}
  646. \put(200,150){$A_{kn}$}
  647. \end{picture}
  648. \end{figure}
  649. \section{Search algorithms}\label{sec:search}
  650. As mentioned in the previous section, the algorithm for
  651. computing the remapping weights is relatively simple. The
  652. process amounts to finding the location of the endpoint
  653. of a segment and then finding the next intersection with
  654. the other grid. The line integrals are then computed and
  655. summed according to which grid cells are associated with
  656. that particular subsegment.
  657. The most time-consuming portion of the algorithm
  658. is finding which cell on one grid
  659. contains an endpoint from the other grid. Optimal
  660. search algorithms can be written when the grid is
  661. well structured and regular. However, if one requires
  662. a search algorithm that will work for any general
  663. grid, a hierarchy of search algorithms appears to
  664. work best. In SCRIP, each grid cell address is
  665. assigned to one or more latitude bins. When the
  666. search begins, only those cells belonging to the
  667. same latitude bin as the search point are used.
  668. The second stage checks the bounding box of each
  669. grid cell in the latitude bin. The bounding box
  670. is formed by the cells minimum and maximum latitude
  671. and longitude. This process further restricts
  672. the search to a small number of cells.
  673. Once the search has been restricted, a robust algorithm
  674. that works for most cases is a cross-product test.
  675. In this test, a cross product is computed between
  676. the vector corresponding to a cell side ($\vec{r}_{12}$ in
  677. Figure~\ref{fig:grids}) and a vector extending from the
  678. beginning of the cell side to the search point ($\vec{r}_{1b}$).
  679. If
  680. \begin{equation}\label{eq:cross}
  681. \vec{r}_{12} \times \vec{r}_{1b} > 0,
  682. \end{equation}
  683. the point lies to the left of the cell side. If
  684. (\ref{eq:cross}) holds for every cell side, the
  685. point is enclosed by the cell.
  686. This test is not completely robust and will fail for
  687. grid cells that are non-convex.
  688. \section{Intersections}\label{sec:intersect}
  689. Once the location of an initial endpoint is found,
  690. it is necessary to check to see if the segment intersects
  691. with the cell side. If the segment is parametrized as
  692. \begin{eqnarray}
  693. \theta &=& \theta_b + s_1 (\theta_e - \theta_b) \nonumber \\
  694. \phi &=& \phi_b + s_1 (\phi_e - \phi_b)
  695. \end{eqnarray}
  696. and the cell side as
  697. \begin{eqnarray}
  698. \theta &=& \theta_1 + s_2 (\theta_2 - \theta_1) \nonumber \\
  699. \phi &=& \phi_1 + s_2 (\phi_2 - \phi_1),
  700. \end{eqnarray}
  701. where $\theta_1, \phi_1, \theta_2, \phi_2, \theta_b,$ and
  702. $\theta_e$ are endpoints as shown in Figure~\ref{fig:grids},
  703. the intersection of the two lines occurs when $\theta$
  704. and $\phi$ are equal. The linear system
  705. \begin{equation}
  706. \left[ \begin{array}{cc}
  707. (\theta_e - \theta_b) & (\theta_1 - \theta_2) \\
  708. (\phi_e - \phi_b) & (\phi_1 - \phi_2) \\
  709. \end{array} \right]
  710. \left[ \begin{array}{c} s_1 \\ s_2 \\ \end{array} \right] =
  711. \left[ \begin{array}{c}
  712. (\theta_1 - \theta_b) \\ (\phi_1 - \phi_b) \\
  713. \end{array} \right]
  714. \end{equation}
  715. is then solved
  716. to determine $s_1$ and $s_2$ at the intersection point.
  717. If $s_1$ and $s_2$ are between zero and one, an
  718. intersection occurs with that cell side.
  719. It is important also to compute identical intersections
  720. during the sweeps of each grid. To ensure that this
  721. will occur, the entire line segment is used to
  722. compute intersections rather than using a previous or
  723. next intersection as an endpoint.
  724. \section{Coincidences}
  725. Often, pairs of grids will share common lines (e.g. the
  726. Equator). When this is the case, the method described
  727. above will double-count the contribution of these line
  728. segments. Coincidences can be detected when computing
  729. cross products for the search algorithm described above.
  730. If the cross product is zero
  731. in this case, the endpoint lies on the cell side. A
  732. second cross product between the line segment and the
  733. cell side can then be computed. If the second cross
  734. product is also zero, the lines are coincident.
  735. Once a coincidence has been detected, the contribution
  736. of the coincident segment can be computed during the
  737. first sweep and ignored during the second sweep.
  738. \section{Spherical coordinates}\label{sec-sphere}
  739. Some aspects of the spherical coordinate system introduce
  740. additional problems for the method described above.
  741. Longitude is multiple valued on one line on the sphere,
  742. and this branch cut may be chosen differently by different
  743. grids. Care must be taken when calculating intersections
  744. and line integrals to ensure that the proper
  745. longitude values are used. A simple method is to always
  746. check to make sure the longitude is in the same interval
  747. as the source grid cell center.
  748. Another problem with computing weights in spherical
  749. coordinates is the treatment of the pole. First, note
  750. that although the pole is physically a point, it is a
  751. line in latitude-longitude space and has a nonzero
  752. contribution to the weight integrals. If a grid does
  753. not contain the pole explicitly as a grid vertex, the
  754. pole contribution must be added to the appropriate cells.
  755. The pole contribution can be computed analytically.
  756. The pole also creates problems for the search and
  757. intersection algorithms described above. For example,
  758. a grid cell that overlaps the pole can result in a
  759. nonconvex cell in latitude-longitude coordinates.
  760. The cross-product test described above
  761. will fail in this case. In addition, segments near
  762. the pole typically exhibit large changes in longitude
  763. even for very short segments. In such a case, the
  764. linear parametrizations used above
  765. result in inaccuracies for determining the correct
  766. intersections.
  767. To avoid these problems, a coordinate transformation
  768. can be used poleward of a given threshold latitude
  769. (typically within one degree of the pole). A possible
  770. transformation is the Lambert equivalent azimuthal projection
  771. \begin{eqnarray}
  772. X &=& 2\sin\left({\pi \over 4} - {\theta \over 2}\right)\cos\phi \nonumber \\
  773. Y &=& 2\sin\left({\pi \over 4} - {\theta \over 2}\right)\sin\phi
  774. \end{eqnarray}
  775. for the North Pole. The transformation for the South
  776. Pole is similar. This transformation is only used to
  777. compute intersections; line integrals are still computed
  778. in latitude-longitude coordinates. Because intersections
  779. computed in the transformed coordinates can be different
  780. from those computed in latitude-longitude coordinates,
  781. line segments which cross the latitude threshold must be
  782. treated carefully. To compute the intersections
  783. consistently for such a segment, intersections with the
  784. threshold latitude are detected and used as a normal
  785. grid intersection to provide a clean break between the
  786. two coordinate systems.
  787. \section{Conclusion}
  788. The implementation in the SCRIP code follows closely
  789. the description above. The user should be able to
  790. follow and understand the process based on this
  791. description.
  792. \chapter{Bilinear Remapping}
  793. Standard bilinear interpolation schemes can be found
  794. in many textbooks. Here we present a more general
  795. scheme which uses a local bilinear approximation
  796. to interpolate to a point in a quadrilateral grid.
  797. Consider the grid points shown in Fig.~\ref{fig:quad}
  798. labelled with logically-rectangular indices (e.g. $(i,j)$).
  799. \begin{figure}
  800. \caption{A general quadrilateral grid. \label{fig:quad}}
  801. \begin{picture}(400,400)
  802. \put(40,40){\line(2,1){200}}
  803. \put(240,140){\line(1,2){100}}
  804. \put(40,40){\line(1,2){100}}
  805. \put(140,240){\line(2,1){200}}
  806. \put(40,40){\circle*{4}}
  807. \put(240,140){\circle*{4}}
  808. \put(140,240){\circle*{4}}
  809. \put(340,340){\circle*{4}}
  810. \put(210,200){\circle*{4}}
  811. \put(30 , 20){1 $(i,j)$}
  812. \put(250,130){2 $(i+1,j)$}
  813. \put( 80,240){$(i,j+1)$ 4}
  814. \put(350,340){3 $(i+1,j+1)$}
  815. \put(200,200){$P$}
  816. \end{picture}
  817. \end{figure}
  818. Let the latitude-longitude coordinates of point
  819. 1 be $(\theta(i,j),\phi(i,j))$, the coordinates of
  820. point 2 be $(\theta(i+1,j),\phi(i+1,j))$, etc.
  821. Now let $\alpha$ and $\beta$ be continuous local
  822. coordinates such that the coordinates $(\alpha,\beta)$
  823. of point 1 are $(0,0)$, point 2 are $(1,0)$, point
  824. 3 are $(1,1)$ and point 4 are $(0,1)$. If point $P$
  825. lies inside the cell formed by the four points above,
  826. the function $f$ at point $P$ can be approximated by
  827. \begin{eqnarray}\label{eq:bilinear}
  828. f_P & = & (1-\alpha)(1-\beta)f(i,j) + \alpha(1-\beta)f(i+1,j) + \nonumber \\
  829. & & \alpha\beta f(i+1,j+1) + (1-\alpha)\beta f(i,j+1) \\
  830. & = & w_1 f(i,j) + w_2 f(i+1,j) + w_3 f(i+1,j+1) + w_4 f(i,j+1). \nonumber
  831. \end{eqnarray}
  832. The remapping weights must therefore be computed by
  833. finding $\alpha$ and $\beta$ at point $P$.
  834. The latitude-longitude coordinates $(\theta,\phi)$ of
  835. point $P$ are known and can also be approximated by
  836. \begin{eqnarray}\label{eq:thetaphi}
  837. \theta & = & (1-\alpha)(1-\beta)\theta_1 + \alpha(1-\beta)\theta_2 + \nonumber
  838. \alpha\beta \theta_3 + (1-\alpha)\beta \theta_4 \\
  839. \phi & = & (1-\alpha)(1-\beta)\phi_1 + \alpha(1-\beta)\phi_2 +
  840. \alpha\beta \phi_3 + (1-\alpha)\beta \phi_4.
  841. \end{eqnarray}
  842. Because (\ref{eq:thetaphi}) is nonlinear in $\alpha$ and $\beta$,
  843. we must linearize and iterate toward a solution. Differentiating
  844. (\ref{eq:thetaphi}) results in
  845. \begin{equation}
  846. \left[\begin{array}{c} \delta\theta \\ \delta\phi \end{array}\right]
  847. = A
  848. \left[\begin{array}{c} \delta\alpha \\ \delta\beta \end{array}\right],
  849. \end{equation}
  850. where
  851. \begin{equation}
  852. A = \left[\begin{array}{cc}
  853. (\theta_2-\theta_1) + (\theta_1-\theta_4+\theta_3-\theta_2)\beta &
  854. (\theta_4-\theta_1) + (\theta_1-\theta_4+\theta_3-\theta_2)\alpha \\
  855. (\phi_2-\phi_1) + (\phi_1-\phi_4+\phi_3-\phi_2)\beta &
  856. (\phi_4-\phi_1) + (\phi_1-\phi_4+\phi_3-\phi_2)\alpha
  857. \end{array}\right].
  858. \end{equation}
  859. Inverting this system,
  860. \begin{equation}\label{eq:dalpha}
  861. \delta\alpha = \left|\begin{array}{cc}
  862. \delta\theta &
  863. (\theta_4-\theta_1) + (\theta_1-\theta_4+\theta_3-\theta_2)\alpha \\
  864. \delta\phi &
  865. (\phi_4-\phi_1) + (\phi_1-\phi_4+\phi_3-\phi_2)\alpha
  866. \end{array}\right| \div \det(A),
  867. \end{equation}
  868. and
  869. \begin{equation}\label{eq:dbeta}
  870. \delta\beta
  871. = \left|\begin{array}{cc}
  872. (\theta_2-\theta_1) + (\theta_1-\theta_4+\theta_3-\theta_2)\beta &
  873. \delta\theta \\
  874. (\phi_2-\phi_1) + (\phi_1-\phi_4+\phi_3-\phi_2)\beta &
  875. \delta\phi
  876. \end{array}\right| \div \det(A).
  877. \end{equation}
  878. Starting with an initial guess for $\alpha$ and $\beta$
  879. (say $\alpha=\beta=0$), equations~(\ref{eq:dalpha}) and
  880. (\ref{eq:dbeta}) can be iterated until
  881. $\delta\alpha$ and $\delta\beta$ are suitably small. The
  882. weights can then be computed from (\ref{eq:bilinear}). Note
  883. that for simple latitude-longitude grids, this iteration
  884. will converge in the first iteration.
  885. In order to compute the weights using this general bilinear
  886. iteration, it must be determined in which box the point $P$
  887. resides. For this, the search algorithms outlined in the
  888. previous chapter are used with the exception that instead
  889. of using cell corners, the relevant box is formed by
  890. neighbor cell centers as shown in Fig.~\ref{fig:quad}.
  891. \chapter{Bicubic Remapping}
  892. The bicubic remapping exactly follows the bilinear remapping
  893. except that four weights for each corner point are required.
  894. Thus, num\_wts is set to four for this option.
  895. The bicubic remapping is
  896. \begin{eqnarray}\label{eq:bicubic}
  897. f_P & = &
  898. (1 - \beta^2(3-2\beta))(1 - \alpha^2(3-2\alpha))f(i ,j ) + \nonumber \\
  899. & & (1 - \beta^2(3-2\beta)) \alpha^2(3-2\alpha) f(i+1,j ) + \nonumber \\
  900. & & \beta^2(3-2\beta) \alpha^2(3-2\alpha) f(i+1,j+1) + \nonumber \\
  901. & & \beta^2(3-2\beta) (1 - \alpha^2(3-2\alpha))f(i ,j+1) + \nonumber \\
  902. & & (1 - \beta^2(3-2\beta))\alpha (\alpha-1)^2
  903. {{\partial f}\over{\partial i}}(i ,j ) + \nonumber \\
  904. & & (1 - \beta^2(3-2\beta))\alpha^2(\alpha-1)
  905. {{\partial f}\over{\partial i}}(i+1,j ) + \nonumber \\
  906. & & \beta^2(3-2\beta) \alpha^2(\alpha-1)
  907. {{\partial f}\over{\partial i}}(i+1,j+1) + \nonumber \\
  908. & & \beta^2(3-2\beta) \alpha (\alpha-1)^2
  909. {{\partial f}\over{\partial i}}(i ,j+1) + \nonumber \\
  910. & & \beta (\beta-1)^2(1 - \alpha^2(3-2\alpha))
  911. {{\partial f}\over{\partial j}}(i ,j ) + \nonumber \\
  912. & & \beta (\beta-1)^2 \alpha^2(3-2\alpha)
  913. {{\partial f}\over{\partial j}}(i+1,j ) + \nonumber \\
  914. & & \beta^2(\beta-1) \alpha^2(3-2\alpha)
  915. {{\partial f}\over{\partial j}}(i+1,j+1) + \nonumber \\
  916. & & \beta^2(\beta-1) (1 - \alpha^2(3-2\alpha))
  917. {{\partial f}\over{\partial j}}(i ,j+1) + \nonumber \\
  918. & & \alpha (\alpha-1)^2\beta (\beta-1)^2
  919. {{\partial^2 f}\over{\partial i \partial j}}(i ,j ) + \nonumber \\
  920. & & \alpha^2(\alpha-1) \beta (\beta-1)^2
  921. {{\partial^2 f}\over{\partial i \partial j}}(i+1,j ) + \nonumber \\
  922. & & \alpha^2(\alpha-1) \beta^2(\beta-1)
  923. {{\partial^2 f}\over{\partial i \partial j}}(i+1,j+1) + \nonumber \\
  924. & & \alpha (\alpha-1)^2\beta^2(\beta-1)
  925. {{\partial^2 f}\over{\partial i \partial j}}(i ,j+1)
  926. \end{eqnarray}
  927. where $\alpha$ and $\beta$ are identical to those found in
  928. the bilinear case and are found using an identical algorithm.
  929. Note that unlike the conservative remappings, the gradients
  930. here are gradients with respect to the {\em logical} variable
  931. and not latitude or longitude. Lastly, the four weights
  932. corresponding to each address pair correspond to the
  933. weight multiplying the field value at the point, the weight
  934. multiplying the gradient with respect to $i$, the weight
  935. multiplying the gradient with respect to $j$, and the weight
  936. multiplying the cross gradient in that order.
  937. \chapter{Distance-weighted Average Remapping}
  938. This scheme for remapping is probably the simplest
  939. in this package. The code simply searches for the
  940. num\_neighbors nearest neighbors and computes the
  941. weights using
  942. \begin{equation}\label{eq:distwgt}
  943. w = {{1/(d+\epsilon)} \over
  944. {\sum_n^{\rm num\_neighbors} [1/(d_n+\epsilon)]}},
  945. \end{equation}
  946. where $\epsilon$ is a small number to prevent
  947. dividing by zero, the sum is for normalization and
  948. $d$ is the distance from the destination grid point
  949. to the source grid point. The distance is the angular
  950. distance
  951. \begin{equation}\label{eq:distance}
  952. d = \cos^{-1}\left(\cos\theta_d\cos\theta_s
  953. (\cos\phi_d\cos\phi_s + \sin\phi_d\sin\phi_s) +
  954. \sin\theta_d\sin\theta_s\right),
  955. \end{equation}
  956. where $\theta$ is latitude, $\phi$ is longitude and the
  957. subscripts $d,s$ denote destination and source grids,
  958. respectively.
  959. When finding nearest neighbors, the distance is not
  960. computed between the destination grid point and every
  961. source grid point. Instead, the search is narrowed by
  962. sorting the two grids into latitude bins. Only those
  963. source grid cells lying in the same latitude bin as
  964. the destination grid cell are checked to find the
  965. nearest neighbors.
  966. \chapter{Bugs}
  967. A file called `bugs' is included in the distribution
  968. which lists current outstanding bugs as well as a
  969. version history. Any further bugs, comments, or suggestions
  970. should be sent to me at pwjones@lanl.gov.
  971. The code does not have very useful error messages to
  972. help diagnose problems so feel free to pester me with
  973. any problems you encounter.
  974. The package has also not been extensively tested on
  975. a variety of machines. It works fine on SGI machines
  976. and IBM machines, but has not been run on other machines.
  977. It is pretty vanilla Fortran, so should be ok on
  978. machines with standard-compliant F90 compilers.
  979. \end{document}