This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
>From: address@hidden >Subject: Error Question >Organization: Florida State University >Keywords: 199610312252.AA00481 netCDF Fortran Hi Dave, > I am trying to run a fortran program that will read in a netCDF > format file. I am trying to use the subroutine ncvgt to read in > data for a variable named pressure. After doing a net cdf dump > on the file I saw the following: > > dimensions: > time = UNLIMITED ; // (2308 currently) > > > float pres(time) ; > pres:units = "hPa" ; > pres:long_name = "Pressure" ; > pres:field_index = "1" ; > pres:resolution = "0.1 hPa" ; > After running my program I get the following error message: > > ncvarget: pres: Invalid Coordinates > > Could you please explain to me what this means? Yes. It means that the "start" and "count" vectors you passed to ncvgt (the Fortran subroutine that calls the C function ncvarget) specified invalid coordinates for the variable. The values start=1 and count=2308 were correct to read all the values of the pres variable, but you forgot to declare the "start" and "count" variables as type integer, so they were type real by default. The FORTRAN compiler doesn't check that the types of parameters are correct, so these real values just looked like very large integers to the ncvgt subroutine, which is why it reported "Invalid Coordinates". If you add the declaration integer start, count I think your program will do what you expect. To prevent such errors in the future, you also might want to add an "implicit none" declaration to make sure every variable has to be declared instead of getting a default type. > ********************************************************************** > * program prototype.f > * > * purpose: to practice reading and writing CDF data > * > * notes: to compile 1. f77 -c -I/path for file in include statement > * program.f > * 2. f77 -o output-file program.o -L/path for netcdf > * library -lnetcdf > * > ********************************************************************** > include '/usr/people/dave/include/netcdf.inc' > integer ncid,rcode > integer ndims,nvars,natts,recdim,timesize > integer timeid,btid,toid,pid > character*31 timename,recname,pname > integer ptype,pn,pdims(maxvdims),pnatt,pindx > real pressure(2308) > parameter(ndims=1,times=2308) > data start/1/ > data count/times/ > ncid=ncopn('test.cdf',ncnowrit,rcode) > call ncinq(ncid,ndims,nvars,natts,recdim,rcode) > timeid=ncdid(ncid,'time',rcode) > call ncdinq(ncid,timeid,timename,timesize,rcode) > pid= ncvid(ncid,'pres',rcode) > call ncvinq(ncid,pid,pname,ptype,pn,pdims,pnatt,rcode) > > write(*,*),'Hello' > call ncvgt(ncid,pid,start,count,pressure,rcode) > write(*,*),ncid > write(*,*),ndims,nvars,natts,recdim,rcode > write(*,*),timeid > write(*,*),timename,timesize > write(*,*),pid > write(*,*),pname,ptype,pn,pnatt > write(*,*),pressure > call ncclos(ncid,rcode) > end _____________________________________________________________________ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu