/*************************************************************************** * Copyright (C) 2006 by Nicolas PASCAL * * pascal@icare-pc12 * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "hdffiledata.h" #include int main(int argc, char *argv[]) { const int X_LENGTH = 5; const int Y_LENGTH = 5; const char* SDS_NAME = "Latitude"; const char* TEST_FILE = "/home/pascal/DATA/LIENS/MODIS/MYD06_L2/2004/2004_01_01/MYD06_L2.A2004001.0000.004.2004077230457.hdf"; /* Open and create the access to the file */ HDFFileData hdf(TEST_FILE); /* load the file before accessing the data */ hdf.load_hdf_file(); /********************************* ******** load a partial sds ****** *********************************/ /* Define the limits of the data selection */ int start[] = {0,0}; int edges[] = {Y_LENGTH,X_LENGTH}; int rank = 2; // dimension of start and edges array /* Declare the buffer */ float data[Y_LENGTH][X_LENGTH]; /* Read the data */ hdf.read_data((void*)data,SDS_NAME,start,NULL,edges,rank); /* Print it */ for (int j = 0; j < Y_LENGTH ; j++) { for (int i = 0; i < X_LENGTH; i++) printf ("%e ", data[j][i]); printf ("\n"); } /******************************************/ /****** load the whole latitude sds *******/ /******************************************/ /* declare a pointer to the data buffer. The allocation is delegate to the read_data method */ float *data2=NULL; /* Read the data. The dynamic allocation is done inside the read_data method */ data2=hdf.read_data(data2,SDS_NAME); /* As the allocation is dynamic, don't forget to delete the data' buffer once used */ delete[] data2; /**********************************************/ /***** access to the dimensions of an sds *****/ /**********************************************/ vector dim=hdf.get_dataset_dimension(SDS_NAME); for (uint i = 0 ; i