summaryrefslogtreecommitdiffstats
path: root/tksao/fitsy++/savefits.C
diff options
context:
space:
mode:
authorWilliam Joye <wjoye@cfa.harvard.edu>2017-08-01 18:23:30 (GMT)
committerWilliam Joye <wjoye@cfa.harvard.edu>2017-08-01 18:23:30 (GMT)
commit82f9236f580ff81aa856a2a20e5e3716854ca4f0 (patch)
tree31252e13f25c726a4ecd17dde2e38eaee5f2451d /tksao/fitsy++/savefits.C
parentf150aca834519d829cc482fe03be43d054669a3e (diff)
downloadblt-82f9236f580ff81aa856a2a20e5e3716854ca4f0.zip
blt-82f9236f580ff81aa856a2a20e5e3716854ca4f0.tar.gz
blt-82f9236f580ff81aa856a2a20e5e3716854ca4f0.tar.bz2
CUBE: remove un-needed WCS keywords when saving as a slice
Diffstat (limited to 'tksao/fitsy++/savefits.C')
-rw-r--r--tksao/fitsy++/savefits.C146
1 files changed, 46 insertions, 100 deletions
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;