Monthly Report on Climate System Separated Volume No.12

--- How to read GRIB format data ? ---


Abstract

The SST data contained in this website is encorded in WMO-GRIB format. GRIB format files can be decoded with the famous free software such as GrADS. Here, we show a instruction of decoding GRIB format data and convert data format through GrADS software. The converted data can be read from FORTRAN or C program easily.

* In advance, please check that GrADS is installed in your computer. GrADS is installable to almost all OS's, such as WINDOWS, UNIX, LINUX, and Macintosh OSX. In the following, it is assumed that your computer is LINUX environment and CD-ROM is mounted on /mnt/cdrom.

Decoding GRIB Data with GrADS

Prease edit the following script files with a text editor. In this example, the data in November, 1997 will be picked up from the data recorded on your disk drive.

*** convert.gs ***
*-----------------------------------------------------------------------
function main()
* Please edit the following line to match your computer environment.
mydir='/home/user_account'
* Those who use WINDOWS, please use your own path to disk drive,
* for exaple, replace '/mnt/cdrom' to 'D:\'.
'open /mnt/cdrom/sstdata/hist/sstmon.ctl'
'set lon 0.5 359.5'
'set lat -89.5 89.5'
'set time nov1997'
'set gxout fwrite'
'set fwrite 'mydir'/sst.dat'
'quit'
*-----------------------------------------------------------------------

Next, please execute this script file in GrADS software.

$ grads -blc "run henkan.gs". 

Carring out like this, Output SST data file will be stored to the specified directory in 4-byte real floating point format.

The data of 4-byte real format can be read with the following programs.

C*** In the case of FORTRAN77 ***
C------------------------------------------------------------------------
program rdsst
parameter(im=360,jm=180)
real dat(im,jm)
open(10,file='sst.dat',form='unformatted',access='direct',
& recl=4*im*jm)
read(10, rec=1) dat
C
C User's Operation
C
close(10)
stop
end
C------------------------------------------------------------------------
/*** In the case of the C language ***/
/*---------------------------------------------------------------------*/
#include <stdio.h>
#define IM 360
#define JM 180

main()
{
FILE *fp;
int i;
float *dat;
dat=(float *)malloc(sizeof(float)*IM*JM);
fp = fopen("sst.dat","r");
fread(dat, sizeof(float), IM*JM, fp);
/*
User's Operation
*/
fclose(fp);
}
/*----------------------------------------------------------------------*/