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 Mike, > I am a researcher at a US university and am using netCDF to process data. > I'm trying to output variables that I have read into the program using > netCDF. Attached is my fortran program. The data file I'm using is here: > > ftp://ftp.cdc.noaa.gov/Datasets/NARR/Dailies/monolevel/air.2m.1980.nc > > I am able to successfully read in each variable from the netCDF file, but > am unsure how to output them to a new netCDF file. The error I get is: > > NetCDF: Variable not found > STOP Error writing variable lat > > I'm wondering if I need to define a new variable before writing to file. > It should be obvious what I'm doing in this simple example. That's in > advance for the help. Yes, after you create a new netCDF file, it is empty, with no dimensions, variables, or attributes. Before writing data to a variable, you must define the necessary dimensions, define the variable, leave define mode, then write to the file. The error you are getting is because "ID_lat" is a variable ID for the open file you are reading, but has no meaning for the open file you are trying to write. When you define a variable in the output filem the NF_DEF_VAR function will return a variable ID you can use to refer to that variable. In general, variables in different files have different variable IDs, even if they have the same names. It may help to look at an example program for creating and writing a file, which you can find here: http://www.unidata.ucar.edu/software/netcdf/examples/programs/ --Russ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: QOP-799183 Department: Support netCDF Priority: Normal Status: Closed