Commit d2902159 authored by Taddeüs Kroes's avatar Taddeüs Kroes

ModSim ass4 taddeus: made command line arguments more sensible.

parent 5a84959c
...@@ -2,12 +2,20 @@ ...@@ -2,12 +2,20 @@
from sys import stdin from sys import stdin
from pylab import figure, plot, axis, draw, ion, clf from pylab import figure, plot, axis, draw, ion, clf
from time import sleep from time import sleep
from sys import argv, exit
if len(argv) < 2:
print 'Usage: python %s TIME_STEP [ DELAY ]' % argv[0]
exit()
stride = int(argv[1])
delay = .1 if len(argv) < 3 else float(argv[2])
# Collect data # Collect data
y = [] y = []
lines = stdin.readlines() lines = stdin.readlines()
x = map(float, lines[0].split(' ')) x = map(float, lines[0].split(' '))
for line in lines[1:]: for line in lines[1::stride]:
y += [map(float, line.split(' '))] y += [map(float, line.split(' '))]
# Find axis maxima # Find axis maxima
...@@ -22,4 +30,4 @@ for i in range(len(y)): ...@@ -22,4 +30,4 @@ for i in range(len(y)):
plot(x, y[i], '-') plot(x, y[i], '-')
axis(ranges) axis(ranges)
draw() draw()
sleep(.01) sleep(delay)
...@@ -54,7 +54,7 @@ void print(int index) { ...@@ -54,7 +54,7 @@ void print(int index) {
/* /*
* *
*/ */
void calculate_steps(int calc_steps, int print_resolution, double tau) { void calculate_steps(int calc_steps, double tau) {
double x; double x;
int i, t, prev = 0, current = 1, next = 2; int i, t, prev = 0, current = 1, next = 2;
...@@ -79,9 +79,7 @@ void calculate_steps(int calc_steps, int print_resolution, double tau) { ...@@ -79,9 +79,7 @@ void calculate_steps(int calc_steps, int print_resolution, double tau) {
// Print init states // Print init states
print(prev); print(prev);
print(current);
if( print_resolution == 1 )
print(current);
#endif #endif
// Iterate over the length of the string for each time interval step // Iterate over the length of the string for each time interval step
...@@ -92,8 +90,7 @@ void calculate_steps(int calc_steps, int print_resolution, double tau) { ...@@ -92,8 +90,7 @@ void calculate_steps(int calc_steps, int print_resolution, double tau) {
} }
#ifdef VERBOSE #ifdef VERBOSE
if( !(t % print_resolution) ) print(next);
print(next);
#endif #endif
prev = current; prev = current;
...@@ -103,14 +100,14 @@ void calculate_steps(int calc_steps, int print_resolution, double tau) { ...@@ -103,14 +100,14 @@ void calculate_steps(int calc_steps, int print_resolution, double tau) {
} }
int main(int argc, const char **argv) { int main(int argc, const char **argv) {
int calc_steps, i, print_resolution; int calc_steps, i;
void (*init_method)(double, double); void (*init_method)(double, double);
double l, tau, constant; double l, tau, constant;
// Parse argument // Parse argument
if( argc < 8 ) { if( argc < 7 ) {
printf("Usage: %s INIT_METHOD CALCULATION_STEPS PRINT_RESOLUTION LENGTH" printf("Usage: %s INIT_METHOD CALCULATION_STEPS LENGTH DX TAU N|XP\n",
" DX TAU N|XP\n", argv[0]); argv[0]);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -124,11 +121,10 @@ int main(int argc, const char **argv) { ...@@ -124,11 +121,10 @@ int main(int argc, const char **argv) {
} }
calc_steps = atoi(argv[2]); calc_steps = atoi(argv[2]);
print_resolution = atoi(argv[3]); l = atof(argv[3]);
l = atof(argv[4]); dx = atof(argv[4]);
dx = atof(argv[5]); tau = atof(argv[5]);
tau = atof(argv[6]); constant = atof(argv[6]);
constant = atof(argv[7]);
// Allocate a 3xN two-dimensional area that functions as a cyclic buffer // Allocate a 3xN two-dimensional area that functions as a cyclic buffer
// for three states of the string (previous, current, next) // for three states of the string (previous, current, next)
...@@ -146,7 +142,7 @@ int main(int argc, const char **argv) { ...@@ -146,7 +142,7 @@ int main(int argc, const char **argv) {
(*init_method)(l, constant); (*init_method)(l, constant);
// Calculate the specified number of steps // Calculate the specified number of steps
calculate_steps(calc_steps, print_resolution, tau); calculate_steps(calc_steps, tau);
// Free allocated memory // Free allocated memory
for( i = 0; i < 3; i++ ) for( i = 0; i < 3; i++ )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment