"Fossies" - the Fresh Open Source Software Archive

Member "SAOImageDS9/funtools/doc/evcol.c" (13 Nov 2019, 3734 Bytes) of package /linux/misc/ds9.8.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  *
    3  * evcol.c -- example program for processing all extensions and adding a
    4  *            column to the binary tables
    5  *
    6  */
    7 #include <funtools.h>
    8 #include <word.h>
    9 
   10 #define MAXROW 8192
   11 
   12 typedef struct evstruct{
   13   char shape[17];
   14   int mycol;
   15 } *Ev, EvRec;
   16 
   17 int main (int argc, char **argv)
   18 {
   19   int i, got;
   20   int idx;
   21   int tlmax;
   22   int ext=1;
   23   int total=1;
   24   int haveshape=0;
   25   char *s[3];
   26   char tbuf[SZ_LINE];
   27   Fun fun, fun2;
   28   Ev ebuf, ev;
   29 
   30   /* exit on gio errors */
   31   setgerror(2);
   32 
   33   /* make sure we have minimal arguments */
   34   if( argc < 3 )
   35     gerror(stderr, "usage: %s iname oname\n", argv[0]);
   36 
   37   /* open a new output FITS file */
   38   if( !(fun2 = FunOpen(argv[2], "w", NULL)) )
   39     gerror(stderr, "could not FunOpen output file: %s\n", argv[2]);
   40 
   41   /* process each input extension in turn */
   42   for(ext=0; ;ext++){
   43     /* get new extension name */
   44     sprintf(tbuf, "%s[%d]", argv[1], ext);
   45     /* open it -- if we cannot open it, we are done */
   46     if( !(fun=FunOpen(tbuf, "r", NULL)) )
   47       break;
   48 
   49     /* make the new extension the reference handle for the output file */
   50     FunInfoPut(fun2, FUN_IFUN, &fun, 0);
   51 
   52     /* if its not a binary table, just write it out */
   53     for(i=0; i<=2; i++) s[i] = NULL;
   54     if( !(s[0]=FunParamGets(fun, "XTENSION", 0, NULL, &got)) || 
   55     strcmp(s[0], "BINTABLE")){
   56       if( s[0] ) free(s[0]);
   57       FunFlush(fun2, "copy=reference");
   58       FunClose(fun);
   59       continue;
   60     }
   61     else{
   62       if( (s[1]=FunParamGets(fun, "EXTNAME", 0, NULL, &got)) ){
   63     fprintf(stdout, "processing %s", s[1]);
   64     if( (s[2]=FunParamGets(fun, "HDUNAME", 0, NULL, &got)) )
   65       fprintf(stdout, " %s", s[2]);
   66     fprintf(stdout, "\n");
   67       }
   68     }
   69     for(i=0; i<=2; i++) if( s[i] ) free(s[i]);
   70 
   71     /* select columns from this new extension for merging */
   72     /* we have some special code to test various bugs with bpix.fits */
   73     if( (idx = FunColumnLookup(fun, "SHAPE", 0,
   74                    NULL, NULL, NULL, NULL, NULL, NULL)) ){
   75       haveshape = 1;
   76       FunColumnSelect(fun, sizeof(EvRec), "merge=update",
   77               "SHAPE",     "16A",   "rw",  FUN_OFFSET(Ev, shape),
   78               "MYCOL",     "J",     "w",   FUN_OFFSET(Ev, mycol),
   79               NULL);
   80     }
   81     else{
   82       FunColumnSelect(fun, sizeof(EvRec), "merge=update",
   83               "MYCOL",     "J",     "w",   FUN_OFFSET(Ev, mycol),
   84               NULL);
   85     }
   86 
   87     /* we have some special code to test various bugs with bpix.fits */
   88     /* we need to increase tlmax value of the "component" column */
   89     if( (idx = FunColumnLookup(fun, "COMPONENT", 0,
   90                    NULL, NULL, NULL, NULL, NULL, NULL)) ){
   91       if( (tlmax=FunParamGeti(fun, "TLMAX", idx, -1, &got)) && got )
   92     FunParamPuti(fun2, "TLMAX", idx, tlmax+100, NULL, 0);
   93     }
   94 
   95     /* get input rows (let routine allocate the row array) */
   96     while( (ebuf = (Ev)FunTableRowGet(fun, NULL, MAXROW, NULL, &got)) ){
   97       /* process all rows */
   98       for(i=0; i<got; i++){
   99     /* point to the i'th row */
  100     ev = ebuf+i;
  101     /* make sure ascii vector is null-terminated */
  102     ev->shape[17] = '\0';
  103     /* used with bpix.ev */
  104     if( haveshape ){
  105       cluc(ev->shape);
  106       fprintf(stdout, "\tshape: %s\n", ev->shape);
  107     }
  108     ev->mycol = total++;
  109       }
  110       /* write out this batch of rows, along with the new column */
  111       FunTableRowPut(fun2, (char *)ebuf, got, 0, NULL);
  112       /* write out one more record with special marker */
  113       ev = ebuf;
  114       strcpy(ev->shape, "hexagon         ");
  115       ev->mycol = -1;
  116       FunTableRowPut(fun2, (char *)ev, 1, 0, NULL);
  117       /* free row data */
  118       if( ebuf ) free(ebuf);
  119     }
  120 
  121     /* flush output extension (write padding, etc.) */
  122     FunFlush(fun2, NULL);
  123     /* close the input extension */
  124     FunClose(fun);
  125   }
  126 
  127   /* all done -- close output */
  128   FunClose(fun2);
  129   return(0);
  130 }