From 2bb0740b68fdb62d45adc00204b3990ca42ade77 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Mon, 22 Aug 2016 10:11:14 -0400 Subject: started repo again without all the data files gunking the works --- src/get_file.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/get_file.c (limited to 'src/get_file.c') diff --git a/src/get_file.c b/src/get_file.c new file mode 100644 index 0000000..9141631 --- /dev/null +++ b/src/get_file.c @@ -0,0 +1,38 @@ + +#include "fracture.h" + +FILE *get_file(const char *prefix, unsigned int width, unsigned int crack, + double beta, unsigned int iter, unsigned int num_iter, + unsigned int num, bool read) { + int prefix_len = strlen(prefix); + int width_len = 1 + (int)log10(width); + int crack_len; + if (crack != 0) { + crack_len = 1 + (int)log10(crack); + } else { + crack_len = 1; + } + int beta_len; + if (beta > 1) { + beta_len = 1 + (int)log10(beta) + 3; + } else { + beta_len = 4; + } + int iter_len = 1 + (int)log10(num_iter); + int num_len = 1 + (int)log10(num); + int num_underscores = 5; + + int len = prefix_len + width_len + crack_len + beta_len + iter_len + num_len + + num_underscores + 4; + + char filename[len + 1]; + snprintf(filename, sizeof(filename), "%s_%u_%u_%.2f_%0*u_%u.txt", prefix, + width, crack, beta, iter_len, iter + 1, num); + + char *mode = "w"; + if (read) { + mode = "r"; + } + FILE *file = fopen(filename, mode); + return file; +} -- cgit v1.2.3-70-g09d2