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.
Hi Lara, > I have recently starting using netcdf 4.1.2. in ifort on my Mac. I have > managed to build the code and have successfully managed to read in some > existing netcdf files, however I am having great difficulty writing to a > netcdf file. I get stuck on the step where I define my variables. > > I have written a very basic program to try to check that this is > working. I can write a single dimension variable but cannot write > multiple dimensional variables. I have basically copied a program from > the examples on your website and tried to change it for my use. > > Ignoring all my definitions for now, I have > > call check (nf90_create(filename, nf90_clobber,ncid)) > > call check (nf90_def_dim(ncid, 'lat', 90, lat_id)) > call check (nf90_def_dim(ncid,'lon',180,lon_id)) > > call check (nf90_def_var (ncid,'latitude',nf90_real,lat_id,latitude)) > call check (nf90_def_var (ncid,'longitude',nf90_real,lon_id,longitude)) > > This all works fine but if I try to define a variable with lat_id,lon_id > it doesn't compile > > call check > (nf90_def_var(ncid,'concentration',nf90_real,(lon_id,lat_id),concentration)) With a compiler that supports Fortran-90 or later, you should be able to use the following syntax for an array of dimids: call check(nf90_def_var(ncid,'concentration',nf90_real, (/ lon_id,lat_id /), concentration)) as in the Fortran-90 examples here: http://www.unidata.ucar.edu/netcdf/examples/programs/ Note the "(/" and "/)" syntax required for an array list constant, but you can also use a named variable to hold the dimension IDs, as in integer :: dimids(NDIMS) ... ! The dimids array is used to pass the dimids of the dimensions of ! the netCDF variables. Both of the netCDF variables we are creating ! share the same four dimensions. In Fortran, the unlimited ! dimension must come last on the list of dimids. dimids = (/ lon_id, lat_id /) ... call check(nf90_def_var(ncid,'concentration',nf90_real, dimids, concentration)) --Russ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: CPI-418355 Department: Support netCDF Priority: Normal Status: Closed