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

ModSim ass3: Code cleanup.

parent 52e5f14c
......@@ -5,6 +5,7 @@ FILE *logfile = NULL;
void logger_open(const char* filename) {
if( logfile )
logger_close();
logfile = fopen(filename, "w");
}
......@@ -13,8 +14,10 @@ void logger(double t, int N, double *y) {
logfile = stdout;
fprintf(logfile, "%e", t);
for( int i = 0; i < N; i++ )
fprintf(logfile, ",%e", y[i]);
fprintf(logfile, "\n");
}
......@@ -22,4 +25,3 @@ void logger_close() {
if( logfile && logfile != stdout && fclose(logfile) )
printf("Failed to close logfile. Error no: %d", errno);
}
......@@ -4,8 +4,6 @@
#include <stdio.h>
#include <errno.h>
//typedef void (*log_function)(double t, double *y);
void logger(double t, int N, double *y);
void logger_close();
......
......@@ -2,12 +2,7 @@
from sys import argv, stdin
from pylab import figure, clf, plot, show, savefig
#try:
# f = open(argv[1], 'r')
#except IndexError:
f = stdin
lines = f.readlines()
f.close()
# Collect data
x = []
y = [[] for i in range(lines[0].count(','))]
for i in range(len(lines)):
......@@ -18,6 +13,8 @@ for i in range(len(lines)):
y_values = parts[1].split(',')
for j in range(len(y_values)):
y[j].append(y_values[j])
# Plot and optionally save data
figure(1)
clf()
for i in range(len(y)):
......
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "methods.h"
#include "integration.h"
#include "logger.h"
#define DT .001
#define DT .01
extern FILE *logfile;
int f_test_1(double t, double *y, double *dy, void *params) {
*dy = 1.0;
......@@ -53,6 +56,8 @@ int f_test_4(double t, double *y, double *dy, void *params) {
int main(void) {
double y0[1] = {.0}, y1[1] = {.0};
logfile = fopen("/dev/null", "w");
COMPARE(.0, .0, 10.0, f_test_1);
puts("");
COMPARE(.0, .0, 10.0, f_test_2);
......
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