1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
// Copyright (C) 1999-2018
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"
#include "analysis.h"
#include "util.h"
FitsAnalysis::FitsAnalysis(FitsFile* src, int bitpix)
{
primary_ = src->primary();
managePrimary_ = 0;
head_ = new FitsHead(*(src->head()));
manageHead_ = 1;
ext_ = src->ext();
inherit_ = src->inherit();
int width = head_->naxis(0);
int height = head_->naxis(1);
size_t size = (size_t)width*height;
switch (bitpix) {
case 8:
head_->setInteger("BITPIX", 8, "");
data_ = new unsigned char[size];
if (data_)
memset(data_, 0, size*sizeof(unsigned char));
break;
case 16:
head_->setInteger("BITPIX", 16, "");
data_ = new short[size];
if (data_)
memset(data_, 0, size*sizeof(short));
break;
case -16:
head_->setInteger("BITPIX", -16, "");
data_ = new unsigned short[size];
if (data_)
memset(data_, 0, size*sizeof(unsigned short));
break;
case 32:
head_->setInteger("BITPIX", 32, "");
data_ = new int[size];
if (data_)
memset(data_, 0, size*sizeof(int));
break;
case 64:
head_->setInteger("BITPIX", 64, "");
data_ = new long long[size];
if (data_)
memset(data_, 0, size*sizeof(long long));
break;
case -32:
head_->setInteger("BITPIX", -32, "");
data_ = new float[size];
if (data_)
memset(data_, 0, size*sizeof(float));
break;
case -64:
head_->setInteger("BITPIX", -64, "");
data_ = new double[size];
if (data_)
memset(data_, 0, size*sizeof(double));
break;
}
// alloc memory
if (!data_)
return;
// unset BZERO/BSCALE if present
if (head_->find("BZERO"))
head_->setReal("BZERO",0,2,NULL);
if (head_->find("BSCALE"))
head_->setReal("BSCALE",1,2,NULL);
head_->updateHDU();
// made it this far, must be valid
dataSize_ = size;
dataSkip_ = 0;
byteswap_ = 0;
endian_ = lsb() ? LITTLE : BIG;
valid_ = 1;
}
FitsAnalysis::~FitsAnalysis()
{
if (data_)
delete [] (char*)data_;
}
|