User-Defined Derived-Type I/O

User-Defined Derived-Type I/O#

WRITE(FORMATTED) – Render Model Objects#

Synopsis

WRITE(UNIT, FMT[, IOSTAT, IOMSG]) OBJECT

Class

Defined formatted output.

Description

Write an error_type, dimension_type, attribute_type, variable_type, group_type, or netcdf_type. List-directed output (FMT=*) and the DT edit descriptor are supported. Model objects render in an ncdump-like representation; error_type renders its NetCDF status and, when available, diagnostic message.

Arguments

UNITINTEGER, INTENT(IN)
Connected formatted I/O unit.

FMTCHARACTER(LEN=*), INTENT(IN)
* for list-directed output or a format containing DT.

OBJECTTYPE(ERROR_TYPE), TYPE(DIMENSION_TYPE), TYPE(ATTRIBUTE_TYPE), TYPE(VARIABLE_TYPE), TYPE(GROUP_TYPE), OR TYPE(NETCDF_TYPE), INTENT(IN)
Object to render.

IOSTATINTEGER, OPTIONAL, INTENT(OUT)
Receives the formatted I/O status.

IOMSGCHARACTER(LEN=*), OPTIONAL, INTENT(INOUT)
Receives an I/O diagnostic when the write fails.

Example

use, non_intrinsic :: nc4f
implicit none (type, external)

integer :: file_unit, iostat
character(len=256) :: iomsg
type(dimension_type) :: time

time = "time" .dim. 24
open (newunit=file_unit, file="model.txt", status="replace", &
  & action="write", form="formatted", iostat=iostat, iomsg=iomsg)
if (iostat == 0) write (file_unit, "(dt)", iostat=iostat, iomsg=iomsg) time
close (file_unit)