casa
$Rev:20696$
|
00001 //# FITSFieldCopier.h: Copy RORecordFields to FitsFields 00002 //# Copyright (C) 1996,1998,1999,2000,2002 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# 00027 //# $Id: FITSFieldCopier.h 18093 2004-11-30 17:51:10Z ddebonis $ 00028 00029 #ifndef FITS_FITSFIELDCOPIER_H 00030 #define FITS_FITSFIELDCOPIER_H 00031 00032 #include <casa/aips.h> 00033 #include <fits/FITS/hdu.h> 00034 #include <casa/Containers/RecordField.h> 00035 #include <casa/Arrays/Array.h> 00036 #include <casa/BasicSL/String.h> 00037 #include <fits/FITS/FITSKeywordUtil.h> 00038 00039 namespace casa { //# NAMESPACE CASA - BEGIN 00040 00041 // <summary> 00042 // Virtual base class for copying RORecordFields to FitsFields 00043 // </summary> 00044 00045 // <use visibility=local> 00046 00047 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00048 // </reviewed> 00049 00050 // <prerequisite> 00051 // <li> RORecordField 00052 // <li> FitsFields 00053 // </prerequisite> 00054 // 00055 // <etymology> 00056 // </etymology> 00057 // 00058 // <synopsis> 00059 // </synopsis> 00060 // 00061 // <example> 00062 // </example> 00063 // 00064 // <motivation> 00065 // </motivation> 00066 // 00067 // <thrown> 00068 // <li> 00069 // <li> 00070 // </thrown> 00071 // 00072 // <todo asof="yyyy/mm/dd"> 00073 // <li> actually document this 00074 // </todo> 00075 00076 00077 class FITSFieldCopier 00078 { 00079 public: 00080 // destructor 00081 virtual ~FITSFieldCopier() {}; 00082 00083 // the things which does the work - to be implemented in each derived class 00084 virtual void copyToFITS() = 0; 00085 }; 00086 00087 // <summary> 00088 // A FITSFieldCopier for copying scalar non-string RecordFields to FitsFields 00089 // </summary> 00090 00091 // <use visibility=local> 00092 00093 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00094 // </reviewed> 00095 00096 // <prerequisite> 00097 // <li> RORecordField 00098 // <li> FitsFields 00099 // </prerequisite> 00100 // 00101 // <etymology> 00102 // </etymology> 00103 // 00104 // <synopsis> 00105 // </synopsis> 00106 // 00107 // <example> 00108 // </example> 00109 // 00110 // <motivation> 00111 // </motivation> 00112 // 00113 // <thrown> 00114 // <li> 00115 // <li> 00116 // </thrown> 00117 // 00118 // <todo asof="yyyy/mm/dd"> 00119 // <li> actually document this 00120 // </todo> 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 // Copy the current contents of the input RORecordFieldPtr to the 00133 // output FitsField 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 // <summary> 00145 // A FITSFieldCopier for copying String RecordFields to FitsFields 00146 // </summary> 00147 00148 // <use visibility=local> 00149 00150 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00151 // </reviewed> 00152 00153 // <prerequisite> 00154 // <li> RORecordField 00155 // <li> FitsFields 00156 // </prerequisite> 00157 // 00158 // <etymology> 00159 // </etymology> 00160 // 00161 // <synopsis> 00162 // </synopsis> 00163 // 00164 // <example> 00165 // </example> 00166 // 00167 // <motivation> 00168 // </motivation> 00169 // 00170 // <thrown> 00171 // <li> 00172 // <li> 00173 // </thrown> 00174 // 00175 // <todo asof="yyyy/mm/dd"> 00176 // <li> actually document this 00177 // </todo> 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 // Copy the current contents of the input RORecordFieldPtr to the 00186 // output FitsField 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'; // null terminate if possible 00199 } 00200 } 00201 ~StringFITSFieldCopier() {delete rec_p; delete fits_p;} 00202 private: 00203 RORecordFieldPtr<String> *rec_p; 00204 FitsField<char> *fits_p; 00205 00206 // Undefined and inaccessible. 00207 StringFITSFieldCopier(const StringFITSFieldCopier &other); 00208 StringFITSFieldCopier &operator=(const StringFITSFieldCopier &other); 00209 }; 00210 00211 // <summary> 00212 // A FITSFieldCopier for copying Array RecordFields to FitsFields 00213 // </summary> 00214 00215 // <use visibility=local> 00216 00217 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00218 // </reviewed> 00219 00220 // <prerequisite> 00221 // <li> RORecordField 00222 // <li> FitsFields 00223 // </prerequisite> 00224 // 00225 // <etymology> 00226 // </etymology> 00227 // 00228 // <synopsis> 00229 // </synopsis> 00230 // 00231 // <example> 00232 // </example> 00233 // 00234 // <motivation> 00235 // </motivation> 00236 // 00237 // <thrown> 00238 // <li> 00239 // <li> 00240 // </thrown> 00241 // 00242 // <todo asof="yyyy/mm/dd"> 00243 // <li> actually document this 00244 // </todo> 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 // Copy the current contents of the input RORecordFieldPtr to the 00255 // output FitsField 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 // pad with nulls 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 // Undefined and inaccessible 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 // Copy the current contents of the input RORecordFieldPtr to the 00291 // output FitsField 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 // and construct the TDIM value for this array 00306 String thisTDIR; 00307 FITSKeywordUtil::toTDIM(thisTDIR, (**rec_p).shape()); 00308 // and store it in the tdir_p FitsField 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'; // null terminate if possible 00319 } 00320 } 00321 private: 00322 RORecordFieldPtr<Array<recordType> > *rec_p; 00323 FitsField<fitsType> *fits_p; 00324 FitsField<char> *tdir_p; 00325 00326 // Undefined and inaccessible 00327 VariableArrayFITSFieldCopier(const VariableArrayFITSFieldCopier<recordType,fitsType> &other); 00328 VariableArrayFITSFieldCopier &operator=( 00329 const VariableArrayFITSFieldCopier<recordType,fitsType> &other); 00330 }; 00331 00332 00333 } //# NAMESPACE CASA - END 00334 00335 #endif