casacore
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: aips2-request@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 //#
27 //# $Id$
28 
29 #ifndef FITS_FITSFIELDCOPIER_H
30 #define FITS_FITSFIELDCOPIER_H
31 
32 #include <casacore/casa/aips.h>
33 #include <casacore/fits/FITS/hdu.h>
34 #include <casacore/casa/Containers/RecordField.h>
35 #include <casacore/casa/Arrays/Array.h>
36 #include <casacore/casa/BasicSL/String.h>
37 #include <casacore/fits/FITS/FITSKeywordUtil.h>
38 
39 namespace casacore { //# NAMESPACE CASACORE - BEGIN
40 
41 // <summary>
42 // Virtual base class for copying RORecordFields to FitsFields
43 // </summary>
44 
45 // <use visibility=local>
46 
47 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
48 // </reviewed>
49 
50 // <prerequisite>
51 // <li> RORecordField
52 // <li> FitsFields
53 // </prerequisite>
54 //
55 // <etymology>
56 // </etymology>
57 //
58 // <synopsis>
59 // </synopsis>
60 //
61 // <example>
62 // </example>
63 //
64 // <motivation>
65 // </motivation>
66 //
67 // <thrown>
68 // <li>
69 // <li>
70 // </thrown>
71 //
72 // <todo asof="yyyy/mm/dd">
73 // <li> actually document this
74 // </todo>
75 
76 
78 {
79 public:
80  // destructor
81  virtual ~FITSFieldCopier() {};
82 
83  // the things which does the work - to be implemented in each derived class
84  virtual void copyToFITS() = 0;
85 };
86 
87 // <summary>
88 // A FITSFieldCopier for copying scalar non-string RecordFields to FitsFields
89 // </summary>
90 
91 // <use visibility=local>
92 
93 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
94 // </reviewed>
95 
96 // <prerequisite>
97 // <li> RORecordField
98 // <li> FitsFields
99 // </prerequisite>
100 //
101 // <etymology>
102 // </etymology>
103 //
104 // <synopsis>
105 // </synopsis>
106 //
107 // <example>
108 // </example>
109 //
110 // <motivation>
111 // </motivation>
112 //
113 // <thrown>
114 // <li>
115 // <li>
116 // </thrown>
117 //
118 // <todo asof="yyyy/mm/dd">
119 // <li> actually document this
120 // </todo>
121 
122 
123 template<class recordType, class fitsType> class ScalarFITSFieldCopier :
124  public FITSFieldCopier
125 {
126 public:
128  FitsField<fitsType> *fitsptr)
129  : rec_p(recptr), fits_p(fitsptr) {}
130  ~ScalarFITSFieldCopier() {delete rec_p; delete fits_p;}
131 
132  // Copy the current contents of the input RORecordFieldPtr to the
133  // output FitsField
134  virtual void copyToFITS() {(*fits_p)() = *(*rec_p); }
135 private:
138 
142 };
143 
144 // <summary>
145 // A FITSFieldCopier for copying String RecordFields to FitsFields
146 // </summary>
147 
148 // <use visibility=local>
149 
150 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
151 // </reviewed>
152 
153 // <prerequisite>
154 // <li> RORecordField
155 // <li> FitsFields
156 // </prerequisite>
157 //
158 // <etymology>
159 // </etymology>
160 //
161 // <synopsis>
162 // </synopsis>
163 //
164 // <example>
165 // </example>
166 //
167 // <motivation>
168 // </motivation>
169 //
170 // <thrown>
171 // <li>
172 // <li>
173 // </thrown>
174 //
175 // <todo asof="yyyy/mm/dd">
176 // <li> actually document this
177 // </todo>
178 
179 
181 {
182  public:
184  FitsField<char> *fptr) : rec_p(rptr), fits_p(fptr) {}
185  // Copy the current contents of the input RORecordFieldPtr to the
186  // output FitsField
187  virtual void copyToFITS()
188  {
189  Int fitslength = fits_p->nelements();
190  Int reclength = (*(*rec_p)).length();
191  Int minlength = fitslength < reclength ? fitslength : reclength;
192  const char *chars = (**rec_p).chars();
193  Int i;
194  for (i=0; i<minlength; i++) {
195  (*fits_p)(i) = chars[i];
196  }
197  if (i < fitslength) {
198  (*fits_p)(i) = '\0'; // null terminate if possible
199  }
200  }
201  ~StringFITSFieldCopier() {delete rec_p; delete fits_p;}
202 private:
205 
206  // Undefined and inaccessible.
209 };
210 
211 // <summary>
212 // A FITSFieldCopier for copying Array RecordFields to FitsFields
213 // </summary>
214 
215 // <use visibility=local>
216 
217 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
218 // </reviewed>
219 
220 // <prerequisite>
221 // <li> RORecordField
222 // <li> FitsFields
223 // </prerequisite>
224 //
225 // <etymology>
226 // </etymology>
227 //
228 // <synopsis>
229 // </synopsis>
230 //
231 // <example>
232 // </example>
233 //
234 // <motivation>
235 // </motivation>
236 //
237 // <thrown>
238 // <li>
239 // <li>
240 // </thrown>
241 //
242 // <todo asof="yyyy/mm/dd">
243 // <li> actually document this
244 // </todo>
245 
246 
247 template<class recordType, class fitsType> class ArrayFITSFieldCopier :
248  public FITSFieldCopier
249 {
250 public:
252  FitsField<fitsType> *fitsptr) : rec_p(recptr), fits_p(fitsptr) {}
253  ~ArrayFITSFieldCopier() {delete rec_p; delete fits_p;}
254  // Copy the current contents of the input RORecordFieldPtr to the
255  // output FitsField
256  virtual void copyToFITS() {
257  uInt nfits = fits_p->nelements();
258  uInt narray = (**rec_p).nelements();
259  uInt nmin = narray < nfits ? narray : nfits;
260  Bool deleteIt;
261  const recordType *rptr = (**rec_p).getStorage(deleteIt);
262  for (uInt i=0; i<nmin; i++) {
263  (*fits_p)(i) = rptr[i];
264  }
265  // pad with nulls
266  for (uInt i=nmin;i<nfits;i++) {
267  (*fits_p)(i) = recordType(0);
268  }
269  (**rec_p).freeStorage(rptr, deleteIt);
270  }
271 private:
274 
275  // Undefined and inaccessible
279 };
280 
281 template<class recordType, class fitsType> class VariableArrayFITSFieldCopier :
282  public FITSFieldCopier
283 {
284 public:
286  FitsField<fitsType> *fitsptr,
287  FitsField<char> *tdirptr)
288  : rec_p(recptr), fits_p(fitsptr), tdir_p(tdirptr) {}
290  // Copy the current contents of the input RORecordFieldPtr to the
291  // output FitsField
292  virtual void copyToFITS() {
293  uInt nfits = fits_p->nelements();
294  uInt narray = (**rec_p).nelements();
295  uInt nmin = narray < nfits ? narray : nfits;
296  Bool deleteIt;
297  const recordType *rptr = (**rec_p).getStorage(deleteIt);
298  for (uInt i=0; i<nmin; i++) {
299  (*fits_p)(i) = rptr[i];
300  }
301  for (uInt i=nmin;i<nfits;i++) {
302  (*fits_p)(i) = recordType(0);
303  }
304  (**rec_p).freeStorage(rptr, deleteIt);
305  // and construct the TDIM value for this array
306  String thisTDIR;
307  FITSKeywordUtil::toTDIM(thisTDIR, (**rec_p).shape());
308  // and store it in the tdir_p FitsField
309  Int fitslength = tdir_p->nelements();
310  Int reclength = thisTDIR.length();
311  Int minlength = fitslength < reclength ? fitslength : reclength;
312  const char *chars = thisTDIR.chars();
313  Int i;
314  for (i=0; i<minlength; i++) {
315  (*tdir_p)(i) = chars[i];
316  }
317  for (Int i=minlength; i<fitslength; i++) {
318  (*tdir_p)(i) = '\0'; // null terminate if possible
319  }
320  }
321 private:
325 
326  // Undefined and inaccessible
330 };
331 
332 
333 } //# NAMESPACE CASACORE - END
334 
335 #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:848
A FITSFieldCopier for copying scalar non-string RecordFields to FitsFields.
FitsField< fitsType > * fits_p
virtual void copyToFITS()
Copy the current contents of the input RORecordFieldPtr to the output FitsField.
ScalarFITSFieldCopier(const ScalarFITSFieldCopier< recordType, fitsType > &other)
ScalarFITSFieldCopier & operator=(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:225
size_type length() const
Definition: String.h:345
const Char * chars() const
** Casacore synonym
Definition: String.h:561
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(const VariableArrayFITSFieldCopier< recordType, fitsType > &other)
Undefined and inaccessible.
VariableArrayFITSFieldCopier & operator=(const VariableArrayFITSFieldCopier< recordType, fitsType > &other)
RORecordFieldPtr< Array< recordType > > * rec_p
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:51
LatticeExprNode length(const LatticeExprNode &expr, const LatticeExprNode &axis)
2-argument function to get the length of an axis.
int Int
Definition: aipstype.h:50
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42