1
#include "atlas_tvec.h"
3
void PrintUsage(char *name, char *arg, int i)
6
"This routine takes two vector files, and combines a list of named vectors\n");
8
"so they form one contiguous range. The range vector is specified by -r,\n");
9
fprintf(stderr, "and these vectors should not overlap.\n\n");
11
fprintf(stderr, "BAD ARG '%s' ON %dth FLAG\n", arg, i);
12
fprintf(stderr, "USAGE: %s <flags> ; flags include:\n", name);
13
fprintf(stderr, " -i1 <file> : (stdin) 1st file wt vecs to combine\n");
14
fprintf(stderr, " -i2 <file> : (stdin) 2nd file wt vecs to combine\n");
15
fprintf(stderr, " -o <file> : (stdout) file for combined vecs\n");
17
" -r <name> : (\"N\"): range vector to sort combine on\n");
18
fprintf(stderr, " -C # <nam1> ... <nam#>: vectors to combine\n");
22
char **GetFlags /* RETURNS: array of names to combine */
26
FILE **fp1, /* 1st input stream */
27
FILE **fp2, /* 2nd input stream */
28
FILE **fpout, /* output stream */
29
char **rngv, /* name of range/sort vector */
30
int *Nc /* # of vectors to combine using rngv */
41
for (i=1; i < nargs; i++)
43
if (args[i][0] != '-')
44
PrintUsage(args[0], "no '-' preceeding flag!", i);
47
case 'i': /* -i[1,2] <file> */
49
PrintUsage(args[0], "out of flags in -i ", i-1);
50
fp = fopen(args[i], "r");
52
if (args[i-1][2] == '1')
57
case 'o': /* -o <file> */
59
PrintUsage(args[0], "out of flags in -i ", i-1);
60
fp = fopen(args[i], "w");
64
case 'r': /* -r <name> */
66
PrintUsage(args[0], "out of flags in -i ", i-1);
69
case 'C': /* -C # <nam1> ... <nam#> */
71
PrintUsage(args[0], "out of flags in -C ", i-1);
72
*Nc = n = atoi(args[i]);
73
assert(n > 0 && n < 2048);
74
na = malloc(sizeof(char*)*n);
79
PrintUsage(args[0], "out of flags in -C ", i-1);
84
PrintUsage(args[0], args[i], i);
85
} /* end switch over flags */
86
} /* end for over flags */
90
na = malloc(sizeof(char*));
94
// assert(*fp1 != *fp2);
98
int main(int nargs, char **args)
100
FILE *fp1, *fp2, *fpout;
101
char *rngv, **combarr, *cmnt;
102
int N, Nc, i, j, RNGINC=0, nrep;
103
ATL_tvec_t *t1, *t2, *tp, *p1, *p2, *r1, *r2, *cb, *cp;
105
combarr = GetFlags(nargs, args, &fp1, &fp2, &fpout, &rngv, &Nc);
107
* Grab only the vectors to be combined, in order user has specified from
108
* both lists, and free all unused vectors
110
t1 = ATL_ReadTvecFile(fp1, &cmnt, &N, &nrep);
113
tp = ATL_PullNamedVecsFromList(Nc, combarr, &t1);
115
ATL_KillAllTvecs(t1);
118
t2 = ATL_ReadTvecFile(fp2, &cmnt, &i, &j);
121
tp = ATL_PullNamedVecsFromList(Nc, combarr, &t2);
123
ATL_KillAllTvecs(t2);
128
r1 = ATL_FindTvecByName(t1, rngv);
129
r2 = ATL_FindTvecByName(t2, rngv);
130
assert(r1->pre == 'i' && r2->pre == 'i'); /* restriction to fix later */
132
* Combine all vectors and build new list cb
134
for (cb=NULL, p1=t1, p2=t2; p1 && p2; p1 = p1->next, p2 = p2->next)
138
assert(!strcmp(p1->name, p2->name));
139
assert(p1->nrep == p2->nrep);
140
p = ATL_CombineTheseVecsUsingInts(r1, r2, p1, p2);
147
ATL_KillAllTvecs(t1);
148
ATL_KillAllTvecs(t2);
149
ATL_WriteTvecFile(fpout, cmnt, Nc, nrep, cb);
150
ATL_KillAllTvecs(cb);
153
printf("rngv = '%s'\n", rngv);
154
for (i=0; i < Nc; i++)
155
printf("nam[%d] = '%s'\n", i, combarr[i]);
157
if (fpout != stdout && fpout != stderr)