- ARL Home
- > ARL FAQs
- > When I use cxy2ll, are the lat/lons associated with the center of the grid box, the lower-left corner, or some other location?
I have been working with the C version of your emapf library and it has been of great use. I would like to clarify a question about the conversion of grid points to lat/lon and vice versa (in cxy2ll and cll2xy). When I use cxy2ll, are the lat/lons associated with the center of the grid box, the lower-left corner, or some other location?
The cxy2ll and cll2xy routines associate a pair of grid indices (x,y or i,j values) with each lat-lon pair, according to specifications you provide through stclmbr and either stcm1p or stcm2p. Typically, the data used would come form published information on various grids in use, such as NCEP.
It is important to note that the functions do not deal directly with gridded data, but are a tool to help you work with gridded data. Accordingly, the library functions have no way of knowing where the boundaries of the grid are. That information is only known to the designers of the grid and to the user of the library. Thus, as far as cll2xy is concerned, point (1,1) or point (0,0) or point (-1,-3) are points of the grid as valid as point (33,33).
Most published grids, such as the 4225 point NGEP grid 27, were laid down by FORTRAN programmers. In the 1950's, when numerical weather prediction was becoming operational, FORTRAN was basically the only computer language for physicists and engineers. Since FORTRAN arrays, by default, begin at index 1, these arrays will generally assume the lower left corner is at (1,1). Since NCEP 27 is a "65x65" grid, that puts the upper right corner at (65,65). Most other grids similarly have the lower left corners arbitrarily defined as (1,1).
If FORTRAN had been like C, whose array indices begin at 0, the lower left corner would most likely have been at (0,0). And if a mathematician had had the tools of FORTRAN 90, with user-definable array limits, the North Pole might have been set at (0,0) instead of (33,33), and the lower left and upper right corners at (-32,-32) and (32,32) respectively.
In short, the libraries do not know the bounds of the grid, and are not "relative" to any particular point on the boundary of the grid.
If you, as a C programmer, are working with gridded data in arrays defined with C-like 0-based indices, with data provided by standard 1-based (FORTRAN indices, you need to either do index-shifting in your program, or accept an unused line on two edges of your arrays.
Albion D. Taylor