Last modified: Mon, 07/10/2017 - 12:35
Since binary and ASCII files are found in a bewildering variety of non-standardized formats a few tricks may help with reading difficult cases.
- Sometimes variables are interleaved with data axes in unstructured (stream) binary files. A simple trick is to read them all as a single variable, say, "Vall," in which the sequence of variables in the file V1, V2, V3, ... is regarded as an axis of the grid. Then extract the variables by defining V1 = Vall[I=1] (if the I axis was used, else J=1, K=1, or L=1) as needed.
- In some ASCII files the variables are presented as blocks—a full grid of variable 1, then a full grid of variable 2, etc. These files may be read using Unix soft links so that the same file can be opened as several Ferret data sets. Then use the FILE command to point separately to each soft link using the /SKIP qualifier to locate the correct starting point in the file for each variable. For example,
Unix commands:
ln -s my_data my_dat.v1 ln -s my_data my_dat.v2 ln -s my_data my_dat.v3
Ferret commands:
yes? FILE/SKIP=0/VAR=v1 my_dat.v1 yes? FILE/SKIP=100/VAR=v2 my_dat.v2 yes? FILE/SKIP=200/VAR=v3 my_dat.v3
- If an ASCII file contains a repeating sequence of records try describing the entire sequence using a single FORTRAN FORMAT statement. An example of such a statement would be (3F8.4,2(/5F6.2)). The slash character and the nested parentheses allow multi-record groups to appear as a single format. Note that the /COLUMNS qualifier should reflect the total number of columns in the repeating group of records.
- If an ASCII or binary file contains gridded data in which the order of axes is not X-Y-Z-T read the data in (which results in the wrong axis ordering) and use the LIST/ORDER= to permute the order on output. The resulting file will have the desired axis ordering.
- If the times and geographical coordinate locations of the grid are inter-mixed with the dependent variables in the file then 1) issue a FILE command to read the coordinates only; 2) use DEFINE AXIS/FROM_DATA to define axes and DEFINE GRID to define the grid; 3) use FILE/GRID=mygrid to read the file again.