1/*! \page grib_dump grib_dump 2\section DESCRIPTION 3 Dump the content of a grib file in different formats. 4 5\section USAGE 6 grib_dump 7 [options] grib_file grib_file ... 8 9\section OPTIONS 10-O \n Octet mode. WMO documentation style dump. 11 \n \n -D \n Debug mode. 12 \n \n -d \n Print all data values. Available only in C mode 13 \n \n -C \n C code mode. A C code program generating the grib message is dumped. 14 \n \n -t \n Print type information. 15 \n \n -H \n Print octet content in hexadecimal format. 16 \n \n -a \n Dump aliases. 17 \n \n -w key[:{s/d/l}]{=/!=}value,key[:{s/d/l}]{=/!=}value,... \n 18 Where clause. 19 Grib messages are processed only if they match all the key/value constraints. 20 A valid constraint is of type key=value or key!=value. 21 For each key a string (key:s) or a double (key:d) or a long (key:l) 22 type can be specified. Default type is string. 23 \n \n -M \n Multi-grib support off. Turn off support for multiple fields in single grib message. 24 \n \n -7 \n Does not fail when the message has wrong length 25 \n \n -V \n Version. 26 \n \n -G \n GRIBEX compatibility mode. 27 \n \n 28\section grib_dump_examples grib_dump examples 29-# To dump in a WMO documentation style with hexadecimal octet values (-H).\n 30\verbatim 31>grib_dump -OH ../data/reduced_gaussian_model_level.grib1 32\endverbatim\n 33-# To add key aliases and type information.\n 34\verbatim 35>grib_dump -OtaH ../data/reduced_gaussian_model_level.grib1 36\endverbatim\n 37-# To obtain all the key names (computed keys included) available in a grib file.\n 38\verbatim 39> grib_dump -D ../data/regular_latlon_surface.grib1 40\endverbatim\n 41-# To obtain a C code example from a grib file.\n 42\code 43>grib_dump -C ../data/regular_latlon_surface.grib1 44#include <grib_api.h> 45 46/* This code was generated automatically */ 47 48 49int main(int argc,const char** argv) 50{ 51 grib_handle *h = NULL; 52 size_t size = 0; 53 double* vdouble = NULL; 54 long* vlong = NULL; 55 FILE* f = NULL; 56 const char* p = NULL; 57 const void* buffer = NULL; 58 59 if(argc != 2) { 60 fprintf(stderr,"usage: %s out\n",argv[0]); 61 exit(1); 62 } 63 64 h = grib_handle_new_from_samples(NULL,"GRIB1"); 65 if(!h) { 66 fprintf(stderr,"Cannot create grib handle\n"); 67 exit(1); 68 } 69 70 GRIB_CHECK(grib_set_long(h,"parametersVersion",1),0); 71 GRIB_CHECK(grib_set_long(h,"truncateLaplacian",0),0); 72 GRIB_CHECK(grib_set_long(h,"truncateDegrees",0),0); 73 GRIB_CHECK(grib_set_long(h,"dummy",1),0); 74 GRIB_CHECK(grib_set_long(h,"changingPrecision",0),0); 75 GRIB_CHECK(grib_set_long(h,"unitsFactor",1),0); 76 GRIB_CHECK(grib_set_long(h,"unitsBias",0),0); 77 GRIB_CHECK(grib_set_long(h,"timeRangeIndicatorFromStepRange",-1),0); 78 GRIB_CHECK(grib_set_long(h,"eps",0),0); 79 GRIB_CHECK(grib_set_long(h,"editionNumber",1),0); 80 GRIB_CHECK(grib_set_long(h,"productionStatusOfProcessedData",0),0); 81 GRIB_CHECK(grib_set_long(h,"table2Version",128),0); 82 83 /* 98 = European Center for Medium-Range Weather Forecasts (grib1/0.table) */ 84 GRIB_CHECK(grib_set_long(h,"centre",98),0); 85 86 GRIB_CHECK(grib_set_long(h,"generatingProcessIdentifier",130),0); 87 GRIB_CHECK(grib_set_long(h,"gridDefinition",255),0); 88 89 /* 128 = 10000000 90 (1=1) Section 2 included 91 (2=0) Section 3 omited 92 See grib1/1.table */ 93 GRIB_CHECK(grib_set_long(h,"section1Flags",128),0); 94 95 96 /* 167 = 2 metre temperature (K) (grib1/2.98.128.table) */ 97 GRIB_CHECK(grib_set_long(h,"indicatorOfParameter",167),0); 98 99 100 /* 1 = Surface (of the Earth, which includes sea surface) (grib1/3.table) */ 101 GRIB_CHECK(grib_set_long(h,"indicatorOfTypeOfLevel",1),0); 102 103 GRIB_CHECK(grib_set_long(h,"level",0),0); 104 GRIB_CHECK(grib_set_long(h,"yearOfCentury",8),0); 105 GRIB_CHECK(grib_set_long(h,"month",2),0); 106 GRIB_CHECK(grib_set_long(h,"day",6),0); 107 GRIB_CHECK(grib_set_long(h,"hour",12),0); 108 GRIB_CHECK(grib_set_long(h,"minute",0),0); 109 GRIB_CHECK(grib_set_long(h,"second",0),0); 110 111 /* 1 = Hour (grib1/4.table) */ 112 GRIB_CHECK(grib_set_long(h,"unitOfTimeRange",1),0); 113 114 GRIB_CHECK(grib_set_long(h,"P1",0),0); 115 GRIB_CHECK(grib_set_long(h,"P2",0),0); 116 117 /* 0 = Forecast product valid at reference time + P1 (P1>0) (grib1/5.table) */ 118 GRIB_CHECK(grib_set_long(h,"timeRangeIndicator",0),0); 119 120 GRIB_CHECK(grib_set_long(h,"numberIncludedInAverage",0),0); 121 GRIB_CHECK(grib_set_long(h,"numberMissingFromAveragesOrAccumulations",0),0); 122 GRIB_CHECK(grib_set_long(h,"centuryOfReferenceTimeOfData",21),0); 123 124 /* 0 = Unknown code table entry (grib1/0.ecmf.table) */ 125 GRIB_CHECK(grib_set_long(h,"subCentre",0),0); 126 127 GRIB_CHECK(grib_set_long(h,"decimalScaleFactor",0),0); 128 GRIB_CHECK(grib_set_long(h,"setLocalDefinition",0),0); 129 GRIB_CHECK(grib_set_long(h,"dataDate",20080206),0); 130 GRIB_CHECK(grib_set_long(h,"dataTime",1200),0); 131 132 /* 1 = Hour (stepUnits.table) */ 133 GRIB_CHECK(grib_set_long(h,"stepUnits",1),0); 134 135 GRIB_CHECK(grib_set_long(h,"deleteLocalDefinition",0),0); 136 137 /* 1 = MARS labelling or ensemble forecast data (grib1/localDefinitionNumber.98.table) */ 138 GRIB_CHECK(grib_set_long(h,"localDefinitionNumber",1),0); 139 140 141 /* 1 = Operational archive (mars/class.table) */ 142 GRIB_CHECK(grib_set_long(h,"marsClass",1),0); 143 144 145 /* 2 = Analysis (mars/type.table) */ 146 GRIB_CHECK(grib_set_long(h,"marsType",2),0); 147 148 149 /* 1025 = Atmospheric model (mars/stream.table) */ 150 GRIB_CHECK(grib_set_long(h,"marsStream",1025),0); 151 152 p = "0001"; 153 size = strlen(p)+1; 154 GRIB_CHECK(grib_set_string(h,"experimentVersionNumber",p,&size),0); 155 GRIB_CHECK(grib_set_long(h,"perturbationNumber",0),0); 156 GRIB_CHECK(grib_set_long(h,"numberOfForecastsInEnsemble",0),0); 157 158 /* x */ 159 160 GRIB_CHECK(grib_set_long(h,"gridDescriptionSectionPresent",1),0); 161 GRIB_CHECK(grib_set_long(h,"GDSPresent",1),0); 162 GRIB_CHECK(grib_set_long(h,"bitmapPresent",0),0); 163 GRIB_CHECK(grib_set_long(h,"radius",6367470),0); 164 GRIB_CHECK(grib_set_long(h,"shapeOfTheEarth",6),0); 165 GRIB_CHECK(grib_set_long(h,"numberOfVerticalCoordinateValues",0),0); 166 GRIB_CHECK(grib_set_long(h,"pvlLocation",255),0); 167 168 /* 0 = Latitude/Longitude Grid (grib1/6.table) */ 169 GRIB_CHECK(grib_set_long(h,"dataRepresentationType",0),0); 170 171 GRIB_CHECK(grib_set_long(h,"Ni",16),0); 172 GRIB_CHECK(grib_set_long(h,"Nj",31),0); 173 GRIB_CHECK(grib_set_long(h,"latitudeOfFirstGridPoint",60000),0); 174 GRIB_CHECK(grib_set_long(h,"longitudeOfFirstGridPoint",0),0); 175 176 /* 128 = 10000000 177 (1=1) Direction increments given 178 (2=0) Earth assumed spherical with radius = 6367.47 km 179 (5=0) u and v components resolved relative to easterly and northerly directions 180 See grib1/7.table */ 181 GRIB_CHECK(grib_set_long(h,"resolutionAndComponentFlags",128),0); 182 183 GRIB_CHECK(grib_set_long(h,"ijDirectionIncrementGiven",1),0); 184 GRIB_CHECK(grib_set_long(h,"earthIsOblate",0),0); 185 GRIB_CHECK(grib_set_long(h,"uvRelativeToGrid",0),0); 186 GRIB_CHECK(grib_set_long(h,"latitudeOfLastGridPoint",0),0); 187 GRIB_CHECK(grib_set_long(h,"longitudeOfLastGridPoint",30000),0); 188 GRIB_CHECK(grib_set_long(h,"iDirectionIncrement",2000),0); 189 GRIB_CHECK(grib_set_long(h,"jDirectionIncrement",2000),0); 190 191 /* 0 = 00000000 192 (1=0) Points scan in +i direction 193 (2=0) Points scan in -j direction 194 (3=0) Adjacent points in i direction are consecutive 195 See grib1/8.table */ 196 GRIB_CHECK(grib_set_long(h,"scanningMode",0),0); 197 198 GRIB_CHECK(grib_set_long(h,"iScansNegatively",0),0); 199 GRIB_CHECK(grib_set_long(h,"jScansPositively",0),0); 200 GRIB_CHECK(grib_set_long(h,"jPointsAreConsecutive",0),0); 201 GRIB_CHECK(grib_set_long(h,"iScansPositively",1),0); 202 203 /* ITERATOR */ 204 205 206 /* NEAREST */ 207 208 GRIB_CHECK(grib_set_long(h,"PVPresent",0),0); 209 GRIB_CHECK(grib_set_long(h,"PLPresent",0),0); 210 GRIB_CHECK(grib_set_long(h,"missingValue",9999),0); 211 GRIB_CHECK(grib_set_long(h,"sphericalHarmonics",0),0); 212 GRIB_CHECK(grib_set_long(h,"complexPacking",0),0); 213 GRIB_CHECK(grib_set_long(h,"integerPointValues",0),0); 214 GRIB_CHECK(grib_set_long(h,"additionalFlagPresent",0),0); 215 GRIB_CHECK(grib_set_long(h,"hideThis",0),0); 216 GRIB_CHECK(grib_set_long(h,"bitsPerValue",16),0); 217 GRIB_CHECK(grib_set_long(h,"dirty_statistics",1),0); 218 GRIB_CHECK(grib_set_long(h,"dataLength",124),0); 219 GRIB_CHECK(grib_set_long(h,"changeDecimalPrecision",0),0); 220 GRIB_CHECK(grib_set_long(h,"decimalPrecision",0),0); 221 GRIB_CHECK(grib_set_long(h,"bitsPerValueAndRepack",16),0); 222/* Save the message */ 223 224 f = fopen(argv[1],"w"); 225 if(!f) { 226 perror(argv[1]); 227 exit(1); 228 } 229 230 GRIB_CHECK(grib_get_message(h,&buffer,&size),0); 231 232 if(fwrite(buffer,1,size,f) != size) { 233 perror(argv[1]); 234 exit(1); 235 } 236 237 if(fclose(f)) { 238 perror(argv[1]); 239 exit(1); 240 } 241 242 grib_handle_delete(h); 243 return 0; 244} 245\endcode\n 246*/ 247