00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022
00023 #include "grib_api.h"
00024
00025 int main(int argc, char** argv) {
00026 int err = 0;
00027 long centre=80;
00028 long long_value=0;
00029 char string_value[100];
00030 size_t len = sizeof(string_value)/sizeof(char);
00031 size_t size=0;
00032
00033 FILE* in = NULL;
00034 char* infile = "../../data/regular_latlon_surface.grib1";
00035 FILE* out = NULL;
00036 char* outfile = "out.grib1";
00037 grib_handle *h = NULL;
00038 const void* buffer = NULL;
00039
00040 in = fopen(infile,"r");
00041 if(!in) {
00042 printf("ERROR: unable to open file %s\n",infile);
00043 return 1;
00044 }
00045
00046 out = fopen(outfile,"w");
00047 if(!in) {
00048 printf("ERROR: unable to open file %s\n",outfile);
00049 return 1;
00050 }
00051
00052
00053 h = grib_handle_new_from_file(0,in,&err);
00054 if (h == NULL) {
00055 printf("Error: unable to create handle from file %s\n",infile);
00056 }
00057
00058
00059 GRIB_CHECK(grib_set_long(h,"centre",centre),0);
00060
00061
00062 GRIB_CHECK(grib_get_long(h,"centre",&long_value),0);
00063 printf("centre long value=%ld\n",long_value);
00064
00065
00066 GRIB_CHECK(grib_get_string(h,"centre",string_value,&len),0);
00067 printf("centre string value=%s\n",string_value);
00068
00069
00070 GRIB_CHECK(grib_get_message(h,&buffer,&size),0);
00071
00072
00073 if(fwrite(buffer,1,size,out) != size)
00074 {
00075 perror(argv[1]);
00076 exit(1);
00077 }
00078
00079
00080 grib_handle_delete(h);
00081
00082 fclose(in);
00083 fclose(out);
00084
00085 return 0;
00086 }