"Fossies" - the Fresh Open Source Software Archive

Member "SAOImageDS9/funtools/doc/evmerge.c" (13 Nov 2019, 2248 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  * evmerge.c -- example program for merging user values into a table file
    4  *
    5  */
    6 #include <funtools.h>
    7 #include <word.h>
    8 
    9 #define MAXROW 8192
   10 
   11 typedef struct evstruct{
   12   double time;
   13   int time2;
   14 } *Ev, EvRec;
   15 
   16 int main (int argc, char **argv)
   17 {
   18   int i, got;
   19   char tbuf[SZ_LINE];
   20   Fun fun, fun2;
   21   Ev ebuf, ev;
   22 
   23   /* exit on gio errors */
   24   setgerror(2);
   25 
   26   /* make sure we have minimal arguments */
   27   if( argc < 4 )
   28     gerror(stderr, "usage: %s iname oname mergetype [columns]\n", argv[0]);
   29 
   30   /* open input file */
   31   if( !(fun = FunOpen(argv[1], "rc", NULL)) )
   32     gerror(stderr, "could not FunOpen input file: %s\n", argv[1]);
   33 
   34   /* open the output FITS image, inheriting params from input */
   35   if( !(fun2 = FunOpen(argv[2], "w", fun)) )
   36     gerror(stderr, "could not FunOpen output file: %s\n", argv[2]);
   37 
   38   /* "merge=[type]" merges original input columns with new ones, where type is:
   39    * update -- add new columns, update value of existing ones (same data type)
   40    * replace -- add new columns, replace data type and value of existing ones
   41    * append -- only add new columns, do not "replace" or "update" existing ones
   42    * If tbuf argument is NULL, no merging is performed -- only user-specified
   43    * columns are output.
   44    */
   45   if( isfalse(argv[3]) )
   46     *tbuf = '\0';
   47   else
   48     sprintf(tbuf, "merge=%s", argv[3]);
   49   FunColumnSelect(fun, sizeof(EvRec), tbuf,
   50           "time",      "D",     "rw",  FUN_OFFSET(Ev, time),
   51           "time2",     "J",     "w",   FUN_OFFSET(Ev, time2),
   52           NULL);
   53 
   54   /* activate specified columns -- these will be written to the output file */
   55   if( argc >= 5 )
   56     FunColumnActivate(fun, argv[4], NULL);
   57 
   58   /* get rows -- let routine allocate the row array */
   59   while( (ebuf = (Ev)FunTableRowGet(fun, NULL, MAXROW, NULL, &got)) ){
   60     /* process all rows */
   61     for(i=0; i<got; i++){
   62       /* point to the i'th row */
   63       ev = ebuf+i;
   64       ev->time2 = (int)(ev->time+.5);
   65       ev->time = -(ev->time/10.0);
   66     }
   67     /* write out this batch of rows with the new column */
   68     FunTableRowPut(fun2, (char *)ebuf, got, 0, NULL);
   69     /* free row data */
   70     if( ebuf ) free(ebuf);
   71   }
   72 
   73   /* clean up -- close output before input to perform flush automatically */
   74   FunClose(fun2);
   75   FunClose(fun);
   76   return(0);
   77 }