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
74 public:
75 // destructor
76 virtual ~FITSFieldCopier() {};
77
78 // the things which does the work - to be implemented in each derived class
79 virtual void copyToFITS() = 0;
80};
81
82// <summary>
83// A FITSFieldCopier for copying scalar non-string RecordFields to FitsFields
84// </summary>
85
86// <use visibility=local>
87
88// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
89// </reviewed>
90
91// <prerequisite>
92// <li> RORecordField
93// <li> FitsFields
94// </prerequisite>
95//
96// <etymology>
97// </etymology>
98//
99// <synopsis>
100// </synopsis>
101//
102// <example>
103// </example>
104//
105// <motivation>
106// </motivation>
107//
108// <thrown>
109// <li>
110// <li>
111// </thrown>
112//
113// <todo asof="yyyy/mm/dd">
114// <li> actually document this
115// </todo>
116
117template <class recordType, class fitsType>
119 public:
123 delete rec_p;
124 delete fits_p;
125 }
126
127 // Copy the current contents of the input RORecordFieldPtr to the
128 // output FitsField
129 virtual void copyToFITS() { (*fits_p)() = *(*rec_p); }
130
131 private:
134
137};
138
139// <summary>
140// A FITSFieldCopier for copying String RecordFields to FitsFields
141// </summary>
142
143// <use visibility=local>
144
145// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
146// </reviewed>
147
148// <prerequisite>
149// <li> RORecordField
150// <li> FitsFields
151// </prerequisite>
152//
153// <etymology>
154// </etymology>
155//
156// <synopsis>
157// </synopsis>
158//
159// <example>
160// </example>
161//
162// <motivation>
163// </motivation>
164//
165// <thrown>
166// <li>
167// <li>
168// </thrown>
169//
170// <todo asof="yyyy/mm/dd">
171// <li> actually document this
172// </todo>
173
175 public:
178 // Copy the current contents of the input RORecordFieldPtr to the
179 // output FitsField
180 virtual void copyToFITS() {
181 Int fitslength = fits_p->nelements();
182 Int reclength = (*(*rec_p)).length();
183 Int minlength = fitslength < reclength ? fitslength : reclength;
184 const char *chars = (**rec_p).c_str();
185 Int i;
186 for (i = 0; i < minlength; i++) {
187 (*fits_p)(i) = chars[i];
188 }
189 if (i < fitslength) {
190 (*fits_p)(i) = '\0'; // null terminate if possible
191 }
192 }
194 delete rec_p;
195 delete fits_p;
196 }
197
198 private:
201
202 // Undefined and inaccessible.
205};
206
207// <summary>
208// A FITSFieldCopier for copying Array RecordFields to FitsFields
209// </summary>
210
211// <use visibility=local>
212
213// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
214// </reviewed>
215
216// <prerequisite>
217// <li> RORecordField
218// <li> FitsFields
219// </prerequisite>
220//
221// <etymology>
222// </etymology>
223//
224// <synopsis>
225// </synopsis>
226//
227// <example>
228// </example>
229//
230// <motivation>
231// </motivation>
232//
233// <thrown>
234// <li>
235// <li>
236// </thrown>
237//
238// <todo asof="yyyy/mm/dd">
239// <li> actually document this
240// </todo>
241
242template <class recordType, class fitsType>
244 public:
248 delete rec_p;
249 delete fits_p;
250 }
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 }
268
269 private:
272
273 // Undefined and inaccessible
276};
277
278template <class recordType, class fitsType>
280 public:
282 FitsField<fitsType> *fitsptr, FitsField<char> *tdirptr)
283 : rec_p(recptr), fits_p(fitsptr), tdir_p(tdirptr) {}
285 delete rec_p;
286 delete fits_p;
287 }
288 // Copy the current contents of the input RORecordFieldPtr to the
289 // output FitsField
290 virtual void copyToFITS() {
291 uInt nfits = fits_p->nelements();
292 uInt narray = (**rec_p).nelements();
293 uInt nmin = narray < nfits ? narray : nfits;
294 Bool deleteIt;
295 const recordType *rptr = (**rec_p).getStorage(deleteIt);
296 for (uInt i = 0; i < nmin; i++) {
297 (*fits_p)(i) = rptr[i];
298 }
299 for (uInt i = nmin; i < nfits; i++) {
300 (*fits_p)(i) = recordType(0);
301 }
302 (**rec_p).freeStorage(rptr, deleteIt);
303 // and construct the TDIM value for this array
304 String thisTDIR;
305 FITSKeywordUtil::toTDIM(thisTDIR, (**rec_p).shape());
306 // and store it in the tdir_p FitsField
307 Int fitslength = tdir_p->nelements();
308 Int reclength = thisTDIR.length();
309 Int minlength = fitslength < reclength ? fitslength : reclength;
310 const char *chars = thisTDIR.c_str();
311 Int i;
312 for (i = 0; i < minlength; i++) {
313 (*tdir_p)(i) = chars[i];
314 }
315 for (Int i = minlength; i < fitslength; i++) {
316 (*tdir_p)(i) = '\0'; // null terminate if possible
317 }
318 }
319
320 private:
324
325 // Undefined and inaccessible
329};
330
331} // namespace casacore
332
333#endif
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.
helper class Note: Note that FitsField does not allocate space for the data; Space is external to Fi...
Definition hdu.h:911
Read-Only access to an individual field from a Record.
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)
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:355
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
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
RecordType & recordType()
Give access to the RecordType flag (write-access is needed when a record is read back).
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