status = nf90_get_att (ncid, 4, "scale_factor", sfactor)
call check (status)
status = nf90_get_att (ncid, 4, "add_offset", aoffset)
call check (status)
status = nf90_get_att (ncid, 4, "missing_value", imvalue)
call check (status)
status = nf90_close (ncid)
call check (status)
! -- Data processing. --------------------------------------------------------------------------
do t = 1, NT
do j = 1, NY
do i = 1, NX
if (ivar(i, j, t) /= imvalue) then
fvar(i, j, t) = ivar(i, j, t) * sfactor + aoffset
else
fvar(i, j, t) = OMVALUE
end if
end do
end do
end do
! -- Data output. ------------------------------------------------------------------------------
open (21, file = OFNAME, form = 'unformatted', access = 'direct', recl = NX * NY * 4)
do t = 1, NT
write (21, rec = t) ((fvar(i, j, t), i = 1, NX), j = 1, NY)
end do
close (21)
contains
! -- Subordinate subroutines and functions. ----------------------------------------------------
subroutine check (status)
integer, intent(in) :: status
if (status /= nf90_noerr) then
write (*, *) trim (nf90_strerror (status))
stop "Stopped"
end if
end subroutine check
end program main
出错的问题如下
D:\fortion\nc\nc1.f90(62): Could not find the file netcdf.mod.
Compiling Fortran...
D:\fortion\nc\nc1.f90
D:\fortion\nc\nc1.f90(62) : Error: Error in opening the Library module file. [NETCDF]
use netcdf
------^
D:\fortion\nc\nc1.f90(109) : Error: This name does not have a type, and must have an explicit type. [NF90_OPEN]
status = nf90_open (IFNAME, nf90_nowrite, ncid)
-----------^
D:\fortion\nc\nc1.f90(133) : Error: This name does not have a type, and must have an explicit type. [NF90_GET_VAR]
status = nf90_get_var (ncid, 4, ivar, start, count)
-----------^
D:\fortion\nc\nc1.f90(136) : Error: This name does not have a type, and must have an explicit type. [NF90_GET_ATT]
status = nf90_get_att (ncid, 4, "scale_factor", sfactor)
-----------^
D:\fortion\nc\nc1.f90(145) : Error: This name does not have a type, and must have an explicit type. [NF90_CLOSE]
status = nf90_close (ncid)
-----------^
D:\fortion\nc\nc1.f90(184) : Error: This name does not have a type, and must have an explicit type. [NF90_NOERR]
if (status /= nf90_noerr) then
------------------^
D:\fortion\nc\nc1.f90(185) : Error: This name does not have a type, and must have an explicit type. [NF90_STRERROR]
write (*, *) trim (nf90_strerror (status))
-------------------------^
D:\fortion\nc\nc1.f90(185) : Error: The data types of the argument(s) are invalid. [TRIM]
write (*, *) trim (nf90_strerror (status))
-------------------------^
Error executing df.exe.