-
Notifications
You must be signed in to change notification settings - Fork 0
/
nc_get2Dvar.F90
58 lines (44 loc) · 1.74 KB
/
nc_get2Dvar.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! svn propset svn:keywords "URL Rev Author Date Id"
! $URL: file:///data/zhuming/.vdras_source_code/SVN_REPOSITORY/VDRAS/trunk/vdras/io/netcdf4/nc_get2Dvar.F90 $
! $Rev: 355 $
! $Author: zhuming $
! $Date: 2014-09-30 11:02:42 -0600 (Tue, 30 Sep 2014) $
! $Id: nc_get2Dvar.F90 355 2014-09-30 17:02:42Z zhuming $
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine nc_get2Dvar(ncid, var_name, var, nrec, &
nxs, nxe, nys, nye)
use netcdf
implicit none
integer, intent(in) :: ncid, nrec
integer, intent(in) :: nxs, nxe, nys, nye
character(len = *), intent(in) :: var_name
real(kind=8), dimension(nxs:nxe, nys:nye), intent(out) :: var
integer, dimension(3) :: start, count
! Variable id
integer :: varid
! Return status
integer :: status
status = nf90_inq_varid(ncid, var_name, varid)
if(status /= nf90_noerr) then
write(unit=0, fmt='(3a)') "Problem to get id for: <", trim(var_name), ">.", &
"Error status: ", trim(nf90_strerror(status))
write(unit=0, fmt='(3a, i4)') &
"Stop in file: <", __FILE__, ">, line: ", __LINE__
stop
end if
start(1) = nxs
start(2) = nys
start(3) = nrec
count(1) = nxe - nxs + 1
count(2) = nye - nys + 1
count(3) = 1
status = nf90_get_var(ncid,varid,var,start=start(1:3),count=count(1:3))
if(status /= nf90_noerr) then
write(unit=0, fmt='(3a)') "Problem to read: <", trim(var_name), ">.", &
"Error status: ", trim(nf90_strerror(status))
write(unit=0, fmt='(3a, i4)') &
"Stop in file: <", __FILE__, ">, line: ", __LINE__
stop
end if
end subroutine nc_get2Dvar