Commit e51f67d8 authored by Laurent Claustre's avatar Laurent Claustre Committed by Sebastien Petitdemange

HDF5 ready for Windows. Supported version is 1.8.19

parent 820072c3
......@@ -75,41 +75,45 @@ endif()
#--------------------------------------------------------------------------------
# Saving formats can be enabled from environment variables using config.inc file
#--------------------------------------------------------------------------------
if(DEFINED ENV{LIMA_ENABLE_CBF})
set(LIMA_ENABLE_CBF "$ENV{LIMA_ENABLE_CBF}" CACHE BOOL "compile CBF saving code?" FORCE)
else()
option(LIMA_ENABLE_CBF "compile CBF saving code?" OFF)
if(UNIX)
# The formats have not been tested on windows
if(DEFINED ENV{LIMA_ENABLE_CBF})
set(LIMA_ENABLE_CBF "$ENV{LIMA_ENABLE_CBF}" CACHE BOOL "compile CBF saving code?" FORCE)
else()
option(LIMA_ENABLE_CBF "compile CBF saving code?" OFF)
endif()
if(DEFINED ENV{LIMA_ENABLE_EDFLZ4})
set(LIMA_ENABLE_EDFLZ4 "$ENV{LIMA_ENABLE_EDFLZ4}" CACHE BOOL "compile EDF.LZ4 saving code?" FORCE)
else()
option(LIMA_ENABLE_EDFLZ4 "compile EDF.LZ4 saving code?" OFF)
endif()
if(DEFINED ENV{LIMA_ENABLE_FITS})
set(LIMA_ENABLE_FITS "$ENV{LIMA_ENABLE_FITS}" CACHE BOOL "compile FITS saving code?" FORCE)
else()
option(LIMA_ENABLE_FITS "compile FITS saving code?" OFF)
endif()
if(DEFINED ENV{LIMA_ENABLE_NXS})
set(LIMA_ENABLE_NXS "$ENV{LIMA_ENABLE_NXS}" CACHE BOOL "compile Nexus saving code?" FORCE)
else()
option(LIMA_ENABLE_NXS "compile Nexus saving code?" OFF)
endif()
if(DEFINED ENV{LIMA_ENABLE_TIFF})
set(LIMA_ENABLE_TIFF "$ENV{LIMA_ENABLE_TIFF}" CACHE BOOL "compile TIFF saving code?" FORCE)
else()
option(LIMA_ENABLE_TIFF "compile TIFF saving code?" OFF)
endif()
endif()
if(DEFINED ENV{LIMA_ENABLE_EDFGZ})
set(LIMA_ENABLE_EDFGZ "$ENV{LIMA_ENABLE_EDFGZ}" CACHE BOOL "compile EDF.GZ saving code?" FORCE)
else()
option(LIMA_ENABLE_EDFGZ "compile EDF.GZ saving code?" OFF)
endif()
if(DEFINED ENV{LIMA_ENABLE_EDFLZ4})
set(LIMA_ENABLE_EDFLZ4 "$ENV{LIMA_ENABLE_EDFLZ4}" CACHE BOOL "compile EDF.LZ4 saving code?" FORCE)
else()
option(LIMA_ENABLE_EDFLZ4 "compile EDF.LZ4 saving code?" OFF)
endif()
if(DEFINED ENV{LIMA_ENABLE_FITS})
set(LIMA_ENABLE_FITS "$ENV{LIMA_ENABLE_FITS}" CACHE BOOL "compile FITS saving code?" FORCE)
else()
option(LIMA_ENABLE_FITS "compile FITS saving code?" OFF)
endif()
if(DEFINED ENV{LIMA_ENABLE_HDF5})
set(LIMA_ENABLE_HDF5 "$ENV{LIMA_ENABLE_HDF5}" CACHE BOOL "compile HDF5 saving code?" FORCE)
else()
option(LIMA_ENABLE_HDF5 "compile HDF5 saving code?" OFF)
endif()
if(DEFINED ENV{LIMA_ENABLE_NXS})
set(LIMA_ENABLE_NXS "$ENV{LIMA_ENABLE_NXS}" CACHE BOOL "compile Nexus saving code?" FORCE)
else()
option(LIMA_ENABLE_NXS "compile Nexus saving code?" OFF)
endif()
if(DEFINED ENV{LIMA_ENABLE_TIFF})
set(LIMA_ENABLE_TIFF "$ENV{LIMA_ENABLE_TIFF}" CACHE BOOL "compile TIFF saving code?" FORCE)
else()
option(LIMA_ENABLE_TIFF "compile TIFF saving code?" OFF)
endif()
# Compile python wrapping code generated using SIP
IF(DEFINED ENV{LIMA_ENABLE_PYTHON})
......
......@@ -284,8 +284,7 @@ void* SaveContainerHdf5::_open(const std::string &filename, std::ios_base::openm
try{
new_file.m_file = new H5File();
is_hdf5 = new_file.m_file->isHdf5(filename);
} catch (FileIException &error){
//error.printError();
} catch (FileIException){
file_exists = false;
}
......@@ -316,7 +315,11 @@ void* SaveContainerHdf5::_open(const std::string &filename, std::ios_base::openm
// create the next entry name and
//fails if it already exists in the file
char strname[256];
sprintf(strname,"/entry_%04d", new_file.m_entry_index);
#ifdef WIN32
sprintf_s(strname,"/entry_%04d", new_file.m_entry_index);
#else
sprintf(strname, "/entry_%04d", new_file.m_entry_index);
#endif
if (!new_file.m_format_written) {
Group *group = NULL;
if (new_file.m_in_append) {
......@@ -431,6 +434,7 @@ void* SaveContainerHdf5::_open(const std::string &filename, std::ios_base::openm
new_file.m_instrument_detector = new Group(instrument.openGroup(m_ct_parameters.det_name));
}
} catch (FileIException &error) {
error.printError();
THROW_CTL_ERROR(Error) << "File " << filename << " not opened successfully";
}
......@@ -452,7 +456,13 @@ void SaveContainerHdf5::_close(void* f) {
time_t now;
time(&now);
char buf[sizeof("2011-10-08T07:07:09Z")];
#ifdef WIN32
struct tm gmtime_now;
gmtime_s(&gmtime_now, &now);
strftime(buf, sizeof(buf), "%FT%TZ", &gmtime_now);
#else
strftime(buf, sizeof(buf), "%FT%TZ", gmtime(&now));
#endif
string etime = string(buf);
write_h5_dataset(*file->m_entry,"end_time",etime);
}
......@@ -511,7 +521,13 @@ long SaveContainerHdf5::_writeFile(void* f,Data &aData,
time_t now;
time(&now);
char buf[sizeof("2011-10-08T07:07:09Z")];
#ifdef WIN32
struct tm gmtime_now;
gmtime_s(&gmtime_now, &now);
strftime(buf, sizeof(buf), "%FT%TZ", &gmtime_now);
#else
strftime(buf, sizeof(buf), "%FT%TZ", gmtime(&now));
#endif
string stime = string(buf);
write_h5_dataset(*file->m_entry,"start_time",stime);
// write header only once into "parameters" group
......@@ -586,11 +602,16 @@ long SaveContainerHdf5::_writeFile(void* f,Data &aData,
slab_dim[0] = 1;
DataSpace slabspace = DataSpace(RANK_THREE, slab_dim);
int image_nb = aData.frameNumber % m_nbframes;
hsize_t start[] = { file->m_prev_images_written + image_nb, 0, 0 };
hsize_t count[] = { 1, aData.dimensions[1], aData.dimensions[0] };
hsize_t start[] = { hsize_t(file->m_prev_images_written + image_nb), hsize_t(0), hsize_t(0)};
hsize_t count[] = { hsize_t(1), hsize_t(aData.dimensions[1]), hsize_t(aData.dimensions[0])};
file->m_image_dataspace->selectHyperslab(H5S_SELECT_SET, count, start);
file->m_image_dataset->write((u_int8_t*) aData.data(), data_type,
#ifdef WIN32
file->m_image_dataset->write((uint8_t*) aData.data(), data_type,
slabspace, *file->m_image_dataspace);
#else
file->m_image_dataset->write((u_int8_t*)aData.data(), data_type,
slabspace, *file->m_image_dataspace);
#endif
// catch failure caused by the DataSet operations
} catch (DataSetIException& error) {
......@@ -626,11 +647,15 @@ int SaveContainerHdf5::findLastEntry(const _File &file) {
int index = -1;
try { // determine the next group Entry index
do {
sprintf(entryName, "/entry_%04d", index+1);
#ifdef WIN32
sprintf_s(entryName, "/entry_%04d", index+1);
#else
sprintf(entryName, "/entry_%04d", index + 1);
#endif
file.m_file->openGroup(entryName);
index++;
} while (1);
} catch (H5::Exception &no_group) {
} catch (H5::Exception) {
// ignore this indicates the last group
}
return index;
......
###########################################################################
# This file is part of LImA, a Library for Image Acquisition
#
# Copyright (C) : 2009-2017
# European Synchrotron Radiation Facility
# BP 220, Grenoble 38043
# FRANCE
#
# Contact: lima@esrf.fr
#
# This is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
############################################################################
from Lima import Core,Simulator
cam=Simulator.Camera()
hwint=Simulator.Interface(cam)
ct=Core.CtControl(hwint)
saving=ct.saving()
acq=ct.acquisition()
saving.setDirectory('c:\\temp'.encode())
saving.setPrefix('test_h5_'.encode())
saving.setFormat(saving.HDF5)
saving.setSuffix('.h5'.encode())
saving.setSavingMode(saving.AutoFrame)
acq.setAcqNbFrames(10)
saving.setFramesPerFile(10)
# set overwrite mode to save multiple dataset in a single file
saving.setOverwritePolicy(saving.MultiSet)
#ct.prepareAcq()
#ct.startAcq()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment