Skip to content

Commit

Permalink
Refactoring variable names for clarity.
Browse files Browse the repository at this point in the history
  • Loading branch information
merrygoat committed May 15, 2019
1 parent 3e84bf4 commit 2c76798
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 43 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(TCC)
message(STATUS "Is CMAKE INSTALL PREFIX deafult? :${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT}")
message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
message(STATUS "Is CMAKE_INSTALL_PREFIX set to its default value?: ${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT}")
message(STATUS "The source directory of CMAKE: ${CMAKE_SOURCE_DIR}")
IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
SET(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/bin)
Expand Down
4 changes: 2 additions & 2 deletions inc/globals.h
Expand Up @@ -20,8 +20,8 @@ extern int* cluster_list_width[]; // A list of pointers to the "m" storage width


struct xyz_info {
int total_frames;
int data_width;
long total_frames;
long max_frames;
long *num_particles;
long *frame_offsets;
};
Expand Down
2 changes: 1 addition & 1 deletion inc/setup.h
Expand Up @@ -15,7 +15,7 @@ void free_frame_variables();

void analyse_cluster_dependencies();

void setup_cluster_lists();
void validate_cluster_lists();

void print_version_number();

Expand Down
2 changes: 1 addition & 1 deletion inc/version.h
Expand Up @@ -3,6 +3,6 @@

#define TCC_VERSION_MAJOR 1
#define TCC_VERSION_MINOR 0
#define TCC_VERSION_PATCH 3
#define TCC_VERSION_PATCH 4

#endif
65 changes: 32 additions & 33 deletions src/input.c
Expand Up @@ -8,7 +8,7 @@ void read_ini_file() {

char errMsg[1000];
dictionary * ini ;
const char *inputfilename = "inputparameters.ini";
const char *input_file_name = "inputparameters.ini";

fXmolName = malloc(500 * sizeof(char));
if (fXmolName==NULL) {
Expand All @@ -19,9 +19,9 @@ void read_ini_file() {
Error_no_free("Initialise_Global_Variables(): fBoxSizeName[] malloc out of memory\n");
}

ini = iniparser_load(inputfilename);
ini = iniparser_load(input_file_name);
if (ini==NULL) {
sprintf(errMsg,"read_ini_file(): Error opening file %s", inputfilename);
sprintf(errMsg,"read_ini_file(): Error opening file %s", input_file_name);
Error_no_free(errMsg);
}

Expand Down Expand Up @@ -243,60 +243,59 @@ struct xyz_info parse_xyz_file() {

char line[1000];
char error_message[100];
int i;
int line_number;
int line_number = 0;
int valid_long = 0;
FILE *xyzfile;
struct xyz_info input_xyz_info;

line_number = 0;
FILE *xyz_file;
struct xyz_info xyz_info;

initialize_xyz_info(&input_xyz_info);
initialize_xyz_info(&xyz_info);

xyzfile=fopen(fXmolName,"rb"); // open xmol trajecotry
if (xyzfile==NULL) {
sprintf(error_message,"Error opening XYZ file %s",fXmolName); // Always test file open
// Open the source XYZ file
xyz_file = fopen(fXmolName, "rb");
if (xyz_file == NULL) {
sprintf(error_message, "Error opening XYZ file %s", fXmolName);
Error_no_free(error_message);
}

while(feof(xyzfile) == 0) {
// Read in num particles
if(input_xyz_info.total_frames > 1000) {
Error_no_free("XYZ file has over 1000 frames, cannot process XYZ file");
while(feof(xyz_file) == 0) {
if(xyz_info.total_frames > xyz_info.max_frames) {
sprintf(error_message, "XYZ file has over %li frames, cannot process XYZ file", xyz_info.max_frames);
Error_no_free(error_message);
}
// Read in num particles
line[0] = '\n';
fgets(line, 1000, xyzfile);
fgets(line, 1000, xyz_file);
if (line[0] != '\n') {
input_xyz_info.num_particles[input_xyz_info.total_frames] = get_long_from_string(line, &valid_long);
xyz_info.num_particles[xyz_info.total_frames] = get_long_from_string(line, &valid_long);
if (valid_long != 1) {
sprintf(error_message, "Unable to read XYZ file. Expected number of particles on line: %d",
line_number);
sprintf(error_message, "Unable to read XYZ file. Expected number of particles on line: %d", line_number);
Error_no_free(error_message);
}
line_number += 1;
input_xyz_info.frame_offsets[input_xyz_info.total_frames] = ftell(xyzfile);
for (i = 0; i < input_xyz_info.num_particles[input_xyz_info.total_frames]+1; i++) {
if(feof(xyzfile)) {
sprintf(error_message, "Unexpected end of file at line %d. Some particles are missing.",
line_number);
// Record where start of frame is
xyz_info.frame_offsets[xyz_info.total_frames] = ftell(xyz_file);
// Loop through particles checking that each line is valid
for (int i = 0; i < xyz_info.num_particles[xyz_info.total_frames] + 1; i++) {
if(feof(xyz_file)) {
sprintf(error_message, "Unexpected end of file at line %d. Some particles are missing.", line_number);
Error_no_free(error_message);
}
try_read_line_from_file(xyzfile);
try_read_line_from_file(xyz_file);
line_number += 1;

}
input_xyz_info.total_frames += 1;
xyz_info.total_frames += 1;
}
}
fclose(xyzfile);
return input_xyz_info;
fclose(xyz_file);
return xyz_info;
}

void initialize_xyz_info(struct xyz_info* input_xyz_info) {
(*input_xyz_info).total_frames = 0;
(*input_xyz_info).data_width = 1000;
(*input_xyz_info).num_particles = malloc((*input_xyz_info).data_width * sizeof(long));
(*input_xyz_info).frame_offsets = malloc((*input_xyz_info).data_width * sizeof(long));
(*input_xyz_info).max_frames = 1000;
(*input_xyz_info).num_particles = malloc((*input_xyz_info).max_frames * sizeof(long));
(*input_xyz_info).frame_offsets = malloc((*input_xyz_info).max_frames * sizeof(long));
}

void free_xyz_info(struct xyz_info* input_xyz_info) {
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Expand Up @@ -75,7 +75,7 @@ int main(int argc, char **argv) {
struct xyz_info input_xyz_info;

print_version_number();
setup_cluster_lists();
validate_cluster_lists();
read_ini_file();
read_clusters_to_analyse();
analyse_cluster_dependencies();
Expand Down
12 changes: 9 additions & 3 deletions src/setup.c
Expand Up @@ -291,15 +291,20 @@ void analyse_cluster_dependencies() {
if(dosp4 == 1) dosp3 = 1;

}
//! Check whether the cluster lists are valid.
/*!
* Counts the number of clusters in the cluster_names at the beginning of
* the main function and then checks if the rest of the lists are this length.
*/
void validate_cluster_lists() {

void setup_cluster_lists() {
num_cluster_types = 0;

while(strcmp(cluster_names[num_cluster_types], "-1") != 0) {
if (strcmp(cluster_names[num_cluster_types], "11A") == 0) {
eleven_A_number = num_cluster_types;
}
else if (strcmp(cluster_names[num_cluster_types], "11A") == 0) {
else if (strcmp(cluster_names[num_cluster_types], "13A") == 0) {
thirteen_A_number = num_cluster_types;
}
num_cluster_types += 1;
Expand All @@ -325,5 +330,6 @@ void setup_cluster_lists() {
}

void print_version_number() {
printf("The Topological Cluster Classification. Version %d.%d.%d.\n", TCC_VERSION_MAJOR, TCC_VERSION_MINOR, TCC_VERSION_PATCH);
printf("The Topological Cluster Classification. Version %d.%d.%d.\n",
TCC_VERSION_MAJOR, TCC_VERSION_MINOR, TCC_VERSION_PATCH);
}
3 changes: 2 additions & 1 deletion src/tools.c
Expand Up @@ -54,7 +54,8 @@ double get_double_from_string(const char *buff, int *validDouble) {
}

int try_read_line_from_file(FILE *file_name) {
// Try to read a line from a file. If line successfuly read return 1 else return 0.
// Try to read a line from a file. If line successfully read return 1,
// else return 0.
char line[1000];
size_t line_length;

Expand Down

0 comments on commit 2c76798

Please sign in to comment.