Debian Codegraph @

libsrc/st/midfctb.c

raw
1 /*===========================================================================
2 Copyright (C) 1995-2009 European Southern Observatory (ESO)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with this program; if not, write to the Free
16 Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
17 MA 02139, USA.
18
19 Correspondence concerning ESO-MIDAS should be addressed as follows:
20 Internet e-mail: [email protected]
21 Postal address: European Southern Observatory
22 Data Management Division
23 Karl-Schwarzschild-Strasse 2
24 D 85748 Garching bei Muenchen
25 GERMANY
26 ===========================================================================*/
27
28 /*+++++++++++++++++++++ Module MIDFCTB +++++++++++++++++++++++++++++++++++++++
29 .LANGUAGE C
30 .IDENTIFICATION Module MIDFCTB.C
31 .AUTHOR Klaus Banse
32 .KEYWORDS Midas FITS utility routines.
33 .ENVIRONMENT VMS and UNIX
34 .COMMENTS
35 holds the FITS input routines: MID_fitstest, MID_fitsin, MID_fitsrdm, MyPut
36
37 .VERSION
38 090326 last modif
39 ------------------------------------------------------------------------*/
40
41 #include <fileexts.h>
42 #include <fsydef.h>
43 #include <errext.h>
44 #include <proto_st.h>
45 #include <proto_tbl.h>
46 #include <proto_dio.h>
47
48 #include <osyparms.h> /* General data definitions */
49 #include <fitsfmt.h> /* General data definitions */
50 #include <fitsdef.h> /* Basic FITS definitions */
51 #include <fitskwt.h> /* Table Extension definitions */
52 #include <computer.h> /* computer specific constants */
53
54 #include <stdio.h>
55 #include <stdlib.h>
56 #include <string.h>
57
58
59 static char *dataout_ptr; /* used in MyPut */
60 static int dataout_outtyp;
61 static int eco, elo, edi; /* for ERRO_CONT, _LOG, _DISP */
62
63 /*
64
65 */
66
67 #ifdef __STDC__
68 void reset_ERRO(int fid)
69 #else
70 void reset_ERRO(fid)
71 int fid;
72 #endif
73
74 {
75 ERRO_CONT = eco; /* reset ERROR environment again */
76 ERRO_LOG = elo;
77 ERRO_DISP = edi;
78
79 dclose(fid); /* close FITS file */
80 }
81
82
83
84
85 #ifdef __STDC__
86 int MID_fitstest(char *fname)
87 #else
88 int MID_fitstest(fname)
89 char *fname; /* IN: name of input FITS file */
90 #endif
91
92 {
93 char work[400], *nampntr;
94
95 int fidcount, fid, n, kpath, retstat;
96
97 extern char DATA_PATH[328];
98
99
100
101
102
103 retstat = -1;
104 kpath = fidcount = n = 0;
105 nampntr = fname;
106 work[0] = '^';
107
108
109 open_file:
110 if ((fid = dopen(nampntr,READ,'S',0)) < 0) /* try to open FITS file */
111 {
112 if (fidcount < 4)
113 {
114 (void) strncpy(work,&DATA_PATH[n],80);
115 if (work[0] != '^')
116 {
117 work[80] = ' ';
118 kpath = CGN_INDEXC(work,' ');
119 (void) strcpy(&work[kpath],fname); /* use new path */
120 nampntr = work;
121 fidcount ++;
122 n += 80;
123 goto open_file;
124 }
125 }
126 return retstat;
127 }
128
129
130 if (drinit() != FITS) /* check file format */
131 retstat = -2;
132 else
133 retstat = 0;
134
135 dclose(fid);
136
137 return retstat;
138 }
139 /*
140
141 */
142
143 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
144 .AUTHOR
145 K. Banse ESO/IPG
146 .KEYWORDS
147 FITS prime data matrix, decode, read
148 .PURPOSE
149 Read prime data matrix in FITS and create a MIDAS bdf-file
150 .ALGORITHM
151 Either just read the FITS header to create a corresponding Midas header
152 in memory
153 Or just skip the FITS header to get to the data.
154 .RETURN
155 status 0: OK, -1: cannot open file, -2: wrong format
156 -3: no data matrix, -4: bad output name
157 -5: unknown FITS extension
158 ---------------------------------------------------------------------*/
159
160 #ifdef __STDC__
161 int MID_fitsin(int flag, char *fname, int extensio, char *bname,
162 char *outbuf, int *mfd, int *info)
163 #else
164 int MID_fitsin(flag,fname,extensio,bname,outbuf,mfd,info)
165 int flag; /* IN: option = 0, get type of FITSfile [extension] (d)
166 = 1, get FITS header (a)
167 = 2, get FITS data (b)
168 = 3, skip FITS header (c) */
169 = -1, list all extensions (e)
170 = -2, get extno from extstring (f) */
171 char *fname; /* IN: name of input FITS file */
172 int extensio; /* IN: extension no. (a,d) */
173 char *bname; /* IN: name of output BDF file */
174 char *outbuf; /* IN/OUT: output buffer
175 (a) return path name if applicable
176 (b) pointer to data area to be filled
177 (c,d,e) ignored
178 (f) EXTNAME string */
179 int *mfd; /* IN/OUT: MIDAS file no.
180 output (a), input (b,c) */
181 int *info; /* OUT: info = FITS file type (a,d)
182 not used (b)
183 fileid from dopen (c)
184 no. of extensions (e)
185 extension no. of EXTNAME (f) */
186 #endif
187
188 {
189 char work[400], *nampntr, extlabel[24], temp[400];
190
191 int Mflag, dsize, fidcount, fid, err, kpath, n, type, mfdt, imno;
192 int extno, extcount, extrecs;
193 int eco, elo, edi; /* for ERRO_CONT, _LOG, _DISP */
194 register int nr;
195
196 BFDEF *bfdefptr, bfdef;
197 ADEF *adefptr, adef[MXDIM];
198 PDEF *pdefptr, pdef[MXPAR];
199
200 struct FCT_STRUCT *fctpntr;
201
202 extern char DATA_PATH[328];
203
204
205
206
207 /*
208 printf("... entering MID_fitsin with flag = %d, name = %s, ext = %d, bname = %s\n",
209 flag,fname,extensio,bname);
210 */
211
212
213 kpath = fidcount = n = 0;
214 nampntr = fname;
215 work[0] = '^';
216
217 open_file:
218 if ((fid = dopen(nampntr,READ,'S',0)) < 0) /* try to open FITS file */
219 {
220 if (fidcount < 4)
221 {
222 (void) strncpy(work,&DATA_PATH[n],80);
223 if (work[0] != '^')
224 {
225 work[80] = ' ';
226 kpath = CGN_INDEXC(work,' ');
227 (void) strcpy(&work[kpath],fname); /* use new path */
228 nampntr = work;
229 fidcount ++;
230 n += 80;
231 goto open_file;
232 }
233 }
234 return (-1);
235 }
236
237
238 if (drinit() != FITS) /* check file format */
239 { /* if not FITS format - exit */
240 dclose(fid);
241 return (-2);
242 }
243
244
245 eco = ERRO_CONT;
246 elo = ERRO_LOG;
247 edi = ERRO_DISP;
248
249
250 /* if flag < 2 we have to get the FITS header in */
251 /* --------------------------------------------- */
252
253 if (flag < 2) /* process flag = -1, 0, 1 */
254 {
255 char *mypntr;
256 int ln0;
257
258 *mfd = mfdt = -1; /* don't access data yet */
259 if (extensio < 0)
260 err = outname(bname,0,'y'); /* no extension, we just need a single name */
261 else
262 err = outname(bname,0,'x');
263 if (err)
264 { /* define output file name + check it */
265 dclose(fid);
266 return (-4);
267 }
268
269 mypntr = malloc((size_t) (sizeof(bfdef)));
270 if (mypntr == (char *) 0) return (-5);
271 bfdefptr = (BFDEF *) mypntr;
272
273 mypntr = malloc((size_t) (MXDIM*sizeof(adef)));
274 if (mypntr == (char *) 0) return (-5);
275 adefptr = (ADEF *) mypntr;
276
277 mypntr = malloc((size_t) (MXPAR*sizeof(pdef)));
278 if (mypntr == (char *) 0) return (-5);
279 pdefptr = (PDEF *) mypntr;
280
281 hdr_init_M(bfdefptr,&adefptr,&pdefptr,0); /* init internal structure */
282 extrecs = 0;
283
284
285 /* read FITS header, create file (only if flag = 1) */
286
287 ERRO_CONT = 1; /* disable SC-error handling */
288 ERRO_LOG = ERRO_DISP = 0;
289 /* instead of: ln1 = 1; ln0 = 0; SCECNT("PUT",&ln1,&ln0,&ln0); */
290
291 extcount = 0;
292
293 if (flag == 0) /* we just want info */
294 Mflag = -2;
295 else
296 Mflag = 1; /* maybe changed in next section */
297
298
299 /* for flag = -1, we just loop through all extensions */
300
301 if (flag == -1)
302 {
303 Mflag = -1;
304 type = fitsrhd(mfd,bfdefptr,&dsize,&mfdt,'O','Y',0,Mflag);
305
306 if (type < BFITS)
307 {
308 ERRO_CONT = eco; /* reset again */
309 ERRO_LOG = elo;
310 ERRO_DISP = edi;
311 dclose(fid);
312 return (-2);
313 }
314
315 memset((void *)work,32,(size_t)25); work[25] = '\0';
316 if (dsize < 1) /* an empty primary matrix, so look for next */
317 {
318 (void) strcpy(extlabel,"Empty primary header");
319 (void) snprintf(temp,(size_t) 400,"extension[%d] %s - type = %s",
320 extcount,work,extlabel);
321 }
322 else
323 {
324 if (type == ATABLE)
325 (void) strcpy(extlabel,"Ascii table");
326 else if (type == BTABLE)
327 (void) strcpy(extlabel,"Binary table");
328 else
329 (void) strcpy(extlabel,"Image");
330 (void) snprintf(temp,(size_t) 400,"extension[%d] %s - type = %s",
331 extcount,work,extlabel);
332 }
333 SCTPUT(temp);
334 extcount ++;
335
336 n_loop:
337 (void) fitssxd(dsize,1); /* skip data matrix */
338
339 hdr_init_M(bfdefptr,&adefptr,&pdefptr,1); /* init again */
340 type = fitsrhd(mfd,bfdefptr,&dsize,&mfdt,'O','Y',0,Mflag);
341
342
343 if (type == EOFITS)
344 { /* we reached EOF */
345 flag = 0;
346 *info = extcount; /* save total no. of extensions */
347 goto after_exttypes; /* continue like the rest */
348 }
349 else if (type < BFITS)
350 {
351 if (flag == -1)
352 {
353 SCTMES(M_BLUE_COLOR,"bad FITS extension ...we skip");
354 if (dsize > 0) fitssxd(dsize,0);
355 goto n_loop;
356 }
357 else
358 {
359 reset_ERRO(fid);
360 return (-2);
361 }
362 }
363
364
365 if (type == ATABLE)
366 (void) strcpy(extlabel,"Ascii table");
367 else if (type == BTABLE)
368 (void) strcpy(extlabel,"Binary table");
369 else if (type == IMAGE)
370 {
371 if (dsize < 1) /* an empty header */
372 (void) strcpy(extlabel,"Empty header");
373 else
374 (void) strcpy(extlabel,"Image");
375 }
376 else
377 {
378 if (dsize < 1) /* an empty header */
379 (void) strcpy(extlabel,"Empty header");
380 else
381 (void) strcpy(extlabel,"? ");
382 }
383
384 (void) snprintf(temp,(size_t) 400,
385 "extension[%d] EXTNAME: %16.16s - type = %s",
386 extcount,bfdefptr->extname,extlabel);
387 SCTPUT(temp);
388
389 extcount ++;
390 goto n_loop;
391 }
392
393 /* --- end of extension-check loop
394 if all o.k. we meet you at label after_exttypes: --- */
395
396
397
398 /* check, if we want an extension of the FITS file */
399
400 if ((flag != -2) && (extensio < 0)) /* No, frame without extension */
401 {
402 type = fitsrhd(mfd,bfdefptr,&dsize,&mfdt,'O','Y',0,Mflag);
403
404 if (type < -990) /* 1st look for TCTINI/SCFCRE errors */
405 {
406 if (type == -998)
407 SCTMES(M_RED_COLOR,"problems creating image...");
408 else
409 SCTMES(M_RED_COLOR,"problems creating table...");
410 reset_ERRO(fid);
411 return (-9);
412 }
413 if (type < BFITS) /* main header */
414 {
415 reset_ERRO(fid);
416 return (-2);
417 }
418
419 if (dsize > 0) /* basic FITS goes to IMAGE type */
420 *info = 1;
421 else
422 { /* search for first non-empty header */
423 if (flag == 0) Mflag = -1;
424
425 while ( (dsize < 1) &&
426 ((type == BFITS) || (type == IMAGE)) )
427 {
428 *mfd = -1; mfdt = -1;
429 hdr_init_M(bfdefptr,&adefptr,&pdefptr,1); /* init again */
430 type = fitsrhd(mfd,bfdefptr,&dsize,&mfdt,'O','Y',0,Mflag);
431
432 if (type < -990) /* 1st look for TCTINI/SCFCRE errors */
433 {
434 if (type == -998)
435 SCTMES(M_RED_COLOR,"problems creating image...");
436 else
437 SCTMES(M_RED_COLOR,"problems creating table...");
438 reset_ERRO(fid);
439 return (-9);
440 }
441 if (type == EOFITS)
442 {
443 reset_ERRO(fid);
444 return (-6);
445 }
446 }
447
448 *info = 0;
449 if (type == ATABLE)
450 *info = 3;
451 else if (type == BTABLE)
452 *info = 2;
453 else if (type == IMAGE)
454 *info = 1;
455 extcount ++; /* count extensions */
456 }
457
458 extno = 0; /* ext.no. 0 = main frame */
459 goto after_exttypes;
460 }
461
462
463 /* Yes - we do have an extension */
464
465 if (flag != -2)
466 {
467 extno = extensio;
468 extlabel[0] = '\0';
469 }
470
471 /* we have to find extension with EXTNAME = input string (outbuf) */
472 else
473 {
474 extno = 1000;
475 extlabel[16] = '\0'; /* extensions have max. 16 chars */
476
477 if (outbuf[0] == '"')
478 {
479 for (nr=0; nr<16; nr++)
480 {
481 extlabel[nr] = outbuf[nr+1];
482 if (extlabel[nr] == '"')
483 {
484 extlabel[nr] = '\0';
485 break;
486 }
487 }
488 }
489 else
490 {
491 for (nr=0; nr<16; nr++)
492 {
493 extlabel[nr] = outbuf[nr];
494 if (extlabel[nr] == ' ')
495 {
496 extlabel[nr] = '\0';
497 break;
498 }
499 }
500 }
501 CGN_UPSTR(extlabel);
502 }
503
504
505 /* read very first FITS header */
506
507 if (Mflag == 1)
508 Mflag = 101; /* mark possible empty file for `fitsrhd' */
509
510 if ((extno > 0) && (Mflag == 101))
511 n = Mflag + 200; /* now 301 */
512 else
513 n = Mflag;
514
515 type = fitsrhd(mfd,bfdefptr,&dsize,&mfdt,'O','Y',0,n);
516 if (type < -990) /* 1st look for TCTINI/SCFCRE errors */
517 {
518 if (type == -998)
519 SCTMES(M_RED_COLOR,"problems creating image...");
520 else
521 SCTMES(M_RED_COLOR,"problems creating table...");
522 reset_ERRO(fid);
523 return (-9);
524 }
525 if (type < BFITS) /* main header */
526 {
527 reset_ERRO(fid);
528 return (-2);
529 }
530
531
532 /* extension 0 has to be treated specially */
533
534 if (extno == 0)
535 {
536 *info = 1; /* always type IMAGE */
537 extno = -1; /* so it's recognized as an extension */
538 goto after_exttypes;
539 }
540
541
542 /* save type of header */
543
544 if (dsize < 1) /* empty primary header -> IMAGE */
545 *info = 1;
546 else
547 {
548 *info = 0;
549 if (type == ATABLE)
550 *info = 3;
551 else if (type == BTABLE)
552 *info = 2;
553 else if (type == IMAGE)
554 *info = 1;
555 }
556
557
558 /* an extension cannot be the first header...
559 so, we move on to next extension of FITS file */
560
561 extens_loop:
562 if (flag == 0) Mflag = -1;
563
564 if (dsize > 0)
565 {
566 ln0 = fitssxd(dsize,1); /* skip data matrix */
567 extrecs += ln0;
568 }
569
570 if (*mfd > -1)
571 { /* clear previously created files */
572 if (*info > 1)
573 (void) TCTCLO(*mfd);
574 else
575 (void) SCFCLO(*mfd);
576 }
577
578 *mfd = -1; mfdt = -1;
579 hdr_init_M(bfdefptr,&adefptr,&pdefptr,1); /* init again */
580
581 type = fitsrhd(mfd,bfdefptr,&dsize,&mfdt,'O','Y',0,Mflag);
582 if (type < -990) /* 1st look for TCTINI/SCFCRE errors */
583 {
584 if (type == -998)
585 SCTMES(M_RED_COLOR,"problems creating image...");
586 else
587 SCTMES(M_RED_COLOR,"problems creating table...");
588 reset_ERRO(fid);
589 return (-9);
590 }
591 if (type == EOFITS)
592 { /* we reached EOF */
593 reset_ERRO(fid);
594 return (-7);
595 }
596
597 extcount ++; /* o.k. we passed one more extension */
598
599
600 /* save type of extensions */
601
602 *info = 0; /* = 0 is bad... */
603 if (type == ATABLE)
604 *info = 3;
605 else if (type == BTABLE)
606 *info = 2;
607 else if (type == IMAGE)
608 *info = 1;
609 else
610 {
611 if (dsize < 1) *info = 1; /* empty headers -> IMAGE */
612 }
613
614
615 /* hunt down the required extension */
616
617 if (extlabel[0] != '\0')
618 {
619 CGN_UPSTR(bfdefptr->extname);
620 if (strcmp(extlabel,bfdefptr->extname) == 0)
621 {
622 if (*mfd > -1)
623 {
624 if (*info > 1)
625 (void) TCTCLO(*mfd);
626 else
627 (void) SCFCLO(*mfd);
628 *mfd = -1;
629 }
630 *info = extcount; /* save this extension no. */
631 goto after_exttypes;
632 }
633 }
634
635 if (extcount != extno) /* always true for extno = 1000 */
636 goto extens_loop;
637
638 /* here the main header + extensions (also ext. 0) join */
639
640 after_exttypes:
641 ERRO_CONT = eco; /* reset again */
642 ERRO_LOG = elo;
643 ERRO_DISP = edi;
644
645 if (type == UKNOWN)
646 {
647 (void) snprintf(temp,(size_t) 400,
648 "Unknown FITS extension ( = %d)\n",extno);
649 SCTPUT(temp);
650
651 dclose(fid);
652 return (-8);
653 }
654
655
656 /* if we just want to know the file type or
657 the extension no. of given EXTNAME, we can return now */
658
659 if ((flag == 0) || (flag == -2))
660 {
661 TXDEF *tpntr;
662
663 if (bfdefptr->extd != (char *) 0)
664 {
665 tpntr = (TXDEF *) bfdefptr->extd;
666 free((char *)tpntr->col);
667 free(bfdefptr->extd);
668 }
669
670 free((char *)bfdefptr);
671 free((char *)adefptr);
672 free((char *)pdefptr);
673 dclose(fid);
674
675 if (*mfd > -1)
676 {
677 fctpntr = FCT.ENTRIES + (*mfd);
678 for (n=0; n<3; n++) fctpntr->FITSADDR[n] = (char *) 0;
679 }
680
681 return (0);
682 }
683
684
685 /* we really want the file - check, if we created the Midas frame */
686
687 if (bfdefptr->cflag == 0) /* extension header was bad... */
688 {
689 bfdefptr->cflag = 1; /* force create_flag and try again */
690 type = fitsrhd(mfd,bfdefptr,&dsize,&mfdt,'O','Y',0,Mflag);
691
692 if (type < -990) /* 1st look for TCTINI/SCFCRE errors */
693 {
694 if (type == -998)
695 SCTMES(M_RED_COLOR,"problems creating image...");
696 else
697 SCTMES(M_RED_COLOR,"problems creating table...");
698 dclose(fid);
699 return (-9);
700 }
701 if (bfdefptr->cflag != -9)
702 {
703 dclose(fid);
704 return (-11);
705 }
706 }
707
708 fctpntr = FCT.ENTRIES + (*mfd);
709
710 fctpntr->KAUX[2] = 0;
711 fctpntr->KAUX[3] = dsize;
712
713 fctpntr->FITSEXT = extno; /* save extension no. */
714 bfdefptr->count += extrecs; /* add skipped records */
715
716 fctpntr->FITSADDR[0] = (char *) bfdefptr;
717 fctpntr->FITSADDR[1] = (char *) adefptr;
718 fctpntr->FITSADDR[2] = (char *) pdefptr;
719
720 if (work[0] != '^') /* return the path name */
721 {
722 work[kpath] = '\0';
723 (void) strcpy(outbuf,work);
724 }
725 else
726 {
727 *outbuf = '^';
728 *(outbuf+1) = '\0';
729 }
730 dclose(fid);
731 }
732
733
734
735 /* if flag > 1 we have the FITS header already in memory */
736 /* ----------------------------------------------------- */
737
738 else
739 { /* file header already in */
740 Mflag = 1;
741 imno = *mfd;
742 fctpntr = FCT.ENTRIES + imno;
743 bfdefptr = (BFDEF *) fctpntr->FITSADDR[0];
744
745 if (flag == 2)
746 {
747 (void) fitsmove(bfdefptr); /* only position file pointer ... */
748
749 fctpntr->FITSOUT = 'X'; /* indicate that the data is in ... */
750 dataout_ptr = outbuf; /* now read the data */
751 dataout_outtyp = fctpntr->DATTYP;
752 dsize = fctpntr->KAUX[3];
753
754 if (fctpntr->FILTYP == 1) /* IMAGE */
755 {
756 if ((bfdefptr->bitpix == -16) || (bfdefptr->bitpix == 16))
757 fitsrdmUI2(imno,bfdefptr,dsize,mfdt,'O',Mflag);
758 else
759 fitsrdm(imno,bfdefptr,dsize,mfdt,'O',Mflag);
760 }
761 else
762 {
763 if (fctpntr->FILTYP == 2) /* BTABLE */
764 fitsrbt(imno,bfdefptr,dsize,Mflag);
765 else /* ATABLE */
766 fitsrat(imno,bfdefptr,dsize,Mflag);
767 fctpntr->KAUX[2] = 0; /* reset descr_changed_flag */
768 }
769
770 dclose(fid);
771 }
772
773 else
774 {
775 switch (bfdefptr->bitpix) /* check original data format */
776 {
777 case 8 : n = D_I1_FORMAT; break;
778 case -16 : n = D_UI2_FORMAT; break;
779 case 16 : n = D_I2_FORMAT; break;
780 case 32 : n = D_I4_FORMAT; break;
781 case -32 : n = D_R4_FORMAT; break;
782 case -64 : n = D_R8_FORMAT; break;
783 }
784 if (n != fctpntr->FORMAT) /* data format changed => cannot copy */
785 {
786 dclose(fid);
787 fid = -99;
788 }
789 else
790 (void) fitsmove(bfdefptr); /* only position file pointer ... */
791
792 *info = fid; /* return the file id of FITS file */
793 }
794 }
795
796 if (fctpntr->FILTYP > 1) n = TCSDSC(*mfd); /* no IMAGE */
797
798 return (0);
799 }
800
801 /*
802
803 */
804
805 #ifdef __STDC__
806 int fitsmove(BFDEF *bfdef)
807 #else
808 int fitsmove(bfdef)
809 BFDEF *bfdef;
810 #endif
811
812 {
813 char *pc;
814
815 register int nr;
816
817
818 for (nr=0; nr<bfdef->count; nr++) dread(&pc,FITSLR);
819
820 return 0;
821 }
822
823 /*
824
825 */
826
827 #ifdef __STDC__
828 int MyPut(int kdfmt, int kfelem, int kdn, char *inbuf)
829 #else
830 int MyPut(kdfmt,kfelem,kdn,inbuf)
831 int kdfmt, kfelem, kdn;
832 char *inbuf;
833 #endif
834
835 /*
836 kdfmt = 8 D_I1_FORMAT
837 kdfmt = 16 D_I2_FORMAT
838 kdfmt = -16 D_UI2_FORMAT
839 kdfmt = 32 D_I4_FORMAT
840 kdfmt = -32 D_R4_FORMAT
841 kdfmt = -64 D_R8_FORMAT
842 */
843
844 {
845 int nbyte, intype, kk;
846
847 char *opntr;
848
849
850
851 kk = kfelem - 1; /* start in output buffer */
852 nbyte = get_byte(dataout_outtyp); /* no. bytes of output data format */
853 opntr = dataout_ptr + (kk*nbyte);
854 if (kdfmt == 8)
855 intype = D_I1_FORMAT;
856 else if (kdfmt == 16)
857 intype = D_I2_FORMAT;
858 else if (kdfmt == -16)
859 intype = D_UI2_FORMAT;
860 else if (kdfmt == 32)
861 intype = D_I4_FORMAT;
862 else if (kdfmt == -32)
863 intype = D_R4_FORMAT;
864 else
865 intype = D_R8_FORMAT;
866
867
868 /* do the conversion or just copy data */
869
870 conv_pix(opntr,inbuf,dataout_outtyp,intype,kdn);
871
872 return 0;
873 }
874