Local forecast by
"City, St" |
|
| |
| |
| |
| |
| |
| |
| |
|
Degrib: FORTRAN or C access to .flt files
For FORTRAN programmers trying to access the .flt file, I'd recommend:
To read the grid value at X,Y into VALUE
- NX=1073
- OPEN (10, FILE="name.flt", ACCESS='DIRECT', RECL=4)
- RECNUM=X+Y*NX
- READ (10, REC=RECNUM) VALUE
- CLOSE (10)
For C programmers trying to access the .flt file, I'd recommend:
To read the grid value at X,Y into VALUE
- FILE *fp
- int NX = 1073;
- float VALUE;
- if ((fp = fopen ("name.flt", "rb")) == NULL) {
- printf ("Couldn't open 'name.flt");
- return -1;
- }
- recNum = X + Y * NX;
- fseek (fp, recNum * 4, SEEK_SET);
- fread (&VALUE, sizeof (float), 1, fp);
- fclose (fp);
The first problem is knowing what NX should be. NX is the width of the
grid. For CONUS NDFD it is 1073, but for other grids, you would want to look
in the meta ".txt" file (click here for how to
get it), and then look for the line that says: "GDS | Nx (Number of
points on parallel) | 1073" and use that value.
The next problem is knowing that 'VALUE' is filled correctly. By default
degrib has "-MSB" on. That means the bytes in the .flt file are in "Most
Significant Byte first", which is fine if you are on a "Big endian" (or
typically unix) machine. Instead, if you are on a PC or a Linux machine, you
are on a "Little endian" machine. In this case you want to use the "-nMSB"
option to have degrib create the .flt files in "Least Significant Byte first".
Next you need to think about the orientation of the grid. ".flt" files
start in the upper left, go across and then start again on the left of the
next row down. If you use "-revFlt" then it will generate ".tlf" files that
start in the lower left, go across and then start again on the left of the next
row up.
For more on "-MSB" and "-revFlt", see the
degrib man page, under
CONVERT OPTIONS, and FLT SPECIFIC OPTIONS.
Now that you know how to get a 'VALUE', given a grid X, Y, you need to
figure out how to go from grid X, Y to lat, lon and vice versa. To do that,
you need to know about the map projection, and have map projection software.
See CMAPF for a
good FORTRAN and C map projection library. Note: I have already
provided a copy of the C code in "/degrib/src/emapf-c". To get the parameters
needed by CMAPF or other map projection libraries, you need to again look
in the meta ".txt" file (click here for how to
get it), particularly the GDS section.
|