summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jkentdobias@g.hmc.edu>2016-08-30 13:23:52 -0400
committerJaron Kent-Dobias <jkentdobias@g.hmc.edu>2016-08-30 13:23:52 -0400
commit68c9e7c4937d391cad533a4e417bd11bfdb1e8b7 (patch)
treed7dc8d9d025355faca066ee8c3f75f82f6e61851
parenta5e505fc1a8f7ae060f8f2604a8d5b6132851d34 (diff)
downloadfuse_networks-68c9e7c4937d391cad533a4e417bd11bfdb1e8b7.tar.gz
fuse_networks-68c9e7c4937d391cad533a4e417bd11bfdb1e8b7.tar.bz2
fuse_networks-68c9e7c4937d391cad533a4e417bd11bfdb1e8b7.zip
added support for saving binary files instead of plaintext
-rw-r--r--src/homo_voronoi_fracture.c103
1 files changed, 51 insertions, 52 deletions
diff --git a/src/homo_voronoi_fracture.c b/src/homo_voronoi_fracture.c
index 1d9d0e6..4ba0244 100644
--- a/src/homo_voronoi_fracture.c
+++ b/src/homo_voronoi_fracture.c
@@ -118,31 +118,29 @@ int main(int argc, char *argv[]) {
unsigned int *cluster_size_dist;
unsigned int *avalanche_size_dist;
char *c_filename;
+ char *a_filename;
if (save_cluster_dist) {
cluster_size_dist =
- (unsigned int *)calloc(c_dist_size, sizeof(unsigned int));
+ (unsigned int *)malloc(c_dist_size * sizeof(unsigned int));
avalanche_size_dist =
- (unsigned int *)calloc(a_dist_size, sizeof(unsigned int));
+ (unsigned int *)malloc(a_dist_size * sizeof(unsigned int));
c_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(c_filename, filename_len, "cstr_v_%c_%c_%d_%g.txt", boundc, boundc2, L, beta);
+ a_filename = (char *)malloc(filename_len * sizeof(char));
+ snprintf(c_filename, filename_len, "cstr_v_%c_%c_%d_%g.dat", boundc, boundc2, L, beta);
+ snprintf(a_filename, filename_len, "avln_v_%c_%c_%d_%g.dat", boundc, boundc2, L, beta);
- FILE *cluster_out = fopen(c_filename, "r");
+ FILE *cluster_out = fopen(c_filename, "rb");
+ FILE *avalanche_out = fopen(a_filename, "rb");
if (cluster_out != NULL) {
- for (unsigned int i = 0; i < c_dist_size; i++) {
- unsigned int tmp;
- fscanf(cluster_out, "%u ", &tmp);
- cluster_size_dist[i] = tmp;
- }
- fscanf(cluster_out, "\n");
- for (unsigned int i = 0; i < a_dist_size; i++) {
- unsigned int tmp;
- fscanf(cluster_out, "%u ", &tmp);
- avalanche_size_dist[i] = tmp;
- }
+ fread(cluster_size_dist, sizeof(unsigned int), c_dist_size, cluster_out);
fclose(cluster_out);
}
+ if (avalanche_out != NULL) {
+ fread(avalanche_size_dist, sizeof(unsigned int), a_dist_size, avalanche_out);
+ fclose(avalanche_out);
+ }
}
double *crit_stress;
@@ -161,9 +159,22 @@ int main(int argc, char *argv[]) {
conductivity = (double *)malloc(N * sizeof(double));
}
- double *damage;
+ // define arrays for saving damage distributions
+ unsigned int *damage;
+ char *d_filename;
if (save_damage) {
- damage = (double *)malloc(N * sizeof(double));
+ damage =
+ (unsigned int *)malloc(a_dist_size * sizeof(unsigned int));
+
+ d_filename = (char *)malloc(filename_len * sizeof(char));
+ snprintf(d_filename, filename_len, "damg_v_%c_%c_%d_%g.dat", boundc, boundc2, L, beta);
+
+ FILE *damage_out = fopen(d_filename, "rb");
+
+ if (damage_out != NULL) {
+ fread(damage, sizeof(unsigned int), a_dist_size, damage_out);
+ fclose(damage_out);
+ }
}
double *toughness;
@@ -267,7 +278,7 @@ int main(int argc, char *argv[]) {
}
if (save_damage) {
- damage[i] = ((double)max_pos) / tmp_instance->network->num_edges;
+ damage[max_pos]++;
}
if (save_cluster_dist) {
@@ -327,24 +338,22 @@ int main(int argc, char *argv[]) {
}
free_break_data(breaking_data);
- if (debug_stop) break;
}
printf("\033[F\033[JFRACTURE: COMPLETE\n");
if (save_cluster_dist) {
- FILE *cluster_out = fopen(c_filename, "w");
+ FILE *cluster_out = fopen(c_filename, "wb");
+ FILE *avalanche_out = fopen(a_filename, "wb");
+
+ fwrite(cluster_size_dist, sizeof(unsigned int), c_dist_size, cluster_out);
+ fwrite(avalanche_size_dist, sizeof(unsigned int), a_dist_size, avalanche_out);
- for (int i = 0; i < c_dist_size; i++) {
- fprintf(cluster_out, "%u ", cluster_size_dist[i]);
- }
- fprintf(cluster_out, "\n");
- for (int i = 0; i < a_dist_size; i++) {
- fprintf(cluster_out, "%u ", avalanche_size_dist[i]);
- }
fclose(cluster_out);
+ fclose(avalanche_out);
free(c_filename);
+ free(a_filename);
free(cluster_size_dist);
free(avalanche_size_dist);
}
@@ -364,11 +373,9 @@ int main(int argc, char *argv[]) {
if (save_conductivity) {
char *cond_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(cond_filename, filename_len, "cond_v_%c_%c_%d_%g.txt", boundc, boundc2, L, beta);
- FILE *cond_file = fopen(cond_filename, "a");
- for (unsigned int i = 0; i < N; i++) {
- fprintf(cond_file, "%g ", conductivity[i]);
- }
+ snprintf(cond_filename, filename_len, "cond_v_%c_%c_%d_%g.dat", boundc, boundc2, L, beta);
+ FILE *cond_file = fopen(cond_filename, "ab");
+ fwrite(conductivity, sizeof(double), N, cond_file);
fclose(cond_file);
free(cond_filename);
free(conductivity);
@@ -376,25 +383,19 @@ int main(int argc, char *argv[]) {
if (save_toughness) {
char *tough_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(tough_filename, filename_len, "tuff_v_%c_%c_%d_%g.txt", boundc, boundc2, L, beta);
- FILE *tough_file = fopen(tough_filename, "a");
- for (unsigned int i = 0; i < N; i++) {
- fprintf(tough_file, "%g ", toughness[i]);
- }
+ snprintf(tough_filename, filename_len, "tuff_v_%c_%c_%d_%g.dat", boundc, boundc2, L, beta);
+ FILE *tough_file = fopen(tough_filename, "ab");
+ fwrite(toughness, sizeof(double), N, tough_file);
fclose(tough_file);
free(tough_filename);
free(toughness);
}
if (save_damage) {
- char *hdam_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(hdam_filename, filename_len, "damg_v_%c_%c_%d_%g.txt", boundc, boundc2, L, beta);
- FILE *hdam_file = fopen(hdam_filename, "a");
- for (unsigned int i = 0; i < N; i++) {
- fprintf(hdam_file, "%g ", damage[i]);
- }
+ FILE *hdam_file = fopen(d_filename, "wb");
+ fwrite(damage, sizeof(unsigned int), a_dist_size, hdam_file);
fclose(hdam_file);
- free(hdam_filename);
+ free(d_filename);
free(damage);
}
@@ -403,14 +404,12 @@ int main(int argc, char *argv[]) {
}
if (save_crit_stress) {
- char *a_filename = (char *)malloc(filename_len * sizeof(char));
- snprintf(a_filename, filename_len, "strs_v_%c_%c_%d_%g.txt", boundc, boundc2, L, beta);
- FILE *a_file = fopen(a_filename, "a");
- for (int i = 0; i < N; i++) {
- fprintf(a_file, "%g ", crit_stress[i]);
- }
- fclose(a_file);
- free(a_filename);
+ char *str_filename = (char *)malloc(filename_len * sizeof(char));
+ snprintf(str_filename, filename_len, "strs_v_%c_%c_%d_%g.dat", boundc, boundc2, L, beta);
+ FILE *str_file = fopen(str_filename, "ab");
+ fwrite(crit_stress, sizeof(double), N, str_file);
+ fclose(str_file);
+ free(str_filename);
free(crit_stress);
}