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 @@
from sys import stdin
from pylab import figure, plot, axis, draw, ion, clf
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
y = []
lines = stdin.readlines()
x = map(float, lines[0].split(' '))
for line in lines[1:]:
for line in lines[1::stride]:
y += [map(float, line.split(' '))]
# Find axis maxima
......@@ -22,4 +30,4 @@ for i in range(len(y)):
plot(x, y[i], '-')
axis(ranges)
draw()
sleep(.01)
sleep(delay)
......@@ -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;
int i, t, prev = 0, current = 1, next = 2;
......@@ -79,9 +79,7 @@ void calculate_steps(int calc_steps, int print_resolution, double tau) {
// Print init states
print(prev);
if( print_resolution == 1 )
print(current);
print(current);
#endif
// 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) {
}
#ifdef VERBOSE
if( !(t % print_resolution) )
print(next);
print(next);
#endif
prev = current;
......@@ -103,14 +100,14 @@ void calculate_steps(int calc_steps, int print_resolution, double tau) {
}
int main(int argc, const char **argv) {
int calc_steps, i, print_resolution;
int calc_steps, i;
void (*init_method)(double, double);
double l, tau, constant;
// Parse argument
if( argc < 8 ) {
printf("Usage: %s INIT_METHOD CALCULATION_STEPS PRINT_RESOLUTION LENGTH"
" DX TAU N|XP\n", argv[0]);
if( argc < 7 ) {
printf("Usage: %s INIT_METHOD CALCULATION_STEPS LENGTH DX TAU N|XP\n",
argv[0]);
return EXIT_FAILURE;
}
......@@ -124,11 +121,10 @@ int main(int argc, const char **argv) {
}
calc_steps = atoi(argv[2]);
print_resolution = atoi(argv[3]);
l = atof(argv[4]);
dx = atof(argv[5]);
tau = atof(argv[6]);
constant = atof(argv[7]);
l = atof(argv[3]);
dx = atof(argv[4]);
tau = atof(argv[5]);
constant = atof(argv[6]);
// Allocate a 3xN two-dimensional area that functions as a cyclic buffer
// for three states of the string (previous, current, next)
......@@ -146,7 +142,7 @@ int main(int argc, const char **argv) {
(*init_method)(l, constant);
// Calculate the specified number of steps
calculate_steps(calc_steps, print_resolution, tau);
calculate_steps(calc_steps, tau);
// Free allocated memory
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