casacore
Loading...
Searching...
No Matches
FITSFieldCopier.h
Go to the documentation of this file.
1//# FITSFieldCopier.h: Copy RORecordFields to FitsFields
2//# Copyright (C) 1996,1998,1999,2000,2002
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef FITS_FITSFIELDCOPIER_H
27#define FITS_FITSFIELDCOPIER_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/fits/FITS/hdu.h>
31#include <casacore/casa/Containers/RecordField.h>
32#include <casacore/casa/Arrays/Array.h>
33#include <casacore/casa/BasicSL/String.h>
34#include <casacore/fits/FITS/FITSKeywordUtil.h>
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38// <summary>
39// Virtual base class for copying RORecordFields to FitsFields
40// </summary>
41
42// <use visibility=local>
43
44// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
45// </reviewed>
46
47// <prerequisite>
48// <li> RORecordField
49// <li> FitsFields
50// </prerequisite>
51//
52// <etymology>
53// </etymology>
54//
55// <synopsis>
56// </synopsis>
57//
58// <example>
59// </example>
60//
61// <motivation>
62// </motivation>
63//
64// <thrown>
65// <li>
66// <li>
67// </thrown>
68//
69// <todo asof="yyyy/mm/dd">
70// <li> actually document this
71// </todo>
72
73
75{
76public:
77 // destructor
78 virtual ~FITSFieldCopier() {};
79
80 // the things which does the work - to be implemented in each derived class
81 virtual void copyToFITS() = 0;
82};
83
84// <summary>
85// A FITSFieldCopier for copying scalar non-string RecordFields to FitsFields
86// </summary>
87
88// <use visibility=local>
89
90// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
91// </reviewed>
92
93// <prerequisite>
94// <li> RORecordField
95// <li> FitsFields
96// </prerequisite>
97//
98// <etymology>
99// </etymology>
100//
101// <synopsis>
102// </synopsis>
103//
104// <example>
105// </example>
106//
107// <motivation>
108// </motivation>
109//
110// <thrown>
111// <li>
112// <li>
113// </thrown>
114//
115// <todo asof="yyyy/mm/dd">
116// <li> actually document this
117// </todo>
118
119
120template<class recordType, class fitsType> class ScalarFITSFieldCopier :
121 public FITSFieldCopier
122{
123public:
125 FitsField<fitsType> *fitsptr)
126 : rec_p(recptr), fits_p(fitsptr) {}
128
129 // Copy the current contents of the input RORecordFieldPtr to the
130 // output FitsField
131 virtual void copyToFITS() {(*fits_p)() = *(*rec_p); }
132private:
135
139};
140
141// <summary>
142// A FITSFieldCopier for copying String RecordFields to FitsFields
143// </summary>
144
145// <use visibility=local>
146
147// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
148// </reviewed>
149
150// <prerequisite>
151// <li> RORecordField
152// <li> FitsFields
153// </prerequisite>
154//
155// <etymology>
156// </etymology>
157//
158// <synopsis>
159// </synopsis>
160//
161// <example>
162// </example>
163//
164// <motivation>
165// </motivation>
166//
167// <thrown>
168// <li>
169// <li>
170// </thrown>
171//
172// <todo asof="yyyy/mm/dd">
173// <li> actually document this
174// </todo>
175
176
178{
179 public:
182 // Copy the current contents of the input RORecordFieldPtr to the
183 // output FitsField
184 virtual void copyToFITS()
185 {
186 Int fitslength = fits_p->nelements();
187 Int reclength = (*(*rec_p)).length();
188 Int minlength = fitslength < reclength ? fitslength : reclength;
189 const char *chars = (**rec_p).chars();
190 Int i;
191 for (i=0; i<minlength; i++) {
192 (*fits_p)(i) = chars[i];
193 }
194 if (i < fitslength) {
195 (*fits_p)(i) = '\0'; // null terminate if possible
196 }
197 }
199private:
202
203 // Undefined and inaccessible.
206};
207
208// <summary>
209// A FITSFieldCopier for copying Array RecordFields to FitsFields
210// </summary>
211
212// <use visibility=local>
213
214// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
215// </reviewed>
216
217// <prerequisite>
218// <li> RORecordField
219// <li> FitsFields
220// </prerequisite>
221//
222// <etymology>
223// </etymology>
224//
225// <synopsis>
226// </synopsis>
227//
228// <example>
229// </example>
230//
231// <motivation>
232// </motivation>
233//
234// <thrown>
235// <li>
236// <li>
237// </thrown>
238//
239// <todo asof="yyyy/mm/dd">
240// <li> actually document this
241// </todo>
242
243
244template<class recordType, class fitsType> class ArrayFITSFieldCopier :
245 public FITSFieldCopier
246{
247public:
251 // Copy the current contents of the input RORecordFieldPtr to the
252 // output FitsField
253 virtual void copyToFITS() {
254 uInt nfits = fits_p->nelements();
255 uInt narray = (**rec_p).nelements();
256 uInt nmin = narray < nfits ? narray : nfits;
257 Bool deleteIt;
258 const recordType *rptr = (**rec_p).getStorage(deleteIt);
259 for (uInt i=0; i<nmin; i++) {
260 (*fits_p)(i) = rptr[i];
261 }
262 // pad with nulls
263 for (uInt i=nmin;i<nfits;i++) {
264 (*fits_p)(i) = recordType(0);
265 }
266 (**rec_p).freeStorage(rptr, deleteIt);
267 }
268private:
271
272 // Undefined and inaccessible
276};
277
278template<class recordType, class fitsType> class VariableArrayFITSFieldCopier :
279 public FITSFieldCopier
280{
281public:
283 FitsField<fitsType> *fitsptr,
284 FitsField<char> *tdirptr)
285 : rec_p(recptr), fits_p(fitsptr), tdir_p(tdirptr) {}
287 // Copy the current contents of the input RORecordFieldPtr to the
288 // output FitsField
289 virtual void copyToFITS() {
290 uInt nfits = fits_p->nelements();
291 uInt narray = (**rec_p).nelements();
292 uInt nmin = narray < nfits ? narray : nfits;
293 Bool deleteIt;
294 const recordType *rptr = (**rec_p).getStorage(deleteIt);
295 for (uInt i=0; i<nmin; i++) {
296 (*fits_p)(i) = rptr[i];
297 }
298 for (uInt i=nmin;i<nfits;i++) {
299 (*fits_p)(i) = recordType(0);
300 }
301 (**rec_p).freeStorage(rptr, deleteIt);
302 // and construct the TDIM value for this array
303 String thisTDIR;
304 FITSKeywordUtil::toTDIM(thisTDIR, (**rec_p).shape());
305 // and store it in the tdir_p FitsField
306 Int fitslength = tdir_p->nelements();
307 Int reclength = thisTDIR.length();
308 Int minlength = fitslength < reclength ? fitslength : reclength;
309 const char *chars = thisTDIR.chars();
310 Int i;
311 for (i=0; i<minlength; i++) {
312 (*tdir_p)(i) = chars[i];
313 }
314 for (Int i=minlength; i<fitslength; i++) {
315 (*tdir_p)(i) = '\0'; // null terminate if possible
316 }
317 }
318private:
322
323 // Undefined and inaccessible
327};
328
329
330} //# NAMESPACE CASACORE - END
331
332#endif
A FITSFieldCopier for copying Array RecordFields to FitsFields.
ArrayFITSFieldCopier & operator=(const ArrayFITSFieldCopier< recordType, fitsType > &other)
ArrayFITSFieldCopier(const ArrayFITSFieldCopier< recordType, fitsType > &other)
Undefined and inaccessible.
virtual void copyToFITS()
Copy the current contents of the input RORecordFieldPtr to the output FitsField.
ArrayFITSFieldCopier(RORecordFieldPtr< Array< recordType > > *recptr, FitsField< fitsType > *fitsptr)
FitsField< fitsType > * fits_p
RORecordFieldPtr< Array< recordType > > * rec_p
virtual ~FITSFieldCopier()
destructor
virtual void copyToFITS()=0
the things which does the work - to be implemented in each derived class
static Bool toTDIM(String &tdim, const IPosition &shape)
Convert an IPosition to a String appropriate for use as the value of a TDIMnnn keyword.
unsigned int nelements() const
Definition hdu.h:846
helper class Note: Note that FitsField does not allocate space for the data; Space is external to Fi...
Definition hdu.h:880
Read-Only access to an individual field from a Record.
A FITSFieldCopier for copying scalar non-string RecordFields to FitsFields.
FitsField< fitsType > * fits_p
ScalarFITSFieldCopier & operator=(const ScalarFITSFieldCopier< recordType, fitsType > &other)
virtual void copyToFITS()
Copy the current contents of the input RORecordFieldPtr to the output FitsField.
ScalarFITSFieldCopier(const ScalarFITSFieldCopier< recordType, fitsType > &other)
RORecordFieldPtr< recordType > * rec_p
ScalarFITSFieldCopier(RORecordFieldPtr< recordType > *recptr, FitsField< fitsType > *fitsptr)
A FITSFieldCopier for copying String RecordFields to FitsFields.
StringFITSFieldCopier(const StringFITSFieldCopier &other)
Undefined and inaccessible.
virtual void copyToFITS()
Copy the current contents of the input RORecordFieldPtr to the output FitsField.
StringFITSFieldCopier & operator=(const StringFITSFieldCopier &other)
RORecordFieldPtr< String > * rec_p
StringFITSFieldCopier(RORecordFieldPtr< String > *rptr, FitsField< char > *fptr)
String: the storage and methods of handling collections of characters.
Definition String.h:223
size_type length() const
Definition String.h:343
const Char * chars() const
** Casacore synonym
Definition String.h:559
virtual void copyToFITS()
Copy the current contents of the input RORecordFieldPtr to the output FitsField.
VariableArrayFITSFieldCopier(RORecordFieldPtr< Array< recordType > > *recptr, FitsField< fitsType > *fitsptr, FitsField< char > *tdirptr)
VariableArrayFITSFieldCopier & operator=(const VariableArrayFITSFieldCopier< recordType, fitsType > &other)
VariableArrayFITSFieldCopier(const VariableArrayFITSFieldCopier< recordType, fitsType > &other)
Undefined and inaccessible.
RORecordFieldPtr< Array< recordType > > * rec_p
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
LatticeExprNode length(const LatticeExprNode &expr, const LatticeExprNode &axis)
2-argument function to get the length of an axis.
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40