43 while ((c = fgetc(fin)) !=
'\n') {
48 if (s >= buf+buf_size-1) {
77 while (!isspace(*s)) {
91 int main(
int argn,
const char*
const argv[])
116 if (argn == 1 || argn > 3) {
117 fprintf(stderr,
"usage: %s <file> <dt>\n", argv[0]);
119 }
else if (argn == 2) {
123 if (!strcmp(argv[1],
"-")) {
126 fin = fopen(argv[1],
"r");
128 fprintf(stderr,
"%s: file <%s> doesn't exist\n", argv[0], argv[1]);
137 fprintf(stderr,
"%s: illegal dt = %f\n", argv[0], dt);
143 fprintf(stderr,
"%s: line 1 is longer that %d in file <%s>\n",
150 fprintf(stderr,
"%s: unable to read first label in file <%s>\n",
156 while ((s =
get_word(next, &next))) {
163 fprintf(stderr,
"%s: line %d is longer that %d in file <%s>\n",
164 argv[0], nrows+1,
BUFSIZE, argv[1]);
168 if (sscanf(buf,
"%d", &icurr) < 1) {
169 fprintf(stderr,
"%s: unable to read label %d in file <%s>\n",
170 argv[0], nrows+1, argv[1]);
173 if (icurr == ifirst) {
179 pd = (
double*)malloc(
sizeof(
double)*(ncols*nrows*3));
180 pdv = (
double**)malloc(
sizeof(
double*)*(nrows*3));
181 pi = (
int*)malloc(
sizeof(
int)*nrows);
183 if (pd == NULL || pdv == NULL) {
184 fprintf(stderr,
"%s: out of memory?\n", argv[0]);
188 for (i = 3*nrows; i-- > 0; ) {
196 for (i = 0; i < nrows; i++) {
201 for (j = 0; j < ncols; j++) {
203 pdv[i1*nrows+i][j] = atof(s);
207 for (i = 0; i < nrows; i++) {
211 printf(
"%8d", pi[i]);
212 for (j = 0; j < ncols; j++) {
214 pdv[i2*nrows+i][j] = atof(s);
215 printf(
"%16.8e", (pdv[i2*nrows+i][j]-pdv[i1*nrows+i][j])/dt);
221 for (i = 0; i < nrows; i++) {
227 printf(
"%8d", pi[i]);
228 for (j = 0; j < ncols; j++) {
230 pdv[i3*nrows+i][j] = atof(s);
231 printf(
"%16.8e", (pdv[i3*nrows+i][j]-pdv[i1*nrows+i][j])/dt2);
242 for (i = 0; i < nrows; i++) {
243 printf(
"%8d", pi[i]);
244 for (j = 0; j < ncols; j++) {
245 printf(
"%16.8e", (pdv[i2*nrows+i][j]-pdv[i1*nrows+i][j])/dt);
char * get_word(char *buf, char **next)
int get_line(FILE *fin, char *buf, int buf_size)
static std::stack< cleanup * > c
static doublereal buf[BUFSIZE]
int main(int argn, const char *const argv[])