NEP 2.7.0
NetCDF Extension Pack
Loading...
Searching...
No Matches
Functions/Subroutines
f_quickstart.f90 File Reference

Minimal introduction to NetCDF from Fortran - the simplest starting point. More...

Functions/Subroutines

program f_quickstart
 
subroutine check (status, context)
 Error handling subroutine.
 

Detailed Description

Minimal introduction to NetCDF from Fortran - the simplest starting point.

This is the most basic NetCDF example in Fortran, demonstrating the essential 6-step pattern:

  1. Create file (nf90_create)
  2. Define dimensions (nf90_def_dim)
  3. Define variables (nf90_def_var)
  4. Add attributes (nf90_put_att)
  5. Write data (nf90_put_var)
  6. Close file (nf90_close)

The program creates a tiny 2D array (2x3) with 6 integer values, adds descriptive attributes, writes it to a file, then reopens and reads the data back to verify the round-trip worked.

Learning Objectives:

Key Concepts:

Fortran vs C Differences:

Prerequisites: Basic Fortran 90 programming knowledge

Related Examples:

Compilation:

gfortran -o f_quickstart f_quickstart.f90 -lnetcdff -lnetcdf
program f_quickstart
Definition f_quickstart.f90:75

Usage:

Expected Output: Creates f_quickstart.nc containing:

Note
Companion code for "The NetCDF Developer's Handbook: The Authoritative Guide to Writing High-Performance Programs for Scientific Data Management, Second Edition" (https://www.amazon.com/dp/B0H7Q1Z75L)
Author
Edward Hartnett
Date
2026-01-29

Function/Subroutine Documentation

◆ check()

subroutine f_quickstart::check ( integer, intent(in)  status,
character(len=*), intent(in)  context 
)

Error handling subroutine.

Parameters
statusNetCDF return status code
contextDescriptive message about the operation

◆ f_quickstart()

program f_quickstart