+ added CMakeLists.txt

+ added headers
+ added library 'add_main.c'
+ some optimization
This commit is contained in:
arcan1s
2013-07-22 06:06:01 +04:00
parent 2057208ef6
commit 51d31d0a2f
22 changed files with 347 additions and 210 deletions

23
statgen/CMakeLists.txt Normal file
View File

@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 2.8)
project(statgen)
set(MY_CXX_FLAGS "-Wall")
set(CMAKE_CXX_FLAGS "-O0 ${MY_CXX_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "-lm")
set(SOURCE_EXE main.c)
set(SOURCE_LIB add_main.c
coords.c
graph.c
int2char.c
messages.c
stat_print.c
stat_select.c
stat_sort.c
summary_stat.c)
add_library(stat SHARED ${SOURCE_LIB})
add_executable(statgen ${SOURCE_EXE})
target_link_libraries(statgen stat)

View File

@ -3,7 +3,7 @@ PROJECT=STATGEN
CC=gcc
CFLAGS=-c -Wall -fPIC
LDFLAGS=-lm
SOURCES=main.c coords.c graph.c int2str.c messages.c stat_print.c stat_select.c stat_sort.c summary_stat.c
SOURCES=main.c add_main.c coords.c graph.c int2char.c messages.c stat_print.c stat_select.c stat_sort.c summary_stat.c
OBJECTS=$(SOURCES:.c=.o)
EXECUTABLE=statgen

85
statgen/add_main.c Normal file
View File

@ -0,0 +1,85 @@
/* Additional library for main.c (statgen)
*/
#include <stdio.h>
int error_checking (const float *cell, const int from, const char *input,
const int max_depth, const int num_of_inter, const char *output,
const int to, const 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;
if ((max_depth < 3) && (max_depth != 0))
return 19;
return 0;
}
int printing_head (const char *output, const int log, const int quiet,
const char *input, const int from, const int to, const float *cell,
const int type_inter, const int *label_atom,
const int num_of_inter, const float *crit, const int max_depth)
{
int i, j;
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<type_inter; i++)
fprintf (f_out, ",%i", label_atom[i]);
fprintf (f_out, "\n");
for (i=0; i<num_of_inter; i++)
{
fprintf (f_out, "INTERACTION=");
for (j=0; j<16; j++)
if ((crit[16*i+j] != 0.0) &&
((j != 4) && (j != 8) && (j != 9) && (j != 12) && (j != 13) && (j != 14)))
fprintf (f_out, "%i-%i:%4.2f,", j/4, j%4, crit[16*i+j]);
fprintf (f_out, "\n");
}
fprintf (f_out, "ISOMORPHISM=%i\n", max_depth);
fprintf (f_out, "END\n\n");
fclose (f_out);
return 0;
}
int set_defaults (float *cell, int *from, char *input, int *log, int *max_depth,
int *num_of_inter, char *output, int *to, int *type_inter, int *quiet)
{
int i;
for (i=0; i<3; i++)
cell[i] = 0.0;
*from = -1;
input[0] = '#';
*log = 0;
*max_depth = 0;
*num_of_inter = 0;
output[0] = '#';
*to = -1;
*type_inter = 0;
*quiet = 0;
return 0;
}

12
statgen/add_main.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef ADD_MAIN_H
#define ADD_MAIN_H
int error_checking (const float *, const int, const char *, const int, const int,
const char *, const int, const int);
int printing_head (const char *, const int, const int, const char *, const int,
const int, const float *, const int, const int *, const int,
const float *, const int);
int set_defaults (float *, int *, char *, int *, int *, int *, char *, int *,
int *, int *);
#endif /* ADD_MAIN_H */

View File

@ -8,7 +8,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int reading_coords (const char *filename, const int type_inter,
@ -27,11 +26,12 @@ int reading_coords (const char *filename, const int type_inter,
* coords - massive of coordinates
*/
{
char file_string[256];
int atoms, i, j, tr_num_atoms, ref_mol, x, y;
float not_tr_coords[750000], ref[3];
char at_symb[32], file_string[256];
int atoms, cur_at_num, cur_at_type, cur_mol, i, j, tr_num_atoms, ref_mol, x, y;
float cur_coords[3], not_tr_coords[750000], ref[3];
FILE *inp;
/* file_string - temp string variable
/* cur_*, at_symb - temp variables
* file_string - temp string variable
* atoms - total number of atoms in system
* tr_num_atoms - number of translated atoms for writing coordinates (m.b. 8*num_atoms)
* ref_mol - number of molecule for reference
@ -50,20 +50,23 @@ int reading_coords (const char *filename, const int type_inter,
ref_mol = -1;
fscanf (inp, "%i", &atoms);
fgets (file_string, 256, inp);
for (i=0; i<atoms; i++)
{
fgets (file_string, 256, inp);
sscanf (file_string, "%i%s%f%f%f%i%i", &cur_at_num, at_symb, &cur_coords[0],
&cur_coords[1], &cur_coords[2], &cur_at_type, &cur_mol);
for (j=0; j<type_inter; j++)
if (atoi (&file_string[47]) == label_atom[j])
if (cur_at_type == label_atom[j])
{
not_tr_coords[3**num_atoms+0] = atof (&file_string[10]);
not_tr_coords[3**num_atoms+1] = atof (&file_string[23]);
not_tr_coords[3**num_atoms+2] = atof (&file_string[35]);
not_tr_coords[3**num_atoms+0] = cur_coords[0];
not_tr_coords[3**num_atoms+1] = cur_coords[1];
not_tr_coords[3**num_atoms+2] = cur_coords[2];
if (ref_mol != atoi (&file_string[53]))
if (ref_mol != cur_mol)
{
ref_mol = atoi (&file_string[53]);
ref_mol = cur_mol;
true_label_mol[*num_mol] = ref_mol;
*num_mol = *num_mol + 1;
}

7
statgen/coords.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef COORDS_H
#define COORDS_H
int reading_coords (const char *, const int, const int *, const float *, int *,
int *, int *, int *, int *, float *);
#endif /* COORDS_H */

View File

@ -1,24 +1,22 @@
/* Library for graph structure analyze
* Usage:
* graph_analyze (N, connect, max_depth)
* graph_analyze (N, connect, max_depth, isomorphism_class)
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int check_cycle (const int N, const int *matrix)
int check_cycle (const int N, const int *pn)
// function to return number of cycles
{
int cycle, i, j;
int cycle, i;
/* cycle - number of cycle
*/
cycle = 0;
for (i=0; i<N; i++)
for (j=0; j<N; j++)
cycle += matrix[i*N+j];
for (i=1; i<N; i++)
cycle += i*pn[i];
// for linear (0.5*cycle == N-1)
cycle = 0.5 * cycle - (N - 1);
@ -27,21 +25,19 @@ int check_cycle (const int N, const int *matrix)
}
int check_cycle_size (const int N, const int *matrix, const int size)
int check_cycle_size (const int N, const int *matrix, const int depth, int *n_cycle)
// function to return number of cycles of certain size
{
int cur_N, cycle, i, j, k, n, num, *submatrix, *vertex;
int cur_N, cycle, i, j, k, n, p, *vertex;
/* cur_N - current number of elements in submatrix
* cycle - if ((0.5 * cycle) == size) that cycle exist
* cycle - if (cycle == 1) that cycle exist
* n - number of samples
* num - number of cycles of certain size
* submatrix - connectivity matrix for subgraph
* vertex - vertexes of subgraph
*/
num = 0;
submatrix = (int *) malloc (size * size * sizeof (int));
vertex = (int *) malloc (N * sizeof (int));
for (i=0; i<depth-2; i++)
n_cycle[i] = 0;
// matrix generation from
// http://wincode.org/acm-icpc/subsets-generation
@ -56,89 +52,82 @@ int check_cycle_size (const int N, const int *matrix, const int size)
cur_N++;
}
if (cur_N == size)
if ((cur_N > 2) && (cur_N <= depth))
{
// copy connectivity matrix
cycle = 1;
for (j=0; j<cur_N; j++)
{
p = 0;
for (k=0; k<cur_N; k++)
submatrix[j*cur_N+k] = matrix[vertex[j]*N+vertex[k]];
p += matrix[vertex[j]*N+vertex[k]];
if (p != 2)
cycle = 0;
}
cycle = 0;
// analyze subgraph
for (j=0; j<cur_N; j++)
for (k=0; k<cur_N; k++)
cycle += submatrix[j*cur_N+j];
if ((0.5 * cycle) == size)
num++;
if (cycle == 1)
n_cycle[cur_N-3]++;
}
}
free (vertex);
free (submatrix);
return num;
return 0;
}
int check_tail (const int N, const int *matrix)
int check_tail (const int *pn)
// function to return number of tails
{
int i, j, pn, tail;
/* pn - weight one vertex
* tail - number of tails
*/
tail = 0;
for (i=0; i<N; i++)
{
pn = 0;
for (j=0; j<N; j++)
pn += matrix[i*N+j];
if (pn == 1)
tail++;
}
return tail;
return pn[1];
}
int graph_analyze (const int N, const int *matrix, const int max_depth, char *iso)
int graph_analyze (const int N, const int *matrix, const int max_depth, int *iso)
/* N - number of vertex in graph
* matrix - connectivity matrix
* max_depth - maximum depth for check_cycle_size
* iso - isomorphism class
*/
{
int cycle, depth, i, *n_cycle, tail;
/* cycle - number of cycles
* depth - depth for check_cycle_size
* n_cycle - number of cycles of certain size
* tail - number of tails
int depth, i, j, *n_cycle, p, *pn;
/* depth - depth for check_cycle_size
* n_cycle - number of cycle
* p - current weight
* pn - total weight
*/
if (max_depth > N)
depth = N;
else
depth = max_depth;
n_cycle = (int *) malloc ((max_depth-2) * sizeof (int));
// convert to matrix of weight
pn = (int *) malloc (N * sizeof (int));
n_cycle = (int *) malloc ((depth - 2) * sizeof (int));
for (i=0; i<N; i++)
pn[i] = 0;
for (i=0; i<N; i++)
{
p = 0;
for (j=0; j<N; j++)
p += matrix[i*N+j];
pn[p]++;
}
tail = check_tail (N, matrix);
cycle = check_cycle (N, matrix);
if (cycle > 0)
iso[0] = check_tail (pn);
iso[1] = check_cycle (N, pn);
for (i=2; i<max_depth; i++)
iso[i] = 0;
if (iso[1] > 0)
{
check_cycle_size (N, matrix, depth, n_cycle);
for (i=0; i<depth-2; i++)
n_cycle[i] = check_cycle_size (N, matrix, i+3);
else
for (i=0; i<depth-2; i++)
n_cycle[i] = 0;
for (i=depth-2; i<max_depth-2; i++)
n_cycle[i] = 0;
sprintf (iso, "%i.%i.%i", N, tail, cycle);
for (i=0; i<max_depth-2; i++)
sprintf (iso, "%s.%i", iso, n_cycle[i]);
iso[i+2] = n_cycle[i];
}
free (n_cycle);
free (pn);
return 1;
}

9
statgen/graph.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef GRAPH_H
#define GRAPH_H
int graph_analyze (const int, const int *, const int, int *);
int check_cycle (const int, const int *);
int check_cycle_size (const int, const int *, const int, int *);
int check_tail (const int *);
#endif /* GRAPH_H */

View File

@ -3,9 +3,6 @@
* char = conv (number, position)
*/
#include <stdio.h>
#include <stdlib.h>
char conv (const int fnumb, const int dig_pos)
/* fnumb - integer

6
statgen/int2char.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef INT2CHAR_H
#define INT2CHAR_H
char conv (const int, const int);
#endif /* INT2CHAR_H */

View File

@ -4,96 +4,14 @@
#include <string.h>
#include <time.h>
// prototypes
char conv (const int, const int);
int create_matrix (const int, const int, const int *, const int *, const float *,
const int, const float *, int *);
int message (const int, const int, const char *, FILE *);
int printing_agl (const char *, const char *, const int *, const int,
const int *, const int *, const int *, const int *, int *);
int proc_matrix (const int, const int *, int *, int *, int *, int *);
int reading_coords (const char *, const int, const int *, const float *, int *,
int *, int *, int *, int *, float *);
int summary_statistic (const char *, const int, const int, const int *, const int *);
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<type_inter; i++)
fprintf (f_out, ",%i", label_atom[i]);
fprintf (f_out, "\n");
for (i=0; i<num_of_inter; i++)
{
fprintf (f_out, "INTERACTION=");
fprintf (f_out, "0-0:%4.2f,0-1:%4.2f,1-1:%4.2f,", crit[16*i+0], crit[16*i+1],
crit[16*i+5]);
fprintf (f_out, "0-2:%4.2f,1-2:%4.2f,2-2:%4.2f,", crit[16*i+2], crit[16*i+6],
crit[16*i+10]);
fprintf (f_out, "0-3:%4.2f,1-3:%4.2f,2-3:%4.2f,3-3:%4.2f\n", crit[16*i+3],
crit[16*i+7], crit[16*i+11], crit[16*i+15]);
}
fprintf (f_out, "END\n\n");
fclose (f_out);
return 0;
}
int set_defaults (float *cell, int *from, char *input, int *log, int *num_of_inter,
char *output, int *to, int *type_agl, int *type_inter, int *quiet)
{
int i;
for (i=0; i<3; i++)
cell[i] = 0.0;
*from = -1;
input[0] = '#';
*log = 0;
*num_of_inter = 0;
output[0] = '#';
*to = -1;
type_agl[0] = 0;
type_agl[1] = 0;
*type_inter = 0;
*quiet = 0;
return 0;
}
#include "add_main.h"
#include "coords.h"
#include "int2char.h"
#include "messages.h"
#include "stat_print.h"
#include "stat_select.h"
#include "stat_sort.h"
#include "summary_stat.h"
int main (int argc, char *argv[])
@ -105,9 +23,9 @@ int main (int argc, char *argv[])
char input[256], logfile[256], output[256];
float cell[3], *coords, *crit;
int *agl, *connect, from, *label_atom, *label_mol, log, num_atoms, num_mol,
*num_mol_agl, num_of_inter, *stat, *stat_all, step, to, *true_label_mol,
type_agl[2], *type_atoms, type_inter, quiet;
int *agl, *connect, from, *label_atom, *label_mol, log, max_depth, num_atoms,
num_mol, *num_mol_agl, num_of_inter, *stat, *stat_all, step, to,
*true_label_mol, *type_agl, *type_atoms, type_inter, quiet;
/* input - mask of input files
* logfile - log file name
* output - output file name
@ -122,6 +40,7 @@ int main (int argc, char *argv[])
* label_atom - types of atom for interaction
* label_mol - massive of numbers of molecule for atoms
* log - status of log-mode
* max_depth - max depth for check cycles in graph analyze
* num_atoms - number of atoms for writing coordinates
* num_mol - number of molecules for writing coordinates
* num_mol_agl - massive of numbers of molecule in aglomerates
@ -137,7 +56,7 @@ int main (int argc, char *argv[])
* quiet - status of quiet-mode
*/
set_defaults (cell, &from, input, &log, &num_of_inter, output, &to, type_agl,
set_defaults (cell, &from, input, &log, &max_depth, &num_of_inter, output, &to,
&type_inter, &quiet);
// reading number of interactions
@ -151,7 +70,7 @@ int main (int argc, char *argv[])
crit[i] = 0.0;
num_of_inter = 0;
}
// reading arguments
for (i=1; i<argc; i++)
{
@ -163,7 +82,7 @@ int main (int argc, char *argv[])
sprintf (tmp_str, "%s Evgeniy Alekseev aka arcanis\n", tmp_str);
sprintf (tmp_str, "%s E-mail : esalexeev@gmail.com\n\n", tmp_str);
sprintf (tmp_str, "%sUsage:\n", tmp_str);
sprintf (tmp_str, "%sstatgen -i INPUT -s FIRST,LAST -c X,Y,Z -a ... -r ... -o OUTPUT [ -l LOGFILE ] [ -q ] [ -h ]\n\n", tmp_str);
sprintf (tmp_str, "%sstatgen -i INPUT -s FIRST,LAST -c X,Y,Z -a ... -r ... -o OUTPUT [ -g DEPTH ] [ -l LOGFILE ] [ -q ] [ -h ]\n\n", tmp_str);
sprintf (tmp_str, "%sParametrs:\n", tmp_str);
sprintf (tmp_str, "%s -i - mask of input files\n", tmp_str);
sprintf (tmp_str, "%s -s - trajectory steps (integer)\n", tmp_str);
@ -172,6 +91,7 @@ int main (int argc, char *argv[])
sprintf (tmp_str, "%s -r - criteria (float), A. Format: '0-0:2.4,0-1:3.0' means 0-0-interaction\n", tmp_str);
sprintf (tmp_str, "%s (<2.4 A) and 0-1 (<3.0) are needed. This flag can be used multiple times\n", tmp_str);
sprintf (tmp_str, "%s -o - output file name\n", tmp_str);
sprintf (tmp_str, "%s -g - check graph isomorphism. DEPTH is max depth for check cycles (>= 3)\n", tmp_str);
sprintf (tmp_str, "%s -l - log enable\n", tmp_str);
sprintf (tmp_str, "%s -q - quiet enable\n", tmp_str);
sprintf (tmp_str, "%s -h - show this help and exit\n", tmp_str);
@ -255,6 +175,12 @@ int main (int argc, char *argv[])
strcpy (output, argv[i+1]);
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'g'))
// graph isomorphism scan
{
sscanf (argv[i+1], "%i", &max_depth);
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'l'))
// log mode
{
@ -284,7 +210,8 @@ int main (int argc, char *argv[])
}
// error checking
error = error_checking (cell, from, input, num_of_inter, output, to, type_inter);
error = error_checking (cell, from, input, max_depth, num_of_inter, output, to,
type_inter);
if (error != 0)
{
sprintf (tmp_str, "Something wrong (error code: %i)!\nSee 'statgen -h' for more details\n", error);
@ -326,6 +253,7 @@ int main (int argc, char *argv[])
coords = (float *) malloc (3 * 8 * num_atoms * sizeof (float));
label_mol = (int *) malloc (8 * num_atoms * sizeof (int));
true_label_mol = (int *) malloc (8 * num_atoms * sizeof (int));
type_agl = (int *) malloc ((max_depth + 2) * sizeof (int));
type_atoms = (int *) malloc (8 * num_atoms * sizeof (int));
// temporary declaration of variables
agl = (int *) malloc (2 * 2 * sizeof (int));
@ -337,6 +265,7 @@ int main (int argc, char *argv[])
if ((coords == NULL) ||
(label_mol == NULL) ||
(true_label_mol == NULL) ||
(type_agl == NULL) ||
(type_atoms == NULL) ||
(agl == NULL) ||
(connect == NULL) ||
@ -350,6 +279,9 @@ int main (int argc, char *argv[])
fputs (tmp_str, f_log);
return 17;
}
// set type_agl to zero
for (i=0; i<max_depth+2; i++)
type_agl[i] = 0;
if (quiet != 1)
{
sprintf (tmp_str, "%6cOutput file: '%s';\n%6cLog: %i;\n%6cQuiet: %i;\n\
@ -362,13 +294,13 @@ int main (int argc, char *argv[])
for (i=0; i<num_of_inter; i++)
{
sprintf (tmp_str, "%s%6cInteraction: ", tmp_str, ' ');
sprintf (tmp_str, "%s0-0:%4.2f,0-1:%4.2f,1-1:%4.2f,", tmp_str, crit[16*i+0],
crit[16*i+1], crit[16*i+5]);
sprintf (tmp_str, "%s0-2:%4.2f,1-2:%4.2f,2-2:%4.2f,", tmp_str, crit[16*i+2],
crit[16*i+6], crit[16*i+10]);
sprintf (tmp_str, "%s0-3:%4.2f,1-3:%4.2f,2-3:%4.2f,3-3:%4.2f;\n", tmp_str,
crit[16*i+3], crit[16*i+7], crit[16*i+11], crit[16*i+15]);
for (j=0; j<16; j++)
if ((crit[16*i+j] != 0.0) &&
((j != 4) && (j != 8) && (j != 9) && (j != 12) && (j != 13) && (j != 14)))
sprintf (tmp_str, "%s%i-%i:%4.2f,", tmp_str, j/4, j%4, crit[16*i+j]);
sprintf (tmp_str, "%s;\n", tmp_str);
}
sprintf (tmp_str, "%s%6cIsomorphism check: %i\n", tmp_str, ' ', max_depth);
message (0, 5, tmp_str, stdout);
}
if (log == 1)
@ -383,19 +315,19 @@ int main (int argc, char *argv[])
for (i=0; i<num_of_inter; i++)
{
sprintf (tmp_str, "%s%34cInteraction: ", tmp_str, ' ');
sprintf (tmp_str, "%s0-0:%4.2f,0-1:%4.2f,1-1:%4.2f,", tmp_str, crit[16*i+0],
crit[16*i+1], crit[16*i+5]);
sprintf (tmp_str, "%s0-2:%4.2f,1-2:%4.2f,2-2:%4.2f,", tmp_str, crit[16*i+2],
crit[16*i+6], crit[16*i+10]);
sprintf (tmp_str, "%s0-3:%4.2f,1-3:%4.2f,2-3:%4.2f,3-3:%4.2f;\n", tmp_str,
crit[16*i+3], crit[16*i+7], crit[16*i+11], crit[16*i+15]);
for (j=0; j<16; j++)
if ((crit[16*i+j] != 0.0) &&
((j != 4) && (j != 8) && (j != 9) && (j != 12) && (j != 13) && (j != 14)))
sprintf (tmp_str, "%s%i-%i:%4.2f,", tmp_str, j/4, j%4, crit[16*i+j]);
sprintf (tmp_str, "%s;\n", tmp_str);
}
sprintf (tmp_str, "%s%34cIsomorphism check: %i\n", tmp_str, ' ', max_depth);
message (1, 5, tmp_str, f_log);
}
// head
printing_head (output, log, quiet, input, from, to, cell, type_inter, label_atom,
num_of_inter, crit);
num_of_inter, crit, max_depth);
// main cycle
if (quiet != 1)
@ -480,8 +412,8 @@ int main (int argc, char *argv[])
message (0, 11, argv[0], stdout);
if (log == 1)
message (1, 11, argv[0], f_log);
error = printing_agl (filename, output, connect, num_mol,
true_label_mol, num_mol_agl, agl, stat, type_agl);
error = printing_agl (filename, output, connect, num_mol, true_label_mol,
num_mol_agl, agl, stat, max_depth, type_agl);
if (error == 0)
{
if (quiet != 1)
@ -505,7 +437,7 @@ int main (int argc, char *argv[])
message (1, 14, output, f_log);
}
// tail
summary_statistic (output, step, num_mol, type_agl, stat_all);
summary_statistic (output, step, num_mol, max_depth, type_agl, stat_all);
if (quiet != 1)
message (0, 15, argv[0], stdout);
@ -521,6 +453,7 @@ int main (int argc, char *argv[])
free (stat);
free (stat_all);
free (true_label_mol);
free (type_agl);
free (type_atoms);
if (quiet != 1)

View File

@ -5,7 +5,6 @@
*/
#include <stdio.h>
#include <string.h>
#include <time.h>

6
statgen/messages.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef MESSAGES_H
#define MESSAGES_H
int message (const int, const int, const char *, FILE *);
#endif /* MESSAGES_H */

View File

@ -3,20 +3,18 @@
* Usage:
* printing_agl (input_file, output_file, number_of_molecules,
* true_label_molecules, num_of_molecules_in_aglomerates, aglomerates,
* statistic, type_of_aglomerate)
* statistic, max_depth, type_of_aglomerate)
*/
#include <stdio.h>
#include <stdlib.h>
// prototype
int graph_analyze (const int, const int *, const int, char *);
#include "graph.h"
int printing_agl (const char *input, const char *output, const int *connect,
const int num_mol, const int *true_label_mol, const int *num_mol_agl,
const int *agl, const int *stat, int *type_agl)
const int *agl, const int *stat, const int max_depth, int *type_agl)
/* input - name of file with coordinates
* output - name of output file
* connect - connectivity graph for all molecules
@ -25,11 +23,11 @@ int printing_agl (const char *input, const char *output, const int *connect,
* num_mol_agl - massive of numbers of molecule in aglomerates
* agl - massive of aglomerates
* stat - massive of statistics
* max_depth - max depth for check cycles in graph analyze
* type_agl - massive of numbers of aglomerate types
*/
{
char iso[256];
int i, j, k, *label_matrix, *matrix;
int i, *iso, j, k, *label_matrix, *matrix;
FILE *f_out;
/* iso - isomorphic graph in database
* label_matrix - massive of indexes of molecule
@ -37,6 +35,7 @@ int printing_agl (const char *input, const char *output, const int *connect,
* f_out - output file
*/
iso = (int *) malloc (max_depth * sizeof (int));
f_out = fopen (output, "a");
// head
@ -71,10 +70,36 @@ int printing_agl (const char *input, const char *output, const int *connect,
}
// graph topology analyze
graph_analyze (num_mol_agl[i], matrix, 3, iso);
if (max_depth > 0)
graph_analyze (num_mol_agl[i], matrix, max_depth, iso);
// printing class of aglomerate
fprintf (f_out, "AGL=%i=%s\n", num_mol_agl[i], iso);
fprintf (f_out, "AGL=%i=", num_mol_agl[i]);
for (j=0; j<max_depth; j++)
{
// number of tails
if (j == 0)
if (iso[j] > 2)
// branched
type_agl[3]++;
else
// not branched
type_agl[2]++;
// number of cycles
else if (j == 1)
if (iso[j] > 0)
// cycle
type_agl[1]++;
else
// linear
type_agl[0]++;
else if (j > 1)
// number of n_cycles
type_agl[j+2] += iso[j];
fprintf (f_out, "%i.", iso[j]);
}
fprintf (f_out, "\n");
for (j=0; j<num_mol_agl[i]; j++)
{
fprintf (f_out, "%7i=", true_label_mol[agl[num_mol*i+j]]);
@ -93,5 +118,6 @@ int printing_agl (const char *input, const char *output, const int *connect,
fprintf (f_out, "---------------------------------------------------\n");
fclose (f_out);
free (iso);
return 0;
}

7
statgen/stat_print.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef STAT_PRINT_H
#define STAT_PRINT_H
int printing_agl (const char *, const char *, const int *, const int, const int *,
const int *, const int *, const int *, const int,int *);
#endif /* STAT_PRINT_H */

View File

@ -6,7 +6,6 @@
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

7
statgen/stat_select.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef STAT_SELECT_H
#define STAT_SELECT_H
int create_matrix (const int, const int, const int *, const int *, const float *,
const int, const float *, int *);
#endif /* STAT_SELECT_H */

View File

@ -5,7 +5,6 @@
* num_of_molecules_in_aglomerates, aglomerates, statistic, summary_statistic)
*/
#include <stdio.h>
#include <stdlib.h>

6
statgen/stat_sort.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef STAT_SORT_H
#define STAT_SORT_H
int proc_matrix (const int, const int *, int *, int *, int *, int *);
#endif /* STAT_SORT_H */

Binary file not shown.

View File

@ -1,18 +1,18 @@
/* Library for summary statistic
* Usage:
* summary_statistic (filename, number_of_step, number_of_molecules,
* type_of_aglomerate, summary_statistic)
* max_depth, type_of_aglomerate, summary_statistic)
*/
#include <stdio.h>
#include <stdlib.h>
int summary_statistic (const char *filename, const int step, const int num_mol,
const int *type_agl, const int *stat_all)
const int max_depth, const int *type_agl, const int *stat_all)
/* filename - name of output file
* step - number of steps
* num_mol - number of molecules
* max_depth - max depth for check cycles in graph analyze
* type_agl - massive of numbers of aglomerate types
* stat_all - massive of summary statistics
*/
@ -52,12 +52,29 @@ int summary_statistic (const char *filename, const int step, const int num_mol,
fprintf (f_out, " %7i %7i %9.2f %9.5f %10.5f\n", i+1, stat_all[i], conc, p, pn);
}
if (max_depth > 0)
{
// types of aglomerates
x = type_agl[0] + type_agl[1];
type[0] = type_agl[0];
type[1] = type_agl[1];
fprintf (f_out, "------------------------------------------------\n");
fprintf (f_out, "LINEAR=%.5f\nCYCLE=%.5f\n", type[0]/x, type[1]/x);
fprintf (f_out, "------------------------------------------------\n");
// linear and cycle
x = type_agl[0] + type_agl[1];
type[0] = type_agl[0];
type[1] = type_agl[1];
fprintf (f_out, "LINEAR=%7.5f\nCYCLE=%7.5f\n--------------------\n", type[0]/x, type[1]/x);
// branched
type[0] = type_agl[2];
type[1] = type_agl[3];
fprintf (f_out, "NOT BRANCHED=%7.5f\nBRANCHED=%7.5f\n--------------------\n", type[0]/x, type[1]/x);
// n_cycle
x = 0;
for (i=4; i<max_depth+2; i++)
x += type_agl[i];
for (i=4; i<max_depth+2; i++)
{
type[0] = type_agl[i];
fprintf (f_out, "CYCLE_'%2i'=%7.5f\n", i-1, type[0]/x);
}
}
fclose (f_out);

7
statgen/summary_stat.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef SUMMARY_STAT_H
#define SUMMARY_STAT_H
int summary_statistic (const char *, const int, const int, const int, const int *,
const int *);
#endif /* SUMMARY_STAT_H */