/*--sample_readpathP_c---------------------------------------------------------
 * 
 *  This is a sample program that demonstrates the use of the the C functions
 *  to access HDF formatted pathP data files
 *---------------------------------------------------------------------------*/

# include <hdf.h>
# include <mfhdf.h>
# include <stdio.h>

main()
{
/* Internal variables */

  FILE    *fd;
  char    *hdf_file="sample.hdf";
  int32   ret,hdf_id;
/* Meta Data variables */

  char    project[256], dataset_name[256],source_name[256],
          start_date[20],stop_date[20],position_type[256],
          grid_type[256],grid_name[256],projection[256],
          reference_date[256], processing_level[256],
          Temporal_Res[256],Spatial_X_Res[256],Spatial_Y_Res[256];


  float32 lat[4],lon[4];

/* Scientific data sets */

  float32 temp[9][67][67], wvapor[5][67][67],sktemp[67][67],fcld[67][67],
          clpress[67][67],zangle[67][67], emiss[67][67],pbl_strat[67][67],
          Cd[67][67],alpha[67][67],cltemp[67][67],
          latgrid[67][67],longrid[67][67],
          temp_sd[9][67][67], wvapor_sd[5][67][67],sktemp_sd[67][67],fcld_sd[67][67],
          clpress_sd[67][67],zangle_sd[67][67], emiss_sd[67][67],pbl_strat_sd[67][67],
          Cd_sd[67][67],alpha_sd[67][67],cltemp_sd[67][67];

  int32   obs[67][67],IIIreject[67][67];

  ret=creadpathP(hdf_file, project,dataset_name,source_name,&processing_level,
		reference_date,start_date,stop_date,position_type,grid_type,
		grid_name,projection,lat,lon,Temporal_Res,Spatial_X_Res,
		Spatial_Y_Res,latgrid,longrid,temp,wvapor,sktemp,fcld,clpress,
		cltemp,zangle,emiss,pbl_strat,Cd,alpha,obs,IIIreject,
                temp_sd,wvapor_sd,sktemp_sd,fcld_sd,clpress_sd,
		cltemp_sd,zangle_sd,emiss_sd,pbl_strat_sd,Cd_sd,alpha_sd);


  fd = fopen("latgrid.tst","w");
  ret= fwrite(latgrid,sizeof(latgrid),1,fd);
  fclose(fd);

  fd = fopen("longrid.tst","w");
  ret= fwrite(longrid,sizeof(longrid),1,fd);
  fclose(fd);

  fd = fopen("temp.tst","w");
  ret= fwrite(temp,sizeof(temp),1,fd);
  fclose(fd);

  fd = fopen("wvapor.tst","w");
  ret= fwrite(wvapor,sizeof(wvapor),1,fd);
  fclose(fd);

  fd = fopen("sktemp.tst","w");
  ret= fwrite(sktemp,sizeof(sktemp),1,fd);
  fclose(fd);

  fd = fopen("fcld.tst","w");
  ret= fwrite(fcld,sizeof(fcld),1,fd);
  fclose(fd);

  fd = fopen("clpress.tst","w");
  ret= fwrite(clpress,sizeof(clpress),1,fd);
  fclose(fd); 

  fd = fopen("cltemp.tst","w");
  ret= fwrite(cltemp,sizeof(cltemp),1,fd);
  fclose(fd); 

  fd = fopen("zangle.tst","w");
  ret= fwrite(zangle,sizeof(zangle),1,fd);
  fclose(fd);

  fd = fopen("emiss.tst","w");
  ret= fwrite(emiss,sizeof(emiss),1,fd);
  fclose(fd);

  fd = fopen("pbl_strat.tst","w");
  ret= fwrite(pbl_strat,sizeof(pbl_strat),1,fd);
  fclose(fd);

  fd = fopen("Cd.tst","w");
  ret= fwrite(Cd,sizeof(Cd),1,fd);
  fclose(fd);

  fd = fopen("alpha.tst","w");
  ret= fwrite(alpha,sizeof(alpha),1,fd);
  fclose(fd);

  fd = fopen("sdtemp.tst","w");
  ret= fwrite(temp_sd,sizeof(temp_sd),1,fd);
  fclose(fd);

  fd = fopen("sdwvapor.tst","w");
  ret= fwrite(wvapor_sd,sizeof(wvapor_sd),1,fd);
  fclose(fd);

  fd = fopen("sdsktemp.tst","w");
  ret= fwrite(sktemp_sd,sizeof(sktemp_sd),1,fd);
  fclose(fd);

  fd = fopen("sdfcld.tst","w");
  ret= fwrite(fcld_sd,sizeof(fcld_sd),1,fd);
  fclose(fd);

  fd = fopen("sdclpress.tst","w");
  ret= fwrite(clpress_sd,sizeof(clpress_sd),1,fd);
  fclose(fd); 

  fd = fopen("sdcltemp.tst","w");
  ret= fwrite(cltemp_sd,sizeof(cltemp_sd),1,fd);
  fclose(fd); 

  fd = fopen("sdzangle.tst","w");
  ret= fwrite(zangle_sd,sizeof(zangle_sd),1,fd);
  fclose(fd);

  fd = fopen("sdemiss.tst","w");
  ret= fwrite(emiss_sd,sizeof(emiss_sd),1,fd);
  fclose(fd);

  fd = fopen("sdpblstrat.tst","w");
  ret= fwrite(pbl_strat_sd,sizeof(pbl_strat_sd),1,fd);
  fclose(fd);

  fd = fopen("sdCg.tst","w");
  ret= fwrite(Cd_sd,sizeof(Cd_sd),1,fd);
  fclose(fd);

  fd = fopen("sdalpha.tst","w");
  ret= fwrite(alpha_sd,sizeof(alpha_sd),1,fd);
  fclose(fd);



  fd = fopen("IIIreject.tst","w");
  ret= fwrite(IIIreject,sizeof(IIIreject),1,fd);
  fclose(fd);

  fd = fopen("obs.tst","w");
  ret= fwrite(obs,sizeof(obs),1,fd);
  fclose(fd);

  fprintf(stdout,"%s\n",project);
  fprintf(stdout,"%s\n",dataset_name);
  fprintf(stdout,"%s\n",source_name);
  fprintf(stdout,"%s\n",processing_level);
  fprintf(stdout,"%s\n",reference_date);
  fprintf(stdout,"%s\n",start_date);
  fprintf(stdout,"%s\n",stop_date);
  fprintf(stdout,"%s\n",position_type);
  fprintf(stdout,"%s\n",grid_name);
  fprintf(stdout,"%s\n",grid_type);
  fprintf(stdout,"%s\n",projection);

  fprintf(stdout,"%s\n",Temporal_Res);
  fprintf(stdout,"%s\n",Spatial_X_Res);
  fprintf(stdout,"%s\n",Spatial_Y_Res);


  fprintf(stdout,"Lat: %f-%f-%f-%f\n",lat[0],lat[1],lat[2],lat[3]);
  fprintf(stdout,"Lon: %f-%f-%f-%f\n",lon[0],lon[1],lon[2],lon[3]);
  if (ret < 0) {
    fprintf(stderr,"Error reading pathP hdf file : %s\n",hdf_file);
    exit(1);
  }
  else {
    fprintf(stderr,"Sucessfully read pathP hdf file : %s\n",hdf_file);
    exit(0);
  }
}












