diff options
author | Jaron Kent-Dobias <jkentdobias@g.hmc.edu> | 2016-08-22 10:11:14 -0400 |
---|---|---|
committer | Jaron Kent-Dobias <jkentdobias@g.hmc.edu> | 2016-08-22 10:11:14 -0400 |
commit | 2bb0740b68fdb62d45adc00204b3990ca42ade77 (patch) | |
tree | a52975e3460da781467ddb70aaa8d76840d01bb4 /src/get_file.c | |
download | fuse_networks-2bb0740b68fdb62d45adc00204b3990ca42ade77.tar.gz fuse_networks-2bb0740b68fdb62d45adc00204b3990ca42ade77.tar.bz2 fuse_networks-2bb0740b68fdb62d45adc00204b3990ca42ade77.zip |
started repo again without all the data files gunking the works
Diffstat (limited to 'src/get_file.c')
-rw-r--r-- | src/get_file.c | 38 |
1 files changed, 38 insertions, 0 deletions
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; +} |