diff options
author | William Joye <wjoye@cfa.harvard.edu> | 2016-10-27 17:38:41 (GMT) |
---|---|---|
committer | William Joye <wjoye@cfa.harvard.edu> | 2016-10-27 17:38:41 (GMT) |
commit | 5b44fb0d6530c4ff66a446afb69933aa8ffd014f (patch) | |
tree | e059f66d1f612e21fe9d83f9620c8715530353ec /funtools/funtest/evmerge.c | |
parent | da2e3d212171bbe64c1af39114fd067308656990 (diff) | |
parent | 23c7930d27fe11c4655e1291a07a821dbbaba78d (diff) | |
download | blt-5b44fb0d6530c4ff66a446afb69933aa8ffd014f.zip blt-5b44fb0d6530c4ff66a446afb69933aa8ffd014f.tar.gz blt-5b44fb0d6530c4ff66a446afb69933aa8ffd014f.tar.bz2 |
Merge commit '23c7930d27fe11c4655e1291a07a821dbbaba78d' as 'funtools'
Diffstat (limited to 'funtools/funtest/evmerge.c')
-rw-r--r-- | funtools/funtest/evmerge.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/funtools/funtest/evmerge.c b/funtools/funtest/evmerge.c new file mode 100644 index 0000000..6b7cebc --- /dev/null +++ b/funtools/funtest/evmerge.c @@ -0,0 +1,77 @@ +/* + * + * evmerge.c -- example program for merging user values into a table file + * + */ +#include <funtools.h> +#include <word.h> + +#define MAXROW 8192 + +typedef struct evstruct{ + double time; + int time2; +} *Ev, EvRec; + +int main (int argc, char **argv) +{ + int i, got; + char tbuf[SZ_LINE]; + Fun fun, fun2; + Ev ebuf, ev; + + /* exit on gio errors */ + setgerror(2); + + /* make sure we have minimal arguments */ + if( argc < 4 ) + gerror(stderr, "usage: %s iname oname mergetype [columns]\n", argv[0]); + + /* open input file */ + if( !(fun = FunOpen(argv[1], "rc", NULL)) ) + gerror(stderr, "could not FunOpen input file: %s\n", argv[1]); + + /* open the output FITS image, inheriting params from input */ + if( !(fun2 = FunOpen(argv[2], "w", fun)) ) + gerror(stderr, "could not FunOpen output file: %s\n", argv[2]); + + /* "merge=[type]" merges original input columns with new ones, where type is: + * update -- add new columns, update value of existing ones (same data type) + * replace -- add new columns, replace data type and value of existing ones + * append -- only add new columns, do not "replace" or "update" existing ones + * If tbuf argument is NULL, no merging is performed -- only user-specified + * columns are output. + */ + if( isfalse(argv[3]) ) + *tbuf = '\0'; + else + sprintf(tbuf, "merge=%s", argv[3]); + FunColumnSelect(fun, sizeof(EvRec), tbuf, + "time", "D", "rw", FUN_OFFSET(Ev, time), + "time2", "J", "w", FUN_OFFSET(Ev, time2), + NULL); + + /* activate specified columns -- these will be written to the output file */ + if( argc >= 5 ) + FunColumnActivate(fun, argv[4], NULL); + + /* get rows -- let routine allocate the row array */ + while( (ebuf = (Ev)FunTableRowGet(fun, NULL, MAXROW, NULL, &got)) ){ + /* process all rows */ + for(i=0; i<got; i++){ + /* point to the i'th row */ + ev = ebuf+i; + ev->time2 = (int)(ev->time+.5); + ev->time = -(ev->time/10.0); + } + /* write out this batch of rows with the new column */ + FunTableRowPut(fun2, (char *)ebuf, got, 0, NULL); + /* free row data */ + if( ebuf ) free(ebuf); + } + + /* clean up -- close output before input to perform flush automatically */ + FunClose(fun2); + FunClose(fun); + return(0); +} |