diff --git a/.gitattributes b/.gitattributes index dd71303..aa18bef 100644 --- a/.gitattributes +++ b/.gitattributes @@ -18,6 +18,7 @@ doc/Doxyfile -text doc/H5X_File_Format.txt -text doc/Makefile.am -text doc/doxyfooter -text +examples/stridedf.F90 -text /install-sh -text /license.txt -text /missing -text diff --git a/examples/stridedf.F90 b/examples/stridedf.F90 new file mode 100644 index 0000000..7eb369e --- /dev/null +++ b/examples/stridedf.F90 @@ -0,0 +1,61 @@ +program H5PartTest + implicit none + + include 'mpif.h' + include 'H5PartF.h' + + integer :: comm, rank, ierr + integer*8 :: file_id, status, npoints, i + real*8, allocatable :: particles(:) + integer*8, allocatable :: id(:) + + comm = MPI_COMM_WORLD + call mpi_init(ierr) + call mpi_comm_rank(comm, rank, ierr) + + ! open the a file for parallel writing + file_id = h5pt_openw_par('test.h5', comm) + + ! in the Fortran API, steps start at 1 + status = h5pt_setstep(file_id, 1_8) + + ! write an attribute to the file + status = h5pt_writefileattrib_string(file_id, 'desc', 'This is a test.') + + ! create fake data + npoints = 99 + allocate(particles(6*npoints), id(npoints)) + do i=0,npoints-1 + particles(6*i+1) = 0.0 + real(i+npoints*rank) + particles(6*i+2) = 0.1 + real(i+npoints*rank) + particles(6*i+3) = 0.2 + real(i+npoints*rank) + particles(6*i+4) = 0.3 + real(i+npoints*rank) + particles(6*i+5) = 0.4 + real(i+npoints*rank) + particles(6*i+6) = 0.5 + real(i+npoints*rank) + id(i+1) = i+npoints*rank + enddo + + ! set the striding to 6 + status = h5pt_setnpoints_strided(file_id, npoints, 6_8) + + ! write the particles + status = h5pt_writedata_r8(file_id, "x", particles(1)) + status = h5pt_writedata_r8(file_id, "y", particles(2)) + status = h5pt_writedata_r8(file_id, "z", particles(3)) + status = h5pt_writedata_r8(file_id, "px", particles(4)) + status = h5pt_writedata_r8(file_id, "py", particles(5)) + status = h5pt_writedata_r8(file_id, "pz", particles(6)) + + ! disable the striding to write the ids + status = h5pt_setnpoints(file_id, npoints) + status = h5pt_writedata_i8(file_id, "id", id) + + ! close the file + status = h5pt_close(file_id) + + deallocate(particles, id) + + call mpi_finalize(ierr) + +end program H5PartTest + diff --git a/src/H5Part.c b/src/H5Part.c index 9ab6992..a107bff 100644 --- a/src/H5Part.c +++ b/src/H5Part.c @@ -782,10 +782,8 @@ _set_num_particles ( total += f->pnparticles[i]; } - if ( stride > 1 ) count = stride * total; - else count = total; - /* declare overall datasize */ + count = total; f->shape = H5Screate_simple (1, &count, NULL); if ( f->shape < 0 ) return HANDLE_H5S_CREATE_SIMPLE_ERR ( count );