From f124bfbcdd8f0e32f143c14d1cfe29c7cd8aed4c Mon Sep 17 00:00:00 2001 From: arcan1s Date: Tue, 28 Jan 2014 05:48:38 +0400 Subject: [PATCH] fixed trj2pdb and trj --- mathmech/trj/src/add_main.c | 52 +------------------------ mathmech/trj/src/add_main.h | 67 +++++++++++++++++++++++++++++++-- mathmech/trj2pdb/src/add_main.c | 44 +--------------------- mathmech/trj2pdb/src/add_main.h | 57 ++++++++++++++++++++++++++-- mathmech/trj2pdb/src/main.c | 29 +++++++------- 5 files changed, 132 insertions(+), 117 deletions(-) diff --git a/mathmech/trj/src/add_main.c b/mathmech/trj/src/add_main.c index d0ec1da..995fef6 100644 --- a/mathmech/trj/src/add_main.c +++ b/mathmech/trj/src/add_main.c @@ -4,6 +4,7 @@ #include +#include "add_main.h" #include @@ -12,25 +13,6 @@ */ int error_checking (const char *input, const char *input_at, const char *output, const int step, const int type) -/** - * @brief function that checks errors in input variables - * @code - * error_checking (cell, from, input, num_needed_at, needed_at, output, to); - * @endcode - * - * @param input input file name - * @param input_at input file name with atom types - * @param output output file name - * @param step number of trajectory steps - * @param type type of trajectory - * - * @return 11 - error in 'input_at' - * @return 12 - error in 'input' - * @return 13 - error in 'output' - * @return 14 - error in 'step' - * @return 15 - error in 'type' - * @return 0 - exit without errors - */ { if (input_at[0] == '#') return 11; @@ -52,21 +34,6 @@ int error_checking (const char *input, const char *input_at, const char *output, */ int print_message (const int quiet, FILE *std_output, const int log, FILE *f_log, const int mode, const char *str) -/** - * @brief function that prints message in log and stdout - * @code - * print_message (quiet, stdout, log, f_log, 0, str); - * @endcode - * - * @param quiet status of quiet-mode - * @param std_output stdout - * @param log status of log-mode - * @param f_log log file - * @param mode number of message in "messages.c" - * @param str additional text in message - * - * @return 0 - exit without errors - */ { if ((quiet != 1) && (std_output != stderr)) message (0, mode, str, std_output); @@ -82,23 +49,6 @@ int print_message (const int quiet, FILE *std_output, const int log, FILE *f_log */ int set_defaults (char *input, char *input_at, int *log, char *output, int *step, int *total_types, int *type, int *quiet) -/** - * @brief function that sets default values of variables - * @code - * set_defaults (input, input_at, &log, output, &step, &type, &quiet); - * @endcode - * - * @param input input file name - * @param input_at input file name with atom types - * @param log status of log-mode - * @param output output file name - * @param step number of trajectory steps - * @param total_types number of different atom types - * @param type type of trajectory - * @param quiet status of quiet-mode - * - * @return 0 - exit without errors - */ { input[0] = '#'; input_at[0] = '#'; diff --git a/mathmech/trj/src/add_main.h b/mathmech/trj/src/add_main.h index 85f52e8..d2f8446 100644 --- a/mathmech/trj/src/add_main.h +++ b/mathmech/trj/src/add_main.h @@ -5,18 +5,77 @@ #ifndef ADD_MAIN_H #define ADD_MAIN_H + /** * @fn error_checking */ +int error_checking (const char *input, const char *input_at, const char *output, + const int step, const int type); +/** + * @brief function that checks errors in input variables + * @code + * error_checking (input, input_at, output, step, type); + * @endcode + * + * @param input input file name + * @param input_at input file name with atom types + * @param output output file name + * @param step number of trajectory steps + * @param type type of trajectory + * + * @return 11 - error in 'input_at' + * @return 12 - error in 'input' + * @return 13 - error in 'output' + * @return 14 - error in 'step' + * @return 15 - error in 'type' + * @return 0 - exit without errors + */ + + /** * @fn print_message */ +int print_message (const int quiet, FILE *std_output, const int log, FILE *f_log, + const int mode, const char *str); +/** + * @brief function that prints message in log and stdout + * @code + * print_message (quiet, stdout, log, f_log, 0, str); + * @endcode + * + * @param quiet status of quiet-mode + * @param std_output stdout + * @param log status of log-mode + * @param f_log log file + * @param mode number of message in "messages.c" + * @param str additional text in message + * + * @return 0 - exit without errors + */ + + /** * @fn set_defaults */ +int set_defaults (char *input, char *input_at, int *log, char *output, int *step, + int *total_types, int *type, int *quiet); +/** + * @brief function that sets default values of variables + * @code + * set_defaults (input, input_at, &log, output, &step, &total_types, &type, &quiet); + * @endcode + * + * @param input input file name + * @param input_at input file name with atom types + * @param log status of log-mode + * @param output output file name + * @param step number of trajectory steps + * @param total_types number of different atom types + * @param type type of trajectory + * @param quiet status of quiet-mode + * + * @return 0 - exit without errors + */ -int error_checking (const char *, const char *, const char *, const int, const int); -int print_message (const int, FILE *, const int, FILE *, const int, const char *); -int set_defaults (char *, char *, int *, char *, int *, int *, int *, int *); -#endif /* ADD_MAIN_H */ \ No newline at end of file +#endif /* ADD_MAIN_H */ diff --git a/mathmech/trj2pdb/src/add_main.c b/mathmech/trj2pdb/src/add_main.c index a6922a1..1c1d0d8 100644 --- a/mathmech/trj2pdb/src/add_main.c +++ b/mathmech/trj2pdb/src/add_main.c @@ -4,6 +4,7 @@ #include +#include "add_main.h" #include @@ -11,21 +12,6 @@ * @fn error_checking */ int error_checking (const const char *input, const char *output) -/** - * @brief function that checks errors in input variables - * @code - * error_checking (input, output); - * @endcode - * - * @param aglinp aglomerate file name - * @param cell massive of cell size - * @param input input file name - * @param output output file name - * - * @return 11 - error in 'input' - * @return 12 - error in 'output' - * @return 0 - exit without errors - */ { if (input[0] == '#') return 11; @@ -41,21 +27,6 @@ int error_checking (const const char *input, const char *output) */ int print_message (const int quiet, FILE *std_output, const int log, FILE *f_log, const int mode, const char *str) -/** - * @brief function that prints message in log and stdout - * @code - * print_message (quiet, stdout, log, f_log, 0, str); - * @endcode - * - * @param quiet status of quiet-mode - * @param std_output stdout - * @param log status of log-mode - * @param f_log log file - * @param mode number of message in "messages.c" - * @param str additional text in message - * - * @return 0 - exit without errors - */ { if ((quiet != 1) && (std_output != stderr)) message (0, mode, str, std_output); @@ -70,19 +41,6 @@ int print_message (const int quiet, FILE *std_output, const int log, FILE *f_log * @fn set_defaults */ int set_defaults (char *input, int *log, char *output, int *quiet) -/** - * @brief function that sets default values of variables - * @code - * set_defaults (input, &log, output, &quiet); - * @endcode - * - * @param input mask of trajectory files - * @param log status of log-mode - * @param output output file name - * @param quiet status of quiet-mode - * - * @return 0 - exit without errors - */ { input[0] = '#'; *log = 0; diff --git a/mathmech/trj2pdb/src/add_main.h b/mathmech/trj2pdb/src/add_main.h index c95aedd..b079d9c 100644 --- a/mathmech/trj2pdb/src/add_main.h +++ b/mathmech/trj2pdb/src/add_main.h @@ -5,18 +5,67 @@ #ifndef ADD_MAIN_H #define ADD_MAIN_H + /** * @fn error_checking */ +int error_checking (const const char *input, const char *output); +/** + * @brief function that checks errors in input variables + * @code + * error_checking (input, output); + * @endcode + * + * @param aglinp aglomerate file name + * @param cell massive of cell size + * @param input input file name + * @param output output file name + * + * @return 11 - error in 'input' + * @return 12 - error in 'output' + * @return 0 - exit without errors + */ + + /** * @fn print_message */ +int print_message (const int quiet, FILE *std_output, const int log, FILE *f_log, + const int mode, const char *str); +/** + * @brief function that prints message in log and stdout + * @code + * print_message (quiet, stdout, log, f_log, 0, str); + * @endcode + * + * @param quiet status of quiet-mode + * @param std_output stdout + * @param log status of log-mode + * @param f_log log file + * @param mode number of message in "messages.c" + * @param str additional text in message + * + * @return 0 - exit without errors + */ + + /** * @fn set_defaults */ +int set_defaults (char *input, int *log, char *output, int *quiet); +/** + * @brief function that sets default values of variables + * @code + * set_defaults (input, &log, output, &quiet); + * @endcode + * + * @param input mask of trajectory files + * @param log status of log-mode + * @param output output file name + * @param quiet status of quiet-mode + * + * @return 0 - exit without errors + */ -int error_checking (const char *, const char *); -int print_message (const int, FILE *, const int, FILE *, const int, const char *); -int set_defaults (char *, int *, char *, int *); -#endif /* ADD_MAIN_H */ \ No newline at end of file +#endif /* ADD_MAIN_H */ diff --git a/mathmech/trj2pdb/src/main.c b/mathmech/trj2pdb/src/main.c index 71603f4..d3e1654 100644 --- a/mathmech/trj2pdb/src/main.c +++ b/mathmech/trj2pdb/src/main.c @@ -9,9 +9,9 @@ #include "add_main.h" #include -#include #include #include +#include /** @@ -31,22 +31,21 @@ int main(int argc, char *argv[]) FILE *f_inp, *f_log; char input[256], logfile[256], output[256]; - float cell[3]; - int log, *needed_mol, num_atoms, num_mol, quiet, *true_label_mol; + int log, *needed_mol, quiet, *true_label_mol; atom_info *_atom_info; + system_info _system_info; /* input input file name * logfile log file name * output output file name * - * cell sell size - * * log status of log-mode * needed_mol massive of numbers of needed molecule * num_atoms number of atoms * num_mol number of molecules * quiet status of quiet-mode * true_label_mol massive of true numbers of molecule for atoms + * * _atom_info atom information structure */ @@ -128,11 +127,11 @@ int main(int argc, char *argv[]) print_message (quiet, stderr, log, f_log, 18, input); return 2; } - fscanf (f_inp, "%i", &num_atoms); + fscanf (f_inp, "%i", &_system_info.num_atoms); fclose (f_inp); - _atom_info = (atom_info *) malloc (8 * num_atoms * sizeof (atom_info)); - needed_mol = (int *) malloc (num_atoms * sizeof (int)); - true_label_mol = (int *) malloc (num_atoms * sizeof (int)); + _atom_info = (atom_info *) malloc (8 * _system_info.num_atoms * sizeof (atom_info)); + needed_mol = (int *) malloc (_system_info.num_atoms * sizeof (int)); + true_label_mol = (int *) malloc (_system_info.num_atoms * sizeof (int)); // error checking if ((_atom_info == NULL) || (needed_mol == NULL) || @@ -142,7 +141,7 @@ int main(int argc, char *argv[]) return 3; } for (i=0; i<3; i++) - cell[i] = 0.0; + _system_info.cell[i] = 0.0; sprintf (tmp_str, "%6cInput file: '%s';\n%6cOutput file: '%s';\n%6cLog: %i;\n%6cQuiet: %i;\n", ' ', input, ' ', output, ' ', log, ' ', quiet); print_message (quiet, stdout, log, f_log, 5, tmp_str); @@ -152,18 +151,18 @@ int main(int argc, char *argv[]) // reading coordinates print_message (quiet, stdout, log, f_log, 7, input); error = 1; - error = reading_coords (1, input, tmp_int, &tmp_int, cell, &num_mol, &num_atoms, - true_label_mol, _atom_info); + error = reading_coords (1, input, tmp_int, &tmp_int, &_system_info, true_label_mol, + _atom_info); // print coordinates if (error == 0) { sprintf (tmp_str, "%6cNumber of molecules: %i; %6cNumber of atoms: %i\n", - ' ', num_mol, ' ', num_atoms); - for (i=0; i