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

Re: ncdinq question



> Organization: CSU
> Keywords: 199401172026.AA11513

Hi Doug,

Did you ever get a satisfactory answer to your question about NCDINQ?

> I was wondering if anyone can help me with a problem I've been  
> experiencing while trying to use ncdinq.  Here is my code :
> 
>       include '/usr/local/src/netcdf/fortran/netcdf.inc'
> 
>       parameter (ndims=1)
> c      parameter (maxncnam = 36)
> 
>       integer cdfid, rcode, start(ndims), count(ndims)
>       integer pid, tid, dpid, rhid, timeid, times
> 
>       character file*30, timename*36
> 
>       print *,'Please enter netCDF file name :'
>       read *,file
>       print *,'Processing ',file,' ...'
> 
> C  (1)NetCDF subroutine to open netCDF file.
>       cdfid = ncopn(file, ncnowrit, rcode)
> 
> C  (2)NetCDF subroutines to find out ID and size of time dimension.
>       timeid = ncdid(cdfid,'time ',rcode)
>       call ncdinq(cdfid,timeid,timename,times,rcode)
> 
> ......
> 
> C  (7)NetCDF subroutine to close open netCDF file.
>       call ncclos(cdfid, rcode)
> 
> 
>       end
> 
> The program compiles alright, but the problem is I keep getting this  
> message when trying to run it :
> NCDINQ: string won't fit in CHARACTER variable provided

You didn't say what platform you are using; it's possible that the Fortran
interface for netCDF has been incorrectly built or installed for your
platform.  When the netCDF library is built and installed, there is a test
program for the Fortran interface that is generated in the netcdf/fortran
directory.  This test program is run if you type "make test" in the netcdf
source directory or in the netcdf/fortran directory.  The test program makes
calls to ncdinq, storing the returned dimension names in variables
declared to be of type "character*31", so if this works, then your program
should work also.  The Fortan interface relies on the size of the character
variable for the dimension name being passed into the ncdinq function
correctly.  You can test whether this is working

> I have done print statements to verify that cdfid and timeid are being  
> returned correctly, and they are.
> 
> I have tried making the character variable timename as big as 100000, and  
> I still get this message.  I'm also curious about the role of "maxncnam"  
> in all this.  The manual says that "The maximum possible length, in  
> characters, of a dimension name is given by the predefined constant  
> maxncnam.  As you can see by the parameter statement commented out above,  
> I thought maybe this was something I was supposed to specify, and I tried  
> it, but to no avail.  Any ideas what I'm doing wrong?

You should not define maxncnam, it is already defined (as 128) in the
netcdf.inc file you have included.  The reason the netcdf.inc file is
included is to define and declare all the constants used in the netcdf
interface.

> A second more general question I have is the netCDF files I'm using  
> (atmospheric soundings) all have differing dimensions for the time  
> variable.  Thus, I'm trying to use the routines in the above segment of  
> code to identify the size of the time dimension, to subsequently use as  
> the size of the other variables' arrays (ie pressure, temperature, etc.) I  
> want to read off the file.  The problem here is my compiler complains  
> about using dummy arrays as adjustable arrays, since the size of the  
> arrays has not really been defined at the time of compilation.  Any way  
> around this?  Should I just write the rest of the program as a subroutine,  
> and not declare pressure, temperature, etc., as reals in the main program?

Fortran requires that the size of actual arrays is known at compile time.
There is no way around this in standard Fortran 77.  You have to pick a
maximum size in the main program or wherever you are actually allocating the
storage to be used.  You could use dummy arrays to divide up one large array
of reals into variable size vectors, using pieces of the array in calls to
subroutines, but somewhere the real array has to be allocated.

C permits malloc() calls to get memory at execution time for variable size
arrays.  Perhaps your Fortran compiler has an extension that permits
run-time allocation for arrays.

__________________________________________________________________________
                      
Russ Rew                                              UCAR Unidata Program
address@hidden                                        P.O. Box 3000
(303)497-8645                                 Boulder, Colorado 80307-3000