Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an issue with imageh5 #191

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 26 additions & 23 deletions src/Image.C
Original file line number Diff line number Diff line change
Expand Up @@ -1347,25 +1347,28 @@ void Image::writeImagePlane_2(int cycle, std::string &path, float_sw4 t )
H5Sclose(dset_space);
H5Dclose(dset);

if( mGridinfo == 1 )
char grid_name[16];
if( mGridinfo >= 1 )
{
int g=mEW->mNumberOfGrids-1;
int globalSizes[3] = {mEW->m_global_nx[g], mEW->m_global_ny[g], mEW->m_global_nz[g]} ;
if(mLocationType == Image::X)
globalSizes[0] = 1;
if (mLocationType == Image::Y)
globalSizes[1] = 1;
if (mLocationType == Image::Z)
globalSizes[2] = 1;

dims = globalSizes[0]*globalSizes[1]*globalSizes[2];
dset_space = H5Screate_simple(1, &dims, NULL);
/* cout << "Rank " << mEW->getRank() << " creating grid array with length " << dims << endl; */
dset = H5Dcreate(h5_fid, "grid", dtype, dset_space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
if( dset < 0 )
cout << "ERROR: Image::writeImagePlane_2 could not create HDF5 grid dataset" << endl;
H5Sclose(dset_space);
H5Dclose(dset);
for (int g = mEW->mNumberOfCartesianGrids; g < mEW->mNumberOfGrids; g++) {
int globalSizes[3] = {mEW->m_global_nx[g], mEW->m_global_ny[g], mEW->m_global_nz[g]} ;
if(mLocationType == Image::X)
globalSizes[0] = 1;
if (mLocationType == Image::Y)
globalSizes[1] = 1;
if (mLocationType == Image::Z)
globalSizes[2] = 1;

dims = globalSizes[0]*globalSizes[1]*globalSizes[2];
dset_space = H5Screate_simple(1, &dims, NULL);
/* cout << "Rank " << mEW->getRank() << " creating grid array with length " << dims << endl; */
sprintf(grid_name, "grid%d", g);
dset = H5Dcreate(h5_fid, grid_name, dtype, dset_space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
if( dset < 0 )
cout << "ERROR: Image::writeImagePlane_2 could not create HDF5 grid dataset" << endl;
H5Sclose(dset_space);
H5Dclose(dset);
}
}

delete [] grid_size;
Expand Down Expand Up @@ -1481,7 +1484,7 @@ void Image::writeImagePlane_2(int cycle, std::string &path, float_sw4 t )
}
} // End if ihavearray

if( mGridinfo == 1 )
if( mGridinfo >= 1 )
add_grid_to_file_hdf5( s.str().c_str(), iwrite, 0);
/* if( mGridinfo == 2 ) */
/* add_grid_filenames_to_file( s.str().c_str() ); */
Expand All @@ -1495,6 +1498,7 @@ void Image::writeImagePlane_2(int cycle, std::string &path, float_sw4 t )
void Image::add_grid_to_file_hdf5( const char* fname, bool iwrite, size_t offset )
{
bool ihavearray = plane_in_proc(m_gridPtIndex[0]);
char grid_name[16];
if( ihavearray )
{
#ifdef USE_HDF5
Expand All @@ -1512,17 +1516,16 @@ void Image::add_grid_to_file_hdf5( const char* fname, bool iwrite, size_t offset
if( mEW->usingParallelFS() )
MPI_Barrier( m_mpiComm_writers );

sprintf(grid_name, "grid%d", g);
if( m_double )
{
char dblStr[]="double";
m_pio[g]->write_array_hdf5(fname, NULL, "grid", 1, m_gridimage->m_doubleField[g], offset, dblStr );
offset += (globalSizes[0]*globalSizes[1]*globalSizes[2]*sizeof(double));
m_pio[g]->write_array_hdf5(fname, NULL, grid_name, 1, m_gridimage->m_doubleField[g], 0, dblStr );
}
else
{
char fltStr[]="float";
m_pio[g]->write_array_hdf5(fname, NULL, "grid", 1, m_gridimage->m_floatField[g], offset, fltStr );
offset += (globalSizes[0]*globalSizes[1]*globalSizes[2]*sizeof(float));
m_pio[g]->write_array_hdf5(fname, NULL, grid_name, 1, m_gridimage->m_floatField[g], 0, fltStr );
}
}
#endif
Expand Down
90 changes: 22 additions & 68 deletions tools/plotimageh5.ipynb

Large diffs are not rendered by default.