This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
/
putkey.c
3278 lines (2839 loc) · 113 KB
/
putkey.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, putkey.c, contains routines that write keywords to */
/* a FITS header. */
/* 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. */
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
/* stddef.h is apparently needed to define size_t */
#include <stddef.h>
#include "fitsio2.h"
/*--------------------------------------------------------------------------*/
int ffcrim(fitsfile *fptr, /* I - FITS file pointer */
int bitpix, /* I - bits per pixel */
int naxis, /* I - number of axes in the array */
long *naxes, /* I - size of each axis */
int *status) /* IO - error status */
/*
create an IMAGE extension following the current HDU. If the
current HDU is empty (contains no header keywords), then simply
write the required image (or primary array) keywords to the current
HDU.
*/
{
if (*status > 0)
return(*status);
if (fptr->HDUposition != (fptr->Fptr)->curhdu)
ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status);
/* create new extension if current header is not empty */
if ((fptr->Fptr)->headend != (fptr->Fptr)->headstart[(fptr->Fptr)->curhdu] )
ffcrhd(fptr, status);
/* write the required header keywords */
ffphpr(fptr, TRUE, bitpix, naxis, naxes, 0, 1, TRUE, status);
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffcrimll(fitsfile *fptr, /* I - FITS file pointer */
int bitpix, /* I - bits per pixel */
int naxis, /* I - number of axes in the array */
LONGLONG *naxes, /* I - size of each axis */
int *status) /* IO - error status */
/*
create an IMAGE extension following the current HDU. If the
current HDU is empty (contains no header keywords), then simply
write the required image (or primary array) keywords to the current
HDU.
*/
{
if (*status > 0)
return(*status);
if (fptr->HDUposition != (fptr->Fptr)->curhdu)
ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status);
/* create new extension if current header is not empty */
if ((fptr->Fptr)->headend != (fptr->Fptr)->headstart[(fptr->Fptr)->curhdu] )
ffcrhd(fptr, status);
/* write the required header keywords */
ffphprll(fptr, TRUE, bitpix, naxis, naxes, 0, 1, TRUE, status);
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffcrtb(fitsfile *fptr, /* I - FITS file pointer */
int tbltype, /* I - type of table to create */
LONGLONG naxis2, /* I - number of rows in the table */
int tfields, /* I - number of columns in the table */
char **ttype, /* I - name of each column */
char **tform, /* I - value of TFORMn keyword for each column */
char **tunit, /* I - value of TUNITn keyword for each column */
const char *extnm, /* I - value of EXTNAME keyword, if any */
int *status) /* IO - error status */
/*
Create a table extension in a FITS file.
*/
{
LONGLONG naxis1 = 0;
long *tbcol = 0;
if (*status > 0)
return(*status);
if (fptr->HDUposition != (fptr->Fptr)->curhdu)
ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status);
/* create new extension if current header is not empty */
if ((fptr->Fptr)->headend != (fptr->Fptr)->headstart[(fptr->Fptr)->curhdu] )
ffcrhd(fptr, status);
if ((fptr->Fptr)->curhdu == 0) /* have to create dummy primary array */
{
ffcrim(fptr, 16, 0, tbcol, status);
ffcrhd(fptr, status);
}
if (tbltype == BINARY_TBL)
{
/* write the required header keywords. This will write PCOUNT = 0 */
ffphbn(fptr, naxis2, tfields, ttype, tform, tunit, extnm, 0, status);
}
else if (tbltype == ASCII_TBL)
{
/* write the required header keywords */
/* default values for naxis1 and tbcol will be calculated */
ffphtb(fptr, naxis1, naxis2, tfields, ttype, tbcol, tform, tunit,
extnm, status);
}
else
*status = NOT_TABLE;
return(*status);
}
/*-------------------------------------------------------------------------*/
int ffpktp(fitsfile *fptr, /* I - FITS file pointer */
const char *filename, /* I - name of template file */
int *status) /* IO - error status */
/*
read keywords from template file and append to the FITS file
*/
{
FILE *diskfile;
char card[FLEN_CARD], template[161];
char keyname[FLEN_KEYWORD], newname[FLEN_KEYWORD];
int keytype;
size_t slen;
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
diskfile = fopen(filename,"r");
if (!diskfile) /* couldn't open file */
{
ffpmsg("ffpktp could not open the following template file:");
ffpmsg(filename);
return(*status = FILE_NOT_OPENED);
}
while (fgets(template, 160, diskfile) ) /* get next template line */
{
template[160] = '\0'; /* make sure string is terminated */
slen = strlen(template); /* get string length */
template[slen - 1] = '\0'; /* over write the 'newline' char */
if (ffgthd(template, card, &keytype, status) > 0) /* parse template */
break;
strncpy(keyname, card, 8);
keyname[8] = '\0';
if (keytype == -2) /* rename the card */
{
strncpy(newname, &card[40], 8);
newname[8] = '\0';
ffmnam(fptr, keyname, newname, status);
}
else if (keytype == -1) /* delete the card */
{
ffdkey(fptr, keyname, status);
}
else if (keytype == 0) /* update the card */
{
ffucrd(fptr, keyname, card, status);
}
else if (keytype == 1) /* append the card */
{
ffprec(fptr, card, status);
}
else /* END card; stop here */
{
break;
}
}
fclose(diskfile); /* close the template file */
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpky( fitsfile *fptr, /* I - FITS file pointer */
int datatype, /* I - datatype of the value */
const char *keyname,/* I - name of keyword to write */
void *value, /* I - keyword value */
const char *comm, /* I - keyword comment */
int *status) /* IO - error status */
/*
Write (put) the keyword, value and comment into the FITS header.
Writes a keyword value with the datatype specified by the 2nd argument.
*/
{
char errmsg[FLEN_ERRMSG];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
if (datatype == TSTRING)
{
ffpkys(fptr, keyname, (char *) value, comm, status);
}
else if (datatype == TBYTE)
{
ffpkyj(fptr, keyname, (LONGLONG) *(unsigned char *) value, comm, status);
}
else if (datatype == TSBYTE)
{
ffpkyj(fptr, keyname, (LONGLONG) *(signed char *) value, comm, status);
}
else if (datatype == TUSHORT)
{
ffpkyj(fptr, keyname, (LONGLONG) *(unsigned short *) value, comm, status);
}
else if (datatype == TSHORT)
{
ffpkyj(fptr, keyname, (LONGLONG) *(short *) value, comm, status);
}
else if (datatype == TUINT)
{
ffpkyg(fptr, keyname, (double) *(unsigned int *) value, 0,
comm, status);
}
else if (datatype == TINT)
{
ffpkyj(fptr, keyname, (LONGLONG) *(int *) value, comm, status);
}
else if (datatype == TLOGICAL)
{
ffpkyl(fptr, keyname, *(int *) value, comm, status);
}
else if (datatype == TULONG)
{
ffpkyuj(fptr, keyname, (ULONGLONG) *(unsigned long *) value,
comm, status);
}
else if (datatype == TULONGLONG)
{
ffpkyuj(fptr, keyname, (ULONGLONG) *(ULONGLONG *) value,
comm, status);
}
else if (datatype == TLONG)
{
ffpkyj(fptr, keyname, (LONGLONG) *(long *) value, comm, status);
}
else if (datatype == TLONGLONG)
{
ffpkyj(fptr, keyname, *(LONGLONG *) value, comm, status);
}
else if (datatype == TFLOAT)
{
ffpkye(fptr, keyname, *(float *) value, -7, comm, status);
}
else if (datatype == TDOUBLE)
{
ffpkyd(fptr, keyname, *(double *) value, -15, comm, status);
}
else if (datatype == TCOMPLEX)
{
ffpkyc(fptr, keyname, (float *) value, -7, comm, status);
}
else if (datatype == TDBLCOMPLEX)
{
ffpkym(fptr, keyname, (double *) value, -15, comm, status);
}
else
{
snprintf(errmsg, FLEN_ERRMSG,"Bad keyword datatype code: %d (ffpky)", datatype);
ffpmsg(errmsg);
*status = BAD_DATATYPE;
}
return(*status);
}
/*-------------------------------------------------------------------------*/
int ffprec(fitsfile *fptr, /* I - FITS file pointer */
const char *card, /* I - string to be written */
int *status) /* IO - error status */
/*
write a keyword record (80 bytes long) to the end of the header
*/
{
char tcard[FLEN_CARD];
size_t len, ii;
long nblocks;
int keylength;
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
if (fptr->HDUposition != (fptr->Fptr)->curhdu)
ffmahd(fptr, (fptr->HDUposition) + 1, NULL, status);
if ( ((fptr->Fptr)->datastart - (fptr->Fptr)->headend) == 80) /* no room */
{
nblocks = 1;
if (ffiblk(fptr, nblocks, 0, status) > 0) /* insert 2880-byte block */
return(*status);
}
strncpy(tcard,card,80);
tcard[80] = '\0';
len = strlen(tcard);
/* silently replace any illegal characters with a space */
for (ii=0; ii < len; ii++)
if (tcard[ii] < ' ' || tcard[ii] > 126) tcard[ii] = ' ';
for (ii=len; ii < 80; ii++) /* fill card with spaces if necessary */
tcard[ii] = ' ';
keylength = strcspn(tcard, "="); /* support for free-format keywords */
if (keylength == 80) keylength = 8;
/* test for the common commentary keywords which by definition have 8-char names */
if ( !fits_strncasecmp( "COMMENT ", tcard, 8) || !fits_strncasecmp( "HISTORY ", tcard, 8) ||
!fits_strncasecmp( " ", tcard, 8) || !fits_strncasecmp( "CONTINUE", tcard, 8) )
keylength = 8;
for (ii=0; ii < keylength; ii++) /* make sure keyword name is uppercase */
tcard[ii] = toupper(tcard[ii]);
fftkey(tcard, status); /* test keyword name contains legal chars */
/* no need to do this any more, since any illegal characters have been removed
fftrec(tcard, status); */ /* test rest of keyword for legal chars */
ffmbyt(fptr, (fptr->Fptr)->headend, IGNORE_EOF, status); /* move to end */
ffpbyt(fptr, 80, tcard, status); /* write the 80 byte card */
if (*status <= 0)
(fptr->Fptr)->headend += 80; /* update end-of-header position */
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpkyu( fitsfile *fptr, /* I - FITS file pointer */
const char *keyname,/* I - name of keyword to write */
const char *comm, /* I - keyword comment */
int *status) /* IO - error status */
/*
Write (put) a null-valued keyword and comment into the FITS header.
*/
{
char valstring[FLEN_VALUE];
char card[FLEN_CARD];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
strcpy(valstring," "); /* create a dummy value string */
ffmkky(keyname, valstring, comm, card, status); /* construct the keyword */
ffprec(fptr, card, status);
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpkys( fitsfile *fptr, /* I - FITS file pointer */
const char *keyname,/* I - name of keyword to write */
const char *value, /* I - keyword value */
const char *comm, /* I - keyword comment */
int *status) /* IO - error status */
/*
Write (put) the keyword, value and comment into the FITS header.
The value string will be truncated at 68 characters which is the
maximum length that will fit on a single FITS keyword.
*/
{
char valstring[FLEN_VALUE];
char card[FLEN_CARD];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
ffs2c(value, valstring, status); /* put quotes around the string */
ffmkky(keyname, valstring, comm, card, status); /* construct the keyword */
ffprec(fptr, card, status);
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpkls( fitsfile *fptr, /* I - FITS file pointer */
const char *keyname,/* I - name of keyword to write */
const char *value, /* I - keyword value */
const char *comm, /* I - keyword comment */
int *status) /* IO - error status */
/*
Write (put) the keyword, value and comment into the FITS header.
This routine is a modified version of ffpkys which supports the
HEASARC long string convention and can write arbitrarily long string
keyword values. The value is continued over multiple keywords that
have the name COMTINUE without an equal sign in column 9 of the card.
This routine also supports simple string keywords which are less than
69 characters in length.
*/
{
char valstring[FLEN_CARD];
char card[FLEN_CARD], tmpkeyname[FLEN_CARD];
char tstring[FLEN_CARD], *cptr;
int next, remain, vlen, nquote, nchar, namelen, contin, tstatus = -1;
int commlen=0, nocomment = 0;
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
remain = maxvalue(strlen(value), 1); /* no. of chars to write (at least 1) */
if (comm) {
commlen = strlen(comm);
if (commlen > 47) commlen = 47; /* only guarantee preserving the first 47 characters */
}
/* count the number of single quote characters are in the string */
tstring[0] = '\0';
strncat(tstring, value, 68); /* copy 1st part of string to temp buff */
nquote = 0;
cptr = strchr(tstring, '\''); /* search for quote character */
while (cptr) /* search for quote character */
{
nquote++; /* increment no. of quote characters */
cptr++; /* increment pointer to next character */
cptr = strchr(cptr, '\''); /* search for another quote char */
}
strncpy(tmpkeyname, keyname, 80);
tmpkeyname[80] = '\0';
cptr = tmpkeyname;
while(*cptr == ' ') /* skip over leading spaces in name */
cptr++;
/* determine the number of characters that will fit on the line */
/* Note: each quote character is expanded to 2 quotes */
namelen = strlen(cptr);
if (namelen <= 8 && (fftkey(cptr, &tstatus) <= 0) )
{
/* This a normal 8-character FITS keyword */
nchar = 68 - nquote; /* max of 68 chars fit in a FITS string value */
}
else
{
nchar = 80 - nquote - namelen - 5;
}
contin = 0;
next = 0; /* pointer to next character to write */
while (remain > 0)
{
tstring[0] = '\0';
strncat(tstring, &value[next], nchar); /* copy string to temp buff */
ffs2c(tstring, valstring, status); /* expand quotes, and put quotes around the string */
if (remain > nchar) /* if string is continued, put & as last char */
{
vlen = strlen(valstring);
nchar -= 1; /* outputting one less character now */
if (valstring[vlen-2] != '\'')
valstring[vlen-2] = '&'; /* over write last char with & */
else
{ /* last char was a pair of single quotes, so over write both */
valstring[vlen-3] = '&';
valstring[vlen-1] = '\0';
}
}
if (contin) /* This is a CONTINUEd keyword */
{
if (nocomment) {
ffmkky("CONTINUE", valstring, NULL, card, status); /* make keyword w/o comment */
} else {
ffmkky("CONTINUE", valstring, comm, card, status); /* make keyword */
}
strncpy(&card[8], " ", 2); /* overwrite the '=' */
}
else
{
ffmkky(keyname, valstring, comm, card, status); /* make keyword */
}
ffprec(fptr, card, status); /* write the keyword */
contin = 1;
remain -= nchar;
next += nchar;
nocomment = 0;
if (remain > 0)
{
/* count the number of single quote characters in next section */
tstring[0] = '\0';
strncat(tstring, &value[next], 68); /* copy next part of string */
nquote = 0;
cptr = strchr(tstring, '\''); /* search for quote character */
while (cptr) /* search for quote character */
{
nquote++; /* increment no. of quote characters */
cptr++; /* increment pointer to next character */
cptr = strchr(cptr, '\''); /* search for another quote char */
}
nchar = 68 - nquote; /* max number of chars to write this time */
}
/* make adjustment if necessary to allow reasonable room for a comment on last CONTINUE card
only need to do this if
a) there is a comment string, and
b) the remaining value string characters could all fit on the next CONTINUE card, and
c) there is not enough room on the next CONTINUE card for both the remaining value
characters, and at least 47 characters of the comment string.
*/
if (commlen > 0 && remain + nquote < 69 && remain + nquote + commlen > 65)
{
if (nchar > 18) { /* only false if there are a rediculous number of quotes in the string */
nchar = remain - 15; /* force continuation onto another card, so that */
/* there is room for a comment up to 47 chara long */
nocomment = 1; /* don't write the comment string this time */
}
}
}
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffplsw( fitsfile *fptr, /* I - FITS file pointer */
int *status) /* IO - error status */
/*
Write the LONGSTRN keyword and a series of related COMMENT keywords
which document that this FITS header may contain long string keyword
values which are continued over multiple keywords using the HEASARC
long string keyword convention. If the LONGSTRN keyword already exists
then this routine simple returns without doing anything.
*/
{
char valstring[FLEN_VALUE], comm[FLEN_COMMENT];
int tstatus;
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
tstatus = 0;
if (ffgkys(fptr, "LONGSTRN", valstring, comm, &tstatus) == 0)
return(*status); /* keyword already exists, so just return */
ffpkys(fptr, "LONGSTRN", "OGIP 1.0",
"The HEASARC Long String Convention may be used.", status);
ffpcom(fptr,
" This FITS file may contain long string keyword values that are", status);
ffpcom(fptr,
" continued over multiple keywords. The HEASARC convention uses the &",
status);
ffpcom(fptr,
" character at the end of each substring which is then continued", status);
ffpcom(fptr,
" on the next keyword which has the name CONTINUE.", status);
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpkyl( fitsfile *fptr, /* I - FITS file pointer */
const char *keyname,/* I - name of keyword to write */
int value, /* I - keyword value */
const char *comm, /* I - keyword comment */
int *status) /* IO - error status */
/*
Write (put) the keyword, value and comment into the FITS header.
Values equal to 0 will result in a False FITS keyword; any other
non-zero value will result in a True FITS keyword.
*/
{
char valstring[FLEN_VALUE];
char card[FLEN_CARD];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
ffl2c(value, valstring, status); /* convert to formatted string */
ffmkky(keyname, valstring, comm, card, status); /* construct the keyword*/
ffprec(fptr, card, status); /* write the keyword*/
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpkyj( fitsfile *fptr, /* I - FITS file pointer */
const char *keyname,/* I - name of keyword to write */
LONGLONG value, /* I - keyword value */
const char *comm, /* I - keyword comment */
int *status) /* IO - error status */
/*
Write (put) the keyword, value and comment into the FITS header.
Writes an integer keyword value.
*/
{
char valstring[FLEN_VALUE];
char card[FLEN_CARD];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
ffi2c(value, valstring, status); /* convert to formatted string */
ffmkky(keyname, valstring, comm, card, status); /* construct the keyword*/
ffprec(fptr, card, status); /* write the keyword*/
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpkyuj( fitsfile *fptr, /* I - FITS file pointer */
const char *keyname,/* I - name of keyword to write */
ULONGLONG value, /* I - keyword value */
const char *comm, /* I - keyword comment */
int *status) /* IO - error status */
/*
Write (put) the keyword, value and comment into the FITS header.
Writes an integer keyword value.
*/
{
char valstring[FLEN_VALUE];
char card[FLEN_CARD];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
ffu2c(value, valstring, status); /* convert to formatted string */
ffmkky(keyname, valstring, comm, card, status); /* construct the keyword*/
ffprec(fptr, card, status); /* write the keyword*/
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpkyf( fitsfile *fptr, /* I - FITS file pointer */
const char *keyname,/* I - name of keyword to write */
float value, /* I - keyword value */
int decim, /* I - number of decimal places to display */
const char *comm, /* I - keyword comment */
int *status) /* IO - error status */
/*
Write (put) the keyword, value and comment into the FITS header.
Writes a fixed float keyword value.
*/
{
char valstring[FLEN_VALUE];
char card[FLEN_CARD];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
ffr2f(value, decim, valstring, status); /* convert to formatted string */
ffmkky(keyname, valstring, comm, card, status); /* construct the keyword*/
ffprec(fptr, card, status); /* write the keyword*/
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpkye( fitsfile *fptr, /* I - FITS file pointer */
const char *keyname,/* I - name of keyword to write */
float value, /* I - keyword value */
int decim, /* I - number of decimal places to display */
const char *comm, /* I - keyword comment */
int *status) /* IO - error status */
/*
Write (put) the keyword, value and comment into the FITS header.
Writes an exponential float keyword value.
*/
{
char valstring[FLEN_VALUE];
char card[FLEN_CARD];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
ffr2e(value, decim, valstring, status); /* convert to formatted string */
ffmkky(keyname, valstring, comm, card, status); /* construct the keyword*/
ffprec(fptr, card, status); /* write the keyword*/
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpkyg( fitsfile *fptr, /* I - FITS file pointer */
const char *keyname,/* I - name of keyword to write */
double value, /* I - keyword value */
int decim, /* I - number of decimal places to display */
const char *comm, /* I - keyword comment */
int *status) /* IO - error status */
/*
Write (put) the keyword, value and comment into the FITS header.
Writes a fixed double keyword value.*/
{
char valstring[FLEN_VALUE];
char card[FLEN_CARD];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
ffd2f(value, decim, valstring, status); /* convert to formatted string */
ffmkky(keyname, valstring, comm, card, status); /* construct the keyword*/
ffprec(fptr, card, status); /* write the keyword*/
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpkyd( fitsfile *fptr, /* I - FITS file pointer */
const char *keyname,/* I - name of keyword to write */
double value, /* I - keyword value */
int decim, /* I - number of decimal places to display */
const char *comm, /* I - keyword comment */
int *status) /* IO - error status */
/*
Write (put) the keyword, value and comment into the FITS header.
Writes an exponential double keyword value.*/
{
char valstring[FLEN_VALUE];
char card[FLEN_CARD];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
ffd2e(value, decim, valstring, status); /* convert to formatted string */
ffmkky(keyname, valstring, comm, card, status); /* construct the keyword*/
ffprec(fptr, card, status); /* write the keyword*/
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpkyc( fitsfile *fptr, /* I - FITS file pointer */
const char *keyname,/* I - name of keyword to write */
float *value, /* I - keyword value (real, imaginary) */
int decim, /* I - number of decimal places to display */
const char *comm, /* I - keyword comment */
int *status) /* IO - error status */
/*
Write (put) the keyword, value and comment into the FITS header.
Writes an complex float keyword value. Format = (realvalue, imagvalue)
*/
{
char valstring[FLEN_VALUE], tmpstring[FLEN_VALUE];
char card[FLEN_CARD];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
strcpy(valstring, "(" );
ffr2e(value[0], decim, tmpstring, status); /* convert to string */
if (strlen(valstring)+strlen(tmpstring)+2 > FLEN_VALUE-1)
{
ffpmsg("Error converting complex to string (ffpkyc)");
return(*status=BAD_F2C);
}
strcat(valstring, tmpstring);
strcat(valstring, ", ");
ffr2e(value[1], decim, tmpstring, status); /* convert to string */
if (strlen(valstring)+strlen(tmpstring)+1 > FLEN_VALUE-1)
{
ffpmsg("Error converting complex to string (ffpkyc)");
return(*status=BAD_F2C);
}
strcat(valstring, tmpstring);
strcat(valstring, ")");
ffmkky(keyname, valstring, comm, card, status); /* construct the keyword*/
ffprec(fptr, card, status); /* write the keyword*/
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpkym( fitsfile *fptr, /* I - FITS file pointer */
const char *keyname,/* I - name of keyword to write */
double *value, /* I - keyword value (real, imaginary) */
int decim, /* I - number of decimal places to display */
const char *comm, /* I - keyword comment */
int *status) /* IO - error status */
/*
Write (put) the keyword, value and comment into the FITS header.
Writes an complex double keyword value. Format = (realvalue, imagvalue)
*/
{
char valstring[FLEN_VALUE], tmpstring[FLEN_VALUE];
char card[FLEN_CARD];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
strcpy(valstring, "(" );
ffd2e(value[0], decim, tmpstring, status); /* convert to string */
if (strlen(valstring)+strlen(tmpstring)+2 > FLEN_VALUE-1)
{
ffpmsg("Error converting complex to string (ffpkym)");
return(*status=BAD_F2C);
}
strcat(valstring, tmpstring);
strcat(valstring, ", ");
ffd2e(value[1], decim, tmpstring, status); /* convert to string */
if (strlen(valstring)+strlen(tmpstring)+1 > FLEN_VALUE-1)
{
ffpmsg("Error converting complex to string (ffpkym)");
return(*status=BAD_F2C);
}
strcat(valstring, tmpstring);
strcat(valstring, ")");
ffmkky(keyname, valstring, comm, card, status); /* construct the keyword*/
ffprec(fptr, card, status); /* write the keyword*/
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpkfc( fitsfile *fptr, /* I - FITS file pointer */
const char *keyname,/* I - name of keyword to write */
float *value, /* I - keyword value (real, imaginary) */
int decim, /* I - number of decimal places to display */
const char *comm, /* I - keyword comment */
int *status) /* IO - error status */
/*
Write (put) the keyword, value and comment into the FITS header.
Writes an complex float keyword value. Format = (realvalue, imagvalue)
*/
{
char valstring[FLEN_VALUE], tmpstring[FLEN_VALUE];
char card[FLEN_CARD];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
strcpy(valstring, "(" );
ffr2f(value[0], decim, tmpstring, status); /* convert to string */
if (strlen(valstring)+strlen(tmpstring)+2 > FLEN_VALUE-1)
{
ffpmsg("Error converting complex to string (ffpkfc)");
return(*status=BAD_F2C);
}
strcat(valstring, tmpstring);
strcat(valstring, ", ");
ffr2f(value[1], decim, tmpstring, status); /* convert to string */
if (strlen(valstring)+strlen(tmpstring)+1 > FLEN_VALUE-1)
{
ffpmsg("Error converting complex to string (ffpkfc)");
return(*status=BAD_F2C);
}
strcat(valstring, tmpstring);
strcat(valstring, ")");
ffmkky(keyname, valstring, comm, card, status); /* construct the keyword*/
ffprec(fptr, card, status); /* write the keyword*/
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpkfm( fitsfile *fptr, /* I - FITS file pointer */
const char *keyname,/* I - name of keyword to write */
double *value, /* I - keyword value (real, imaginary) */
int decim, /* I - number of decimal places to display */
const char *comm, /* I - keyword comment */
int *status) /* IO - error status */
/*
Write (put) the keyword, value and comment into the FITS header.
Writes an complex double keyword value. Format = (realvalue, imagvalue)
*/
{
char valstring[FLEN_VALUE], tmpstring[FLEN_VALUE];
char card[FLEN_CARD];
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
strcpy(valstring, "(" );
ffd2f(value[0], decim, tmpstring, status); /* convert to string */
if (strlen(valstring)+strlen(tmpstring)+2 > FLEN_VALUE-1)
{
ffpmsg("Error converting complex to string (ffpkfm)");
return(*status=BAD_F2C);
}
strcat(valstring, tmpstring);
strcat(valstring, ", ");
ffd2f(value[1], decim, tmpstring, status); /* convert to string */
if (strlen(valstring)+strlen(tmpstring)+1 > FLEN_VALUE-1)
{
ffpmsg("Error converting complex to string (ffpkfm)");
return(*status=BAD_F2C);
}
strcat(valstring, tmpstring);
strcat(valstring, ")");
ffmkky(keyname, valstring, comm, card, status); /* construct the keyword*/
ffprec(fptr, card, status); /* write the keyword*/
return(*status);
}
/*--------------------------------------------------------------------------*/
int ffpkyt( fitsfile *fptr, /* I - FITS file pointer */
const char *keyname,/* I - name of keyword to write */
long intval, /* I - integer part of value */
double fraction, /* I - fractional part of value */
const char *comm, /* I - keyword comment */
int *status) /* IO - error status */
/*
Write (put) a 'triple' precision keyword where the integer and
fractional parts of the value are passed in separate parameters to
increase the total amount of numerical precision.
*/
{
char valstring[FLEN_VALUE];
char card[FLEN_CARD];
char fstring[20], *cptr;
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
if (fraction > 1. || fraction < 0.)
{
ffpmsg("fraction must be between 0. and 1. (ffpkyt)");
return(*status = BAD_F2C);
}
ffi2c(intval, valstring, status); /* convert integer to string */
ffd2f(fraction, 16, fstring, status); /* convert to 16 decimal string */
cptr = strchr(fstring, '.'); /* find the decimal point */
if (strlen(valstring)+strlen(cptr) > FLEN_VALUE-1)
{
ffpmsg("converted numerical string too long");
return(*status=BAD_F2C);
}
strcat(valstring, cptr); /* append the fraction to the integer */
ffmkky(keyname, valstring, comm, card, status); /* construct the keyword*/
ffprec(fptr, card, status); /* write the keyword*/
return(*status);
}
/*-----------------------------------------------------------------*/
int ffpcom( fitsfile *fptr, /* I - FITS file pointer */
const char *comm, /* I - comment string */
int *status) /* IO - error status */
/*
Write 1 or more COMMENT keywords. If the comment string is too
long to fit on a single keyword (72 chars) then it will automatically
be continued on multiple CONTINUE keywords.
*/
{
char card[FLEN_CARD];
int len, ii;
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
len = strlen(comm);
ii = 0;
for (; len > 0; len -= 72)
{
strcpy(card, "COMMENT ");
strncat(card, &comm[ii], 72);
ffprec(fptr, card, status);
ii += 72;
}
return(*status);
}
/*-----------------------------------------------------------------*/
int ffphis( fitsfile *fptr, /* I - FITS file pointer */
const char *history, /* I - history string */
int *status) /* IO - error status */
/*
Write 1 or more HISTORY keywords. If the history string is too
long to fit on a single keyword (72 chars) then it will automatically
be continued on multiple HISTORY keywords.
*/
{
char card[FLEN_CARD];
int len, ii;
if (*status > 0) /* inherit input status value if > 0 */
return(*status);
len = strlen(history);
ii = 0;
for (; len > 0; len -= 72)
{
strcpy(card, "HISTORY ");
strncat(card, &history[ii], 72);
ffprec(fptr, card, status);
ii += 72;
}
return(*status);
}
/*-----------------------------------------------------------------*/
int ffpdat( fitsfile *fptr, /* I - FITS file pointer */