/* Read data from an HDF4 file. Assume the array has been setup correctly. If mode is 0 then just read the rank and dim data. If mode is 1 then read the data as well. */ int ReadHDF(char *filename,float *array,int *rank,int *dims,int mode) { int sd_id, sds_id, sds_idx; int n_datasets, n_file_attrs; int start[2], edges[2]; int num_type, attributes; intn istat; char name[64]="\0"; int i; // Read data back and write to a new array if ((sd_id = SDstart(filename, DFACC_READ)) == FAIL) { fprintf(stderr,"SDstart() failed\n"); return(FALSE); } // Determine the contents of the file. istat = SDfileinfo(sd_id,&n_datasets,&n_file_attrs); sds_idx = SDnametoindex (sd_id,"image_data"); if (sds_idx == FAIL) // norm/sino/recon data sets sds_idx = SDnametoindex(sd_id,"data"); sds_id = SDselect (sd_id, sds_idx); // Read from file: rank, dims, num_type and attribute istat = SDgetinfo(sds_id,name,rank,dims,&num_type,&attributes); //fprintf(stderr,"Rank: %d\n",*rank); if (mode == 1) { // Define the location, and size of the data set for (i=0;i<*rank;i++) { start[i] = 0; edges[i] = dims[i]; //fprintf(stderr," Rank: %d, dimension: %d\n",i,dims[i]); } istat = SDreaddata(sds_id,start,NULL,edges,array); } // Terminate access to the array. istat = SDendaccess(sds_id); // Terminate access to the SD interface and close the file. istat = SDend(sd_id); return(TRUE); }