Changeset 13830
- Timestamp:
- 02/21/08 14:37:29 (5 months ago)
- Files:
-
- spike/grib/gribdataset.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
spike/grib/gribdataset.cpp
r13823 r13830 67 67 const char *GetProjectionRef(); 68 68 private: 69 void Set MetaData(grib_MetaData* meta);69 void SetGribMetaData(grib_MetaData* meta); 70 70 FILE *fp; 71 71 char *pszProjection; … … 198 198 IS_Init (&is); 199 199 200 int bandNr = 0;201 202 200 203 201 /* Read GRIB message from file position "start". */ … … 210 208 211 209 char * errMsg = errSprintf(NULL); // no intention to show errors, just swallow it and free the memory 210 CPLDebug( "GRIB", "%s", errMsg ); 212 211 free(errMsg); 213 212 IS_Free(&is); … … 215 214 216 215 /************************************************************************/ 217 /* ~ MSGRasterBand()*/216 /* ~GRIBRasterBand() */ 218 217 /************************************************************************/ 219 218 … … 303 302 free (buff); 304 303 char * errMsg = errSprintf(NULL); 304 CPLDebug( "GRIB", "%s", errMsg ); 305 305 free(errMsg); 306 306 return NULL; … … 339 339 int msgNum =0; /* The messageNumber during the inventory. */ 340 340 341 if (GRIB2Inventory (grib_fp, &Inv, &LenInv, 0, &msgNum) >= 0) 342 { 343 for (uInt4 i = 0; i < LenInv; ++i) 341 if (GRIB2Inventory (grib_fp, &Inv, &LenInv, 0, &msgNum) <= 0 ) 342 { 343 CPLError( CE_Failure, CPLE_OpenFailed, 344 "%s is a grib file, but no raster dataset was successfully identified.", 345 poOpenInfo->pszFilename ); 346 delete poDS; 347 return NULL; 348 } 349 350 /* -------------------------------------------------------------------- */ 351 /* Create band objects. */ 352 /* -------------------------------------------------------------------- */ 353 for (uInt4 i = 0; i < LenInv; ++i) 354 { 355 uInt4 bandNr = i+1; 356 if (bandNr == 1) 344 357 { 345 uInt4 bandNr = i+1; 346 if (bandNr == 1) 358 // important: set DataSet extents before creating first RasterBand in it 359 double * data = NULL; 360 grib_MetaData* metaData; 361 GRIBRasterBand::ReadGribData(grib_fp, 0, Inv[i].subgNum, &data, &metaData); 362 if (metaData->gds.Nx < 1 || metaData->gds.Ny < 1 ) 347 363 { 348 // important: set DataSet extents before creating first RasterBand in it 349 double * data = NULL; 350 grib_MetaData* metaData; 351 GRIBRasterBand::ReadGribData(grib_fp, 0, Inv[i].subgNum, &data, &metaData); 352 poDS->SetMetaData(metaData); // set the DataSet's x,y size, georeference and projection from the first GRIB band 353 GRIBRasterBand* gribBand = new GRIBRasterBand( poDS, bandNr, Inv[i].start, Inv[i].subgNum, Inv[i].longFstLevel); 354 gribBand->m_Grib_Data = data; 355 gribBand->m_Grib_MetaData = metaData; 356 poDS->SetBand( bandNr, gribBand); 364 CPLError( CE_Failure, CPLE_OpenFailed, 365 "%s is a grib file, but no raster dataset was successfully identified.", 366 poOpenInfo->pszFilename ); 367 delete poDS; 368 return NULL; 357 369 } 358 else 359 poDS->SetBand( bandNr, new GRIBRasterBand( poDS, bandNr, Inv[i].start, Inv[i].subgNum, Inv[i].longFstLevel)); 360 GRIB2InventoryFree (Inv + i); 370 371 poDS->SetGribMetaData(metaData); // set the DataSet's x,y size, georeference and projection from the first GRIB band 372 GRIBRasterBand* gribBand = new GRIBRasterBand( poDS, bandNr, Inv[i].start, Inv[i].subgNum, Inv[i].longFstLevel); 373 gribBand->m_Grib_Data = data; 374 gribBand->m_Grib_MetaData = metaData; 375 poDS->SetBand( bandNr, gribBand); 361 376 } 362 free (Inv); 363 } 377 else 378 poDS->SetBand( bandNr, new GRIBRasterBand( poDS, bandNr, Inv[i].start, Inv[i].subgNum, Inv[i].longFstLevel)); 379 GRIB2InventoryFree (Inv + i); 380 } 381 free (Inv); 364 382 365 383 /* -------------------------------------------------------------------- */ … … 376 394 /************************************************************************/ 377 395 378 void GRIBDataset::Set MetaData(grib_MetaData* meta)396 void GRIBDataset::SetGribMetaData(grib_MetaData* meta) 379 397 { 380 398 nRasterXSize = meta->gds.Nx;
