forked from namelessjon/tip_trace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore_trace.c
181 lines (151 loc) · 5.22 KB
/
core_trace.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* core_trace.c
* Jonathan D. Stott <[email protected]>
*
*/
#include <stdio.h>
#include <getopt.h>
#include <string.h>
#include "tip_trace_binary.h"
#include "utils/string_list.h"
#include "helper.h"
static void print_help_text(char * progname);
// help text output
int main (int argc, char ** argv) {
int c, file_set = 0;
// dimensions of the sheet.
int nx, ny;
// timestep
float dt;
// isoline level
float isoline;
// output file
FILE *output;
// inpit file
FILE *input;
string_list_t *filenames;
char filename[64];
// filetype
file_type_t type;
// set some defaults
nx = 375;
ny = 375;
isoline = -30;
output = stdout;
type = BINARY_FLOAT;
dt = 1;
filenames = new_string_list();
while (1)
{
static struct option long_options[] =
{
/* These options don't set a flag.
We distinguish them by their indices. */
{"x-dim", required_argument, 0, 'x'},
{"y-dim", required_argument, 0, 'y'},
{"timestep", required_argument, 0, 't'},
{"file", required_argument, 0, 'f'},
{"isoline", required_argument, 0, 'i'},
{"output", required_argument, 0, 'o'},
{"type", required_argument, 0, 'T'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
/* getopt_long stores the option index here. */
int option_index = 0;
c = getopt_long (argc, argv, "x:y:t:f:i:o:T:h",
long_options, &option_index);
/* Detect the end of the options. */
if (c == -1)
break;
switch (c)
{
case 'x':
nx = atoi(optarg);
break;
case 'y':
ny = atoi(optarg);
break;
case 't':
dt = atof(optarg);
break;
case 'i':
isoline = atof(optarg);
break;
case 'o':
open(output, "w", optarg);
break;
case 'T':
if (0==strcmp("float", optarg)) {
type = BINARY_FLOAT;
break;
}
if (0==strcmp("double", optarg)) {
type = BINARY_DOUBLE;
break;
}
if (0==strcmp("text", optarg)) {
type = TEXT;
break;
}
fprintf(stderr, "Unrecognised type. Try float or double or text\n");
exit(EXIT_FAILURE);
case 'f':
if ((optarg[0] == '-') && (optarg[1] == 0)) {
input = stdin;
break;
}
open(input, "r", optarg);
file_set = 1;
break;
case 'h':
print_help_text(argv[0]);
case '?':
print_help_text(argv[0]);
/* getopt_long already printed an error message. */
break;
default:
abort ();
}
}
// if we didn't set a file, use the spare args from the commandline
if (0 == file_set) {
while (optind < argc) {
string_list_push(filenames, argv[optind++]);
}
} else {
// read the file
while(EOF != fscanf(input, "%s", filename)) {
string_list_push(filenames, filename);
}
}
if (string_list_length(filenames) < 1) {
fprintf(stderr, "No filenames found!\n");
print_help_text(argv[0]);
exit(EXIT_FAILURE);
}
// scan in all the filelist!
process_file_list(nx, ny, dt, isoline, filenames, type, output);
return 0;
} /* end of main() */
void print_help_text(char * progname) {
fprintf(stderr, "Usage: %s [OPTIONS] [FILE, FILE, ...]\n", progname);
fprintf(stderr, "Calculates the spiral tip trajectories in files...\n\n");
fprintf(stderr, " -x NX, --x-dim NX\n");
fprintf(stderr, " The x dimension of the sheet (defaults to 375)\n");
fprintf(stderr, " -y NY, --y-dim NY\n");
fprintf(stderr, " The y dimension of the sheet (defaults to 375)\n");
fprintf(stderr, " -t DT, --timestep DT\n");
fprintf(stderr, " The timestep between successive frames of the sheet (defaults to 1)\n");
fprintf(stderr, " -i LEVEL, --isoline LEVEL\n");
fprintf(stderr, " The isoline to track the tips alone (defaults to -30 mV)\n");
fprintf(stderr, " -o FILE, --output FILE\n");
fprintf(stderr, " File to divert output to. stdout otherwise.\n");
fprintf(stderr, " -f FILE, --file FILE\n");
fprintf(stderr, " File to read framelist from. - for stdin. argv otherwise\n");
fprintf(stderr, " -T TYPE, --type TYPE\n");
fprintf(stderr, " Type of input files. One of float (binary floats), double (binary doubles) or text (whitespace delimited text). Defaults to float.\n");
fprintf(stderr, " -h, --help\n");
fprintf(stderr, " This help\n");
exit(EXIT_FAILURE);
}