Skip to content

Commit 5b51977

Browse files
committed
slice
1 parent bfca19a commit 5b51977

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

src/interface.f90

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,55 +105,62 @@ module subroutine nc_write_1d(self, dname, value, dims, istart, iend, chunk_size
105105
character(*), intent(in) :: dname
106106
class(*), intent(in) :: value(:)
107107
character(*), intent(in), optional :: dims(1)
108-
integer, intent(in), dimension(1), optional :: istart, iend, chunk_size
108+
integer, intent(in), dimension(1), optional :: istart, iend
109+
integer, intent(in), dimension(1), optional :: chunk_size
109110
end subroutine
110111

111112
module subroutine nc_write_2d(self, dname, value, dims, istart, iend, chunk_size)
112113
class(netcdf_file), intent(in) :: self
113114
character(*), intent(in) :: dname
114115
class(*), intent(in) :: value(:,:)
115116
character(*), intent(in), optional :: dims(2)
116-
integer, intent(in), dimension(2), optional :: istart, iend, chunk_size
117+
integer, intent(in), dimension(2), optional :: istart, iend
118+
integer, intent(in), dimension(2), optional :: chunk_size
117119
end subroutine
118120

119121
module subroutine nc_write_3d(self, dname, value, dims, istart, iend, chunk_size)
120122
class(netcdf_file), intent(in) :: self
121123
character(*), intent(in) :: dname
122124
class(*), intent(in) :: value(:,:,:)
123125
character(*), intent(in), optional :: dims(3)
124-
integer, intent(in), dimension(3), optional :: istart, iend, chunk_size
126+
integer, intent(in), dimension(3), optional :: istart, iend
127+
integer, intent(in), dimension(3), optional :: chunk_size
125128
end subroutine
126129

127130
module subroutine nc_write_4d(self, dname, value, dims, istart, iend, chunk_size)
128131
class(netcdf_file), intent(in) :: self
129132
character(*), intent(in) :: dname
130133
class(*), intent(in) :: value(:,:,:,:)
131134
character(*), intent(in), optional :: dims(4)
132-
integer, intent(in), dimension(4), optional :: istart, iend, chunk_size
135+
integer, intent(in), dimension(4), optional :: istart, iend
136+
integer, intent(in), dimension(4), optional :: chunk_size
133137
end subroutine
134138

135139
module subroutine nc_write_5d(self, dname, value, dims, istart, iend, chunk_size)
136140
class(netcdf_file), intent(in) :: self
137141
character(*), intent(in) :: dname
138142
class(*), intent(in) :: value(:,:,:,:,:)
139143
character(*), intent(in), optional :: dims(5)
140-
integer, intent(in), dimension(5), optional :: istart, iend, chunk_size
144+
integer, intent(in), dimension(5), optional :: istart, iend
145+
integer, intent(in), dimension(5), optional :: chunk_size
141146
end subroutine
142147

143148
module subroutine nc_write_6d(self, dname, value, dims, istart, iend, chunk_size)
144149
class(netcdf_file), intent(in) :: self
145150
character(*), intent(in) :: dname
146151
class(*), intent(in) :: value(:,:,:,:,:,:)
147152
character(*), intent(in), optional :: dims(6)
148-
integer, intent(in), dimension(6), optional :: istart, iend, chunk_size
153+
integer, intent(in), dimension(6), optional :: istart, iend
154+
integer, intent(in), dimension(6), optional :: chunk_size
149155
end subroutine
150156

151157
module subroutine nc_write_7d(self, dname, value, dims, istart, iend, chunk_size)
152158
class(netcdf_file), intent(in) :: self
153159
character(*), intent(in) :: dname
154160
class(*), intent(in) :: value(:,:,:,:,:,:,:)
155161
character(*), intent(in), optional :: dims(7)
156-
integer, intent(in), dimension(7), optional :: istart, iend, chunk_size
162+
integer, intent(in), dimension(7), optional :: istart, iend
163+
integer, intent(in), dimension(7), optional :: chunk_size
157164
end subroutine
158165

159166
end interface

src/reader.inc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
integer :: varid, ier, drank
1+
integer :: varid, ier, drank, i(rank(value))
22

33
if(.not.self%is_open) error stop 'nc4fortran:reader file handle not open'
44

@@ -12,17 +12,24 @@ if(drank /= rank(value)) then
1212
error stop
1313
endif
1414

15+
if(present(istart) .and. present(iend)) then
16+
i = iend - istart + 1
17+
else
18+
i = shape(value)
19+
endif
20+
1521
select type (value)
1622
type is (real(real64))
17-
ier = nf90_get_var(self%file_id, varid, value)
23+
ier = nf90_get_var(self%file_id, varid, value, start=istart, count=i)
1824
type is (real(real32))
19-
ier = nf90_get_var(self%file_id, varid, value)
25+
ier = nf90_get_var(self%file_id, varid, value, start=istart, count=i)
2026
type is (integer(int64))
21-
ier = nf90_get_var(self%file_id, varid, value)
27+
ier = nf90_get_var(self%file_id, varid, value, start=istart, count=i)
2228
type is (integer(int32))
23-
ier = nf90_get_var(self%file_id, varid, value)
29+
ier = nf90_get_var(self%file_id, varid, value, start=istart, count=i)
2430
class default
2531
ier = NF90_EBADTYPE
2632
end select
2733

34+
2835
if (check_error(ier, dname)) error stop 'nc4fortran:read read ' // dname // ' in ' // self%filename

src/writer.inc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
integer :: varid, ier, dtype
2-
integer, dimension(rank(value)) :: i0, i1
2+
integer, dimension(rank(value)) :: i
33

44
if (self%exist(dname)) then
55
ier = nf90_inq_varid(self%file_id, dname, varid)
@@ -20,21 +20,21 @@ else
2020
call nc_create(self, dname, dtype, dims=shape(value), dim_names=dims, chunk_size=chunk_size, varid=varid)
2121
endif
2222

23-
i0 = 1
24-
if(present(istart)) i0 = istart
25-
26-
i1 = shape(value)
27-
if(present(iend)) i1 = iend
23+
if(present(istart) .and. present(iend)) then
24+
i = iend - istart + 1
25+
else
26+
i = shape(value)
27+
endif
2828

2929
select type (value)
3030
type is (real(real32))
31-
ier = nf90_put_var(self%file_id, varid, value, start=istart)
31+
ier = nf90_put_var(self%file_id, varid, value, start=istart, count=i)
3232
type is (real(real64))
33-
ier = nf90_put_var(self%file_id, varid, value, start=istart)
33+
ier = nf90_put_var(self%file_id, varid, value, start=istart, count=i)
3434
type is (integer(int32))
35-
ier = nf90_put_var(self%file_id, varid, value, start=istart)
35+
ier = nf90_put_var(self%file_id, varid, value, start=istart, count=i)
3636
type is (integer(int64))
37-
ier = nf90_put_var(self%file_id, varid, value, start=istart)
37+
ier = nf90_put_var(self%file_id, varid, value, start=istart, count=i)
3838
class default
3939
ier = NF90_EBADTYPE
4040
end select

0 commit comments

Comments
 (0)