1
#include "atlas_tvec.h"
3
void PrintUsage(char *name, char *arg, int i)
5
fprintf(stderr, "This routine gets rid of the repititions within vectors\n");
6
fprintf(stderr, "Vectors are *reduced* or *combined*:\n");
7
fprintf(stderr, " reduced vectors should be repeats (eg 100, 100)\n");
9
" combined vectors are combined and produce several vectors:\n");
10
fprintf(stderr, " v_1...v_<nreps>, v_avg, v_min, v_max\n");
12
" any vector not collapsed or combined does not appear in the output\n");
14
fprintf(stderr, "BAD ARG '%s' ON %dth FLAG\n", arg, i);
15
fprintf(stderr, "USAGE: %s <flags> ; flags include:\n", name);
16
fprintf(stderr, " -i <file> : (stdin) file with vecs to reduce\n");
17
fprintf(stderr, " -o <file> : (stdout) file for reduced vecs\n");
18
fprintf(stderr, " -R # <nam1> ... <nam#>: vectors to collapse\n");
19
fprintf(stderr, " -C # <nam1> ... <nam#>: vectors to combine\n");
20
fprintf(stderr, " -c [+,<,>,a] : specify how to combine repeated elts:\n");
21
fprintf(stderr, " +: repeated vector replaced by average of repeats\n");
22
fprintf(stderr, " <: repeated vector replaced by minimum of repeats\n");
23
fprintf(stderr, " >: repeated vector replaced by maximum of repeats\n");
27
char **GetFlags /* RETURNS: array of names to combine/reduce */
31
int *ncomb, /* # of vecs to combine, stored in 1st ncomb elts */
32
int *nred, /* # of vecs to reduce, stored at end of ret array */
33
FILE **fpin, /* input stream */
34
FILE **fpout /* output stream */
37
char **vc=NULL, **vr=NULL, **vv, *sp;
38
int i, j, n, nc=0, nr=0;
43
for (i=1; i < nargs; i++)
45
if (args[i][0] != '-')
46
PrintUsage(args[0], "no '-' preceeding flag!", i);
49
case 'i': /* -i <file> */
51
PrintUsage(args[0], "out of flags in -i ", i-1);
52
*fpin = fopen(args[i], "r");
55
case 'o': /* -o <file> */
57
PrintUsage(args[0], "out of flags in -i ", i-1);
58
fp = fopen(args[i], "w");
62
case 'R': /* -R # <nam1> ... <nam#> */
64
PrintUsage(args[0], "out of flags in -R ", i-1);
66
assert(nr > 0 && nr < 2048);
67
vr = malloc(sizeof(char*)*nr);
69
for (j=0; j < nr; j++)
72
PrintUsage(args[0], "out of flags in -R ", i-1);
76
case 'C': /* -C # <nam1> ... <nam#> */
78
PrintUsage(args[0], "out of flags in -C ", i-1);
80
assert(nc > 0 && nc < 2048);
81
vc = malloc(sizeof(char*)*nc);
83
for (j=0; j < nc; j++)
86
PrintUsage(args[0], "out of flags in -C ", i-1);
91
PrintUsage(args[0], args[i], i);
92
} /* end switch over flags */
93
} /* end for over flags */
97
vv = malloc(2*sizeof(char*));
105
vv = malloc(n*sizeof(char*));
107
for (i=0; i < nc; i++)
123
int main(int nargs, char **args)
126
char **redarr, **combarr, *cmnt;
127
int N, Nc, Nr, i, j, RNGINC=0, nrep;
128
ATL_tvec_t *tr, *tc, *tp, *np, *nb=NULL;
130
combarr = GetFlags(nargs, args, &Nc, &Nr, &fpin, &fpout);
131
redarr = combarr + Nc;
134
* Grab only the vectors to be combined and reduced (in the order the user
135
* has specified) from list, and free all unused vectors
138
np = ATL_ReadTvecFile(fpin, &cmnt, &N, &nrep);
141
tc = ATL_PullNamedVecsFromList(Nc, combarr, &np);
142
tr = ATL_PullNamedVecsFromList(Nr, redarr, &np);
144
ATL_KillAllTvecs(np);
146
* Create all individual run vectors, add to new list
148
for (tp=tc; tp; tp = tp->next)
151
p = ATL_SplitRepsVector(tp);
152
ATL_FindLastVecInList(p)->next = nb;
156
* Create all statistic vectors in queue
158
for (tp=tc; tp; tp = tp->next)
161
assert(tp->pre == 'd'); /* relax this later if needed */
162
p = ATL_GetStatVecsDOUBLE(tp);
163
p->next->next->next = nb;
166
ATL_KillAllTvecs(tc);
168
* Now reduce any repeated vectors
170
for (tp=tr; tp; tp = tp->next)
176
p = ATL_GetRep1Vector(tp, 0);
180
for (sp=p->name,i=0; sp[i] != '_'; i++); /* fix name back to orig */
181
sp[i] = '\0'; /* from name_0 */
183
ATL_KillAllTvecs(tr);
185
ATL_WriteTvecFile(fpout, cmnt, ATL_CountTVecsInList(nb), 1, nb);
186
ATL_KillAllTvecs(nb);
188
if (fpout != stdout && fpout != stderr)