Loading...
Searching...
No Matches
FITSFieldCopier.h
Go to the documentation of this file.
//# FITSFieldCopier.h: Copy RORecordFields to FitsFields
//# Copyright (C) 1996,1998,1999,2000,2002
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library 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 Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: casa-feedback@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
#ifndef FITS_FITSFIELDCOPIER_H
#define FITS_FITSFIELDCOPIER_H
#include <casacore/casa/aips.h>
#include <casacore/fits/FITS/hdu.h>
#include <casacore/casa/Containers/RecordField.h>
#include <casacore/casa/Arrays/Array.h>
#include <casacore/casa/BasicSL/String.h>
#include <casacore/fits/FITS/FITSKeywordUtil.h>
namespace casacore { //# NAMESPACE CASACORE - BEGIN
// <summary>
// Virtual base class for copying RORecordFields to FitsFields
// </summary>
// <use visibility=local>
// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
// </reviewed>
// <prerequisite>
// <li> RORecordField
// <li> FitsFields
// </prerequisite>
//
// <etymology>
// </etymology>
//
// <synopsis>
// </synopsis>
//
// <example>
// </example>
//
// <motivation>
// </motivation>
//
// <thrown>
// <li>
// <li>
// </thrown>
//
// <todo asof="yyyy/mm/dd">
// <li> actually document this
// </todo>
class FITSFieldCopier
{
public:
// destructor
virtual ~FITSFieldCopier() {};
// the things which does the work - to be implemented in each derived class
virtual void copyToFITS() = 0;
};
// <summary>
// A FITSFieldCopier for copying scalar non-string RecordFields to FitsFields
// </summary>
// <use visibility=local>
// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
// </reviewed>
// <prerequisite>
// <li> RORecordField
// <li> FitsFields
// </prerequisite>
//
// <etymology>
// </etymology>
//
// <synopsis>
// </synopsis>
//
// <example>
// </example>
//
// <motivation>
// </motivation>
//
// <thrown>
// <li>
// <li>
// </thrown>
//
// <todo asof="yyyy/mm/dd">
// <li> actually document this
// </todo>
template<class recordType, class fitsType> class ScalarFITSFieldCopier :
public FITSFieldCopier
{
public:
ScalarFITSFieldCopier(RORecordFieldPtr<recordType> *recptr,
FitsField<fitsType> *fitsptr)
: rec_p(recptr), fits_p(fitsptr) {}
~ScalarFITSFieldCopier() {delete rec_p; delete fits_p;}
// Copy the current contents of the input RORecordFieldPtr to the
// output FitsField
virtual void copyToFITS() {(*fits_p)() = *(*rec_p); }
private:
RORecordFieldPtr<recordType> *rec_p;
FitsField<fitsType> *fits_p;
ScalarFITSFieldCopier(const ScalarFITSFieldCopier<recordType,fitsType> &other);
ScalarFITSFieldCopier &operator=(
const ScalarFITSFieldCopier<recordType,fitsType> &other);
};
// <summary>
// A FITSFieldCopier for copying String RecordFields to FitsFields
// </summary>
// <use visibility=local>
// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
// </reviewed>
// <prerequisite>
// <li> RORecordField
// <li> FitsFields
// </prerequisite>
//
// <etymology>
// </etymology>
//
// <synopsis>
// </synopsis>
//
// <example>
// </example>
//
// <motivation>
// </motivation>
//
// <thrown>
// <li>
// <li>
// </thrown>
//
// <todo asof="yyyy/mm/dd">
// <li> actually document this
// </todo>
class StringFITSFieldCopier : public FITSFieldCopier
{
public:
StringFITSFieldCopier(RORecordFieldPtr<String> *rptr,
FitsField<char> *fptr) : rec_p(rptr), fits_p(fptr) {}
// Copy the current contents of the input RORecordFieldPtr to the
// output FitsField
virtual void copyToFITS()
{
Int fitslength = fits_p->nelements();
Int reclength = (*(*rec_p)).length();
Int minlength = fitslength < reclength ? fitslength : reclength;
const char *chars = (**rec_p).chars();
Int i;
for (i=0; i<minlength; i++) {
(*fits_p)(i) = chars[i];
}
if (i < fitslength) {
(*fits_p)(i) = '\0'; // null terminate if possible
}
}
~StringFITSFieldCopier() {delete rec_p; delete fits_p;}
private:
RORecordFieldPtr<String> *rec_p;
FitsField<char> *fits_p;
// Undefined and inaccessible.
StringFITSFieldCopier(const StringFITSFieldCopier &other);
StringFITSFieldCopier &operator=(const StringFITSFieldCopier &other);
};
// <summary>
// A FITSFieldCopier for copying Array RecordFields to FitsFields
// </summary>
// <use visibility=local>
// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
// </reviewed>
// <prerequisite>
// <li> RORecordField
// <li> FitsFields
// </prerequisite>
//
// <etymology>
// </etymology>
//
// <synopsis>
// </synopsis>
//
// <example>
// </example>
//
// <motivation>
// </motivation>
//
// <thrown>
// <li>
// <li>
// </thrown>
//
// <todo asof="yyyy/mm/dd">
// <li> actually document this
// </todo>
template<class recordType, class fitsType> class ArrayFITSFieldCopier :
public FITSFieldCopier
{
public:
ArrayFITSFieldCopier(RORecordFieldPtr<Array<recordType> > *recptr,
FitsField<fitsType> *fitsptr) : rec_p(recptr), fits_p(fitsptr) {}
~ArrayFITSFieldCopier() {delete rec_p; delete fits_p;}
// Copy the current contents of the input RORecordFieldPtr to the
// output FitsField
virtual void copyToFITS() {
uInt nfits = fits_p->nelements();
uInt narray = (**rec_p).nelements();
uInt nmin = narray < nfits ? narray : nfits;
Bool deleteIt;
const recordType *rptr = (**rec_p).getStorage(deleteIt);
for (uInt i=0; i<nmin; i++) {
(*fits_p)(i) = rptr[i];
}
// pad with nulls
for (uInt i=nmin;i<nfits;i++) {
(*fits_p)(i) = recordType(0);
}
(**rec_p).freeStorage(rptr, deleteIt);
}
private:
RORecordFieldPtr<Array<recordType> > *rec_p;
FitsField<fitsType> *fits_p;
// Undefined and inaccessible
ArrayFITSFieldCopier(const ArrayFITSFieldCopier<recordType,fitsType> &other);
ArrayFITSFieldCopier &operator=(
const ArrayFITSFieldCopier<recordType,fitsType> &other);
};
template<class recordType, class fitsType> class VariableArrayFITSFieldCopier :
public FITSFieldCopier
{
public:
VariableArrayFITSFieldCopier(RORecordFieldPtr<Array<recordType> > *recptr,
FitsField<fitsType> *fitsptr,
FitsField<char> *tdirptr)
: rec_p(recptr), fits_p(fitsptr), tdir_p(tdirptr) {}
~VariableArrayFITSFieldCopier() {delete rec_p; delete fits_p;}
// Copy the current contents of the input RORecordFieldPtr to the
// output FitsField
virtual void copyToFITS() {
uInt nfits = fits_p->nelements();
uInt narray = (**rec_p).nelements();
uInt nmin = narray < nfits ? narray : nfits;
Bool deleteIt;
const recordType *rptr = (**rec_p).getStorage(deleteIt);
for (uInt i=0; i<nmin; i++) {
(*fits_p)(i) = rptr[i];
}
for (uInt i=nmin;i<nfits;i++) {
(*fits_p)(i) = recordType(0);
}
(**rec_p).freeStorage(rptr, deleteIt);
// and construct the TDIM value for this array
String thisTDIR;
FITSKeywordUtil::toTDIM(thisTDIR, (**rec_p).shape());
// and store it in the tdir_p FitsField
Int fitslength = tdir_p->nelements();
Int reclength = thisTDIR.length();
Int minlength = fitslength < reclength ? fitslength : reclength;
const char *chars = thisTDIR.chars();
Int i;
for (i=0; i<minlength; i++) {
(*tdir_p)(i) = chars[i];
}
for (Int i=minlength; i<fitslength; i++) {
(*tdir_p)(i) = '\0'; // null terminate if possible
}
}
private:
RORecordFieldPtr<Array<recordType> > *rec_p;
FitsField<fitsType> *fits_p;
FitsField<char> *tdir_p;
// Undefined and inaccessible
VariableArrayFITSFieldCopier(const VariableArrayFITSFieldCopier<recordType,fitsType> &other);
VariableArrayFITSFieldCopier &operator=(
const VariableArrayFITSFieldCopier<recordType,fitsType> &other);
};
} //# NAMESPACE CASACORE - END
#endif
casacore::ArrayFITSFieldCopier::operator=
ArrayFITSFieldCopier & operator=(const ArrayFITSFieldCopier< recordType, fitsType > &other)
casacore::ArrayFITSFieldCopier::ArrayFITSFieldCopier
ArrayFITSFieldCopier(const ArrayFITSFieldCopier< recordType, fitsType > &other)
Undefined and inaccessible.
casacore::ArrayFITSFieldCopier::~ArrayFITSFieldCopier
~ArrayFITSFieldCopier()
Definition FITSFieldCopier.h:250
casacore::ArrayFITSFieldCopier::copyToFITS
virtual void copyToFITS()
Copy the current contents of the input RORecordFieldPtr to the output FitsField.
Definition FITSFieldCopier.h:253
casacore::ArrayFITSFieldCopier::ArrayFITSFieldCopier
ArrayFITSFieldCopier(RORecordFieldPtr< Array< recordType > > *recptr, FitsField< fitsType > *fitsptr)
Definition FITSFieldCopier.h:248
casacore::ArrayFITSFieldCopier::fits_p
FitsField< fitsType > * fits_p
Definition FITSFieldCopier.h:270
casacore::ArrayFITSFieldCopier::rec_p
RORecordFieldPtr< Array< recordType > > * rec_p
Definition FITSFieldCopier.h:269
casacore::Array
Definition Array.h:155
casacore::FITSFieldCopier
Definition FITSFieldCopier.h:75
casacore::FITSFieldCopier::~FITSFieldCopier
virtual ~FITSFieldCopier()
destructor
Definition FITSFieldCopier.h:78
casacore::FITSFieldCopier::copyToFITS
virtual void copyToFITS()=0
the things which does the work - to be implemented in each derived class
casacore::FITSKeywordUtil::toTDIM
static Bool toTDIM(String &tdim, const IPosition &shape)
Convert an IPosition to a String appropriate for use as the value of a TDIMnnn keyword.
casacore::FitsField
helper class Note: Note that FitsField does not allocate space for the data; Space is external to Fi...
Definition hdu.h:880
casacore::RORecordFieldPtr
Read-Only access to an individual field from a Record.
Definition RecordField.h:209
casacore::ScalarFITSFieldCopier::fits_p
FitsField< fitsType > * fits_p
Definition FITSFieldCopier.h:134
casacore::ScalarFITSFieldCopier::operator=
ScalarFITSFieldCopier & operator=(const ScalarFITSFieldCopier< recordType, fitsType > &other)
casacore::ScalarFITSFieldCopier::copyToFITS
virtual void copyToFITS()
Copy the current contents of the input RORecordFieldPtr to the output FitsField.
Definition FITSFieldCopier.h:131
casacore::ScalarFITSFieldCopier::ScalarFITSFieldCopier
ScalarFITSFieldCopier(const ScalarFITSFieldCopier< recordType, fitsType > &other)
casacore::ScalarFITSFieldCopier::~ScalarFITSFieldCopier
~ScalarFITSFieldCopier()
Definition FITSFieldCopier.h:127
casacore::ScalarFITSFieldCopier::rec_p
RORecordFieldPtr< recordType > * rec_p
Definition FITSFieldCopier.h:133
casacore::ScalarFITSFieldCopier::ScalarFITSFieldCopier
ScalarFITSFieldCopier(RORecordFieldPtr< recordType > *recptr, FitsField< fitsType > *fitsptr)
Definition FITSFieldCopier.h:124
casacore::StringFITSFieldCopier::fits_p
FitsField< char > * fits_p
Definition FITSFieldCopier.h:201
casacore::StringFITSFieldCopier::StringFITSFieldCopier
StringFITSFieldCopier(const StringFITSFieldCopier &other)
Undefined and inaccessible.
casacore::StringFITSFieldCopier::copyToFITS
virtual void copyToFITS()
Copy the current contents of the input RORecordFieldPtr to the output FitsField.
Definition FITSFieldCopier.h:184
casacore::StringFITSFieldCopier::operator=
StringFITSFieldCopier & operator=(const StringFITSFieldCopier &other)
casacore::StringFITSFieldCopier::rec_p
RORecordFieldPtr< String > * rec_p
Definition FITSFieldCopier.h:200
casacore::StringFITSFieldCopier::StringFITSFieldCopier
StringFITSFieldCopier(RORecordFieldPtr< String > *rptr, FitsField< char > *fptr)
Definition FITSFieldCopier.h:180
casacore::StringFITSFieldCopier::~StringFITSFieldCopier
~StringFITSFieldCopier()
Definition FITSFieldCopier.h:198
casacore::String
String: the storage and methods of handling collections of characters.
Definition String.h:223
casacore::String::length
size_type length() const
Definition String.h:343
casacore::String::chars
const Char * chars() const
** Casacore synonym
Definition String.h:559
casacore::VariableArrayFITSFieldCopier::tdir_p
FitsField< char > * tdir_p
Definition FITSFieldCopier.h:321
casacore::VariableArrayFITSFieldCopier::copyToFITS
virtual void copyToFITS()
Copy the current contents of the input RORecordFieldPtr to the output FitsField.
Definition FITSFieldCopier.h:289
casacore::VariableArrayFITSFieldCopier::VariableArrayFITSFieldCopier
VariableArrayFITSFieldCopier(RORecordFieldPtr< Array< recordType > > *recptr, FitsField< fitsType > *fitsptr, FitsField< char > *tdirptr)
Definition FITSFieldCopier.h:282
casacore::VariableArrayFITSFieldCopier::operator=
VariableArrayFITSFieldCopier & operator=(const VariableArrayFITSFieldCopier< recordType, fitsType > &other)
casacore::VariableArrayFITSFieldCopier::fits_p
FitsField< fitsType > * fits_p
Definition FITSFieldCopier.h:320
casacore::VariableArrayFITSFieldCopier::~VariableArrayFITSFieldCopier
~VariableArrayFITSFieldCopier()
Definition FITSFieldCopier.h:286
casacore::VariableArrayFITSFieldCopier::VariableArrayFITSFieldCopier
VariableArrayFITSFieldCopier(const VariableArrayFITSFieldCopier< recordType, fitsType > &other)
Undefined and inaccessible.
casacore::VariableArrayFITSFieldCopier::rec_p
RORecordFieldPtr< Array< recordType > > * rec_p
Definition FITSFieldCopier.h:319
casacore
this file contains all the compiler specific defines
Definition mainpage.dox:28
casacore::uInt
unsigned int uInt
Definition aipstype.h:49
casacore::recordType
RecordType & recordType()
Give access to the RecordType flag (write-access is needed when a record is read back).
Definition RecordInterface.h:555
casacore::length
LatticeExprNode length(const LatticeExprNode &expr, const LatticeExprNode &axis)
2-argument function to get the length of an axis.
casacore::Int
int Int
Definition aipstype.h:48
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40