Re: [netcdfgroup] 1995-era code

Hi Catherine:

Just a guess, but the include at:

#include "/usr/local/src/HDF4.2r3/hdf4/include/netcdf.h"

may not be compatible. Have you tried including instead the header file that comes with the netcdf library?

-Roy

On Jul 10, 2009, at 1:12 PM, Cronin, Catherine Kemble (LARC-B702) wrote:

I have a C program that was written in the 1995 time frame that reads a netCDF file. It uses “ncopen” and “ncinquire” calls, which I assume means it was from version 2. I did not write this program and do not have any experience with netCDF files directly. My SA installed the netCDF software (I believe it’s the latest version), and the HDF4 software and I have been able to successfully compile the C program. However, the ncopen call fails upon execution.

After a brief search, I found that I could check the libnetcdf.a file to see if the installation was backward compatible with the old version. Which I did, and here are the results from that:

nm -A libnetcdf.a | grep ncopen

libnetcdf.a:v2i.o:00000052 R $XBK2SpSrz1VKG1G.ncopen.__func__
libnetcdf.a:v2i.o:00000f40 T ncopen
libnetcdf.a:fort-v2compat.o:         U ncopen

So, it appears that the library does contain the old functions. Also, I can successfully run an ncdump on the file, so I don’t believe the netCDF file is corrupted.

Does anyone have any other ideas on what I could check or why I may not be able to open the file using ncopen? Any help would be greatly appreciated.

Cathy

/ *----------------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <time.h>
/ *----------------------------------------------------------------------------*/

#include "/usr/local/src/HDF4.2r3/hdf4/include/netcdf.h"

#define MAX_CHAR_STR_LEN 80

static char attname[MAX_CHAR_STR_LEN];
static char format_value[MAX_CHAR_STR_LEN];
static char output_format[MAX_CHAR_STR_LEN];

/*
   Find PrISM variables in HLFC netCDF file
*/
int netcdf2PrISM(netCDFfile, fp_out)
char *netCDFfile;
FILE *fp_out;
{

   int  ncid;                   /* netCDF id */
   int ndims;                  /* number of dimensions */
   int nvars;                  /* number of variables */
   int ngatts;    /* number of global attributes */
   int xdimid;                 /* id of unlimited dimension */

   char varname[MAX_NC_NAME];
   nc_type vartype;
   int varndims;
   int vardims[MAX_VAR_DIMS];
   int varnatts;
   long int start[1], count[1];
   void *value;

   int varid;
   int i;
   nc_type atttype;
   int attlen;
   void *attvalue;
   int default_format;


   char dimname[MAX_NC_NAME];
   long dimsize;

   strcpy (attname, "prism");
   /* customize netCDF error processing */
   /*dpr ncopts = NC_VERBOSE; dpr*/
   ncopts = 0;

   /* open netCDF file for reading */
   if ((ncid = ncopen (netCDFfile, NC_NOWRITE)) == -1)
    {
      fprintf (stderr,"HLFC netCDF file could not be opened\n");
      return(-1);
    }

   /* get information about netCDF file */
   if (ncinquire(ncid, &ndims, &nvars, &ngatts, &xdimid) == -1)
    {
      fprintf (stderr,"HLFC netCDF file ncinquire read error\n");
      return(-1);
    }

   /* loop thru the number of variables in netCDF file */
   for (varid=0; varid<nvars; varid++)
   {
if (ncvarinq(ncid,varid,varname,&vartype,&varndims,vardims,&varnatts)
          == -1)
      {
         fprintf (stderr,"HLFC netCDF file ncvarinq read error\n");
         return(-1);
      }

…………………………………………………. It goes on further, but hopefully this is enough to get the idea………………..
_______________________________________________
netcdfgroup mailing list
netcdfgroup@xxxxxxxxxxxxxxxx
For list information or to unsubscribe,  visit: 
http://www.unidata.ucar.edu/mailing_lists/

**********************
"The contents of this message do not reflect any position of the U.S. Government or NOAA."
**********************
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
1352 Lighthouse Avenue
Pacific Grove, CA 93950-2097

e-mail: Roy.Mendelssohn@xxxxxxxx (Note new e-mail address)
voice: (831)-648-9029
fax: (831)-648-8440
www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected"



  • 2009 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: