#include /* if defined, user allocated row buffer, otherwise let funtools do it */ /* #define USER_ALLOC 1 */ #define MAXROW 100000 typedef struct evstruct{ double x, y; int *phas; } *Ev, EvRec; void Reverse(double x, double y, int *phas, double *nx, double *ny, int *nphas, int npha) { int i; *nx = y; *ny = x; for(i=0; iphas = (int *)calloc(npha, sizeof(int)); /* create format statement for the pha vector, @ means its a pointer */ sprintf(tbuf, "@%dJ", npha); /* specify input columns we want brought into user space */ FunColumnSelect(fun, sizeof(EvRec), "merge=replace", "$x", "D", "rw", FUN_OFFSET(Ev, x), "$y", "D", "rw", FUN_OFFSET(Ev, y), "phas", tbuf, "rw", FUN_OFFSET(Ev, phas), NULL); /* set columns to be written to the output file */ if( argc >= 4 ) FunColumnActivate(fun, argv[3], NULL); /* loop through rows and replicate */ while( (ebuf=(Ev)FunTableRowGet(fun, NULL, MAXROW, NULL, &got)) ){ for(i=0; ix, ev->y, ev->phas, &(nev->x), &(nev->y), nev->phas, npha); /* write this new row -- with the replacements from user space */ FunTableRowPut(fun2, nev, 1, i, NULL); } if( ebuf ) free(ebuf); } /* free the new row */ if( nev ){ if( nev->phas ) free(nev->phas); free(nev); } /* close output before input so that funtools will copy the rest of the input extensions to the output (if such copy is requred) */ FunClose(fun2); FunClose(fun); return(0); }