[GrADS] How to plot stations climatology contour in a map?

Qingfang Dai qdai at MATH.UALBERTA.CA
Mon Jan 21 13:45:30 EST 2008


Dear GrADS Users,

I want to plot the stations' climatology contour. My TXT data file is the format of (stnid, lat, lon, climatology value). So I did as followings but it doesn't work. I don't how I shuld do.

First, I used the following C++ program to write the TXT file into DAT file:

#include "stdafx.h"
#include <stdio.h>

int main(int argc, char* argv[])
{
  /* 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;

  FILE  *ifile, *ofile;
  char  rec[80];
  //int   flag,year,month,yrsav,mnsav;
  int   i;
  float val;

/* Open files */
  ifile = fopen ("clim.txt","r");
  ofile = fopen ("clim.dat","wb");

   if (ifile==NULL || ofile==NULL) {
    printf("Error opening files\n");
    return 1;
  }

/* Read, write loop */
  val = 0.0;
  while (fgets(rec,79,ifile)!=NULL) {
    /* Format conversion */
  sscanf (rec+8," %g %g %g",&hdr.lat,&hdr.lon,&val);
    for (i=0; i<8; i++) hdr.id[i] = rec[i];

    /* 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);
  }
  /* Time group terminator */
  hdr.nlev = 0;
  fwrite (&hdr,sizeof(struct rpthdr), 1, ofile);

  fclose(ifile);
  fclose(ofile);

  return 0;
}

Second, I write the ctl file 'clim.ctl' as

DSET ^clim.dat
DTYPE  station
STNMAP ^clim.map
UNDEF -999.9
TITLE 61-90 climatology
TDEF  1 LINEAR Jan1960 1mo
VARS  1
prep  1  99  precipitation climatology of station
ENDVARS

Finally, I write the gs file 'clim.gs' as

'!stnmap -i ../stnmap/AB_elev.ctl'

'reinit'
'open ../stnmap/AB_elev.ctl'
'set gxout contour'
'set grads off'
'set mproj nps'
'set grid off'
'set frame off'
'set cstyle 3'
'set csmooth off'
'set t 1 1'
'd prep'

'set font 1'
'set string 1 tc 3'
'set strsiz 0.15 0.15'
'draw title 1961-1990 Climatology in January'
'printim ../Clim.gif gif white'

Thanks.

Qingfang


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20080121/122dc06b/attachment.html 


More information about the gradsusr mailing list