FITSFieldCopier.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef FITS_FITSFIELDCOPIER_H
00030 #define FITS_FITSFIELDCOPIER_H
00031
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/fits/FITS/hdu.h>
00034 #include <casacore/casa/Containers/RecordField.h>
00035 #include <casacore/casa/Arrays/Array.h>
00036 #include <casacore/casa/BasicSL/String.h>
00037 #include <casacore/fits/FITS/FITSKeywordUtil.h>
00038
00039 namespace casacore {
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 class FITSFieldCopier
00078 {
00079 public:
00080
00081 virtual ~FITSFieldCopier() {};
00082
00083
00084 virtual void copyToFITS() = 0;
00085 };
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 template<class recordType, class fitsType> class ScalarFITSFieldCopier :
00124 public FITSFieldCopier
00125 {
00126 public:
00127 ScalarFITSFieldCopier(RORecordFieldPtr<recordType> *recptr,
00128 FitsField<fitsType> *fitsptr)
00129 : rec_p(recptr), fits_p(fitsptr) {}
00130 ~ScalarFITSFieldCopier() {delete rec_p; delete fits_p;}
00131
00132
00133
00134 virtual void copyToFITS() {(*fits_p)() = *(*rec_p); }
00135 private:
00136 RORecordFieldPtr<recordType> *rec_p;
00137 FitsField<fitsType> *fits_p;
00138
00139 ScalarFITSFieldCopier(const ScalarFITSFieldCopier<recordType,fitsType> &other);
00140 ScalarFITSFieldCopier &operator=(
00141 const ScalarFITSFieldCopier<recordType,fitsType> &other);
00142 };
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 class StringFITSFieldCopier : public FITSFieldCopier
00181 {
00182 public:
00183 StringFITSFieldCopier(RORecordFieldPtr<String> *rptr,
00184 FitsField<char> *fptr) : rec_p(rptr), fits_p(fptr) {}
00185
00186
00187 virtual void copyToFITS()
00188 {
00189 Int fitslength = fits_p->nelements();
00190 Int reclength = (*(*rec_p)).length();
00191 Int minlength = fitslength < reclength ? fitslength : reclength;
00192 const char *chars = (**rec_p).chars();
00193 Int i;
00194 for (i=0; i<minlength; i++) {
00195 (*fits_p)(i) = chars[i];
00196 }
00197 if (i < fitslength) {
00198 (*fits_p)(i) = '\0';
00199 }
00200 }
00201 ~StringFITSFieldCopier() {delete rec_p; delete fits_p;}
00202 private:
00203 RORecordFieldPtr<String> *rec_p;
00204 FitsField<char> *fits_p;
00205
00206
00207 StringFITSFieldCopier(const StringFITSFieldCopier &other);
00208 StringFITSFieldCopier &operator=(const StringFITSFieldCopier &other);
00209 };
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 template<class recordType, class fitsType> class ArrayFITSFieldCopier :
00248 public FITSFieldCopier
00249 {
00250 public:
00251 ArrayFITSFieldCopier(RORecordFieldPtr<Array<recordType> > *recptr,
00252 FitsField<fitsType> *fitsptr) : rec_p(recptr), fits_p(fitsptr) {}
00253 ~ArrayFITSFieldCopier() {delete rec_p; delete fits_p;}
00254
00255
00256 virtual void copyToFITS() {
00257 uInt nfits = fits_p->nelements();
00258 uInt narray = (**rec_p).nelements();
00259 uInt nmin = narray < nfits ? narray : nfits;
00260 Bool deleteIt;
00261 const recordType *rptr = (**rec_p).getStorage(deleteIt);
00262 for (uInt i=0; i<nmin; i++) {
00263 (*fits_p)(i) = rptr[i];
00264 }
00265
00266 for (uInt i=nmin;i<nfits;i++) {
00267 (*fits_p)(i) = recordType(0);
00268 }
00269 (**rec_p).freeStorage(rptr, deleteIt);
00270 }
00271 private:
00272 RORecordFieldPtr<Array<recordType> > *rec_p;
00273 FitsField<fitsType> *fits_p;
00274
00275
00276 ArrayFITSFieldCopier(const ArrayFITSFieldCopier<recordType,fitsType> &other);
00277 ArrayFITSFieldCopier &operator=(
00278 const ArrayFITSFieldCopier<recordType,fitsType> &other);
00279 };
00280
00281 template<class recordType, class fitsType> class VariableArrayFITSFieldCopier :
00282 public FITSFieldCopier
00283 {
00284 public:
00285 VariableArrayFITSFieldCopier(RORecordFieldPtr<Array<recordType> > *recptr,
00286 FitsField<fitsType> *fitsptr,
00287 FitsField<char> *tdirptr)
00288 : rec_p(recptr), fits_p(fitsptr), tdir_p(tdirptr) {}
00289 ~VariableArrayFITSFieldCopier() {delete rec_p; delete fits_p;}
00290
00291
00292 virtual void copyToFITS() {
00293 uInt nfits = fits_p->nelements();
00294 uInt narray = (**rec_p).nelements();
00295 uInt nmin = narray < nfits ? narray : nfits;
00296 Bool deleteIt;
00297 const recordType *rptr = (**rec_p).getStorage(deleteIt);
00298 for (uInt i=0; i<nmin; i++) {
00299 (*fits_p)(i) = rptr[i];
00300 }
00301 for (uInt i=nmin;i<nfits;i++) {
00302 (*fits_p)(i) = recordType(0);
00303 }
00304 (**rec_p).freeStorage(rptr, deleteIt);
00305
00306 String thisTDIR;
00307 FITSKeywordUtil::toTDIM(thisTDIR, (**rec_p).shape());
00308
00309 Int fitslength = tdir_p->nelements();
00310 Int reclength = thisTDIR.length();
00311 Int minlength = fitslength < reclength ? fitslength : reclength;
00312 const char *chars = thisTDIR.chars();
00313 Int i;
00314 for (i=0; i<minlength; i++) {
00315 (*tdir_p)(i) = chars[i];
00316 }
00317 for (Int i=minlength; i<fitslength; i++) {
00318 (*tdir_p)(i) = '\0';
00319 }
00320 }
00321 private:
00322 RORecordFieldPtr<Array<recordType> > *rec_p;
00323 FitsField<fitsType> *fits_p;
00324 FitsField<char> *tdir_p;
00325
00326
00327 VariableArrayFITSFieldCopier(const VariableArrayFITSFieldCopier<recordType,fitsType> &other);
00328 VariableArrayFITSFieldCopier &operator=(
00329 const VariableArrayFITSFieldCopier<recordType,fitsType> &other);
00330 };
00331
00332
00333 }
00334
00335 #endif