Skip to content

Commit

Permalink
fixing order of chunksizes
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardhartnett committed Aug 28, 2020
1 parent e37d19a commit 15a191b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
13 changes: 10 additions & 3 deletions src/flib/pio_nf.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1298,19 +1298,26 @@ integer function inq_var_chunking_id(ncid, varid, storage, chunksizes) result(ie
integer, intent(in) :: varid
integer, intent(out) :: storage
integer (kind=PIO_OFFSET_KIND), intent(out) :: chunksizes(*)
integer(kind=PIO_OFFSET_KIND) :: cchunksizes(PIO_MAX_VAR_DIMS)
integer :: ndims, i

interface
integer(C_INT) function PIOc_inq_var_chunking(ncid, varid, storage, chunksizes) &
integer(C_INT) function PIOc_inq_var_chunking(ncid, varid, storage, cchunksizes) &
bind(C, name="PIOc_inq_var_chunking")
use iso_c_binding
integer(C_INT), value :: ncid
integer(C_INT), value :: varid
integer(C_INT) :: storage
integer(C_SIZE_T) :: chunksizes(*)
integer(C_SIZE_T) :: cchunksizes(*)
end function PIOc_inq_var_chunking
end interface

ierr = PIOc_inq_var_chunking(ncid, varid-1, storage, chunksizes)
ierr = PIOc_inq_var_chunking(ncid, varid-1, storage, cchunksizes)
ierr = pio_inq_varndims(ncid, varid, ndims)
do i = 1, ndims
chunksizes(i) = cchunksizes(ndims - i + 1)
enddo

end function inq_var_chunking_id

!>
Expand Down
17 changes: 9 additions & 8 deletions tests/unit/ftst_vars_chunking.F90
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ program ftst_vars_chunking
character(len=64) :: dim_name_1 = 'influence_on_Roman_history'
character(len=64) :: dim_name_2 = 'age_at_death'
character(len=64) :: var_name = 'Caesar'
integer :: dimid1, dimid2, dim_len = 40
integer :: chunksize = 10
integer :: dimid1, dimid2, dim_len1 = 40, dim_len2 = 80
integer :: chunksize1 = 10, chunksize2 = 20
integer :: storage_in
integer (kind=PIO_OFFSET_KIND) :: chunksizes_in(NDIM2)
integer :: iotype(NUM_IOTYPES) = (/ PIO_iotype_netcdf4c, PIO_iotype_netcdf4p /)
Expand Down Expand Up @@ -58,17 +58,17 @@ program ftst_vars_chunking
if (ierr .ne. PIO_NOERR) stop 3

! Define dims.
ret_val = PIO_def_dim(pio_file, dim_name_1, dim_len, dimid1)
ret_val = PIO_def_dim(pio_file, dim_name_1, dim_len1, dimid1)
if (ierr .ne. PIO_NOERR) stop 5
ret_val = PIO_def_dim(pio_file, dim_name_2, dim_len, dimid2)
ret_val = PIO_def_dim(pio_file, dim_name_2, dim_len2, dimid2)
if (ierr .ne. PIO_NOERR) stop 6

! Define a var.
ret_val = PIO_def_var(pio_file, var_name, PIO_int, (/dimid1, dimid2/), pio_var)
if (ierr .ne. PIO_NOERR) stop 7

! Define chunking for var.
ret_val = PIO_def_var_chunking(pio_file, pio_var, 0, (/chunksize, chunksize/))
ret_val = PIO_def_var_chunking(pio_file, pio_var, 0, (/chunksize1, chunksize2/))
if (ierr .ne. PIO_NOERR) stop 9

! Close the file.
Expand All @@ -79,9 +79,10 @@ program ftst_vars_chunking
if (ierr .ne. PIO_NOERR) stop 23

! ! Find var chunksizes.
! ret_val = PIO_inq_var_chunking(pio_file, 1, storage_in, chunksizes_in)
! if (ierr .ne. PIO_NOERR) stop 25
! if (chunksizes_in(1) .ne. chunksize) stop 26
ret_val = PIO_inq_var_chunking(pio_file, 1, storage_in, chunksizes_in)
if (ierr .ne. PIO_NOERR) stop 25
if (chunksizes_in(1) .ne. chunksize1) stop 26
if (chunksizes_in(2) .ne. chunksize2) stop 26

! Close the file.
call PIO_closefile(pio_file)
Expand Down

0 comments on commit 15a191b

Please sign in to comment.