rfits 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile.rb +92 -0
- data/lib/rfits.rb +1 -0
- data/lib/rfits/ext/extconf.rb +7 -0
- data/lib/rfits/ext/rfitsio.c +2797 -0
- data/lib/rfits/rfits.rb +1328 -0
- data/test/rfits_test.rb +310 -0
- data/test/rfitsio_test.rb +315 -0
- data/test/test.1.fits +7522 -2
- data/test/test.2.fits +1796 -0
- metadata +55 -0
data/Rakefile.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'rubygems' rescue LoadError
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/rdoctask'
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
|
8
|
+
PKG_VERSION = '0.0.1'
|
9
|
+
PKG_FILES = FileList['Rakefile.rb', 'test/**', 'lib/**/*.rb', 'lib/**/*.c']
|
10
|
+
|
11
|
+
desc 'Execute all tests'
|
12
|
+
task :test => ['rfits:test']
|
13
|
+
|
14
|
+
desc 'Create the API documentation'
|
15
|
+
task :doc => ['rfits:doc']
|
16
|
+
|
17
|
+
desc 'Recreate the API documentation'
|
18
|
+
task :redoc => ['rfits:redoc']
|
19
|
+
|
20
|
+
namespace 'rfits' do
|
21
|
+
RFITS_EXT_DIR = 'lib/rfits/ext'
|
22
|
+
RFITS_DOC_DIR = 'doc'
|
23
|
+
|
24
|
+
Rake::RDocTask.new(:doc) do |rd| # rake rfits:doc
|
25
|
+
rd.rdoc_dir = RFITS_DOC_DIR
|
26
|
+
rd.title = 'rfits API Documentation'
|
27
|
+
rd.rdoc_files.include(FileList['lib/rfits'])
|
28
|
+
end
|
29
|
+
|
30
|
+
Rake::TestTask.new(:test) do |t| # rake rfits:test
|
31
|
+
t.test_files = FileList['test/rfits_test.rb']
|
32
|
+
t.verbose = true
|
33
|
+
t.warning = true
|
34
|
+
end
|
35
|
+
|
36
|
+
namespace 'ext' do
|
37
|
+
desc 'Configure the rfits extension'
|
38
|
+
task :configure do # rake rfits:ext:configure
|
39
|
+
Dir.chdir(RFITS_EXT_DIR) do ruby "extconf.rb" end
|
40
|
+
end
|
41
|
+
|
42
|
+
desc 'Compile the rfits extension'
|
43
|
+
task :make => [:configure] do # rake rfits:ext:make
|
44
|
+
Dir.chdir(RFITS_EXT_DIR) do sh 'make' end
|
45
|
+
end
|
46
|
+
|
47
|
+
desc 'Install the rfits extension'
|
48
|
+
task :install => [:make] do # rake rfits:ext:install
|
49
|
+
Dir.chdir(RFITS_EXT_DIR) do sh 'make install' end
|
50
|
+
end
|
51
|
+
|
52
|
+
desc 'Clean the rfits extension'
|
53
|
+
task :clean do # rake rfits:ext:clean
|
54
|
+
Dir.chdir(RFITS_EXT_DIR) do sh 'make clean' end
|
55
|
+
end
|
56
|
+
|
57
|
+
desc 'Clobber the rfits extension'
|
58
|
+
task :clobber do # rake rfits:ext:clobber
|
59
|
+
Dir.chdir(RFITS_EXT_DIR) do sh 'make distclean' end
|
60
|
+
end
|
61
|
+
|
62
|
+
Rake::TestTask.new do |t| # rake rfits:ext:test
|
63
|
+
t.test_files = FileList['test/rfitsio_test.rb']
|
64
|
+
t.verbose = true
|
65
|
+
t.warning = true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
spec = Gem::Specification.new do |s|
|
71
|
+
s.summary = 'Routines for manipulating FITS files.'
|
72
|
+
s.name = 'rfits'
|
73
|
+
s.version = PKG_VERSION
|
74
|
+
s.author = 'David Gasson'
|
75
|
+
s.email = 'dgasson@noao.edu'
|
76
|
+
s.rubyforge_project = 'rfits'
|
77
|
+
s.has_rdoc = true
|
78
|
+
s.requirements << 'cfitsio >= 3.060 from http://heasarc.gsfc.nasa.gov/docs/software/fitsio/fitsio.html'
|
79
|
+
s.extensions << 'lib/rfits/ext/extconf.rb'
|
80
|
+
s.files = PKG_FILES.to_a
|
81
|
+
s.test_files = FileList['test/**/*.rb'].to_a
|
82
|
+
s.description = <<EOF
|
83
|
+
RFits is a set of routines for reading, writing and manipulating FITS (Flexible Image Transport System)
|
84
|
+
files--the standard image file format in astronomy. It is based on the the well-known CFITSIO library
|
85
|
+
provided by HEASARC (http://heasarc.gsfc.nasa.gov/docs/software/fitsio/fitsio.html).
|
86
|
+
EOF
|
87
|
+
end
|
88
|
+
|
89
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
90
|
+
pkg.need_zip = true
|
91
|
+
pkg.need_tar = true
|
92
|
+
end
|
data/lib/rfits.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rfits/rfits'
|
@@ -0,0 +1,2797 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
#include "fitsio.h"
|
3
|
+
|
4
|
+
static VALUE rb_mRFits;
|
5
|
+
static VALUE rb_mRFitsIO;
|
6
|
+
static VALUE rb_cProxy;
|
7
|
+
static VALUE rb_cException;
|
8
|
+
|
9
|
+
/* Convert a ruby FITS struct into a cfitsio fitsfile pointer. */
|
10
|
+
fitsfile * RFITS2CFITS(VALUE klass){
|
11
|
+
fitsfile *cfits;
|
12
|
+
Data_Get_Struct(klass, fitsfile, cfits);
|
13
|
+
return(cfits);
|
14
|
+
}
|
15
|
+
|
16
|
+
/* Raise an exception if the error status implies something is wrong. */
|
17
|
+
void raise_exception_if_necessary(int status){
|
18
|
+
char errmsg[FLEN_ERRMSG];
|
19
|
+
|
20
|
+
fits_get_errstatus(status, errmsg);
|
21
|
+
if(status != 0){
|
22
|
+
rb_raise(rb_cException, "fitsio error: %s (status code = %d)", errmsg, status);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
/* Determine the name of a class. */
|
27
|
+
char * name_of_class(VALUE obj){
|
28
|
+
char *type = STR2CSTR(rb_funcall(rb_funcall(obj, rb_intern("class"), 0), rb_intern("to_s"), 0));
|
29
|
+
return(type);
|
30
|
+
}
|
31
|
+
|
32
|
+
/* Find the number of pixels between two points on an image. */
|
33
|
+
long number_of_pixels_between_points(int naxis, long *fpixel, long *lpixel, long *inc){
|
34
|
+
long nelem = 1;
|
35
|
+
int i;
|
36
|
+
|
37
|
+
for(i = 0; i < naxis; i++){
|
38
|
+
nelem *= (lpixel[i] - fpixel[i] + 1) / inc[i] +
|
39
|
+
(((lpixel[i] - fpixel[i] + 1) % inc[i]) ? 1 : 0);
|
40
|
+
}
|
41
|
+
return(nelem);
|
42
|
+
}
|
43
|
+
|
44
|
+
/* Open an existing data file. */
|
45
|
+
static VALUE cfits_open_file(VALUE self, VALUE filename, VALUE iomode){
|
46
|
+
fitsfile *cfits;
|
47
|
+
int status = 0;
|
48
|
+
|
49
|
+
fits_open_file(&cfits, STR2CSTR(filename), NUM2INT(iomode), &status);
|
50
|
+
raise_exception_if_necessary(status);
|
51
|
+
|
52
|
+
return(Data_Wrap_Struct(self, 0, -1, cfits));
|
53
|
+
}
|
54
|
+
|
55
|
+
/* Create and open a new empty output FITS file. */
|
56
|
+
static VALUE cfits_create_file(VALUE self, VALUE filename){
|
57
|
+
fitsfile *cfits;
|
58
|
+
int status = 0;
|
59
|
+
|
60
|
+
fits_create_file(&cfits, STR2CSTR(filename), &status);
|
61
|
+
raise_exception_if_necessary(status);
|
62
|
+
|
63
|
+
return(Data_Wrap_Struct(self, 0, -1, cfits));
|
64
|
+
}
|
65
|
+
|
66
|
+
/* Close a previously opened FITS file. */
|
67
|
+
static VALUE cfits_close_file(VALUE self, VALUE rfits){
|
68
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
69
|
+
int status = 0;
|
70
|
+
|
71
|
+
fits_close_file(cfits, &status);
|
72
|
+
raise_exception_if_necessary(status);
|
73
|
+
|
74
|
+
return(Qnil);
|
75
|
+
}
|
76
|
+
|
77
|
+
/* Close a previously opened FITS file and delete it. */
|
78
|
+
static VALUE cfits_delete_file(VALUE self, VALUE rfits){
|
79
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
80
|
+
int status = 0;
|
81
|
+
|
82
|
+
fits_delete_file(cfits, &status);
|
83
|
+
|
84
|
+
return(Qnil);
|
85
|
+
}
|
86
|
+
|
87
|
+
/* Return the name of the opened FITS file. */
|
88
|
+
static VALUE cfits_file_name(VALUE self, VALUE rfits){
|
89
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
90
|
+
int status = 0;
|
91
|
+
|
92
|
+
char filename[FLEN_FILENAME];
|
93
|
+
|
94
|
+
fits_file_name(cfits, filename, &status);
|
95
|
+
raise_exception_if_necessary(status);
|
96
|
+
|
97
|
+
return(rb_str_new2(filename));
|
98
|
+
}
|
99
|
+
|
100
|
+
/* Return the IO mode of the opened FITS file. */
|
101
|
+
static VALUE cfits_file_mode(VALUE self, VALUE rfits){
|
102
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
103
|
+
int status = 0;
|
104
|
+
|
105
|
+
int iomode = 0;
|
106
|
+
|
107
|
+
fits_file_mode(cfits, &iomode, &status);
|
108
|
+
raise_exception_if_necessary(status);
|
109
|
+
|
110
|
+
return(INT2NUM(iomode));
|
111
|
+
}
|
112
|
+
|
113
|
+
/* Return the file type (e.g. 'file://', 'ftp://') of the opened FITS file. */
|
114
|
+
static VALUE cfits_url_type(VALUE self, VALUE rfits){
|
115
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
116
|
+
int status = 0;
|
117
|
+
|
118
|
+
char urltype[8];
|
119
|
+
|
120
|
+
fits_url_type(cfits, urltype, &status);
|
121
|
+
raise_exception_if_necessary(status);
|
122
|
+
|
123
|
+
return(rb_str_new2(urltype));
|
124
|
+
}
|
125
|
+
|
126
|
+
/* Move to a specified absolute HDU number (starting with 1 for the primary array) in the FITS file. */
|
127
|
+
static VALUE cfits_movabs_hdu(VALUE self, VALUE rfits, VALUE hdunum){
|
128
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
129
|
+
int status = 0;
|
130
|
+
|
131
|
+
int hdutype;
|
132
|
+
|
133
|
+
fits_movabs_hdu(cfits, NUM2INT(hdunum), &hdutype, &status);
|
134
|
+
raise_exception_if_necessary(status);
|
135
|
+
|
136
|
+
return(INT2NUM(hdutype));
|
137
|
+
}
|
138
|
+
|
139
|
+
/* Return the total number of HDUs in the FITS file. */
|
140
|
+
static VALUE cfits_get_num_hdus(VALUE self, VALUE rfits){
|
141
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
142
|
+
int status = 0;
|
143
|
+
|
144
|
+
int hdunum;
|
145
|
+
|
146
|
+
fits_get_num_hdus(cfits, &hdunum, &status);
|
147
|
+
raise_exception_if_necessary(status);
|
148
|
+
|
149
|
+
return(INT2NUM(hdunum));
|
150
|
+
}
|
151
|
+
|
152
|
+
/* Return the number of the current HDU (CHDU) in the FITS file (where the primary array = 1). */
|
153
|
+
static VALUE cfits_get_hdu_num(VALUE self, VALUE rfits){
|
154
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
155
|
+
|
156
|
+
int hdunum;
|
157
|
+
|
158
|
+
fits_get_hdu_num(cfits, &hdunum);
|
159
|
+
|
160
|
+
return(INT2NUM(hdunum));
|
161
|
+
}
|
162
|
+
|
163
|
+
/* Return the type of the current HDU in the FITS file. */
|
164
|
+
static VALUE cfits_get_hdu_type(VALUE self, VALUE rfits){
|
165
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
166
|
+
int status = 0;
|
167
|
+
|
168
|
+
int hdutype;
|
169
|
+
|
170
|
+
fits_get_hdu_type(cfits, &hdutype, &status);
|
171
|
+
raise_exception_if_necessary(status);
|
172
|
+
|
173
|
+
return(INT2NUM(hdutype));
|
174
|
+
}
|
175
|
+
|
176
|
+
/* Copy all or part of the HDUs in the FITS file associated with in and append them to the end of the FITS file associated with out. */
|
177
|
+
static VALUE cfits_copy_file(VALUE self, VALUE in, VALUE out, VALUE previous, VALUE current, VALUE following){
|
178
|
+
fitsfile *in_cfits = RFITS2CFITS(in);
|
179
|
+
fitsfile *out_cfits = RFITS2CFITS(out);
|
180
|
+
int status = 0;
|
181
|
+
|
182
|
+
fits_copy_file(in_cfits, out_cfits, NUM2INT(previous), NUM2INT(current), NUM2INT(following), &status);
|
183
|
+
raise_exception_if_necessary(status);
|
184
|
+
|
185
|
+
return(Qnil);
|
186
|
+
}
|
187
|
+
|
188
|
+
/* Copy the current HDU from the FITS file associated with in and append it to the end of the FITS file associated with out. */
|
189
|
+
static VALUE cfits_copy_hdu(VALUE self, VALUE in, VALUE out, VALUE morekeys){
|
190
|
+
fitsfile *in_cfits = RFITS2CFITS(in);
|
191
|
+
fitsfile *out_cfits = RFITS2CFITS(out);
|
192
|
+
int status = 0;
|
193
|
+
|
194
|
+
fits_copy_hdu(in_cfits, out_cfits, NUM2INT(morekeys), &status);
|
195
|
+
raise_exception_if_necessary(status);
|
196
|
+
|
197
|
+
return(Qnil);
|
198
|
+
}
|
199
|
+
|
200
|
+
/* Copy the header (and not the data) from the CHDU associated with in to the CHDU associated with out. */
|
201
|
+
static VALUE cfits_copy_header(VALUE self, VALUE in, VALUE out){
|
202
|
+
fitsfile *in_cfits = RFITS2CFITS(in);
|
203
|
+
fitsfile *out_cfits = RFITS2CFITS(out);
|
204
|
+
int status = 0;
|
205
|
+
|
206
|
+
fits_copy_header(in_cfits, out_cfits, &status);
|
207
|
+
raise_exception_if_necessary(status);
|
208
|
+
|
209
|
+
return(Qnil);
|
210
|
+
}
|
211
|
+
|
212
|
+
/* Create (append) a new empty HDU at the end of the FITS file. */
|
213
|
+
static VALUE cfits_create_hdu(VALUE self, VALUE rfits){
|
214
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
215
|
+
int status = 0;
|
216
|
+
|
217
|
+
fits_create_hdu(cfits, &status);
|
218
|
+
raise_exception_if_necessary(status);
|
219
|
+
|
220
|
+
return(Qnil);
|
221
|
+
}
|
222
|
+
|
223
|
+
/* Modify the size, dimensions, and/or data type of the current primary array or image extension. */
|
224
|
+
static VALUE cfits_resize_img(VALUE self, VALUE rfits, VALUE bitpix, VALUE naxis, VALUE naxes){
|
225
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
226
|
+
int status = 0, i;
|
227
|
+
|
228
|
+
int cnaxis = NUM2INT(naxis);
|
229
|
+
long cnaxes[cnaxis];
|
230
|
+
for(i = 0; i < cnaxis; i++){
|
231
|
+
cnaxes[i] = NUM2LONG(rb_ary_entry(naxes, i));
|
232
|
+
}
|
233
|
+
|
234
|
+
fits_resize_img(cfits, NUM2INT(bitpix), cnaxis, cnaxes, &status);
|
235
|
+
raise_exception_if_necessary(status);
|
236
|
+
|
237
|
+
return(Qnil);
|
238
|
+
}
|
239
|
+
|
240
|
+
/* Delete the CHDU in the FITS file. */
|
241
|
+
static VALUE cfits_delete_hdu(VALUE self, VALUE rfits){
|
242
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
243
|
+
int status = 0;
|
244
|
+
|
245
|
+
int hdutype;
|
246
|
+
|
247
|
+
fits_delete_hdu(cfits, &hdutype, &status);
|
248
|
+
raise_exception_if_necessary(status);
|
249
|
+
|
250
|
+
return(INT2NUM(hdutype));
|
251
|
+
}
|
252
|
+
|
253
|
+
/* Return the number of existing keywords (not counting the END keyword) and the amount of space currently available for more
|
254
|
+
keywords. */
|
255
|
+
static VALUE cfits_get_hdrspace(VALUE self, VALUE rfits){
|
256
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
257
|
+
int status = 0;
|
258
|
+
|
259
|
+
int keysexist, morekeys;
|
260
|
+
|
261
|
+
fits_get_hdrspace(cfits, &keysexist, &morekeys, &status);
|
262
|
+
raise_exception_if_necessary(status);
|
263
|
+
|
264
|
+
return(rb_ary_new3(2, INT2NUM(keysexist), INT2NUM(morekeys)));
|
265
|
+
}
|
266
|
+
|
267
|
+
/* Write the required extension header keywords into the CHU. */
|
268
|
+
static VALUE cfits_write_grphdr(VALUE self, VALUE rfits, VALUE simple, VALUE bitpix, VALUE naxis, VALUE naxes, VALUE pcount, VALUE gcount, VALUE extend){
|
269
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
270
|
+
int status = 0, i;
|
271
|
+
|
272
|
+
int cnaxis = NUM2INT(naxis);
|
273
|
+
long cnaxes[cnaxis];
|
274
|
+
for(i = 0; i < cnaxis; i++){
|
275
|
+
cnaxes[i] = NUM2LONG(rb_ary_entry(naxes, i));
|
276
|
+
}
|
277
|
+
|
278
|
+
fits_write_grphdr(cfits, NUM2INT(simple), NUM2INT(bitpix), cnaxis, cnaxes,
|
279
|
+
NUM2LONG(pcount), NUM2LONG(gcount), NUM2INT(extend), &status);
|
280
|
+
raise_exception_if_necessary(status);
|
281
|
+
|
282
|
+
return(Qnil);
|
283
|
+
}
|
284
|
+
|
285
|
+
/* Return the specified keyword */
|
286
|
+
static VALUE cfits_read_key(VALUE self, VALUE rfits, VALUE datatype, VALUE keyname){
|
287
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
288
|
+
int status = 0;
|
289
|
+
|
290
|
+
int cdatatype = NUM2INT(datatype);
|
291
|
+
char ccomment[FLEN_COMMENT];
|
292
|
+
|
293
|
+
VALUE result;
|
294
|
+
switch(cdatatype){
|
295
|
+
case TSTRING: {
|
296
|
+
char cvalue[FLEN_VALUE];
|
297
|
+
fits_read_key(cfits, cdatatype, STR2CSTR(keyname), cvalue, ccomment, &status);
|
298
|
+
result = rb_ary_new3(2, rb_str_new2(cvalue), rb_str_new2(ccomment));
|
299
|
+
break;
|
300
|
+
}
|
301
|
+
case TLOGICAL: {
|
302
|
+
int cvalue;
|
303
|
+
fits_read_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, ccomment, &status);
|
304
|
+
result = rb_ary_new3(2, cvalue == 1 ? Qtrue : Qfalse, rb_str_new2(ccomment));
|
305
|
+
break;
|
306
|
+
}
|
307
|
+
case TBYTE: {
|
308
|
+
char cvalue;
|
309
|
+
fits_read_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, ccomment, &status);
|
310
|
+
result = rb_ary_new3(2, CHR2FIX(cvalue), rb_str_new2(ccomment));
|
311
|
+
break;
|
312
|
+
}
|
313
|
+
case TSHORT: {
|
314
|
+
short cvalue;
|
315
|
+
fits_read_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, ccomment, &status);
|
316
|
+
result = rb_ary_new3(2, INT2NUM(cvalue), rb_str_new2(ccomment));
|
317
|
+
break;
|
318
|
+
}
|
319
|
+
case TUSHORT: {
|
320
|
+
unsigned short cvalue;
|
321
|
+
fits_read_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, ccomment, &status);
|
322
|
+
result = rb_ary_new3(2, INT2NUM(cvalue), rb_str_new2(ccomment));
|
323
|
+
break;
|
324
|
+
}
|
325
|
+
case TINT: {
|
326
|
+
int cvalue;
|
327
|
+
fits_read_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, ccomment, &status);
|
328
|
+
result = rb_ary_new3(2, INT2NUM(cvalue), rb_str_new2(ccomment));
|
329
|
+
break;
|
330
|
+
}
|
331
|
+
case TUINT: {
|
332
|
+
unsigned int cvalue;
|
333
|
+
fits_read_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, ccomment, &status);
|
334
|
+
result = rb_ary_new3(2, INT2NUM(cvalue), rb_str_new2(ccomment));
|
335
|
+
break;
|
336
|
+
}
|
337
|
+
case TLONG: {
|
338
|
+
long cvalue;
|
339
|
+
fits_read_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, ccomment, &status);
|
340
|
+
result = rb_ary_new3(2, INT2NUM(cvalue), rb_str_new2(ccomment));
|
341
|
+
break;
|
342
|
+
}
|
343
|
+
case TULONG: {
|
344
|
+
unsigned long cvalue;
|
345
|
+
fits_read_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, ccomment, &status);
|
346
|
+
result = rb_ary_new3(2, INT2NUM(cvalue), rb_str_new2(ccomment));
|
347
|
+
break;
|
348
|
+
}
|
349
|
+
case TLONGLONG: {
|
350
|
+
long long cvalue;
|
351
|
+
fits_read_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, ccomment, &status);
|
352
|
+
result = rb_ary_new3(2, INT2NUM(cvalue), rb_str_new2(ccomment));
|
353
|
+
break;
|
354
|
+
}
|
355
|
+
case TFLOAT: {
|
356
|
+
float cvalue;
|
357
|
+
fits_read_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, ccomment, &status);
|
358
|
+
result = rb_ary_new3(2, rb_float_new(cvalue), rb_str_new2(ccomment));
|
359
|
+
break;
|
360
|
+
}
|
361
|
+
case TDOUBLE: {
|
362
|
+
double cvalue;
|
363
|
+
fits_read_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, ccomment, &status);
|
364
|
+
result = rb_ary_new3(2, rb_float_new(cvalue), rb_str_new2(ccomment));
|
365
|
+
break;
|
366
|
+
}
|
367
|
+
case TCOMPLEX: {
|
368
|
+
float cvalue[2];
|
369
|
+
fits_read_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, ccomment, &status);
|
370
|
+
|
371
|
+
VALUE cmp = rb_funcall(
|
372
|
+
rb_const_get(rb_cObject, rb_intern("Complex")),
|
373
|
+
rb_intern("new"),
|
374
|
+
2,
|
375
|
+
rb_float_new(cvalue[0]), rb_float_new(cvalue[1]));
|
376
|
+
|
377
|
+
result = rb_ary_new3(2, cmp, rb_str_new2(ccomment));
|
378
|
+
break;
|
379
|
+
}
|
380
|
+
case TDBLCOMPLEX: {
|
381
|
+
double cvalue[2];
|
382
|
+
fits_read_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, ccomment, &status);
|
383
|
+
|
384
|
+
VALUE cmp = rb_funcall(
|
385
|
+
rb_const_get(rb_cObject, rb_intern("Complex")),
|
386
|
+
rb_intern("new"),
|
387
|
+
2,
|
388
|
+
rb_float_new(cvalue[0]), rb_float_new(cvalue[1]));
|
389
|
+
|
390
|
+
result = rb_ary_new3(2, cmp, rb_str_new2(ccomment));
|
391
|
+
break;
|
392
|
+
}
|
393
|
+
default: {
|
394
|
+
char cvalue[FLEN_VALUE];
|
395
|
+
fits_read_key(cfits, cdatatype, STR2CSTR(keyname), cvalue, ccomment, &status);
|
396
|
+
result = rb_ary_new3(2, rb_str_new2(cvalue), rb_str_new2(ccomment));
|
397
|
+
}
|
398
|
+
}
|
399
|
+
raise_exception_if_necessary(status);
|
400
|
+
|
401
|
+
return(result);
|
402
|
+
}
|
403
|
+
|
404
|
+
/* Return the keyword value as a character string (a literal copy of what is in the value field) regardless of the intrinsic data
|
405
|
+
type of the keyword. */
|
406
|
+
static VALUE cfits_read_keyword(VALUE self, VALUE rfits, VALUE keyname){
|
407
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
408
|
+
int status = 0;
|
409
|
+
|
410
|
+
char value[FLEN_VALUE];
|
411
|
+
char comment[FLEN_COMMENT];
|
412
|
+
|
413
|
+
fits_read_keyword(cfits, STR2CSTR(keyname), value, comment, &status);
|
414
|
+
raise_exception_if_necessary(status);
|
415
|
+
|
416
|
+
return(rb_ary_new3(2, rb_str_new2(value), rb_str_new2(comment)));
|
417
|
+
}
|
418
|
+
|
419
|
+
/* Concatenate the header keywords in the CHDU into a single long string of characters. */
|
420
|
+
static VALUE cfits_hdr2str(VALUE self, VALUE rfits, VALUE nocomments, VALUE exclist, VALUE nexc){
|
421
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
422
|
+
int status = 0;
|
423
|
+
|
424
|
+
int cnocomments = nocomments == Qtrue ? 1 : 0;
|
425
|
+
int cnexc = NUM2INT(nexc);
|
426
|
+
|
427
|
+
long i;
|
428
|
+
char *cexclist[cnexc];
|
429
|
+
for(i = 0; i < cnexc; i++){
|
430
|
+
cexclist[i] = STR2CSTR(rb_ary_entry(exclist, i));
|
431
|
+
}
|
432
|
+
|
433
|
+
int nkeys = 0;
|
434
|
+
char *header[FLEN_CARD];
|
435
|
+
fits_hdr2str(cfits, cnocomments, cexclist, cnexc, header, &nkeys, &status);
|
436
|
+
raise_exception_if_necessary(status);
|
437
|
+
|
438
|
+
VALUE hdr = rb_str_new2(header[0]);
|
439
|
+
free(header[0]);
|
440
|
+
|
441
|
+
return(hdr);
|
442
|
+
}
|
443
|
+
|
444
|
+
/* Return the nth header record in the CHU. */
|
445
|
+
static VALUE cfits_read_keyn(VALUE self, VALUE rfits, VALUE keynum){
|
446
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
447
|
+
int status = 0;
|
448
|
+
|
449
|
+
char keyname[FLEN_KEYWORD];
|
450
|
+
char value[FLEN_VALUE];
|
451
|
+
char comment[FLEN_COMMENT];
|
452
|
+
|
453
|
+
fits_read_keyn(cfits, NUM2INT(keynum), keyname, value, comment, &status);
|
454
|
+
raise_exception_if_necessary(status);
|
455
|
+
|
456
|
+
return(rb_ary_new3(3, rb_str_new2(keyname), rb_str_new2(value), rb_str_new2(comment)));
|
457
|
+
}
|
458
|
+
|
459
|
+
/* Determine the data type of a keyword value string. */
|
460
|
+
static VALUE cfits_get_keytype(VALUE self, VALUE value){
|
461
|
+
int status = 0;
|
462
|
+
|
463
|
+
char dtype[2];
|
464
|
+
|
465
|
+
fits_get_keytype(STR2CSTR(value), dtype, &status);
|
466
|
+
raise_exception_if_necessary(status);
|
467
|
+
|
468
|
+
return(rb_str_new2(dtype));
|
469
|
+
}
|
470
|
+
|
471
|
+
/* Update or append a string keyword to the CHU. */
|
472
|
+
static VALUE cfits_update_key(VALUE self, VALUE rfits, VALUE datatype, VALUE keyname, VALUE value, VALUE comment){
|
473
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
474
|
+
int status = 0;
|
475
|
+
|
476
|
+
int cdatatype = NUM2INT(datatype);
|
477
|
+
int comment_null = NIL_P(comment);
|
478
|
+
|
479
|
+
switch(cdatatype){
|
480
|
+
case TSTRING: {
|
481
|
+
fits_update_key(cfits, cdatatype, STR2CSTR(keyname), STR2CSTR(value), comment_null ? NULL : STR2CSTR(comment), &status);
|
482
|
+
break;
|
483
|
+
}
|
484
|
+
case TLOGICAL: {
|
485
|
+
int cvalue = TYPE(value) == T_TRUE ? 1 : 0;
|
486
|
+
fits_update_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, comment_null ? NULL : STR2CSTR(comment), &status);
|
487
|
+
break;
|
488
|
+
}
|
489
|
+
case TBYTE: {
|
490
|
+
char cvalue = NUM2CHR(value);
|
491
|
+
fits_update_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, comment_null ? NULL : STR2CSTR(comment), &status);
|
492
|
+
break;
|
493
|
+
}
|
494
|
+
case TSHORT: {
|
495
|
+
short cvalue = (short) NUM2INT(value);
|
496
|
+
fits_update_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, comment_null ? NULL : STR2CSTR(comment), &status);
|
497
|
+
break;
|
498
|
+
}
|
499
|
+
case TUSHORT: {
|
500
|
+
unsigned short cvalue = (unsigned short) NUM2UINT(value);
|
501
|
+
fits_update_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, comment_null ? NULL : STR2CSTR(comment), &status);
|
502
|
+
break;
|
503
|
+
}
|
504
|
+
case TINT: {
|
505
|
+
int cvalue = NUM2INT(value);
|
506
|
+
fits_update_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, comment_null ? NULL : STR2CSTR(comment), &status);
|
507
|
+
break;
|
508
|
+
}
|
509
|
+
case TUINT: {
|
510
|
+
unsigned int cvalue = NUM2UINT(value);
|
511
|
+
fits_update_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, comment_null ? NULL : STR2CSTR(comment), &status);
|
512
|
+
break;
|
513
|
+
}
|
514
|
+
case TLONG: {
|
515
|
+
long cvalue = NUM2LONG(value);
|
516
|
+
fits_update_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, comment_null ? NULL : STR2CSTR(comment), &status);
|
517
|
+
break;
|
518
|
+
}
|
519
|
+
case TULONG: {
|
520
|
+
unsigned long cvalue = NUM2ULONG(value);
|
521
|
+
fits_update_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, comment_null ? NULL : STR2CSTR(comment), &status);
|
522
|
+
break;
|
523
|
+
}
|
524
|
+
case TFLOAT: {
|
525
|
+
float cvalue = (float) NUM2DBL(value);
|
526
|
+
fits_update_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, comment_null ? NULL : STR2CSTR(comment), &status);
|
527
|
+
break;
|
528
|
+
}
|
529
|
+
case TDOUBLE: {
|
530
|
+
double cvalue = NUM2DBL(value);
|
531
|
+
fits_update_key(cfits, cdatatype, STR2CSTR(keyname), &cvalue, comment_null ? NULL : STR2CSTR(comment), &status);
|
532
|
+
break;
|
533
|
+
}
|
534
|
+
case TCOMPLEX: {
|
535
|
+
if(strcmp(name_of_class(value), "Complex") != 0){
|
536
|
+
rb_raise(rb_eTypeError, "value must be of Complex type.");
|
537
|
+
}
|
538
|
+
|
539
|
+
float real = (float) NUM2DBL(rb_funcall(value, rb_intern("real"), 0));
|
540
|
+
float imag = (float) NUM2DBL(rb_funcall(value, rb_intern("image"), 0));
|
541
|
+
float cvalue[] = {real, imag};
|
542
|
+
fits_update_key(cfits, cdatatype, STR2CSTR(keyname), cvalue, comment_null ? NULL : STR2CSTR(comment), &status);
|
543
|
+
break;
|
544
|
+
}
|
545
|
+
case TDBLCOMPLEX: {
|
546
|
+
if(strcmp(name_of_class(value), "Complex") != 0){
|
547
|
+
rb_raise(rb_eTypeError, "value must be of Complex type.");
|
548
|
+
}
|
549
|
+
|
550
|
+
double real = NUM2DBL(rb_funcall(value, rb_intern("real"), 0));
|
551
|
+
double imag = NUM2DBL(rb_funcall(value, rb_intern("image"), 0));
|
552
|
+
double cvalue[] = {real, imag};
|
553
|
+
fits_update_key(cfits, cdatatype, STR2CSTR(keyname), cvalue, comment_null ? NULL : STR2CSTR(comment), &status);
|
554
|
+
break;
|
555
|
+
}
|
556
|
+
default: {
|
557
|
+
fits_update_key(cfits, cdatatype, STR2CSTR(keyname), STR2CSTR(value), comment_null ? NULL : STR2CSTR(comment), &status);
|
558
|
+
}
|
559
|
+
}
|
560
|
+
raise_exception_if_necessary(status);
|
561
|
+
|
562
|
+
return(Qnil);
|
563
|
+
}
|
564
|
+
|
565
|
+
/* Update or append a null keyword to the CHU. */
|
566
|
+
static VALUE cfits_update_key_null(VALUE self, VALUE rfits, VALUE keyname, VALUE comment){
|
567
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
568
|
+
int status = 0;
|
569
|
+
|
570
|
+
if(NIL_P(comment)){
|
571
|
+
fits_update_key_null(cfits, STR2CSTR(keyname), NULL, &status);
|
572
|
+
} else {
|
573
|
+
fits_update_key_null(cfits, STR2CSTR(keyname), STR2CSTR(comment), &status);
|
574
|
+
}
|
575
|
+
raise_exception_if_necessary(status);
|
576
|
+
|
577
|
+
return(Qnil);
|
578
|
+
}
|
579
|
+
|
580
|
+
/* Delete a keyword record with the specifically named keyword. */
|
581
|
+
static VALUE cfits_delete_key(VALUE self, VALUE rfits, VALUE keyname){
|
582
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
583
|
+
int status = 0;
|
584
|
+
|
585
|
+
fits_delete_key(cfits, STR2CSTR(keyname), &status);
|
586
|
+
raise_exception_if_necessary(status);
|
587
|
+
|
588
|
+
return(Qnil);
|
589
|
+
}
|
590
|
+
|
591
|
+
/* Write (append) a COMMENT keyword to the CHU. */
|
592
|
+
static VALUE cfits_write_comment(VALUE self, VALUE rfits, VALUE comment){
|
593
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
594
|
+
int status = 0;
|
595
|
+
|
596
|
+
fits_write_comment(cfits, STR2CSTR(comment), &status);
|
597
|
+
raise_exception_if_necessary(status);
|
598
|
+
|
599
|
+
return(Qnil);
|
600
|
+
}
|
601
|
+
|
602
|
+
/* Write (append) a HISTORY keyword to the CHU. */
|
603
|
+
static VALUE cfits_write_history(VALUE self, VALUE rfits, VALUE history){
|
604
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
605
|
+
int status = 0;
|
606
|
+
|
607
|
+
fits_write_history(cfits, STR2CSTR(history), &status);
|
608
|
+
raise_exception_if_necessary(status);
|
609
|
+
|
610
|
+
return(Qnil);
|
611
|
+
}
|
612
|
+
|
613
|
+
/* Get the data type (bitpix) of the image. */
|
614
|
+
static VALUE cfits_get_img_type(VALUE self, VALUE rfits){
|
615
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
616
|
+
int status = 0;
|
617
|
+
|
618
|
+
int bitpix;
|
619
|
+
|
620
|
+
fits_get_img_type(cfits, &bitpix, &status);
|
621
|
+
raise_exception_if_necessary(status);
|
622
|
+
|
623
|
+
return(INT2NUM(bitpix));
|
624
|
+
}
|
625
|
+
|
626
|
+
/* Get the equivalent data type (bitpix) of the image. */
|
627
|
+
static VALUE cfits_get_img_equivtype(VALUE self, VALUE rfits){
|
628
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
629
|
+
int status = 0;
|
630
|
+
|
631
|
+
int bitpix;
|
632
|
+
|
633
|
+
fits_get_img_equivtype(cfits, &bitpix, &status);
|
634
|
+
raise_exception_if_necessary(status);
|
635
|
+
|
636
|
+
return(INT2NUM(bitpix));
|
637
|
+
}
|
638
|
+
|
639
|
+
/* Get the number of dimensions of the image. */
|
640
|
+
static VALUE cfits_get_img_dim(VALUE self, VALUE rfits){
|
641
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
642
|
+
int status = 0;
|
643
|
+
|
644
|
+
int naxis;
|
645
|
+
|
646
|
+
fits_get_img_dim(cfits, &naxis, &status);
|
647
|
+
raise_exception_if_necessary(status);
|
648
|
+
|
649
|
+
return(INT2NUM(naxis));
|
650
|
+
}
|
651
|
+
|
652
|
+
/* Get the size of each dimension of the image. */
|
653
|
+
static VALUE cfits_get_img_size(VALUE self, VALUE rfits, VALUE maxdim){
|
654
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
655
|
+
int status = 0, i;
|
656
|
+
|
657
|
+
int cmaxdim = NUM2INT(maxdim);
|
658
|
+
long cnaxes[cmaxdim];
|
659
|
+
fits_get_img_size(cfits, cmaxdim, cnaxes, &status);
|
660
|
+
raise_exception_if_necessary(status);
|
661
|
+
|
662
|
+
VALUE rnaxes = rb_ary_new2(cmaxdim);
|
663
|
+
for(i = 0; i < cmaxdim; i++){
|
664
|
+
rb_ary_push(rnaxes, INT2NUM(cnaxes[i]));
|
665
|
+
}
|
666
|
+
|
667
|
+
return(rnaxes);
|
668
|
+
}
|
669
|
+
|
670
|
+
/* Get the number of dimension, image type (bitpix), and the dimensions of the image. */
|
671
|
+
static VALUE cfits_get_img_param(VALUE self, VALUE rfits, VALUE maxdim){
|
672
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
673
|
+
int status = 0, i;
|
674
|
+
|
675
|
+
int bitpix;
|
676
|
+
int naxis;
|
677
|
+
int cmaxdim = NUM2INT(maxdim);
|
678
|
+
long cnaxes[cmaxdim];
|
679
|
+
|
680
|
+
fits_get_img_param(cfits, cmaxdim, &bitpix, &naxis, cnaxes, &status);
|
681
|
+
raise_exception_if_necessary(status);
|
682
|
+
|
683
|
+
VALUE rnaxes = rb_ary_new2(cmaxdim);
|
684
|
+
for(i = 0; i < cmaxdim; i++){
|
685
|
+
rb_ary_push(rnaxes, INT2NUM(cnaxes[i]));
|
686
|
+
}
|
687
|
+
|
688
|
+
return(rb_ary_new3(3, INT2NUM(bitpix), INT2NUM(naxis), rnaxes));
|
689
|
+
}
|
690
|
+
|
691
|
+
/* Create a new primary array or IMAGE extension at the end of the file. */
|
692
|
+
static VALUE cfits_create_img(VALUE self, VALUE rfits, VALUE bitpix, VALUE naxis, VALUE naxes){
|
693
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
694
|
+
int status = 0, i;
|
695
|
+
|
696
|
+
int cnaxis = NUM2INT(naxis);
|
697
|
+
long cnaxes[cnaxis];
|
698
|
+
for(i = 0; i < cnaxis; i++){
|
699
|
+
cnaxes[i] = NUM2LONG(rb_ary_entry(naxes, i));
|
700
|
+
}
|
701
|
+
|
702
|
+
fits_create_img(cfits, NUM2INT(bitpix), cnaxis, cnaxes, &status);
|
703
|
+
raise_exception_if_necessary(status);
|
704
|
+
|
705
|
+
return(Qnil);
|
706
|
+
}
|
707
|
+
|
708
|
+
/* Insert a new primary array or IMAGE extension with a specified data type and size at the CHDU. */
|
709
|
+
static VALUE cfits_insert_img(VALUE self, VALUE rfits, VALUE bitpix, VALUE naxis, VALUE naxes){
|
710
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
711
|
+
int status = 0, i;
|
712
|
+
|
713
|
+
int cnaxis = NUM2INT(naxis);
|
714
|
+
long cnaxes[cnaxis];
|
715
|
+
for(i = 0; i < cnaxis; i++){
|
716
|
+
cnaxes[i] = NUM2LONG(rb_ary_entry(naxes, i));
|
717
|
+
}
|
718
|
+
|
719
|
+
fits_insert_img(cfits, NUM2INT(bitpix), cnaxis, cnaxes, &status);
|
720
|
+
raise_exception_if_necessary(status);
|
721
|
+
|
722
|
+
return(Qnil);
|
723
|
+
}
|
724
|
+
|
725
|
+
/* Copy an n-dimensional image in a particular row and column of a binary table (in a vector column) to a
|
726
|
+
primary array or image extension. */
|
727
|
+
static VALUE cfits_copy_cell2image(VALUE self, VALUE rinfits, VALUE routfits, VALUE colname, VALUE rownum){
|
728
|
+
fitsfile *cinfits = RFITS2CFITS(rinfits);
|
729
|
+
fitsfile *coutfits = RFITS2CFITS(routfits);
|
730
|
+
int status = 0;
|
731
|
+
|
732
|
+
fits_copy_cell2image(cinfits, coutfits, STR2CSTR(colname), NUM2LONG(rownum), &status);
|
733
|
+
raise_exception_if_necessary(status);
|
734
|
+
|
735
|
+
return(Qnil);
|
736
|
+
}
|
737
|
+
|
738
|
+
/* Copy an n-dimensional image in a particular row and column of a binary table (in a vector column) from a
|
739
|
+
primary array or image extension. */
|
740
|
+
static VALUE cfits_copy_image2cell(VALUE self, VALUE rinfits, VALUE routfits, VALUE colname, VALUE rownum, VALUE copykeyflag){
|
741
|
+
fitsfile *cinfits = RFITS2CFITS(rinfits);
|
742
|
+
fitsfile *coutfits = RFITS2CFITS(routfits);
|
743
|
+
int status = 0;
|
744
|
+
|
745
|
+
fits_copy_image2cell(cinfits, coutfits, STR2CSTR(colname), NUM2LONG(rownum), NUM2INT(copykeyflag), &status);
|
746
|
+
raise_exception_if_necessary(status);
|
747
|
+
|
748
|
+
return(Qnil);
|
749
|
+
}
|
750
|
+
|
751
|
+
/* Read elements from the FITS data array. */
|
752
|
+
static VALUE cfits_read_img(VALUE self, VALUE rfits, VALUE datatype, VALUE firstelem, VALUE nelements, VALUE nulval){
|
753
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
754
|
+
int status = 0, anynul, i;
|
755
|
+
|
756
|
+
int cdatatype = NUM2INT(datatype);
|
757
|
+
long nelem = NUM2LONG(nelements);
|
758
|
+
long cfirstelem = NUM2LONG(firstelem);
|
759
|
+
|
760
|
+
int nulval_null = NIL_P(nulval);
|
761
|
+
|
762
|
+
VALUE pixels = rb_ary_new2(nelem);
|
763
|
+
switch(cdatatype){
|
764
|
+
case TBYTE: {
|
765
|
+
int array[nelem];
|
766
|
+
int cnulval;
|
767
|
+
if(!nulval_null){ cnulval = NUM2INT(nulval); }
|
768
|
+
|
769
|
+
fits_read_img(cfits, cdatatype, cfirstelem, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
770
|
+
for(i = 0; i < nelem; i++){
|
771
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
772
|
+
}
|
773
|
+
break;
|
774
|
+
}
|
775
|
+
case TSHORT: {
|
776
|
+
short array[nelem];
|
777
|
+
short cnulval;
|
778
|
+
if(!nulval_null){ cnulval = (short) NUM2INT(nulval); }
|
779
|
+
|
780
|
+
fits_read_img(cfits, cdatatype, cfirstelem, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
781
|
+
for(i = 0; i < nelem; i++){
|
782
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
783
|
+
}
|
784
|
+
break;
|
785
|
+
}
|
786
|
+
case TUSHORT: {
|
787
|
+
unsigned short array[nelem];
|
788
|
+
unsigned short cnulval;
|
789
|
+
if(!nulval_null){ cnulval = (unsigned short) NUM2UINT(nulval); }
|
790
|
+
|
791
|
+
fits_read_img(cfits, cdatatype, cfirstelem, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
792
|
+
for(i = 0; i < nelem; i++){
|
793
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
794
|
+
}
|
795
|
+
break;
|
796
|
+
}
|
797
|
+
case TINT: {
|
798
|
+
int array[nelem];
|
799
|
+
int cnulval;
|
800
|
+
if(nulval_null){ cnulval = NUM2INT(nulval); }
|
801
|
+
|
802
|
+
fits_read_img(cfits, cdatatype, cfirstelem, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
803
|
+
for(i = 0; i < nelem; i++){
|
804
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
805
|
+
}
|
806
|
+
break;
|
807
|
+
}
|
808
|
+
case TUINT: {
|
809
|
+
unsigned int array[nelem];
|
810
|
+
unsigned int cnulval;
|
811
|
+
if(!nulval_null){ cnulval = (unsigned int) NUM2UINT(nulval); }
|
812
|
+
|
813
|
+
fits_read_img(cfits, cdatatype, cfirstelem, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
814
|
+
for(i = 0; i < nelem; i++){
|
815
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
816
|
+
}
|
817
|
+
break;
|
818
|
+
}
|
819
|
+
case TLONG: {
|
820
|
+
long array[nelem];
|
821
|
+
long cnulval;
|
822
|
+
if(!nulval_null){ cnulval = NUM2LONG(nulval); }
|
823
|
+
|
824
|
+
fits_read_img(cfits, cdatatype, cfirstelem, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
825
|
+
for(i = 0; i < nelem; i++){
|
826
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
827
|
+
}
|
828
|
+
break;
|
829
|
+
}
|
830
|
+
case TLONGLONG: {
|
831
|
+
long long array[nelem];
|
832
|
+
long long cnulval;
|
833
|
+
if(!nulval_null){ cnulval = (long long) NUM2LONG(nulval); }
|
834
|
+
|
835
|
+
fits_read_img(cfits, cdatatype, cfirstelem, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
836
|
+
for(i = 0; i < nelem; i++){
|
837
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
838
|
+
}
|
839
|
+
break;
|
840
|
+
}
|
841
|
+
case TULONG: {
|
842
|
+
unsigned long array[nelem];
|
843
|
+
unsigned long cnulval;
|
844
|
+
if(!nulval_null){ cnulval = (unsigned long) NUM2ULONG(nulval); }
|
845
|
+
|
846
|
+
fits_read_img(cfits, cdatatype, cfirstelem, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
847
|
+
for(i = 0; i < nelem; i++){
|
848
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
849
|
+
}
|
850
|
+
break;
|
851
|
+
}
|
852
|
+
case TFLOAT: {
|
853
|
+
float array[nelem];
|
854
|
+
float cnulval;
|
855
|
+
if(!nulval_null){ cnulval = (float) NUM2DBL(nulval); }
|
856
|
+
|
857
|
+
fits_read_img(cfits, cdatatype, cfirstelem, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
858
|
+
for(i = 0; i < nelem; i++){
|
859
|
+
rb_ary_push(pixels, rb_float_new(array[i]));
|
860
|
+
}
|
861
|
+
break;
|
862
|
+
}
|
863
|
+
case TDOUBLE: {
|
864
|
+
double array[nelem];
|
865
|
+
double cnulval;
|
866
|
+
if(!nulval_null){ cnulval = NUM2DBL(nulval); }
|
867
|
+
|
868
|
+
fits_read_img(cfits, cdatatype, cfirstelem, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
869
|
+
for(i = 0; i < nelem; i++){
|
870
|
+
rb_ary_push(pixels, rb_float_new(array[i]));
|
871
|
+
}
|
872
|
+
break;
|
873
|
+
}
|
874
|
+
default: {
|
875
|
+
double array[nelem];
|
876
|
+
double cnulval;
|
877
|
+
if(!nulval_null){ cnulval = NUM2DBL(nulval); }
|
878
|
+
|
879
|
+
fits_read_img(cfits, cdatatype, cfirstelem, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
880
|
+
for(i = 0; i < nelem; i++){
|
881
|
+
rb_ary_push(pixels, rb_float_new(array[i]));
|
882
|
+
}
|
883
|
+
}
|
884
|
+
}
|
885
|
+
raise_exception_if_necessary(status);
|
886
|
+
|
887
|
+
return(rb_ary_new3(2, pixels, INT2NUM(anynul)));
|
888
|
+
}
|
889
|
+
|
890
|
+
/* Write elements into the FITS data array. */
|
891
|
+
static VALUE cfits_write_img(VALUE self, VALUE rfits, VALUE datatype, VALUE firstelem, VALUE nelements, VALUE array){
|
892
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
893
|
+
int status = 0, i;
|
894
|
+
|
895
|
+
int cdatatype = NUM2INT(datatype);
|
896
|
+
long cfirstelem = NUM2LONG(firstelem);
|
897
|
+
long nelem = NUM2LONG(nelements);
|
898
|
+
|
899
|
+
switch(cdatatype){
|
900
|
+
case TBYTE: {
|
901
|
+
int carray[nelem];
|
902
|
+
for(i = 0; i < nelem; i++){
|
903
|
+
carray[i] = NUM2INT(rb_ary_entry(array, i));
|
904
|
+
}
|
905
|
+
|
906
|
+
fits_write_img(cfits, cdatatype, cfirstelem, nelem, carray, &status);
|
907
|
+
break;
|
908
|
+
}
|
909
|
+
case TSHORT: {
|
910
|
+
short carray[nelem];
|
911
|
+
for(i = 0; i < nelem; i++){
|
912
|
+
carray[i] = (short) NUM2INT(rb_ary_entry(array, i));
|
913
|
+
}
|
914
|
+
|
915
|
+
fits_write_img(cfits, cdatatype, cfirstelem, nelem, carray, &status);
|
916
|
+
break;
|
917
|
+
}
|
918
|
+
case TUSHORT: {
|
919
|
+
unsigned short carray[nelem];
|
920
|
+
for(i = 0; i < nelem; i++){
|
921
|
+
carray[i] = (unsigned short) NUM2INT(rb_ary_entry(array, i));
|
922
|
+
}
|
923
|
+
|
924
|
+
fits_write_img(cfits, cdatatype, cfirstelem, nelem, carray, &status);
|
925
|
+
break;
|
926
|
+
}
|
927
|
+
case TINT: {
|
928
|
+
int carray[nelem];
|
929
|
+
for(i = 0; i < nelem; i++){
|
930
|
+
carray[i] = NUM2INT(rb_ary_entry(array, i));
|
931
|
+
}
|
932
|
+
|
933
|
+
fits_write_img(cfits, cdatatype, cfirstelem, nelem, carray, &status);
|
934
|
+
break;
|
935
|
+
}
|
936
|
+
case TUINT: {
|
937
|
+
unsigned int carray[nelem];
|
938
|
+
for(i = 0; i < nelem; i++){
|
939
|
+
carray[i] = NUM2UINT(rb_ary_entry(array, i));
|
940
|
+
}
|
941
|
+
|
942
|
+
fits_write_img(cfits, cdatatype, cfirstelem, nelem, carray, &status);
|
943
|
+
}
|
944
|
+
case TLONG: {
|
945
|
+
long carray[nelem];
|
946
|
+
for(i = 0; i < nelem; i++){
|
947
|
+
carray[i] = NUM2LONG(rb_ary_entry(array, i));
|
948
|
+
}
|
949
|
+
|
950
|
+
fits_write_img(cfits, cdatatype, cfirstelem, nelem, carray, &status);
|
951
|
+
break;
|
952
|
+
}
|
953
|
+
case TLONGLONG: {
|
954
|
+
long long carray[nelem];
|
955
|
+
for(i = 0; i < nelem; i++){
|
956
|
+
carray[i] = (long long) NUM2LONG(rb_ary_entry(array, i));
|
957
|
+
}
|
958
|
+
|
959
|
+
fits_write_img(cfits, cdatatype, cfirstelem, nelem, carray, &status);
|
960
|
+
break;
|
961
|
+
}
|
962
|
+
case TULONG: {
|
963
|
+
unsigned long carray[nelem];
|
964
|
+
for(i = 0; i < nelem; i++){
|
965
|
+
carray[i] = NUM2ULONG(rb_ary_entry(array, i));
|
966
|
+
}
|
967
|
+
|
968
|
+
fits_write_img(cfits, cdatatype, cfirstelem, nelem, carray, &status);
|
969
|
+
break;
|
970
|
+
}
|
971
|
+
case TFLOAT: {
|
972
|
+
float carray[nelem];
|
973
|
+
for(i = 0; i < nelem; i++){
|
974
|
+
carray[i] = (float) NUM2DBL(rb_ary_entry(array, i));
|
975
|
+
}
|
976
|
+
|
977
|
+
fits_write_img(cfits, cdatatype, cfirstelem, nelem, carray, &status);
|
978
|
+
break;
|
979
|
+
}
|
980
|
+
case TDOUBLE: {
|
981
|
+
double carray[nelem];
|
982
|
+
for(i = 0; i < nelem; i++){
|
983
|
+
carray[i] = NUM2DBL(rb_ary_entry(array, i));
|
984
|
+
}
|
985
|
+
|
986
|
+
fits_write_img(cfits, cdatatype, cfirstelem, nelem, carray, &status);
|
987
|
+
break;
|
988
|
+
}
|
989
|
+
default: {
|
990
|
+
double carray[nelem];
|
991
|
+
for(i = 0; i < nelem; i++){
|
992
|
+
carray[i] = NUM2DBL(rb_ary_entry(array, i));
|
993
|
+
}
|
994
|
+
|
995
|
+
fits_write_img(cfits, cdatatype, cfirstelem, nelem, carray, &status);
|
996
|
+
}
|
997
|
+
}
|
998
|
+
raise_exception_if_necessary(status);
|
999
|
+
|
1000
|
+
return(Qnil);
|
1001
|
+
}
|
1002
|
+
|
1003
|
+
/* Read an arbitrary data subsection from the data array. */
|
1004
|
+
static VALUE cfits_read_subset(VALUE self, VALUE rfits, VALUE datatype, VALUE fpixel, VALUE lpixel, VALUE inc, VALUE nulval){
|
1005
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1006
|
+
int status = 0, i;
|
1007
|
+
|
1008
|
+
int cdatatype = NUM2INT(datatype);
|
1009
|
+
int cnaxis = RARRAY(fpixel)->len;
|
1010
|
+
int anynul;
|
1011
|
+
|
1012
|
+
long cfpixel[cnaxis];
|
1013
|
+
long clpixel[cnaxis];
|
1014
|
+
long cinc[cnaxis];
|
1015
|
+
for(i = 0; i < cnaxis; i++){
|
1016
|
+
cfpixel[i] = NUM2LONG(rb_ary_entry(fpixel, i));
|
1017
|
+
clpixel[i] = NUM2LONG(rb_ary_entry(lpixel, i));
|
1018
|
+
cinc[i] = NUM2LONG(rb_ary_entry(inc, i));
|
1019
|
+
}
|
1020
|
+
long nelem = number_of_pixels_between_points(cnaxis, cfpixel, clpixel, cinc);
|
1021
|
+
|
1022
|
+
int nulval_null = NIL_P(nulval);
|
1023
|
+
|
1024
|
+
VALUE pixels = rb_ary_new2(nelem);
|
1025
|
+
switch(cdatatype){
|
1026
|
+
case TBYTE: {
|
1027
|
+
int array[nelem];
|
1028
|
+
int cnulval;
|
1029
|
+
if(!nulval_null){ cnulval = NUM2INT(nulval); }
|
1030
|
+
|
1031
|
+
fits_read_subset(cfits, cdatatype, cfpixel, clpixel, cinc, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1032
|
+
for(i = 0; i < nelem; i++){
|
1033
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
1034
|
+
}
|
1035
|
+
break;
|
1036
|
+
}
|
1037
|
+
case TSHORT: {
|
1038
|
+
short array[nelem];
|
1039
|
+
short cnulval;
|
1040
|
+
if(!nulval_null){ cnulval = (short) NUM2INT(nulval); }
|
1041
|
+
|
1042
|
+
fits_read_subset(cfits, cdatatype, cfpixel, clpixel, cinc, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1043
|
+
for(i = 0; i < nelem; i++){
|
1044
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
1045
|
+
}
|
1046
|
+
break;
|
1047
|
+
}
|
1048
|
+
case TUSHORT: {
|
1049
|
+
unsigned short array[nelem];
|
1050
|
+
unsigned short cnulval;
|
1051
|
+
if(!nulval_null){ cnulval = (unsigned short) NUM2UINT(nulval); }
|
1052
|
+
|
1053
|
+
fits_read_subset(cfits, cdatatype, cfpixel, clpixel, cinc, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1054
|
+
for(i = 0; i < nelem; i++){
|
1055
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
1056
|
+
}
|
1057
|
+
break;
|
1058
|
+
}
|
1059
|
+
case TINT: {
|
1060
|
+
int array[nelem];
|
1061
|
+
int cnulval;
|
1062
|
+
if(!nulval_null){ cnulval = NUM2INT(nulval); }
|
1063
|
+
|
1064
|
+
fits_read_subset(cfits, cdatatype, cfpixel, clpixel, cinc, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1065
|
+
for(i = 0; i < nelem; i++){
|
1066
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
1067
|
+
}
|
1068
|
+
break;
|
1069
|
+
}
|
1070
|
+
case TUINT: {
|
1071
|
+
unsigned int array[nelem];
|
1072
|
+
unsigned int cnulval;
|
1073
|
+
if(!nulval_null){ cnulval = (unsigned int) NUM2UINT(nulval); }
|
1074
|
+
|
1075
|
+
fits_read_subset(cfits, cdatatype, cfpixel, clpixel, cinc, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1076
|
+
for(i = 0; i < nelem; i++){
|
1077
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
1078
|
+
}
|
1079
|
+
break;
|
1080
|
+
}
|
1081
|
+
case TLONG: {
|
1082
|
+
long array[nelem];
|
1083
|
+
long cnulval;
|
1084
|
+
if(!nulval_null){ cnulval = NUM2LONG(nulval); }
|
1085
|
+
|
1086
|
+
fits_read_subset(cfits, cdatatype, cfpixel, clpixel, cinc, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1087
|
+
for(i = 0; i < nelem; i++){
|
1088
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
1089
|
+
}
|
1090
|
+
break;
|
1091
|
+
}
|
1092
|
+
case TLONGLONG: {
|
1093
|
+
long long array[nelem];
|
1094
|
+
long long cnulval;
|
1095
|
+
if(!nulval_null){ cnulval = (long long) NUM2LONG(nulval); }
|
1096
|
+
|
1097
|
+
fits_read_subset(cfits, cdatatype, cfpixel, clpixel, cinc, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1098
|
+
for(i = 0; i < nelem; i++){
|
1099
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
1100
|
+
}
|
1101
|
+
break;
|
1102
|
+
}
|
1103
|
+
case TULONG: {
|
1104
|
+
unsigned long array[nelem];
|
1105
|
+
unsigned long cnulval;
|
1106
|
+
if(!nulval_null){ cnulval = NUM2ULONG(nulval); }
|
1107
|
+
|
1108
|
+
fits_read_subset(cfits, cdatatype, cfpixel, clpixel, cinc, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1109
|
+
for(i = 0; i < nelem; i++){
|
1110
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
1111
|
+
}
|
1112
|
+
break;
|
1113
|
+
}
|
1114
|
+
case TFLOAT: {
|
1115
|
+
double array[nelem];
|
1116
|
+
double cnulval;
|
1117
|
+
if(!nulval_null){ cnulval = (float) NUM2DBL(nulval); }
|
1118
|
+
|
1119
|
+
fits_read_subset(cfits, cdatatype, cfpixel, clpixel, cinc, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1120
|
+
for(i = 0; i < nelem; i++){
|
1121
|
+
rb_ary_push(pixels, rb_float_new(array[i]));
|
1122
|
+
}
|
1123
|
+
break;
|
1124
|
+
}
|
1125
|
+
case TDOUBLE: {
|
1126
|
+
double array[nelem];
|
1127
|
+
double cnulval;
|
1128
|
+
if(!nulval_null){ cnulval = NUM2DBL(nulval); }
|
1129
|
+
|
1130
|
+
fits_read_subset(cfits, cdatatype, cfpixel, clpixel, cinc, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1131
|
+
for(i = 0; i < nelem; i++){
|
1132
|
+
rb_ary_push(pixels, rb_float_new(array[i]));
|
1133
|
+
}
|
1134
|
+
break;
|
1135
|
+
}
|
1136
|
+
default: {
|
1137
|
+
double array[nelem];
|
1138
|
+
double cnulval;
|
1139
|
+
if(!nulval_null){ cnulval = NUM2DBL(nulval); }
|
1140
|
+
|
1141
|
+
fits_read_subset(cfits, cdatatype, cfpixel, clpixel, cinc, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1142
|
+
for(i = 0; i < nelem; i++){
|
1143
|
+
rb_ary_push(pixels, rb_float_new(array[i]));
|
1144
|
+
}
|
1145
|
+
}
|
1146
|
+
}
|
1147
|
+
raise_exception_if_necessary(status);
|
1148
|
+
|
1149
|
+
return(rb_ary_new3(2, pixels, INT2NUM(anynul)));
|
1150
|
+
}
|
1151
|
+
|
1152
|
+
/* Write a rectangular subimage (or the whole image) to the FITS data array. */
|
1153
|
+
static VALUE cfits_write_subset(VALUE self, VALUE rfits, VALUE datatype, VALUE fpixel, VALUE lpixel, VALUE array){
|
1154
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1155
|
+
int status = 0, i;
|
1156
|
+
|
1157
|
+
int cdatatype = NUM2INT(datatype);
|
1158
|
+
int cnaxis = RARRAY(fpixel)->len;
|
1159
|
+
int nelem = RARRAY(array)->len;
|
1160
|
+
|
1161
|
+
long cfpixel[cnaxis];
|
1162
|
+
long clpixel[cnaxis];
|
1163
|
+
for(i = 0; i < cnaxis; i++){
|
1164
|
+
cfpixel[i] = NUM2LONG(rb_ary_entry(fpixel, i));
|
1165
|
+
clpixel[i] = NUM2LONG(rb_ary_entry(lpixel, i));
|
1166
|
+
}
|
1167
|
+
|
1168
|
+
switch(cdatatype){
|
1169
|
+
case TBYTE: {
|
1170
|
+
int carray[nelem];
|
1171
|
+
for(i = 0; i < nelem; i++){
|
1172
|
+
carray[i] = NUM2INT(rb_ary_entry(array, i));
|
1173
|
+
}
|
1174
|
+
|
1175
|
+
fits_write_subset(cfits, cdatatype, cfpixel, clpixel, carray, &status);
|
1176
|
+
break;
|
1177
|
+
}
|
1178
|
+
case TSHORT: {
|
1179
|
+
short carray[nelem];
|
1180
|
+
for(i = 0; i < nelem; i++){
|
1181
|
+
carray[i] = (short) NUM2INT(rb_ary_entry(array, i));
|
1182
|
+
}
|
1183
|
+
|
1184
|
+
fits_write_subset(cfits, cdatatype, cfpixel, clpixel, carray, &status);
|
1185
|
+
break;
|
1186
|
+
}
|
1187
|
+
case TUSHORT: {
|
1188
|
+
unsigned short carray[nelem];
|
1189
|
+
for(i = 0; i < nelem; i++){
|
1190
|
+
carray[i] = (unsigned short) NUM2INT(rb_ary_entry(array, i));
|
1191
|
+
}
|
1192
|
+
|
1193
|
+
fits_write_subset(cfits, cdatatype, cfpixel, clpixel, carray, &status);
|
1194
|
+
break;
|
1195
|
+
}
|
1196
|
+
case TINT: {
|
1197
|
+
int carray[nelem];
|
1198
|
+
for(i = 0; i < nelem; i++){
|
1199
|
+
carray[i] = NUM2INT(rb_ary_entry(array, i));
|
1200
|
+
}
|
1201
|
+
|
1202
|
+
fits_write_subset(cfits, cdatatype, cfpixel, clpixel, carray, &status);
|
1203
|
+
break;
|
1204
|
+
}
|
1205
|
+
case TUINT: {
|
1206
|
+
unsigned int carray[nelem];
|
1207
|
+
for(i = 0; i < nelem; i++){
|
1208
|
+
carray[i] = NUM2UINT(rb_ary_entry(array, i));
|
1209
|
+
}
|
1210
|
+
|
1211
|
+
fits_write_subset(cfits, cdatatype, cfpixel, clpixel, carray, &status);
|
1212
|
+
break;
|
1213
|
+
}
|
1214
|
+
case TLONG: {
|
1215
|
+
long carray[nelem];
|
1216
|
+
for(i = 0; i < nelem; i++){
|
1217
|
+
carray[i] = NUM2LONG(rb_ary_entry(array, i));
|
1218
|
+
}
|
1219
|
+
|
1220
|
+
fits_write_subset(cfits, cdatatype, cfpixel, clpixel, carray, &status);
|
1221
|
+
break;
|
1222
|
+
}
|
1223
|
+
case TLONGLONG: {
|
1224
|
+
long long carray[nelem];
|
1225
|
+
for(i = 0; i < nelem; i++){
|
1226
|
+
carray[i] = (long long) NUM2LONG(rb_ary_entry(array, i));
|
1227
|
+
}
|
1228
|
+
|
1229
|
+
fits_write_subset(cfits, cdatatype, cfpixel, clpixel, carray, &status);
|
1230
|
+
break;
|
1231
|
+
}
|
1232
|
+
case TULONG: {
|
1233
|
+
unsigned long carray[nelem];
|
1234
|
+
for(i = 0; i < nelem; i++){
|
1235
|
+
carray[i] = NUM2ULONG(rb_ary_entry(array, i));
|
1236
|
+
}
|
1237
|
+
|
1238
|
+
fits_write_subset(cfits, cdatatype, cfpixel, clpixel, carray, &status);
|
1239
|
+
break;
|
1240
|
+
}
|
1241
|
+
case TFLOAT: {
|
1242
|
+
float carray[nelem];
|
1243
|
+
for(i = 0; i < nelem; i++){
|
1244
|
+
carray[i] = (float) NUM2DBL(rb_ary_entry(array, i));
|
1245
|
+
}
|
1246
|
+
|
1247
|
+
fits_write_subset(cfits, cdatatype, cfpixel, clpixel, carray, &status);
|
1248
|
+
break;
|
1249
|
+
}
|
1250
|
+
case TDOUBLE: {
|
1251
|
+
double carray[nelem];
|
1252
|
+
for(i = 0; i < nelem; i++){
|
1253
|
+
carray[i] = NUM2DBL(rb_ary_entry(array, i));
|
1254
|
+
}
|
1255
|
+
|
1256
|
+
fits_write_subset(cfits, cdatatype, cfpixel, clpixel, carray, &status);
|
1257
|
+
break;
|
1258
|
+
}
|
1259
|
+
default: {
|
1260
|
+
double carray[nelem];
|
1261
|
+
for(i = 0; i < nelem; i++){
|
1262
|
+
carray[i] = NUM2DBL(rb_ary_entry(array, i));
|
1263
|
+
}
|
1264
|
+
|
1265
|
+
fits_write_subset(cfits, cdatatype, cfpixel, clpixel, carray, &status);
|
1266
|
+
}
|
1267
|
+
}
|
1268
|
+
raise_exception_if_necessary(status);
|
1269
|
+
|
1270
|
+
return(Qnil);
|
1271
|
+
}
|
1272
|
+
|
1273
|
+
/* Read pixels from the FITS data array. */
|
1274
|
+
static VALUE cfits_read_pix(VALUE self, VALUE rfits, VALUE datatype, VALUE fpixel, VALUE nelements, VALUE nulval){
|
1275
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1276
|
+
int status = 0, i;
|
1277
|
+
|
1278
|
+
int cdatatype = NUM2INT(datatype);
|
1279
|
+
int cnaxis = RARRAY(fpixel)->len;
|
1280
|
+
long nelem = NUM2LONG(nelements);
|
1281
|
+
int anynul;
|
1282
|
+
|
1283
|
+
long cfpixel[cnaxis];
|
1284
|
+
for(i = 0; i < cnaxis; i++){
|
1285
|
+
cfpixel[i] = NUM2LONG(rb_ary_entry(fpixel, i));
|
1286
|
+
}
|
1287
|
+
|
1288
|
+
int nulval_null = NIL_P(nulval);
|
1289
|
+
|
1290
|
+
VALUE pixels = rb_ary_new2(nelem);
|
1291
|
+
switch(cdatatype){
|
1292
|
+
case TBYTE: {
|
1293
|
+
int array[nelem];
|
1294
|
+
int cnulval;
|
1295
|
+
if(!nulval_null){ cnulval = NUM2INT(nulval); }
|
1296
|
+
|
1297
|
+
fits_read_pix(cfits, cdatatype, cfpixel, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1298
|
+
for(i = 0; i < nelem; i++){
|
1299
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
1300
|
+
}
|
1301
|
+
break;
|
1302
|
+
}
|
1303
|
+
case TSHORT: {
|
1304
|
+
short array[nelem];
|
1305
|
+
short cnulval;
|
1306
|
+
if(!nulval_null){ cnulval = (short) NUM2INT(nulval); }
|
1307
|
+
|
1308
|
+
fits_read_pix(cfits, cdatatype, cfpixel, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1309
|
+
for(i = 0; i < nelem; i++){
|
1310
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
1311
|
+
}
|
1312
|
+
break;
|
1313
|
+
}
|
1314
|
+
case TUSHORT: {
|
1315
|
+
unsigned short array[nelem];
|
1316
|
+
unsigned short cnulval;
|
1317
|
+
if(!nulval_null){ cnulval = (unsigned short) NUM2INT(nulval); }
|
1318
|
+
|
1319
|
+
fits_read_pix(cfits, cdatatype, cfpixel, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1320
|
+
for(i = 0; i < nelem; i++){
|
1321
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
1322
|
+
}
|
1323
|
+
break;
|
1324
|
+
}
|
1325
|
+
case TINT: {
|
1326
|
+
int array[nelem];
|
1327
|
+
int cnulval;
|
1328
|
+
if(!nulval_null){ cnulval = NUM2INT(nulval); }
|
1329
|
+
|
1330
|
+
fits_read_pix(cfits, cdatatype, cfpixel, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1331
|
+
for(i = 0; i < nelem; i++){
|
1332
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
1333
|
+
}
|
1334
|
+
break;
|
1335
|
+
}
|
1336
|
+
case TUINT: {
|
1337
|
+
unsigned int array[nelem];
|
1338
|
+
unsigned int cnulval;
|
1339
|
+
if(!nulval_null){ cnulval = (unsigned int) NUM2UINT(nulval); }
|
1340
|
+
|
1341
|
+
fits_read_pix(cfits, cdatatype, cfpixel, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1342
|
+
for(i = 0; i < nelem; i++){
|
1343
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
1344
|
+
}
|
1345
|
+
break;
|
1346
|
+
}
|
1347
|
+
case TLONG: {
|
1348
|
+
long array[nelem];
|
1349
|
+
long cnulval;
|
1350
|
+
if(!nulval_null){ cnulval = (long) NUM2LONG(nulval); }
|
1351
|
+
|
1352
|
+
fits_read_pix(cfits, cdatatype, cfpixel, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1353
|
+
for(i = 0; i < nelem; i++){
|
1354
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
1355
|
+
}
|
1356
|
+
break;
|
1357
|
+
}
|
1358
|
+
case TLONGLONG: {
|
1359
|
+
long long array[nelem];
|
1360
|
+
long long cnulval;
|
1361
|
+
if(!nulval_null){ cnulval = (long long) NUM2LONG(nulval); }
|
1362
|
+
|
1363
|
+
fits_read_pix(cfits, cdatatype, cfpixel, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1364
|
+
for(i = 0; i < nelem; i++){
|
1365
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
1366
|
+
}
|
1367
|
+
break;
|
1368
|
+
}
|
1369
|
+
case TULONG: {
|
1370
|
+
unsigned long array[nelem];
|
1371
|
+
unsigned long cnulval;
|
1372
|
+
if(!nulval_null){ cnulval = NUM2ULONG(nulval); }
|
1373
|
+
|
1374
|
+
fits_read_pix(cfits, cdatatype, cfpixel, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1375
|
+
for(i = 0; i < nelem; i++){
|
1376
|
+
rb_ary_push(pixels, INT2NUM(array[i]));
|
1377
|
+
}
|
1378
|
+
break;
|
1379
|
+
}
|
1380
|
+
case TFLOAT: {
|
1381
|
+
float array[nelem];
|
1382
|
+
float cnulval;
|
1383
|
+
if(!nulval_null){ cnulval = (float) NUM2DBL(nulval); }
|
1384
|
+
|
1385
|
+
fits_read_pix(cfits, cdatatype, cfpixel, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1386
|
+
for(i = 0; i < nelem; i++){
|
1387
|
+
rb_ary_push(pixels, rb_float_new(array[i]));
|
1388
|
+
}
|
1389
|
+
break;
|
1390
|
+
}
|
1391
|
+
case TDOUBLE: {
|
1392
|
+
double array[nelem];
|
1393
|
+
double cnulval;
|
1394
|
+
if(!nulval_null){ cnulval = NUM2DBL(nulval); }
|
1395
|
+
|
1396
|
+
fits_read_pix(cfits, cdatatype, cfpixel, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1397
|
+
for(i = 0; i < nelem; i++){
|
1398
|
+
rb_ary_push(pixels, rb_float_new(array[i]));
|
1399
|
+
}
|
1400
|
+
break;
|
1401
|
+
}
|
1402
|
+
default: {
|
1403
|
+
double array[nelem];
|
1404
|
+
double cnulval;
|
1405
|
+
if(!nulval_null){ cnulval = NUM2DBL(nulval); }
|
1406
|
+
|
1407
|
+
fits_read_pix(cfits, cdatatype, cfpixel, nelem, nulval_null ? NULL : &cnulval, array, &anynul, &status);
|
1408
|
+
for(i = 0; i < nelem; i++){
|
1409
|
+
rb_ary_push(pixels, rb_float_new(array[i]));
|
1410
|
+
}
|
1411
|
+
}
|
1412
|
+
}
|
1413
|
+
raise_exception_if_necessary(status);
|
1414
|
+
|
1415
|
+
return(rb_ary_new3(2, pixels, INT2NUM(anynul)));
|
1416
|
+
}
|
1417
|
+
|
1418
|
+
/* Write pixels into the FITS data array. */
|
1419
|
+
static VALUE cfits_write_pixnull(VALUE self, VALUE rfits, VALUE datatype, VALUE fpixel, VALUE nelements, VALUE array, VALUE nulval){
|
1420
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1421
|
+
int status = 0, i;
|
1422
|
+
|
1423
|
+
int cdatatype = NUM2INT(datatype);
|
1424
|
+
int cnaxis = RARRAY(fpixel)->len;
|
1425
|
+
long nelem = NUM2LONG(nelements);
|
1426
|
+
|
1427
|
+
long cfpixel[cnaxis];
|
1428
|
+
for(i = 0; i < cnaxis; i++){
|
1429
|
+
cfpixel[i] = NUM2LONG(rb_ary_entry(fpixel, i));
|
1430
|
+
}
|
1431
|
+
|
1432
|
+
int nulval_null = NIL_P(nulval);
|
1433
|
+
|
1434
|
+
switch(cdatatype){
|
1435
|
+
case TBYTE: {
|
1436
|
+
int cnulval;
|
1437
|
+
if(!nulval_null){ cnulval = NUM2INT(nulval); }
|
1438
|
+
|
1439
|
+
int carray[nelem];
|
1440
|
+
for(i = 0; i < nelem; i++){
|
1441
|
+
carray[i] = NUM2INT(rb_ary_entry(array, i));
|
1442
|
+
}
|
1443
|
+
|
1444
|
+
fits_write_pixnull(cfits, cdatatype, cfpixel, nelem, carray, nulval_null ? NULL : &cnulval, &status);
|
1445
|
+
break;
|
1446
|
+
}
|
1447
|
+
case TSHORT: {
|
1448
|
+
short cnulval;
|
1449
|
+
if(!nulval_null){ cnulval = (short) NUM2INT(nulval); }
|
1450
|
+
|
1451
|
+
short carray[nelem];
|
1452
|
+
for(i = 0; i < nelem; i++){
|
1453
|
+
carray[i] = (short) NUM2INT(rb_ary_entry(array, i));
|
1454
|
+
}
|
1455
|
+
|
1456
|
+
fits_write_pixnull(cfits, cdatatype, cfpixel, nelem, carray, nulval_null ? NULL : &cnulval, &status);
|
1457
|
+
break;
|
1458
|
+
}
|
1459
|
+
case TUSHORT: {
|
1460
|
+
unsigned short cnulval;
|
1461
|
+
if(!nulval_null){ cnulval = (unsigned short) NUM2INT(nulval); }
|
1462
|
+
|
1463
|
+
unsigned short carray[nelem];
|
1464
|
+
for(i = 0; i < nelem; i++){
|
1465
|
+
carray[i] = (unsigned short) NUM2INT(rb_ary_entry(array, i));
|
1466
|
+
}
|
1467
|
+
|
1468
|
+
fits_write_pixnull(cfits, cdatatype, cfpixel, nelem, carray, nulval_null ? NULL : &cnulval, &status);
|
1469
|
+
break;
|
1470
|
+
}
|
1471
|
+
case TINT: {
|
1472
|
+
int cnulval;
|
1473
|
+
if(!nulval_null){ cnulval = NUM2INT(nulval); }
|
1474
|
+
|
1475
|
+
int carray[nelem];
|
1476
|
+
for(i = 0; i < nelem; i++){
|
1477
|
+
carray[i] = NUM2INT(rb_ary_entry(array, i));
|
1478
|
+
}
|
1479
|
+
|
1480
|
+
fits_write_pixnull(cfits, cdatatype, cfpixel, nelem, carray, nulval_null ? NULL : &cnulval, &status);
|
1481
|
+
break;
|
1482
|
+
}
|
1483
|
+
case TUINT: {
|
1484
|
+
unsigned int cnulval;
|
1485
|
+
if(!nulval_null){ cnulval = NUM2UINT(nulval); }
|
1486
|
+
|
1487
|
+
unsigned int carray[nelem];
|
1488
|
+
for(i = 0; i < nelem; i++){
|
1489
|
+
carray[i] = NUM2UINT(rb_ary_entry(array, i));
|
1490
|
+
}
|
1491
|
+
|
1492
|
+
fits_write_pixnull(cfits, cdatatype, cfpixel, nelem, carray, nulval_null ? NULL : &cnulval, &status);
|
1493
|
+
break;
|
1494
|
+
}
|
1495
|
+
case TLONG: {
|
1496
|
+
long cnulval;
|
1497
|
+
if(!nulval_null){ cnulval = NUM2LONG(nulval); }
|
1498
|
+
|
1499
|
+
long carray[nelem];
|
1500
|
+
for(i = 0; i < nelem; i++){
|
1501
|
+
carray[i] = NUM2LONG(rb_ary_entry(array, i));
|
1502
|
+
}
|
1503
|
+
|
1504
|
+
fits_write_pixnull(cfits, cdatatype, cfpixel, nelem, carray, nulval_null ? NULL : &cnulval, &status);
|
1505
|
+
break;
|
1506
|
+
}
|
1507
|
+
case TLONGLONG: {
|
1508
|
+
long long cnulval;
|
1509
|
+
if(!nulval_null){ cnulval = (long long) NUM2LONG(nulval); }
|
1510
|
+
|
1511
|
+
long long carray[nelem];
|
1512
|
+
for(i = 0; i < nelem; i++){
|
1513
|
+
carray[i] = (long long) NUM2LONG(rb_ary_entry(array, i));
|
1514
|
+
}
|
1515
|
+
|
1516
|
+
fits_write_pixnull(cfits, cdatatype, cfpixel, nelem, carray, nulval_null ? NULL : &cnulval, &status);
|
1517
|
+
break;
|
1518
|
+
}
|
1519
|
+
case TULONG: {
|
1520
|
+
unsigned long cnulval;
|
1521
|
+
if(!nulval_null){ cnulval = NUM2ULONG(nulval); }
|
1522
|
+
|
1523
|
+
unsigned long carray[nelem];
|
1524
|
+
for(i = 0; i < nelem; i++){
|
1525
|
+
carray[i] = NUM2ULONG(rb_ary_entry(array, i));
|
1526
|
+
}
|
1527
|
+
|
1528
|
+
fits_write_pixnull(cfits, cdatatype, cfpixel, nelem, carray, nulval_null ? NULL : &cnulval, &status);
|
1529
|
+
break;
|
1530
|
+
}
|
1531
|
+
case TFLOAT: {
|
1532
|
+
float cnulval;
|
1533
|
+
if(!nulval_null){ cnulval = (float) NUM2DBL(nulval); }
|
1534
|
+
|
1535
|
+
float carray[nelem];
|
1536
|
+
for(i = 0; i < nelem; i++){
|
1537
|
+
carray[i] = (float) NUM2DBL(rb_ary_entry(array, i));
|
1538
|
+
}
|
1539
|
+
|
1540
|
+
fits_write_pixnull(cfits, cdatatype, cfpixel, nelem, carray, nulval_null ? NULL : &cnulval, &status);
|
1541
|
+
break;
|
1542
|
+
}
|
1543
|
+
case TDOUBLE: {
|
1544
|
+
double cnulval;
|
1545
|
+
if(!nulval_null){ cnulval = NUM2DBL(nulval); }
|
1546
|
+
|
1547
|
+
double carray[nelem];
|
1548
|
+
for(i = 0; i < nelem; i++){
|
1549
|
+
carray[i] = NUM2DBL(rb_ary_entry(array, i));
|
1550
|
+
}
|
1551
|
+
|
1552
|
+
fits_write_pixnull(cfits, cdatatype, cfpixel, nelem, carray, nulval_null ? NULL : &cnulval, &status);
|
1553
|
+
break;
|
1554
|
+
}
|
1555
|
+
default: {
|
1556
|
+
double cnulval;
|
1557
|
+
if(!nulval_null){ cnulval = NUM2DBL(nulval); }
|
1558
|
+
|
1559
|
+
double carray[nelem];
|
1560
|
+
for(i = 0; i < nelem; i++){
|
1561
|
+
carray[i] = NUM2DBL(rb_ary_entry(array, i));
|
1562
|
+
}
|
1563
|
+
|
1564
|
+
fits_write_pixnull(cfits, cdatatype, cfpixel, nelem, carray, nulval_null ? NULL : &cnulval, &status);
|
1565
|
+
}
|
1566
|
+
}
|
1567
|
+
raise_exception_if_necessary(status);
|
1568
|
+
|
1569
|
+
return(Qnil);
|
1570
|
+
}
|
1571
|
+
|
1572
|
+
/* Set FITS data array elements equal to the appropriate null pixel value. */
|
1573
|
+
static VALUE cfits_write_null_img(VALUE self, VALUE rfits, VALUE firstelem, VALUE nelements){
|
1574
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1575
|
+
int status = 0;
|
1576
|
+
|
1577
|
+
fits_write_null_img(cfits, NUM2LONG(firstelem), NUM2LONG(nelements), &status);
|
1578
|
+
raise_exception_if_necessary(status);
|
1579
|
+
|
1580
|
+
return(Qnil);
|
1581
|
+
}
|
1582
|
+
|
1583
|
+
/* Set the compression type of the IMAGE. */
|
1584
|
+
static VALUE cfits_set_compression_type(VALUE self, VALUE rfits, VALUE comptype){
|
1585
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1586
|
+
int status = 0;
|
1587
|
+
|
1588
|
+
if(NIL_P(comptype)){
|
1589
|
+
fits_set_compression_type(cfits, 0, &status);
|
1590
|
+
} else {
|
1591
|
+
fits_set_compression_type(cfits, NUM2INT(comptype), &status);
|
1592
|
+
}
|
1593
|
+
raise_exception_if_necessary(status);
|
1594
|
+
|
1595
|
+
return(Qnil);
|
1596
|
+
}
|
1597
|
+
|
1598
|
+
/* Get the compression type of the IMAGE. */
|
1599
|
+
static VALUE cfits_get_compression_type(VALUE self, VALUE rfits){
|
1600
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1601
|
+
int status = 0;
|
1602
|
+
|
1603
|
+
int comptype;
|
1604
|
+
fits_get_compression_type(cfits, &comptype, &status);
|
1605
|
+
raise_exception_if_necessary(status);
|
1606
|
+
|
1607
|
+
return(INT2NUM(comptype));
|
1608
|
+
}
|
1609
|
+
|
1610
|
+
/* Set the compression tile dimensions for the IMAGE. */
|
1611
|
+
static VALUE cfits_set_tile_dim(VALUE self, VALUE rfits, VALUE ndim, VALUE tilesize){
|
1612
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1613
|
+
int status = 0, i;
|
1614
|
+
|
1615
|
+
int cndim = NUM2INT(ndim);
|
1616
|
+
|
1617
|
+
long ctilesize[cndim];
|
1618
|
+
for(i = 0; i < cndim; i++){
|
1619
|
+
ctilesize[i] = NUM2LONG(rb_ary_entry(tilesize, i));
|
1620
|
+
}
|
1621
|
+
|
1622
|
+
fits_set_tile_dim(cfits, cndim, ctilesize, &status);
|
1623
|
+
raise_exception_if_necessary(status);
|
1624
|
+
|
1625
|
+
return(Qnil);
|
1626
|
+
}
|
1627
|
+
|
1628
|
+
/* Get the compression tile dimensions for the IMAGE. */
|
1629
|
+
static VALUE cfits_get_tile_dim(VALUE self, VALUE rfits, VALUE ndim){
|
1630
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1631
|
+
int status = 0, i;
|
1632
|
+
|
1633
|
+
int cndim = NUM2INT(ndim);
|
1634
|
+
long ctilesize[cndim];
|
1635
|
+
|
1636
|
+
fits_get_tile_dim(cfits, cndim, ctilesize, &status);
|
1637
|
+
raise_exception_if_necessary(status);
|
1638
|
+
|
1639
|
+
VALUE rtilesize = rb_ary_new2(cndim);
|
1640
|
+
for(i = 0; i < cndim; i++){
|
1641
|
+
rb_ary_push(rtilesize, INT2NUM(ctilesize[i]));
|
1642
|
+
}
|
1643
|
+
|
1644
|
+
return(rtilesize);
|
1645
|
+
}
|
1646
|
+
|
1647
|
+
/* Set the compression noise bits for the IMAGE. */
|
1648
|
+
static VALUE cfits_set_noise_bits(VALUE self, VALUE rfits, VALUE noisebits){
|
1649
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1650
|
+
int status = 0;
|
1651
|
+
|
1652
|
+
fits_set_noise_bits(cfits, NUM2INT(noisebits), &status);
|
1653
|
+
raise_exception_if_necessary(status);
|
1654
|
+
|
1655
|
+
return(Qnil);
|
1656
|
+
}
|
1657
|
+
|
1658
|
+
/* Get the compression noise bits for the IMAGE. */
|
1659
|
+
static VALUE cfits_get_noise_bits(VALUE self, VALUE rfits){
|
1660
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1661
|
+
int status = 0;
|
1662
|
+
|
1663
|
+
int noisebits;
|
1664
|
+
fits_get_noise_bits(cfits, &noisebits, &status);
|
1665
|
+
raise_exception_if_necessary(status);
|
1666
|
+
|
1667
|
+
return(INT2NUM(noisebits));
|
1668
|
+
}
|
1669
|
+
|
1670
|
+
/* Set the compression scale factor for the IMAGE. */
|
1671
|
+
static VALUE cfits_set_hcomp_scale(VALUE self, VALUE rfits, VALUE scale){
|
1672
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1673
|
+
int status = 0;
|
1674
|
+
|
1675
|
+
fits_set_hcomp_scale(cfits, NUM2INT(scale), &status);
|
1676
|
+
raise_exception_if_necessary(status);
|
1677
|
+
|
1678
|
+
return(Qnil);
|
1679
|
+
}
|
1680
|
+
|
1681
|
+
/* Get the compression scale factor for the IMAGE. */
|
1682
|
+
static VALUE cfits_get_hcomp_scale(VALUE self, VALUE rfits){
|
1683
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1684
|
+
int status = 0;
|
1685
|
+
|
1686
|
+
int scale;
|
1687
|
+
fits_get_hcomp_scale(cfits, &scale, &status);
|
1688
|
+
raise_exception_if_necessary(status);
|
1689
|
+
|
1690
|
+
return(INT2NUM(scale));
|
1691
|
+
}
|
1692
|
+
|
1693
|
+
/* Set the compression smoothing for the IMAGE. */
|
1694
|
+
static VALUE cfits_set_hcomp_smooth(VALUE self, VALUE rfits, VALUE smooth){
|
1695
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1696
|
+
int status = 0;
|
1697
|
+
|
1698
|
+
fits_set_hcomp_smooth(cfits, NUM2INT(smooth), &status);
|
1699
|
+
raise_exception_if_necessary(status);
|
1700
|
+
|
1701
|
+
return(Qnil);
|
1702
|
+
}
|
1703
|
+
|
1704
|
+
/* Get the compression smoothing for the IMAGE. */
|
1705
|
+
static VALUE cfits_get_hcomp_smooth(VALUE self, VALUE rfits){
|
1706
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1707
|
+
int status = 0;
|
1708
|
+
|
1709
|
+
int smooth;
|
1710
|
+
fits_get_hcomp_smooth(cfits, &smooth, &status);
|
1711
|
+
raise_exception_if_necessary(status);
|
1712
|
+
|
1713
|
+
return(INT2NUM(smooth));
|
1714
|
+
}
|
1715
|
+
|
1716
|
+
/* Compress an IMAGE. */
|
1717
|
+
static VALUE cfits_img_compress(VALUE self, VALUE rinfits, VALUE routfits){
|
1718
|
+
fitsfile *cinfits = RFITS2CFITS(rinfits);
|
1719
|
+
fitsfile *coutfits = RFITS2CFITS(routfits);
|
1720
|
+
int status = 0;
|
1721
|
+
|
1722
|
+
fits_img_compress(cinfits, coutfits, &status);
|
1723
|
+
raise_exception_if_necessary(status);
|
1724
|
+
|
1725
|
+
return(Qnil);
|
1726
|
+
}
|
1727
|
+
|
1728
|
+
/* Decompress an IMAGE. */
|
1729
|
+
static VALUE cfits_img_decompress(VALUE self, VALUE rinfits, VALUE routfits){
|
1730
|
+
fitsfile *cinfits = RFITS2CFITS(rinfits);
|
1731
|
+
fitsfile *coutfits = RFITS2CFITS(routfits);
|
1732
|
+
int status = 0;
|
1733
|
+
|
1734
|
+
fits_img_decompress(cinfits, coutfits, &status);
|
1735
|
+
raise_exception_if_necessary(status);
|
1736
|
+
|
1737
|
+
return(Qnil);
|
1738
|
+
}
|
1739
|
+
|
1740
|
+
/* Determine whether the CHDU is compressed. */
|
1741
|
+
static VALUE cfits_is_compressed_image(VALUE self, VALUE rfits){
|
1742
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1743
|
+
int status = 0;
|
1744
|
+
|
1745
|
+
int compressed = fits_is_compressed_image(cfits, &status);
|
1746
|
+
raise_exception_if_necessary(status);
|
1747
|
+
|
1748
|
+
return(INT2NUM(compressed));
|
1749
|
+
}
|
1750
|
+
|
1751
|
+
/* Create a new ASCII or bintable table extension. */
|
1752
|
+
static VALUE cfits_create_tbl(VALUE self, VALUE rfits, VALUE tbltype, VALUE naxis2, VALUE tfields, VALUE ttype, VALUE tform, VALUE tunit, VALUE extname){
|
1753
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1754
|
+
int status = 0, i;
|
1755
|
+
|
1756
|
+
int ctfields = NUM2INT(tfields);
|
1757
|
+
|
1758
|
+
// column names
|
1759
|
+
char *cttype[ctfields];
|
1760
|
+
for(i = 0; i < ctfields; i++){
|
1761
|
+
cttype[i] = STR2CSTR(rb_ary_entry(ttype, i));
|
1762
|
+
}
|
1763
|
+
|
1764
|
+
// format of the column
|
1765
|
+
char *ctform[ctfields];
|
1766
|
+
for(i = 0; i < ctfields; i++){
|
1767
|
+
ctform[i] = STR2CSTR(rb_ary_entry(tform, i));
|
1768
|
+
}
|
1769
|
+
|
1770
|
+
// physical unit for table column
|
1771
|
+
char *ctunit[ctfields];
|
1772
|
+
int tunit_is_null = 0;
|
1773
|
+
if(NIL_P(tunit)){
|
1774
|
+
tunit_is_null = 1;
|
1775
|
+
} else {
|
1776
|
+
for(i = 0; i < ctfields; i++){
|
1777
|
+
ctunit[i] = STR2CSTR(rb_ary_entry(tunit, i));
|
1778
|
+
}
|
1779
|
+
}
|
1780
|
+
|
1781
|
+
// extension name
|
1782
|
+
char *cextname = NIL_P(extname) ? NULL : STR2CSTR(extname);
|
1783
|
+
|
1784
|
+
fits_create_tbl(cfits,
|
1785
|
+
NUM2INT(tbltype), NUM2LONG(naxis2), ctfields,
|
1786
|
+
cttype,
|
1787
|
+
ctform,
|
1788
|
+
tunit_is_null ? NULL : ctunit,
|
1789
|
+
cextname,
|
1790
|
+
&status);
|
1791
|
+
raise_exception_if_necessary(status);
|
1792
|
+
|
1793
|
+
return(Qnil);
|
1794
|
+
}
|
1795
|
+
|
1796
|
+
/* Insert a new ASCII table extension immediately following the CHDU. */
|
1797
|
+
static VALUE cfits_insert_atbl(VALUE self, VALUE rfits, VALUE rowlen, VALUE nrows, VALUE tfields, VALUE ttype, VALUE tbcol, VALUE tform, VALUE tunit, VALUE extname){
|
1798
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1799
|
+
int status = 0, i;
|
1800
|
+
|
1801
|
+
int nttype = NUM2INT(tfields);
|
1802
|
+
|
1803
|
+
// column names
|
1804
|
+
char *cttype[nttype];
|
1805
|
+
for(i = 0; i < nttype; i++){
|
1806
|
+
cttype[i] = STR2CSTR(rb_ary_entry(ttype, i));
|
1807
|
+
}
|
1808
|
+
|
1809
|
+
// byte position in row to start of column
|
1810
|
+
long ctbcol[nttype];
|
1811
|
+
int tbcol_is_null = 0;
|
1812
|
+
if(NIL_P(tbcol)){
|
1813
|
+
tbcol_is_null = 1;
|
1814
|
+
} else {
|
1815
|
+
for(i = 0; i < nttype; i++){
|
1816
|
+
ctbcol[i] = NUM2LONG(rb_ary_entry(tbcol, i));
|
1817
|
+
}
|
1818
|
+
}
|
1819
|
+
|
1820
|
+
// format of the column
|
1821
|
+
char *ctform[nttype];
|
1822
|
+
for(i = 0; i < nttype; i++){
|
1823
|
+
ctform[i] = STR2CSTR(rb_ary_entry(tform, i));
|
1824
|
+
}
|
1825
|
+
|
1826
|
+
// physical unit for table column
|
1827
|
+
char *ctunit[nttype];
|
1828
|
+
int tunit_is_null = 0;
|
1829
|
+
if(NIL_P(tunit)){
|
1830
|
+
tunit_is_null = 1;
|
1831
|
+
} else {
|
1832
|
+
for(i = 0; i < nttype; i++){
|
1833
|
+
ctunit[i] = STR2CSTR(rb_ary_entry(tunit, i));
|
1834
|
+
}
|
1835
|
+
}
|
1836
|
+
|
1837
|
+
// extension name
|
1838
|
+
char *cextname = NIL_P(extname) ? NULL : STR2CSTR(extname);
|
1839
|
+
|
1840
|
+
fits_insert_atbl(cfits,
|
1841
|
+
NUM2LONG(rowlen), NUM2LONG(nrows), NUM2INT(tfields),
|
1842
|
+
cttype,
|
1843
|
+
tbcol_is_null ? NULL : ctbcol,
|
1844
|
+
ctform,
|
1845
|
+
tunit_is_null ? NULL : ctunit,
|
1846
|
+
cextname,
|
1847
|
+
&status);
|
1848
|
+
raise_exception_if_necessary(status);
|
1849
|
+
|
1850
|
+
return(Qnil);
|
1851
|
+
}
|
1852
|
+
|
1853
|
+
/* Insert a new binary table extension immediately following the CHDU. */
|
1854
|
+
static VALUE cfits_insert_btbl(VALUE self, VALUE rfits, VALUE nrows, VALUE tfields, VALUE ttype, VALUE tform, VALUE tunit, VALUE extname, VALUE pcount){
|
1855
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1856
|
+
int status = 0, i;
|
1857
|
+
|
1858
|
+
int nttype = NUM2INT(tfields);
|
1859
|
+
|
1860
|
+
// column names
|
1861
|
+
char *cttype[nttype];
|
1862
|
+
for(i = 0; i < nttype; i++){
|
1863
|
+
cttype[i] = STR2CSTR(rb_ary_entry(ttype, i));
|
1864
|
+
}
|
1865
|
+
|
1866
|
+
// format of the column
|
1867
|
+
char *ctform[nttype];
|
1868
|
+
for(i = 0; i < nttype; i++){
|
1869
|
+
ctform[i] = STR2CSTR(rb_ary_entry(tform, i));
|
1870
|
+
}
|
1871
|
+
|
1872
|
+
// physical unit for table column
|
1873
|
+
char *ctunit[nttype];
|
1874
|
+
int tunit_is_null = 0;
|
1875
|
+
if(NIL_P(tunit)){
|
1876
|
+
tunit_is_null = 1;
|
1877
|
+
} else {
|
1878
|
+
for(i = 0; i < nttype; i++){
|
1879
|
+
ctunit[i] = STR2CSTR(rb_ary_entry(tunit, i));
|
1880
|
+
}
|
1881
|
+
}
|
1882
|
+
|
1883
|
+
// extension name
|
1884
|
+
char *cextname = NIL_P(extname) ? NULL : STR2CSTR(extname);
|
1885
|
+
|
1886
|
+
fits_insert_btbl(cfits,
|
1887
|
+
NUM2LONG(nrows), NUM2INT(tfields),
|
1888
|
+
cttype,
|
1889
|
+
ctform,
|
1890
|
+
tunit_is_null ? NULL : ctunit,
|
1891
|
+
cextname,
|
1892
|
+
NUM2LONG(pcount),
|
1893
|
+
&status);
|
1894
|
+
raise_exception_if_necessary(status);
|
1895
|
+
|
1896
|
+
return(Qnil);
|
1897
|
+
}
|
1898
|
+
|
1899
|
+
/* Get the number of rows in the current FITS table. */
|
1900
|
+
static VALUE cfits_get_num_rows(VALUE self, VALUE rfits){
|
1901
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1902
|
+
int status = 0;
|
1903
|
+
|
1904
|
+
long nrows;
|
1905
|
+
fits_get_num_rows(cfits, &nrows, &status);
|
1906
|
+
raise_exception_if_necessary(status);
|
1907
|
+
|
1908
|
+
return(INT2NUM(nrows));
|
1909
|
+
}
|
1910
|
+
|
1911
|
+
/* Get the number of columns in the current FITS table. */
|
1912
|
+
static VALUE cfits_get_num_cols(VALUE self, VALUE rfits){
|
1913
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1914
|
+
int status = 0;
|
1915
|
+
|
1916
|
+
int ncols;
|
1917
|
+
fits_get_num_cols(cfits, &ncols, &status);
|
1918
|
+
raise_exception_if_necessary(status);
|
1919
|
+
|
1920
|
+
return(INT2NUM(ncols));
|
1921
|
+
}
|
1922
|
+
|
1923
|
+
/* Get the table column number of the column whose name matches an input template name. */
|
1924
|
+
static VALUE cfits_get_colnum(VALUE self, VALUE rfits, VALUE casesen, VALUE templt){
|
1925
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1926
|
+
int status = 0;
|
1927
|
+
|
1928
|
+
int colnum;
|
1929
|
+
fits_get_colnum(cfits, NUM2INT(casesen), STR2CSTR(templt), &colnum, &status);
|
1930
|
+
raise_exception_if_necessary(status);
|
1931
|
+
|
1932
|
+
return(INT2NUM(colnum));
|
1933
|
+
}
|
1934
|
+
|
1935
|
+
/* Get the table column name and number of the column whose name matches an input template name. */
|
1936
|
+
static VALUE cfits_get_colname(VALUE self, VALUE rfits, VALUE casesen, VALUE templt){
|
1937
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1938
|
+
int status = 0;
|
1939
|
+
|
1940
|
+
char colname[70];
|
1941
|
+
int colnum;
|
1942
|
+
fits_get_colname(cfits, NUM2INT(casesen), STR2CSTR(templt), colname, &colnum, &status);
|
1943
|
+
raise_exception_if_necessary(status);
|
1944
|
+
|
1945
|
+
return(rb_ary_new3(2, rb_str_new2(colname), INT2NUM(colnum)));
|
1946
|
+
}
|
1947
|
+
|
1948
|
+
/* Return the data type, vector repeat value, and the width in bytes of a column in an ASCII or binary table. */
|
1949
|
+
static VALUE cfits_get_coltype(VALUE self, VALUE rfits, VALUE colnum){
|
1950
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1951
|
+
int status = 0;
|
1952
|
+
|
1953
|
+
int typecode;
|
1954
|
+
long repeat, width;
|
1955
|
+
fits_get_coltype(cfits, NUM2INT(colnum), &typecode, &repeat, &width, &status);
|
1956
|
+
raise_exception_if_necessary(status);
|
1957
|
+
|
1958
|
+
return(rb_ary_new3(3, INT2NUM(typecode), INT2NUM(repeat), INT2NUM(width)));
|
1959
|
+
}
|
1960
|
+
|
1961
|
+
/* Return the equivalent data type, vector repeat value, and the width in bytes of a column in an ASCII or binary table. */
|
1962
|
+
static VALUE cfits_get_eqcoltype(VALUE self, VALUE rfits, VALUE colnum){
|
1963
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1964
|
+
int status = 0;
|
1965
|
+
|
1966
|
+
int typecode;
|
1967
|
+
long repeat, width;
|
1968
|
+
fits_get_eqcoltype(cfits, NUM2INT(colnum), &typecode, &repeat, &width, &status);
|
1969
|
+
raise_exception_if_necessary(status);
|
1970
|
+
|
1971
|
+
return(rb_ary_new3(3, INT2NUM(typecode), INT2NUM(repeat), INT2NUM(width)));
|
1972
|
+
}
|
1973
|
+
|
1974
|
+
/* Return the display width of a column. */
|
1975
|
+
static VALUE cfits_get_col_display_width(VALUE self, VALUE rfits, VALUE colnum){
|
1976
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1977
|
+
int status = 0;
|
1978
|
+
|
1979
|
+
int dispwidth;
|
1980
|
+
fits_get_col_display_width(cfits, NUM2INT(colnum), &dispwidth, &status);
|
1981
|
+
raise_exception_if_necessary(status);
|
1982
|
+
|
1983
|
+
return(INT2NUM(dispwidth));
|
1984
|
+
}
|
1985
|
+
|
1986
|
+
/* Return the number of and size of the dimensions of a table column in a binary table. */
|
1987
|
+
static VALUE cfits_read_tdim(VALUE self, VALUE rfits, VALUE colnum, VALUE maxdim){
|
1988
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
1989
|
+
int status = 0, i;
|
1990
|
+
|
1991
|
+
int cmaxdim = NUM2INT(maxdim);
|
1992
|
+
|
1993
|
+
int naxis;
|
1994
|
+
long naxes[cmaxdim];
|
1995
|
+
fits_read_tdim(cfits, NUM2INT(colnum), cmaxdim, &naxis, naxes, &status);
|
1996
|
+
raise_exception_if_necessary(status);
|
1997
|
+
|
1998
|
+
VALUE rnaxes = rb_ary_new2(cmaxdim);
|
1999
|
+
for(i = 0; i < cmaxdim; i++){
|
2000
|
+
rb_ary_push(rnaxes, INT2NUM(naxes[i]));
|
2001
|
+
}
|
2002
|
+
|
2003
|
+
return(rb_ary_new3(2, INT2NUM(naxis), rnaxes));
|
2004
|
+
}
|
2005
|
+
|
2006
|
+
/* Write a TDIMn keyword whose value has the form '(l,m,n...)' where l, m, n... are the dimensions of a multidimension
|
2007
|
+
array column in a binary table. */
|
2008
|
+
static VALUE cfits_write_tdim(VALUE self, VALUE rfits, VALUE colnum, VALUE naxis, VALUE naxes){
|
2009
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
2010
|
+
int status = 0, i;
|
2011
|
+
|
2012
|
+
int cnaxis = NUM2INT(naxis);
|
2013
|
+
|
2014
|
+
long cnaxes[cnaxis];
|
2015
|
+
for(i = 0; i < cnaxis; i++){
|
2016
|
+
cnaxes[i] = NUM2LONG(rb_ary_entry(naxes, i));
|
2017
|
+
}
|
2018
|
+
|
2019
|
+
fits_write_tdim(cfits, NUM2INT(colnum), cnaxis, cnaxes, &status);
|
2020
|
+
raise_exception_if_necessary(status);
|
2021
|
+
|
2022
|
+
return(Qnil);
|
2023
|
+
}
|
2024
|
+
|
2025
|
+
/* Insert blank rows in an ASCII or binary table. */
|
2026
|
+
static VALUE cfits_insert_rows(VALUE self, VALUE rfits, VALUE firstrow, VALUE nrows){
|
2027
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
2028
|
+
int status = 0;
|
2029
|
+
|
2030
|
+
fits_insert_rows(cfits, NUM2LONG(firstrow), NUM2LONG(nrows), &status);
|
2031
|
+
raise_exception_if_necessary(status);
|
2032
|
+
|
2033
|
+
return(Qnil);
|
2034
|
+
}
|
2035
|
+
|
2036
|
+
/* Delete rows in an ASCII or binary table. */
|
2037
|
+
static VALUE cfits_delete_rows(VALUE self, VALUE rfits, VALUE firstrow, VALUE nrows){
|
2038
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
2039
|
+
int status = 0;
|
2040
|
+
|
2041
|
+
fits_delete_rows(cfits, NUM2LONG(firstrow), NUM2LONG(nrows), &status);
|
2042
|
+
raise_exception_if_necessary(status);
|
2043
|
+
|
2044
|
+
return(Qnil);
|
2045
|
+
}
|
2046
|
+
|
2047
|
+
/* Delete rows in an ASCII or binary table using a range list. */
|
2048
|
+
static VALUE cfits_delete_rowrange(VALUE self, VALUE rfits, VALUE rangelist){
|
2049
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
2050
|
+
int status = 0;
|
2051
|
+
|
2052
|
+
fits_delete_rowrange(cfits, STR2CSTR(rangelist), &status);
|
2053
|
+
raise_exception_if_necessary(status);
|
2054
|
+
|
2055
|
+
return(Qnil);
|
2056
|
+
}
|
2057
|
+
|
2058
|
+
/* Delete rows in an ASCII or binary table using a row list. */
|
2059
|
+
static VALUE cfits_delete_rowlist(VALUE self, VALUE rfits, VALUE rowlist, VALUE nrows){
|
2060
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
2061
|
+
int status = 0, i;
|
2062
|
+
|
2063
|
+
long cnrows = NUM2LONG(nrows);
|
2064
|
+
|
2065
|
+
long crowlist[cnrows];
|
2066
|
+
for(i = 0; i < cnrows; i++){
|
2067
|
+
crowlist[i] = NUM2LONG(rb_ary_entry(rowlist, i));
|
2068
|
+
}
|
2069
|
+
|
2070
|
+
fits_delete_rowlist(cfits, crowlist, cnrows, &status);
|
2071
|
+
raise_exception_if_necessary(status);
|
2072
|
+
|
2073
|
+
return(Qnil);
|
2074
|
+
}
|
2075
|
+
|
2076
|
+
/* Insert column(s) in an ASCII or binary table. */
|
2077
|
+
static VALUE cfits_insert_cols(VALUE self, VALUE rfits, VALUE colnum, VALUE ncols, VALUE ttype, VALUE tform){
|
2078
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
2079
|
+
int status = 0, i;
|
2080
|
+
|
2081
|
+
int cncols = NUM2INT(ncols);
|
2082
|
+
|
2083
|
+
char *cttype[cncols];
|
2084
|
+
for(i = 0; i < cncols; i++){
|
2085
|
+
cttype[i] = STR2CSTR(rb_ary_entry(ttype, i));
|
2086
|
+
}
|
2087
|
+
|
2088
|
+
char *ctform[cncols];
|
2089
|
+
for(i = 0; i < cncols; i++){
|
2090
|
+
ctform[i] = STR2CSTR(rb_ary_entry(tform, i));
|
2091
|
+
}
|
2092
|
+
|
2093
|
+
fits_insert_cols(cfits, NUM2INT(colnum), cncols, cttype, ctform, &status);
|
2094
|
+
raise_exception_if_necessary(status);
|
2095
|
+
|
2096
|
+
return(Qnil);
|
2097
|
+
}
|
2098
|
+
|
2099
|
+
/* Delete column in an ASCII or binary table. */
|
2100
|
+
static VALUE cfits_delete_col(VALUE self, VALUE rfits, VALUE colnum){
|
2101
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
2102
|
+
int status = 0;
|
2103
|
+
|
2104
|
+
fits_delete_col(cfits, NUM2INT(colnum), &status);
|
2105
|
+
raise_exception_if_necessary(status);
|
2106
|
+
|
2107
|
+
return(Qnil);
|
2108
|
+
}
|
2109
|
+
|
2110
|
+
/* Copy a column from one HDU to another (or to the same HDU). */
|
2111
|
+
static VALUE cfits_copy_col(VALUE self, VALUE rinfits, VALUE routfits, VALUE incolnum, VALUE outcolnum, VALUE create_col){
|
2112
|
+
fitsfile *cinfits = RFITS2CFITS(rinfits);
|
2113
|
+
fitsfile *coutfits = RFITS2CFITS(routfits);
|
2114
|
+
int status = 0;
|
2115
|
+
|
2116
|
+
fits_copy_col(cinfits, coutfits, NUM2INT(incolnum), NUM2INT(outcolnum), NUM2INT(create_col), &status);
|
2117
|
+
raise_exception_if_necessary(status);
|
2118
|
+
|
2119
|
+
return(Qnil);
|
2120
|
+
}
|
2121
|
+
|
2122
|
+
/* Modify the vector length of a binary table column (e.g., change a column from TFORMn = '1E' to '20E'). */
|
2123
|
+
static VALUE cfits_modify_vector_len(VALUE self, VALUE rfits, VALUE colnum, VALUE newveclen){
|
2124
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
2125
|
+
int status = 0;
|
2126
|
+
|
2127
|
+
fits_modify_vector_len(cfits, NUM2INT(colnum), NUM2LONG(newveclen), &status);
|
2128
|
+
raise_exception_if_necessary(status);
|
2129
|
+
|
2130
|
+
return(Qnil);
|
2131
|
+
}
|
2132
|
+
|
2133
|
+
/* Writes the array of values to the FITS file (doing data type conversion if necessary). */
|
2134
|
+
static VALUE cfits_write_colnull(VALUE self, VALUE rfits, VALUE datatype, VALUE colnum, VALUE firstrow, VALUE firstelem, VALUE nelements, VALUE array, VALUE nulval){
|
2135
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
2136
|
+
int status = 0, i, j = 0;
|
2137
|
+
|
2138
|
+
int cdatatype = NUM2INT(datatype);
|
2139
|
+
long cnelements = NUM2LONG(nelements);
|
2140
|
+
int nulval_null = NIL_P(nulval);
|
2141
|
+
|
2142
|
+
switch(cdatatype){
|
2143
|
+
case TSTRING: {
|
2144
|
+
char *carray[cnelements];
|
2145
|
+
for(i = 0; i < cnelements; i++){
|
2146
|
+
carray[i] = STR2CSTR(rb_ary_entry(array, i));
|
2147
|
+
}
|
2148
|
+
|
2149
|
+
fits_write_colnull(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), cnelements,
|
2150
|
+
carray, nulval_null ? NULL : STR2CSTR(nulval), &status);
|
2151
|
+
break;
|
2152
|
+
}
|
2153
|
+
case TSHORT: {
|
2154
|
+
short cnulval;
|
2155
|
+
if(!nulval_null){ cnulval = (short) NUM2INT(nulval); }
|
2156
|
+
|
2157
|
+
short carray[cnelements];
|
2158
|
+
for(i = 0; i < cnelements; i++){
|
2159
|
+
carray[i] = (short) NUM2INT(rb_ary_entry(array, i));
|
2160
|
+
}
|
2161
|
+
|
2162
|
+
fits_write_colnull(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), cnelements,
|
2163
|
+
carray, nulval_null ? NULL : &cnulval, &status);
|
2164
|
+
break;
|
2165
|
+
}
|
2166
|
+
case TUSHORT: {
|
2167
|
+
unsigned short cnulval;
|
2168
|
+
if(!nulval_null){ cnulval = (unsigned short) NUM2UINT(nulval); }
|
2169
|
+
|
2170
|
+
unsigned short carray[cnelements];
|
2171
|
+
for(i = 0; i < cnelements; i++){
|
2172
|
+
carray[i] = (unsigned short) NUM2INT(rb_ary_entry(array, i));
|
2173
|
+
}
|
2174
|
+
|
2175
|
+
fits_write_colnull(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), cnelements,
|
2176
|
+
carray, nulval_null ? NULL : &cnulval, &status);
|
2177
|
+
break;
|
2178
|
+
}
|
2179
|
+
case TINT: {
|
2180
|
+
int cnulval;
|
2181
|
+
if(!nulval_null){ cnulval = NUM2INT(nulval); }
|
2182
|
+
|
2183
|
+
int carray[cnelements];
|
2184
|
+
for(i = 0; i < cnelements; i++){
|
2185
|
+
carray[i] = NUM2INT(rb_ary_entry(array, i));
|
2186
|
+
}
|
2187
|
+
|
2188
|
+
fits_write_colnull(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), cnelements,
|
2189
|
+
carray, nulval_null ? NULL : &cnulval, &status);
|
2190
|
+
break;
|
2191
|
+
}
|
2192
|
+
case TUINT: {
|
2193
|
+
unsigned int cnulval;
|
2194
|
+
if(!nulval_null){ cnulval = NUM2UINT(nulval); }
|
2195
|
+
|
2196
|
+
unsigned int carray[cnelements];
|
2197
|
+
for(i = 0; i < cnelements; i++){
|
2198
|
+
carray[i] = NUM2UINT(rb_ary_entry(array, i));
|
2199
|
+
}
|
2200
|
+
|
2201
|
+
fits_write_colnull(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), cnelements,
|
2202
|
+
carray, nulval_null ? NULL : &cnulval, &status);
|
2203
|
+
break;
|
2204
|
+
}
|
2205
|
+
case TLONG: {
|
2206
|
+
long cnulval;
|
2207
|
+
if(!nulval_null){ cnulval = NUM2LONG(nulval); }
|
2208
|
+
|
2209
|
+
long carray[cnelements];
|
2210
|
+
for(i = 0; i < cnelements; i++){
|
2211
|
+
carray[i] = NUM2LONG(rb_ary_entry(array, i));
|
2212
|
+
}
|
2213
|
+
|
2214
|
+
fits_write_colnull(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), cnelements,
|
2215
|
+
carray, nulval_null ? NULL : &cnulval, &status);
|
2216
|
+
break;
|
2217
|
+
}
|
2218
|
+
case TLONGLONG: {
|
2219
|
+
long long cnulval;
|
2220
|
+
if(!nulval_null){ cnulval = (long long) NUM2LONG(nulval); }
|
2221
|
+
|
2222
|
+
long long carray[cnelements];
|
2223
|
+
for(i = 0; i < cnelements; i++){
|
2224
|
+
carray[i] = (long long) NUM2LONG(rb_ary_entry(array, i));
|
2225
|
+
}
|
2226
|
+
|
2227
|
+
fits_write_colnull(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), cnelements,
|
2228
|
+
carray, nulval_null ? NULL : &cnulval, &status);
|
2229
|
+
break;
|
2230
|
+
}
|
2231
|
+
case TULONG: {
|
2232
|
+
unsigned long cnulval;
|
2233
|
+
if(!nulval_null){ cnulval = NUM2ULONG(nulval); }
|
2234
|
+
|
2235
|
+
unsigned long carray[cnelements];
|
2236
|
+
for(i = 0; i < cnelements; i++){
|
2237
|
+
carray[i] = NUM2ULONG(rb_ary_entry(array, i));
|
2238
|
+
}
|
2239
|
+
|
2240
|
+
fits_write_colnull(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), cnelements,
|
2241
|
+
carray, nulval_null ? NULL : &cnulval, &status);
|
2242
|
+
break;
|
2243
|
+
}
|
2244
|
+
case TFLOAT: {
|
2245
|
+
float cnulval;
|
2246
|
+
if(!nulval_null){ cnulval = (float) NUM2DBL(nulval); }
|
2247
|
+
|
2248
|
+
float carray[cnelements];
|
2249
|
+
for(i = 0; i < cnelements; i++){
|
2250
|
+
carray[i] = (float) NUM2DBL(rb_ary_entry(array, i));
|
2251
|
+
}
|
2252
|
+
|
2253
|
+
fits_write_colnull(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), cnelements,
|
2254
|
+
carray, nulval_null ? NULL : &cnulval, &status);
|
2255
|
+
break;
|
2256
|
+
}
|
2257
|
+
case TDOUBLE: {
|
2258
|
+
double cnulval;
|
2259
|
+
if(!nulval_null){ cnulval = NUM2DBL(nulval); }
|
2260
|
+
|
2261
|
+
double carray[cnelements];
|
2262
|
+
for(i = 0; i < cnelements; i++){
|
2263
|
+
carray[i] = NUM2DBL(rb_ary_entry(array, i));
|
2264
|
+
}
|
2265
|
+
|
2266
|
+
fits_write_colnull(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), cnelements,
|
2267
|
+
carray, nulval_null ? NULL : &cnulval, &status);
|
2268
|
+
break;
|
2269
|
+
}
|
2270
|
+
case TBYTE: {
|
2271
|
+
char cnulval;
|
2272
|
+
if(!nulval_null){ cnulval = NUM2CHR(nulval); }
|
2273
|
+
|
2274
|
+
char carray[cnelements];
|
2275
|
+
for(i = 0; i < cnelements; i++){
|
2276
|
+
carray[i] = NUM2CHR(rb_ary_entry(array, i));
|
2277
|
+
}
|
2278
|
+
|
2279
|
+
fits_write_colnull(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), cnelements,
|
2280
|
+
carray, nulval_null ? NULL : &cnulval, &status);
|
2281
|
+
break;
|
2282
|
+
}
|
2283
|
+
case TSBYTE: {
|
2284
|
+
char cnulval;
|
2285
|
+
if(!nulval_null){ cnulval = NUM2CHR(nulval); }
|
2286
|
+
|
2287
|
+
char carray[cnelements];
|
2288
|
+
for(i = 0; i < cnelements; i++){
|
2289
|
+
carray[i] = NUM2CHR(rb_ary_entry(array, i));
|
2290
|
+
}
|
2291
|
+
|
2292
|
+
fits_write_colnull(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), cnelements,
|
2293
|
+
carray, nulval_null ? NULL : &cnulval, &status);
|
2294
|
+
break;
|
2295
|
+
}
|
2296
|
+
case TBIT: {
|
2297
|
+
char cnulval;
|
2298
|
+
if(!nulval_null){ cnulval = NUM2CHR(nulval); }
|
2299
|
+
|
2300
|
+
char carray[cnelements];
|
2301
|
+
for(i = 0; i < cnelements; i++){
|
2302
|
+
carray[i] = NUM2CHR(rb_ary_entry(array, i));
|
2303
|
+
}
|
2304
|
+
|
2305
|
+
fits_write_colnull(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), cnelements,
|
2306
|
+
carray, nulval_null ? NULL : &cnulval, &status);
|
2307
|
+
break;
|
2308
|
+
}
|
2309
|
+
case TLOGICAL: {
|
2310
|
+
int cnulval;
|
2311
|
+
if(!nulval_null){ cnulval = TYPE(nulval) == T_TRUE ? 1 : 0; }
|
2312
|
+
|
2313
|
+
int carray[cnelements];
|
2314
|
+
for(i = 0; i < cnelements; i++){
|
2315
|
+
carray[i] = TYPE(rb_ary_entry(array, i)) == T_TRUE ? 1 : 0;
|
2316
|
+
}
|
2317
|
+
|
2318
|
+
fits_write_colnull(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), cnelements,
|
2319
|
+
carray, nulval_null ? NULL : &cnulval, &status);
|
2320
|
+
break;
|
2321
|
+
}
|
2322
|
+
case TCOMPLEX: {
|
2323
|
+
float cnulval[2];
|
2324
|
+
if(!nulval_null){
|
2325
|
+
cnulval[0] = (float) NUM2DBL(rb_funcall(nulval, rb_intern("real"), 0));
|
2326
|
+
cnulval[1] = (float) NUM2DBL(rb_funcall(nulval, rb_intern("image"), 0));
|
2327
|
+
}
|
2328
|
+
|
2329
|
+
float carray[cnelements*2];
|
2330
|
+
for(i = 0; i < cnelements; i++){
|
2331
|
+
VALUE entry = rb_ary_entry(array, i);
|
2332
|
+
carray[j] = (float) NUM2DBL(rb_funcall(entry, rb_intern("real"), 0));
|
2333
|
+
carray[j+1] = (float) NUM2DBL(rb_funcall(entry, rb_intern("image"), 0));
|
2334
|
+
j += 2;
|
2335
|
+
}
|
2336
|
+
|
2337
|
+
fits_write_colnull(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), cnelements,
|
2338
|
+
carray, nulval_null ? NULL : cnulval, &status);
|
2339
|
+
break;
|
2340
|
+
}
|
2341
|
+
case TDBLCOMPLEX: {
|
2342
|
+
double cnulval[2];
|
2343
|
+
if(!nulval_null){
|
2344
|
+
cnulval[0] = NUM2DBL(rb_funcall(nulval, rb_intern("real"), 0));
|
2345
|
+
cnulval[1] = NUM2DBL(rb_funcall(nulval, rb_intern("image"), 0));
|
2346
|
+
}
|
2347
|
+
|
2348
|
+
double carray[cnelements*2];
|
2349
|
+
for(i = 0; i < cnelements; i++){
|
2350
|
+
VALUE entry = rb_ary_entry(array, i);
|
2351
|
+
carray[j] = NUM2DBL(rb_funcall(entry, rb_intern("real"), 0));
|
2352
|
+
carray[j+1] = NUM2DBL(rb_funcall(entry, rb_intern("image"), 0));
|
2353
|
+
j += 2;
|
2354
|
+
}
|
2355
|
+
|
2356
|
+
fits_write_colnull(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), cnelements,
|
2357
|
+
carray, nulval_null ? NULL : cnulval, &status);
|
2358
|
+
break;
|
2359
|
+
}
|
2360
|
+
default: {
|
2361
|
+
double cnulval;
|
2362
|
+
if(!nulval_null){ cnulval = NUM2DBL(nulval); }
|
2363
|
+
|
2364
|
+
double carray[cnelements];
|
2365
|
+
for(i = 0; i < cnelements; i++){
|
2366
|
+
carray[i] = NUM2DBL(rb_ary_entry(array, i));
|
2367
|
+
}
|
2368
|
+
|
2369
|
+
fits_write_colnull(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), cnelements,
|
2370
|
+
carray, nulval_null ? NULL : &cnulval, &status);
|
2371
|
+
}
|
2372
|
+
}
|
2373
|
+
raise_exception_if_necessary(status);
|
2374
|
+
|
2375
|
+
return(Qnil);
|
2376
|
+
}
|
2377
|
+
|
2378
|
+
/* Read an array of values from the FITS file (doing data type conversion if necessary). */
|
2379
|
+
static VALUE cfits_read_col(VALUE self, VALUE rfits, VALUE datatype, VALUE colnum, VALUE firstrow, VALUE firstelem, VALUE nelements, VALUE nulval){
|
2380
|
+
fitsfile *cfits = RFITS2CFITS(rfits);
|
2381
|
+
int status = 0, i;
|
2382
|
+
|
2383
|
+
int cdatatype = NUM2INT(datatype);
|
2384
|
+
long cnelements = NUM2LONG(nelements);
|
2385
|
+
int nulval_null = NIL_P(nulval);
|
2386
|
+
int anynul;
|
2387
|
+
|
2388
|
+
VALUE list = rb_ary_new2(cnelements);
|
2389
|
+
switch(cdatatype){
|
2390
|
+
case TSTRING: {
|
2391
|
+
int dispwidth;
|
2392
|
+
fits_get_col_display_width(cfits, NUM2INT(colnum), &dispwidth, &status);
|
2393
|
+
|
2394
|
+
char *carray[cnelements];
|
2395
|
+
for(i = 0; i < cnelements; i++){
|
2396
|
+
carray[i] = (char *) calloc(dispwidth, sizeof(char));
|
2397
|
+
}
|
2398
|
+
|
2399
|
+
fits_read_col(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), NUM2LONG(nelements),
|
2400
|
+
nulval_null ? NULL : STR2CSTR(nulval), carray, &anynul, &status);
|
2401
|
+
|
2402
|
+
|
2403
|
+
for(i = 0; i < cnelements; i++){
|
2404
|
+
rb_ary_push(list, rb_str_new2(carray[i]));
|
2405
|
+
}
|
2406
|
+
|
2407
|
+
break;
|
2408
|
+
}
|
2409
|
+
case TBYTE: {
|
2410
|
+
char cnulval;
|
2411
|
+
if(!nulval_null){ cnulval = NUM2CHR(nulval); }
|
2412
|
+
|
2413
|
+
char carray[cnelements];
|
2414
|
+
fits_read_col(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), NUM2LONG(nelements),
|
2415
|
+
nulval_null ? NULL : &cnulval, carray, &anynul, &status);
|
2416
|
+
|
2417
|
+
for(i = 0; i < cnelements; i++){
|
2418
|
+
rb_ary_push(list, CHR2FIX(carray[i]));
|
2419
|
+
}
|
2420
|
+
|
2421
|
+
break;
|
2422
|
+
}
|
2423
|
+
case TSBYTE: {
|
2424
|
+
char cnulval;
|
2425
|
+
if(!nulval_null){ cnulval = NUM2CHR(nulval); }
|
2426
|
+
|
2427
|
+
char carray[cnelements];
|
2428
|
+
fits_read_col(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), NUM2LONG(nelements),
|
2429
|
+
nulval_null ? NULL : &cnulval, carray, &anynul, &status);
|
2430
|
+
|
2431
|
+
for(i = 0; i < cnelements; i++){
|
2432
|
+
rb_ary_push(list, CHR2FIX(carray[i]));
|
2433
|
+
}
|
2434
|
+
|
2435
|
+
break;
|
2436
|
+
}
|
2437
|
+
case TBIT: {
|
2438
|
+
char cnulval;
|
2439
|
+
if(!nulval_null){ cnulval = NUM2CHR(nulval); }
|
2440
|
+
|
2441
|
+
char carray[cnelements];
|
2442
|
+
fits_read_col(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), NUM2LONG(nelements),
|
2443
|
+
nulval_null ? NULL : &cnulval, carray, &anynul, &status);
|
2444
|
+
|
2445
|
+
for(i = 0; i < cnelements; i++){
|
2446
|
+
rb_ary_push(list, carray[i] == 1 ? Qtrue : Qfalse);
|
2447
|
+
}
|
2448
|
+
|
2449
|
+
break;
|
2450
|
+
}
|
2451
|
+
case TSHORT: {
|
2452
|
+
short cnulval;
|
2453
|
+
if(!nulval_null){ cnulval = (short) NUM2INT(nulval); }
|
2454
|
+
|
2455
|
+
short carray[cnelements];
|
2456
|
+
fits_read_col(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), NUM2LONG(nelements),
|
2457
|
+
nulval_null ? NULL : &cnulval, carray, &anynul, &status);
|
2458
|
+
|
2459
|
+
for(i = 0; i < cnelements; i++){
|
2460
|
+
rb_ary_push(list, INT2NUM(carray[i]));
|
2461
|
+
}
|
2462
|
+
|
2463
|
+
break;
|
2464
|
+
}
|
2465
|
+
case TUSHORT: {
|
2466
|
+
unsigned short cnulval;
|
2467
|
+
if(!nulval_null){ cnulval = (unsigned short) NUM2UINT(nulval); }
|
2468
|
+
|
2469
|
+
unsigned short carray[cnelements];
|
2470
|
+
fits_read_col(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), NUM2LONG(nelements),
|
2471
|
+
nulval_null ? NULL : &cnulval, carray, &anynul, &status);
|
2472
|
+
|
2473
|
+
for(i = 0; i < cnelements; i++){
|
2474
|
+
rb_ary_push(list, INT2NUM(carray[i]));
|
2475
|
+
}
|
2476
|
+
|
2477
|
+
break;
|
2478
|
+
}
|
2479
|
+
case TINT: {
|
2480
|
+
int cnulval;
|
2481
|
+
if(!nulval_null){ cnulval = NUM2INT(nulval); }
|
2482
|
+
|
2483
|
+
int carray[cnelements];
|
2484
|
+
fits_read_col(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), NUM2LONG(nelements),
|
2485
|
+
nulval_null ? NULL : &cnulval, carray, &anynul, &status);
|
2486
|
+
|
2487
|
+
for(i = 0; i < cnelements; i++){
|
2488
|
+
rb_ary_push(list, INT2NUM(carray[i]));
|
2489
|
+
}
|
2490
|
+
|
2491
|
+
break;
|
2492
|
+
}
|
2493
|
+
case TUINT: {
|
2494
|
+
unsigned int cnulval;
|
2495
|
+
if(!nulval_null){ cnulval = NUM2UINT(nulval); }
|
2496
|
+
|
2497
|
+
unsigned int carray[cnelements];
|
2498
|
+
fits_read_col(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), NUM2LONG(nelements),
|
2499
|
+
nulval_null ? NULL : &cnulval, carray, &anynul, &status);
|
2500
|
+
|
2501
|
+
for(i = 0; i < cnelements; i++){
|
2502
|
+
rb_ary_push(list, INT2NUM(carray[i]));
|
2503
|
+
}
|
2504
|
+
|
2505
|
+
break;
|
2506
|
+
}
|
2507
|
+
case TLONG: {
|
2508
|
+
long cnulval;
|
2509
|
+
if(!nulval_null){ cnulval = NUM2LONG(nulval); }
|
2510
|
+
|
2511
|
+
long carray[cnelements];
|
2512
|
+
fits_read_col(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), NUM2LONG(nelements),
|
2513
|
+
nulval_null ? NULL : &cnulval, carray, &anynul, &status);
|
2514
|
+
|
2515
|
+
for(i = 0; i < cnelements; i++){
|
2516
|
+
rb_ary_push(list, INT2NUM(carray[i]));
|
2517
|
+
}
|
2518
|
+
|
2519
|
+
break;
|
2520
|
+
}
|
2521
|
+
case TLONGLONG: {
|
2522
|
+
long long cnulval;
|
2523
|
+
if(!nulval_null){ cnulval = (long long) NUM2LONG(nulval); }
|
2524
|
+
|
2525
|
+
long long carray[cnelements];
|
2526
|
+
fits_read_col(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), NUM2LONG(nelements),
|
2527
|
+
nulval_null ? NULL : &cnulval, carray, &anynul, &status);
|
2528
|
+
|
2529
|
+
for(i = 0; i < cnelements; i++){
|
2530
|
+
rb_ary_push(list, INT2NUM(carray[i]));
|
2531
|
+
}
|
2532
|
+
|
2533
|
+
break;
|
2534
|
+
}
|
2535
|
+
case TULONG: {
|
2536
|
+
unsigned long cnulval;
|
2537
|
+
if(!nulval_null){ cnulval = NUM2ULONG(nulval); }
|
2538
|
+
|
2539
|
+
unsigned long carray[cnelements];
|
2540
|
+
fits_read_col(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), NUM2LONG(nelements),
|
2541
|
+
nulval_null ? NULL : &cnulval, carray, &anynul, &status);
|
2542
|
+
|
2543
|
+
for(i = 0; i < cnelements; i++){
|
2544
|
+
rb_ary_push(list, INT2NUM(carray[i]));
|
2545
|
+
}
|
2546
|
+
|
2547
|
+
break;
|
2548
|
+
}
|
2549
|
+
case TFLOAT: {
|
2550
|
+
float cnulval;
|
2551
|
+
if(!nulval_null){ cnulval = (float) NUM2DBL(nulval); }
|
2552
|
+
|
2553
|
+
float carray[cnelements];
|
2554
|
+
fits_read_col(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), NUM2LONG(nelements),
|
2555
|
+
nulval_null ? NULL : &cnulval, carray, &anynul, &status);
|
2556
|
+
|
2557
|
+
for(i = 0; i < cnelements; i++){
|
2558
|
+
rb_ary_push(list, rb_float_new(carray[i]));
|
2559
|
+
}
|
2560
|
+
|
2561
|
+
break;
|
2562
|
+
}
|
2563
|
+
case TDOUBLE: {
|
2564
|
+
double cnulval;
|
2565
|
+
if(!nulval_null){ cnulval = NUM2DBL(nulval); }
|
2566
|
+
|
2567
|
+
double carray[cnelements];
|
2568
|
+
fits_read_col(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), NUM2LONG(nelements),
|
2569
|
+
nulval_null ? NULL : &cnulval, carray, &anynul, &status);
|
2570
|
+
|
2571
|
+
for(i = 0; i < cnelements; i++){
|
2572
|
+
rb_ary_push(list, rb_float_new(carray[i]));
|
2573
|
+
}
|
2574
|
+
|
2575
|
+
break;
|
2576
|
+
}
|
2577
|
+
case TLOGICAL: {
|
2578
|
+
int cnulval;
|
2579
|
+
if(!nulval_null){ cnulval = TYPE(nulval) == T_TRUE ? 1 : 0 ; }
|
2580
|
+
|
2581
|
+
int carray[cnelements];
|
2582
|
+
fits_read_col(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), NUM2LONG(nelements),
|
2583
|
+
nulval_null ? NULL : &cnulval, carray, &anynul, &status);
|
2584
|
+
|
2585
|
+
for(i = 0; i < cnelements; i++){
|
2586
|
+
rb_ary_push(list, carray[i] == 1 ? Qtrue : Qfalse);
|
2587
|
+
}
|
2588
|
+
|
2589
|
+
break;
|
2590
|
+
}
|
2591
|
+
case TCOMPLEX: {
|
2592
|
+
float cnulval[2];
|
2593
|
+
if(!nulval_null){
|
2594
|
+
cnulval[0] = (float) NUM2DBL(rb_funcall(nulval, rb_intern("real"), 0));
|
2595
|
+
cnulval[1] = (float) NUM2DBL(rb_funcall(nulval, rb_intern("image"), 0));
|
2596
|
+
}
|
2597
|
+
|
2598
|
+
float carray[cnelements*2];
|
2599
|
+
fits_read_col(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), NUM2LONG(nelements),
|
2600
|
+
nulval_null ? NULL : cnulval, carray, &anynul, &status);
|
2601
|
+
|
2602
|
+
for(i = 0; i < cnelements*2; i+=2){
|
2603
|
+
VALUE cmp = rb_funcall(
|
2604
|
+
rb_const_get(rb_cObject, rb_intern("Complex")),
|
2605
|
+
rb_intern("new"),
|
2606
|
+
2,
|
2607
|
+
rb_float_new(carray[i]), rb_float_new(carray[i+1]));
|
2608
|
+
rb_ary_push(list, cmp);
|
2609
|
+
}
|
2610
|
+
|
2611
|
+
break;
|
2612
|
+
}
|
2613
|
+
case TDBLCOMPLEX: {
|
2614
|
+
double cnulval[2];
|
2615
|
+
if(!nulval_null){
|
2616
|
+
cnulval[0] = NUM2DBL(rb_funcall(nulval, rb_intern("real"), 0));
|
2617
|
+
cnulval[1] = NUM2DBL(rb_funcall(nulval, rb_intern("image"), 0));
|
2618
|
+
}
|
2619
|
+
|
2620
|
+
double carray[cnelements*2];
|
2621
|
+
fits_read_col(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), NUM2LONG(nelements),
|
2622
|
+
nulval_null ? NULL : cnulval, carray, &anynul, &status);
|
2623
|
+
|
2624
|
+
for(i = 0; i < cnelements*2; i+=2){
|
2625
|
+
VALUE cmp = rb_funcall(
|
2626
|
+
rb_const_get(rb_cObject, rb_intern("Complex")),
|
2627
|
+
rb_intern("new"),
|
2628
|
+
2,
|
2629
|
+
rb_float_new(carray[i]), rb_float_new(carray[i+1]));
|
2630
|
+
rb_ary_push(list, cmp);
|
2631
|
+
}
|
2632
|
+
|
2633
|
+
break;
|
2634
|
+
}
|
2635
|
+
default: {
|
2636
|
+
double cnulval;
|
2637
|
+
if(!nulval_null){ cnulval = NUM2DBL(nulval); }
|
2638
|
+
|
2639
|
+
double carray[cnelements];
|
2640
|
+
fits_read_col(cfits, cdatatype, NUM2INT(colnum), NUM2LONG(firstrow), NUM2LONG(firstelem), NUM2LONG(nelements),
|
2641
|
+
nulval_null ? NULL : &cnulval, carray, &anynul, &status);
|
2642
|
+
|
2643
|
+
for(i = 0; i < cnelements; i++){
|
2644
|
+
rb_ary_push(list, rb_float_new(carray[i]));
|
2645
|
+
}
|
2646
|
+
|
2647
|
+
break;
|
2648
|
+
}
|
2649
|
+
}
|
2650
|
+
raise_exception_if_necessary(status);
|
2651
|
+
|
2652
|
+
return(rb_ary_new3(2, list, INT2NUM(anynul)));
|
2653
|
+
}
|
2654
|
+
|
2655
|
+
void Init_rfitsio(void){
|
2656
|
+
rb_require("complex");
|
2657
|
+
|
2658
|
+
/* A thin wrapper around the CFITSIO library (http://heasarc.gsfc.nasa.gov/docs/software/fitsio/fitsio.html) of routines. */
|
2659
|
+
rb_mRFits = rb_define_module("RFits");
|
2660
|
+
rb_mRFitsIO = rb_define_module_under(rb_mRFits, "IO");
|
2661
|
+
|
2662
|
+
/* Thrown whenever CFITSIO claims an error has occurred. */
|
2663
|
+
rb_cException = rb_define_class_under(rb_mRFitsIO, "Exception", rb_eRuntimeError);
|
2664
|
+
|
2665
|
+
/* A namespace encapsulating a subset of CFITSIO's routines. */
|
2666
|
+
rb_cProxy = rb_define_class_under(rb_mRFitsIO, "Proxy", rb_cObject);
|
2667
|
+
|
2668
|
+
rb_define_const(rb_cProxy, "READONLY", INT2NUM(READONLY));
|
2669
|
+
rb_define_const(rb_cProxy, "READWRITE", INT2NUM(READWRITE));
|
2670
|
+
|
2671
|
+
rb_define_singleton_method(rb_cProxy, "fits_open_file", cfits_open_file, 2);
|
2672
|
+
rb_define_singleton_method(rb_cProxy, "fits_create_file", cfits_create_file, 1);
|
2673
|
+
rb_define_singleton_method(rb_cProxy, "fits_close_file", cfits_close_file, 1);
|
2674
|
+
rb_define_singleton_method(rb_cProxy, "fits_delete_file", cfits_delete_file, 1);
|
2675
|
+
rb_define_singleton_method(rb_cProxy, "fits_file_name", cfits_file_name, 1);
|
2676
|
+
rb_define_singleton_method(rb_cProxy, "fits_file_mode", cfits_file_mode, 1);
|
2677
|
+
rb_define_singleton_method(rb_cProxy, "fits_url_type", cfits_url_type, 1);
|
2678
|
+
|
2679
|
+
rb_define_const(rb_cProxy, "IMAGE_HDU", INT2NUM(IMAGE_HDU));
|
2680
|
+
rb_define_const(rb_cProxy, "ASCII_TBL", INT2NUM(ASCII_TBL));
|
2681
|
+
rb_define_const(rb_cProxy, "BINARY_TBL", INT2NUM(BINARY_TBL));
|
2682
|
+
rb_define_const(rb_cProxy, "ANY_HDU", INT2NUM(ANY_HDU));
|
2683
|
+
|
2684
|
+
rb_define_singleton_method(rb_cProxy, "fits_movabs_hdu", cfits_movabs_hdu, 2);
|
2685
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_num_hdus", cfits_get_num_hdus, 1);
|
2686
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_hdu_num", cfits_get_hdu_num, 1);
|
2687
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_hdu_type", cfits_get_hdu_type, 1);
|
2688
|
+
rb_define_singleton_method(rb_cProxy, "fits_copy_file", cfits_copy_file, 5);
|
2689
|
+
rb_define_singleton_method(rb_cProxy, "fits_copy_hdu", cfits_copy_hdu, 3);
|
2690
|
+
rb_define_singleton_method(rb_cProxy, "fits_copy_header", cfits_copy_header, 2);
|
2691
|
+
rb_define_singleton_method(rb_cProxy, "fits_create_hdu", cfits_create_hdu, 1);
|
2692
|
+
rb_define_singleton_method(rb_cProxy, "fits_delete_hdu", cfits_delete_hdu, 1);
|
2693
|
+
|
2694
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_hdrspace", cfits_get_hdrspace, 1);
|
2695
|
+
rb_define_singleton_method(rb_cProxy, "fits_write_grphdr", cfits_write_grphdr, 8);
|
2696
|
+
rb_define_singleton_method(rb_cProxy, "fits_read_key", cfits_read_key, 3);
|
2697
|
+
rb_define_singleton_method(rb_cProxy, "fits_read_keyword", cfits_read_keyword, 2);
|
2698
|
+
rb_define_singleton_method(rb_cProxy, "fits_hdr2str", cfits_hdr2str, 4);
|
2699
|
+
rb_define_singleton_method(rb_cProxy, "fits_read_keyn", cfits_read_keyn, 2);
|
2700
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_keytype", cfits_get_keytype, 1);
|
2701
|
+
rb_define_singleton_method(rb_cProxy, "fits_write_comment", cfits_write_comment, 2);
|
2702
|
+
rb_define_singleton_method(rb_cProxy, "fits_write_history", cfits_write_history, 2);
|
2703
|
+
|
2704
|
+
rb_define_singleton_method(rb_cProxy, "fits_update_key", cfits_update_key, 5);
|
2705
|
+
rb_define_singleton_method(rb_cProxy, "fits_update_key_null", cfits_update_key_null, 3);
|
2706
|
+
rb_define_singleton_method(rb_cProxy, "fits_delete_key", cfits_delete_key, 2);
|
2707
|
+
|
2708
|
+
rb_define_const(rb_cProxy, "BYTE_IMG", INT2NUM(BYTE_IMG));
|
2709
|
+
rb_define_const(rb_cProxy, "SHORT_IMG", INT2NUM(SHORT_IMG));
|
2710
|
+
rb_define_const(rb_cProxy, "LONG_IMG", INT2NUM(LONG_IMG));
|
2711
|
+
rb_define_const(rb_cProxy, "LONGLONG_IMG", INT2NUM(LONGLONG_IMG));
|
2712
|
+
rb_define_const(rb_cProxy, "FLOAT_IMG", INT2NUM(FLOAT_IMG));
|
2713
|
+
rb_define_const(rb_cProxy, "DOUBLE_IMG", INT2NUM(DOUBLE_IMG));
|
2714
|
+
rb_define_const(rb_cProxy, "SBYTE_IMG", INT2NUM(SBYTE_IMG));
|
2715
|
+
rb_define_const(rb_cProxy, "USHORT_IMG", INT2NUM(USHORT_IMG));
|
2716
|
+
rb_define_const(rb_cProxy, "ULONG_IMG", INT2NUM(ULONG_IMG));
|
2717
|
+
|
2718
|
+
rb_define_const(rb_cProxy, "TSTRING", INT2NUM(TSTRING));
|
2719
|
+
rb_define_const(rb_cProxy, "TBIT", INT2NUM(TBIT));
|
2720
|
+
rb_define_const(rb_cProxy, "TLOGICAL", INT2NUM(TLOGICAL));
|
2721
|
+
rb_define_const(rb_cProxy, "TBYTE", INT2NUM(TBYTE));
|
2722
|
+
rb_define_const(rb_cProxy, "TSBYTE", INT2NUM(TSBYTE));
|
2723
|
+
rb_define_const(rb_cProxy, "TSHORT", INT2NUM(TSHORT));
|
2724
|
+
rb_define_const(rb_cProxy, "TUSHORT", INT2NUM(TUSHORT));
|
2725
|
+
rb_define_const(rb_cProxy, "TINT", INT2NUM(TINT));
|
2726
|
+
rb_define_const(rb_cProxy, "TUINT", INT2NUM(TUINT));
|
2727
|
+
rb_define_const(rb_cProxy, "TLONG", INT2NUM(TLONG));
|
2728
|
+
rb_define_const(rb_cProxy, "TLONGLONG", INT2NUM(TLONGLONG));
|
2729
|
+
rb_define_const(rb_cProxy, "TULONG", INT2NUM(TULONG));
|
2730
|
+
rb_define_const(rb_cProxy, "TFLOAT", INT2NUM(TFLOAT));
|
2731
|
+
rb_define_const(rb_cProxy, "TDOUBLE", INT2NUM(TDOUBLE));
|
2732
|
+
rb_define_const(rb_cProxy, "TCOMPLEX", INT2NUM(TCOMPLEX));
|
2733
|
+
rb_define_const(rb_cProxy, "TDBLCOMPLEX", INT2NUM(TDBLCOMPLEX));
|
2734
|
+
|
2735
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_img_type", cfits_get_img_type, 1);
|
2736
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_img_equivtype", cfits_get_img_equivtype, 1);
|
2737
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_img_dim", cfits_get_img_dim, 1);
|
2738
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_img_size", cfits_get_img_size, 2);
|
2739
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_img_param", cfits_get_img_param, 2);
|
2740
|
+
rb_define_singleton_method(rb_cProxy, "fits_insert_img", cfits_insert_img, 4);
|
2741
|
+
rb_define_singleton_method(rb_cProxy, "fits_create_img", cfits_create_img, 4);
|
2742
|
+
rb_define_singleton_method(rb_cProxy, "fits_resize_img", cfits_resize_img, 4);
|
2743
|
+
rb_define_singleton_method(rb_cProxy, "fits_copy_cell2image", cfits_copy_cell2image, 4);
|
2744
|
+
rb_define_singleton_method(rb_cProxy, "fits_copy_image2cell", cfits_copy_image2cell, 5);
|
2745
|
+
rb_define_singleton_method(rb_cProxy, "fits_read_img", cfits_read_img, 5);
|
2746
|
+
rb_define_singleton_method(rb_cProxy, "fits_write_img", cfits_write_img, 5);
|
2747
|
+
rb_define_singleton_method(rb_cProxy, "fits_read_subset", cfits_read_subset, 6);
|
2748
|
+
rb_define_singleton_method(rb_cProxy, "fits_write_subset", cfits_write_subset, 5);
|
2749
|
+
rb_define_singleton_method(rb_cProxy, "fits_read_pix", cfits_read_pix, 5);
|
2750
|
+
rb_define_singleton_method(rb_cProxy, "fits_write_pixnull", cfits_write_pixnull, 6);
|
2751
|
+
rb_define_singleton_method(rb_cProxy, "fits_write_null_img", cfits_write_null_img, 3);
|
2752
|
+
|
2753
|
+
rb_define_const(rb_cProxy, "RICE_1", INT2NUM(RICE_1));
|
2754
|
+
rb_define_const(rb_cProxy, "GZIP_1", INT2NUM(GZIP_1));
|
2755
|
+
rb_define_const(rb_cProxy, "PLIO_1", INT2NUM(PLIO_1));
|
2756
|
+
rb_define_const(rb_cProxy, "HCOMPRESS_1", INT2NUM(HCOMPRESS_1));
|
2757
|
+
|
2758
|
+
rb_define_singleton_method(rb_cProxy, "fits_set_compression_type", cfits_set_compression_type, 2);
|
2759
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_compression_type", cfits_get_compression_type, 1);
|
2760
|
+
rb_define_singleton_method(rb_cProxy, "fits_set_tile_dim", cfits_set_tile_dim, 3);
|
2761
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_tile_dim", cfits_get_tile_dim, 2);
|
2762
|
+
rb_define_singleton_method(rb_cProxy, "fits_set_noise_bits", cfits_set_noise_bits, 2);
|
2763
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_noise_bits", cfits_get_noise_bits, 1);
|
2764
|
+
rb_define_singleton_method(rb_cProxy, "fits_set_hcomp_scale", cfits_set_hcomp_scale, 2);
|
2765
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_hcomp_scale", cfits_get_hcomp_scale, 1);
|
2766
|
+
rb_define_singleton_method(rb_cProxy, "fits_set_hcomp_smooth", cfits_set_hcomp_smooth, 2);
|
2767
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_hcomp_smooth", cfits_get_hcomp_smooth, 1);
|
2768
|
+
rb_define_singleton_method(rb_cProxy, "fits_img_compress", cfits_img_compress, 2);
|
2769
|
+
rb_define_singleton_method(rb_cProxy, "fits_img_decompress", cfits_img_decompress, 2);
|
2770
|
+
rb_define_singleton_method(rb_cProxy, "fits_is_compressed_image", cfits_is_compressed_image, 1);
|
2771
|
+
|
2772
|
+
rb_define_const(rb_cProxy, "CASESEN", INT2NUM(CASESEN));
|
2773
|
+
rb_define_const(rb_cProxy, "CASEINSEN", INT2NUM(CASEINSEN));
|
2774
|
+
|
2775
|
+
rb_define_singleton_method(rb_cProxy, "fits_create_tbl", cfits_create_tbl, 8);
|
2776
|
+
rb_define_singleton_method(rb_cProxy, "fits_insert_atbl", cfits_insert_atbl, 9);
|
2777
|
+
rb_define_singleton_method(rb_cProxy, "fits_insert_btbl", cfits_insert_btbl, 8);
|
2778
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_num_rows", cfits_get_num_rows, 1);
|
2779
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_num_cols", cfits_get_num_cols, 1);
|
2780
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_colnum", cfits_get_colnum, 3);
|
2781
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_colname", cfits_get_colname, 3);
|
2782
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_coltype", cfits_get_coltype, 2);
|
2783
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_eqcoltype", cfits_get_eqcoltype, 2);
|
2784
|
+
rb_define_singleton_method(rb_cProxy, "fits_get_col_display_width", cfits_get_col_display_width, 2);
|
2785
|
+
rb_define_singleton_method(rb_cProxy, "fits_read_tdim", cfits_read_tdim, 3);
|
2786
|
+
rb_define_singleton_method(rb_cProxy, "fits_write_tdim", cfits_write_tdim, 4);
|
2787
|
+
rb_define_singleton_method(rb_cProxy, "fits_insert_rows", cfits_insert_rows, 3);
|
2788
|
+
rb_define_singleton_method(rb_cProxy, "fits_delete_rows", cfits_delete_rows, 3);
|
2789
|
+
rb_define_singleton_method(rb_cProxy, "fits_delete_rowrange", cfits_delete_rowrange, 2);
|
2790
|
+
rb_define_singleton_method(rb_cProxy, "fits_delete_rowlist", cfits_delete_rowlist, 3);
|
2791
|
+
rb_define_singleton_method(rb_cProxy, "fits_insert_cols", cfits_insert_cols, 5);
|
2792
|
+
rb_define_singleton_method(rb_cProxy, "fits_delete_col", cfits_delete_col, 2);
|
2793
|
+
rb_define_singleton_method(rb_cProxy, "fits_copy_col", cfits_copy_col, 5);
|
2794
|
+
rb_define_singleton_method(rb_cProxy, "fits_modify_vector_len", cfits_modify_vector_len, 3);
|
2795
|
+
rb_define_singleton_method(rb_cProxy, "fits_write_colnull", cfits_write_colnull, 8);
|
2796
|
+
rb_define_singleton_method(rb_cProxy, "fits_read_col", cfits_read_col, 7);
|
2797
|
+
}
|