#include "TKheaders.h"
#include "TK_3GSLH.h"

#define LAT 268  /* number of resolution 0.5°grid intervals of latitude from 67°S to 67°N. */ 
#define LON 720  /* number of resolution 0.5°grid intervals of longitude from 180°W to 180°E. */
#define LAYER  80  /* number of layer */

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


    /* declare Data struct */
    TKINFO granuleHandle3GSLH;
    L3GSLH_GRID  L3GSLH;

    /* 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;
    float  lat,lon;
 
    /* declare array */
    float  allLHCndMean[80][720][268];

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

    /* Grid data read */
    status = TKreadGrid( &granuleHandle3GSLH, &L3GSLH);

    /* allLHCndMean read */
    for (j=0; j<LAYER; j++){
	  for (k=0; k<LON; k++){
        for (l=0; l<LAT; l++){
	      allLHCndMean[j][k][l] = L3GSLH.allLHCndMean[j][k][l];
		  if( j==1 && k==620 && l==200 ){ 
            lat = (134.0/268.0) * l - 67.0 + (134.0/268.0/2);
            lon = (360.0/720.0) * k - 180.0 + (360.0/72.0/2);
		    printf("lat=%f, lon=%f\n",lat,lon);
		    printf("allLHCndMean[%d][%d][%d]= %f (K/hr)\n",
                           j, k, l, allLHCndMean[j][k][l]);	
          }
	    }
	  }
    }

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

    return 0;
}

