>grib_dump -C ../data/regular_latlon_surface.grib1
#include <grib_api.h>
int main(int argc,const char** argv)
{
grib_handle *h = NULL;
size_t size = 0;
double* vdouble = NULL;
long* vlong = NULL;
FILE* f = NULL;
const char* p = NULL;
const void* buffer = NULL;
if(argc != 2) {
fprintf(stderr,"usage: %s out\n",argv[0]);
exit(1);
}
h = grib_handle_new_from_samples(NULL,"GRIB1");
if(!h) {
fprintf(stderr,"Cannot create grib handle\n");
exit(1);
}
GRIB_CHECK(grib_set_long(h,"editionNumber",1),0);
GRIB_CHECK(grib_set_long(h,"table2Version",128),0);
GRIB_CHECK(grib_set_long(h,"centre",98),0);
GRIB_CHECK(grib_set_long(h,"generatingProcessIdentifier",130),0);
GRIB_CHECK(grib_set_long(h,"gridDefinition",255),0);
GRIB_CHECK(grib_set_long(h,"section1Flags",128),0);
GRIB_CHECK(grib_set_long(h,"indicatorOfParameter",167),0);
GRIB_CHECK(grib_set_long(h,"indicatorOfTypeOfLevel",1),0);
GRIB_CHECK(grib_set_long(h,"level",0),0);
GRIB_CHECK(grib_set_long(h,"yearOfCentury",8),0);
GRIB_CHECK(grib_set_long(h,"month",2),0);
GRIB_CHECK(grib_set_long(h,"day",6),0);
GRIB_CHECK(grib_set_long(h,"hour",12),0);
GRIB_CHECK(grib_set_long(h,"minute",0),0);
GRIB_CHECK(grib_set_long(h,"unitOfTimeRange",1),0);
GRIB_CHECK(grib_set_long(h,"P1",0),0);
GRIB_CHECK(grib_set_long(h,"P2",0),0);
GRIB_CHECK(grib_set_long(h,"timeRangeIndicator",0),0);
GRIB_CHECK(grib_set_long(h,"numberIncludedInAverage",0),0);
GRIB_CHECK(grib_set_long(h,"numberMissingFromAveragesOrAccumulations",0),0);
GRIB_CHECK(grib_set_long(h,"centuryOfReferenceTimeOfData",21),0);
GRIB_CHECK(grib_set_long(h,"subCentre",0),0);
GRIB_CHECK(grib_set_long(h,"decimalScaleFactor",0),0);
GRIB_CHECK(grib_set_long(h,"localDefinitionNumber",1),0);
GRIB_CHECK(grib_set_long(h,"marsClass",1),0);
GRIB_CHECK(grib_set_long(h,"marsType",2),0);
GRIB_CHECK(grib_set_long(h,"marsStream",1025),0);
p = "0001";
size = strlen(p)+1;
GRIB_CHECK(grib_set_string(h,"experimentVersionNumber",p,&size),0);
GRIB_CHECK(grib_set_long(h,"perturbationNumber",0),0);
GRIB_CHECK(grib_set_long(h,"numberOfForecastsInEnsemble",0),0);
GRIB_CHECK(grib_set_long(h,"numberOfVerticalCoordinateValues",0),0);
GRIB_CHECK(grib_set_long(h,"pvlLocation",255),0);
GRIB_CHECK(grib_set_long(h,"dataRepresentationType",0),0);
GRIB_CHECK(grib_set_long(h,"Ni",16),0);
GRIB_CHECK(grib_set_long(h,"Nj",31),0);
GRIB_CHECK(grib_set_long(h,"latitudeOfFirstGridPoint",60000),0);
GRIB_CHECK(grib_set_long(h,"longitudeOfFirstGridPoint",0),0);
GRIB_CHECK(grib_set_long(h,"resolutionAndComponentFlags",128),0);
GRIB_CHECK(grib_set_long(h,"latitudeOfLastGridPoint",0),0);
GRIB_CHECK(grib_set_long(h,"longitudeOfLastGridPoint",30000),0);
GRIB_CHECK(grib_set_long(h,"iDirectionIncrement",2000),0);
GRIB_CHECK(grib_set_long(h,"jDirectionIncrement",2000),0);
GRIB_CHECK(grib_set_long(h,"scanningMode",0),0);
GRIB_CHECK(grib_set_long(h,"bitsPerValue",16),0);
GRIB_CHECK(grib_set_long(h,"sphericalHarmonics",0),0);
GRIB_CHECK(grib_set_long(h,"complexPacking",0),0);
GRIB_CHECK(grib_set_long(h,"integerPointValues",0),0);
GRIB_CHECK(grib_set_long(h,"additionalFlagPresent",0),0);
f = fopen(argv[1],"w");
if(!f) {
perror(argv[1]);
exit(1);
}
GRIB_CHECK(grib_get_message(h,&buffer,&size),0);
if(fwrite(buffer,1,size,f) != size) {
perror(argv[1]);
exit(1);
}
if(fclose(f)) {
perror(argv[1]);
exit(1);
}
grib_handle_delete(h);
return 0;
}