[gradsusr] Using station data in Grads

Charles Langton Vanya dolesibeni at gmail.com
Sat Jan 17 13:07:27 EST 2015


Dear all,

I need your help, I am struggling to plot my station data using Grads. From
my google searching, I found different ways of doing it but I am failing to
write mt descriptor so that it can be able to read my data.


I want to make my station data to be able read by grads, so using the C
script and descriptor below:


#include <stdio.h>

/* Structure that describes a report header in a stn file */

struct rpthdr {

char id[8]; /* Station ID */

float lat; /* Latitude of Station */

float lon; /* Longitude of Station */

float t; /* Time in grid-relative units */

int nlev; /* Number of levels following */

int flag; /* Level independent var set flag */

} hdr;

main ()

{

FILE *ifile, *ofile;

char rec[80];

int flag,year,month,yrsav,mnsav,i;

float val;

/* Open files */

ifile = fopen ("rainfall.txt","r");

ofile = fopen ("rainfall.dat","wb");

if (ifile==NULL || ofile==NULL) {

printf("Error opening files\n");

return;

}

/* Read, write loop */

flag = 1;

while (fgets(rec,79,ifile)!=NULL) {

/* Format conversion */

sscanf (rec,"%i %i",&year,&month);

sscanf (rec+20," %g %g %g",&hdr.lat,&hdr.lon,&val);

for (i=0; i<8; i++) hdr.id[i] = rec[i+11];

/* Time group terminator if needed */

if (flag) {

yrsav = year;

mnsav = month;

flag = 0;

}

if (yrsav!=year || mnsav!=month) {

hdr.nlev = 0;

fwrite(&hdr,sizeof(struct rpthdr), 1, ofile);

}

yrsav = year;

mnsav = month;

/* Write this report */

hdr.nlev = 1;

hdr.flag = 1;

hdr.t = 0.0;

fwrite (&hdr,sizeof(struct rpthdr), 1, ofile);

fwrite (&val,sizeof(float), 1, ofile);

}

hdr.nlev = 0;

fwrite (&hdr,sizeof(struct rpthdr), 1, ofile);

}



*Descriptor file*

dset ^rainfall.dat

dtype station

stnmap rainfall.map

undef -999.0

title Rainfall data at some test stations

tdef 1 linear 1JAN1990 1dy

vars 8

prcp1 0 99 1990OND

prcp2 0 99 1990JFM

prcp3 0 99 2000OND

prcp4 0 99 2000JFM

prcp5 0 99 2010OND

prcp6 0 99 2010JFM

prcp7 0 99 ONDLTM

prcp8 0 99 JFMLTM

endvars


, I did what is below:


C:\Users\hq\Desktop\DATA>tcc stationgrid.c -o stationgrid.exe

C:\Users\hq\Desktop\DATA>stationgrid

Error opening files

C:\Users\hq\Desktop\DATA>tcc stationgrid.c -o stationgrid.exe

C:\Users\hq\Desktop\DATA>stationgrid



ga-> open stationgrid.ctl

Scanning description file:  stationgrid.ctl

Open Error:  Can't open Station/Index map file station_data_sample.map

  The data file was not opened.

ga-> exit

Unknown command: exit

ga-> quit

No hardcopy metafile open

GX package terminated

C:\Users\hq\Desktop\DATA>stnmap -i stationgrid.ctl

  Name of binary data set: rain.dat

  Number of times in the data set: 10

  Number of surface variables: 6

  Number of level dependent variables: 5

Starting scan of station data binary file.

Binary data file open: rain.dat

Processing time step 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 = 1123457434  flag = 0  time = 5

C:\Users\hq\Desktop\DATA>stnmap -i stationgrid.ctl

  Name of binary data set: rain.dat

  Number of times in the data set: 1

  Number of surface variables: 1

  Number of level dependent variables: 0

Starting scan of station data binary file.

Binary data file open: rain.dat

Processing time step 1

     Time = 1 has stn count = 1

  Max reports per time:  1 reports at t = 1

  Max data elements in largest report: 1

Version 2 Station map file created: rain.map

stnmap: WARNING!!  This stnmap file can only be accessed by GrADS Version
2.0.1.oga.1

stnmap: WARNING!!  However, GrADS Version 2.0.1.oga.1 can read both versions

stnmap: COMMENT  -- use the -1 command line option to create a map for
older GrADS versions

C:\Users\hq\Desktop\DATA>grads

Starting X server under C:\PROGRA~1\OPENGR~1\Contents\Resources\Xming

Starting grads under
C:\PROGRA~1\OPENGR~1\Contents\Cygwin\Versions\201OGA~1.1\i686 ...

Grid Analysis and Display System (GrADS) Version 2.0.1.oga.1

Copyright (c) 1988-2011 by Brian Doty and the

Institute for Global Environment and Society (IGES)

GrADS comes with ABSOLUTELY NO WARRANTY

See file COPYRIGHT for more information

Config: v2.0.1.oga.1 little-endian readline printim grib2 netcdf hdf4-sds
hdf5 opendap-grids,stn athena geotiff shapefile

Issue 'q config' command for more detailed configuration information

Loading User Defined Extensions table
</cygdrive/c/PROGRA~1/OPENGR~1/Contents/Cygwin/Versions/201OGA~1.1/i686/gex/udxt>
... ok.

Landscape mode? ('n' for portrait):

GX Package Initialization: Size = 11 8.5

ga-> open stationgrid.ctl

Scanning description file:  stationgrid.ctl

Data file rain.dat is open as file 1

LON set to 0 360

LAT set to -90 90

LEV set to 500 500

Time values set: 1980:1:1:12 1980:1:1:12

E set to 1 1

ga-> q file

File 1 : Station Data Sample

  Descriptor: stationgrid.ctl

  Binary: rain.dat

  Type = Station Data

  Tsize = 1

  Number of Variables = 1

     prcp  0  99  Rainfall

ga-> d prcp

ga-> set gxout shaded

ga-> d prcp

ga-> set display color white

ga-> c

ga-> d prcp

ga-> set lat 22 45

LAT set to 22 45

ga-> set lon -86 -81

LON set to -86 -81

ga-> d prcp

ga-> c

ga-> d prcp

ga-> set lon -86 -81

XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server
"localhost:7.0"

      after 473 requests (473 known processed) with 11 events remaining.





C:\Users\hq\Desktop\DATA>tcc stationgrid.c -o normal_rain.exe

C:\Users\hq\Desktop\DATA>normal_rain

C:\Users\hq\Desktop\DATA>stnmap -i normal.ctl

  Name of binary data set: normal_data.dat

  Number of times in the data set: 1

  Number of surface variables: 8

  Number of level dependent variables: 0

Starting scan of station data binary file.

Error opening station data binary file

 File name is: normal_data.dat

C:\Users\hq\Desktop\DATA>stnmap -i normal_rain.ctl

Open Error:  Invalid variable record

  --> The invalid description file record is:

  --> vars 8

  The data file was not opened.

File name is:  normal_rain.ctl



C:\Users\hq\Desktop\DATA>stnmap -i normal_rain.ctl

  Name of binary data set: normal_rain.dat

  Number of times in the data set: 1

  Number of surface variables: 8

  Number of level dependent variables: 0

Starting scan of station data binary file.

Binary data file open: normal_rain.dat

Processing time step 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 = 0  flag = 0  time = 626.5



C:\Users\hq\Desktop\DATA>stnmap -i normal.ctl

  Name of binary data set: normal_data.dat

  Number of times in the data set: 1

  Number of surface variables: 8

  Number of level dependent variables: 0

Starting scan of station data binary file.

Error opening station data binary file

 File name is: normal_data.dat



C:\Users\hq\Desktop\DATA>tcc stationgrid.c -o normal_rain.exe

C:\Users\hq\Desktop\DATA>normal_rain

C:\Users\hq\Desktop\DATA>stnmap -i normal.ctl

Open Error:  Invalid variable record

  --> The invalid description file record is:

  --> 90OND 0 99 1990OND

  The data file was not opened.

File name is:  normal.ctl



C:\Users\hq\Desktop\DATA>stnmap -i normal.ctl

" instead.:  Looking for "endvars", found "jfme 0 99 1990jfm

  --> The invalid description file record is:

  --> jfme 0 99 1990JFM

  The data file was not opened.

File name is:  normal.ctl



C:\Users\hq\Desktop\DATA>stnmap -i normal.ctl

" instead.:  Looking for "endvars", found "jfme 0 99 1990jfm

  --> The invalid description file record is:

  --> jfme 0 99 1990JFM

  The data file was not opened.

File name is:  normal.ctl



C:\Users\hq\Desktop\DATA>stnmap -i normal.ctl

  Name of binary data set: normal_data.dat

  Number of times in the data set: 1

  Number of surface variables: 8

  Number of level dependent variables: 0

Starting scan of station data binary file.

Error opening station data binary file

 File name is: normal_data.dat





C:\Users\hq\Desktop\DATA>tcc stationgrid.c -o rainfall.exe

C:\Users\hq\Desktop\DATA>rainfall

C:\Users\hq\Desktop\DATA>stnmap -i normal_rain.ctl

  Name of binary data set: rainfall.dat

  Number of times in the data set: 1

  Number of surface variables: 1

  Number of level dependent variables: 0

Starting scan of station data binary file.

Binary data file open: rainfall.dat



Processing time step 1

     Time = 1 has stn count = 41

  Max reports per time:  41 reports at t = 1

  Max data elements in largest report: 1

Version 2 Station map file created: rainfall.map

stnmap: WARNING!!  This stnmap file can only be accessed by GrADS Version
2.0.1.oga.1

stnmap: WARNING!!  However, GrADS Version 2.0.1.oga.1 can read both versions

stnmap: COMMENT  -- use the -1 command line option to create a map for
older GrADS versions



C:\Users\hq\Desktop\DATA>grads

Starting X server under C:\PROGRA~1\OPENGR~1\Contents\Resources\Xming

Starting grads under
C:\PROGRA~1\OPENGR~1\Contents\Cygwin\Versions\201OGA~1.1\i686 ...

Grid Analysis and Display System (GrADS) Version 2.0.1.oga.1

Copyright (c) 1988-2011 by Brian Doty and the

Institute for Global Environment and Society (IGES)

GrADS comes with ABSOLUTELY NO WARRANTY

See file COPYRIGHT for more information

Config: v2.0.1.oga.1 little-endian readline printim grib2 netcdf hdf4-sds
hdf5 opendap-grids,stn athena geotiff shapefile

Issue 'q config' command for more detailed configuration information

Loading User Defined Extensions table
</cygdrive/c/PROGRA~1/OPENGR~1/Contents/Cygwin/Versions/201OGA~1.1/i686/gex/udxt>
... ok.

Landscape mode? ('n' for portrait):

GX Package Initialization: Size = 11 8.5

ga-> open normal_rain.ctl

Scanning description file:  normal_rain.ctl

Data file rainfall.dat is open as file 1

LON set to 0 360

LAT set to -90 90

LEV set to 500 500

Time values set: 1990:1:1:12 1990:1:1:12

E set to 1 1

ga-> q file

File 1 : Station Data Sample

  Descriptor: normal_rain.ctl

  Binary: rainfall.dat

  Type = Station Data

  Tsize = 1

  Number of Variables = 1

     prcp  0  99  rainfall(mm)

ga-> d prcp

ga-> set lat -18 -8

LAT set to -18 -8

ga-> set lon 32 36

LON set to 32 36

ga-> d prcp

ga-> set display color white

ga-> c

ga-> set display color white

ga-> d prcp

ga->

My normal_rain.ch file looks like this

Station

LAT

LON

1990OND

1990JFM

2000OND

2000JFM

2010OND

2010JFM

ONDLTM

JFMLTM

CHIT_OND

-9.7

33.27

304.6373333

626.5

264.1232

620

274.8033333

617.3

286.9777358

613.9

KAR_OND

-9.88

33.95

256.05

619.7

218.7833333

585.5

212.3366667

568.1

228.4471698

608.2

BOL_OND

-11.02

33.78

201.6040385

448.4

175.7366667

400.8

170.2733333

402.6

177.0060595

442.7

MZIM_OND

-11.9

33.6

260.9166667

575

243.8866667

588.7

238.91

562.7

240.9132075

568.6

MZUZ_OND

-11.47

34.03

326.5966667

610.5

287.3566667

590

302.4466667

589.4

294.6339623

604

NKB_OND

-11.6

34.3

364.6926667

798.8

319.016

777.1

274.5733333

741.7

321.8996226

780.3

KU_OND

-13.02

33.47

230.3266667

508.9

219.8766667

516.4

230.8366667

519.1

221.5716981

513.9

CHITE_OND

-13.97

33.63

291.7733333

552.1

269.5766667

576.1

260.97

577.5

272.154717

558.2

DEDZ_OND

-14.32

34.25

277.2433333

567.9

267.4566667

584.3

258.9566667

630

271.6886792

587.3

KK_OND

-12.92

34.28

368.9566667

984.7

339.4933333

968.2

303.3766667

921.4

344.2698113

956.1

SAL_OND

-13.75

34.58

296.3266667

863.7

257.5933333

881.5

277.9933333

852.8

284.2660377

851.1

MGH_OND

-14.47

35.25

249.5333333

540.9

230.5833333

536.6

236.6633333

515.4

243.6981132

528.2

M-BAY_OND

-14.08

34.92

240.5373333

573.7

229.1890667

621.4

229.16

650.6

227.8041509

608.8

MAKO_OND

-15.53

35.18

324.7918

628.1

309.71

640.8

305.5966667

641.2

307.5708302

624.1

CHILE_OND

-15.67

34.97

301.1666667

530

296.6333333

557.9

285.4733333

544.3

288.6509434

529.9

CHIC_OND

-15.78

35.05

351.7066667

655.9

343.0266667

682

352.5466667

675.3

348.9264151

666.4

BVU_OND

-15.92

35.07

341.1833333

640.2

329.0766667

682

341.1109366

659.2

331.6778886

656.4

THY_OND

-16.13

35.13

380.9283333

651.3

357.38

706.5

372.4433333

713

369.8971698

690.8

MIMO_OND

-16.07

35.62

483.34

800.1

460.0966667

816.9

438.7233333

818.6

451.2754717

815.3

NGAB_OND

-16.5

34.95

250.61

438.2

255.57

474.6

269.9733333

466.5

253.7867925

446.1

MAKH_

-16.52

35.15

246.11

398.5

217.2533333

451.8

125.4333333

467.8

36.85471698

435.6

MCHIN_OND

-13.82

32.87

338.6833333

649.9

331.3333333

647

328.67

646.2

338.0811321

641.5

DOWA_OND

-13.65

33.93

255.4966667

609.4

234.88

619.7

227.2666667

606.2

239.0301887

592.7

CHINGA_OND

-15.37

35.25

289.1733333

591.7

276.48

582.3

252.3466667

593.9

273.0830189

580.2

LUJER_OND

-16.03

35.65

650.1933333

1115.9

633.0166667

1111.9

608.7866667

1073.9

622.4679245

1121.3

MWANZ_OND

-15.62

34.52

344.84

593.1

318.52

627.8

302.6766667

614.8

314.4735849

608.1

CK_OND

-16.03

34.78

250.8024

446.9

246.4866667

473.3

221.3933333

492.8

234.033434

478.9

ZA_OND

-14.98

35.24

405.0766667

748.2

352.79

718.3

342.28

744.6

368.6622642

731.8

CHANCO_OND

-15.38

35.35

424.7666667

879.9

396.6833333

882

370.5633333

799.7

399.3245283

829.2

NTCH_OND

-13.35

33.92

322.2988

686.6

314.2464

673.7

314.9633333

692.2

309.8993208

676.4

MOMBEZ_OND

-15.73

35.12

338.94

585.9

312.0566667

600.8

294.9566667

572.9

314.4773585

573.4

CHINTHE_OND

-11.83

34.17

483.5433333

1019.4

370.6033333

883.4

330.1933333

860.1

404.4584906

944.9

NENO_OND

-15.4

34.65

361.68

681.4

314.0033333

708.7

332.4066667

729.4

344.6754717

693.2

NATHEN_OND

-14.08

33.92

269.0866667

553.7

249.88

562.4

253.7333333

593.6

258.5811321

574.4

NTCHIS_OND

-13.4

33.98

376.2766667

855.3

339.28

814.1

301.69

704.7

315.0113208

749.1



The Challenge  I am getting is to make this data be opened by grads because
it is complaining of endvars. When I try to use just Vars =1 I am able to
create a *.dat data file that can be opened by grads but when I try to map
it it Grads, it is blank.

Can anyone help please.
Regards,
Charles Vanya


Meteorological Services
P.O.Box 1808,
Blantyre,
Malawi
Cell:+265-888-980 545
 + 254 714 586 517
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20150117/bfd42557/attachment-0001.html 


More information about the gradsusr mailing list