summaryrefslogtreecommitdiffstats
path: root/tksao/fitsy++/envi.C
diff options
context:
space:
mode:
authorWilliam Joye <wjoye@cfa.harvard.edu>2016-10-27 18:59:29 (GMT)
committerWilliam Joye <wjoye@cfa.harvard.edu>2016-10-27 18:59:29 (GMT)
commitd4d595fa7fb12903db9227d33d48b2b00120dbd1 (patch)
tree7d18365de0d6d1b29399b6a17c7eb01c2eb3ed49 /tksao/fitsy++/envi.C
parent949f96e29bfe0bd8710d775ce220e597064e2589 (diff)
downloadblt-d4d595fa7fb12903db9227d33d48b2b00120dbd1.zip
blt-d4d595fa7fb12903db9227d33d48b2b00120dbd1.tar.gz
blt-d4d595fa7fb12903db9227d33d48b2b00120dbd1.tar.bz2
Initial commit
Diffstat (limited to 'tksao/fitsy++/envi.C')
-rw-r--r--tksao/fitsy++/envi.C141
1 files changed, 141 insertions, 0 deletions
diff --git a/tksao/fitsy++/envi.C b/tksao/fitsy++/envi.C
new file mode 100644
index 0000000..08b0cc0
--- /dev/null
+++ b/tksao/fitsy++/envi.C
@@ -0,0 +1,141 @@
+// Copyright (C) 1999-2016
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "envi.h"
+#include "head.h"
+
+FitsENVI::FitsENVI(FitsFile* fits)
+{
+ byteswap_ = fits->byteswap();
+ endian_ = fits->endian();
+
+ pBitpix_ = fits->pBitpix();
+ pWidth_ = fits->pWidth();
+ pHeight_ = fits->pHeight();
+ pDepth_ = fits->pDepth();
+
+ pEncoding_ = FitsFile::BSQ;
+
+ pCRPIX3_ = fits->pCRPIX3();
+ pCRVAL3_ = fits->pCRVAL3();
+ pCDELT3_ = fits->pCDELT3();
+
+ size_ = (size_t)pWidth_*pHeight_*pDepth_;
+}
+
+FitsENVI::~FitsENVI()
+{
+ if (data_)
+ delete [] (char*)data_;
+}
+
+int FitsENVI::initHeader(FitsFile* fits)
+{
+ // simple check
+ if (!pWidth_ || !pHeight_ || !pBitpix_)
+ return 0;
+
+ // create header
+ head_ = new FitsHead(pWidth_, pHeight_, pDepth_, pBitpix_);
+ if (!head_->isValid())
+ return 0;
+
+ // WCS?
+ if (pCRPIX3_>0 || pCRVAL3_>0 || pCDELT3_!=1) {
+ head_->appendString("CTYPE1","LINEAR", NULL);
+ head_->appendReal("CRPIX1",1, 9, NULL);
+ head_->appendReal("CRVAL1",1, 9, NULL);
+ head_->appendReal("CDELT1",1, 9, NULL);
+
+ head_->appendString("CTYPE2","LINEAR", NULL);
+ head_->appendReal("CRPIX2",1, 9, NULL);
+ head_->appendReal("CRVAL2",1, 9, NULL);
+ head_->appendReal("CDELT2",1, 9, NULL);
+
+ head_->appendString("CTYPE3","WAVELENGTH", NULL);
+ head_->appendReal("CRPIX3",pCRPIX3_, 9, NULL);
+ head_->appendReal("CRVAL3",pCRVAL3_, 9, NULL);
+ head_->appendReal("CDELT3",pCDELT3_, 9, NULL);
+ }
+
+ // other
+ primary_ = fits->primary();
+ managePrimary_ = 0;
+
+ inherit_ = head_->inherit();
+
+ return 1;
+}
+
+template <class T> FitsENVIBIPm<T>::FitsENVIBIPm(FitsFile* fits)
+ : FitsENVI(fits)
+{
+ if (!initHeader(fits))
+ return;
+
+ T* dest = new T[size_];
+ if (!dest) {
+ internalError("Fitsy++ envi unable to allocate memory");
+ return;
+ }
+ memset(dest, 0, size_*sizeof(T));
+
+ T* ptr = (T*)fits->data();
+ for (int jj=0; jj<pHeight_; jj++)
+ for (int ii=0; ii<pWidth_; ii++)
+ for (int kk=0; kk<pDepth_; kk++)
+ dest[kk*pWidth_*pHeight_ + jj*pWidth_ + ii] = *ptr++;
+
+ data_ = dest;
+
+ dataSize_ = size_;
+ dataSkip_ = 0;
+
+ // all done
+ valid_ = 1;
+}
+
+template class FitsENVIBIPm<unsigned char>;
+template class FitsENVIBIPm<short>;
+template class FitsENVIBIPm<unsigned short>;
+template class FitsENVIBIPm<int>;
+template class FitsENVIBIPm<long long>;
+template class FitsENVIBIPm<float>;
+template class FitsENVIBIPm<double>;
+
+template <class T> FitsENVIBILm<T>::FitsENVIBILm(FitsFile* fits)
+ : FitsENVI(fits)
+{
+ if (!initHeader(fits))
+ return;
+
+ T* dest = new T[size_];
+ if (!dest) {
+ internalError("Fitsy++ envi unable to allocate memory");
+ return;
+ }
+ memset(dest, 0, size_*sizeof(T));
+
+ T* ptr = (T*)fits->data();
+ for (int jj=0; jj<pHeight_; jj++)
+ for (int kk=0; kk<pDepth_; kk++)
+ for (int ii=0; ii<pWidth_; ii++)
+ dest[kk*pWidth_*pHeight_ + jj*pWidth_ + ii] = *ptr++;
+
+ data_ = dest;
+
+ dataSize_ = size_;
+ dataSkip_ = 0;
+
+ // all done
+ valid_ = 1;
+}
+
+template class FitsENVIBILm<unsigned char>;
+template class FitsENVIBILm<short>;
+template class FitsENVIBILm<unsigned short>;
+template class FitsENVIBILm<int>;
+template class FitsENVIBILm<long long>;
+template class FitsENVIBILm<float>;
+template class FitsENVIBILm<double>;