diff options
author | William Joye <wjoye@cfa.harvard.edu> | 2017-08-01 18:23:30 (GMT) |
---|---|---|
committer | William Joye <wjoye@cfa.harvard.edu> | 2017-08-01 18:23:30 (GMT) |
commit | 82f9236f580ff81aa856a2a20e5e3716854ca4f0 (patch) | |
tree | 31252e13f25c726a4ecd17dde2e38eaee5f2451d | |
parent | f150aca834519d829cc482fe03be43d054669a3e (diff) | |
download | blt-82f9236f580ff81aa856a2a20e5e3716854ca4f0.zip blt-82f9236f580ff81aa856a2a20e5e3716854ca4f0.tar.gz blt-82f9236f580ff81aa856a2a20e5e3716854ca4f0.tar.bz2 |
CUBE: remove un-needed WCS keywords when saving as a slice
-rw-r--r-- | tksao/fitsy++/file.h | 1 | ||||
-rw-r--r-- | tksao/fitsy++/savefits.C | 146 | ||||
-rw-r--r-- | tksao/frame/frsave.C | 6 |
3 files changed, 50 insertions, 103 deletions
diff --git a/tksao/fitsy++/file.h b/tksao/fitsy++/file.h index 674e9cd..e410d92 100644 --- a/tksao/fitsy++/file.h +++ b/tksao/fitsy++/file.h @@ -87,6 +87,7 @@ protected: int validParams(); int findEnd(const char*); void setByteSwap(); + int saveFitsHeaderCards(OutFitsStream&, int, int); public: FitsFile(); diff --git a/tksao/fitsy++/savefits.C b/tksao/fitsy++/savefits.C index f539d5e..96870ba 100644 --- a/tksao/fitsy++/savefits.C +++ b/tksao/fitsy++/savefits.C @@ -41,19 +41,14 @@ int FitsFile::saveFitsPrimHeader(OutFitsStream& str) return FTY_BLOCK; } -int FitsFile::saveFitsHeader(OutFitsStream& str, int depth) +int FitsFile::saveFitsHeaderCards(OutFitsStream& str, int depth, int cc) { - int cnt =0; char buf[FTY_CARDLEN]; + int cnt = 0; - memset(buf,' ',FTY_CARDLEN); - memcpy(buf,"SIMPLE = ",10); - memcpy(buf+32-3,"T /",3); - str.write(buf, FTY_CARDLEN); - cnt += FTY_CARDLEN; - - char* ptr = head()->cards()+FTY_CARDLEN; + char* ptr = head()->cards() + cc; char* end = head()->cards() + head()->headbytes(); + while (ptr<end) { if (!strncmp(ptr,"BITPIX",6) && head()->bitpix() == -16) { memset(buf,' ',FTY_CARDLEN); @@ -91,15 +86,15 @@ int FitsFile::saveFitsHeader(OutFitsStream& str, int depth) } } else if (!strncmp(ptr,"NAXIS3",6)) { - // skip + // skip, we already take care of it above cnt -= FTY_CARDLEN; } else if (!strncmp(ptr,"NAXIS4",6)) { - // skip + // skip, better not be here cnt -= FTY_CARDLEN; } else if (!strncmp(ptr,"NAXIS5",6)) { - // skip + // skip, better not be here cnt -= FTY_CARDLEN; } else if (!strncmp(ptr,"PCOUNT",6)) { @@ -111,13 +106,34 @@ int FitsFile::saveFitsHeader(OutFitsStream& str, int depth) cnt -= FTY_CARDLEN; } else if (!strncmp(ptr,"END ",6)) { - // skip + // skip, will insert at the end cnt -= FTY_CARDLEN; } + else if (!strncmp(ptr,"CRVAL3",6) && depth==1) + // skip + cnt -= FTY_CARDLEN; + else if (!strncmp(ptr,"CRPIX3",6) && depth==1) + // skip + cnt -= FTY_CARDLEN; + else if (!strncmp(ptr,"CDELT3",6) && depth==1) + // skip + cnt -= FTY_CARDLEN; + else if (!strncmp(ptr,"CTYPE3",6) && depth==1) + // skip + cnt -= FTY_CARDLEN; + else if (!strncmp(ptr,"CUNIT3",6) && depth==1) + // skip + cnt -= FTY_CARDLEN; + else if (!strncmp(ptr,"CD3_",4) && depth==1) + // skip + cnt -= FTY_CARDLEN; + else if (!strncmp(ptr,"PC3_",4) && depth==1) + // skip + cnt -= FTY_CARDLEN; else str.write(ptr, FTY_CARDLEN); - ptr+=FTY_CARDLEN; + ptr += FTY_CARDLEN; cnt += FTY_CARDLEN; } @@ -127,110 +143,40 @@ int FitsFile::saveFitsHeader(OutFitsStream& str, int depth) str.write(buf, FTY_CARDLEN); cnt += FTY_CARDLEN; - cnt += saveFitsPad(str,cnt,' '); - return cnt; } -int FitsFile::saveFitsXtHeader(OutFitsStream& str, int depth) +int FitsFile::saveFitsHeader(OutFitsStream& str, int depth) { - // write xtension header - // the header may be an xtension, or primary, so lets force a - // first line of 'SIMPLE' and then write the rest of the header int cnt =0; char buf[FTY_CARDLEN]; memset(buf,' ',FTY_CARDLEN); - memcpy(buf,"XTENSION= 'IMAGE '",20); + memcpy(buf,"SIMPLE = ",10); + memcpy(buf+32-3,"T /",3); str.write(buf, FTY_CARDLEN); cnt += FTY_CARDLEN; - char* ptr = head()->cards()+FTY_CARDLEN; - char* end = head()->cards() + head()->headbytes(); - while (ptr<end) { - if (!strncmp(ptr,"BITPIX",6) && head()->bitpix() == -16) { - memset(buf,' ',FTY_CARDLEN); - memcpy(buf,"BITPIX = ",10); - memcpy(buf+32-4,"32 /",4); - str.write(buf, FTY_CARDLEN); - } - else if (!strncmp(ptr,"NAXIS ",6)) { - memset(buf,' ',FTY_CARDLEN); - memcpy(buf,"NAXIS = ",10); - if (depth>1) - memcpy(buf+32-3,"3 /",3); - else - if (head()->naxis(1)>1) - memcpy(buf+32-3,"2 /",3); - else - memcpy(buf+32-3,"1 /",3); - str.write(buf, FTY_CARDLEN); - } - else if (!strncmp(ptr,"NAXIS2",6)) { - str.write(ptr, FTY_CARDLEN); - - if (depth>1) { - ostringstream ddstr; - ddstr << depth << " /" << ends; - const char* ddptr = ddstr.str().c_str(); - int ll = strlen(ddptr); - - memset(buf,' ',FTY_CARDLEN); - memcpy(buf,"NAXIS3 = ",10); - memcpy(buf+32-ll, ddptr, ll); - str.write(buf, FTY_CARDLEN); - cnt += FTY_CARDLEN; - } - - memset(buf,' ',FTY_CARDLEN); - memcpy(buf,"PCOUNT = ",10); - memcpy(buf+32-3,"0 /",3); - str.write(buf, FTY_CARDLEN); - cnt += FTY_CARDLEN; + cnt += saveFitsHeaderCards(str,depth,cnt); + cnt += saveFitsPad(str,cnt,' '); - memset(buf,' ',FTY_CARDLEN); - memcpy(buf,"GCOUNT = ",10); - memcpy(buf+32-3,"1 /",3); - str.write(buf, FTY_CARDLEN); - cnt += FTY_CARDLEN; - } - else if (!strncmp(ptr,"NAXIS3",6)) { - // skip - cnt -= FTY_CARDLEN; - } - else if (!strncmp(ptr,"NAXIS4",6)) { - // skip - cnt -= FTY_CARDLEN; - } - else if (!strncmp(ptr,"NAXIS5",6)) { - // skip - cnt -= FTY_CARDLEN; - } - else if (!strncmp(ptr,"PCOUNT",6)) { - // skip - cnt -= FTY_CARDLEN; - } - else if (!strncmp(ptr,"GCOUNT",6)) { - // skip - cnt -= FTY_CARDLEN; - } - else if (!strncmp(ptr,"END ",6)) { - // skip - cnt -= FTY_CARDLEN; - } - else - str.write(ptr, FTY_CARDLEN); + return cnt; +} - ptr+=FTY_CARDLEN; - cnt += FTY_CARDLEN; - } +int FitsFile::saveFitsXtHeader(OutFitsStream& str, int depth) +{ + // write xtension header + // the header may be an xtension, or primary, so lets force a + // first line of 'SIMPLE' and then write the rest of the header + int cnt =0; + char buf[FTY_CARDLEN]; - // final END memset(buf,' ',FTY_CARDLEN); - memcpy(buf,"END",3); + memcpy(buf,"XTENSION= 'IMAGE '",20); str.write(buf, FTY_CARDLEN); cnt += FTY_CARDLEN; + cnt += saveFitsHeaderCards(str,depth,cnt); cnt += saveFitsPad(str,cnt,' '); return cnt; diff --git a/tksao/frame/frsave.C b/tksao/frame/frsave.C index a7b26d4..791d31c 100644 --- a/tksao/frame/frsave.C +++ b/tksao/frame/frsave.C @@ -54,7 +54,7 @@ void Base::saveFitsSlice(OutFitsStream& str) if (!ptr) return; - ptr->saveFitsHeader(str,0); + ptr->saveFitsHeader(str,1); size_t cnt = ptr->saveFits(str); ptr->saveFitsPad(str,cnt,'\0'); } @@ -67,7 +67,7 @@ void Base::saveFitsExtCube(OutFitsStream& str) ptr->saveFitsPrimHeader(str); while (ptr) { - ptr->saveFitsXtHeader(str, 0); + ptr->saveFitsXtHeader(str, 1); size_t cnt = ptr->saveFits(str); ptr->saveFitsPad(str,cnt,'\0'); ptr = ptr->nextSlice(); @@ -130,7 +130,7 @@ void FrameRGB::saveFitsRGBImage(OutFitsStream& str) ptr->saveFitsPrimHeader(str); for (int ii=0; ii<3; ii++) { if (context[ii].fits) { - context[ii].fits->saveFitsXtHeader(str,0); + context[ii].fits->saveFitsXtHeader(str,1); size_t cnt = context[ii].fits->saveFits(str); context[ii].fits->saveFitsPad(str,cnt,'\0'); } |