[gradsusr] Convert text data to Binary using GrADS script
Bradley NAVARRO
brad.navarro at wni.com
Thu Sep 24 12:20:57 EDT 2020
Hi all,
I know GrADS has the ability to convert regular numerical text to binary, which is ideal because while I can do it with Fortran, I’d prefer to be able to do everything in GrADS in one script. Before I get to the issue, here are the ‘q config’ data:
Built Fri Nov 9 13:38:49 MST 2012 for i686-pc-linux-gnu
This version of GrADS has been configured with the following options:
o Built on a LITTLE ENDIAN machine
o Athena Widget GUI DISABLED
o Command line editing ENABLED
http://tiswww.case.edu/php/chet/readline/rltop.html
o printim command for image output ENABLED
http://www.zlib.net
http://www.libpng.org/pub/png/libpng.html
http://www.libgd.org/Main_Page
o GRIB2 interface ENABLED
http://www.ijg.org
http://www.ece.uvic.ca/~mdadams/jasper
http://www.nco.ncep.noaa.gov/pmb/codes/GRIB2
g2clib-1.4.0
o NetCDF interface ENABLED
http://www.unidata.ucar.edu/software/netcdf
netcdf 4.1.2 of Oct 6 2011 13:44:26 $
o OPeNDAP gridded data interface ENABLED
o OPeNDAP station data interface ENABLED
http://iges.org/grads/gadoc/supplibs.html
libgadap 2.0
o HDF4 and HDF5 interfaces ENABLED
http://hdfgroup.org
HDF 4.2r3
HDF5 1.8.7
o GeoTIFF and KML/TIFF output ENABLED
http://www.libtiff.org
http://geotiff.osgeo.org
o KML contour output ENABLED
o Shapefile interface ENABLED
http://shapelib.maptools.org
Ok, so now on to the issue. Basically, I have some output written to a file called result.txt where each row is a latitude and each column is a longitude. Thus the file is 181 latitude x 360 longitude. It starts at -90 and ends at 90, 0 to 359 degrees longitude. I have 21 time steps so a total of 3801 lines (181 * 21 = 3801). I use a simple script using fwrite to take each line and convert to binary. Below is the basic script (I have left out the dummy.ctl file for clarity):
file='result.txt'
'set gxout fwrite'
'set fwrite result.bin'
res=read(file)
rc=sublin(res,1)
while(rc=0)
line=sublin(res,2)
'd 'line
res=read(file)
rc=sublin(res,1)
endwhile
'disable fwrite'
When I run the above script, it seems to run fine. I get a file called result.bin with 15204 bytes. I then run the control file to try to plot the newly converted binary data:
dset ^result.bin
undef 9.999E+20
title analog damage areas
ydef 181 linear -90 1
xdef 360 linear 0 1
tdef 21 linear 06Z23SEP2020 6hr
zdef 1 linear 1 1
vars 1
damage 0,0 0,0,0 ** areas where damage detected
ENDVARS
I then get the following error:
ga-> set t 1
Time values set: 2020:9:23:6 2020:9:23:6
ga-> d damage
Low Level I/O Error: Read error on data file
Data file name = result.bin
Error reading 1440 bytes at location 14400
Data Request Error: Error for variable 'damage'
Error ocurred at column 1
DISPLAY error: Invalid expression
Expression = damage
I can confirm that the original result.txt file contains 181 x 360 data points for 21 time steps. But the byte size of the binary file seems to be smaller than I would expect, maybe? I’ve tried much from the archives to try to figure this issue out but perhaps my understanding is lacking and I am now out of ideas. And just for reference, I can run result.txt through a Fortran script to convert to binary and the resulting file plots perfectly fine with the control file above. But like I said, it seems like I should be able to do the conversion in GrADS. Any help on this issue would be greatly appreciated.
Thanks,
Brad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gradsusr.org/pipermail/gradsusr/attachments/20200924/e6f04745/attachment-0001.html>
More information about the gradsusr
mailing list