From 06afc729f9061c1cfa14c78728d61d518324c2f0 Mon Sep 17 00:00:00 2001 From: Samo Penic <samo.penic@gmail.com> Date: Wed, 04 May 2022 05:46:43 +0000 Subject: [PATCH] Moved all global variables to separate file and defined extern keyword where appropriate --- src/main.c | 2 src/snapshot.c | 2 + src/io.c | 1 src/bondflip.c | 1 src/general.h | 8 ---- src/general.c | 2 src/tspoststat.c | 2 src/vertexmove.c | 1 src/io.h | 4 - src/Makefile.am | 4 +- src/timestep.c | 1 src/globals.h | 14 +++++++ src/restore.c | 1 src/sh.c | 2 src/globals.c | 15 +++++++ src/tsmeasure.c | 2 16 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index c7e3c88..00c8988 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,7 +14,7 @@ #------------- LIBS ---------- lib_LTLIBRARIES= libtrisurf.la -libtrisurf_la_SOURCES= general.c vertex.c bond.c triangle.c cell.c vesicle.c initial_distribution.c io.c dumpstate.c frame.c energy.c timestep.c vertexmove.c bondflip.c poly.c stats.c sh.c shcomplex.c constvol.c snapshot.c restore.c cluster.c +libtrisurf_la_SOURCES= general.c vertex.c bond.c triangle.c cell.c vesicle.c initial_distribution.c io.c dumpstate.c frame.c energy.c timestep.c vertexmove.c bondflip.c poly.c stats.c sh.c shcomplex.c constvol.c snapshot.c restore.c cluster.c globals.c #libtrisurf_la_CPPFLAGS = ${libxml2_CFLAGS} libtrisurf_la_LIBADD=${libxml2_LIBS} -pkginclude_HEADERS=general.h vertex.h bond.h triangle.h cell.h vesicle.h initial_distribution.h io.h dumpstate.h frame.h energy.h timestep.h vertexmove.h bondflip.h poly.h stats.h sh.h shcomplex.h constvol.h snapshot.h restore.h cluster.h +pkginclude_HEADERS=general.h vertex.h bond.h triangle.h cell.h vesicle.h initial_distribution.h io.h dumpstate.h frame.h energy.h timestep.h vertexmove.h bondflip.h poly.h stats.h sh.h shcomplex.h constvol.h snapshot.h restore.h cluster.h globals.h diff --git a/src/bondflip.c b/src/bondflip.c index 8eb6da9..973a58a 100644 --- a/src/bondflip.c +++ b/src/bondflip.c @@ -14,6 +14,7 @@ #include<stdio.h> #include<string.h> #include "constvol.h" +#include "globals.h" ts_bool single_bondflip_timestep(ts_vesicle *vesicle, ts_bond *bond, ts_double *rn){ /*c Vertex and triangle (lm and lp) indexing for bond flip: diff --git a/src/general.c b/src/general.c index 6b8a99c..1d72323 100644 --- a/src/general.c +++ b/src/general.c @@ -12,7 +12,7 @@ #include <fcntl.h> #include <errno.h> #include <string.h> - +#include "globals.h" ts_uint ts_fprintf(FILE *fd, char *fmt, ...){ if(quiet) return TS_SUCCESS; va_list ap; diff --git a/src/general.h b/src/general.h index d131ca6..2f15c50 100644 --- a/src/general.h +++ b/src/general.h @@ -352,14 +352,6 @@ ts_cluster **cluster; } ts_cluster_list; - -/* GLOBAL VARIABLES */ - -int quiet; -ts_double V0; -ts_double A0; -ts_double epsvol; -ts_double epsarea; /* FUNCTIONS */ /** Non-fatal error function handler: diff --git a/src/globals.c b/src/globals.c new file mode 100644 index 0000000..f3cab81 --- /dev/null +++ b/src/globals.c @@ -0,0 +1,15 @@ +#include "general.h" +#include "io.h" +#include "globals.h" + +/* GLOBAL VARIABLES */ + +int quiet; +ts_double V0; +ts_double A0; +ts_double epsvol; +ts_double epsarea; +ts_args command_line_args; +int force_from_tape; +char tapetxt[128000]; //stores text file of the tape + diff --git a/src/globals.h b/src/globals.h new file mode 100644 index 0000000..3e46ab8 --- /dev/null +++ b/src/globals.h @@ -0,0 +1,14 @@ +#ifndef __GLOBALS +#define __GLOBALS +/* GLOBAL VARIABLES */ +#include "general.h" +#include "io.h" +extern int quiet; +extern ts_double V0; +extern ts_double A0; +extern ts_double epsvol; +extern ts_double epsarea; +extern ts_args command_line_args; +extern int force_from_tape; +extern char tapetxt[128000]; //stores text file of the tape +#endif diff --git a/src/io.c b/src/io.c index 034207b..a331c44 100644 --- a/src/io.c +++ b/src/io.c @@ -1,6 +1,7 @@ /* vim: set ts=4 sts=4 sw=4 noet : */ #include "general.h" +#include "globals.h" #include<stdio.h> #include "io.h" #include "vertex.h" diff --git a/src/io.h b/src/io.h index 265992b..07f47eb 100644 --- a/src/io.h +++ b/src/io.h @@ -7,8 +7,7 @@ static char prefixname[1024]; static ts_bool restore=0; static char tape[1024]; */ -int force_from_tape; -char tapetxt[128000]; //stores text file of the tape + typedef struct{ ts_int force_from_tape; ts_int reset_iteration_count; @@ -21,7 +20,6 @@ char dump_from_vtk[1024]; } ts_args; -ts_args command_line_args; ts_bool parse_args(int argc, char **argv); diff --git a/src/main.c b/src/main.c index ee462aa..5f8858f 100644 --- a/src/main.c +++ b/src/main.c @@ -17,7 +17,7 @@ #include "shcomplex.h" #include "dumpstate.h" #include "restore.h" - +#include "globals.h" #include <fcntl.h> /** Entrance function to the program * @param argv is a number of parameters used in program call (including the program name diff --git a/src/restore.c b/src/restore.c index 9ee9c45..1d4d7f8 100644 --- a/src/restore.c +++ b/src/restore.c @@ -17,6 +17,7 @@ #include "initial_distribution.h" #include "io.h" #include <math.h> +#include "globals.h" ts_vesicle *parseDump(char *dumpfname) { xmlDocPtr doc; diff --git a/src/sh.c b/src/sh.c index 3f64939..668617f 100644 --- a/src/sh.c +++ b/src/sh.c @@ -5,7 +5,7 @@ #include "sh.h" #include "io.h" #include <string.h> - +#include "globals.h" ts_spharm *sph_init(ts_vertex_list *vlist, ts_uint l){ ts_uint j,i; diff --git a/src/snapshot.c b/src/snapshot.c index 46534dc..81fb476 100644 --- a/src/snapshot.c +++ b/src/snapshot.c @@ -10,6 +10,8 @@ #include<config.h> #include <time.h> #include "io.h" +#include "globals.h" + /* a helper function that utilizes ts_string data structure and performs same as sprintf */ ts_uint ts_sprintf(ts_string *str, char *fmt, ...){ va_list ap; diff --git a/src/timestep.c b/src/timestep.c index 66b3a39..753d8b3 100644 --- a/src/timestep.c +++ b/src/timestep.c @@ -4,6 +4,7 @@ #include<math.h> //#include "io.h" #include "general.h" +#include "globals.h" #include "timestep.h" #include "vertexmove.h" #include "bondflip.h" diff --git a/src/tsmeasure.c b/src/tsmeasure.c index beabc61..ed0a0d8 100644 --- a/src/tsmeasure.c +++ b/src/tsmeasure.c @@ -26,7 +26,7 @@ #include <snapshot.h> #include<gsl/gsl_complex.h> #include<gsl/gsl_complex_math.h> - +#include "globals.h" ts_vesicle *restoreVesicle(char *filename){ ts_vesicle *vesicle = parseDump(filename); diff --git a/src/tspoststat.c b/src/tspoststat.c index f518000..c0b0175 100644 --- a/src/tspoststat.c +++ b/src/tspoststat.c @@ -29,7 +29,7 @@ #include<gsl/gsl_complex.h> #include<gsl/gsl_complex_math.h> #include<stdio.h> - +#include "globals.h" ts_vesicle *restoreVesicle(char *filename){ ts_vesicle *vesicle = parseDump(filename); return vesicle; diff --git a/src/vertexmove.c b/src/vertexmove.c index e74fa74..406ec9e 100644 --- a/src/vertexmove.c +++ b/src/vertexmove.c @@ -15,6 +15,7 @@ #include "vertexmove.h" #include <string.h> #include "constvol.h" +#include "globals.h" ts_bool single_verticle_timestep(ts_vesicle *vesicle,ts_vertex *vtx,ts_double *rn){ ts_uint i; -- Gitblit v1.9.3