WXP C++ Library Version 6.74.9
Loading...
Searching...
No Matches
GribFile.h
1#ifndef _WINC_GRIBFILE
2#define _WINC_GRIBFILE
3
4#include <WXP/Date.h>
5#include <WXP/DomainVal.h>
6#include <WXP/File.h>
7#include <WXP/Filename.h>
8#include <WXP/GribPDB.h>
9#include <WXP/GribParam.h>
10#include <WXP/Grid.h>
11#include <WXP/GridSpec.h>
12#include <WXP/Grids.h>
13#include <WXP/ModelName.h>
14#include <WXP/VarName.h>
15
16namespace WXP {
17 class GribFile {
18 File file;
19 int access;
20 bool opened;
21 File hfile;
22 Date date;
23 GribPDB pdb;
24 DomainVal dv;
25 GribParam gparam[200];
26 VarName vname;
27 int nparam;
28 bool use_hfile;
29 int wrap;
30
31 /* Grid definition parameters */
32 int version;
33 int type;
34 int discipline;
35 int sect_flag;
36
37 int ploc; /* Location of beginning of product */
38 int gloc; /* Location of beginning of GRIB product */
39 int dloc; /* Location of beginning of data */
40 int gind; /* Grid index within GRIB product */
41 char wmo_hdr[30];/* WMO header */
42 int size; /* GRIB product size */
43 int num; /* Current product count */
44 int gnum; /* Current grid count in product */
45 bool peeked;
46
47 static const int NUM_VALID = 20;
48
49 /* Data block */
50 static const int DATA_SIZE = 25000;
51 int data_size;
52 int data_off;
53 unsigned char data[DATA_SIZE];
54 float miss; /* Missing value */
55
56 /* GRIB2 section parameters */
57 int sect;
58 int slen;
59 bool cont;
60 bool pcont;
61
62 /* GRIB2 data template and grid size */
63 int data_pnts;
64 int drs_temp;
65
66 /* Grid definition parameters */
67 float lat; /* The latitude of the first gridpoint */
68 int xdir; /* The scanning on x direction */
69 int ydir; /* The scanning on y direction */
70 int xalt; /* Rows scan in different directions */
71 int pole; /* Specifies single pole point */
72
73 /* Thinned grid parameters */
74 int thin; /* Specifies whether grid is thinning */
75 int *thin_val; /* Thinning array */
76
77 /* Base values for grid value scaling */
78 float ref; /* Reference value */
79 float sfac; /* Scale factor */
80 float dscale; /* Scale factor */
81 int max_val;
82 int data_type; /* Whether data is integer or float */
83
84 /* Bit Map section parameters */
85 unsigned char *bmb; /* The bit map block */
86 int bmoff; /* Offset in the BMB */
87 int bmlen; /* Length in the BMB */
88
89 /* Bitwise storage parameters */
90 int bpval; /* Specifies the number of bits per
91 * gridpoint value used in encoding GRIB */
92 int bpoff; /* Offset in data stream in bytes */
93 int data_bits;
94 int data_bytes;
95 long bit_mask;
96 int temp_data;
97
98 /* GRIB2 complex decoding */
99 int split_method;
100 int miss_type;
101 float miss1, miss2;
102 int num_bits;
103 int num_group;
104 int num_bits_gref;
105 int ref_gwidth;
106 int num_bits_gwidth;
107 int ref_glen;
108 int inc_glen;
109 int last_glen;
110 int num_bits_glen;
111 int order;
112 int spat_bytes;
113
114 /* JMA codec data */
115 float *map;
116 int num_map;
117
118 /* Checks for corrupt data */
119 int valid_data[NUM_VALID];
120 int bad; /* Specifies whether gridpoint data bad */
121 int bad_limit; /* Limit value for determining bad grid */
122 int bad_max; /* Max number of bad values before all bad */
123 int bad_test; /* Limit value for determining bad grid */
124 int prev_val;
125
126 /* Miscellaneous parameters */
127 int lev_type; /* Type of vertical level */
128 int grid_type; /* Type of grid */
129 ModelName mname;
130
131 int initClass();
132 public:
133 GribFile();
134 GribFile( const char *filename );
135 GribFile( Filename &filename );
136 ~GribFile();
137 int init();
138 bool isOpen();
139 int setParam( const char *str );
140 int useHdrFile( bool val );
141 int setMaxBad( int val );
142 inline int setMissValue( float rmiss ){ miss = rmiss; return 1; };
143 inline int setValueBits( int val ){ bpval = val; return 1; };
144 inline int setWrap( int val ){ wrap = val; return 1; };
145 int open( const char *filename, int raccess );
146 int open( const char *filename );
147 int open( Filename &filename );
148 int close();
149 int rewind();
151 inline int getVersion(){ return version; };
153 inline const char* getWmoHdr(){ return wmo_hdr; };
154 int getHeader( Grid &grid );
155 int read( Grid &grid );
156 int read( const char *spec, Grid &grid );
157 int read( GridSpec &spec, Grid &grid );
158 int read( Grids &grids );
159 int makeInfo( GribPDB &pdb, Grid &grid );
160 int makeDatim( Grid &grid );
161 int peek( Grid &grid );
162 int next( );
163 int readHeader();
164 int searchGRIB();
165 int readData( int bytes );
166 int readBits();
167 unsigned char getByte( int loc );
168 int seekData( int val );
169 int tellData();
170
171 GribParam getVer1Param( int ver, int src, int table, int param );
172 int readPDB( GribPDB &pdb );
173 int setPDB( GribPDB &pdb, Grid &grid );
174 int readGDB( DomainVal &dv );
175 int readBMB();
176 bool checkBMB();
177 int readBDB( Grid &grid );
178
179 int readSection();
180 int skipSection();
181 GribParam getVer2Param( int src, int disc, int cat, int param );
182 int readIDS( GribPDB &pdb );
183 int readGDS( DomainVal &dv );
184 int readPDS( GribPDB &pdb );
185 int readDRS();
186 int readBMS();
187 int readDS( Grid &grid );
188
189 int writeBits( int val );
190 int write( Grid &grid );
191
192 static int checkType( const char *filename );
193 static float convIBMFloat( const unsigned char *pc );
194 static int convIBMFloat( float val, unsigned char *pc );
195 static float convIEEEFloat( const unsigned char *pc );
196 static float convScale( const unsigned char *pc );
197 static int convScale( float scale );
198 static int setDomain( int type, DomainVal &dv );
199
200 static const int LIMIT = 300000;
201
202 enum Type {
203 NONE,
204 WXP,
205 WMO,
206 WXP_OLD,
207 NCEP,
208 RAW,
209 RAW_NS };
210 };
211}
212#endif
This class stores date and time information.
Definition Date.h:8
This class accesses files.
Definition File.h:15
This class creates filenames.
Definition Filename.h:11
This class reads in and decodes GRIB data.
Definition GribFile.h:17
unsigned char getByte(int loc)
Definition GribFile.cc:836
GribFile()
Definition GribFile.cc:42
int readIDS(GribPDB &pdb)
Definition GribFile.cc:2040
static int checkType(const char *filename)
Definition GribFile.cc:181
int readGDB(DomainVal &dv)
Definition GribFile.cc:1399
int readBits()
Definition GribFile.cc:863
int read(Grid &grid)
Definition GribFile.cc:331
~GribFile()
Definition GribFile.cc:70
int init()
Definition GribFile.cc:88
int seekData(int val)
Definition GribFile.cc:844
int readSection()
Definition GribFile.cc:2007
int next()
Definition GribFile.cc:672
int getVersion()
Definition GribFile.h:151
int readBMB()
Definition GribFile.cc:1715
int writeBits(int val)
Definition GribFile.cc:4715
int setPDB(GribPDB &pdb, Grid &grid)
Definition GribFile.cc:1369
int close()
Definition GribFile.cc:270
static float convScale(const unsigned char *pc)
Definition GribFile.cc:4584
int readHeader()
Definition GribFile.cc:687
int readPDB(GribPDB &pdb)
Definition GribFile.cc:1099
int searchGRIB()
Definition GribFile.cc:767
int readGDS(DomainVal &dv)
Definition GribFile.cc:2068
static int setDomain(int type, DomainVal &dv)
Definition GribFile.cc:906
int readData(int bytes)
Definition GribFile.cc:810
static float convIEEEFloat(const unsigned char *pc)
Definition GribFile.cc:4555
int skipSection()
Definition GribFile.cc:2030
int readDRS()
Definition GribFile.cc:3604
int readDS(Grid &grid)
Definition GribFile.cc:3766
bool checkBMB()
Definition GribFile.cc:1743
int readPDS(GribPDB &pdb)
Definition GribFile.cc:2536
int readBDB(Grid &grid)
Definition GribFile.cc:1762
int readBMS()
Definition GribFile.cc:3721
int makeDatim(Grid &grid)
Definition GribFile.cc:4607
int useHdrFile(bool val)
Definition GribFile.cc:157
bool isOpen()
Definition GribFile.cc:119
int setMaxBad(int val)
Definition GribFile.cc:171
static float convIBMFloat(const unsigned char *pc)
Definition GribFile.cc:4490
const char * getWmoHdr()
Definition GribFile.h:153
int getHeader(Grid &grid)
Definition GribFile.cc:296
int makeInfo(GribPDB &pdb, Grid &grid)
Definition GribFile.cc:4682
This class defines vertical level parameters.
Definition GridSpec.h:7
This class defines a grid.
Definition Grid.h:20
This class sets up a repository for grids.
Definition Grids.h:14
This class retrieves forecast model name from file. The model name is cached in the object so it ca...
Definition ModelName.h:8
This class processes variable information from variable.lup file.
Definition VarName.h:9
All WXP classes fall under the WXP namespace.
Definition Angle.h:4
This struct defines basic domain parameters.
Definition DomainVal.h:5
This structure contains the values from the GRIB Product Definition Block.
Definition GribPDB.h:10
This struct stores GRIB parameter information.
Definition GribParam.h:5