Merge remote-tracking branch 'origin/release-v4.6.1'
[WRF.git] / external / io_grib1 / test_write_grib.c
blobf521cef49dd4813612dac86abef6b7b8e9e4593b
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "grib1_routines.h"
5 #define LATLON 0
6 #define LAMBERT 1
7 #define POLAR_STEREO 2
8 #define MERCATOR 3
10 main()
12 int level;
13 int projection;
14 int xdim;
15 int ydim;
16 int grid_id;
17 float center_lat, center_lon;
18 float proj_central_lon;
19 float dx, dy;
20 int south;
21 float latin1, latin2;
22 float *data;
23 int filefd;
24 int error;
25 char datestr[200];
26 int i,j;
27 float fcst_secs;
28 int accum_period;
29 int leveltype;
30 int level2;
31 Grib1_Tables grib1_tables;
32 int ret;
33 int status;
34 Grid_Info gridinfo;
36 level = 9950;
37 projection = LAMBERT;
38 xdim = 422;
39 ydim = 271;
40 center_lat = 0.0;
41 center_lon = 0.0;
42 proj_central_lon = -100.0;
43 dx = 12.0;
44 dy = 12.0;
45 south = 0;
46 latin1 = 30.0;
47 latin2 = 60.0;
48 data = (float *)calloc(xdim*ydim,sizeof(float));
49 fcst_secs = 360;
50 accum_period = 0;
51 leveltype = 119;
52 level2 = 0;
53 grid_id = 255;
55 read_gribmap_("gribmap.txt",&grib1_tables,&ret);
57 open_file_("test2.grb","w",&filefd,&error,9,1);
58 strcpy(datestr,"2005-01-01_00:00:00");
59 for (i=0; i< 1; i++) {
60 for (j=0; j<xdim*ydim; j++) {
62 data[j] = rand()/RAND_MAX;
64 data[j] = j/(float)ydim;
66 fprintf(stderr,"Writing grib record %d\n",i);
67 status = LOAD_GRID_INFO("TSK", datestr, &leveltype, &level,
68 &level2, &fcst_secs, &accum_period, &grid_id, &projection,
69 &xdim, &ydim, &center_lat, &center_lon, &dx, &dy,
70 &proj_central_lon, &south, &latin1, &latin2,
71 &grib1_tables, &gridinfo, strlen("TSK"), strlen(datestr));
73 WRITE_GRIB(&gridinfo, &filefd, data);
75 status = WRITE_GRIB("ABC",&level,&level2,&leveltype,
76 datestr,&fcst_secs,&accum_period,
77 &projection,&grid_id,&xdim,&ydim,&center_lat,
78 &center_lon,&proj_central_lon,&dx,&dy,&south,&latin1,
79 &latin2,data,&grib_table_info,&filefd,8);
81 fprintf(stderr,"status: %d\n",status);
85 FREE_GRIBMAP(&grib1_tables);