Commit a58d9713 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Make Fortran 2003 example friendly to gfortran 4.3.

* This circumvents a compiler bug when using character valued functions
  in calls to WRITE.
* Also add exit status to STOP, it is not 1 on all platforms.
parent 2b4a13c0
......@@ -9,14 +9,15 @@ PROGRAM CDIREADF2003
INTEGER :: streamID, varID, gridID, zaxisID
INTEGER :: tsID, vlistID, taxisID
DOUBLE PRECISION, ALLOCATABLE :: field(:,:)
CHARACTER(kind=c_char,len=256) :: name, longname, units
CHARACTER(kind=c_char,len=256) :: name, longname, units, msg
! Open the dataset
streamID = streamOpenRead(C_CHAR_"example.nc"//C_NULL_CHAR)
IF ( streamID < 0 ) THEN
PRINT *,'Could not Read the file.'
WRITE(0,*) cdiStringError(streamID)
STOP
PRINT *, 'Could not Read the file.'
msg = cdiStringError(streamID)
WRITE(0,*) msg
STOP 1
END IF
! Get the variable list of the dataset
......@@ -29,7 +30,7 @@ PROGRAM CDIREADF2003
CALL vlistInqVarName(vlistID, varID, name)
CALL vlistInqVarLongname(vlistID, varID, longname)
CALL vlistInqVarUnits(vlistID, varID, units)
CALL ctrim(name)
CALL ctrim(longname)
CALL ctrim(units)
......
......@@ -17,6 +17,7 @@
DOUBLE PRECISION lons(nlon), lats(nlat), levs(nlev)
DOUBLE PRECISION var1(nlon*nlat), var2(nlon*nlat*nlev)
CHARACTER(len=256) :: varname
CHARACTER(kind=c_char,len=256) :: msg
DATA lons /0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330/
DATA lats /-75, -45, -15, 15, 45, 75/
......@@ -37,7 +38,7 @@
! Create a pressure level Z-axis
zaxisID2 = zaxisCreate(ZAXIS_PRESSURE, nlev)
CALL zaxisDefLevels(zaxisID2, levs)
! Create a variable list
vlistID = vlistCreate()
......@@ -59,8 +60,9 @@
! Create a dataset in netCDF fromat
streamID = streamOpenWrite(C_CHAR_"example.nc"//C_NULL_CHAR, FILETYPE_NC)
IF ( streamID < 0 ) THEN
WRITE(0,*) cdiStringError(streamID)
STOP
msg = cdiStringError(streamID)
WRITE(0,*) msg
STOP 1
END IF
! Assign the variable list to the dataset
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment