Skip to content

Commit

Permalink
Merge pull request #332 from matt-frey/fix-reading-datasets
Browse files Browse the repository at this point in the history
Fix reading netcdf datasets
  • Loading branch information
matt-frey authored Mar 10, 2022
2 parents 05eea72 + 8c2c1f3 commit 8e8b2bc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
14 changes: 11 additions & 3 deletions src/netcdf/netcdf_reader.f90
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ subroutine read_netcdf_dataset_2d(ncid, name, buffer, start, cnt)
call check_netcdf_error("Reading dataset id failed.")

ncerr = nf90_get_var(ncid=ncid, varid=varid, values=values, &
start=start, count=cnt, map=(/map(1), 1/))
start=start, count=cnt)

buffer = transpose(values)

Expand All @@ -179,13 +179,21 @@ subroutine read_netcdf_dataset_3d(ncid, name, buffer, start, cnt)
double precision, intent(out) :: buffer(:, :, :)
integer, optional, intent(in) :: start(:)
integer, optional, intent(in) :: cnt(:)
integer :: varid
integer :: varid, map(3)
double precision, allocatable :: values(:, :, :)

map = shape(buffer)

allocate(values(map(3), map(2), map(1)))

ncerr = nf90_inq_varid(ncid, name, varid)
call check_netcdf_error("Reading dataset id failed.")

ncerr = nf90_get_var(ncid=ncid, varid=varid, values=buffer, &
ncerr = nf90_get_var(ncid=ncid, varid=varid, values=values, &
start=start, count=cnt)

buffer = reshape(values, shape=(/map(1), map(2), map(3)/), order=(/3, 2, 1/))
deallocate(values)
end subroutine read_netcdf_dataset_3d

subroutine read_netcdf_global_attrib_integer(ncid, name, val)
Expand Down
2 changes: 1 addition & 1 deletion unit-tests/netcdf/test_netcdf_read_dataset_1d.f90
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ program test_netcdf_read_dataset_1d

passed = (passed .and. (ncerr == 0))

error = sum(wdset - rdset(1:n_parcels))
error = sum(abs(wdset - rdset(1:n_parcels)))

passed = (passed .and. (ncerr == 0) .and. (error == 0.0d0))

Expand Down
2 changes: 1 addition & 1 deletion unit-tests/netcdf/test_netcdf_read_dataset_2d.f90
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ program test_netcdf_read_dataset_2d

passed = (passed .and. (ncerr == 0))

error = sum(wdset - rdset)
error = sum(abs(wdset - rdset))

passed = (passed .and. (ncerr == 0) .and. (error == 0.0d0))

Expand Down
2 changes: 1 addition & 1 deletion unit-tests/netcdf/test_netcdf_read_dataset_3d.f90
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ program test_netcdf_read_dataset_3d

passed = (passed .and. (ncerr == 0))

error = sum(wdset - rdset)
error = sum(abs(wdset - rdset))

passed = (passed .and. (ncerr == 0) .and. (error == 0.0d0))

Expand Down

0 comments on commit 8e8b2bc

Please sign in to comment.