This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
fitscore.c
9818 lines (8539 loc) · 313 KB
/
fitscore.c
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, fitscore.c, contains the core set of FITSIO routines. */
/* The FITSIO software was written by William Pence at the High Energy */
/* Astrophysic Science Archive Research Center (HEASARC) at the NASA */
/* Goddard Space Flight Center. */
/*
Copyright (Unpublished--all rights reserved under the copyright laws of
the United States), U.S. Government as represented by the Administrator
of the National Aeronautics and Space Administration. No copyright is
claimed in the United States under Title 17, U.S. Code.
Permission to freely use, copy, modify, and distribute this software
and its documentation without fee is hereby granted, provided that this
copyright notice and disclaimer of warranty appears in all copies.
DISCLAIMER:
THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND,
EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO,
ANY WARRANTY THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, AND FREEDOM FROM INFRINGEMENT, AND ANY WARRANTY THAT THE
DOCUMENTATION WILL CONFORM TO THE SOFTWARE, OR ANY WARRANTY THAT THE
SOFTWARE WILL BE ERROR FREE. IN NO EVENT SHALL NASA BE LIABLE FOR ANY
DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL OR
CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, OR IN ANY WAY
CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY,
CONTRACT, TORT , OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY
PERSONS OR PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED
FROM, OR AROSE OUT OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR
SERVICES PROVIDED HEREUNDER."
*/
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <errno.h>
/* stddef.h is apparently needed to define size_t with some compilers ?? */
#include <stddef.h>
#include <locale.h>
#include "fitsio2.h"
#define errmsgsiz 25
#define ESMARKER 27 /* Escape character is used as error stack marker */
#define DelAll 1 /* delete all messages on the error stack */
#define DelMark 2 /* delete newest messages back to and including marker */
#define DelNewest 3 /* delete the newest message from the stack */
#define GetMesg 4 /* pop and return oldest message, ignoring marks */
#define PutMesg 5 /* add a new message to the stack */
#define PutMark 6 /* add a marker to the stack */
#ifdef _REENTRANT
/*
Fitsio_Lock and Fitsio_Pthread_Status are declared in fitsio2.h.
*/
pthread_mutex_t Fitsio_Lock;
int Fitsio_Pthread_Status = 0;
#endif
int STREAM_DRIVER = 0;
struct lconv *lcxxx;
/*--------------------------------------------------------------------------*/
float ffvers(float *version) /* IO - version number */
/*
return the current version number of the FITSIO software
Note that this method of calculation limits minor/micro fields to < 100.
*/
{
*version = (float)CFITSIO_MAJOR + (float)(.01*CFITSIO_MINOR)
+ (float)(.0001*CFITSIO_MICRO);
/* *version = 4.1.0 Feb 2022
Previous releases:
*version = 4.0.0 May 2021
*version = 3.49 Aug 2020
*version = 3.48 Apr 2020
*version = 3.47 May 2019
*version = 3.46 Oct 2018
*version = 3.45 May 2018
*version = 3.44 Apr 2018
*version = 3.43 Mar 2018
*version = 3.42 Mar 2017
*version = 3.41 Nov 2016
*version = 3.40 Oct 2016
*version = 3.39 Apr 2016
*version = 3.38 Feb 2016
*version = 3.37 3 Jun 2014
*version = 3.36 6 Dec 2013
*version = 3.35 23 May 2013
*version = 3.34 20 Mar 2013
*version = 3.33 14 Feb 2013
*version = 3.32 Oct 2012
*version = 3.31 18 Jul 2012
*version = 3.30 11 Apr 2012
*version = 3.29 22 Sep 2011
*version = 3.28 12 May 2011
*version = 3.27 3 Mar 2011
*version = 3.26 30 Dec 2010
*version = 3.25 9 June 2010
*version = 3.24 26 Jan 2010
*version = 3.23 7 Jan 2010
*version = 3.22 28 Oct 2009
*version = 3.21 24 Sep 2009
*version = 3.20 31 Aug 2009
*version = 3.18 12 May 2009 (beta version)
*version = 3.14 18 Mar 2009
*version = 3.13 5 Jan 2009
*version = 3.12 8 Oct 2008
*version = 3.11 19 Sep 2008
*version = 3.10 20 Aug 2008
*version = 3.09 3 Jun 2008
*version = 3.08 15 Apr 2007 (internal release)
*version = 3.07 5 Nov 2007 (internal release)
*version = 3.06 27 Aug 2007
*version = 3.05 12 Jul 2007 (internal release)
*version = 3.03 11 Dec 2006
*version = 3.02 18 Sep 2006
*version = 3.01 May 2006 included in FTOOLS 6.1 release
*version = 3.006 20 Feb 2006
*version = 3.005 20 Dec 2005 (beta, in heasoft swift release
*version = 3.004 16 Sep 2005 (beta, in heasoft swift release
*version = 3.003 28 Jul 2005 (beta, in heasoft swift release
*version = 3.002 15 Apr 2005 (beta)
*version = 3.001 15 Mar 2005 (beta) released with heasoft 6.0
*version = 3.000 1 Mar 2005 (internal release only)
*version = 2.51 2 Dec 2004
*version = 2.50 28 Jul 2004
*version = 2.49 11 Feb 2004
*version = 2.48 28 Jan 2004
*version = 2.470 18 Aug 2003
*version = 2.460 20 May 2003
*version = 2.450 30 Apr 2003 (internal release only)
*version = 2.440 8 Jan 2003
*version = 2.430; 4 Nov 2002
*version = 2.420; 19 Jul 2002
*version = 2.410; 22 Apr 2002 used in ftools v5.2
*version = 2.401; 28 Jan 2002
*version = 2.400; 18 Jan 2002
*version = 2.301; 7 Dec 2001
*version = 2.300; 23 Oct 2001
*version = 2.204; 26 Jul 2001
*version = 2.203; 19 Jul 2001 used in ftools v5.1
*version = 2.202; 22 May 2001
*version = 2.201; 15 Mar 2001
*version = 2.200; 26 Jan 2001
*version = 2.100; 26 Sep 2000
*version = 2.037; 6 Jul 2000
*version = 2.036; 1 Feb 2000
*version = 2.035; 7 Dec 1999 (internal release only)
*version = 2.034; 23 Nov 1999
*version = 2.033; 17 Sep 1999
*version = 2.032; 25 May 1999
*version = 2.031; 31 Mar 1999
*version = 2.030; 24 Feb 1999
*version = 2.029; 11 Feb 1999
*version = 2.028; 26 Jan 1999
*version = 2.027; 12 Jan 1999
*version = 2.026; 23 Dec 1998
*version = 2.025; 1 Dec 1998
*version = 2.024; 9 Nov 1998
*version = 2.023; 1 Nov 1998 first full release of V2.0
*version = 1.42; 30 Apr 1998
*version = 1.40; 6 Feb 1998
*version = 1.33; 16 Dec 1997 (internal release only)
*version = 1.32; 21 Nov 1997 (internal release only)
*version = 1.31; 4 Nov 1997 (internal release only)
*version = 1.30; 11 Sep 1997
*version = 1.27; 3 Sep 1997 (internal release only)
*version = 1.25; 2 Jul 1997
*version = 1.24; 2 May 1997
*version = 1.23; 24 Apr 1997
*version = 1.22; 18 Apr 1997
*version = 1.21; 26 Mar 1997
*version = 1.2; 29 Jan 1997
*version = 1.11; 04 Dec 1996
*version = 1.101; 13 Nov 1996
*version = 1.1; 6 Nov 1996
*version = 1.04; 17 Sep 1996
*version = 1.03; 20 Aug 1996
*version = 1.02; 15 Aug 1996
*version = 1.01; 12 Aug 1996
*/
return(*version);
}
/*--------------------------------------------------------------------------*/
int ffflnm(fitsfile *fptr, /* I - FITS file pointer */
char *filename, /* O - name of the file */
int *status) /* IO - error status */
/*
return the name of the FITS file
*/
{
strcpy(filename,(fptr->Fptr)->filename);
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffflmd(fitsfile *fptr, /* I - FITS file pointer */
int *filemode, /* O - open mode of the file */
int *status) /* IO - error status */
/*
return the access mode of the FITS file
*/
{
*filemode = (fptr->Fptr)->writemode;
return(*status);
}
/*--------------------------------------------------------------------------*/
void ffgerr(int status, /* I - error status value */
char *errtext) /* O - error message (max 30 char long + null) */
/*
Return a short descriptive error message that corresponds to the input
error status value. The message may be up to 30 characters long, plus
the terminating null character.
*/
{
errtext[0] = '\0';
if (status >= 0 && status < 300)
{
switch (status) {
case 0:
strcpy(errtext, "OK - no error");
break;
case 1:
strcpy(errtext, "non-CFITSIO program error");
break;
case 101:
strcpy(errtext, "same input and output files");
break;
case 103:
strcpy(errtext, "attempt to open too many files");
break;
case 104:
strcpy(errtext, "could not open the named file");
break;
case 105:
strcpy(errtext, "couldn't create the named file");
break;
case 106:
strcpy(errtext, "error writing to FITS file");
break;
case 107:
strcpy(errtext, "tried to move past end of file");
break;
case 108:
strcpy(errtext, "error reading from FITS file");
break;
case 110:
strcpy(errtext, "could not close the file");
break;
case 111:
strcpy(errtext, "array dimensions too big");
break;
case 112:
strcpy(errtext, "cannot write to readonly file");
break;
case 113:
strcpy(errtext, "could not allocate memory");
break;
case 114:
strcpy(errtext, "invalid fitsfile pointer");
break;
case 115:
strcpy(errtext, "NULL input pointer");
break;
case 116:
strcpy(errtext, "error seeking file position");
break;
case 117:
strcpy(errtext, "bad value for file download timeout setting");
break;
case 121:
strcpy(errtext, "invalid URL prefix");
break;
case 122:
strcpy(errtext, "too many I/O drivers");
break;
case 123:
strcpy(errtext, "I/O driver init failed");
break;
case 124:
strcpy(errtext, "no I/O driver for this URLtype");
break;
case 125:
strcpy(errtext, "parse error in input file URL");
break;
case 126:
strcpy(errtext, "parse error in range list");
break;
case 151:
strcpy(errtext, "bad argument (shared mem drvr)");
break;
case 152:
strcpy(errtext, "null ptr arg (shared mem drvr)");
break;
case 153:
strcpy(errtext, "no free shared memory handles");
break;
case 154:
strcpy(errtext, "share mem drvr not initialized");
break;
case 155:
strcpy(errtext, "IPC system error (shared mem)");
break;
case 156:
strcpy(errtext, "no memory (shared mem drvr)");
break;
case 157:
strcpy(errtext, "share mem resource deadlock");
break;
case 158:
strcpy(errtext, "lock file open/create failed");
break;
case 159:
strcpy(errtext, "can't resize share mem block");
break;
case 201:
strcpy(errtext, "header already has keywords");
break;
case 202:
strcpy(errtext, "keyword not found in header");
break;
case 203:
strcpy(errtext, "keyword number out of bounds");
break;
case 204:
strcpy(errtext, "keyword value is undefined");
break;
case 205:
strcpy(errtext, "string missing closing quote");
break;
case 206:
strcpy(errtext, "error in indexed keyword name");
break;
case 207:
strcpy(errtext, "illegal character in keyword");
break;
case 208:
strcpy(errtext, "required keywords out of order");
break;
case 209:
strcpy(errtext, "keyword value not positive int");
break;
case 210:
strcpy(errtext, "END keyword not found");
break;
case 211:
strcpy(errtext, "illegal BITPIX keyword value");
break;
case 212:
strcpy(errtext, "illegal NAXIS keyword value");
break;
case 213:
strcpy(errtext, "illegal NAXISn keyword value");
break;
case 214:
strcpy(errtext, "illegal PCOUNT keyword value");
break;
case 215:
strcpy(errtext, "illegal GCOUNT keyword value");
break;
case 216:
strcpy(errtext, "illegal TFIELDS keyword value");
break;
case 217:
strcpy(errtext, "negative table row size");
break;
case 218:
strcpy(errtext, "negative number of rows");
break;
case 219:
strcpy(errtext, "named column not found");
break;
case 220:
strcpy(errtext, "illegal SIMPLE keyword value");
break;
case 221:
strcpy(errtext, "first keyword not SIMPLE");
break;
case 222:
strcpy(errtext, "second keyword not BITPIX");
break;
case 223:
strcpy(errtext, "third keyword not NAXIS");
break;
case 224:
strcpy(errtext, "missing NAXISn keywords");
break;
case 225:
strcpy(errtext, "first keyword not XTENSION");
break;
case 226:
strcpy(errtext, "CHDU not an ASCII table");
break;
case 227:
strcpy(errtext, "CHDU not a binary table");
break;
case 228:
strcpy(errtext, "PCOUNT keyword not found");
break;
case 229:
strcpy(errtext, "GCOUNT keyword not found");
break;
case 230:
strcpy(errtext, "TFIELDS keyword not found");
break;
case 231:
strcpy(errtext, "missing TBCOLn keyword");
break;
case 232:
strcpy(errtext, "missing TFORMn keyword");
break;
case 233:
strcpy(errtext, "CHDU not an IMAGE extension");
break;
case 234:
strcpy(errtext, "illegal TBCOLn keyword value");
break;
case 235:
strcpy(errtext, "CHDU not a table extension");
break;
case 236:
strcpy(errtext, "column exceeds width of table");
break;
case 237:
strcpy(errtext, "more than 1 matching col. name");
break;
case 241:
strcpy(errtext, "row width not = field widths");
break;
case 251:
strcpy(errtext, "unknown FITS extension type");
break;
case 252:
strcpy(errtext, "1st key not SIMPLE or XTENSION");
break;
case 253:
strcpy(errtext, "END keyword is not blank");
break;
case 254:
strcpy(errtext, "Header fill area not blank");
break;
case 255:
strcpy(errtext, "Data fill area invalid");
break;
case 261:
strcpy(errtext, "illegal TFORM format code");
break;
case 262:
strcpy(errtext, "unknown TFORM datatype code");
break;
case 263:
strcpy(errtext, "illegal TDIMn keyword value");
break;
case 264:
strcpy(errtext, "invalid BINTABLE heap pointer");
break;
default:
strcpy(errtext, "unknown error status");
break;
}
}
else if (status < 600)
{
switch(status) {
case 301:
strcpy(errtext, "illegal HDU number");
break;
case 302:
strcpy(errtext, "column number < 1 or > tfields");
break;
case 304:
strcpy(errtext, "negative byte address");
break;
case 306:
strcpy(errtext, "negative number of elements");
break;
case 307:
strcpy(errtext, "bad first row number");
break;
case 308:
strcpy(errtext, "bad first element number");
break;
case 309:
strcpy(errtext, "not an ASCII (A) column");
break;
case 310:
strcpy(errtext, "not a logical (L) column");
break;
case 311:
strcpy(errtext, "bad ASCII table datatype");
break;
case 312:
strcpy(errtext, "bad binary table datatype");
break;
case 314:
strcpy(errtext, "null value not defined");
break;
case 317:
strcpy(errtext, "not a variable length column");
break;
case 320:
strcpy(errtext, "illegal number of dimensions");
break;
case 321:
strcpy(errtext, "1st pixel no. > last pixel no.");
break;
case 322:
strcpy(errtext, "BSCALE or TSCALn = 0.");
break;
case 323:
strcpy(errtext, "illegal axis length < 1");
break;
case 340:
strcpy(errtext, "not group table");
break;
case 341:
strcpy(errtext, "HDU already member of group");
break;
case 342:
strcpy(errtext, "group member not found");
break;
case 343:
strcpy(errtext, "group not found");
break;
case 344:
strcpy(errtext, "bad group id");
break;
case 345:
strcpy(errtext, "too many HDUs tracked");
break;
case 346:
strcpy(errtext, "HDU alread tracked");
break;
case 347:
strcpy(errtext, "bad Grouping option");
break;
case 348:
strcpy(errtext, "identical pointers (groups)");
break;
case 360:
strcpy(errtext, "malloc failed in parser");
break;
case 361:
strcpy(errtext, "file read error in parser");
break;
case 362:
strcpy(errtext, "null pointer arg (parser)");
break;
case 363:
strcpy(errtext, "empty line (parser)");
break;
case 364:
strcpy(errtext, "cannot unread > 1 line");
break;
case 365:
strcpy(errtext, "parser too deeply nested");
break;
case 366:
strcpy(errtext, "file open failed (parser)");
break;
case 367:
strcpy(errtext, "hit EOF (parser)");
break;
case 368:
strcpy(errtext, "bad argument (parser)");
break;
case 369:
strcpy(errtext, "unexpected token (parser)");
break;
case 401:
strcpy(errtext, "bad int to string conversion");
break;
case 402:
strcpy(errtext, "bad float to string conversion");
break;
case 403:
strcpy(errtext, "keyword value not integer");
break;
case 404:
strcpy(errtext, "keyword value not logical");
break;
case 405:
strcpy(errtext, "keyword value not floating pt");
break;
case 406:
strcpy(errtext, "keyword value not double");
break;
case 407:
strcpy(errtext, "bad string to int conversion");
break;
case 408:
strcpy(errtext, "bad string to float conversion");
break;
case 409:
strcpy(errtext, "bad string to double convert");
break;
case 410:
strcpy(errtext, "illegal datatype code value");
break;
case 411:
strcpy(errtext, "illegal no. of decimals");
break;
case 412:
strcpy(errtext, "datatype conversion overflow");
break;
case 413:
strcpy(errtext, "error compressing image");
break;
case 414:
strcpy(errtext, "error uncompressing image");
break;
case 420:
strcpy(errtext, "bad date or time conversion");
break;
case 431:
strcpy(errtext, "syntax error in expression");
break;
case 432:
strcpy(errtext, "expression result wrong type");
break;
case 433:
strcpy(errtext, "vector result too large");
break;
case 434:
strcpy(errtext, "missing output column");
break;
case 435:
strcpy(errtext, "bad data in parsed column");
break;
case 436:
strcpy(errtext, "output extension of wrong type");
break;
case 501:
strcpy(errtext, "WCS angle too large");
break;
case 502:
strcpy(errtext, "bad WCS coordinate");
break;
case 503:
strcpy(errtext, "error in WCS calculation");
break;
case 504:
strcpy(errtext, "bad WCS projection type");
break;
case 505:
strcpy(errtext, "WCS keywords not found");
break;
default:
strcpy(errtext, "unknown error status");
break;
}
}
else
{
strcpy(errtext, "unknown error status");
}
return;
}
/*--------------------------------------------------------------------------*/
void ffpmsg(const char *err_message)
/*
put message on to error stack
*/
{
ffxmsg(PutMesg, (char *)err_message);
return;
}
/*--------------------------------------------------------------------------*/
void ffpmrk(void)
/*
write a marker to the stack. It is then possible to pop only those
messages following the marker off of the stack, leaving the previous
messages unaffected.
The marker is ignored by the ffgmsg routine.
*/
{
char *dummy = 0;
ffxmsg(PutMark, dummy);
return;
}
/*--------------------------------------------------------------------------*/
int ffgmsg(char *err_message)
/*
get oldest message from error stack, ignoring markers
*/
{
ffxmsg(GetMesg, err_message);
return(*err_message);
}
/*--------------------------------------------------------------------------*/
void ffcmsg(void)
/*
erase all messages in the error stack
*/
{
char *dummy = 0;
ffxmsg(DelAll, dummy);
return;
}
/*--------------------------------------------------------------------------*/
void ffcmrk(void)
/*
erase newest messages in the error stack, stopping if a marker is found.
The marker is also erased in this case.
*/
{
char *dummy = 0;
ffxmsg(DelMark, dummy);
return;
}
/*--------------------------------------------------------------------------*/
void ffxmsg( int action,
char *errmsg)
/*
general routine to get, put, or clear the error message stack.
Use a static array rather than allocating memory as needed for
the error messages because it is likely to be more efficient
and simpler to implement.
Action Code:
DelAll 1 delete all messages on the error stack
DelMark 2 delete messages back to and including the 1st marker
DelNewest 3 delete the newest message from the stack
GetMesg 4 pop and return oldest message, ignoring marks
PutMesg 5 add a new message to the stack
PutMark 6 add a marker to the stack
*/
{
int ii;
char markflag;
static char *txtbuff[errmsgsiz], *tmpbuff, *msgptr;
static char errbuff[errmsgsiz][81]; /* initialize all = \0 */
static int nummsg = 0;
FFLOCK;
if (action == DelAll) /* clear the whole message stack */
{
for (ii = 0; ii < nummsg; ii ++)
*txtbuff[ii] = '\0';
nummsg = 0;
}
else if (action == DelMark) /* clear up to and including first marker */
{
while (nummsg > 0) {
nummsg--;
markflag = *txtbuff[nummsg]; /* store possible marker character */
*txtbuff[nummsg] = '\0'; /* clear the buffer for this msg */
if (markflag == ESMARKER)
break; /* found a marker, so quit */
}
}
else if (action == DelNewest) /* remove newest message from stack */
{
if (nummsg > 0)
{
nummsg--;
*txtbuff[nummsg] = '\0'; /* clear the buffer for this msg */
}
}
else if (action == GetMesg) /* pop and return oldest message from stack */
{ /* ignoring markers */
while (nummsg > 0)
{
strcpy(errmsg, txtbuff[0]); /* copy oldest message to output */
*txtbuff[0] = '\0'; /* clear the buffer for this msg */
nummsg--;
for (ii = 0; ii < nummsg; ii++)
txtbuff[ii] = txtbuff[ii + 1]; /* shift remaining pointers */
if (errmsg[0] != ESMARKER) { /* quit if this is not a marker */
FFUNLOCK;
return;
}
}
errmsg[0] = '\0'; /* no messages in the stack */
}
else if (action == PutMesg) /* add new message to stack */
{
msgptr = errmsg;
while (strlen(msgptr))
{
if (nummsg == errmsgsiz)
{
tmpbuff = txtbuff[0]; /* buffers full; reuse oldest buffer */
*txtbuff[0] = '\0'; /* clear the buffer for this msg */
nummsg--;
for (ii = 0; ii < nummsg; ii++)
txtbuff[ii] = txtbuff[ii + 1]; /* shift remaining pointers */
txtbuff[nummsg] = tmpbuff; /* set pointer for the new message */
}
else
{
for (ii = 0; ii < errmsgsiz; ii++)
{
if (*errbuff[ii] == '\0') /* find first empty buffer */
{
txtbuff[nummsg] = errbuff[ii];
break;
}
}
}
strncat(txtbuff[nummsg], msgptr, 80);
nummsg++;
msgptr += minvalue(80, strlen(msgptr));
}
}
else if (action == PutMark) /* put a marker on the stack */
{
if (nummsg == errmsgsiz)
{
tmpbuff = txtbuff[0]; /* buffers full; reuse oldest buffer */
*txtbuff[0] = '\0'; /* clear the buffer for this msg */
nummsg--;
for (ii = 0; ii < nummsg; ii++)
txtbuff[ii] = txtbuff[ii + 1]; /* shift remaining pointers */
txtbuff[nummsg] = tmpbuff; /* set pointer for the new message */
}
else
{
for (ii = 0; ii < errmsgsiz; ii++)
{
if (*errbuff[ii] == '\0') /* find first empty buffer */
{
txtbuff[nummsg] = errbuff[ii];
break;
}
}
}
*txtbuff[nummsg] = ESMARKER; /* write the marker */
*(txtbuff[nummsg] + 1) = '\0';
nummsg++;
}
FFUNLOCK;
return;
}
/*--------------------------------------------------------------------------*/
int ffpxsz(int datatype)
/*
return the number of bytes per pixel associated with the datatype
*/
{
if (datatype == TBYTE)
return(sizeof(char));
else if (datatype == TUSHORT)
return(sizeof(short));
else if (datatype == TSHORT)
return(sizeof(short));
else if (datatype == TULONG)
return(sizeof(long));
else if (datatype == TLONG)
return(sizeof(long));
else if (datatype == TINT)
return(sizeof(int));
else if (datatype == TUINT)
return(sizeof(int));
else if (datatype == TFLOAT)
return(sizeof(float));
else if (datatype == TDOUBLE)
return(sizeof(double));
else if (datatype == TLOGICAL)
return(sizeof(char));
else
return(0);
}
/*--------------------------------------------------------------------------*/
int fftkey(const char *keyword, /* I - keyword name */
int *status) /* IO - error status */
/*
Test that the keyword name conforms to the FITS standard. Must contain
only capital letters, digits, minus or underscore chars. Trailing spaces
are allowed. If the input status value is less than zero, then the test
is modified so that upper or lower case letters are allowed, and no
error messages are printed if the keyword is not legal.
*/
{
size_t maxchr, ii;
int spaces=0;
char msg[FLEN_ERRMSG], testchar;
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
maxchr=strlen(keyword);
if (maxchr > 8)
maxchr = 8;
for (ii = 0; ii < maxchr; ii++)
{
if (*status == 0)
testchar = keyword[ii];
else
testchar = toupper(keyword[ii]);
if ( (testchar >= 'A' && testchar <= 'Z') ||
(testchar >= '0' && testchar <= '9') ||
testchar == '-' || testchar == '_' )
{
if (spaces)
{
if (*status == 0)
{
/* don't print error message if status < 0 */
snprintf(msg, FLEN_ERRMSG,
"Keyword name contains embedded space(s): %.8s",
keyword);
ffpmsg(msg);
}
return(*status = BAD_KEYCHAR);
}
}
else if (keyword[ii] == ' ')
spaces = 1;
else
{
if (*status == 0)
{
/* don't print error message if status < 0 */
snprintf(msg, FLEN_ERRMSG,"Character %d in this keyword is illegal: %.8s",
(int) (ii+1), keyword);
ffpmsg(msg);
/* explicitly flag the 2 most common cases */
if (keyword[ii] == 0)
ffpmsg(" (This a NULL (0) character).");
else if (keyword[ii] == 9)
ffpmsg(" (This an ASCII TAB (9) character).");
}
return(*status = BAD_KEYCHAR);
}
}
return(*status);
}
/*--------------------------------------------------------------------------*/
int fftrec(char *card, /* I - keyword card to test */
int *status) /* IO - error status */
/*
Test that the keyword card conforms to the FITS standard. Must contain
only printable ASCII characters;
*/
{
size_t ii, maxchr;
char msg[FLEN_ERRMSG];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
maxchr = strlen(card);
for (ii = 8; ii < maxchr; ii++)
{
if (card[ii] < 32 || card[ii] > 126)
{
snprintf(msg, FLEN_ERRMSG,
"Character %d in this keyword is illegal. Hex Value = %X",
(int) (ii+1), (int) card[ii] );
if (card[ii] == 0)
strncat(msg, " (NULL char.)",FLEN_ERRMSG-strlen(msg)-1);
else if (card[ii] == 9)
strncat(msg, " (TAB char.)",FLEN_ERRMSG-strlen(msg)-1);
else if (card[ii] == 10)
strncat(msg, " (Line Feed char.)",FLEN_ERRMSG-strlen(msg)-1);
else if (card[ii] == 11)
strncat(msg, " (Vertical Tab)",FLEN_ERRMSG-strlen(msg)-1);
else if (card[ii] == 12)