[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #RQJ-625597]: cannot read or write netcdf files (Linux)



Cameron,

Maybe you are calling your read_netcdf subroutine with parameters of
the wrong type.  I made up a little main program to call it, and
everything came out as expected.

      program main
      parameter(LEN_T=4,LEN_SURFACE=1,LEN_LATITUDE=10,LEN_LONGITUDE=29)
      real latitude(LEN_LATITUDE)
      real longitude(LEN_LONGITUDE)
      real surface(LEN_SURFACE)
      real t(LEN_T)
      real TP(LEN_LONGITUDE,LEN_LATITUDE,LEN_SURFACE,LEN_T)

      character*200 file_name
      file_name = 'bgp_precip.nc'

      call read_netcdf(file_name, LEN_T, LEN_SURFACE, LEN_LATITUDE,
     & LEN_LONGITUDE, t, surface, latitude, longitude, TP)

      end

I put this in a file named "cameron.f" along with your read_netcdf
subroutine and compile it like this:

 f77 -g -o cameron -I/usr/local/include cameron.f -L/usr/local/lib -lnetcdf

Then run it and get all the latitudes and longitudes to be what are
expected.  However, I had to add a print statement for latitude,
because you only printed out the status of the call and not the
latitude values:

      status = nf_get_var_real(ncid, latitude_id, latitude)
      print *, status
      if (status .ne. nf_noerr) stop 'nf_get_var_real'

and similarly for the "t" variable.

You might want to print the value of "t_len" and "surface_len" inside
your read_netcdf subroutine for debugging, in case you used real
parameters instead of integers in calling this subroutine.

As some advice for the future, your subroutine reads whole netCDF
variables into program variables, such as TP.  Usually the variables
in the netCDF file are larger than what you want to read into your
program all at once.  For example, you would typically read in a
single time-step or a slice of a multidimensional variable with a call
to nf_get_vara_real() rather than nf_get_var_real().  The "vara" call
takes a couple of extra arguments to specify what subset of data you
want from the variable.

There is a warning about using the "var" functions with record
variables that is in the C and Fortran-90 user guides:

  Take care when using the simplest forms of this interface with
  record variables when you don't specify how many records are to be
  read. If you try to read all the values of a record variable into an
  array but there are more records in the file than you assume, more
  data will be read than you expect, which may cause a segmentation
  violation.

which should also be in the F77 manual, but apparently it's not.  I'll
add that warning for the next version.

--Russ

Russ Rew                                         UCAR Unidata Program
address@hidden                     http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: RQJ-625597
Department: Support netCDF
Priority: Normal
Status: Closed