Commit cb21acfe authored by Alexander Lenz's avatar Alexander Lenz

FITS saving implemented. Header information is still very short.

parent d00e2744
......@@ -2,10 +2,11 @@ prefix=@prefix@
libdir=@libdir@
includedir=@includedir@
config_defines=@config_defines@
libadd=@libadd@
Name: Lima
Description: LImA (L ibrary for Im age A cquisition) is a project for the unified control of 2D detectors.
Requires:
Version: @VERSION@
Libs: -L${libdir} -llimacore
Libs: -L${libdir} -llimacore ${libadd}
Cflags: -I${includedir} ${config_defines}
......@@ -34,6 +34,11 @@ CORE_LDFLAGS += -L../third-party/CBFLib/lib
CORE_LDLIBS += -lcbf
endif
ifneq ($(COMPILE_FITS_SAVING),0)
CORE_LDFLAGS += -L../usr/local/lib
CORE_LDLIBS += -lCCfits -lcfitsio
endif
ifneq ($(COMPILE_CORE),0)
name := core
......
......@@ -64,6 +64,7 @@ namespace lima {
CBFFormat, ///< CBF format
NXS, ///< Soleil Nexus format
HARDWARE_SPECIFIC, ///< extended hardware format (ADSC,MarCCD...) @see setHardwareFormat
FITS, ///< Flexible Image Transport Layer (NOST)
};
enum SavingMode
......
......@@ -42,6 +42,10 @@
#include "CtSaving_Cbf.h"
#endif
#ifdef WITH_FITS_SAVING
#include "CtSaving_Fits.h"
#endif
#include "TaskMgr.h"
#include "SinkTask.h"
......@@ -243,6 +247,11 @@ void CtSaving::Stream::createSaveContainer()
#ifndef WITH_NXS_SAVING
THROW_CTL_ERROR(NotSupported) << "Lima is not compiled with the nxs "
"saving option, not managed";
#endif
case FITS:
#ifndef WITH_FITS_SAVING
THROW_CTL_ERROR(NotSupported) << "Lima is not compiled with the fits "
"saving option, not managed";
#endif
case RAW:
case EDF:
......@@ -274,6 +283,11 @@ void CtSaving::Stream::createSaveContainer()
case NXS:
m_save_cnt = new SaveContainerNxs(*this);
break;
#endif
#ifdef WITH_FITS_SAVING
case FITS:
m_save_cnt = new SaveContainerFits(*this);
break;
#endif
default:
break;
......
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// 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/>.
//###########################################################################
#ifdef __unix
#include <sys/time.h>
#else
#include <time_compat.h>
#endif
#include <iostream>
#include <memory>
#include <numeric>
#include <functional>
#include <sstream>
#include <CCfits/CCfits>
#include "CtSaving_Fits.h"
#define WORKING 1
using namespace lima;
/** @brief saving container
*
* This class manage file saving
*/
SaveContainerFits::SaveContainerFits(CtSaving::Stream& stream) :
CtSaving::SaveContainer(stream)
{
DEB_CONSTRUCTOR();
}
SaveContainerFits::~SaveContainerFits()
{
DEB_DESTRUCTOR();
}
bool SaveContainerFits::_open(const std::string &filename,
std::ios_base::openmode openFlags)
{
DEB_MEMBER_FUNCT();
_filename = "!" + filename + ".fits";
return true;
}
void SaveContainerFits::_close()
{
DEB_MEMBER_FUNCT();
}
void SaveContainerFits::_writeFile(Data &aData,
CtSaving::HeaderMap &aHeader,
CtSaving::FileFormat aFormat)
{
DEB_MEMBER_FUNCT();
// init file
long naxis = aData.dimensions.size();
long *naxes = new long[naxis];
for(int i(0); i < naxis; ++i)
naxes[i] = aData.dimensions[i];
std::auto_ptr<CCfits::FITS> pFits(NULL);
try
{
// determine bits per pixel
short bitpix;
std::string bitpixName;
switch(aData.type)
{
case Data::UINT8:
bitpix = SBYTE_IMG;
bitpixName = "SBYTE_IMG";
break;
case Data::INT8:
bitpix = BYTE_IMG;
bitpixName = "BYTE_IMG";
break;
case Data::UINT16:
bitpix = USHORT_IMG;
bitpixName = "USHORT_IMG";
break;
case Data::INT16:
bitpix = SHORT_IMG;
bitpixName = "SHORT_IMG";
break;
case Data::UINT32:
bitpix = ULONG_IMG;
bitpixName = "ULONG_IMG";
break;
case Data::INT32:
bitpix = LONG_IMG;
bitpixName = "LONG_IMG";
break;
case Data::UINT64:
case Data::INT64:
bitpix = LONGLONG_IMG;
bitpixName = "LONGLONG_IMG";
break;
case Data::FLOAT:
bitpix = FLOAT_IMG;
bitpixName = "FLOAT_IMG";
break;
case Data::DOUBLE:
bitpix = DOUBLE_IMG;
bitpixName = "DOUBLE_IMG";
break;
default:
throw LIMA_CTL_EXC(Error, "Can't determine bitpix");
}
DEB_TRACE() << "SaveContainerFits::_writeFile(): used bitpix: " << bitpixName << "(" << bitpix << ")";
// create fits file
pFits.reset(new CCfits::FITS(_filename,bitpix,naxis,naxes));
pFits->setVerboseMode(true);
// write
writeHeader(pFits, aHeader);
writeData(pFits, aData, bitpix);
DEB_TRACE() << "FITS PHDU: " << pFits->pHDU();
}catch(CCfits::FITS::CantCreate)
{
throw LIMA_CTL_EXC(Error, "Can't create FITS file");
}
delete naxes;
}
void SaveContainerFits::writeHeader(std::auto_ptr<CCfits::FITS> &fitsFile, CtSaving::HeaderMap &header)
{
DEB_MEMBER_FUNCT();
for(CtSaving::HeaderMap::iterator it = header.begin();it != header.end();++it)
{
std::string keyword = it->first;
std::transform(keyword.begin(), keyword.end(),
keyword.begin(), ::toupper);
fitsFile->pHDU().addKey(keyword,it->second, "Dynamic header information");
}
}
void SaveContainerFits::writeData(std::auto_ptr<CCfits::FITS> &fitsFile, Data &data, short dataType)
{
DEB_MEMBER_FUNCT();
// number of pixels: x*y
unsigned long nPixels = data.dimensions[0] * data.dimensions[1];
lima::CtSaving::Parameters param;
getParameters(param);
switch(param.imageType)
{
case lima::Bpp8:
{
unsigned char *castedData = (unsigned char *)data.data();
std::valarray<unsigned char> dataArray(nPixels);
for(int i(0); i < nPixels; ++i)
dataArray[i] = castedData[i];
fitsFile->pHDU().write(1,nPixels,dataArray);
}
break;
case lima::Bpp32:
{
unsigned int *castedData = (unsigned int *)data.data();
std::valarray<unsigned int> dataArray(nPixels);
for(int i(0); i < nPixels; ++i)
dataArray[i] = castedData[i];
fitsFile->pHDU().write(1,nPixels,dataArray);
}
break;
default:
{
unsigned short *castedData = (unsigned short *)data.data();
std::valarray<unsigned short> dataArray(nPixels);
for(int i(0); i < nPixels; ++i)
dataArray[i] = castedData[i];
fitsFile->pHDU().write(1,nPixels,dataArray);
}
}
}
//###########################################################################
//
// Copyright (C) 2012 Alexander Lenz <alexander.lenz@frm2.tum.de>
//
// 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/>.
//###########################################################################
#ifndef CTSAVING_FITS_H
#define CTSAVING_FITS_H
#include "CtSaving.h"
#include <memory>
namespace CCfits
{
class FITS;
}
namespace lima {
class SaveContainerFits : public CtSaving::SaveContainer
{
DEB_CLASS_NAMESPC(DebModControl,"Saving FITS Container","Control");
public:
SaveContainerFits(CtSaving::Stream& stream);
virtual ~SaveContainerFits();
protected:
virtual bool _open(const std::string &filename,
std::ios_base::openmode flags);
virtual void _close();
virtual void _writeFile(Data &data,
CtSaving::HeaderMap &aHeader,
CtSaving::FileFormat);
private:
void writeHeader(std::auto_ptr<CCfits::FITS> &fitsFile, CtSaving::HeaderMap &header);
void writeData(std::auto_ptr<CCfits::FITS> &fitsFile, Data &data, short dataType);
std::ofstream m_fout;
std::string _filename;
};
}
#endif // CTSAVING_FITS_H
......@@ -39,6 +39,10 @@ ifndef COMPILE_NXS_SAVING
COMPILE_NXS_SAVING = 0
endif
ifndef COMPILE_FITS_SAVING
COMPILE_FITS_SAVING = 0
endif
ifneq ($(COMPILE_CBF_SAVING),0)
ct-objs += CtSaving_Cbf.o
INCLUDES += -I../../third-party/CBFLib/include
......@@ -52,6 +56,12 @@ ct-objs += CtSaving_Nxs.o
CXXFLAGS += -DWITH_NXS_SAVING
endif
ifneq ($(COMPILE_FITS_SAVING),0)
ct-objs += CtSaving_Fits.o
CXXFLAGS += -DWITH_FITS_SAVING -I/usr/local/include
endif
ifndef COMPILE_SPS_IMAGE
COMPILE_SPS_IMAGE = 0
endif
......
......@@ -45,6 +45,7 @@ INSTALL_LIB_DIR = $(INSTALL_PLAT_DIR)/Lib
INSTALL_INCLUDE_DIR = $(INSTALL_PLAT_DIR)/include
INSTALL_PKG_CONFIG_DIR = $(INSTALL_LIB_DIR)/pkgconfig
INSTALL_CONFIG_DEFINES =
INSTALL_LIBADD =
ifneq ($(COMPILE_CORE), 0)
INSTALL_CORE_DIR = $(INSTALL_PLAT_DIR)/Core
......@@ -157,6 +158,12 @@ ifneq ($(COMPILE_NXS_SAVING),0)
INSTALL_CONFIG_DEFINES += -DWITH_NXS_SAVING
endif
ifneq ($(COMPILE_FITS_SAVING),0)
INSTALL_CONFIG_DEFINES += -DWITH_FITS_SAVING
#INSTALL_LIBADD += -lCCfits
endif
.PHONY: install
......@@ -171,6 +178,7 @@ install:
sed -e "s,@prefix@,${INSTALL_DIR},g" \
-e "s,@libdir@,${INSTALL_LIB_DIR},g" \
-e "s,@libadd@,${INSTALL_LIBADD},g" \
-e "s,@includedir@,${INSTALL_INCLUDE_DIR},g" \
-e "s,@config_defines@,${INSTALL_CONFIG_DEFINES},g" \
-e "s,@VERSION@,`cat common/VERSION`,g" \
......
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