1 #include <string.h>
2 #include <stdlib.h>
3 #include "fitsio.h"
4 int main(void);
5
main()6 int main()
7 {
8 /*
9 This is a big and complicated program that tests most of
10 the cfitsio routines. This code does not represent
11 the most efficient method of reading or writing FITS files
12 because this code is primarily designed to stress the cfitsio
13 library routines.
14 */
15 char asciisum[17];
16 unsigned long checksum, datsum;
17 int datastatus, hdustatus, filemode;
18 int status, simple, bitpix, naxis, extend, hdutype, hdunum, tfields;
19 long ii, jj, extvers;
20 int nkeys, nfound, colnum, typecode, signval,nmsg;
21 char cval, cvalstr[2];
22 long repeat, offset, width, jnulval;
23 int anynull;
24 /* float vers; */
25 unsigned char xinarray[21], binarray[21], boutarray[21], bnul;
26 short iinarray[21], ioutarray[21], inul;
27 int kinarray[21], koutarray[21], knul;
28 long jinarray[21], joutarray[21], jnul;
29 float einarray[21], eoutarray[21], enul, cinarray[42];
30 double dinarray[21], doutarray[21], dnul, minarray[42];
31 double scale, zero;
32 long naxes[3], pcount, gcount, npixels, nrows, rowlen, firstpix[3];
33 int existkeys, morekeys, keynum;
34
35 char larray[42], larray2[42], colname[70], tdisp[40], nulstr[40];
36 char oskey[] = "value_string";
37 char iskey[21];
38 int olkey = 1;
39 int ilkey;
40 short oshtkey, ishtkey;
41 long ojkey = 11, ijkey;
42 long otint = 12345678;
43 float ofkey = 12.121212f;
44 float oekey = 13.131313f, iekey;
45 double ogkey = 14.1414141414141414;
46 double odkey = 15.1515151515151515, idkey;
47 double otfrac = .1234567890123456;
48
49 double xrval,yrval,xrpix,yrpix,xinc,yinc,rot,xpos,ypos,xpix,ypix;
50 char xcoordtype[] = "RA---TAN";
51 char ycoordtype[] = "DEC--TAN";
52 char ctype[5];
53
54 char *lsptr; /* pointer to long string value */
55 char comm[73];
56 char *comms[3];
57 char *inskey[21];
58 char *onskey[3] = {"first string", "second string", " "};
59 char *inclist[2] = {"key*", "newikys"};
60 char *exclist[2] = {"key_pr*", "key_pkls"};
61
62 int onlkey[3] = {1, 0, 1}, inlkey[3];
63 long onjkey[3] = {11, 12, 13}, injkey[3];
64 float onfkey[3] = {12.121212f, 13.131313f, 14.141414f};
65 float onekey[3] = {13.131313f, 14.141414f, 15.151515f}, inekey[3];
66 double ongkey[3] = {14.1414141414141414, 15.1515151515151515,
67 16.1616161616161616};
68 double ondkey[3] = {15.1515151515151515, 16.1616161616161616,
69 17.1717171717171717}, indkey[3];
70
71 long tbcol[5] = {1, 17, 28, 43, 56};
72
73 char filename[40], card[FLEN_CARD], card2[FLEN_CARD];
74 char keyword[FLEN_KEYWORD];
75 char value[FLEN_VALUE], comment[FLEN_COMMENT];
76 unsigned char uchars[80];
77
78 fitsfile *fptr, *tmpfptr;
79 char *ttype[10], *tform[10], *tunit[10];
80 char tblname[40];
81 char binname[] = "Test-BINTABLE";
82 char templt[] = "testprog.tpt";
83 char errmsg[FLEN_ERRMSG];
84 short imgarray[30][19], imgarray2[20][10];
85 long fpixels[2], lpixels[2], inc[2];
86
87 status = 0;
88 strcpy(tblname, "Test-ASCII");
89
90 /* ffvers(&vers);
91 printf("CFITSIO TESTPROG, v%.3f\n\n",vers);
92 */
93 printf("CFITSIO TESTPROG\n\n");
94 printf("Try opening then closing a nonexistent file:\n");
95 fits_open_file(&fptr, "tq123x.kjl", READWRITE, &status);
96 printf(" ffopen fptr, status = %lu %d (expect an error)\n",
97 (unsigned long) fptr, status);
98 ffclos(fptr, &status);
99 printf(" ffclos status = %d\n\n", status);
100 ffcmsg();
101 status = 0;
102
103 for (ii = 0; ii < 21; ii++) /* allocate space for string column value */
104 inskey[ii] = (char *) malloc(21);
105
106 for (ii = 0; ii < 10; ii++)
107 {
108 ttype[ii] = (char *) malloc(20);
109 tform[ii] = (char *) malloc(20);
110 tunit[ii] = (char *) malloc(20);
111 }
112
113 comms[0] = comm;
114
115 /* delete previous version of the file, if it exists (with ! prefix) */
116 strcpy(filename, "!testprog.fit");
117
118 status = 0;
119
120 /*
121 #####################
122 # create FITS file #
123 #####################
124 */
125
126 ffinit(&fptr, filename, &status);
127 printf("ffinit create new file status = %d\n", status);
128 if (status)
129 goto errstatus;
130
131 filename[0] = '\0';
132 ffflnm(fptr, filename, &status);
133
134 ffflmd(fptr, &filemode, &status);
135 printf("Name of file = %s, I/O mode = %d\n", filename, filemode);
136 simple = 1;
137 bitpix = 32;
138 naxis = 2;
139 naxes[0] = 10;
140 naxes[1] = 2;
141 npixels = 20;
142 pcount = 0;
143 gcount = 1;
144 extend = 1;
145 /*
146 ############################
147 # write single keywords #
148 ############################
149 */
150
151 if (ffphps(fptr, bitpix, naxis, naxes, &status) > 0)
152 printf("ffphps status = %d\n", status);
153
154 if (ffprec(fptr,
155 "key_prec= 'This keyword was written by fxprec' / comment goes here",
156 &status) > 0 )
157 printf("ffprec status = %d\n", status);
158
159 printf("\ntest writing of long string keywords:\n");
160 strcpy(card, "1234567890123456789012345678901234567890");
161 strcat(card, "12345678901234567890123456789012345");
162 ffpkys(fptr, "card1", card, "", &status);
163 ffgkey(fptr, "card1", card2, comment, &status);
164 printf(" %s\n%s\n", card, card2);
165
166 strcpy(card, "1234567890123456789012345678901234567890");
167 strcat(card, "123456789012345678901234'6789012345");
168 ffpkys(fptr, "card2", card, "", &status);
169 ffgkey(fptr, "card2", card2, comment, &status);
170 printf(" %s\n%s\n", card, card2);
171
172 strcpy(card, "1234567890123456789012345678901234567890");
173 strcat(card, "123456789012345678901234''789012345");
174 ffpkys(fptr, "card3", card, "", &status);
175 ffgkey(fptr, "card3", card2, comment, &status);
176 printf(" %s\n%s\n", card, card2);
177
178 strcpy(card, "1234567890123456789012345678901234567890");
179 strcat(card, "123456789012345678901234567'9012345");
180 ffpkys(fptr, "card4", card, "", &status);
181 ffgkey(fptr, "card4", card2, comment, &status);
182 printf(" %s\n%s\n", card, card2);
183
184 if (ffpkys(fptr, "key_pkys", oskey, "fxpkys comment", &status) > 0)
185 printf("ffpkys status = %d\n", status);
186
187 if (ffpkyl(fptr, "key_pkyl", olkey, "fxpkyl comment", &status) > 0)
188 printf("ffpkyl status = %d\n", status);
189
190 if (ffpkyj(fptr, "key_pkyj", ojkey, "fxpkyj comment", &status) > 0)
191 printf("ffpkyj status = %d\n", status);
192
193 if (ffpkyf(fptr, "key_pkyf", ofkey, 5, "fxpkyf comment", &status) > 0)
194 printf("ffpkyf status = %d\n", status);
195
196 if (ffpkye(fptr, "key_pkye", oekey, 6, "fxpkye comment", &status) > 0)
197 printf("ffpkye status = %d\n", status);
198
199 if (ffpkyg(fptr, "key_pkyg", ogkey, 14, "fxpkyg comment", &status) > 0)
200 printf("ffpkyg status = %d\n", status);
201
202 if (ffpkyd(fptr, "key_pkyd", odkey, 14, "fxpkyd comment", &status) > 0)
203 printf("ffpkyd status = %d\n", status);
204
205 if (ffpkyc(fptr, "key_pkyc", onekey, 6, "fxpkyc comment", &status) > 0)
206 printf("ffpkyc status = %d\n", status);
207
208 if (ffpkym(fptr, "key_pkym", ondkey, 14, "fxpkym comment", &status) > 0)
209 printf("ffpkym status = %d\n", status);
210
211 if (ffpkfc(fptr, "key_pkfc", onekey, 6, "fxpkfc comment", &status) > 0)
212 printf("ffpkfc status = %d\n", status);
213
214 if (ffpkfm(fptr, "key_pkfm", ondkey, 14, "fxpkfm comment", &status) > 0)
215 printf("ffpkfm status = %d\n", status);
216
217 if (ffpkls(fptr, "key_pkls",
218 "This is a very long string value that is continued over more than one keyword.",
219 "fxpkls comment", &status) > 0)
220 printf("ffpkls status = %d\n", status);
221
222 if (ffplsw(fptr, &status) > 0 )
223 printf("ffplsw status = %d\n", status);
224
225 if (ffpkyt(fptr, "key_pkyt", otint, otfrac, "fxpkyt comment", &status) > 0)
226 printf("ffpkyt status = %d\n", status);
227
228 if (ffpcom(fptr, " This keyword was written by fxpcom.", &status) > 0)
229 printf("ffpcom status = %d\n", status);
230
231 if (ffphis(fptr, " This keyword written by fxphis (w/ 2 leading spaces).",
232 &status) > 0)
233 printf("ffphis status = %d\n", status);
234
235 if (ffpdat(fptr, &status) > 0)
236 {
237 printf("ffpdat status = %d\n", status);
238 goto errstatus;
239 }
240
241 /*
242 ###############################
243 # write arrays of keywords #
244 ###############################
245 */
246 nkeys = 3;
247
248 comms[0] = comm; /* use the inskey array of pointers for the comments */
249
250 strcpy(comm, "fxpkns comment&");
251 if (ffpkns(fptr, "ky_pkns", 1, nkeys, onskey, comms, &status) > 0)
252 printf("ffpkns status = %d\n", status);
253
254 strcpy(comm, "fxpknl comment&");
255 if (ffpknl(fptr, "ky_pknl", 1, nkeys, onlkey, comms, &status) > 0)
256 printf("ffpknl status = %d\n", status);
257
258 strcpy(comm, "fxpknj comment&");
259 if (ffpknj(fptr, "ky_pknj", 1, nkeys, onjkey, comms, &status) > 0)
260 printf("ffpknj status = %d\n", status);
261
262 strcpy(comm, "fxpknf comment&");
263 if (ffpknf(fptr, "ky_pknf", 1, nkeys, onfkey, 5, comms, &status) > 0)
264 printf("ffpknf status = %d\n", status);
265
266 strcpy(comm, "fxpkne comment&");
267 if (ffpkne(fptr, "ky_pkne", 1, nkeys, onekey, 6, comms, &status) > 0)
268 printf("ffpkne status = %d\n", status);
269
270 strcpy(comm, "fxpkng comment&");
271 if (ffpkng(fptr, "ky_pkng", 1, nkeys, ongkey, 13, comms, &status) > 0)
272 printf("ffpkng status = %d\n", status);
273
274 strcpy(comm, "fxpknd comment&");
275 if (ffpknd(fptr, "ky_pknd", 1, nkeys, ondkey, 14, comms, &status) > 0)
276 {
277 printf("ffpknd status = %d\n", status);
278 goto errstatus;
279 }
280 /*
281 ############################
282 # write generic keywords #
283 ############################
284 */
285
286 strcpy(oskey, "1");
287 if (ffpky(fptr, TSTRING, "tstring", oskey, "tstring comment", &status) > 0)
288 printf("ffpky status = %d\n", status);
289
290 olkey = TLOGICAL;
291 if (ffpky(fptr, TLOGICAL, "tlogical", &olkey, "tlogical comment",
292 &status) > 0)
293 printf("ffpky status = %d\n", status);
294
295 cval = TBYTE;
296 if (ffpky(fptr, TBYTE, "tbyte", &cval, "tbyte comment", &status) > 0)
297 printf("ffpky status = %d\n", status);
298
299 oshtkey = TSHORT;
300 if (ffpky(fptr, TSHORT, "tshort", &oshtkey, "tshort comment", &status) > 0)
301 printf("ffpky status = %d\n", status);
302
303 olkey = TINT;
304 if (ffpky(fptr, TINT, "tint", &olkey, "tint comment", &status) > 0)
305 printf("ffpky status = %d\n", status);
306
307 ojkey = TLONG;
308 if (ffpky(fptr, TLONG, "tlong", &ojkey, "tlong comment", &status) > 0)
309 printf("ffpky status = %d\n", status);
310
311 oekey = TFLOAT;
312 if (ffpky(fptr, TFLOAT, "tfloat", &oekey, "tfloat comment", &status) > 0)
313 printf("ffpky status = %d\n", status);
314
315 odkey = TDOUBLE;
316 if (ffpky(fptr, TDOUBLE, "tdouble", &odkey, "tdouble comment",
317 &status) > 0)
318 printf("ffpky status = %d\n", status);
319
320 /*
321 ############################
322 # write data #
323 ############################
324 */
325 /* define the null value (must do this before writing any data) */
326 if (ffpkyj(fptr, "BLANK", -99, "value to use for undefined pixels",
327 &status) > 0)
328 printf("BLANK keyword status = %d\n", status);
329
330 /* initialize arrays of values to write to primary array */
331 for (ii = 0; ii < npixels; ii++)
332 {
333 boutarray[ii] = (unsigned char) (ii + 1);
334 ioutarray[ii] = (short) (ii + 1);
335 joutarray[ii] = ii + 1;
336 eoutarray[ii] = (float) (ii + 1);
337 doutarray[ii] = ii + 1;
338 }
339
340 /* write a few pixels with each datatype */
341 /* set the last value in each group of 4 as undefined */
342
343 /*
344 ffpprb(fptr, 1, 1, 2, &boutarray[0], &status);
345 ffppri(fptr, 1, 5, 2, &ioutarray[4], &status);
346 ffpprj(fptr, 1, 9, 2, &joutarray[8], &status);
347 ffppre(fptr, 1, 13, 2, &eoutarray[12], &status);
348 ffpprd(fptr, 1, 17, 2, &doutarray[16], &status);
349 */
350
351 /* test the newer ffpx routine, instead of the older ffppr_ routines */
352 firstpix[0]=1;
353 firstpix[1]=1;
354 ffppx(fptr, TBYTE, firstpix, 2, &boutarray[0], &status);
355 firstpix[0]=5;
356 ffppx(fptr, TSHORT, firstpix, 2, &ioutarray[4], &status);
357 firstpix[0]=9;
358 ffppx(fptr, TLONG, firstpix, 2, &joutarray[8], &status);
359 firstpix[0]=3;
360 firstpix[1]=2;
361 ffppx(fptr, TFLOAT, firstpix, 2, &eoutarray[12], &status);
362 firstpix[0]=7;
363 ffppx(fptr, TDOUBLE, firstpix, 2, &doutarray[16], &status);
364
365 /*
366 ffppnb(fptr, 1, 3, 2, &boutarray[2], 4, &status);
367 ffppni(fptr, 1, 7, 2, &ioutarray[6], 8, &status);
368 ffppnj(fptr, 1, 11, 2, &joutarray[10], 12, &status);
369 ffppne(fptr, 1, 15, 2, &eoutarray[14], 16., &status);
370 ffppnd(fptr, 1, 19, 2, &doutarray[18], 20., &status);
371 */
372 firstpix[0]=3;
373 firstpix[1]=1;
374 bnul = 4;
375 ffppxn(fptr, TBYTE, firstpix, 2, &boutarray[2], &bnul, &status);
376 firstpix[0]=7;
377 inul = 8;
378 ffppxn(fptr, TSHORT, firstpix, 2, &ioutarray[6], &inul, &status);
379 firstpix[0]=1;
380 firstpix[1]=2;
381 jnul = 12;
382 ffppxn(fptr, TLONG, firstpix, 2, &joutarray[10], &jnul, &status);
383 firstpix[0]=5;
384 enul = 16.;
385 ffppxn(fptr, TFLOAT, firstpix, 2, &eoutarray[14], &enul, &status);
386 firstpix[0]=9;
387 dnul = 20.;
388 ffppxn(fptr, TDOUBLE, firstpix, 2, &doutarray[18], &dnul, &status);
389
390 ffppru(fptr, 1, 1, 1, &status);
391
392
393 if (status > 0)
394 {
395 printf("ffppnx status = %d\n", status);
396 goto errstatus;
397 }
398
399 ffflus(fptr, &status); /* flush all data to the disk file */
400 printf("ffflus status = %d\n", status);
401 printf("HDU number = %d\n", ffghdn(fptr, &hdunum));
402
403 /*
404 ############################
405 # read data #
406 ############################
407 */
408 /* read back the data, setting null values = 99 */
409 printf("\nValues read back from primary array (99 = null pixel)\n");
410 printf("The 1st, and every 4th pixel should be undefined:\n");
411
412 anynull = 0;
413 ffgpvb(fptr, 1, 1, 10, 99, binarray, &anynull, &status);
414
415 ffgpvb(fptr, 1, 11, 10, 99, &binarray[10], &anynull, &status);
416
417 for (ii = 0; ii < npixels; ii++)
418 printf(" %2d", binarray[ii]);
419 printf(" %d (ffgpvb)\n", anynull);
420
421 ffgpvi(fptr, 1, 1, npixels, 99, iinarray, &anynull, &status);
422
423 for (ii = 0; ii < npixels; ii++)
424 printf(" %2d", iinarray[ii]);
425 printf(" %d (ffgpvi)\n", anynull);
426
427 ffgpvj(fptr, 1, 1, npixels, 99, jinarray, &anynull, &status);
428
429 for (ii = 0; ii < npixels; ii++)
430 printf(" %2ld", jinarray[ii]);
431 printf(" %d (ffgpvj)\n", anynull);
432
433 ffgpve(fptr, 1, 1, npixels, 99., einarray, &anynull, &status);
434
435 for (ii = 0; ii < npixels; ii++)
436 printf(" %2.0f", einarray[ii]);
437 printf(" %d (ffgpve)\n", anynull);
438
439 ffgpvd(fptr, 1, 1, 10, 99., dinarray, &anynull, &status);
440 ffgpvd(fptr, 1, 11, 10, 99., &dinarray[10], &anynull, &status);
441
442 for (ii = 0; ii < npixels; ii++)
443 printf(" %2.0f", dinarray[ii]);
444 printf(" %d (ffgpvd)\n", anynull);
445
446 if (status > 0)
447 {
448 printf("ERROR: ffgpv_ status = %d\n", status);
449 goto errstatus;
450 }
451 if (anynull == 0)
452 printf("ERROR: ffgpv_ did not detect null values\n");
453
454 /* reset the output null value to the expected input value */
455 for (ii = 3; ii < npixels; ii += 4)
456 {
457 boutarray[ii] = 99;
458 ioutarray[ii] = 99;
459 joutarray[ii] = 99;
460 eoutarray[ii] = 99.;
461 doutarray[ii] = 99.;
462 }
463 ii = 0;
464 boutarray[ii] = 99;
465 ioutarray[ii] = 99;
466 joutarray[ii] = 99;
467 eoutarray[ii] = 99.;
468 doutarray[ii] = 99.;
469
470 /* compare the output with the input; flag any differences */
471 for (ii = 0; ii < npixels; ii++)
472 {
473 if (boutarray[ii] != binarray[ii])
474 printf("bout != bin = %u %u \n", boutarray[ii], binarray[ii]);
475
476 if (ioutarray[ii] != iinarray[ii])
477 printf("iout != iin = %d %d \n", ioutarray[ii], iinarray[ii]);
478
479 if (joutarray[ii] != jinarray[ii])
480 printf("jout != jin = %ld %ld \n", joutarray[ii], jinarray[ii]);
481
482 if (eoutarray[ii] != einarray[ii])
483 printf("eout != ein = %f %f \n", eoutarray[ii], einarray[ii]);
484
485 if (doutarray[ii] != dinarray[ii])
486 printf("dout != din = %f %f \n", doutarray[ii], dinarray[ii]);
487 }
488
489 for (ii = 0; ii < npixels; ii++)
490 {
491 binarray[ii] = 0;
492 iinarray[ii] = 0;
493 jinarray[ii] = 0;
494 einarray[ii] = 0.;
495 dinarray[ii] = 0.;
496 }
497
498 anynull = 0;
499 ffgpfb(fptr, 1, 1, 10, binarray, larray, &anynull, &status);
500 ffgpfb(fptr, 1, 11, 10, &binarray[10], &larray[10], &anynull, &status);
501
502 for (ii = 0; ii < npixels; ii++)
503 if (larray[ii])
504 printf(" *");
505 else
506 printf(" %2d", binarray[ii]);
507 printf(" %d (ffgpfb)\n", anynull);
508
509 ffgpfi(fptr, 1, 1, npixels, iinarray, larray, &anynull, &status);
510
511 for (ii = 0; ii < npixels; ii++)
512 if (larray[ii])
513 printf(" *");
514 else
515 printf(" %2d", iinarray[ii]);
516 printf(" %d (ffgpfi)\n", anynull);
517
518 ffgpfj(fptr, 1, 1, npixels, jinarray, larray, &anynull, &status);
519
520 for (ii = 0; ii < npixels; ii++)
521 if (larray[ii])
522 printf(" *");
523 else
524 printf(" %2ld", jinarray[ii]);
525 printf(" %d (ffgpfj)\n", anynull);
526
527 ffgpfe(fptr, 1, 1, npixels, einarray, larray, &anynull, &status);
528
529 for (ii = 0; ii < npixels; ii++)
530 if (larray[ii])
531 printf(" *");
532 else
533 printf(" %2.0f", einarray[ii]);
534 printf(" %d (ffgpfe)\n", anynull);
535
536 ffgpfd(fptr, 1, 1, 10, dinarray, larray, &anynull, &status);
537 ffgpfd(fptr, 1, 11, 10, &dinarray[10], &larray[10], &anynull, &status);
538
539 for (ii = 0; ii < npixels; ii++)
540 if (larray[ii])
541 printf(" *");
542 else
543 printf(" %2.0f", dinarray[ii]);
544 printf(" %d (ffgpfd)\n", anynull);
545
546 if (status > 0)
547 {
548 printf("ERROR: ffgpf_ status = %d\n", status);
549 goto errstatus;
550 }
551 if (anynull == 0)
552 printf("ERROR: ffgpf_ did not detect null values\n");
553
554
555 /*
556 ##########################################
557 # close and reopen file multiple times #
558 ##########################################
559 */
560
561 for (ii = 0; ii < 10; ii++)
562 {
563 if (ffclos(fptr, &status) > 0)
564 {
565 printf("ERROR in ftclos (1) = %d", status);
566 goto errstatus;
567 }
568
569 if (fits_open_file(&fptr, filename, READWRITE, &status) > 0)
570 {
571 printf("ERROR: ffopen open file status = %d\n", status);
572 goto errstatus;
573 }
574 }
575 printf("\nClosed then reopened the FITS file 10 times.\n");
576 printf("HDU number = %d\n", ffghdn(fptr, &hdunum));
577
578 filename[0] = '\0';
579 ffflnm(fptr, filename, &status);
580
581 ffflmd(fptr, &filemode, &status);
582 printf("Name of file = %s, I/O mode = %d\n", filename, filemode);
583
584 /*
585 ############################
586 # read single keywords #
587 ############################
588 */
589
590 simple = 0;
591 bitpix = 0;
592 naxis = 0;
593 naxes[0] = 0;
594 naxes[1] = 0;
595 pcount = -99;
596 gcount = -99;
597 extend = -99;
598 printf("\nRead back keywords:\n");
599 ffghpr(fptr, 99, &simple, &bitpix, &naxis, naxes, &pcount,
600 &gcount, &extend, &status);
601 printf("simple = %d, bitpix = %d, naxis = %d, naxes = (%ld, %ld)\n",
602 simple, bitpix, naxis, naxes[0], naxes[1]);
603 printf(" pcount = %ld, gcount = %ld, extend = %d\n",
604 pcount, gcount, extend);
605
606 ffgrec(fptr, 9, card, &status);
607 printf("%s\n", card);
608 if (strncmp(card, "KEY_PREC= 'This", 15) )
609 printf("ERROR in ffgrec\n");
610
611 ffgkyn(fptr, 9, keyword, value, comment, &status);
612 printf("%s : %s : %s :\n",keyword, value, comment);
613 if (strncmp(keyword, "KEY_PREC", 8) )
614 printf("ERROR in ffgkyn: %s\n", keyword);
615
616 ffgcrd(fptr, keyword, card, &status);
617 printf("%s\n", card);
618
619 if (strncmp(keyword, card, 8) )
620 printf("ERROR in ffgcrd: %s\n", keyword);
621
622 ffgkey(fptr, "KY_PKNS1", value, comment, &status);
623 printf("KY_PKNS1 : %s : %s :\n", value, comment);
624
625 if (strncmp(value, "'first string'", 14) )
626 printf("ERROR in ffgkey: %s\n", value);
627
628 ffgkys(fptr, "key_pkys", iskey, comment, &status);
629 printf("KEY_PKYS %s %s %d\n", iskey, comment, status);
630
631 ffgkyl(fptr, "key_pkyl", &ilkey, comment, &status);
632 printf("KEY_PKYL %d %s %d\n", ilkey, comment, status);
633
634 ffgkyj(fptr, "KEY_PKYJ", &ijkey, comment, &status);
635 printf("KEY_PKYJ %ld %s %d\n",ijkey, comment, status);
636
637 ffgkye(fptr, "KEY_PKYJ", &iekey, comment, &status);
638 printf("KEY_PKYJ %f %s %d\n",iekey, comment, status);
639
640 ffgkyd(fptr, "KEY_PKYJ", &idkey, comment, &status);
641 printf("KEY_PKYJ %f %s %d\n",idkey, comment, status);
642
643 if (ijkey != 11 || iekey != 11. || idkey != 11.)
644 printf("ERROR in ffgky[jed]: %ld, %f, %f\n",ijkey, iekey, idkey);
645
646 iskey[0] = '\0';
647 ffgky(fptr, TSTRING, "key_pkys", iskey, comment, &status);
648 printf("KEY_PKY S %s %s %d\n", iskey, comment, status);
649
650 ilkey = 0;
651 ffgky(fptr, TLOGICAL, "key_pkyl", &ilkey, comment, &status);
652 printf("KEY_PKY L %d %s %d\n", ilkey, comment, status);
653
654 ffgky(fptr, TBYTE, "KEY_PKYJ", &cval, comment, &status);
655 printf("KEY_PKY BYTE %d %s %d\n",cval, comment, status);
656
657 ffgky(fptr, TSHORT, "KEY_PKYJ", &ishtkey, comment, &status);
658 printf("KEY_PKY SHORT %d %s %d\n",ishtkey, comment, status);
659
660 ffgky(fptr, TINT, "KEY_PKYJ", &ilkey, comment, &status);
661 printf("KEY_PKY INT %d %s %d\n",ilkey, comment, status);
662
663 ijkey = 0;
664 ffgky(fptr, TLONG, "KEY_PKYJ", &ijkey, comment, &status);
665 printf("KEY_PKY J %ld %s %d\n",ijkey, comment, status);
666
667 iekey = 0;
668 ffgky(fptr, TFLOAT, "KEY_PKYE", &iekey, comment, &status);
669 printf("KEY_PKY E %f %s %d\n",iekey, comment, status);
670
671 idkey = 0;
672 ffgky(fptr, TDOUBLE, "KEY_PKYD", &idkey, comment, &status);
673 printf("KEY_PKY D %f %s %d\n",idkey, comment, status);
674
675 ffgkyd(fptr, "KEY_PKYF", &idkey, comment, &status);
676 printf("KEY_PKYF %f %s %d\n",idkey, comment, status);
677
678 ffgkyd(fptr, "KEY_PKYE", &idkey, comment, &status);
679 printf("KEY_PKYE %f %s %d\n",idkey, comment, status);
680
681 ffgkyd(fptr, "KEY_PKYG", &idkey, comment, &status);
682 printf("KEY_PKYG %.14f %s %d\n",idkey, comment, status);
683
684 ffgkyd(fptr, "KEY_PKYD", &idkey, comment, &status);
685 printf("KEY_PKYD %.14f %s %d\n",idkey, comment, status);
686
687 ffgkyc(fptr, "KEY_PKYC", inekey, comment, &status);
688 printf("KEY_PKYC %f %f %s %d\n",inekey[0], inekey[1], comment, status);
689
690 ffgkyc(fptr, "KEY_PKFC", inekey, comment, &status);
691 printf("KEY_PKFC %f %f %s %d\n",inekey[0], inekey[1], comment, status);
692
693 ffgkym(fptr, "KEY_PKYM", indkey, comment, &status);
694 printf("KEY_PKYM %f %f %s %d\n",indkey[0], indkey[1], comment, status);
695
696 ffgkym(fptr, "KEY_PKFM", indkey, comment, &status);
697 printf("KEY_PKFM %f %f %s %d\n",indkey[0], indkey[1], comment, status);
698
699 ffgkyt(fptr, "KEY_PKYT", &ijkey, &idkey, comment, &status);
700 printf("KEY_PKYT %ld %.14f %s %d\n",ijkey, idkey, comment, status);
701
702 ffpunt(fptr, "KEY_PKYJ", "km/s/Mpc", &status);
703 ijkey = 0;
704 ffgky(fptr, TLONG, "KEY_PKYJ", &ijkey, comment, &status);
705 printf("KEY_PKY J %ld %s %d\n",ijkey, comment, status);
706 ffgunt(fptr,"KEY_PKYJ", comment, &status);
707 printf("KEY_PKY units = %s\n",comment);
708
709 ffpunt(fptr, "KEY_PKYJ", "", &status);
710 ijkey = 0;
711 ffgky(fptr, TLONG, "KEY_PKYJ", &ijkey, comment, &status);
712 printf("KEY_PKY J %ld %s %d\n",ijkey, comment, status);
713 ffgunt(fptr,"KEY_PKYJ", comment, &status);
714 printf("KEY_PKY units = %s\n",comment);
715
716 ffpunt(fptr, "KEY_PKYJ", "feet/second/second", &status);
717 ijkey = 0;
718 ffgky(fptr, TLONG, "KEY_PKYJ", &ijkey, comment, &status);
719 printf("KEY_PKY J %ld %s %d\n",ijkey, comment, status);
720 ffgunt(fptr,"KEY_PKYJ", comment, &status);
721 printf("KEY_PKY units = %s\n",comment);
722
723 ffgkls(fptr, "key_pkls", &lsptr, comment, &status);
724 printf("KEY_PKLS long string value = \n%s\n", lsptr);
725
726 /* free the memory for the long string value */
727 fits_free_memory(lsptr, &status);
728
729 /* get size and position in header */
730 ffghps(fptr, &existkeys, &keynum, &status);
731 printf("header contains %d keywords; located at keyword %d \n",existkeys,
732 keynum);
733
734 /*
735 ############################
736 # read array keywords #
737 ############################
738 */
739 ffgkns(fptr, "ky_pkns", 1, 3, inskey, &nfound, &status);
740 printf("ffgkns: %s, %s, %s\n", inskey[0], inskey[1], inskey[2]);
741 if (nfound != 3 || status > 0)
742 printf("\nERROR in ffgkns %d, %d\n", nfound, status);
743
744 ffgknl(fptr, "ky_pknl", 1, 3, inlkey, &nfound, &status);
745 printf("ffgknl: %d, %d, %d\n", inlkey[0], inlkey[1], inlkey[2]);
746 if (nfound != 3 || status > 0)
747 printf("\nERROR in ffgknl %d, %d\n", nfound, status);
748
749 ffgknj(fptr, "ky_pknj", 1, 3, injkey, &nfound, &status);
750 printf("ffgknj: %ld, %ld, %ld\n", injkey[0], injkey[1], injkey[2]);
751 if (nfound != 3 || status > 0)
752 printf("\nERROR in ffgknj %d, %d\n", nfound, status);
753
754 ffgkne(fptr, "ky_pkne", 1, 3, inekey, &nfound, &status);
755 printf("ffgkne: %f, %f, %f\n", inekey[0], inekey[1], inekey[2]);
756 if (nfound != 3 || status > 0)
757 printf("\nERROR in ffgkne %d, %d\n", nfound, status);
758
759 ffgknd(fptr, "ky_pknd", 1, 3, indkey, &nfound, &status);
760 printf("ffgknd: %f, %f, %f\n", indkey[0], indkey[1], indkey[2]);
761 if (nfound != 3 || status > 0)
762 printf("\nERROR in ffgknd %d, %d\n", nfound, status);
763
764 /* get position of HISTORY keyword for subsequent deletes and inserts */
765 ffgcrd(fptr, "HISTORY", card, &status);
766 ffghps(fptr, &existkeys, &keynum, &status);
767 keynum -= 2;
768
769 printf("\nBefore deleting the HISTORY and DATE keywords...\n");
770 for (ii = keynum; ii <= keynum + 3; ii++)
771 {
772 ffgrec(fptr, ii, card, &status);
773 printf("%.8s\n", card); /* don't print date value, so that */
774 } /* the output will always be the same */
775 /*
776 ############################
777 # delete keywords #
778 ############################
779 */
780
781 ffdrec(fptr, keynum + 1, &status);
782 ffdkey(fptr, "DATE", &status);
783
784 printf("\nAfter deleting the keywords...\n");
785 for (ii = keynum; ii <= keynum + 1; ii++)
786 {
787 ffgrec(fptr, ii, card, &status);
788 printf("%s\n", card);
789 }
790
791 if (status > 0)
792 printf("\nERROR deleting keywords\n");
793 /*
794 ############################
795 # insert keywords #
796 ############################
797 */
798 keynum += 4;
799 ffirec(fptr, keynum - 3, "KY_IREC = 'This keyword inserted by fxirec'",
800 &status);
801 ffikys(fptr, "KY_IKYS", "insert_value_string", "ikys comment", &status);
802 ffikyj(fptr, "KY_IKYJ", 49, "ikyj comment", &status);
803 ffikyl(fptr, "KY_IKYL", 1, "ikyl comment", &status);
804 ffikye(fptr, "KY_IKYE", 12.3456f, 4, "ikye comment", &status);
805 ffikyd(fptr, "KY_IKYD", 12.345678901234567, 14, "ikyd comment", &status);
806 ffikyf(fptr, "KY_IKYF", 12.3456f, 4, "ikyf comment", &status);
807 ffikyg(fptr, "KY_IKYG", 12.345678901234567, 13, "ikyg comment", &status);
808
809 printf("\nAfter inserting the keywords...\n");
810 for (ii = keynum - 4; ii <= keynum + 5; ii++)
811 {
812 ffgrec(fptr, ii, card, &status);
813 printf("%s\n", card);
814 }
815
816 if (status > 0)
817 printf("\nERROR inserting keywords\n");
818 /*
819 ############################
820 # modify keywords #
821 ############################
822 */
823 ffmrec(fptr, keynum - 4, "COMMENT This keyword was modified by fxmrec", &status);
824 ffmcrd(fptr, "KY_IREC", "KY_MREC = 'This keyword was modified by fxmcrd'",
825 &status);
826 ffmnam(fptr, "KY_IKYS", "NEWIKYS", &status);
827
828 ffmcom(fptr, "KY_IKYJ","This is a modified comment", &status);
829 ffmkyj(fptr, "KY_IKYJ", 50, "&", &status);
830 ffmkyl(fptr, "KY_IKYL", 0, "&", &status);
831 ffmkys(fptr, "NEWIKYS", "modified_string", "&", &status);
832 ffmkye(fptr, "KY_IKYE", -12.3456f, 4, "&", &status);
833 ffmkyd(fptr, "KY_IKYD", -12.345678901234567, 14, "modified comment",
834 &status);
835 ffmkyf(fptr, "KY_IKYF", -12.3456f, 4, "&", &status);
836 ffmkyg(fptr, "KY_IKYG", -12.345678901234567, 13, "&", &status);
837
838 printf("\nAfter modifying the keywords...\n");
839 for (ii = keynum - 4; ii <= keynum + 5; ii++)
840 {
841 ffgrec(fptr, ii, card, &status);
842 printf("%s\n", card);
843 }
844 if (status > 0)
845 printf("\nERROR modifying keywords\n");
846
847 /*
848 ############################
849 # update keywords #
850 ############################
851 */
852 ffucrd(fptr, "KY_MREC", "KY_UCRD = 'This keyword was updated by fxucrd'",
853 &status);
854
855 ffukyj(fptr, "KY_IKYJ", 51, "&", &status);
856 ffukyl(fptr, "KY_IKYL", 1, "&", &status);
857 ffukys(fptr, "NEWIKYS", "updated_string", "&", &status);
858 ffukye(fptr, "KY_IKYE", -13.3456f, 4, "&", &status);
859 ffukyd(fptr, "KY_IKYD", -13.345678901234567, 14, "modified comment",
860 &status);
861 ffukyf(fptr, "KY_IKYF", -13.3456f, 4, "&", &status);
862 ffukyg(fptr, "KY_IKYG", -13.345678901234567, 13, "&", &status);
863
864 printf("\nAfter updating the keywords...\n");
865 for (ii = keynum - 4; ii <= keynum + 5; ii++)
866 {
867 ffgrec(fptr, ii, card, &status);
868 printf("%s\n", card);
869 }
870 if (status > 0)
871 printf("\nERROR modifying keywords\n");
872
873 /* move to top of header and find keywords using wild cards */
874 ffgrec(fptr, 0, card, &status);
875
876 printf("\nKeywords found using wildcard search (should be 13)...\n");
877 nfound = 0;
878 while (!ffgnxk(fptr,inclist, 2, exclist, 2, card, &status))
879 {
880 nfound++;
881 printf("%s\n", card);
882 }
883 if (nfound != 13)
884 {
885 printf("\nERROR reading keywords using wildcards (ffgnxk)\n");
886 goto errstatus;
887 }
888 status = 0;
889
890 /*
891 ############################
892 # copy index keyword #
893 ############################
894 */
895 ffcpky(fptr, fptr, 1, 4, "KY_PKNE", &status);
896 ffgkne(fptr, "ky_pkne", 2, 4, inekey, &nfound, &status);
897 printf("\nCopied keyword: ffgkne: %f, %f, %f\n", inekey[0], inekey[1],
898 inekey[2]);
899
900 if (status > 0)
901 {
902 printf("\nERROR in ffgkne %d, %d\n", nfound, status);
903 goto errstatus;
904 }
905
906 /*
907 ######################################
908 # modify header using template file #
909 ######################################
910 */
911 if (ffpktp(fptr, templt, &status))
912 {
913 printf("\nERROR returned by ffpktp:\n");
914 printf("Could not open or process the file 'testprog.tpt'.\n");
915 printf(" This file is included with the CFITSIO distribution\n");
916 printf(" and should be copied into the current directory\n");
917 printf(" before running the testprog program.\n");
918 status = 0;
919 }
920 printf("Updated header using template file (ffpktp)\n");
921 /*
922 ############################
923 # create binary table #
924 ############################
925 */
926
927 strcpy(tform[0], "15A");
928 strcpy(tform[1], "1L");
929 strcpy(tform[2], "16X");
930 strcpy(tform[3], "1B");
931 strcpy(tform[4], "1I");
932 strcpy(tform[5], "1J");
933 strcpy(tform[6], "1E");
934 strcpy(tform[7], "1D");
935 strcpy(tform[8], "1C");
936 strcpy(tform[9], "1M");
937
938 strcpy(ttype[0], "Avalue");
939 strcpy(ttype[1], "Lvalue");
940 strcpy(ttype[2], "Xvalue");
941 strcpy(ttype[3], "Bvalue");
942 strcpy(ttype[4], "Ivalue");
943 strcpy(ttype[5], "Jvalue");
944 strcpy(ttype[6], "Evalue");
945 strcpy(ttype[7], "Dvalue");
946 strcpy(ttype[8], "Cvalue");
947 strcpy(ttype[9], "Mvalue");
948
949 strcpy(tunit[0], "");
950 strcpy(tunit[1], "m**2");
951 strcpy(tunit[2], "cm");
952 strcpy(tunit[3], "erg/s");
953 strcpy(tunit[4], "km/s");
954 strcpy(tunit[5], "");
955 strcpy(tunit[6], "");
956 strcpy(tunit[7], "");
957 strcpy(tunit[8], "");
958 strcpy(tunit[9], "");
959
960 nrows = 21;
961 tfields = 10;
962 pcount = 0;
963
964 /*
965 ffcrtb(fptr, BINARY_TBL, nrows, tfields, ttype, tform, tunit, binname,
966 &status);
967 */
968 ffibin(fptr, nrows, tfields, ttype, tform, tunit, binname, 0L,
969 &status);
970
971 printf("\nffibin status = %d\n", status);
972 printf("HDU number = %d\n", ffghdn(fptr, &hdunum));
973
974 /* get size and position in header, and reserve space for more keywords */
975 ffghps(fptr, &existkeys, &keynum, &status);
976 printf("header contains %d keywords; located at keyword %d \n",existkeys,
977 keynum);
978
979 morekeys = 40;
980 ffhdef(fptr, morekeys, &status);
981 ffghsp(fptr, &existkeys, &morekeys, &status);
982 printf("header contains %d keywords with room for %d more\n",existkeys,
983 morekeys);
984
985 fftnul(fptr, 4, 99, &status); /* define null value for int cols */
986 fftnul(fptr, 5, 99, &status);
987 fftnul(fptr, 6, 99, &status);
988
989 extvers = 1;
990 ffpkyj(fptr, "EXTVER", extvers, "extension version number", &status);
991 ffpkyj(fptr, "TNULL4", 99, "value for undefined pixels", &status);
992 ffpkyj(fptr, "TNULL5", 99, "value for undefined pixels", &status);
993 ffpkyj(fptr, "TNULL6", 99, "value for undefined pixels", &status);
994
995 naxis = 3;
996 naxes[0] = 1;
997 naxes[1] = 2;
998 naxes[2] = 8;
999 ffptdm(fptr, 3, naxis, naxes, &status);
1000
1001 naxis = 0;
1002 naxes[0] = 0;
1003 naxes[1] = 0;
1004 naxes[2] = 0;
1005 ffgtdm(fptr, 3, 3, &naxis, naxes, &status);
1006 ffgkys(fptr, "TDIM3", iskey, comment, &status);
1007 printf("TDIM3 = %s, %d, %ld, %ld, %ld\n", iskey, naxis, naxes[0],
1008 naxes[1], naxes[2]);
1009
1010 ffrdef(fptr, &status); /* force header to be scanned (not required) */
1011
1012 /*
1013 ############################
1014 # write data to columns #
1015 ############################
1016 */
1017
1018 /* initialize arrays of values to write to table */
1019 signval = -1;
1020 for (ii = 0; ii < 21; ii++)
1021 {
1022 signval *= -1;
1023 boutarray[ii] = (unsigned char) (ii + 1);
1024 ioutarray[ii] = (short) ((ii + 1) * signval);
1025 joutarray[ii] = (ii + 1) * signval;
1026 koutarray[ii] = (ii + 1) * signval;
1027 eoutarray[ii] = (float) ((ii + 1) * signval);
1028 doutarray[ii] = (ii + 1) * signval;
1029 }
1030
1031 ffpcls(fptr, 1, 1, 1, 3, onskey, &status); /* write string values */
1032 ffpclu(fptr, 1, 4, 1, 1, &status); /* write null value */
1033
1034 larray[0] = 0;
1035 larray[1] = 1;
1036 larray[2] = 0;
1037 larray[3] = 0;
1038 larray[4] = 1;
1039 larray[5] = 1;
1040 larray[6] = 0;
1041 larray[7] = 0;
1042 larray[8] = 0;
1043 larray[9] = 1;
1044 larray[10] = 1;
1045 larray[11] = 1;
1046 larray[12] = 0;
1047 larray[13] = 0;
1048 larray[14] = 0;
1049 larray[15] = 0;
1050 larray[16] = 1;
1051 larray[17] = 1;
1052 larray[18] = 1;
1053 larray[19] = 1;
1054 larray[20] = 0;
1055 larray[21] = 0;
1056 larray[22] = 0;
1057 larray[23] = 0;
1058 larray[24] = 0;
1059 larray[25] = 1;
1060 larray[26] = 1;
1061 larray[27] = 1;
1062 larray[28] = 1;
1063 larray[29] = 1;
1064 larray[30] = 0;
1065 larray[31] = 0;
1066 larray[32] = 0;
1067 larray[33] = 0;
1068 larray[34] = 0;
1069 larray[35] = 0;
1070
1071
1072 ffpclx(fptr, 3, 1, 1, 36, larray, &status); /*write bits*/
1073
1074 for (ii = 4; ii < 9; ii++) /* loop over cols 4 - 8 */
1075 {
1076 ffpclb(fptr, ii, 1, 1, 2, boutarray, &status);
1077 if (status == NUM_OVERFLOW)
1078 status = 0;
1079 ffpcli(fptr, ii, 3, 1, 2, &ioutarray[2], &status);
1080 if (status == NUM_OVERFLOW)
1081 status = 0;
1082 ffpclk(fptr, ii, 5, 1, 2, &koutarray[4], &status);
1083 if (status == NUM_OVERFLOW)
1084 status = 0;
1085 ffpcle(fptr, ii, 7, 1, 2, &eoutarray[6], &status);
1086 if (status == NUM_OVERFLOW)
1087 status = 0;
1088 ffpcld(fptr, ii, 9, 1, 2, &doutarray[8], &status);
1089 if (status == NUM_OVERFLOW)
1090 status = 0;
1091
1092 ffpclu(fptr, ii, 11, 1, 1, &status); /* write null value */
1093 }
1094
1095 ffpclc(fptr, 9, 1, 1, 10, eoutarray, &status);
1096 ffpclm(fptr, 10, 1, 1, 10, doutarray, &status);
1097
1098 for (ii = 4; ii < 9; ii++) /* loop over cols 4 - 8 */
1099 {
1100 ffpcnb(fptr, ii, 12, 1, 2, &boutarray[11], 13, &status);
1101 if (status == NUM_OVERFLOW)
1102 status = 0;
1103 ffpcni(fptr, ii, 14, 1, 2, &ioutarray[13], 15, &status);
1104 if (status == NUM_OVERFLOW)
1105 status = 0;
1106 ffpcnk(fptr, ii, 16, 1, 2, &koutarray[15], 17, &status);
1107 if (status == NUM_OVERFLOW)
1108 status = 0;
1109 ffpcne(fptr, ii, 18, 1, 2, &eoutarray[17], 19., &status);
1110 if (status == NUM_OVERFLOW)
1111 status = 0;
1112 ffpcnd(fptr, ii, 20, 1, 2, &doutarray[19], 21., &status);
1113 if (status == NUM_OVERFLOW)
1114 status = 0;
1115
1116 }
1117 ffpcll(fptr, 2, 1, 1, 21, larray, &status); /*write logicals*/
1118 ffpclu(fptr, 2, 11, 1, 1, &status); /* write null value */
1119 printf("ffpcl_ status = %d\n", status);
1120
1121 /*
1122 #########################################
1123 # get information about the columns #
1124 #########################################
1125 */
1126
1127 printf("\nFind the column numbers; a returned status value of 237 is");
1128 printf("\nexpected and indicates that more than one column name matches");
1129 printf("\nthe input column name template. Status = 219 indicates that");
1130 printf("\nthere was no matching column name.");
1131
1132 ffgcno(fptr, 0, "Xvalue", &colnum, &status);
1133 printf("\nColumn Xvalue is number %d; status = %d.\n", colnum, status);
1134
1135 while (status != COL_NOT_FOUND)
1136 {
1137 ffgcnn(fptr, 1, "*ue", colname, &colnum, &status);
1138 printf("Column %s is number %d; status = %d.\n",
1139 colname, colnum, status);
1140 }
1141 status = 0;
1142
1143 printf("\nInformation about each column:\n");
1144
1145 for (ii = 0; ii < tfields; ii++)
1146 {
1147 ffgtcl(fptr, ii + 1, &typecode, &repeat, &width, &status);
1148 printf("%4s %3d %2ld %2ld", tform[ii], typecode, repeat, width);
1149 ffgbcl(fptr, ii + 1, ttype[0], tunit[0], cvalstr, &repeat, &scale,
1150 &zero, &jnulval, tdisp, &status);
1151 printf(" %s, %s, %c, %ld, %f, %f, %ld, %s.\n",
1152 ttype[0], tunit[0], cvalstr[0], repeat, scale, zero, jnulval, tdisp);
1153 }
1154
1155 printf("\n");
1156
1157 /*
1158 ###############################################
1159 # insert ASCII table before the binary table #
1160 ###############################################
1161 */
1162
1163 if (ffmrhd(fptr, -1, &hdutype, &status) > 0)
1164 goto errstatus;
1165
1166 strcpy(tform[0], "A15");
1167 strcpy(tform[1], "I10");
1168 strcpy(tform[2], "F14.6");
1169 strcpy(tform[3], "E12.5");
1170 strcpy(tform[4], "D21.14");
1171
1172 strcpy(ttype[0], "Name");
1173 strcpy(ttype[1], "Ivalue");
1174 strcpy(ttype[2], "Fvalue");
1175 strcpy(ttype[3], "Evalue");
1176 strcpy(ttype[4], "Dvalue");
1177
1178 strcpy(tunit[0], "");
1179 strcpy(tunit[1], "m**2");
1180 strcpy(tunit[2], "cm");
1181 strcpy(tunit[3], "erg/s");
1182 strcpy(tunit[4], "km/s");
1183
1184 rowlen = 76;
1185 nrows = 11;
1186 tfields = 5;
1187
1188 ffitab(fptr, rowlen, nrows, tfields, ttype, tbcol, tform, tunit, tblname,
1189 &status);
1190 printf("ffitab status = %d\n", status);
1191 printf("HDU number = %d\n", ffghdn(fptr, &hdunum));
1192
1193 ffsnul(fptr, 1, "null1", &status); /* define null value for int cols */
1194 ffsnul(fptr, 2, "null2", &status);
1195 ffsnul(fptr, 3, "null3", &status);
1196 ffsnul(fptr, 4, "null4", &status);
1197 ffsnul(fptr, 5, "null5", &status);
1198
1199 extvers = 2;
1200 ffpkyj(fptr, "EXTVER", extvers, "extension version number", &status);
1201
1202 ffpkys(fptr, "TNULL1", "null1", "value for undefined pixels", &status);
1203 ffpkys(fptr, "TNULL2", "null2", "value for undefined pixels", &status);
1204 ffpkys(fptr, "TNULL3", "null3", "value for undefined pixels", &status);
1205 ffpkys(fptr, "TNULL4", "null4", "value for undefined pixels", &status);
1206 ffpkys(fptr, "TNULL5", "null5", "value for undefined pixels", &status);
1207
1208 if (status > 0)
1209 goto errstatus;
1210
1211 /*
1212 ############################
1213 # write data to columns #
1214 ############################
1215 */
1216
1217 /* initialize arrays of values to write to table */
1218 for (ii = 0; ii < 21; ii++)
1219 {
1220 boutarray[ii] = (unsigned char) (ii + 1);
1221 ioutarray[ii] = (short) (ii + 1);
1222 joutarray[ii] = ii + 1;
1223 eoutarray[ii] = (float) (ii + 1);
1224 doutarray[ii] = ii + 1;
1225 }
1226
1227 ffpcls(fptr, 1, 1, 1, 3, onskey, &status); /* write string values */
1228 ffpclu(fptr, 1, 4, 1, 1, &status); /* write null value */
1229
1230 for (ii = 2; ii < 6; ii++) /* loop over cols 2 - 5 */
1231 {
1232 ffpclb(fptr, ii, 1, 1, 2, boutarray, &status); /* char array */
1233 if (status == NUM_OVERFLOW)
1234 status = 0;
1235 ffpcli(fptr, ii, 3, 1, 2, &ioutarray[2], &status); /* short array */
1236 if (status == NUM_OVERFLOW)
1237 status = 0;
1238 ffpclj(fptr, ii, 5, 1, 2, &joutarray[4], &status); /* long array */
1239 if (status == NUM_OVERFLOW)
1240 status = 0;
1241 ffpcle(fptr, ii, 7, 1, 2, &eoutarray[6], &status); /* float array */
1242 if (status == NUM_OVERFLOW)
1243 status = 0;
1244 ffpcld(fptr, ii, 9, 1, 2, &doutarray[8], &status); /* double array */
1245 if (status == NUM_OVERFLOW)
1246 status = 0;
1247
1248 ffpclu(fptr, ii, 11, 1, 1, &status); /* write null value */
1249 }
1250 printf("ffpcl_ status = %d\n", status);
1251
1252 /*
1253 ################################
1254 # read data from ASCII table #
1255 ################################
1256 */
1257 ffghtb(fptr, 99, &rowlen, &nrows, &tfields, ttype, tbcol,
1258 tform, tunit, tblname, &status);
1259
1260 printf("\nASCII table: rowlen, nrows, tfields, extname: %ld %ld %d %s\n",
1261 rowlen, nrows, tfields, tblname);
1262
1263 for (ii = 0; ii < tfields; ii++)
1264 printf("%8s %3ld %8s %8s \n", ttype[ii], tbcol[ii],
1265 tform[ii], tunit[ii]);
1266
1267 nrows = 11;
1268 ffgcvs(fptr, 1, 1, 1, nrows, "UNDEFINED", inskey, &anynull, &status);
1269 ffgcvb(fptr, 2, 1, 1, nrows, 99, binarray, &anynull, &status);
1270 ffgcvi(fptr, 2, 1, 1, nrows, 99, iinarray, &anynull, &status);
1271 ffgcvj(fptr, 3, 1, 1, nrows, 99, jinarray, &anynull, &status);
1272 ffgcve(fptr, 4, 1, 1, nrows, 99., einarray, &anynull, &status);
1273 ffgcvd(fptr, 5, 1, 1, nrows, 99., dinarray, &anynull, &status);
1274
1275 printf("\nData values read from ASCII table:\n");
1276 for (ii = 0; ii < nrows; ii++)
1277 {
1278 printf("%15s %2d %2d %2ld %4.1f %4.1f\n", inskey[ii], binarray[ii],
1279 iinarray[ii], jinarray[ii], einarray[ii], dinarray[ii]);
1280 }
1281
1282 ffgtbb(fptr, 1, 20, 78, uchars, &status);
1283 uchars[78] = '\0';
1284 printf("\n%s\n", uchars);
1285 ffptbb(fptr, 1, 20, 78, uchars, &status);
1286
1287 /*
1288 #########################################
1289 # get information about the columns #
1290 #########################################
1291 */
1292
1293 ffgcno(fptr, 0, "name", &colnum, &status);
1294 printf("\nColumn name is number %d; status = %d.\n", colnum, status);
1295
1296 while (status != COL_NOT_FOUND)
1297 {
1298 ffgcnn(fptr, 1, "*ue", colname, &colnum, &status);
1299 printf("Column %s is number %d; status = %d.\n",
1300 colname, colnum, status);
1301 }
1302 status = 0;
1303
1304 for (ii = 0; ii < tfields; ii++)
1305 {
1306 ffgtcl(fptr, ii + 1, &typecode, &repeat, &width, &status);
1307 printf("%4s %3d %2ld %2ld", tform[ii], typecode, repeat, width);
1308 ffgacl(fptr, ii + 1, ttype[0], tbcol, tunit[0], tform[0], &scale,
1309 &zero, nulstr, tdisp, &status);
1310 printf(" %s, %ld, %s, %s, %f, %f, %s, %s.\n",
1311 ttype[0], tbcol[0], tunit[0], tform[0], scale, zero,
1312 nulstr, tdisp);
1313 }
1314
1315 printf("\n");
1316
1317 /*
1318 ###############################################
1319 # test the insert/delete row/column routines #
1320 ###############################################
1321 */
1322
1323 if (ffirow(fptr, 2, 3, &status) > 0)
1324 goto errstatus;
1325
1326 nrows = 14;
1327 ffgcvs(fptr, 1, 1, 1, nrows, "UNDEFINED", inskey, &anynull, &status);
1328 ffgcvb(fptr, 2, 1, 1, nrows, 99, binarray, &anynull, &status);
1329 ffgcvi(fptr, 2, 1, 1, nrows, 99, iinarray, &anynull, &status);
1330 ffgcvj(fptr, 3, 1, 1, nrows, 99, jinarray, &anynull, &status);
1331 ffgcve(fptr, 4, 1, 1, nrows, 99., einarray, &anynull, &status);
1332 ffgcvd(fptr, 5, 1, 1, nrows, 99., dinarray, &anynull, &status);
1333
1334
1335 printf("\nData values after inserting 3 rows after row 2:\n");
1336 for (ii = 0; ii < nrows; ii++)
1337 {
1338 printf("%15s %2d %2d %2ld %4.1f %4.1f\n", inskey[ii], binarray[ii],
1339 iinarray[ii], jinarray[ii], einarray[ii], dinarray[ii]);
1340 }
1341
1342 if (ffdrow(fptr, 10, 2, &status) > 0)
1343 goto errstatus;
1344
1345 nrows = 12;
1346 ffgcvs(fptr, 1, 1, 1, nrows, "UNDEFINED", inskey, &anynull, &status);
1347 ffgcvb(fptr, 2, 1, 1, nrows, 99, binarray, &anynull, &status);
1348 ffgcvi(fptr, 2, 1, 1, nrows, 99, iinarray, &anynull, &status);
1349 ffgcvj(fptr, 3, 1, 1, nrows, 99, jinarray, &anynull, &status);
1350 ffgcve(fptr, 4, 1, 1, nrows, 99., einarray, &anynull, &status);
1351 ffgcvd(fptr, 5, 1, 1, nrows, 99., dinarray, &anynull, &status);
1352
1353 printf("\nData values after deleting 2 rows at row 10:\n");
1354 for (ii = 0; ii < nrows; ii++)
1355 {
1356 printf("%15s %2d %2d %2ld %4.1f %4.1f\n", inskey[ii], binarray[ii],
1357 iinarray[ii], jinarray[ii], einarray[ii], dinarray[ii]);
1358 }
1359 if (ffdcol(fptr, 3, &status) > 0)
1360 goto errstatus;
1361
1362 ffgcvs(fptr, 1, 1, 1, nrows, "UNDEFINED", inskey, &anynull, &status);
1363 ffgcvb(fptr, 2, 1, 1, nrows, 99, binarray, &anynull, &status);
1364 ffgcvi(fptr, 2, 1, 1, nrows, 99, iinarray, &anynull, &status);
1365 ffgcve(fptr, 3, 1, 1, nrows, 99., einarray, &anynull, &status);
1366 ffgcvd(fptr, 4, 1, 1, nrows, 99., dinarray, &anynull, &status);
1367
1368 printf("\nData values after deleting column 3:\n");
1369 for (ii = 0; ii < nrows; ii++)
1370 {
1371 printf("%15s %2d %2d %4.1f %4.1f\n", inskey[ii], binarray[ii],
1372 iinarray[ii], einarray[ii], dinarray[ii]);
1373 }
1374
1375 if (fficol(fptr, 5, "INSERT_COL", "F14.6", &status) > 0)
1376 goto errstatus;
1377
1378 ffgcvs(fptr, 1, 1, 1, nrows, "UNDEFINED", inskey, &anynull, &status);
1379 ffgcvb(fptr, 2, 1, 1, nrows, 99, binarray, &anynull, &status);
1380 ffgcvi(fptr, 2, 1, 1, nrows, 99, iinarray, &anynull, &status);
1381 ffgcve(fptr, 3, 1, 1, nrows, 99., einarray, &anynull, &status);
1382 ffgcvd(fptr, 4, 1, 1, nrows, 99., dinarray, &anynull, &status);
1383 ffgcvj(fptr, 5, 1, 1, nrows, 99, jinarray, &anynull, &status);
1384
1385 printf("\nData values after inserting column 5:\n");
1386 for (ii = 0; ii < nrows; ii++)
1387 {
1388 printf("%15s %2d %2d %4.1f %4.1f %ld\n", inskey[ii], binarray[ii],
1389 iinarray[ii], einarray[ii], dinarray[ii] , jinarray[ii]);
1390 }
1391
1392 /*
1393 ############################################################
1394 # create a temporary file and copy the ASCII table to it, #
1395 # column by column. #
1396 ############################################################
1397 */
1398 bitpix = 16;
1399 naxis = 0;
1400
1401 strcpy(filename, "!t1q2s3v6.tmp");
1402 ffinit(&tmpfptr, filename, &status);
1403 printf("Create temporary file: ffinit status = %d\n", status);
1404
1405 ffiimg(tmpfptr, bitpix, naxis, naxes, &status);
1406 printf("\nCreate null primary array: ffiimg status = %d\n", status);
1407
1408 /* create an empty table with 12 rows and 0 columns */
1409 nrows = 12;
1410 tfields = 0;
1411 rowlen = 0;
1412 ffitab(tmpfptr, rowlen, nrows, tfields, ttype, tbcol, tform, tunit,
1413 tblname, &status);
1414 printf("\nCreate ASCII table with 0 columns: ffitab status = %d\n",
1415 status);
1416
1417 /* copy columns from one table to the other */
1418 ffcpcl(fptr, tmpfptr, 4, 1, TRUE, &status);
1419 printf("copy column, ffcpcl status = %d\n", status);
1420 ffcpcl(fptr, tmpfptr, 3, 1, TRUE, &status);
1421 printf("copy column, ffcpcl status = %d\n", status);
1422 ffcpcl(fptr, tmpfptr, 2, 1, TRUE, &status);
1423 printf("copy column, ffcpcl status = %d\n", status);
1424 ffcpcl(fptr, tmpfptr, 1, 1, TRUE, &status);
1425 printf("copy column, ffcpcl status = %d\n", status);
1426
1427 /* now repeat by copying ASCII input to Binary output table */
1428 ffibin(tmpfptr, nrows, tfields, ttype, tform, tunit,
1429 tblname, 0L, &status);
1430 printf("\nCreate Binary table with 0 columns: ffibin status = %d\n",
1431 status);
1432
1433 /* copy columns from one table to the other */
1434 ffcpcl(fptr, tmpfptr, 4, 1, TRUE, &status);
1435 printf("copy column, ffcpcl status = %d\n", status);
1436 ffcpcl(fptr, tmpfptr, 3, 1, TRUE, &status);
1437 printf("copy column, ffcpcl status = %d\n", status);
1438 ffcpcl(fptr, tmpfptr, 2, 1, TRUE, &status);
1439 printf("copy column, ffcpcl status = %d\n", status);
1440 ffcpcl(fptr, tmpfptr, 1, 1, TRUE, &status);
1441 printf("copy column, ffcpcl status = %d\n", status);
1442
1443
1444 /*
1445 ffclos(tmpfptr, &status);
1446 printf("Close the tmp file: ffclos status = %d\n", status);
1447 */
1448
1449 ffdelt(tmpfptr, &status);
1450 printf("Delete the tmp file: ffdelt status = %d\n", status);
1451
1452 if (status > 0)
1453 {
1454 goto errstatus;
1455 }
1456
1457 /*
1458 ################################
1459 # read data from binary table #
1460 ################################
1461 */
1462
1463 if (ffmrhd(fptr, 1, &hdutype, &status) > 0)
1464 goto errstatus;
1465
1466 printf("HDU number = %d\n", ffghdn(fptr, &hdunum));
1467
1468 ffghsp(fptr, &existkeys, &morekeys, &status);
1469 printf("header contains %d keywords with room for %d more\n",existkeys,
1470 morekeys);
1471
1472 ffghbn(fptr, 99, &nrows, &tfields, ttype,
1473 tform, tunit, binname, &pcount, &status);
1474
1475 printf("\nBinary table: nrows, tfields, extname, pcount: %ld %d %s %ld\n",
1476 nrows, tfields, binname, pcount);
1477
1478 for (ii = 0; ii < tfields; ii++)
1479 printf("%8s %8s %8s \n", ttype[ii], tform[ii], tunit[ii]);
1480
1481 for (ii = 0; ii < 40; ii++)
1482 larray[ii] = 0;
1483
1484 printf("\nData values read from binary table:\n");
1485 printf(" Bit column (X) data values: \n\n");
1486
1487 ffgcx(fptr, 3, 1, 1, 36, larray, &status);
1488 for (jj = 0; jj < 5; jj++)
1489 {
1490 for (ii = 0; ii < 8; ii++)
1491 printf("%1d",larray[jj * 8 + ii]);
1492 printf(" ");
1493 }
1494
1495 for (ii = 0; ii < nrows; ii++)
1496 {
1497 larray[ii] = 0;
1498 xinarray[ii] = 0;
1499 binarray[ii] = 0;
1500 iinarray[ii] = 0;
1501 kinarray[ii] = 0;
1502 einarray[ii] = 0.;
1503 dinarray[ii] = 0.;
1504 cinarray[ii * 2] = 0.;
1505 minarray[ii * 2] = 0.;
1506 cinarray[ii * 2 + 1] = 0.;
1507 minarray[ii * 2 + 1] = 0.;
1508 }
1509
1510 printf("\n\n");
1511 ffgcvs(fptr, 1, 4, 1, 1, "", inskey, &anynull, &status);
1512 printf("null string column value = -%s- (should be --)\n",inskey[0]);
1513
1514 nrows = 21;
1515 ffgcvs(fptr, 1, 1, 1, nrows, "NOT DEFINED", inskey, &anynull, &status);
1516 ffgcl( fptr, 2, 1, 1, nrows, larray, &status);
1517 ffgcvb(fptr, 3, 1, 1, nrows, 98, xinarray, &anynull, &status);
1518 ffgcvb(fptr, 4, 1, 1, nrows, 98, binarray, &anynull, &status);
1519 ffgcvi(fptr, 5, 1, 1, nrows, 98, iinarray, &anynull, &status);
1520 ffgcvk(fptr, 6, 1, 1, nrows, 98, kinarray, &anynull, &status);
1521 ffgcve(fptr, 7, 1, 1, nrows, 98., einarray, &anynull, &status);
1522 ffgcvd(fptr, 8, 1, 1, nrows, 98., dinarray, &anynull, &status);
1523 ffgcvc(fptr, 9, 1, 1, nrows, 98., cinarray, &anynull, &status);
1524 ffgcvm(fptr, 10, 1, 1, nrows, 98., minarray, &anynull, &status);
1525
1526 printf("\nRead columns with ffgcv_:\n");
1527 for (ii = 0; ii < nrows; ii++)
1528 {
1529 printf("%15s %d %3d %2d %3d %3d %5.1f %5.1f (%5.1f,%5.1f) (%5.1f,%5.1f) \n",
1530 inskey[ii], larray[ii], xinarray[ii], binarray[ii], iinarray[ii],
1531 kinarray[ii], einarray[ii], dinarray[ii], cinarray[ii * 2],
1532 cinarray[ii * 2 + 1], minarray[ii * 2], minarray[ii * 2 + 1]);
1533 }
1534
1535 for (ii = 0; ii < nrows; ii++)
1536 {
1537 larray[ii] = 0;
1538 xinarray[ii] = 0;
1539 binarray[ii] = 0;
1540 iinarray[ii] = 0;
1541 kinarray[ii] = 0;
1542 einarray[ii] = 0.;
1543 dinarray[ii] = 0.;
1544 cinarray[ii * 2] = 0.;
1545 minarray[ii * 2] = 0.;
1546 cinarray[ii * 2 + 1] = 0.;
1547 minarray[ii * 2 + 1] = 0.;
1548 }
1549
1550 ffgcfs(fptr, 1, 1, 1, nrows, inskey, larray2, &anynull, &status);
1551 ffgcfl(fptr, 2, 1, 1, nrows, larray, larray2, &anynull, &status);
1552 ffgcfb(fptr, 3, 1, 1, nrows, xinarray, larray2, &anynull, &status);
1553 ffgcfb(fptr, 4, 1, 1, nrows, binarray, larray2, &anynull, &status);
1554 ffgcfi(fptr, 5, 1, 1, nrows, iinarray, larray2, &anynull, &status);
1555 ffgcfk(fptr, 6, 1, 1, nrows, kinarray, larray2, &anynull, &status);
1556 ffgcfe(fptr, 7, 1, 1, nrows, einarray, larray2, &anynull, &status);
1557 ffgcfd(fptr, 8, 1, 1, nrows, dinarray, larray2, &anynull, &status);
1558 ffgcfc(fptr, 9, 1, 1, nrows, cinarray, larray2, &anynull, &status);
1559 ffgcfm(fptr, 10, 1, 1, nrows, minarray, larray2, &anynull, &status);
1560
1561 printf("\nRead columns with ffgcf_:\n");
1562 for (ii = 0; ii < 10; ii++)
1563 {
1564
1565 printf("%15s %d %3d %2d %3d %3d %5.1f %5.1f (%5.1f,%5.1f) (%5.1f,%5.1f)\n",
1566 inskey[ii], larray[ii], xinarray[ii], binarray[ii], iinarray[ii],
1567 kinarray[ii], einarray[ii], dinarray[ii], cinarray[ii * 2],
1568 cinarray[ii * 2 + 1], minarray[ii * 2], minarray[ii * 2 + 1]);
1569 }
1570 for (ii = 10; ii < nrows; ii++)
1571 {
1572 /* don't try to print the NaN values */
1573 printf("%15s %d %3d %2d %3d \n",
1574 inskey[ii], larray[ii], xinarray[ii], binarray[ii], iinarray[ii]);
1575 }
1576 ffprec(fptr,
1577 "key_prec= 'This keyword was written by f_prec' / comment here", &status);
1578
1579 /*
1580 ###############################################
1581 # test the insert/delete row/column routines #
1582 ###############################################
1583 */
1584 if (ffirow(fptr, 2, 3, &status) > 0)
1585 goto errstatus;
1586
1587 nrows = 14;
1588 ffgcvs(fptr, 1, 1, 1, nrows, "NOT DEFINED", inskey, &anynull, &status);
1589 ffgcvb(fptr, 4, 1, 1, nrows, 98, binarray, &anynull, &status);
1590 ffgcvi(fptr, 5, 1, 1, nrows, 98, iinarray, &anynull, &status);
1591 ffgcvj(fptr, 6, 1, 1, nrows, 98, jinarray, &anynull, &status);
1592 ffgcve(fptr, 7, 1, 1, nrows, 98., einarray, &anynull, &status);
1593 ffgcvd(fptr, 8, 1, 1, nrows, 98., dinarray, &anynull, &status);
1594
1595 printf("\nData values after inserting 3 rows after row 2:\n");
1596 for (ii = 0; ii < nrows; ii++)
1597 {
1598 printf("%15s %2d %3d %3ld %5.1f %5.1f\n", inskey[ii], binarray[ii],
1599 iinarray[ii], jinarray[ii], einarray[ii], dinarray[ii]);
1600 }
1601
1602 if (ffdrow(fptr, 10, 2, &status) > 0)
1603 goto errstatus;
1604
1605 nrows = 12;
1606 ffgcvs(fptr, 1, 1, 1, nrows, "NOT DEFINED", inskey, &anynull, &status);
1607 ffgcvb(fptr, 4, 1, 1, nrows, 98, binarray, &anynull, &status);
1608 ffgcvi(fptr, 5, 1, 1, nrows, 98, iinarray, &anynull, &status);
1609 ffgcvj(fptr, 6, 1, 1, nrows, 98, jinarray, &anynull, &status);
1610 ffgcve(fptr, 7, 1, 1, nrows, 98., einarray, &anynull, &status);
1611 ffgcvd(fptr, 8, 1, 1, nrows, 98., dinarray, &anynull, &status);
1612
1613 printf("\nData values after deleting 2 rows at row 10:\n");
1614 for (ii = 0; ii < nrows; ii++)
1615 {
1616 printf("%15s %2d %3d %3ld %5.1f %5.1f\n", inskey[ii], binarray[ii],
1617 iinarray[ii], jinarray[ii], einarray[ii], dinarray[ii]);
1618 }
1619
1620 if (ffdcol(fptr, 6, &status) > 0)
1621 goto errstatus;
1622
1623 ffgcvs(fptr, 1, 1, 1, nrows, "NOT DEFINED", inskey, &anynull, &status);
1624 ffgcvb(fptr, 4, 1, 1, nrows, 98, binarray, &anynull, &status);
1625 ffgcvi(fptr, 5, 1, 1, nrows, 98, iinarray, &anynull, &status);
1626 ffgcve(fptr, 6, 1, 1, nrows, 98., einarray, &anynull, &status);
1627 ffgcvd(fptr, 7, 1, 1, nrows, 98., dinarray, &anynull, &status);
1628
1629 printf("\nData values after deleting column 6:\n");
1630 for (ii = 0; ii < nrows; ii++)
1631 {
1632 printf("%15s %2d %3d %5.1f %5.1f\n", inskey[ii], binarray[ii],
1633 iinarray[ii], einarray[ii], dinarray[ii]);
1634 }
1635
1636 if (fficol(fptr, 8, "INSERT_COL", "1E", &status) > 0)
1637 goto errstatus;
1638
1639 ffgcvs(fptr, 1, 1, 1, nrows, "NOT DEFINED", inskey, &anynull, &status);
1640 ffgcvb(fptr, 4, 1, 1, nrows, 98, binarray, &anynull, &status);
1641 ffgcvi(fptr, 5, 1, 1, nrows, 98, iinarray, &anynull, &status);
1642 ffgcve(fptr, 6, 1, 1, nrows, 98., einarray, &anynull, &status);
1643 ffgcvd(fptr, 7, 1, 1, nrows, 98., dinarray, &anynull, &status);
1644 ffgcvj(fptr, 8, 1, 1, nrows, 98, jinarray, &anynull, &status);
1645
1646 printf("\nData values after inserting column 8:\n");
1647 for (ii = 0; ii < nrows; ii++)
1648 {
1649 printf("%15s %2d %3d %5.1f %5.1f %ld\n", inskey[ii], binarray[ii],
1650 iinarray[ii], einarray[ii], dinarray[ii] , jinarray[ii]);
1651 }
1652
1653 ffpclu(fptr, 8, 1, 1, 10, &status);
1654
1655 ffgcvs(fptr, 1, 1, 1, nrows, "NOT DEFINED", inskey, &anynull, &status);
1656 ffgcvb(fptr, 4, 1, 1, nrows, 98, binarray, &anynull, &status);
1657 ffgcvi(fptr, 5, 1, 1, nrows, 98, iinarray, &anynull, &status);
1658 ffgcve(fptr, 6, 1, 1, nrows, 98., einarray, &anynull, &status);
1659 ffgcvd(fptr, 7, 1, 1, nrows, 98., dinarray, &anynull, &status);
1660 ffgcvj(fptr, 8, 1, 1, nrows, 98, jinarray, &anynull, &status);
1661
1662 printf("\nValues after setting 1st 10 elements in column 8 = null:\n");
1663 for (ii = 0; ii < nrows; ii++)
1664 {
1665 printf("%15s %2d %3d %5.1f %5.1f %ld\n", inskey[ii], binarray[ii],
1666 iinarray[ii], einarray[ii], dinarray[ii] , jinarray[ii]);
1667 }
1668
1669 /*
1670 ############################################################
1671 # create a temporary file and copy the binary table to it,#
1672 # column by column. #
1673 ############################################################
1674 */
1675 bitpix = 16;
1676 naxis = 0;
1677
1678 strcpy(filename, "!t1q2s3v5.tmp");
1679 ffinit(&tmpfptr, filename, &status);
1680 printf("Create temporary file: ffinit status = %d\n", status);
1681
1682 ffiimg(tmpfptr, bitpix, naxis, naxes, &status);
1683 printf("\nCreate null primary array: ffiimg status = %d\n", status);
1684
1685 /* create an empty table with 22 rows and 0 columns */
1686 nrows = 22;
1687 tfields = 0;
1688 ffibin(tmpfptr, nrows, tfields, ttype, tform, tunit, binname, 0L,
1689 &status);
1690 printf("\nCreate binary table with 0 columns: ffibin status = %d\n",
1691 status);
1692
1693 /* copy columns from one table to the other */
1694 ffcpcl(fptr, tmpfptr, 7, 1, TRUE, &status);
1695 printf("copy column, ffcpcl status = %d\n", status);
1696 ffcpcl(fptr, tmpfptr, 6, 1, TRUE, &status);
1697 printf("copy column, ffcpcl status = %d\n", status);
1698 ffcpcl(fptr, tmpfptr, 5, 1, TRUE, &status);
1699 printf("copy column, ffcpcl status = %d\n", status);
1700 ffcpcl(fptr, tmpfptr, 4, 1, TRUE, &status);
1701 printf("copy column, ffcpcl status = %d\n", status);
1702 ffcpcl(fptr, tmpfptr, 3, 1, TRUE, &status);
1703 printf("copy column, ffcpcl status = %d\n", status);
1704 ffcpcl(fptr, tmpfptr, 2, 1, TRUE, &status);
1705 printf("copy column, ffcpcl status = %d\n", status);
1706 ffcpcl(fptr, tmpfptr, 1, 1, TRUE, &status);
1707 printf("copy column, ffcpcl status = %d\n", status);
1708
1709 /*
1710 ffclos(tmpfptr, &status);
1711 printf("Close the tmp file: ffclos status = %d\n", status);
1712 */
1713
1714 ffdelt(tmpfptr, &status);
1715 printf("Delete the tmp file: ffdelt status = %d\n", status);
1716 if (status > 0)
1717 {
1718 goto errstatus;
1719 }
1720 /*
1721 ####################################################
1722 # insert binary table following the primary array #
1723 ####################################################
1724 */
1725
1726 ffmahd(fptr, 1, &hdutype, &status);
1727
1728 strcpy(tform[0], "15A");
1729 strcpy(tform[1], "1L");
1730 strcpy(tform[2], "16X");
1731 strcpy(tform[3], "1B");
1732 strcpy(tform[4], "1I");
1733 strcpy(tform[5], "1J");
1734 strcpy(tform[6], "1E");
1735 strcpy(tform[7], "1D");
1736 strcpy(tform[8], "1C");
1737 strcpy(tform[9], "1M");
1738
1739 strcpy(ttype[0], "Avalue");
1740 strcpy(ttype[1], "Lvalue");
1741 strcpy(ttype[2], "Xvalue");
1742 strcpy(ttype[3], "Bvalue");
1743 strcpy(ttype[4], "Ivalue");
1744 strcpy(ttype[5], "Jvalue");
1745 strcpy(ttype[6], "Evalue");
1746 strcpy(ttype[7], "Dvalue");
1747 strcpy(ttype[8], "Cvalue");
1748 strcpy(ttype[9], "Mvalue");
1749
1750 strcpy(tunit[0], "");
1751 strcpy(tunit[1], "m**2");
1752 strcpy(tunit[2], "cm");
1753 strcpy(tunit[3], "erg/s");
1754 strcpy(tunit[4], "km/s");
1755 strcpy(tunit[5], "");
1756 strcpy(tunit[6], "");
1757 strcpy(tunit[7], "");
1758 strcpy(tunit[8], "");
1759 strcpy(tunit[9], "");
1760
1761 nrows = 20;
1762 tfields = 10;
1763 pcount = 0;
1764
1765 ffibin(fptr, nrows, tfields, ttype, tform, tunit, binname, pcount,
1766 &status);
1767 printf("ffibin status = %d\n", status);
1768 printf("HDU number = %d\n", ffghdn(fptr, &hdunum));
1769
1770 extvers = 3;
1771 ffpkyj(fptr, "EXTVER", extvers, "extension version number", &status);
1772
1773
1774 ffpkyj(fptr, "TNULL4", 77, "value for undefined pixels", &status);
1775 ffpkyj(fptr, "TNULL5", 77, "value for undefined pixels", &status);
1776 ffpkyj(fptr, "TNULL6", 77, "value for undefined pixels", &status);
1777
1778 ffpkyj(fptr, "TSCAL4", 1000, "scaling factor", &status);
1779 ffpkyj(fptr, "TSCAL5", 1, "scaling factor", &status);
1780 ffpkyj(fptr, "TSCAL6", 100, "scaling factor", &status);
1781
1782 ffpkyj(fptr, "TZERO4", 0, "scaling offset", &status);
1783 ffpkyj(fptr, "TZERO5", 32768, "scaling offset", &status);
1784 ffpkyj(fptr, "TZERO6", 100, "scaling offset", &status);
1785
1786 fftnul(fptr, 4, 77, &status); /* define null value for int cols */
1787 fftnul(fptr, 5, 77, &status);
1788 fftnul(fptr, 6, 77, &status);
1789 /* set scaling */
1790 fftscl(fptr, 4, 1000., 0., &status);
1791 fftscl(fptr, 5, 1., 32768., &status);
1792 fftscl(fptr, 6, 100., 100., &status);
1793
1794 /*
1795 ############################
1796 # write data to columns #
1797 ############################
1798 */
1799
1800 /* initialize arrays of values to write to table */
1801
1802 joutarray[0] = 0;
1803 joutarray[1] = 1000;
1804 joutarray[2] = 10000;
1805 joutarray[3] = 32768;
1806 joutarray[4] = 65535;
1807
1808
1809 for (ii = 4; ii < 7; ii++)
1810 {
1811 ffpclj(fptr, ii, 1, 1, 5, joutarray, &status);
1812 if (status == NUM_OVERFLOW)
1813 {
1814 printf("Overflow writing to column %ld\n", ii);
1815 status = 0;
1816 }
1817
1818 ffpclu(fptr, ii, 6, 1, 1, &status); /* write null value */
1819 }
1820
1821 for (jj = 4; jj < 7; jj++)
1822 {
1823 ffgcvj(fptr, jj, 1, 1, 6, -999, jinarray, &anynull, &status);
1824 for (ii = 0; ii < 6; ii++)
1825 {
1826 printf(" %6ld", jinarray[ii]);
1827 }
1828 printf("\n");
1829 }
1830
1831 printf("\n");
1832 /* turn off scaling, and read the unscaled values */
1833 fftscl(fptr, 4, 1., 0., &status);
1834 fftscl(fptr, 5, 1., 0., &status);
1835 fftscl(fptr, 6, 1., 0., &status);
1836
1837 for (jj = 4; jj < 7; jj++)
1838 {
1839 ffgcvj(fptr, jj, 1, 1, 6, -999, jinarray, &anynull, &status);
1840 for (ii = 0; ii < 6; ii++)
1841 {
1842 printf(" %6ld", jinarray[ii]);
1843 }
1844 printf("\n");
1845 }
1846 /*
1847 ######################################################
1848 # insert image extension following the binary table #
1849 ######################################################
1850 */
1851
1852 bitpix = -32;
1853 naxis = 2;
1854 naxes[0] = 15;
1855 naxes[1] = 25;
1856 ffiimg(fptr, bitpix, naxis, naxes, &status);
1857 printf("\nCreate image extension: ffiimg status = %d\n", status);
1858 printf("HDU number = %d\n", ffghdn(fptr, &hdunum));
1859
1860 for (jj = 0; jj < 30; jj++)
1861 {
1862 for (ii = 0; ii < 19; ii++)
1863 {
1864 imgarray[jj][ii] = (short) ((jj * 10) + ii);
1865 }
1866 }
1867
1868 ffp2di(fptr, 1, 19, naxes[0], naxes[1], imgarray[0], &status);
1869 printf("\nWrote whole 2D array: ffp2di status = %d\n", status);
1870
1871 for (jj = 0; jj < 30; jj++)
1872 {
1873 for (ii = 0; ii < 19; ii++)
1874 {
1875 imgarray[jj][ii] = 0;
1876 }
1877 }
1878
1879 ffg2di(fptr, 1, 0, 19, naxes[0], naxes[1], imgarray[0], &anynull,
1880 &status);
1881 printf("\nRead whole 2D array: ffg2di status = %d\n", status);
1882
1883 for (jj = 0; jj < 30; jj++)
1884 {
1885 for (ii = 0; ii < 19; ii++)
1886 {
1887 printf(" %3d", imgarray[jj][ii]);
1888 }
1889 printf("\n");
1890 }
1891
1892 for (jj = 0; jj < 30; jj++)
1893 {
1894 for (ii = 0; ii < 19; ii++)
1895 {
1896 imgarray[jj][ii] = 0;
1897 }
1898 }
1899
1900 for (jj = 0; jj < 20; jj++)
1901 {
1902 for (ii = 0; ii < 10; ii++)
1903 {
1904 imgarray2[jj][ii] = (short) ((jj * -10) - ii);
1905 }
1906 }
1907
1908 fpixels[0] = 5;
1909 fpixels[1] = 5;
1910 lpixels[0] = 14;
1911 lpixels[1] = 14;
1912 ffpssi(fptr, 1, naxis, naxes, fpixels, lpixels,
1913 imgarray2[0], &status);
1914 printf("\nWrote subset 2D array: ffpssi status = %d\n", status);
1915
1916 ffg2di(fptr, 1, 0, 19, naxes[0], naxes[1], imgarray[0], &anynull,
1917 &status);
1918 printf("\nRead whole 2D array: ffg2di status = %d\n", status);
1919
1920 for (jj = 0; jj < 30; jj++)
1921 {
1922 for (ii = 0; ii < 19; ii++)
1923 {
1924 printf(" %3d", imgarray[jj][ii]);
1925 }
1926 printf("\n");
1927 }
1928
1929 fpixels[0] = 2;
1930 fpixels[1] = 5;
1931 lpixels[0] = 10;
1932 lpixels[1] = 8;
1933 inc[0] = 2;
1934 inc[1] = 3;
1935
1936 for (jj = 0; jj < 30; jj++)
1937 {
1938 for (ii = 0; ii < 19; ii++)
1939 {
1940 imgarray[jj][ii] = 0;
1941 }
1942 }
1943
1944 ffgsvi(fptr, 1, naxis, naxes, fpixels, lpixels, inc, 0,
1945 imgarray[0], &anynull, &status);
1946 printf("\nRead subset of 2D array: ffgsvi status = %d\n", status);
1947
1948 for (ii = 0; ii < 10; ii++)
1949 {
1950 printf(" %3d", imgarray[0][ii]);
1951 }
1952 printf("\n");
1953
1954 /*
1955 ###########################################################
1956 # insert another image extension #
1957 # copy the image extension to primary array of tmp file. #
1958 # then delete the tmp file, and the image extension #
1959 ###########################################################
1960 */
1961 bitpix = 16;
1962 naxis = 2;
1963 naxes[0] = 15;
1964 naxes[1] = 25;
1965 ffiimg(fptr, bitpix, naxis, naxes, &status);
1966 printf("\nCreate image extension: ffiimg status = %d\n", status);
1967 printf("HDU number = %d\n", ffghdn(fptr, &hdunum));
1968
1969 strcpy(filename, "t1q2s3v4.tmp");
1970 ffinit(&tmpfptr, filename, &status);
1971 printf("Create temporary file: ffinit status = %d\n", status);
1972
1973 ffcopy(fptr, tmpfptr, 0, &status);
1974 printf("Copy image extension to primary array of tmp file.\n");
1975 printf("ffcopy status = %d\n", status);
1976
1977 ffgrec(tmpfptr, 1, card, &status);
1978 printf("%s\n", card);
1979 ffgrec(tmpfptr, 2, card, &status);
1980 printf("%s\n", card);
1981 ffgrec(tmpfptr, 3, card, &status);
1982 printf("%s\n", card);
1983 ffgrec(tmpfptr, 4, card, &status);
1984 printf("%s\n", card);
1985 ffgrec(tmpfptr, 5, card, &status);
1986 printf("%s\n", card);
1987 ffgrec(tmpfptr, 6, card, &status);
1988 printf("%s\n", card);
1989
1990 ffdelt(tmpfptr, &status);
1991 printf("Delete the tmp file: ffdelt status = %d\n", status);
1992
1993 ffdhdu(fptr, &hdutype, &status);
1994 printf("Delete the image extension; hdutype, status = %d %d\n",
1995 hdutype, status);
1996 printf("HDU number = %d\n", ffghdn(fptr, &hdunum));
1997
1998 /*
1999 ###########################################################
2000 # append bintable extension with variable length columns #
2001 ###########################################################
2002 */
2003
2004 ffcrhd(fptr, &status);
2005 printf("ffcrhd status = %d\n", status);
2006
2007 strcpy(tform[0], "1PA");
2008 strcpy(tform[1], "1PL");
2009 strcpy(tform[2], "1PB"); /* Fortran FITSIO doesn't support 1PX */
2010 strcpy(tform[3], "1PB");
2011 strcpy(tform[4], "1PI");
2012 strcpy(tform[5], "1PJ");
2013 strcpy(tform[6], "1PE");
2014 strcpy(tform[7], "1PD");
2015 strcpy(tform[8], "1PC");
2016 strcpy(tform[9], "1PM");
2017
2018 strcpy(ttype[0], "Avalue");
2019 strcpy(ttype[1], "Lvalue");
2020 strcpy(ttype[2], "Xvalue");
2021 strcpy(ttype[3], "Bvalue");
2022 strcpy(ttype[4], "Ivalue");
2023 strcpy(ttype[5], "Jvalue");
2024 strcpy(ttype[6], "Evalue");
2025 strcpy(ttype[7], "Dvalue");
2026 strcpy(ttype[8], "Cvalue");
2027 strcpy(ttype[9], "Mvalue");
2028
2029 strcpy(tunit[0], "");
2030 strcpy(tunit[1], "m**2");
2031 strcpy(tunit[2], "cm");
2032 strcpy(tunit[3], "erg/s");
2033 strcpy(tunit[4], "km/s");
2034 strcpy(tunit[5], "");
2035 strcpy(tunit[6], "");
2036 strcpy(tunit[7], "");
2037 strcpy(tunit[8], "");
2038 strcpy(tunit[9], "");
2039
2040 nrows = 20;
2041 tfields = 10;
2042 pcount = 0;
2043
2044 ffphbn(fptr, nrows, tfields, ttype, tform, tunit, binname, pcount,
2045 &status);
2046 printf("Variable length arrays: ffphbn status = %d\n", status);
2047
2048
2049 extvers = 4;
2050 ffpkyj(fptr, "EXTVER", extvers, "extension version number", &status);
2051
2052 ffpkyj(fptr, "TNULL4", 88, "value for undefined pixels", &status);
2053 ffpkyj(fptr, "TNULL5", 88, "value for undefined pixels", &status);
2054 ffpkyj(fptr, "TNULL6", 88, "value for undefined pixels", &status);
2055
2056 /*
2057 ############################
2058 # write data to columns #
2059 ############################
2060 */
2061
2062 /* initialize arrays of values to write to table */
2063 strcpy(iskey,"abcdefghijklmnopqrst");
2064
2065 for (ii = 0; ii < 20; ii++)
2066 {
2067 boutarray[ii] = (unsigned char) (ii + 1);
2068 ioutarray[ii] = (short) (ii + 1);
2069 joutarray[ii] = ii + 1;
2070 eoutarray[ii] = (float) (ii + 1);
2071 doutarray[ii] = ii + 1;
2072 }
2073
2074 larray[0] = 0;
2075 larray[1] = 1;
2076 larray[2] = 0;
2077 larray[3] = 0;
2078 larray[4] = 1;
2079 larray[5] = 1;
2080 larray[6] = 0;
2081 larray[7] = 0;
2082 larray[8] = 0;
2083 larray[9] = 1;
2084 larray[10] = 1;
2085 larray[11] = 1;
2086 larray[12] = 0;
2087 larray[13] = 0;
2088 larray[14] = 0;
2089 larray[15] = 0;
2090 larray[16] = 1;
2091 larray[17] = 1;
2092 larray[18] = 1;
2093 larray[19] = 1;
2094
2095 /* write values in 1st row */
2096 /* strncpy(inskey[0], iskey, 1); */
2097 inskey[0][0] = '\0'; /* write a null string (i.e., a blank) */
2098 ffpcls(fptr, 1, 1, 1, 1, inskey, &status); /* write string values */
2099 ffpcll(fptr, 2, 1, 1, 1, larray, &status); /* write logicals */
2100 ffpclx(fptr, 3, 1, 1, 1, larray, &status); /* write bits */
2101 ffpclb(fptr, 4, 1, 1, 1, boutarray, &status);
2102 ffpcli(fptr, 5, 1, 1, 1, ioutarray, &status);
2103 ffpclj(fptr, 6, 1, 1, 1, joutarray, &status);
2104 ffpcle(fptr, 7, 1, 1, 1, eoutarray, &status);
2105 ffpcld(fptr, 8, 1, 1, 1, doutarray, &status);
2106
2107 for (ii = 2; ii <= 20; ii++) /* loop over rows 1 - 20 */
2108 {
2109 strncpy(inskey[0], iskey, ii);
2110 inskey[0][ii] = '\0';
2111 ffpcls(fptr, 1, ii, 1, 1, inskey, &status); /* write string values */
2112
2113 ffpcll(fptr, 2, ii, 1, ii, larray, &status); /* write logicals */
2114 ffpclu(fptr, 2, ii, ii-1, 1, &status);
2115
2116 ffpclx(fptr, 3, ii, 1, ii, larray, &status); /* write bits */
2117
2118 ffpclb(fptr, 4, ii, 1, ii, boutarray, &status);
2119 ffpclu(fptr, 4, ii, ii-1, 1, &status);
2120
2121 ffpcli(fptr, 5, ii, 1, ii, ioutarray, &status);
2122 ffpclu(fptr, 5, ii, ii-1, 1, &status);
2123
2124 ffpclj(fptr, 6, ii, 1, ii, joutarray, &status);
2125 ffpclu(fptr, 6, ii, ii-1, 1, &status);
2126
2127 ffpcle(fptr, 7, ii, 1, ii, eoutarray, &status);
2128 ffpclu(fptr, 7, ii, ii-1, 1, &status);
2129
2130 ffpcld(fptr, 8, ii, 1, ii, doutarray, &status);
2131 ffpclu(fptr, 8, ii, ii-1, 1, &status);
2132 }
2133 printf("ffpcl_ status = %d\n", status);
2134
2135 /*
2136 #################################
2137 # close then reopen this HDU #
2138 #################################
2139 */
2140
2141
2142 ffmrhd(fptr, -1, &hdutype, &status);
2143 ffmrhd(fptr, 1, &hdutype, &status);
2144
2145 /*
2146 #############################
2147 # read data from columns #
2148 #############################
2149 */
2150
2151 ffgkyj(fptr, "PCOUNT", &pcount, comm, &status);
2152 printf("PCOUNT = %ld\n", pcount);
2153
2154 /* initialize the variables to be read */
2155 strcpy(inskey[0]," ");
2156 strcpy(iskey," ");
2157
2158
2159 printf("HDU number = %d\n", ffghdn(fptr, &hdunum));
2160 for (ii = 1; ii <= 20; ii++) /* loop over rows 1 - 20 */
2161 {
2162 for (jj = 0; jj < ii; jj++)
2163 {
2164 larray[jj] = 0;
2165 boutarray[jj] = 0;
2166 ioutarray[jj] = 0;
2167 joutarray[jj] = 0;
2168 eoutarray[jj] = 0;
2169 doutarray[jj] = 0;
2170 }
2171
2172 ffgcvs(fptr, 1, ii, 1, 1, iskey, inskey, &anynull, &status);
2173 printf("A %s %d\nL", inskey[0], status);
2174
2175 ffgcl( fptr, 2, ii, 1, ii, larray, &status);
2176 for (jj = 0; jj < ii; jj++)
2177 printf(" %2d", larray[jj]);
2178 printf(" %d\nX", status);
2179
2180 ffgcx(fptr, 3, ii, 1, ii, larray, &status);
2181 for (jj = 0; jj < ii; jj++)
2182 printf(" %2d", larray[jj]);
2183 printf(" %d\nB", status);
2184
2185 ffgcvb(fptr, 4, ii, 1, ii, 99, boutarray, &anynull, &status);
2186 for (jj = 0; jj < ii; jj++)
2187 printf(" %2d", boutarray[jj]);
2188 printf(" %d\nI", status);
2189
2190 ffgcvi(fptr, 5, ii, 1, ii, 99, ioutarray, &anynull, &status);
2191 for (jj = 0; jj < ii; jj++)
2192 printf(" %2d", ioutarray[jj]);
2193 printf(" %d\nJ", status);
2194
2195 ffgcvj(fptr, 6, ii, 1, ii, 99, joutarray, &anynull, &status);
2196 for (jj = 0; jj < ii; jj++)
2197 printf(" %2ld", joutarray[jj]);
2198 printf(" %d\nE", status);
2199
2200 ffgcve(fptr, 7, ii, 1, ii, 99., eoutarray, &anynull, &status);
2201 for (jj = 0; jj < ii; jj++)
2202 printf(" %2.0f", eoutarray[jj]);
2203 printf(" %d\nD", status);
2204
2205 ffgcvd(fptr, 8, ii, 1, ii, 99., doutarray, &anynull, &status);
2206 for (jj = 0; jj < ii; jj++)
2207 printf(" %2.0f", doutarray[jj]);
2208 printf(" %d\n", status);
2209
2210 ffgdes(fptr, 8, ii, &repeat, &offset, &status);
2211 printf("Column 8 repeat and offset = %ld %ld\n", repeat, offset);
2212 }
2213
2214 /*
2215 #####################################
2216 # create another image extension #
2217 #####################################
2218 */
2219
2220 bitpix = 32;
2221 naxis = 2;
2222 naxes[0] = 10;
2223 naxes[1] = 2;
2224 npixels = 20;
2225
2226 /* ffcrim(fptr, bitpix, naxis, naxes, &status); */
2227 ffiimg(fptr, bitpix, naxis, naxes, &status);
2228 printf("\nffcrim status = %d\n", status);
2229
2230 /* initialize arrays of values to write to primary array */
2231 for (ii = 0; ii < npixels; ii++)
2232 {
2233 boutarray[ii] = (unsigned char) (ii * 2);
2234 ioutarray[ii] = (short) (ii * 2);
2235 joutarray[ii] = ii * 2;
2236 koutarray[ii] = ii * 2;
2237 eoutarray[ii] = (float) (ii * 2);
2238 doutarray[ii] = ii * 2;
2239 }
2240
2241 /* write a few pixels with each datatype */
2242 ffppr(fptr, TBYTE, 1, 2, &boutarray[0], &status);
2243 ffppr(fptr, TSHORT, 3, 2, &ioutarray[2], &status);
2244 ffppr(fptr, TINT, 5, 2, &koutarray[4], &status);
2245 ffppr(fptr, TSHORT, 7, 2, &ioutarray[6], &status);
2246 ffppr(fptr, TLONG, 9, 2, &joutarray[8], &status);
2247 ffppr(fptr, TFLOAT, 11, 2, &eoutarray[10], &status);
2248 ffppr(fptr, TDOUBLE, 13, 2, &doutarray[12], &status);
2249 printf("ffppr status = %d\n", status);
2250
2251 /* read back the pixels with each datatype */
2252 bnul = 0;
2253 inul = 0;
2254 knul = 0;
2255 jnul = 0;
2256 enul = 0.;
2257 dnul = 0.;
2258
2259 ffgpv(fptr, TBYTE, 1, 14, &bnul, binarray, &anynull, &status);
2260 ffgpv(fptr, TSHORT, 1, 14, &inul, iinarray, &anynull, &status);
2261 ffgpv(fptr, TINT, 1, 14, &knul, kinarray, &anynull, &status);
2262 ffgpv(fptr, TLONG, 1, 14, &jnul, jinarray, &anynull, &status);
2263 ffgpv(fptr, TFLOAT, 1, 14, &enul, einarray, &anynull, &status);
2264 ffgpv(fptr, TDOUBLE, 1, 14, &dnul, dinarray, &anynull, &status);
2265
2266 printf("\nImage values written with ffppr and read with ffgpv:\n");
2267 npixels = 14;
2268 for (ii = 0; ii < npixels; ii++)
2269 printf(" %2d", binarray[ii]);
2270 printf(" %d (byte)\n", anynull);
2271 for (ii = 0; ii < npixels; ii++)
2272 printf(" %2d", iinarray[ii]);
2273 printf(" %d (short)\n", anynull);
2274 for (ii = 0; ii < npixels; ii++)
2275 printf(" %2d", kinarray[ii]);
2276 printf(" %d (int)\n", anynull);
2277 for (ii = 0; ii < npixels; ii++)
2278 printf(" %2ld", jinarray[ii]);
2279 printf(" %d (long)\n", anynull);
2280 for (ii = 0; ii < npixels; ii++)
2281 printf(" %2.0f", einarray[ii]);
2282 printf(" %d (float)\n", anynull);
2283 for (ii = 0; ii < npixels; ii++)
2284 printf(" %2.0f", dinarray[ii]);
2285 printf(" %d (double)\n", anynull);
2286
2287 /*
2288 ##########################################
2289 # test world coordinate system routines #
2290 ##########################################
2291 */
2292
2293 xrval = 45.83;
2294 yrval = 63.57;
2295 xrpix = 256.;
2296 yrpix = 257.;
2297 xinc = -.00277777;
2298 yinc = .00277777;
2299
2300 /* write the WCS keywords */
2301 /* use example values from the latest WCS document */
2302 ffpkyd(fptr, "CRVAL1", xrval, 10, "comment", &status);
2303 ffpkyd(fptr, "CRVAL2", yrval, 10, "comment", &status);
2304 ffpkyd(fptr, "CRPIX1", xrpix, 10, "comment", &status);
2305 ffpkyd(fptr, "CRPIX2", yrpix, 10, "comment", &status);
2306 ffpkyd(fptr, "CDELT1", xinc, 10, "comment", &status);
2307 ffpkyd(fptr, "CDELT2", yinc, 10, "comment", &status);
2308 /* ffpkyd(fptr, "CROTA2", rot, 10, "comment", &status); */
2309 ffpkys(fptr, "CTYPE1", xcoordtype, "comment", &status);
2310 ffpkys(fptr, "CTYPE2", ycoordtype, "comment", &status);
2311 printf("\nWrote WCS keywords status = %d\n",status);
2312
2313 xrval = 0.;
2314 yrval = 0.;
2315 xrpix = 0.;
2316 yrpix = 0.;
2317 xinc = 0.;
2318 yinc = 0.;
2319 rot = 0.;
2320
2321 ffgics(fptr, &xrval, &yrval, &xrpix,
2322 &yrpix, &xinc, &yinc, &rot, ctype, &status);
2323 printf("Read WCS keywords with ffgics status = %d\n",status);
2324
2325 xpix = 0.5;
2326 ypix = 0.5;
2327
2328 ffwldp(xpix,ypix,xrval,yrval,xrpix,yrpix,xinc,yinc,rot,ctype,
2329 &xpos, &ypos,&status);
2330
2331 printf(" CRVAL1, CRVAL2 = %16.12f, %16.12f\n", xrval,yrval);
2332 printf(" CRPIX1, CRPIX2 = %16.12f, %16.12f\n", xrpix,yrpix);
2333 printf(" CDELT1, CDELT2 = %16.12f, %16.12f\n", xinc,yinc);
2334 printf(" Rotation = %10.3f, CTYPE = %s\n", rot, ctype);
2335 printf("Calculated sky coordinate with ffwldp status = %d\n",status);
2336 printf(" Pixels (%8.4f,%8.4f) --> (%11.6f, %11.6f) Sky\n",
2337 xpix,ypix,xpos,ypos);
2338 ffxypx(xpos,ypos,xrval,yrval,xrpix,yrpix,xinc,yinc,rot,ctype,
2339 &xpix, &ypix,&status);
2340 printf("Calculated pixel coordinate with ffxypx status = %d\n",status);
2341 printf(" Sky (%11.6f, %11.6f) --> (%8.4f,%8.4f) Pixels\n",
2342 xpos,ypos,xpix,ypix);
2343 /*
2344 ######################################
2345 # append another ASCII table #
2346 ######################################
2347 */
2348
2349 strcpy(tform[0], "A15");
2350 strcpy(tform[1], "I11");
2351 strcpy(tform[2], "F15.6");
2352 strcpy(tform[3], "E13.5");
2353 strcpy(tform[4], "D22.14");
2354
2355 strcpy(ttype[0], "Name");
2356 strcpy(ttype[1], "Ivalue");
2357 strcpy(ttype[2], "Fvalue");
2358 strcpy(ttype[3], "Evalue");
2359 strcpy(ttype[4], "Dvalue");
2360
2361 strcpy(tunit[0], "");
2362 strcpy(tunit[1], "m**2");
2363 strcpy(tunit[2], "cm");
2364 strcpy(tunit[3], "erg/s");
2365 strcpy(tunit[4], "km/s");
2366
2367 nrows = 11;
2368 tfields = 5;
2369 strcpy(tblname, "new_table");
2370
2371 ffcrtb(fptr, ASCII_TBL, nrows, tfields, ttype, tform, tunit, tblname,
2372 &status);
2373 printf("\nffcrtb status = %d\n", status);
2374
2375 extvers = 5;
2376 ffpkyj(fptr, "EXTVER", extvers, "extension version number", &status);
2377
2378 ffpcl(fptr, TSTRING, 1, 1, 1, 3, onskey, &status); /* write string values */
2379
2380 /* initialize arrays of values to write */
2381
2382 for (ii = 0; ii < npixels; ii++)
2383 {
2384 boutarray[ii] = (unsigned char) (ii * 3);
2385 ioutarray[ii] = (short) (ii * 3);
2386 joutarray[ii] = ii * 3;
2387 koutarray[ii] = ii * 3;
2388 eoutarray[ii] = (float) (ii * 3);
2389 doutarray[ii] = ii * 3;
2390 }
2391
2392 for (ii = 2; ii < 6; ii++) /* loop over cols 2 - 5 */
2393 {
2394 ffpcl(fptr, TBYTE, ii, 1, 1, 2, boutarray, &status);
2395 ffpcl(fptr, TSHORT, ii, 3, 1, 2, &ioutarray[2], &status);
2396 ffpcl(fptr, TLONG, ii, 5, 1, 2, &joutarray[4], &status);
2397 ffpcl(fptr, TFLOAT, ii, 7, 1, 2, &eoutarray[6], &status);
2398 ffpcl(fptr, TDOUBLE, ii, 9, 1, 2, &doutarray[8], &status);
2399 }
2400 printf("ffpcl status = %d\n", status);
2401
2402 /* read back the pixels with each datatype */
2403 ffgcv(fptr, TBYTE, 2, 1, 1, 10, &bnul, binarray, &anynull, &status);
2404 ffgcv(fptr, TSHORT, 2, 1, 1, 10, &inul, iinarray, &anynull, &status);
2405 ffgcv(fptr, TINT, 3, 1, 1, 10, &knul, kinarray, &anynull, &status);
2406 ffgcv(fptr, TLONG, 3, 1, 1, 10, &jnul, jinarray, &anynull, &status);
2407 ffgcv(fptr, TFLOAT, 4, 1, 1, 10, &enul, einarray, &anynull, &status);
2408 ffgcv(fptr, TDOUBLE, 5, 1, 1, 10, &dnul, dinarray, &anynull, &status);
2409
2410 printf("\nColumn values written with ffpcl and read with ffgcl:\n");
2411 npixels = 10;
2412 for (ii = 0; ii < npixels; ii++)
2413 printf(" %2d", binarray[ii]);
2414 printf(" %d (byte)\n", anynull);
2415 for (ii = 0; ii < npixels; ii++)
2416 printf(" %2d", iinarray[ii]);
2417 printf(" %d (short)\n", anynull);
2418
2419 for (ii = 0; ii < npixels; ii++)
2420 printf(" %2d", kinarray[ii]);
2421 printf(" %d (int)\n", anynull);
2422
2423 for (ii = 0; ii < npixels; ii++)
2424 printf(" %2ld", jinarray[ii]);
2425 printf(" %d (long)\n", anynull);
2426 for (ii = 0; ii < npixels; ii++)
2427 printf(" %2.0f", einarray[ii]);
2428 printf(" %d (float)\n", anynull);
2429 for (ii = 0; ii < npixels; ii++)
2430 printf(" %2.0f", dinarray[ii]);
2431 printf(" %d (double)\n", anynull);
2432
2433 /*
2434 ###########################################################
2435 # perform stress test by cycling thru all the extensions #
2436 ###########################################################
2437 */
2438 printf("\nRepeatedly move to the 1st 4 HDUs of the file:\n");
2439 for (ii = 0; ii < 10; ii++)
2440 {
2441 ffmahd(fptr, 1, &hdutype, &status);
2442 printf("%d", ffghdn(fptr, &hdunum));
2443 ffmrhd(fptr, 1, &hdutype, &status);
2444 printf("%d", ffghdn(fptr, &hdunum));
2445 ffmrhd(fptr, 1, &hdutype, &status);
2446 printf("%d", ffghdn(fptr, &hdunum));
2447 ffmrhd(fptr, 1, &hdutype, &status);
2448 printf("%d", ffghdn(fptr, &hdunum));
2449 ffmrhd(fptr, -1, &hdutype, &status);
2450 printf("%d", ffghdn(fptr, &hdunum));
2451 if (status > 0)
2452 break;
2453 }
2454 printf("\n");
2455
2456 printf("Move to extensions by name and version number: (ffmnhd)\n");
2457 extvers = 1;
2458 ffmnhd(fptr, ANY_HDU, binname, (int) extvers, &status);
2459 ffghdn(fptr, &hdunum);
2460 printf(" %s, %ld = hdu %d, %d\n", binname, extvers, hdunum, status);
2461 extvers = 3;
2462 ffmnhd(fptr, ANY_HDU, binname, (int) extvers, &status);
2463 ffghdn(fptr, &hdunum);
2464 printf(" %s, %ld = hdu %d, %d\n", binname, extvers, hdunum, status);
2465 extvers = 4;
2466 ffmnhd(fptr, ANY_HDU, binname, (int) extvers, &status);
2467 ffghdn(fptr, &hdunum);
2468 printf(" %s, %ld = hdu %d, %d\n", binname, extvers, hdunum, status);
2469
2470
2471 strcpy(tblname, "Test-ASCII");
2472 extvers = 2;
2473 ffmnhd(fptr, ANY_HDU, tblname, (int) extvers, &status);
2474 ffghdn(fptr, &hdunum);
2475 printf(" %s, %ld = hdu %d, %d\n", tblname, extvers, hdunum, status);
2476
2477 strcpy(tblname, "new_table");
2478 extvers = 5;
2479 ffmnhd(fptr, ANY_HDU, tblname, (int) extvers, &status);
2480 ffghdn(fptr, &hdunum);
2481 printf(" %s, %ld = hdu %d, %d\n", tblname, extvers, hdunum, status);
2482 extvers = 0;
2483 ffmnhd(fptr, ANY_HDU, binname, (int) extvers, &status);
2484 ffghdn(fptr, &hdunum);
2485 printf(" %s, %ld = hdu %d, %d\n", binname, extvers, hdunum, status);
2486 extvers = 17;
2487 ffmnhd(fptr, ANY_HDU, binname, (int) extvers, &status);
2488 ffghdn(fptr, &hdunum);
2489 printf(" %s, %ld = hdu %d, %d", binname, extvers, hdunum, status);
2490 printf (" (expect a 301 error status here)\n");
2491 status = 0;
2492
2493 ffthdu(fptr, &hdunum, &status);
2494 printf("Total number of HDUs in the file = %d\n", hdunum);
2495 /*
2496 ########################
2497 # checksum tests #
2498 ########################
2499 */
2500 checksum = 1234567890;
2501 ffesum(checksum, 0, asciisum);
2502 printf("\nEncode checksum: %lu -> %s\n", checksum, asciisum);
2503 checksum = 0;
2504 ffdsum(asciisum, 0, &checksum);
2505 printf("Decode checksum: %s -> %lu\n", asciisum, checksum);
2506
2507 ffpcks(fptr, &status);
2508
2509 /*
2510 don't print the CHECKSUM value because it is different every day
2511 because the current date is in the comment field.
2512
2513 ffgcrd(fptr, "CHECKSUM", card, &status);
2514 printf("%s\n", card);
2515 */
2516
2517 ffgcrd(fptr, "DATASUM", card, &status);
2518 printf("%.30s\n", card);
2519
2520 ffgcks(fptr, &datsum, &checksum, &status);
2521 printf("ffgcks data checksum, status = %lu, %d\n",
2522 datsum, status);
2523
2524 ffvcks(fptr, &datastatus, &hdustatus, &status);
2525 printf("ffvcks datastatus, hdustatus, status = %d %d %d\n",
2526 datastatus, hdustatus, status);
2527
2528 ffprec(fptr,
2529 "new_key = 'written by fxprec' / to change checksum", &status);
2530 ffupck(fptr, &status);
2531 printf("ffupck status = %d\n", status);
2532
2533 ffgcrd(fptr, "DATASUM", card, &status);
2534 printf("%.30s\n", card);
2535 ffvcks(fptr, &datastatus, &hdustatus, &status);
2536 printf("ffvcks datastatus, hdustatus, status = %d %d %d\n",
2537 datastatus, hdustatus, status);
2538
2539 /*
2540 delete the checksum keywords, so that the FITS file is always
2541 the same, regardless of the date of when testprog is run.
2542 */
2543
2544 ffdkey(fptr, "CHECKSUM", &status);
2545 ffdkey(fptr, "DATASUM", &status);
2546
2547 /*
2548 ############################
2549 # close file and quit #
2550 ############################
2551 */
2552
2553 errstatus: /* jump here on error */
2554
2555 ffclos(fptr, &status);
2556 printf("ffclos status = %d\n", status);
2557
2558 printf("\nNormally, there should be 8 error messages on the stack\n");
2559 printf("all regarding 'numerical overflows':\n");
2560
2561 ffgmsg(errmsg);
2562 nmsg = 0;
2563
2564 while (errmsg[0])
2565 {
2566 printf(" %s\n", errmsg);
2567 nmsg++;
2568 ffgmsg(errmsg);
2569 }
2570
2571 if (nmsg != 8)
2572 printf("\nWARNING: Did not find the expected 8 error messages!\n");
2573
2574 ffgerr(status, errmsg);
2575 printf("\nStatus = %d: %s\n", status, errmsg);
2576
2577 /* free the allocated memory */
2578 for (ii = 0; ii < 21; ii++)
2579 free(inskey[ii]);
2580 for (ii = 0; ii < 10; ii++)
2581 {
2582 free(ttype[ii]);
2583 free(tform[ii]);
2584 free(tunit[ii]);
2585 }
2586
2587 return(status);
2588 }
2589
2590