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, Your subject line asked how to compile and run sample netCDF programs, but didn't mention whether you want to use C, Fortran, or some other programming language. For C, see the documentation section "1.6 Compiling and Linking with the NetCDF Library": http://www.unidata.ucar.edu/netcdf/docs/netcdf-c.html#Compiling For Fortran, see the similar section in the Fortran NetCDF Users Guide: http://www.unidata.ucar.edu/netcdf/docs/netcdf-f90.html#Compiling-and-Linking-with-the-NetCDF-Library As an example, assume you want to compile and run the program simple_xy_wr.c from the downloadable netCDF example programs listed here: http://www.unidata.ucar.edu/netcdf/examples/programs/ If you had netCDF-3 installed in /opt, then you could do it like this on most Unix platforms: $ cc -I/opt/include simple_xy_wr.c -o simple_xy_wr -L/opt/lib -lnetcdf $ ./simple_xy_wr *** SUCCESS writing example file simple_xy.nc! If instead you had installed netCDF-4 with OPeNDAP support, you would need a few more libraries, for which the "nc-config" program would help: $ cc -I/opt/include simple_xy_wr.c -o simple_xy_wr `nc-config --libs` $ ./simple_xy_wr *** SUCCESS writing example file simple_xy.nc! You can even use the nc-config program to provide the C flags: $ cc `nc-config --cflags` simple_xy_wr.c -o simple_xy_wr `nc-config --libs` and similarly with Fortran: $ f95 `nc-config --fflags` simple_xy_wr.f -o simple_xy_wr `nc-config --flibs` --Russ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: PPR-499757 Department: Support netCDF Priority: High Status: Closed