#include "TKheaders.h"
#include "TK_3GPROF.h"

int main(int argc, char *argv[]){

    /* declare Data struct */
    TKINFO granuleHandle3GPROF;
    L3GPROF_GRID  L3GPROF;

    /* declare character */
    char job[256];
    char inputfile[256];

    strcpy(job, argv[1]);
    strcpy(inputfile, argv[2]);

    /* declare variables */
    int i, j, k, l, m, n;
    int status;
 
    /* declare array */
    float  surfacePrecipitation[1440][720];

    /* HDF file open */
    /*status = TKopen(inputfile, "3GPROF", TKREAD, "HDF5", job, &granuleHandle3GPROF, 1);*/
    status = TKopen(inputfile, "3GPROF", TKREAD, "NETCDF4", job, &granuleHandle3GPROF, 1);
    if(status != TK_SUCCESS) {
        fprintf(stderr, "error:file open error[%s] input3GPROF\n", inputfile);
    }

    /* Grid data read */
    status = TKreadGrid( &granuleHandle3GPROF, &L3GPROF);

    /* surfacePrecipitation data read */
    for (j=0; j<1440; j++){
	for (k=0; k<720; k++){
	       surfacePrecipitation[j][k] = L3GPROF.surfacePrecipitation[j][k];
	       if( j==1109 && k==409 ) printf("surfacePrecipitation[%d][%d]= %f (mm/hr)\n",
                                              j, k, surfacePrecipitation[j][k]);	
	}
    }

    /* HDF File close*/
    status = TKclose(&granuleHandle3GPROF);

    return 0;
}

