-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathutils.go
909 lines (811 loc) · 19.5 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
// Copyright 2015 The astrogo Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package fitsio
import (
"bytes"
"fmt"
"math/big"
"reflect"
"strconv"
"strings"
)
// var (
// g_debug = false
// )
// func printf(format string, args ...interface{}) (int, error) {
// if g_debug {
// return fmt.Printf(format, args...)
// }
// return 0, nil
// }
// alignBlock returns a size adjusted to align at a FITS block size
func alignBlock(sz int) int {
padding := padBlock(sz)
return sz + padding
}
// padBlock returns the amount of padding to align to a FITS block size
func padBlock(sz int) int {
padding := (blockSize - (sz % blockSize)) % blockSize
return padding
}
// processString is utilized by DecodeHDU to process string-type values in the header
// it uses a 3-state machine to process double single quotes
func processString(s string) (string, int, error) {
var buf bytes.Buffer
state := 0
for i, char := range s {
quote := (char == '\'')
switch state {
case 0:
if !quote {
return "", i, fmt.Errorf("fitsio: string does not start with a quote (%q)", s)
}
state = 1
case 1:
if quote {
state = 2
} else {
buf.WriteRune(char)
state = 1
}
case 2:
if quote {
buf.WriteRune(char)
state = 1
} else {
return strings.TrimRight(buf.String(), " "), i, nil
}
}
}
if s[len(s)-1] == '\'' {
return strings.TrimRight(buf.String(), " "), len(s), nil
}
return "", 0, fmt.Errorf("fitsio: string ends prematurely (%q)", s)
}
// parseHeaderLine parses a 80-byte line from an input header FITS block.
// transliteration of CFITSIO's ffpsvc.
func parseHeaderLine(bline []byte) (*Card, error) {
var err error
var card Card
valpos := 0
keybeg := 0
keyend := 0
const (
kLINE = 80
)
var (
kHIERARCH = []byte("HIERARCH ")
kCOMMENT = []byte("COMMENT ")
kCONTINUE = []byte("CONTINUE")
kHISTORY = []byte("HISTORY ")
kEND = []byte("END ")
kEMPTY = []byte(" ")
)
if len(bline) != kLINE {
return nil, fmt.Errorf("fitsio: invalid header line length")
}
// support for ESO HIERARCH keywords: find the '='
if bytes.HasPrefix(bline, kHIERARCH) {
idx := bytes.Index(bline, []byte("="))
if idx < 0 {
// no value indicator
card.Comment = strings.TrimRight(string(bline[8:]), " ")
return &card, nil
}
valpos = idx + 1 // point after '='
keybeg = len(kHIERARCH)
keyend = idx
} else if len(bline) < 9 ||
bytes.HasPrefix(bline, kCOMMENT) ||
bytes.HasPrefix(bline, kCONTINUE) ||
bytes.HasPrefix(bline, kHISTORY) ||
bytes.HasPrefix(bline, kEND) ||
bytes.HasPrefix(bline, kEMPTY) ||
!bytes.HasPrefix(bline[8:], []byte("= ")) { // no '= ' in cols 9-10
// no value, so the comment extends from cols 9 - 80
card.Comment = strings.TrimRight(string(bline[8:]), " ")
if bytes.HasPrefix(bline, kCOMMENT) {
card.Name = "COMMENT"
} else if bytes.HasPrefix(bline, kCONTINUE) {
card.Name = "CONTINUE"
str := strings.TrimSpace(string(bline[len(kCONTINUE):]))
value, _, err := processString(str)
if err != nil {
return nil, err
}
card.Comment = value
return &card, nil
} else if bytes.HasPrefix(bline, kHISTORY) {
card.Name = "HISTORY"
} else if bytes.HasPrefix(bline, kEND) {
card.Name = "END"
} else if bytes.HasPrefix(bline, kEMPTY) ||
!bytes.HasPrefix(bline[8:], []byte("= ")) {
card.Name = ""
}
return &card, nil
} else {
valpos = 10
keybeg = 0
keyend = 8
}
card.Name = strings.TrimSpace(string(bline[keybeg:keyend]))
// find number of leading blanks
nblanks := 0
for _, c := range bline[valpos:] {
if c != ' ' {
break
}
nblanks += 1
}
if nblanks+valpos == len(bline) {
// the absence of a value string is legal and simply indicates
// that the keyword value is undefined.
// don't write an error message in this case
return &card, nil
}
i := valpos + nblanks
switch bline[i] {
case '/': // start of the comment
i += 1
case '\'': // quoted string value ?
str, idx, err := processString(string(bline[i:]))
if err != nil {
return nil, err
}
switch {
case len(str) <= 69: // don't exceed 70-char null-terminated string length
card.Value = str
case len(str) > 69:
card.Value = str[:70]
}
i += idx
case '(': // a complex value
idx := bytes.IndexByte(bline[i:], ')')
if idx < 0 {
return nil, fmt.Errorf("fitsio: complex keyword missing closing ')' (%q)", string(bline))
}
var x, y float64
str := strings.TrimSpace(string(bline[i : i+idx+1]))
_, err = fmt.Sscanf(str, "(%f,%f)", &x, &y)
if err != nil {
return nil, err
}
card.Value = complex(x, y)
i += idx + 1
default: // integer, float or logical FITS value string
v0 := bline[i]
value := ""
// find the end of the token
if valend := bytes.Index(bline[i:], []byte(" /")); valend < 0 {
value = string(bline[i:])
} else {
value = string(bline[i : i+valend])
}
i += len(value)
if (v0 >= '0' && v0 <= '9') || v0 == '+' || v0 == '-' {
value = strings.TrimSpace(value)
if strings.ContainsAny(value, ".DE") {
value = strings.Replace(value, "D", "E", 1) // converts D type floats to E type
x, err := strconv.ParseFloat(value, 64)
if err != nil {
return nil, err
}
card.Value = x
} else {
x, err := strconv.ParseInt(value, 10, 64)
if err != nil {
switch err := err.(type) {
case *strconv.NumError:
// try math/big.Int
if err.Err == strconv.ErrRange {
var x big.Int
_, err := fmt.Sscanf(value, "%v", &x)
if err != nil {
return nil, err
}
card.Value = x
}
default:
return nil, err
}
} else {
card.Value = int(x)
}
}
} else if v0 == 'T' {
card.Value = true
} else if v0 == 'F' {
card.Value = false
} else {
return nil, fmt.Errorf("fitsio: invalid card line (%q)", string(bline))
}
}
idx := bytes.IndexByte(bline[i:], '/')
if idx < 0 {
// no comment
return &card, err
}
com := bline[i+idx+1:]
card.Comment = strings.TrimSpace(string(com))
return &card, err
}
// makeHeaderLine makes a 80-byte line (or more) for a header FITS block from a Card.
// transliterated from CFITSIO's ffmkky.
func makeHeaderLine(card *Card) ([]byte, error) {
var err error
const kLINE = 80
var (
kCONTINUE = []byte("CONTINUE")
)
buf := new(bytes.Buffer)
buf.Grow(kLINE)
if card == nil {
return nil, fmt.Errorf("fitsio: nil Card")
}
switch card.Name {
case "", "COMMENT", "HISTORY":
str := card.Comment
vlen := len(str)
for i := 0; i < vlen; i += 72 {
end := i + 72
if end > vlen {
end = vlen
}
_, err = fmt.Fprintf(buf, "%-8s%-72s", card.Name, str[i:end])
if err != nil {
return nil, err
}
}
return buf.Bytes(), err
case "END":
_, err = fmt.Fprintf(buf, "%-80s", "END")
if err != nil {
return nil, err
}
return buf.Bytes(), err
}
klen := len(card.Name)
if klen <= 8 && verifyCardName(card) == nil {
// a normal FITS keyword
_, err = fmt.Fprintf(buf, "%-8s= ", card.Name)
if err != nil {
return nil, err
}
klen = 10
} else {
// use the ESO HIERARCH convention for longer keyword names
if strings.Contains(card.Name, "=") {
return nil, fmt.Errorf(
"fitsio: illegal keyword name. contains an equal sign [%s]",
card.Name,
)
}
key := card.Name
// dont repeat HIERARCH if the keyword already contains it
if !strings.HasPrefix(card.Name, "HIERARCH ") &&
!strings.HasPrefix(card.Name, "hierarch ") {
key = "HIERARCH " + card.Name
}
n, err := fmt.Fprintf(buf, "%s= ", key)
if err != nil {
return nil, err
}
klen = n
}
if card.Value == nil {
// this case applies to normal keywords only
if klen == 10 {
// keywords with no value have no '='
buf.Bytes()[8] = ' '
if card.Comment != "" {
comment := " / " + card.Comment
max := len(comment)
if max > kLINE-klen {
max = kLINE - klen
}
_, err = fmt.Fprintf(buf, "%s", comment[:max])
if err != nil {
return nil, err
}
}
}
} else {
buflen := buf.Len()
//valstr := ""
n := 0
switch v := card.Value.(type) {
case string:
vstr := "''"
if v != "" {
vstr = fmt.Sprintf("'%-8s'", v)
}
if len(vstr) < kLINE-buflen {
n, err = fmt.Fprintf(buf, "%-20s", vstr)
if err != nil {
return nil, fmt.Errorf("fitsio: error writing card value [%s]: %v", card.Name, err)
}
} else {
// string too long.
// use CONTINUE blocks.
// replace last character of string with '&'
ampersand := len("&")
quotes := len("''")
spacesz := len(" ")
sz := kLINE - buflen - ampersand - quotes
vstr = fmt.Sprintf("'%-8s'", v[:sz]+"&")
n, err = fmt.Fprintf(buf, "%-20s", vstr)
if err != nil {
return nil, fmt.Errorf("fitsio: error writing card value [%s]: %v", card.Name, err)
}
contlen := len(kCONTINUE)
blocksz := kLINE - contlen - ampersand - quotes - spacesz
for i := sz; i < len(v); i += blocksz {
end := i + blocksz
amper := "&"
if end > len(v) {
end = len(v)
amper = ""
}
vv := v[i:end]
vstr := fmt.Sprintf("'%-8s'", vv+amper)
n, err = fmt.Fprintf(buf, "%s %-20s", string(kCONTINUE), vstr)
if err != nil {
return nil, fmt.Errorf("fitsio: error writing card value [%s]: %v", card.Name, err)
}
}
// fill buffer up to 80-byte mark so any remaining comment
// will have to be handled by a separate 'COMMENT' line
n = buf.Len()
align80 := (kLINE - (n % kLINE)) % kLINE
if align80 > 0 {
_, err = buf.Write(bytes.Repeat([]byte(" "), align80))
if err != nil {
return nil, err
}
}
n = 0
buflen = buf.Len() % kLINE
}
case bool:
vv := "F"
if v {
vv = "T"
}
n, err = fmt.Fprintf(buf, "%20s", vv)
if err != nil {
return nil, fmt.Errorf("fitsio: error writing card value [%s]: %v", card.Name, err)
}
case int:
n, err = fmt.Fprintf(buf, "%20d", v)
if err != nil {
return nil, fmt.Errorf("fitsio: error writing card value [%s]: %v", card.Name, err)
}
case float64:
n, err = fmt.Fprintf(buf, "%#20G", v)
if err != nil {
return nil, fmt.Errorf("fitsio: error writing card value [%s]: %v", card.Name, err)
}
case complex128:
n, err = fmt.Fprintf(buf, "(%10f,%10f)", real(v), imag(v))
if err != nil {
return nil, fmt.Errorf("fitsio: error writing card value [%s]: %v", card.Name, err)
}
case big.Int:
n, err = fmt.Fprintf(buf, "%s", v.String())
if err != nil {
return nil, fmt.Errorf("fitsio: error writing card value [%s]: %v", card.Name, err)
}
default:
panic(fmt.Errorf("fitsio: invalid card value [%s]: %#v (%T)", card.Name, v, v))
}
if n+buflen > kLINE {
return nil, fmt.Errorf("fitsio: value-string too big (%d) for card [%s]: %v\nbuf=|%s|",
n, card.Name, card.Value, string(buf.Bytes()),
)
}
buflen = buf.Len() % kLINE
comment := " / " + card.Comment
max := len(comment)
// if card.Comment == "my-comment" {
// fmt.Printf("max=%d\n", max)
// fmt.Printf("buf=%d\n", buflen)
// fmt.Printf("buf=%d\n", buf.Len())
// fmt.Printf("dif=%d\n", kLINE-buflen)
// }
if max > kLINE-buflen || (buf.Len() > kLINE && (buf.Len()%kLINE) == 0) {
// append a 'COMMENT' line
if buflen > 0 {
_, err = buf.Write(bytes.Repeat([]byte(" "), kLINE-buflen))
if err != nil {
return nil, err
}
}
comline, err := makeHeaderLine(&Card{Name: "COMMENT", Comment: card.Comment})
if err != nil {
return nil, err
}
_, err = buf.Write(comline)
if err != nil {
return nil, err
}
} else {
_, err = fmt.Fprintf(buf, "%s", comment[:max])
if err != nil {
return nil, err
}
}
}
n := buf.Len()
align80 := (kLINE - (n % kLINE)) % kLINE
if align80 > 0 {
_, err = buf.Write(bytes.Repeat([]byte(" "), align80))
}
return buf.Bytes(), err
}
// verifyCardName verifies a Card name conforms to the FITS standard.
// Must contain only capital letters, digits, minus or underscore chars.
// Trailing spaces are allowed.
func verifyCardName(card *Card) error {
var err error
spaces := false
max := len(card.Name)
if max > 8 {
max = 8
}
for idx, c := range card.Name {
switch {
case (c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') ||
c == '-' || c == '_':
if spaces {
return fmt.Errorf("fitsio: card name contains embedded space(s): %q", card.Name)
}
case c == ' ':
spaces = true
default:
return fmt.Errorf(
"fitsio: card name contains illegal character %q (idx=%d)",
card.Name, idx,
)
}
}
return err
}
// typeFromForm returns a FITS Type corresponding to a FITS TFORM string
func typeFromForm(form string, htype HDUType) (Type, error) {
var err error
var typ Type
switch htype {
case BINARY_TBL:
j := strings.IndexAny(form, "PQABCDEIJKLMX")
if j < 0 {
return typ, fmt.Errorf("fitsio: invalid TFORM format (%s)", form)
}
repeat := 1
if j > 0 {
r, err := strconv.ParseInt(form[:j], 10, 32)
if err != nil {
return typ, fmt.Errorf("fitsio: invalid TFORM format (%s)", form)
}
repeat = int(r)
}
slice := false
dsize := 0
hsize := 0
switch form[j] {
case 'P':
j += 1
slice = true
dsize = 2 * 4
case 'Q':
j += 1
slice = true
dsize = 2 * 8
}
tc, ok := g_fits2tc[BINARY_TBL][form[j]]
if !ok {
return typ, fmt.Errorf("fitsio: invalid TFORM format (%s) (no typecode found)", form)
}
rt, ok := g_fits2go[BINARY_TBL][form[j]]
if !ok {
return typ, fmt.Errorf("fitsio: invalid TFORM format (%s) (no Type found)", form)
}
elemsz := 0
switch form[j] {
case 'A':
elemsz = repeat
repeat = 1
case 'X':
elemsz = 1
const nbits = 8
sz := repeat + (nbits-(repeat%nbits))%nbits
repeat = sz / nbits
case 'L', 'B':
elemsz = 1
case 'I':
elemsz = 2
case 'J', 'E':
elemsz = 4
case 'K', 'D', 'C':
elemsz = 8
case 'M':
elemsz = 16
}
switch slice {
case true:
hsize = elemsz
typ = Type{
tc: -tc,
len: repeat,
dsize: dsize,
hsize: hsize,
gotype: reflect.SliceOf(rt),
}
case false:
dsize = elemsz
if repeat > 1 {
typ = Type{
tc: tc,
len: repeat,
dsize: dsize,
hsize: hsize,
gotype: reflect.ArrayOf(repeat, rt),
}
} else {
typ = Type{
tc: tc,
len: repeat,
dsize: dsize,
hsize: hsize,
gotype: rt,
}
}
}
if typ.dsize*typ.len == 0 {
if form != "0A" {
return typ, fmt.Errorf("fitsio: invalid dtype! form=%q typ=%#v\n", form, typ)
}
}
case ASCII_TBL:
// fmt.Printf("### form %q\n", form)
j := strings.IndexAny(form, "ADEFI")
if j < 0 {
return typ, fmt.Errorf("fitsio: invalid TFORM format (%s)", form)
}
j = strings.Index(form, ".")
if j == -1 {
j = len(form)
}
repeat := 1
r, err := strconv.ParseInt(form[1:j], 10, 32)
if err != nil {
return typ, fmt.Errorf("fitsio: invalid TFORM format (%s)", form)
}
repeat = int(r)
tc, ok := g_fits2tc[ASCII_TBL][form[0]]
if !ok {
return typ, fmt.Errorf("fitsio: invalid TFORM format (%s) (no typecode found)", form)
}
rt, ok := g_fits2go[ASCII_TBL][form[0]]
if !ok {
return typ, fmt.Errorf("fitsio: invalid TFORM format (%s) (no Type found)", form)
}
dsize := 0
hsize := 0
switch form[0] {
case 'A':
dsize = repeat
repeat = 1
case 'I':
dsize = repeat
repeat = 1
case 'D', 'E':
dsize = repeat
repeat = 1
case 'F':
dsize = repeat
repeat = 1
}
typ = Type{
tc: tc,
len: repeat,
dsize: dsize,
hsize: hsize,
gotype: rt,
}
// fmt.Printf(">>> %#v (%v)\n", typ, typ.gotype.Name())
if typ.dsize*typ.len == 0 {
if form != "0A" {
return typ, fmt.Errorf("fitsio: invalid dtype! form=%q typ=%#v\n", form, typ)
}
}
}
return typ, err
}
// txtfmtFromForm returns a suitable go-fmt format from a FITS TFORM
func txtfmtFromForm(form string) string {
var format string
var code rune
m := -1
w := 14
fmt.Sscanf(form, "%c%d.%d", &code, &w, &m)
switch form[0] {
case 'A':
format = fmt.Sprintf("%%%d.%ds", w, w) // Aw -> %ws
case 'I':
format = fmt.Sprintf("%%%dd", w) // Iw -> %wd
case 'B':
format = fmt.Sprintf("%%%db", w) // Bw -> %wb, binary
case 'O':
format = fmt.Sprintf("%%%do", w) // Ow -> %wo, octal
case 'Z':
format = fmt.Sprintf("%%%dX", w) // Zw -> %wX, hexadecimal
case 'F':
if m != -1 {
format = fmt.Sprintf("%%%d.%df", w, m) // Fw.d -> %w.df
} else {
format = fmt.Sprintf("%%%df", w) // Fw -> %wf
}
case 'E', 'D':
if m != -1 {
format = fmt.Sprintf("%%%d.%de", w, m) // Fw.d -> %w.df
} else {
format = fmt.Sprintf("%%%de", w) // Ew -> %we
}
case 'G':
if m != -1 {
format = fmt.Sprintf("%%%d.%dg", w, m) // Fw.d -> %w.df
} else {
format = fmt.Sprintf("%%%dg", w) // Gw -> %wg
}
}
return format
}
// formFromGoType returns a suitable FITS TFORM string from a reflect.Type
func formFromGoType(rt reflect.Type, htype HDUType) string {
hdr := ""
var t reflect.Type
switch rt.Kind() {
case reflect.Array:
hdr = fmt.Sprintf("%d", rt.Len())
t = rt.Elem()
case reflect.Slice:
hdr = "Q"
t = rt.Elem()
default:
t = rt
}
dict, ok := g_gotype2FITS[t.Kind()]
if !ok {
return ""
}
form, ok := dict[htype]
if !ok {
return ""
}
return hdr + form
}
var g_gotype2FITS = map[reflect.Kind]map[HDUType]string{
reflect.Bool: {
ASCII_TBL: "",
BINARY_TBL: "L",
},
reflect.Int: {
ASCII_TBL: "I4",
BINARY_TBL: "K",
},
reflect.Int8: {
ASCII_TBL: "I4",
BINARY_TBL: "B",
},
reflect.Int16: {
ASCII_TBL: "I4",
BINARY_TBL: "I",
},
reflect.Int32: {
ASCII_TBL: "I4",
BINARY_TBL: "J",
},
reflect.Int64: {
ASCII_TBL: "I4",
BINARY_TBL: "K",
},
reflect.Uint: {
ASCII_TBL: "I4",
BINARY_TBL: "V",
},
reflect.Uint8: {
ASCII_TBL: "I4",
BINARY_TBL: "B",
},
reflect.Uint16: {
ASCII_TBL: "I4",
BINARY_TBL: "U",
},
reflect.Uint32: {
ASCII_TBL: "I4",
BINARY_TBL: "V",
},
reflect.Uint64: {
ASCII_TBL: "I4",
BINARY_TBL: "V",
},
reflect.Uintptr: {
ASCII_TBL: "",
BINARY_TBL: "",
},
reflect.Float32: {
ASCII_TBL: "E26.17", // must write as float64 since we can only read as such
BINARY_TBL: "E",
},
reflect.Float64: {
ASCII_TBL: "E26.17",
BINARY_TBL: "D",
},
reflect.Complex64: {
ASCII_TBL: "",
BINARY_TBL: "C",
},
reflect.Complex128: {
ASCII_TBL: "",
BINARY_TBL: "M",
},
reflect.Array: {
ASCII_TBL: "",
BINARY_TBL: "",
},
reflect.Slice: {
ASCII_TBL: "",
BINARY_TBL: "",
},
reflect.String: {
ASCII_TBL: "A80",
BINARY_TBL: "80A",
},
}
var g_fits2go = map[HDUType]map[byte]reflect.Type{
ASCII_TBL: {
'A': reflect.TypeOf((*string)(nil)).Elem(),
'I': reflect.TypeOf((*int)(nil)).Elem(),
'E': reflect.TypeOf((*float64)(nil)).Elem(),
'D': reflect.TypeOf((*float64)(nil)).Elem(),
'F': reflect.TypeOf((*float64)(nil)).Elem(),
},
BINARY_TBL: {
'A': reflect.TypeOf((*string)(nil)).Elem(),
'B': reflect.TypeOf((*byte)(nil)).Elem(),
'L': reflect.TypeOf((*bool)(nil)).Elem(),
'I': reflect.TypeOf((*int16)(nil)).Elem(),
'J': reflect.TypeOf((*int32)(nil)).Elem(),
'K': reflect.TypeOf((*int64)(nil)).Elem(),
'E': reflect.TypeOf((*float32)(nil)).Elem(),
'D': reflect.TypeOf((*float64)(nil)).Elem(),
'C': reflect.TypeOf((*complex64)(nil)).Elem(),
'M': reflect.TypeOf((*complex128)(nil)).Elem(),
'X': reflect.TypeOf((*byte)(nil)).Elem(),
},
}
var g_fits2tc = map[HDUType]map[byte]typecode{
ASCII_TBL: {
'A': tcString,
'I': tcInt64,
'E': tcFloat64,
'D': tcFloat64,
'F': tcFloat64,
},
BINARY_TBL: {
'A': tcString,
'B': tcByte,
'L': tcBool,
'I': tcInt16,
'J': tcInt32,
'K': tcInt64,
'E': tcFloat32,
'D': tcFloat64,
'C': tcComplex64,
'M': tcComplex128,
'X': tcByte,
},
}