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.
Stefan, > To: address@hidden > From: Stefan Maehlmann <address@hidden> > Subject: netcdf problem > Organization: UCAR/Unidata > Keywords: 200009151648.e8FGmtb07020 The above message contained the following: > i'm new with netcdf. But for most things, i tried up to now i works fine. > However i have a problem treating scalars and arrays: > I want to write a simple scalar value to a file and then an array. So i coded > up the following lines: > .... > > > integer, parameter :: time_rank = 0, & > val_rank = 2 > integer val_dims (val_rank) > > .... > > status = nf_def_var_double (ncid, 'time',nf_double,time_rank,0,time_id) > if (status.ne.0) then ... > > status = nf_def_var_double (ncid,'val',nf_double,val_rank, val_dims,val_id) > > if (status.ne.0) then ... > .... > > The compiler (NAG f95) says: > > .... inconstant structure for arg 5 in call to nf_def_var_double ... > > So there is a difference if i set the dim value in the function > nf_def_var_double to zero which should repreesent a scalar an for > examples to 2 (2-dim array) > > I don't know how to solve the problem in handling scalar and array. So > i please you to help me > > Thanx in advance, > > Stefan Maehlmann > ------------------------------------ > Stefan Maehlmann Email: address@hidden > Aerodynamisches Institut der RWTH-Aachen WWW: http://www.aia.rwth-aachen.de > Wuellnerstr. zw. 5 u. 7 Ftp: ftp://ftp.aia.rwth-aachen.de > D-52062 Aachen, Germany Phone: +49-241-80-5426 Fax: +49-241-8888-257 First off, you should used the function "nf_def_var" rather than "nf_def_var_double". Here's how to do what you want: integer, parameter :: time_rank = 0, & val_rank = 2 integer val_dims (val_rank) status = nf_def_var(ncid,'time',nf_double,time_rank,val_dims,time_id) status = nf_def_var(ncid,'val',nf_double,val_rank,val_dims,val_id) The key issue is that the dimension-array argument must have the same type in both calls (i.e. it must be a vector of integers). The argument will be ignored in the scalar case (i.e. where the rank is zero). Regards, Steve Emmerson <http://www.unidata.ucar.edu>