@@ -66,7 +66,6 @@ func (hdu *ImageHDU) Data(data interface{}) error {
66
66
67
67
// load loads the image data associated with this HDU into v.
68
68
func (hdu * ImageHDU ) load (v reflect.Value ) error {
69
- var err error
70
69
hdr := hdu .Header ()
71
70
naxes := len (hdr .Axes ())
72
71
if naxes == 0 {
@@ -76,78 +75,65 @@ func (hdu *ImageHDU) load(v reflect.Value) error {
76
75
for _ , dim := range hdr .Axes () {
77
76
nelmts *= int (dim )
78
77
}
79
- rv := reflect .MakeSlice (v .Type (), nelmts , nelmts )
78
+ if v .Len () != nelmts {
79
+ return fmt .Errorf ("cfitsio: slice length [%v] is not as expected [%v]" , v .Len (), nelmts )
80
+ }
80
81
81
82
c_start := C .LONGLONG (0 )
82
83
c_nelmts := C .LONGLONG (nelmts )
83
- c_anynull := C .int (0 )
84
84
c_status := C .int (0 )
85
85
c_imgtype := C .int (0 )
86
86
var c_ptr unsafe.Pointer
87
- switch rv .Interface ().(type ) {
87
+ switch data := v .Interface ().(type ) {
88
88
case []byte :
89
89
c_imgtype = C .TBYTE
90
- data := rv .Interface ().([]byte )
91
90
c_ptr = unsafe .Pointer (& data [0 ])
92
91
93
92
case []int8 :
94
93
c_imgtype = C .TBYTE
95
- data := rv .Interface ().([]int8 )
96
94
c_ptr = unsafe .Pointer (& data [0 ])
97
95
98
96
case []int16 :
99
97
c_imgtype = C .TSHORT
100
- data := rv .Interface ().([]int16 )
101
98
c_ptr = unsafe .Pointer (& data [0 ])
102
99
103
100
case []uint16 :
104
101
c_imgtype = C .TUSHORT
105
- data := rv .Interface ().([]uint16 )
106
102
c_ptr = unsafe .Pointer (& data [0 ])
107
103
108
104
case []int32 :
109
105
c_imgtype = C .TINT
110
- data := rv .Interface ().([]int32 )
111
106
c_ptr = unsafe .Pointer (& data [0 ])
112
107
113
108
case []uint32 :
114
109
c_imgtype = C .TUINT
115
- data := rv .Interface ().([]uint32 )
116
110
c_ptr = unsafe .Pointer (& data [0 ])
117
111
118
112
case []int64 :
119
113
c_imgtype = C .TLONGLONG
120
- data := rv .Interface ().([]int64 )
121
114
c_ptr = unsafe .Pointer (& data [0 ])
122
115
123
116
case []uint64 :
124
117
c_imgtype = C .TULONGLONG
125
- data := rv .Interface ().([]uint64 )
126
118
c_ptr = unsafe .Pointer (& data [0 ])
127
119
128
120
case []float32 :
129
121
c_imgtype = C .TFLOAT
130
- data := rv .Interface ().([]float32 )
131
122
c_ptr = unsafe .Pointer (& data [0 ])
132
123
133
124
case []float64 :
134
125
c_imgtype = C .TDOUBLE
135
- data := rv .Interface ().([]float64 )
136
126
c_ptr = unsafe .Pointer (& data [0 ])
137
127
138
128
default :
139
- panic (fmt .Errorf ("invalid image type [%T]" , rv .Interface ()))
129
+ panic (fmt .Errorf ("invalid image type [%T]" , v .Interface ()))
140
130
}
141
- C .fits_read_img (hdu .f .c , c_imgtype , c_start + 1 , c_nelmts , c_ptr , c_ptr , & c_anynull , & c_status )
131
+ C .fits_read_img (hdu .f .c , c_imgtype , c_start + 1 , c_nelmts , nil , c_ptr , nil , & c_status )
142
132
if c_status > 0 {
143
133
return to_err (c_status )
144
134
}
145
135
146
- n := reflect .Copy (v , rv )
147
- if n != nelmts {
148
- err = fmt .Errorf ("cfitsio: copied [%v] elements. expected [%v]" , n , nelmts )
149
- }
150
- return err
136
+ return nil
151
137
}
152
138
153
139
// Write writes the image to disk
@@ -175,55 +161,45 @@ func (hdu *ImageHDU) Write(data interface{}) error {
175
161
c_imgtype := C .int (0 )
176
162
var c_ptr unsafe.Pointer
177
163
178
- switch rv .Interface ().(type ) {
164
+ switch data := rv .Interface ().(type ) {
179
165
case []byte :
180
166
c_imgtype = C .TBYTE
181
- data := rv .Interface ().([]byte )
182
167
c_ptr = unsafe .Pointer (& data [0 ])
183
168
184
169
case []int8 :
185
170
c_imgtype = C .TBYTE
186
- data := rv .Interface ().([]int8 )
187
171
c_ptr = unsafe .Pointer (& data [0 ])
188
172
189
173
case []int16 :
190
174
c_imgtype = C .TSHORT
191
- data := rv .Interface ().([]int16 )
192
175
c_ptr = unsafe .Pointer (& data [0 ])
193
176
194
177
case []uint16 :
195
178
c_imgtype = C .TUSHORT
196
- data := rv .Interface ().([]uint16 )
197
179
c_ptr = unsafe .Pointer (& data [0 ])
198
180
199
181
case []int32 :
200
182
c_imgtype = C .TINT
201
- data := rv .Interface ().([]int32 )
202
183
c_ptr = unsafe .Pointer (& data [0 ])
203
184
204
185
case []uint32 :
205
186
c_imgtype = C .TUINT
206
- data := rv .Interface ().([]uint32 )
207
187
c_ptr = unsafe .Pointer (& data [0 ])
208
188
209
189
case []int64 :
210
190
c_imgtype = C .TLONGLONG
211
- data := rv .Interface ().([]int64 )
212
191
c_ptr = unsafe .Pointer (& data [0 ])
213
192
214
193
case []uint64 :
215
194
c_imgtype = C .TULONGLONG
216
- data := rv .Interface ().([]uint64 )
217
195
c_ptr = unsafe .Pointer (& data [0 ])
218
196
219
197
case []float32 :
220
198
c_imgtype = C .TFLOAT
221
- data := rv .Interface ().([]float32 )
222
199
c_ptr = unsafe .Pointer (& data [0 ])
223
200
224
201
case []float64 :
225
202
c_imgtype = C .TDOUBLE
226
- data := rv .Interface ().([]float64 )
227
203
c_ptr = unsafe .Pointer (& data [0 ])
228
204
229
205
default :
0 commit comments