[2759] | 1 | #include "gribfuncs.h" |
---|
| 2 | #include "read_grib.h" |
---|
| 3 | #include "gribmap.h" |
---|
| 4 | |
---|
| 5 | #ifndef CRAY |
---|
| 6 | # ifdef NOUNDERSCORE |
---|
| 7 | # define GET_FILEINDEX_SIZE get_fileindex_size |
---|
| 8 | # define INDEX_FILE index_file |
---|
| 9 | # define GET_METADATA_VALUE get_metadata_value |
---|
| 10 | # define GET_GRIB_INDEX get_grib_index |
---|
| 11 | # define GET_GRIB_INDEX_GUESS get_grib_index_guess |
---|
| 12 | # define GET_GRIB_INDEX_VALIDTIME get_grib_index_validtime |
---|
| 13 | # define GET_GRIB_INDEX_VALIDTIME_GUESS get_grib_index_validtime_guess |
---|
| 14 | # define GET_GRIB_INDICES get_grib_indices |
---|
| 15 | # define ALLOC_INDEX_FILE alloc_index_file |
---|
| 16 | # define FREE_INDEX_FILE free_index_file |
---|
| 17 | # define GET_NUM_TIMES get_num_times |
---|
| 18 | # define GET_LEVEL1 get_level1 |
---|
| 19 | # define GET_LEVEL2 get_level2 |
---|
| 20 | # define GET_TIME get_time |
---|
| 21 | # define GET_GRID_INFO_SIZE get_grid_info_size |
---|
| 22 | # define LOAD_GRID_INFO load_grid_info |
---|
| 23 | # define FREE_GRID_INFO free_grid_info |
---|
| 24 | # define PRINT_GRID_INFO print_grid_info |
---|
| 25 | # define READ_GRIB read_grib |
---|
| 26 | # define WRITE_GRIB write_grib |
---|
| 27 | # define GET_GRIB_SEARCH_SIZE get_grib_search_size |
---|
| 28 | # define LOAD_GRIB_SEARCH load_grib_search |
---|
| 29 | # define FREE_GRIB_SEARCH free_grib_search |
---|
| 30 | # define GET_SIZEOF_GRID get_sizeof_grid |
---|
| 31 | # define GET_GRIB_CENTER get_grib_center |
---|
| 32 | # define GET_GRIB_SUBCENTER get_grib_subcenter |
---|
| 33 | # define GET_GRIB_TBLVERSION get_grib_tblversion |
---|
| 34 | # define GET_GRIB_PROCID get_grib_procid |
---|
| 35 | # else |
---|
| 36 | # ifdef F2CSTYLE |
---|
| 37 | # define GET_FILEINDEX_SIZE get_fileindex_size__ |
---|
| 38 | # define INDEX_FILE index_file__ |
---|
| 39 | # define GET_METADATA_VALUE get_metadata_value__ |
---|
| 40 | # define GET_GRIB_INDEX get_grib_index__ |
---|
| 41 | # define GET_GRIB_INDEX_GUESS get_grib_index_guess__ |
---|
| 42 | # define GET_GRIB_INDEX_VALIDTIME_GUESS get_grib_index_validtime_guess__ |
---|
| 43 | # define GET_GRIB_INDICES get_grib_indices__ |
---|
| 44 | # define ALLOC_INDEX_FILE alloc_index_file__ |
---|
| 45 | # define FREE_INDEX_FILE free_index_file__ |
---|
| 46 | # define GET_NUM_TIMES get_num_times__ |
---|
| 47 | # define GET_LEVEL1 get_level1__ |
---|
| 48 | # define GET_LEVEL2 get_level2__ |
---|
| 49 | # define GET_TIME get_time__ |
---|
| 50 | # define GET_GRID_INFO_SIZE get_grid_info_size__ |
---|
| 51 | # define LOAD_GRID_INFO load_grid_info__ |
---|
| 52 | # define FREE_GRID_INFO free_grid_info__ |
---|
| 53 | # define PRINT_GRID_INFO print_grid_info__ |
---|
| 54 | # define READ_GRIB read_grib__ |
---|
| 55 | # define WRITE_GRIB write_grib__ |
---|
| 56 | # define GET_GRIB_SEARCH_SIZE get_grib_search_size__ |
---|
| 57 | # define LOAD_GRIB_SEARCH load_grib_search__ |
---|
| 58 | # define FREE_GRIB_SEARCH free_grib_search__ |
---|
| 59 | # define GET_SIZEOF_GRID get_sizeof_grid__ |
---|
| 60 | # define GET_GRIB_CENTER get_grib_center__ |
---|
| 61 | # define GET_GRIB_SUBCENTER get_grib_subcenter__ |
---|
| 62 | # define GET_GRIB_TBLVERSION get_grib_tblversion__ |
---|
| 63 | # define GET_GRIB_PROCID get_grib_procid__ |
---|
| 64 | # else |
---|
| 65 | # define GET_FILEINDEX_SIZE get_fileindex_size_ |
---|
| 66 | # define INDEX_FILE index_file_ |
---|
| 67 | # define GET_METADATA_VALUE get_metadata_value_ |
---|
| 68 | # define GET_GRIB_INDEX get_grib_index_ |
---|
| 69 | # define GET_GRIB_INDEX_GUESS get_grib_index_guess_ |
---|
| 70 | # define GET_GRIB_INDEX_VALIDTIME get_grib_index_validtime_ |
---|
| 71 | # define GET_GRIB_INDEX_VALIDTIME_GUESS get_grib_index_validtime_guess_ |
---|
| 72 | # define GET_GRIB_INDICES get_grib_indices_ |
---|
| 73 | # define ALLOC_INDEX_FILE alloc_index_file_ |
---|
| 74 | # define FREE_INDEX_FILE free_index_file_ |
---|
| 75 | # define GET_NUM_TIMES get_num_times_ |
---|
| 76 | # define GET_LEVEL1 get_level1_ |
---|
| 77 | # define GET_LEVEL2 get_level2_ |
---|
| 78 | # define GET_TIME get_time_ |
---|
| 79 | # define GET_GRID_INFO_SIZE get_grid_info_size_ |
---|
| 80 | # define LOAD_GRID_INFO load_grid_info_ |
---|
| 81 | # define FREE_GRID_INFO free_grid_info_ |
---|
| 82 | # define PRINT_GRID_INFO print_grid_info_ |
---|
| 83 | # define READ_GRIB read_grib_ |
---|
| 84 | # define WRITE_GRIB write_grib_ |
---|
| 85 | # define GET_GRIB_SEARCH_SIZE get_grib_search_size_ |
---|
| 86 | # define LOAD_GRIB_SEARCH load_grib_search_ |
---|
| 87 | # define FREE_GRIB_SEARCH free_grib_search_ |
---|
| 88 | # define GET_SIZEOF_GRID get_sizeof_grid_ |
---|
| 89 | # define GET_GRIB_CENTER get_grib_center_ |
---|
| 90 | # define GET_GRIB_SUBCENTER get_grib_subcenter_ |
---|
| 91 | # define GET_GRIB_TBLVERSION get_grib_tblversion_ |
---|
| 92 | # define GET_GRIB_PROCID get_grib_procid_ |
---|
| 93 | # endif |
---|
| 94 | # endif |
---|
| 95 | #endif |
---|
| 96 | |
---|
| 97 | typedef struct { |
---|
| 98 | char VarName[100]; |
---|
| 99 | char DateStr[100]; |
---|
| 100 | char Element[100]; |
---|
| 101 | char Value[1000]; |
---|
| 102 | } MetaData_Elements; |
---|
| 103 | |
---|
| 104 | typedef struct { |
---|
| 105 | int num_elements; |
---|
| 106 | MetaData_Elements *elements; |
---|
| 107 | } MetaData; |
---|
| 108 | |
---|
| 109 | typedef struct { |
---|
| 110 | char valid_time[30]; |
---|
| 111 | } Times_Elements; |
---|
| 112 | |
---|
| 113 | typedef struct { |
---|
| 114 | int num_elements; |
---|
| 115 | Times_Elements *elements; |
---|
| 116 | } Times; |
---|
| 117 | |
---|
| 118 | typedef struct { |
---|
| 119 | MetaData *metadata; |
---|
| 120 | GribInfo *gribinfo; |
---|
| 121 | Times *times; |
---|
| 122 | } FileIndex; |
---|
| 123 | |
---|
| 124 | typedef struct { |
---|
| 125 | char varname[200]; |
---|
| 126 | char initdate[20]; |
---|
| 127 | int leveltype; |
---|
| 128 | int level1; |
---|
| 129 | int level2; |
---|
| 130 | float fcst_time; |
---|
| 131 | int accum_period; |
---|
| 132 | int grid_id; |
---|
| 133 | int projection; |
---|
| 134 | int xpoints; |
---|
| 135 | int ypoints; |
---|
| 136 | float center_lat; |
---|
| 137 | float center_lon; |
---|
| 138 | float Di; |
---|
| 139 | float Dj; |
---|
| 140 | float central_lon; |
---|
| 141 | int proj_center_flag; |
---|
| 142 | float latin1; |
---|
| 143 | float latin2; |
---|
| 144 | Grib1_Tables *grib_tables; |
---|
| 145 | } Grid_Info; |
---|
| 146 | |
---|
| 147 | int GET_FILEINDEX_SIZE(int *size); |
---|
| 148 | |
---|
| 149 | int ALLOC_INDEX_FILE(FileIndex *fileindex); |
---|
| 150 | void FREE_INDEX_FILE(FileIndex *fileindex); |
---|
| 151 | |
---|
| 152 | int INDEX_FILE(int *fid, FileIndex *fileindex); |
---|
| 153 | |
---|
| 154 | int GET_METADATA_VALUE(FileIndex *fileindex, char Element[], char DateStr[], |
---|
| 155 | char VarName[], char Value[], int *stat, int strlen1, |
---|
| 156 | int strlen2, int strlen3, int strlen4, int strlen5); |
---|
| 157 | |
---|
| 158 | int GET_GRIB_INDEX(FileIndex *fileindex, |
---|
| 159 | int *center, int *subcenter, int *parmtbl, |
---|
| 160 | int *parmid, char DateStrIn[], |
---|
| 161 | int *leveltype, int *level1, int *level2, int *fcsttime1, |
---|
| 162 | int *fcsttime2, int *index, int strlen1, int strlen2); |
---|
| 163 | |
---|
| 164 | int GET_GRIB_INDEX_GUESS(FileIndex *fileindex, int *center, int *subcenter, |
---|
| 165 | int *parmtbl, int *parmid, char DateStrIn[], |
---|
| 166 | int *leveltype, int *level1, int *level2, |
---|
| 167 | int *fcsttime1,int *fcsttime2, int *guessidx, |
---|
| 168 | int *index, int strlen1, int strlen2); |
---|
| 169 | |
---|
| 170 | int GET_GRIB_INDICES(FileIndex *fileindex, int *center, int *subcenter, |
---|
| 171 | int *parmtbl,int *parmid, char DateStrIn[], |
---|
| 172 | int *leveltype, int *level1, int *level2, int *fcsttime1, |
---|
| 173 | int *fcsttime2, int *indices, int *num_indices, |
---|
| 174 | int strlen1, int strlen2); |
---|
| 175 | |
---|
| 176 | int GET_NUM_TIMES(FileIndex *fileindex, int *numtimes); |
---|
| 177 | |
---|
| 178 | int GET_TIME(FileIndex *fileindex, int *idx, char time[]); |
---|
| 179 | |
---|
| 180 | int GET_GRID_INFO_SIZE(int *size); |
---|
| 181 | |
---|
| 182 | int LOAD_GRID_INFO(char *varname, char *initdate, int *leveltype, |
---|
| 183 | int *level1, int *level2, float *fcst_time, |
---|
| 184 | int *accum_period, int *grid_id, int *projection, |
---|
| 185 | int *xpoints, int *ypoints, float *center_lat, |
---|
| 186 | float *center_lon, float *Di, float *Dj,float *central_lon, |
---|
| 187 | int *proj_center_flag, float *latin1, |
---|
| 188 | float *latin2, Grib1_Tables *grib_tables, |
---|
| 189 | Grid_Info *grid_info, int strlen1, int strlen2); |
---|
| 190 | |
---|
| 191 | int PRINT_GRID_INFO(Grid_Info *grid_info); |
---|
| 192 | |
---|
| 193 | int WRITE_GRIB(Grid_Info *grid_info, int *filefd, float *data); |
---|
| 194 | |
---|
| 195 | int READ_GRIB(FileIndex *fileindex, int *fid, int *index, float *data); |
---|
| 196 | |
---|
| 197 | int GET_SIZEOF_GRID(FileIndex *fileindex, int *index, int *numcols, |
---|
| 198 | int *numrows); |
---|
| 199 | |
---|
| 200 | int GET_LEVEL1(FileIndex *fileindex, int *idx, int *level1); |
---|
| 201 | |
---|
| 202 | int GET_LEVEL2(FileIndex *fileindex, int *idx, int *level2); |
---|
| 203 | |
---|
| 204 | int GET_GRIB_INDEX_VALIDTIME(FileIndex *fileindex, |
---|
| 205 | int *center, int *subcenter, int *parmtbl, |
---|
| 206 | int *parmid, |
---|
| 207 | char DateStrIn[], int *leveltype, int *level1, |
---|
| 208 | int *level2, int *index, int strlen1, |
---|
| 209 | int strlen2); |
---|
| 210 | |
---|
| 211 | int GET_GRIB_INDEX_VALIDTIME_GUESS(FileIndex *fileindex, int *center, |
---|
| 212 | int *subcenter, int *parmtbl, int *parmid, |
---|
| 213 | char DateStrIn[], int *leveltype, |
---|
| 214 | int *level1, int *level2, int *guessidx, |
---|
| 215 | int *index, int strlen1, int strlen2); |
---|
| 216 | |
---|
| 217 | int GET_GRIB_CENTER(FileIndex *fileindex, int *parmid, int *center); |
---|
| 218 | |
---|
| 219 | int GET_GRIB_SUBCENTER(FileIndex *fileindex, int *parmid, int *subcenter); |
---|
| 220 | |
---|
| 221 | int GET_GRIB_TBLVERSION(FileIndex *fileindex, int *parmid, int *parmtbl); |
---|
| 222 | |
---|
| 223 | int GET_GRIB_PROCID(FileIndex *fileindex, int *parmid, int *proc_id); |
---|
| 224 | |
---|
| 225 | int GET_REGION_CENTER(char *MemoryOrderIn, int *projection, |
---|
| 226 | float *domain_center_lat, |
---|
| 227 | float *domain_center_lon, int *full_xsize, |
---|
| 228 | int *full_ysize, float *dx, float *dy, |
---|
| 229 | float *proj_central_lon, |
---|
| 230 | int *proj_center_flag, float *truelat1, |
---|
| 231 | float *truelat2, int *region_xsize, int *region_ysize, |
---|
| 232 | float *region_center_lat, float *region_center_lon, |
---|
| 233 | int strlen1); |
---|