Opened 10 years ago

Closed 9 years ago

#5613 closed task (invalid)

unable to read Watervapour band of hdf file taken by 3DIMG payload using gdal apis

Reported by: mahiprajapati123 Owned by: warmerdam
Priority: highest Milestone:
Component: GDAL_Raster Version: unspecified
Severity: major Keywords:
Cc:

Description

Hello, I am new to gdal.I want to write a program using GDAL APIs in c++ which open a hdf file taken by 3DIMG payload(ex. 3DIMG_07JUL2014_0000_L1B_STD.h5) and extract out all its band. My program works fine for 5 bands MIR,SWIR,TIR,TIR1,VIS but as it call same function for watervapour(WV) band it shows me memory curruption error.can anybody help me to resolve this error???

I also tried to dump the same file using h5dump and it works fine.so there is no problem with file.then why gdal can not read only WV band?

I am using gdal-1.11.0 and hdf-1.8.7 . Any help would be appreciated. Thank you.

Change History (8)

comment:1 by Even Rouault, 10 years ago

Attaching the file if it is small or including a link to it might be a start. You can also check if gdalinfo -checksum works fine. If it does, then it is very likely an issue in your program

in reply to:  1 comment:2 by mahiprajapati123, 10 years ago

Hi,

first of all thanks for your quick reply..i tried gdalinfo -checksum for watervapour band. command is: ./gdalinfo -checksum HDF5:"/home/chehar-pc/Desktop/3DIMG_12JUN2014_0300_L1B_STD.h5":IMG_WV and output is:Segmentation fault (core dumped) this command works fine for other band. also i attach program..if possible direct me for how to get out of this error? sry i cant attach hdf file as privacy reasons my institute in which i am working. Thank You, Mahi

program:

#include "gdal_priv.h"
#include "cpl_conv.h" // for CPLMalloc()
#include <iostream>
#include <cstdlib>
#include <string>



static void read_dataset(const char *objpath)
{
  GDALDataset *poDataset;

  // open a child object that corresponds to an HDF5 dataset
  poDataset = (GDALDataset *)GDALOpen(objpath, GA_ReadOnly);
  if (!poDataset) {
    std::cerr << "cannot open " << objpath << std::endl;
    return;
  }
  

  // read dimension sizes
  int xsize = poDataset->GetRasterXSize();
  int ysize = poDataset->GetRasterYSize();
  
 std::cout << "X size = " << xsize << ", " << "Y size = " << ysize << std::endl;
  int num = poDataset->GetRasterCount();
  std::cout<<"total band is:"<<num<<'\n';

  //read elements
  unsigned short *buffer = new unsigned short[xsize * ysize];
  GDALRasterBand *rb = poDataset->GetRasterBand(1);
  GDALDataType dtype = rb->GetRasterDataType();
  std::cout<<GDALGetDataTypeName(dtype)<<'\n';
  if(strcmp((GDALGetDataTypeName(dtype)),"UInt16")==0)
  {
 
   Size[0]=xsize;
   Size[1]=ysize;
  
   rb->RasterIO(GF_Read, 0, 0, xsize, ysize,buffer, xsize, ysize,GDT_UInt16, 0, 0);
   
  for (int j = 0; j < ysize; ++j) {
    for (int k = 0; k < xsize; ++k) {
      std::cout << localBuffer[j * xsize + k] << " "<<'\n';
    }
    std::cout << std::endl;
  
  }
  
 
  
  delete [] buffer;
 }
}

static void read_ae_rngd(const char *filename,const char *str)
{
  GDALDataset *poDataset;

  // open an HDF5 file
  poDataset = (GDALDataset *)GDALOpen(filename, GA_ReadOnly);
  if (!poDataset) {
    std::cerr << "cannot open " << filename << std::endl;
    return;
  }

   //dump the first HDF5 attribute
 /*char **metadata = poDataset->GetMetadata("");
  if (metadata) {
    std::cout << "metadata: " << *metadata << std::endl;
  }

 std::cout<<"hello"<<'\n';

  // open the first child object
 /* char **children = poDataset->GetMetadata("SUBDATASETS");
  if (children) {
    const char *objpath = strstr(*children, "=");
    objpath++;

    std::cout << "child: " << objpath << std::endl;
    read_dataset(objpath);
  }*/
    // recursively dump all child objects
 
    char **children = poDataset->GetMetadata("SUBDATASETS");
    if (children) {
      // need to skip SUBDATASET_?_DESC;
      // we only need SUBDATASET_?_NAME here
      for (char **child1 = children; *child1; child1 += 2) {
        if(child1)
        {
	const char *name = strstr(*child1, "=");
	
         name++;

    std::cout << "child: " << name << std::endl;
	//if (!name) suicide();
        if(strcasestr(name,str))
	read_dataset(name);
       }
      }
    }
  
}

int main(int argc, char **argv)
{
  typedef unsigned short PixelType;
 // const char dir_path=argv[1];
  
  
  GDALAllRegister();

  read_ae_rngd("/data2/trainee/payal/otb123/3DIMG_12JUN2014_0300_L1B_STD.h5","WV");

  return 0;
}

// vim:ts=8:sw=2:sts=2

comment:3 by Even Rouault, 10 years ago

If gdalinfo -cheksum fails then it is a bug in the GDAL HDF5 driver. Nothing you can really do in your own code. I can try to investigate within the driver but i need access to the data to be able to debug. You can privately send me a file or link by email to "contact at spatialys.com"

in reply to:  3 comment:4 by mahiprajapati123, 10 years ago

Hi,

Sry ,I cant upload the file as i am working in ISRO(Indian Space Research Organization),India and Authorities dont allow me to disclose any other information. if possible suggest me solution.sorry again.

Thank You, mahi

comment:5 by Even Rouault, 10 years ago

This is the kind of issue that cannot be solved without access to the data. Maybe you have internal qualified ressources for that or you can try to contract an Indian based GDAL service provider : http://www.osgeo.org/search_profile?SET=1&MUL_COUNTRY%5B%5D=00003&MUL_TECH%5B%5D=00013

comment:6 by mahiprajapati123, 10 years ago

Hey rouault,

I want solution for my problem.I mailed u an .h5 file with randomly generated data containing only two bands- WaterVapour and MIR(It is created using the same way as 3DIMG hdf file). same problem as mentioned in the first post with this file.I can successfully read MIR band but can not read WV band. gdalinfo -checksum fails for WV band. I have tried for hdf file containing only WV band and it works fine but when i add another band gdal stop working for WV band only, for other band it works fine.now u can figure out problem with gdal hdf5 driver using this file.

Thank you, Mahi

comment:7 by mahiprajapati123, 10 years ago

hello,

I am not able to mail you.delivery report failed. Also file attachment exceeds the size limit provided here.what to do?

comment:8 by Even Rouault, 9 years ago

Resolution: invalid
Status: newclosed

I couldn't find any related file in my mailbox. Perhaps I've lost it... Anyway there's no point keeping that ticket open since nobody can do action on it without data

Note: See TracTickets for help on using tickets.