#include <stdlib.h> 
#include <string.h> 
#include "hdf5.h"
int main(){

    hid_t  file_id, dataset_id;

    /* declare character */
    char inputfile[256]= "../data/GPM/DPR/GPMCOR_DPR_2604010211_0345_068594_L2S_DD2_08A.nc";
    char dsetname[32]= "/FS/SLV/precipRateESurface";

    /* declare variables */
    int ret;
 
    /* declare array */
    float precipRateESurface[7988][49];

    /* HDF file open */
    file_id = H5Fopen(inputfile, H5F_ACC_RDONLY, H5P_DEFAULT);
    //printf("H5Fopen=%d \n", file_id);
    if(file_id < 0 ) {
        fprintf(stderr, "error:file open error[%s] \n", inputfile);
    }
    else
    { 
        /* dataset open */
        dataset_id = H5Dopen(file_id, dsetname, H5P_DEFAULT);
        //printf("H5Dopen=%d \n", dataset_id); 
        if(dataset_id < 0 ) {
            fprintf(stderr, "error:file open error[%s] \n", inputfile);
        }
        else
        {    
            /* precipRateESurface read   */
            ret = H5Dread(dataset_id,H5T_NATIVE_FLOAT,H5S_ALL,H5S_ALL, H5P_DEFAULT, precipRateESurface);
            //printf("H5Dread=%d \n", ret); 
            if(ret < 0) {
                fprintf(stderr, "error:Dataset read error[%s]\n", inputfile);
            }   
            else
            {
                /* file,dataset print */
                printf("file name= %s \n", inputfile);
                printf("data set name= %s \n", dsetname);
                /* precipRateESurface print */
                printf("precipRateESurface[5210][43]= %f (mm/hr)\n", precipRateESurface[5210][43]);
            } 
            /* detaset close   */
            ret = H5Dclose(dataset_id);
        }
        /* HDF file close   */
        ret = H5Fclose(file_id);
    }
    return 0;
}

