-
Notifications
You must be signed in to change notification settings - Fork 7
/
hget.h
2544 lines (2263 loc) · 66.3 KB
/
hget.h
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
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This file was originally hget.c by Doug Mink of the SAO. It has been
// converted into a .h file of static functions for internal use within a C
// compilation unit. You may want to consider using the original hget.c/hput.c
// rather than this file.
#ifndef HGET_H
#define HGET_H
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h> /* NULL, strlen, strstr, strcpy */
#include <limits.h>
#define VLENGTH 81
#define multiline 0
#define lhead0 0
static char *
hgetc(const char *hstring, const char *keyword0, char *value_buffer);
static int
hgets(const char *hstring, const char *keyword, const const int lstr, char *str);
static int
isnum(const char *string);
static char *
ksearch(const char *hstring, const char *keyword);
static char *
strsrch(const char *s1, const char *s2);
static char *
strnsrch(const char *s1, const char *s2, const const int ls1);
static char *
strcsrch(const char *s1, const char *s2);
static char *
strncsrch(const char *s1, const char *s2, const const int ls1);
/*** File libwcs/hget.c
*** August 22, 2007
*** By Doug Mink, dmink@cfa.harvard.edu
*** Harvard-Smithsonian Center for Astrophysics
*** Copyright (C) 1994-2007
*** Smithsonian Astrophysical Observatory, Cambridge, MA, USA
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Correspondence concerning WCSTools should be addressed as follows:
Internet email: dmink@cfa.harvard.edu
Postal address: Doug Mink
Smithsonian Astrophysical Observatory
60 Garden St.
Cambridge, MA 02138 USA
* Module: hget.c (Get FITS Header parameter values)
* Purpose: Extract values for variables from FITS header string
* Subroutine: hgeti2 (hstring,keyword,ival) returns short integer
* Subroutine: hgeti4c (hstring,keyword,wchar,ival) returns long integer
* Subroutine: hgeti4 (hstring,keyword,ival) returns long integer
* Subroutine: hgetr4 (hstring,keyword,rval) returns real
* Subroutine: hgetra (hstring,keyword,ra) returns double RA in degrees
* Subroutine: hgetdec (hstring,keyword,dec) returns double Dec in degrees
* Subroutine: hgetr8c (hstring,keyword,wchar,dval) returns double
* Subroutine: hgetr8 (hstring,keyword,dval) returns double
* Subroutine: hgetl (hstring,keyword,lval) returns logical int (0=F, 1=T)
* Subroutine: hgetsc (hstring,keyword,wchar,lstr,str) returns character string
* Subroutine: hgets (hstring,keyword, lstr, str) returns character string
* Subroutine: hgetm (hstring,keyword, lstr, str) returns multi-keyword string
* Subroutine: hgetdate (hstring,keyword,date) returns date as fractional year
* Subroutine: hgetndec (hstring, keyword, ndec) returns number of dec. places
* Subroutine: hgetc (hstring,keyword,value_buffer) returns character string
* Subroutine: blsearch (hstring,keyword) returns pointer to blank lines
before keyword
* Subroutine: ksearch (hstring,keyword) returns pointer to header string entry
* Subroutine: str2ra (in) converts string to right ascension in degrees
* Subroutine: str2dec (in) converts string to declination in degrees
* Subroutine: strsrch (s1, s2) finds string s2 in null-terminated string s1
* Subroutine: strnsrch (s1, s2, ls1) finds string s2 in ls1-byte string s1
* Subroutine: hlength (header,lhead) sets length of FITS header for searching
* Subroutine: isnum (string) returns 1 if integer, 2 if fp number, else 0
* Subroutine: notnum (string) returns 0 if number, else 1
* Subroutine: numdec (string) returns number of decimal places in numeric string
* Subroutine: strfix (string,blankfill,zerodrop) removes extraneous characters
*/
#if 0
#include <string.h> /* NULL, strlen, strstr, strcpy */
#include <stdio.h>
#include "fitshead.h" /* FITS header extraction subroutines */
#include <stdlib.h>
#ifndef VMS
#include <limits.h>
#else
#define INT_MAX 2147483647 /* Biggest number that can fit in long */
#define SHRT_MAX 32767
#endif
#define VLENGTH 81
static char *hgetc(const char *hstring, const char *keyword0, char *value_buffer);
/* Don't know why this is global, seems to be just a
* temp buffer for parsing strings. Made local copies in
* each function that uses it. --PBD
*/
//static char val[VLENGTH+1];
/* See comments at start of hgetm. Changed multiline to const 0.
* This is fine if we never need multiline strings.
* --PBD
*/
//static int multiline = 0;
const static int multiline = 0;
/* This looks like a hack to get around header strings that
* aren't null terminated. We can fix it at zero as long as
* we always have a null somewhere before our header memory runs
* out. --PBD
*/
//static int lhead0 = 0; /* Length of header string */
const static int lhead0 = 0; /* Length of header string */
/* Set the length of the header string, if not terminated by NULL */
int
hlength(const char *header, int lhead)
/* FITS header */
/* Maximum length of FITS header */
{
char *hend;
#if 0
if (lhead0 > 0)
lhead0 = lhead;
else {
lhead0 = 0;
hend = ksearch (header,"END");
lhead0 = hend + 80 - header;
}
#endif
/* Always return header length based on END. --PBD*/
hend = ksearch(header, "END");
return (hend + 80 - header);
}
/* Return the length of the header string, computing it if lhead0 not set */
int
gethlength(char *header)
/* FITS header */
{
if (lhead0 > 0)
{
return (lhead0);
}
else
{
return (hlength(header, 0));
}
}
/* Extract Integer*4 value for variable from FITS header string */
int
hgeti4c(const char *hstring, const char *keyword, const char *wchar, int *ival)
/* character string containing FITS header information
in the format <keyword>= <value> {/ <comment>} */
/* character string containing the name of the keyword
the value of which is returned. hget searches for
a line beginning with this string. if "[n]" is
present, the n'th token in the value is returned.
(the first 8 characters must be unique) */
/* Character of multiple WCS header; =0 if unused */
/* Keyword value returned */
{
char keyword1[16];
int lkey;
if (wchar[0] < (char) 64)
{
return (hgeti4(hstring, keyword, ival));
}
else
{
strcpy(keyword1, keyword);
lkey = strlen(keyword);
keyword1[lkey] = wchar[0];
keyword1[lkey + 1] = (char) 0;
return (hgeti4(hstring, keyword1, ival));
}
}
#endif // 0
/* Extract integer*8 value for variable from FITS header string */
static int
hgeti8 (hstring,keyword,i8val)
const char *hstring; /* character string containing FITS header information
in the format <keyword>= <value> {/ <comment>} */
const char *keyword; /* character string containing the name of the keyword
the value of which is returned. hget searches for a
line beginning with this string. if "[n]" is present,
the n'th token in the value is returned.
(the first 8 characters must be unique) */
int64_t *i8val;
{
char *value;
char *endptr;
char value_buffer[VLENGTH + 1];
/* Get value and comment from header string */
value = hgetc(hstring, keyword, value_buffer);
/* Translate value from ASCII to binary */
if (value != NULL) {
if (value[0] == '#') value++;
*i8val = strtoll(value, &endptr, 0);
if(endptr && endptr[0]) {
fprintf(stderr, "%s:%s got invalid integer character '%c' (%d)\n",
__FUNCTION__, keyword, endptr[0], endptr[0]);
*i8val = (long long)atof(value);
}
return 1;
} else {
return 0;
}
}
/* Extract unsigned integer*8 value for variable from FITS header string */
static int
hgetu8 (hstring,keyword,i8val)
const char *hstring; /* character string containing FITS header information
in the format <keyword>= <value> {/ <comment>} */
const char *keyword; /* character string containing the name of the keyword
the value of which is returned. hget searches for a
line beginning with this string. if "[n]" is present,
the n'th token in the value is returned.
(the first 8 characters must be unique) */
uint64_t *i8val;
{
char *value;
char *endptr;
char value_buffer[VLENGTH + 1];
/* Get value and comment from header string */
value = hgetc (hstring,keyword, value_buffer);
/* Translate value from ASCII to binary */
if (value != NULL) {
if (value[0] == '#') value++;
*i8val = strtoull(value, &endptr, 0);
if(endptr && endptr[0]) {
fprintf(stderr, "%s:%s got invalid integer character '%c' (%d)\n",
__FUNCTION__, keyword, endptr[0], endptr[0]);
*i8val = (unsigned long long)atof(value);
}
return 1;
} else {
return 0;
}
}
/* Extract long value for variable from FITS header string */
static int
hgeti4(const char *hstring, const char *keyword, int *ival)
/* character string containing FITS header information
in the format <keyword>= <value> {/ <comment>} */
/* character string containing the name of the keyword
the value of which is returned. hget searches for a
line beginning with this string. if "[n]" is present,
the n'th token in the value is returned.
(the first 8 characters must be unique) */
{
char *value;
double dval;
int minint;
int lval;
char *dchar;
char val[VLENGTH + 1];
char value_buffer[VLENGTH + 1];
/* Get value and comment from header string */
value = hgetc(hstring, keyword, value_buffer);
/* Translate value from ASCII to binary */
if (value != NULL)
{
if (value[0] == '#')
{
value++;
}
minint = -INT_MAX - 1;
lval = strlen(value);
if (lval > VLENGTH)
{
strncpy(val, value, VLENGTH);
val[VLENGTH] = (char) 0;
}
else
{
strcpy(val, value);
}
if (isnum(val) == 2)
{
if ((dchar = strchr(val, 'D')))
{
*dchar = 'e';
}
if ((dchar = strchr(val, 'd')))
{
*dchar = 'e';
}
if ((dchar = strchr(val, 'E')))
{
*dchar = 'e';
}
}
dval = atof(val);
if (dval + 0.001 > INT_MAX)
{
*ival = INT_MAX;
}
else if (dval >= 0)
{
*ival = (int) (dval + 0.001);
}
else if (dval - 0.001 < minint)
{
*ival = minint;
}
else
{
*ival = (int) (dval - 0.001);
}
return (1);
}
else
{
return (0);
}
}
/* Extract unsigned integer*4 value for variable from FITS header string */
static uint32_t
hgetu4 (hstring,keyword,i4val)
const char *hstring; /* character string containing FITS header information
in the format <keyword>= <value> {/ <comment>} */
const char *keyword; /* character string containing the name of the keyword
the value of which is returned. hget searches for a
line beginning with this string. if "[n]" is present,
the n'th token in the value is returned.
(the first 8 characters must be unique) */
uint32_t *i4val;
{
char *value;
char *endptr;
char value_buffer[VLENGTH + 1];
/* Get value and comment from header string */
value = hgetc (hstring,keyword, value_buffer);
/* Translate value from ASCII to binary */
if (value != NULL) {
if (value[0] == '#') value++;
*i4val = strtoul(value, &endptr, 0);
if(endptr && endptr[0]) {
fprintf(stderr, "%s:%s got invalid integer character '%c' (%d)\n",
__FUNCTION__, keyword, endptr[0], endptr[0]);
*i4val = (uint32_t)atof(value);
}
return 1;
} else {
return 0;
}
}
#if 0
/* Extract integer*2 value for variable from fits header string */
int
hgeti2(const char *hstring, const char *keyword, short int *ival)
/* character string containing FITS header information
in the format <keyword>= <value> {/ <comment>} */
/* character string containing the name of the keyword
the value of which is returned. hget searches for a
line beginning with this string. if "[n]" is present,
the n'th token in the value is returned.
(the first 8 characters must be unique) */
{
char *value;
double dval;
int minshort;
int lval;
char *dchar;
char val[VLENGTH + 1];
char value_buffer[VLENGTH + 1];
/* Get value and comment from header string */
value = hgetc(hstring, keyword, value_buffer);
/* Translate value from ASCII to binary */
if (value != NULL)
{
if (value[0] == '#')
{
value++;
}
lval = strlen(value);
if (lval > VLENGTH)
{
strncpy(val, value, VLENGTH);
val[VLENGTH] = (char) 0;
}
else
{
strcpy(val, value);
}
if (isnum(val) == 2)
{
if ((dchar = strchr(val, 'D')))
{
*dchar = 'e';
}
if ((dchar = strchr(val, 'd')))
{
*dchar = 'e';
}
if ((dchar = strchr(val, 'E')))
{
*dchar = 'e';
}
}
dval = atof(val);
minshort = -SHRT_MAX - 1;
if (dval + 0.001 > SHRT_MAX)
{
*ival = SHRT_MAX;
}
else if (dval >= 0)
{
*ival = (short) (dval + 0.001);
}
else if (dval - 0.001 < minshort)
{
*ival = minshort;
}
else
{
*ival = (short) (dval - 0.001);
}
return (1);
}
else
{
return (0);
}
}
/* Extract real value for variable from FITS header string */
int
hgetr4(const char *hstring, const char *keyword, float *rval)
/* character string containing FITS header information
in the format <keyword>= <value> {/ <comment>} */
/* character string containing the name of the keyword
the value of which is returned. hget searches for a
line beginning with this string. if "[n]" is present,
the n'th token in the value is returned.
(the first 8 characters must be unique) */
{
char *value;
int lval;
char *dchar;
char val[VLENGTH + 1];
char value_buffer[VLENGTH + 1];
/* Get value and comment from header string */
value = hgetc(hstring, keyword, value_buffer);
/* translate value from ASCII to binary */
if (value != NULL)
{
if (value[0] == '#')
{
value++;
}
lval = strlen(value);
if (lval > VLENGTH)
{
strncpy(val, value, VLENGTH);
val[VLENGTH] = (char) 0;
}
else
{
strcpy(val, value);
}
if (isnum(val) == 2)
{
if ((dchar = strchr(val, 'D')))
{
*dchar = 'e';
}
if ((dchar = strchr(val, 'd')))
{
*dchar = 'e';
}
if ((dchar = strchr(val, 'E')))
{
*dchar = 'e';
}
}
*rval = (float) atof(val);
return (1);
}
else
{
return (0);
}
}
/* Extract real*8 right ascension in degrees from FITS header string */
int
hgetra(const char *hstring, const char *keyword, double *dval)
/* character string containing FITS header information
in the format <keyword>= <value> {/ <comment>} */
/* character string containing the name of the keyword
the value of which is returned. hget searches for a
line beginning with this string. if "[n]" is present,
the n'th token in the value is returned.
(the first 8 characters must be unique) */
/* Right ascension in degrees (returned) */
{
char *value;
char value_buffer[VLENGTH + 1];
/* Get value from header string */
value = hgetc(hstring, keyword, value_buffer);
/* Translate value from ASCII colon-delimited string to binary */
if (value != NULL)
{
*dval = str2ra(value);
return (1);
}
else
{
return (0);
}
}
/* Extract real*8 declination in degrees from FITS header string */
int
hgetdec(const char *hstring, const char *keyword, double *dval)
/* character string containing FITS header information
in the format <keyword>= <value> {/ <comment>} */
/* character string containing the name of the keyword
the value of which is returned. hget searches for a
line beginning with this string. if "[n]" is present,
the n'th token in the value is returned.
(the first 8 characters must be unique) */
/* Right ascension in degrees (returned) */
{
char *value;
char value_buffer[VLENGTH + 1];
/* Get value from header string */
value = hgetc(hstring, keyword, value_buffer);
/* Translate value from ASCII colon-delimited string to binary */
if (value != NULL)
{
*dval = str2dec(value);
return (1);
}
else
{
return (0);
}
}
/* Extract real*8 value for variable from FITS header string */
int
hgetr8c(const char *hstring, const char *keyword, const char *wchar, double *dval)
/* character string containing FITS header information
in the format <keyword>= <value> {/ <comment>} */
/* character string containing the name of the keyword
the value of which is returned. hget searches for
a line beginning with this string. if "[n]" is
present, the n'th token in the value is returned.
(the first 8 characters must be unique) */
/* Character of multiple WCS header; =0 if unused */
/* Keyword value returned */
{
char keyword1[16];
int lkey;
if (wchar[0] < (char) 64)
{
return (hgetr8(hstring, keyword, dval));
}
else
{
strcpy(keyword1, keyword);
lkey = strlen(keyword);
keyword1[lkey] = wchar[0];
keyword1[lkey + 1] = (char) 0;
return (hgetr8(hstring, keyword1, dval));
}
}
#endif // 0
/* Extract real*8 value for variable from FITS header string */
static int
hgetr8(const char *hstring, const char *keyword, double *dval)
/* character string containing FITS header information
in the format <keyword>= <value> {/ <comment>} */
/* character string containing the name of the keyword
the value of which is returned. hget searches for a
line beginning with this string. if "[n]" is present,
the n'th token in the value is returned.
(the first 8 characters must be unique) */
{
char *value;
int lval;
char *dchar;
char val[VLENGTH + 1];
char value_buffer[VLENGTH + 1];
/* Get value and comment from header string */
value = hgetc(hstring, keyword, value_buffer);
/* Translate value from ASCII to binary */
if (value != NULL)
{
if (value[0] == '#')
{
value++;
}
lval = strlen(value);
if (lval > VLENGTH)
{
strncpy(val, value, VLENGTH);
val[VLENGTH] = (char) 0;
}
else
{
strcpy(val, value);
}
if (isnum(val) == 2)
{
if ((dchar = strchr(val, 'D')))
{
*dchar = 'e';
}
if ((dchar = strchr(val, 'd')))
{
*dchar = 'e';
}
if ((dchar = strchr(val, 'E')))
{
*dchar = 'e';
}
}
*dval = atof(val);
return (1);
}
else
{
return (0);
}
}
#if 0
/* Extract logical value for variable from FITS header string */
int
hgetl(const char *hstring, const char *keyword, int *ival)
/* character string containing FITS header information
in the format <keyword>= <value> {/ <comment>} */
/* character string containing the name of the keyword
the value of which is returned. hget searches for a
line beginning with this string. if "[n]" is present,
the n'th token in the value is returned.
(the first 8 characters must be unique) */
{
char *value;
char newval;
int lval;
char val[VLENGTH + 1];
char value_buffer[VLENGTH + 1];
/* Get value and comment from header string */
value = hgetc(hstring, keyword, value_buffer);
/* Translate value from ASCII to binary */
if (value != NULL)
{
lval = strlen(value);
if (lval > VLENGTH)
{
strncpy(val, value, VLENGTH);
val[VLENGTH] = (char) 0;
}
else
{
strcpy(val, value);
}
newval = val[0];
if (newval == 't' || newval == 'T')
{
*ival = 1;
}
else
{
*ival = 0;
}
return (1);
}
else
{
return (0);
}
}
/* Extract real*8 date from FITS header string (dd/mm/yy or dd-mm-yy) */
int
hgetdate(const char *hstring, const char *keyword, double *dval)
/* character string containing FITS header information
in the format <keyword>= <value> {/ <comment>} */
/* character string containing the name of the keyword
the value of which is returned. hget searches for a
line beginning with this string. if "[n]" is present,
the n'th token in the value is returned.
(the first 8 characters must be unique) */
{
double yeardays, seconds, fday;
char *value, *sstr, *dstr, *tstr, *cstr, *nval;
int year, month, day, yday, i, hours, minutes;
//static int mday[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int mday[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char value_buffer[VLENGTH + 1];
/* Get value and comment from header string */
value = hgetc(hstring, keyword, value_buffer);
/* Translate value from ASCII to binary */
if (value != NULL)
{
sstr = strchr(value, '/');
dstr = strchr(value, '-');
/* Original FITS date format: dd/mm/yy */
if (sstr > value)
{
*sstr = '\0';
day = (int) atof(value);
*sstr = '/';
nval = sstr + 1;
sstr = strchr(nval, '/');
if (sstr == NULL)
{
sstr = strchr(nval, '-');
}
if (sstr > value)
{
*sstr = '\0';
month = (int) atof(nval);
*sstr = '/';
nval = sstr + 1;
year = (int) atof(nval);
if (day > 31)
{
yday = year;
year = day;
day = yday;
}
if (year >= 0 && year <= 49)
{
year = year + 2000;
}
else if (year < 100)
{
year = year + 1900;
}
if ((year % 4) == 0)
{
mday[1] = 29;
}
else
{
mday[1] = 28;
}
if ((year % 100) == 0 && (year % 400) != 0)
{
mday[1] = 28;
}
if (day > mday[month - 1])
{
day = mday[month - 1];
}
else if (day < 1)
{
day = 1;
}
if (mday[1] == 28)
{
yeardays = 365.0;
}
else
{
yeardays = 366.0;
}
yday = day - 1;
for (i = 0; i < month - 1; i++)
{
yday = yday + mday[i];
}
*dval = (double) year + ((double) yday / yeardays);
return (1);
}
else
{
return (0);
}
}
/* New FITS date format: yyyy-mm-ddThh:mm:ss[.sss] */
else if (dstr > value)
{
*dstr = '\0';
year = (int) atof(value);
*dstr = '-';
nval = dstr + 1;
dstr = strchr(nval, '-');
month = 1;
day = 1;
tstr = NULL;
if (dstr > value)
{
*dstr = '\0';
month = (int) atof(nval);
*dstr = '-';
nval = dstr + 1;
tstr = strchr(nval, 'T');
if (tstr > value)
{
*tstr = '\0';
}
day = (int) atof(nval);
if (tstr > value)
{
*tstr = 'T';
}
}
/* If year is < 32, it is really day of month in old format */
if (year < 32)
{
i = year;
year = day + 1900;
day = i;
}
if ((year % 4) == 0)
{
mday[1] = 29;
}
else
{
mday[1] = 28;
}
if ((year % 100) == 0 && (year % 400) != 0)
{
mday[1] = 28;
}
if (day > mday[month - 1])
{
day = mday[month - 1];
}
else if (day < 1)
{
day = 1;
}
if (mday[1] == 28)
{
yeardays = 365.0;
}
else
{
yeardays = 366.0;
}
yday = day - 1;
for (i = 0; i < month - 1; i++)
{
yday = yday + mday[i];
}
*dval = (double) year + ((double) yday / yeardays);
/* Extract time, if it is present */
if (tstr > value)
{
nval = tstr + 1;
hours = 0.0;
minutes = 0.0;
seconds = 0.0;
cstr = strchr(nval, ':');
if (cstr > value)
{
*cstr = '\0';
hours = (int) atof(nval);
*cstr = ':';
nval = cstr + 1;
cstr = strchr(nval, ':');
if (cstr > value)
{
*cstr = '\0';
minutes = (int) atof(nval);
*cstr = ':';
nval = cstr + 1;
seconds = atof(nval);
}
else
{
minutes = (int) atof(nval);
seconds = 0.0;
}
}
fday = ((3.6e3 * (double) hours) + (6.e1 * (double) minutes) +
seconds) / 8.64e4;
*dval = *dval + (fday / yeardays);
}
return (1);
}
else
{
return (0);
}
}
else
{
return (0);
}
}
/* This routine breaks thread safety by using the global var
* "multiline". We likely won't ever call this one, but removed
* it just in case. --PBD
*/
#if 0
/* Extract IRAF multiple-keyword string value from FITS header string */
int