Skip to main content

Error Checking

Subroutines for validating NetCDF operations and memory allocation.

check (Generic Interface)

The check interface dispatches to three subroutines based on arguments:

checkerror

General NetCDF status check. Aborts with a colored error message on failure.

call check(nf90_status)
ParameterIntentTypeDescription
nf90_statusinintegerReturn code from any nf90_* call

checktype

Validates that the declared FPL type matches the NetCDF variable type.

call check(nf90_status, vartype_code, declared_type_string, filepath)
ParameterIntentTypeDescription
nf90_statusinintegerNetCDF status
vartype_codeinintegerNetCDF variable type (1=byte, 3=short, 4=int, 5=float, 6=double)
declared_type_stringincharacter(*)Type declared by the user
filepathincharacter(*)File path for diagnostics

checkatt

Validates NetCDF attribute retrieval. Behavior depends on the attribute:

  • _FillValue: Aborts with an error message and ncatted suggestion to add the attribute
  • Other attributes (e.g., units): Prints a warning and continues processing, with an ncatted suggestion
call check(nf90_status, attribute_name, filepath)
ParameterIntentTypeDescription
nf90_statusinintegerNetCDF status
attribute_nameincharacter(*)Attribute name (e.g., "_FillValue")
filepathincharacter(*)File path for diagnostics

Standalone Subroutines

checkvarid

Checks nf90_inq_varid status. Aborts if variable not found.

call checkvarid(nf90_status, varname)

checkdimid

Checks nf90_inq_dimid status. Aborts if dimension not found.

call checkdimid(nf90_status, dimname)

check_alloc

Checks allocate / deallocate status.

integer :: istat
allocate(array(n), stat=istat)
call check_alloc(istat, "array")
ParameterIntentTypeDescription
istatinintegerStatus from stat= keyword
arrnameincharacter(*)Array name for error message

Extracts and prints the filename component from a full path.

call print_filename("/path/to/file.nc")
! Output: File: file.nc