packing data in binary format for GrADS
Diane Stokes
Diane.Stokes at NOAA.GOV
Mon Dec 12 10:07:26 EST 2005
Hi, Dan.
I didn't go through your msg carefully to catch everything, but for
starters, it doesn't look like you are following the required format
described at:
http://grads.iges.org/grads/gadoc/aboutstationdata.html#station
The station id should be the first word in your header and should be
written out as type character with length 8. nlev and nflag should be
written as integer, not float.
Diane
Dan Leins wrote:
> List,
>
> I'm working on a project that involves parsing through a page of text,
> stripping out the data I want, and writing it to a binary file.
> Ultimately I would like to take the data in the binary file and plot it
> as station data in GrADS, but I've come across a problem when I try to
> write my data out as binary.
>
> I'm decoding RR2 SHEF encoded snowfall data, stripping out the LAT/LON
> of the station of interest, 6/12/24hr snowfall totals (if available,
> using -999.0 to fill in missing data), and snow depth (again, -999.0 if
> missing).
>
>
> .A CLE141 1126 Z DH0000/DVH12/SFV 1.5"LAT=41.86 LON=-80.8 ASHTABULA 3S"/
> .A CLE130 1126 Z DH0000/DVH12/SFV 1.5"LAT=41.58 LON=-81.2 CHARDON"/
> .A CLE221 1126 Z DH0000/DVH12/SFV 1.4"LAT= 41.16 LON=-81.21 RAVENNA 1E"/
> .A CLE032 1126 Z DH0000/DVH12/SFV 5.0"LAT=41.83 LON=-80.09 CAMBRIDGE
> SPRINGS"/
> .A CLE020 1126 Z DH0000/DVH12/SFV 3.2"LAT=41.93 LON=-80.3 FRANKLIN CTR"/
> .A CLE023 1126 Z DH0000/DVH12/SFV 0.8"LAT=41.92 LON=-79.64 CORRY"/
> .A CLE032 1126 Z DH0230/DVH24/SFV 3.0"LAT=41.81 LON=-80.07 CAMBRIDGE
> SPGS"/
> .A CLE020 1126 Z DH0000/DVH6/SFV 16.0"LAT=41.93 LON=-80.3 FRANKLIN CTR"/
> .A CLE141 1126 Z DH0000/SD/ 5.0"LAT=41.86 LON=-80.8 ASHTABULA 3S"/
> .A CLE130 1126 Z DH0000/SD/ 10.0"LAT=41.58 LON=-81.2 CHARDON"/
> .A CLE221 1126 Z DH0230/SD/ 6.0"LAT=41.34 LON=-81.2 HIRAM RAPIDS"/
> .A CLE221 1126 Z DH0000/SD/ 6.0"LAT=41.16 LON=-81.21 RAVENNA 1E"/
> .A CLE032 1126 Z DH0000/SD/ 15.0"LAT=41.83 LON=-80.09 CAMBRIDGE SPRINGS"/
> .A CLE032 1126 Z DH0230/SD/ 7.0"LAT=41.81 LON=-80.07 CAMBRIDGE SPGS"/
> .A CLE023 1126 Z DH0000/SD/ 17.0"LAT=41.92 LON=-79.64 CORRY"/
> .A CLE020 1126 Z DH0000/SD/ 12.0"LAT=41.93 LON=-80.3 FRANKLIN CTR"/
>
> Using the logic from an existing script...I start w/
>
> #!/usr/local/perl/bin/perl
> open BINFILE, ">snowfall.bin";
>
> open (RR2, "<rr2.txt");
> while (<RR2>){
>
> #6 hr snow depth search
> if (/DVH6\S{4}\s(\d+.\d+)"LAT=(\d{2}.\d+)\sLON=(-\d{2}.\d+)\s/){
> $sf_6 = $1;
> $latitude="$2";
> $longitude="$3";
> $sf_12= "-999.0";
> $sf_24= "-999.0";
> $sd= "-999.0";
> print "6hr: $sf_6 12hr: $sf_12 24hr: $sf_24 SD: $sd LAT: $latitude LON:
> $longitude\n";
> $nLev=1;
> $nFlag=1;
> $timeInc=0.;
> $buffer = pack 'f f f f f f f f f', $latitude, $longitude, $timeInc,
> $nLev, $nFlag, $sf_6, $sf_12, $sf_24, $sd;
> print BINFILE $buffer;
> }
>
> I do the same thing for the other variables too, 12hr, 24hr, and snow
> depth. I didn't bother to include them here, they look the same except
> for the - 999.0 values which vary.
>
> At the end of my script, I end w/
>
>
> $nLev=0;
> $nFlag=0;
> $buffer = "pack 'f f f f f', $latitude, $longitude, $timeInc, $nLev,
> $nFlag";
> print $buffer;
>
> exit;
>
> Again, following suit with what I've seen before. I get a snowfall.bin
> file w/out a problem, but when I go to run `stnmap -i snowfall.ctl`...I
> get the following error...
>
> Name of binary data set: snowfall.bin
> Number of times in the data set: 1
> Number of surface variables: 4
> Number of level dependent variables: 0
>
> Starting scan of station data binary file.
> Binary data file open: snowfall.bin
> Processing time = 1
> Invalid station hdr found in station binary file
> Possible causes: Invalid level count in hdr
> Descriptor file mismatch
> File not station data
> Invalid relative time
> levs = -998653952 flag = 1069547520 time = 1
>
> My snowfall.ctl file is pretty straightforward, I'm pretty confident I
> don't have any errors in there, just 4 variables (6hr,12hr,24hr,sd) and
> the DTYPE set to station. While the error is semi-cryptic, I can infer
> that something's not right with how the data is being written to the
> binary file. Like I said, this is more of a problem of getting data
> into a "grads-readable" format instead of actually using GrADS, but
> maybe someone has used station data enough to have come across this
> error. Does anyone have any insight as to how I can go about fixing it?
> Any help would be appreciated!
>
> Thanks!
>
> Dan Leins
>
--
Diane Stokes
Environmental Modeling Center
National Weather Service/NOAA
More information about the gradsusr
mailing list