//-------------------------------------------------------------------------
//
//  This code was generated by cdf2c to read the netCDF data from the 
//  jes2_met1m.cdf file into memory.
//
//  NOTE:  The code creates global variables, but you may move the variable
//         definitions inside the read_netCDF_file procedure if you wish.
//         The code REQUIRES the netCDF C libraries to run, and assumes that
//         netcdf.h is in the common include path.  DON'T FORGET to link with
//         -lnetcdf -lsun when you compile the code.
//
//  This file contains the following routines:
//
//     read_netCDF_file - reads the data from the given netCDF file into memory
//     main - driver for program
//
//  History:
//  Date       Name          Action
//  ---------  ------------  -------------------------------------------------
//  ?? ??? ??  CIDS          Work in Progress.
//
//-------------------------------------------------------------------------

#include <netcdf.h>

// Variable definitions.  The comments contain the dimension names.
long   year[21480];                           // time
long   month[21480];                          // time
long   date[21480];                           // time
double hour[21480];                           // time
double dd[21480];                             // time
double longitude[21480];                      // time
double latitude[21480];                       // time
float  gyro_heading[21480];                   // time
float  wind_velocity_east[21480];             // time
float  wind_velocity_north[21480];            // time
float  t_air[21480];                          // time
float  relative_humidity[21480];              // time
float  barometric_pressure[21480];            // time
float  short_wave_rad[21480];                 // time
float  long_wave_rad[21480];                  // time
float  accum_precip[21480];                   // time
float  t_seasurface[21480];                   // time


void 
read_netCDF_file ()
{
   //# func_description
   //  This routine reads the data from jes2_met1m.cdf into memory.

   int   fd,ii;
   long  start[MAX_NC_VARS];
   long  end[MAX_NC_VARS];

   // Open the netCDF file.
   fd = ncopen("jes2_met1m.cdf", NC_NOWRITE);

   // Initialize start so all elements are zero.
   bzero(start, MAX_NC_VARS * sizeof(long));

   // Read in the variables and their attributes.
   // Read: year.
   end[0] = 21480;
   ncvarget(fd, 0, start, end, year);

   // Read: month.
   end[0] = 21480;
   ncvarget(fd, 1, start, end, month);
   for (ii=0;ii<10;ii++) {
     printf("%ld, %d\n",month[ii],ii);
   }
   
   // Read: date.
   end[0] = 21480;
   ncvarget(fd, 2, start, end, date);

   // Read: hour.
   end[0] = 21480;
   ncvarget(fd, 3, start, end, hour);

   // Read: dd.
   end[0] = 21480;
   ncvarget(fd, 4, start, end, dd);

   // Read: longitude.
   end[0] = 21480;
   ncvarget(fd, 5, start, end, longitude);

   // Read: latitude.
   end[0] = 21480;
   ncvarget(fd, 6, start, end, latitude);

   // Read: gyro_heading.
   end[0] = 21480;
   ncvarget(fd, 7, start, end, gyro_heading);

   // Read: wind_velocity_east.
   end[0] = 21480;
   ncvarget(fd, 8, start, end, wind_velocity_east);

   // Read: wind_velocity_north.
   end[0] = 21480;
   ncvarget(fd, 9, start, end, wind_velocity_north);

   // Read: t_air.
   end[0] = 21480;
   ncvarget(fd, 10, start, end, t_air);

   // Read: relative_humidity.
   end[0] = 21480;
   ncvarget(fd, 11, start, end, relative_humidity);

   // Read: barometric_pressure.
   end[0] = 21480;
   ncvarget(fd, 12, start, end, barometric_pressure);

   // Read: short_wave_rad.
   end[0] = 21480;
   ncvarget(fd, 13, start, end, short_wave_rad);

   // Read: long_wave_rad.
   end[0] = 21480;
   ncvarget(fd, 14, start, end, long_wave_rad);

   // Read: accum_precip.
   end[0] = 21480;
   ncvarget(fd, 15, start, end, accum_precip);

   // Read: t_seasurface.
   end[0] = 21480;
   ncvarget(fd, 16, start, end, t_seasurface);

   // Read in the Global Attributes.
   // Close the netCDF file.
   ncclose(fd);
}


void
main ()
{
   //# func_description
   //  This routine will serve as the driver for all processes affecting
   //  the netCDF data.

   // Read the netCDF data into memory.
   read_netCDF_file();

   // This is were you should begin adding code to act on the data.
}
