diff --git a/stat_new/Makefile b/stat_new/Makefile new file mode 100644 index 0000000..7eeaca2 --- /dev/null +++ b/stat_new/Makefile @@ -0,0 +1,20 @@ +PROJECT=STATGEN + +CC=gcc +CFLAGS=-c -Wall -fPIC +LDFLAGS=-lm +SOURCES=main.c coords.c int2str.c stat_print.c stat_select.c stat_sort.c summary_stat.c +OBJECTS=$(SOURCES:.c=.o) +EXECUTABLE=statgen + +$(STATGEN): $(SOURCES) $(EXECUTABLE) + +$(EXECUTABLE): $(OBJECTS) + $(CC) $(LDFLAGS) $(OBJECTS) -o $@ + +.c.o: + $(CC) $(CFLAGS) $< -o $@ + +clean: + rm -f *.o + diff --git a/stat_new/coords b/stat_new/coords deleted file mode 100755 index fc2e2bb..0000000 Binary files a/stat_new/coords and /dev/null differ diff --git a/stat_new/coords.c b/stat_new/coords.c index 2639307..8e7a82d 100644 --- a/stat_new/coords.c +++ b/stat_new/coords.c @@ -11,22 +11,6 @@ #include -char conv (int fnumb, int dig_pos) -{ - int d, h, o; - char const digit[] = "0123456789"; - - h = fnumb / 100; - d = (fnumb % 100) / 10; - o = fnumb % 10; - - if (dig_pos == 1) return digit[o]; - if (dig_pos == 2) return digit[d]; - if (dig_pos == 3) return digit[h]; - else return digit[0]; -} - - int reading_coords (char *filename, int type_inter, const int *label_atom, const float *cell, int *num_mol, int *num_atoms, int *true_label_mol, int *label_mol, @@ -44,7 +28,7 @@ int reading_coords (char *filename, int type_inter, const int *label_atom, */ { char file_string[256]; - int atoms, i, j, tr_num_atoms, ref_mol, x, y, z; + int atoms, i, j, tr_num_atoms, ref_mol, x, y; float not_tr_coords[750000], ref[3]; FILE *inp; /* file_string - temp string variable @@ -291,23 +275,5 @@ int reading_coords (char *filename, int type_inter, const int *label_atom, } } - return 0; -} - - -int main (int argc, char *argv[]) -{ -// int i, label_atom[5], label_mol[200000], num_atoms, num_mol, type_atoms[200000]; -// float a[600000], cell[3]; -// -// for (i=0; i<5; i++) -// label_atom[i] = 0; -// label_atom[0] = 1; -// cell[0] = 34.8616; -// cell[1] = 34.7930; -// cell[2] = 34.7925; -// -// reading_coords ("oct.001", 1, label_atom, cell, &num_mol, &num_atoms, label_mol, type_atoms, a); -// return 0; } \ No newline at end of file diff --git a/stat_new/int2str.c b/stat_new/int2str.c new file mode 100644 index 0000000..7e74363 --- /dev/null +++ b/stat_new/int2str.c @@ -0,0 +1,26 @@ +/* Library for converting integer to string + * Usage + * char = conv (number, position) + */ + +#include +#include + + +char conv (int fnumb, int dig_pos) +/* fnumb - integer + * dig_pos - position + */ +{ + int d, h, o; + char const digit[] = "0123456789"; + + h = fnumb / 100; + d = (fnumb % 100) / 10; + o = fnumb % 10; + + if (dig_pos == 1) return digit[o]; + if (dig_pos == 2) return digit[d]; + if (dig_pos == 3) return digit[h]; + else return digit[0]; +} \ No newline at end of file diff --git a/stat_new/main.c b/stat_new/main.c new file mode 100644 index 0000000..9ce5876 --- /dev/null +++ b/stat_new/main.c @@ -0,0 +1,342 @@ +#include +#include +#include +#include + + +int error_checking (const float *cell, int from, const char *input, + int num_of_inter, const char *output, int to, int type_inter) +{ + if ((type_inter == 0) || (type_inter > 4)) + return 11; + if ((cell[0] == 0.0) || (cell[1] == 0.0) || (cell[2] == 0.0)) + return 12; + if ((to == -1) || (from == -1)) + return 13; + if (num_of_inter == 0) + return 14; + if (input[0] == '#') + return 15; + if (output[0] == '#') + return 16; + + return 0; +} + + +int printing_head (const char *output, int log, int quiet, const char *input, + int from, int to, const float *cell, int type_inter, + const int *label_atom, int num_of_inter, const float *crit) +{ + int i; + FILE *f_out; + + f_out = fopen (output, "w"); + fprintf (f_out, "statgen ::: V.1.0.0 ::: 2013-07-17\n\n"); + fprintf (f_out, "CONFIGURATION\n"); + + fprintf (f_out, "LOG=%i\nQUIET=%i\n", log, quiet); + fprintf (f_out, "MASK=%s\nFIRST=%i\nLAST=%i\n", input, from, to); + fprintf (f_out, "CELL=%.4f,%.4f,%.4f\n", cell[0], cell[1], cell[2]); + fprintf (f_out, "ATOMS=%i", label_atom[0]); + for (i=1; i 0) + { + crit = (float *) malloc ( 16 * num_of_inter * sizeof (float)); + for (i=0; i<16*num_of_inter; i++) + crit[i] = 0.0; + num_of_inter = 0; + } + +// reading arguments + for (i=1; i to) + { + to += from; + from = to - from; + to -= from; + } + step = to - from + 1; + i++; + } + else if ((argv[i][0] == '-') && (argv[i][1] == 'c')) +// cell size + { + sscanf (argv[i+1], "%f,%f,%f", &cell[0], &cell[1], &cell[2]); + i++; + } + else if ((argv[i][0] == '-') && (argv[i][1] == 'a')) +// atom types + { + type_inter = 1; + for (j=0; j 1) + { + printf ("Something wrong (error code: %i)!\nSee 'statgen -h' for more details\n", error); + return 1; + } + +// processing +// initial variables + k = strlen (input); + strcpy (filename, input); + filename[k] = '.'; + filename[k+1] = conv (from, 3); + filename[k+2] = conv (from, 2); + filename[k+3] = conv (from, 1); + filename[k+4] = '\0'; + f_inp = fopen (filename, "r"); + if (f_inp == NULL) + return 1; + fscanf (f_inp, "%i", &num_atoms); + fclose (f_inp); + coords = (float *) malloc (3 * num_atoms * sizeof (float)); + label_mol = (int *) malloc (num_atoms * sizeof (int)); + true_label_mol = (int *) malloc (num_atoms * sizeof (int)); + type_atoms = (int *) malloc (num_atoms * sizeof (int)); + +// head + printing_head (output, log, quiet, input, from, to, cell, type_inter, label_atom, + num_of_inter, crit); + +// main cycle + for (i=from; i