NCEPLIBS-ncio  1.0.0
All Namespaces Files Functions
read_vardata_code_1d.f90
1 
5  type(Dataset), intent(in) :: dset
6  character(len=*), intent(in) :: varname
7  integer, intent(in), optional :: nslice
8  integer, intent(in), optional :: slicedim
9  integer, intent(in), optional :: ncstart(1)
10  integer, intent(in), optional :: nccount(1)
11  integer, intent(out), optional :: errcode
12  integer ncerr, nvar, n, nd, dimlen, ncount
13  integer, allocatable, dimension(:) :: start, count
14  logical return_errcode
15  ! check if use the errcode
16  if(present(errcode)) then
17  return_errcode=.true.
18  errcode = 0
19  else
20  return_errcode=.false.
21  endif
22  ! check if count/dims of data is avail
23  if (present(nslice)) then
24  ncount = nslice
25  else
26  ncount = 1
27  endif
28  nvar = get_nvar(dset,varname)
29  allocate(start(dset%variables(nvar)%ndims),count(dset%variables(nvar)%ndims))
30  start(:) = 1
31  count(:) = 1
32  if (present(slicedim)) then
33  nd = slicedim
34  else
35  nd = dset%variables(nvar)%ndims
36  end if
37  do n=1,dset%variables(nvar)%ndims
38  if (n == nd) then
39  start(n) = ncount
40  count(n) = 1
41  else
42  start(n) = 1
43  count(n) = dset%variables(nvar)%dimlens(n)
44  dimlen = dset%variables(nvar)%dimlens(n)
45  end if
46  end do
47  if (dset%variables(nvar)%ndims /= 1 .and. dset%variables(nvar)%ndims /= 2) then
48  if (return_errcode) then
49  call nccheck(ncerr,halt=.false.)
50  errcode=nf90_ebaddim
51  return
52  else
53  print *,'rank of data array != variable ndims (or ndims-1)'
54  stop 99
55  endif
56  endif
57  ! allocate/deallocate values
58  if (allocated(values)) deallocate(values)
59  if (present(ncstart) .and. present(nccount)) then
60  allocate(values(nccount(1)))
61  start(1)=ncstart(1); count(1)=nccount(1)
62  if (dset%variables(nvar)%ndims == 2) then
63  start(2)=1; count(2)=1
64  end if
65  ncerr = nf90_get_var(dset%ncid, dset%variables(nvar)%varid, values,&
66  start=start, count=count)
67  else
68  if (dset%variables(nvar)%ndims == 2) then
69  allocate(values(dimlen))
70  ncerr = nf90_get_var(dset%ncid, dset%variables(nvar)%varid, values,&
71  start=start, count=count)
72  else
73  allocate(values(dset%variables(nvar)%dimlens(1)))
74  ncerr = nf90_get_var(dset%ncid, dset%variables(nvar)%varid, values)
75  end if
76  end if
77  !err check
78  if (return_errcode) then
79  call nccheck(ncerr,halt=.false.)
80  errcode=ncerr
81  else
82  call nccheck(ncerr)
83  endif