refactoring

This commit is contained in:
arcan1s
2013-07-22 15:42:42 +04:00
parent 51d31d0a2f
commit 694751ce09
46 changed files with 1140 additions and 225760 deletions

View File

@ -0,0 +1,61 @@
set ("${PROJECT}_VERSION_MAJOR" 1)
set ("${PROJECT}_VERSION_MINOR" 0)
set ("${PROJECT}_VERSION_PATCH" 1)
set ("${PROJECT}_VERSION" ${${PROJECT}_VERSION_MAJOR}.${${PROJECT}_VERSION_MINOR}.${${PROJECT}_VERSION_PATCH})
message (STATUS ${${PROJECT}_VERSION})
## set files
# main files
set (MAIN_SOURCES main)
# not public srcs
set (PRIVATE_CLASSES)
# headers only files
SET (HEADERS_ONLY)
# public srcs
set (PUBLIC_CLASSES add_main
coords
graph
int2char
messages
stat_print
stat_select
stat_sort
summary_stat)
# public headers
set (PUBLIC_HEADERS)
# shared libraries
if (CMAKE_COMPILER_IS_GNUCXX)
set (ADDITIONAL_LIB m)
else ()
set (ADDITIONAL_LIB)
endif()
set (SOURCES)
# append list
foreach (class ${PRIVATE_CLASSES})
LIST (APPEND SOURCES ${class}.c)
LIST (APPEND HEADERS ${class}.h)
endforeach ()
foreach (class ${HEADERS_ONLY})
LIST (APPEND HEADERS ${class}.h)
endforeach ()
foreach (class ${PUBLIC_CLASSES})
LIST (APPEND SOURCES ${class}.c)
LIST (APPEND HEADERS ../include/${PROJECT}/${class}.h)
LIST (APPEND PUBLIC_HEADERS ../include/${PROJECT}/${class}.h)
endforeach ()
# link libraries and compile
add_executable (${PROJECT} ${MAIN_SOURCES} ${SOURCES})
target_link_libraries (${PROJECT} ${ADDITIONAL_LIB})
# install properties
INSTALL (TARGETS ${PROJECT}
DESTINATION bin)
if (ADD_INCLUDE)
INSTALL (FILES ${PUBLIC_HEADERS}
DESTINATION include/${PROJECT})
endif ()

85
statgen/src/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;
}

282
statgen/src/coords.c Normal file
View File

@ -0,0 +1,282 @@
/* Library for reading coordinates from input file
*
* Usage:
* reading_coords (filename, type_interaction, labels, cell,
* &number_of_molecules, &number_of_atoms, true_label_molecule, label_molecule,
* type_atoms, coords)
*/
#include <stdio.h>
#include <stdlib.h>
int reading_coords (const char *filename, const int type_inter,
const int *label_atom, const float *cell, int *num_mol,
int *num_atoms, int *true_label_mol, int *label_mol,
int *type_atoms, float *coords)
/* filename - name of file with coordinates
* type_inter - type interaction (number of molecules for interaction)
* label_atom - types of atom for interaction
* cell - cell dimension
* num_mol - number of molecules for writing coordinates
* num_atoms - number of atoms for writing coordinates
* true_label_mol - massive of true numbers of molecule for atoms
* label_mol - massive of numbers of molecule for atoms
* type_atoms - massive of atom types for atoms
* coords - massive of coordinates
*/
{
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;
/* 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
* not_tr_coords - not translated coordinates
* ref - coordinates of reference molecule
* inp - file with input data
*/
*num_atoms = 0;
*num_mol = 0;
// Reading file
inp = fopen (filename, "r");
if (inp == NULL)
return 1;
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 (cur_at_type == label_atom[j])
{
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 != cur_mol)
{
ref_mol = cur_mol;
true_label_mol[*num_mol] = ref_mol;
*num_mol = *num_mol + 1;
}
label_mol[*num_atoms] = *num_mol - 1;
type_atoms[*num_atoms] = j;
*num_atoms = *num_atoms + 1;
}
}
fclose (inp);
// Translation
tr_num_atoms = *num_atoms;
for (i=0; i<*num_atoms; i++)
for (j=0; j<3; j++)
coords[3*i+j] = not_tr_coords[3*i+j];
// Assign initial value to reference coordinates
ref_mol = label_mol[0];
for (i=0; i<3; i++)
ref[i] = coords[i];
for (i=0; i<*num_atoms; i++)
{
if (label_mol[i] != ref_mol)
{
ref_mol = label_mol[i];
for (j=0; j<3; j++)
ref[j] = not_tr_coords[3*i+j];
}
for (x=0; x<3; x++)
{
if (ref[x] >= 0.0)
// if xyz >= 0.0 A
{
for (j=0; j<3; j++)
if (j == x)
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j] - cell[j];
else
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
else
// if xyz < 0.0 A
{
for (j=0; j<3; j++)
if (j == x)
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j] + cell[j];
else
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
}
for (x=0; x<3; x++)
{
for (y=x+1; y<3; y++)
{
if ((ref[x] >= 0.0) && (ref[y] >= 0.0))
// if xyz and xyz >= 0.0 A
{
for (j=0; j<3; j++)
if ((j == x) || (j == y))
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j] - cell[j];
else
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
if ((ref[x] < 0.0) && (ref[y] < 0.0))
// if xyz and xyz < 0.0 A
{
for (j=0; j<3; j++)
if ((j == x) || (j == y))
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j] + cell[j];
else
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
}
for (y=0; y<3; y++)
if ((ref[x] < 0.0) && (ref[y] >= 0.0))
// if xyz OR xyz >= 0.0
{
for (j=0; j<3; j++)
{
if (j == x)
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j] + cell[j];
if (j == y)
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j] - cell[j];
if ((j != x) && (j != y))
coords[3*tr_num_atoms+j] = not_tr_coords[3*i+j];
}
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
}
if ((ref[0] >= 0.0) && (ref[1] >= 0.0) && (ref[2] >= 0.0))
// if x and y and z >= 0.0 A
{
coords[3*tr_num_atoms+0] = not_tr_coords[3*i+0] - cell[0];
coords[3*tr_num_atoms+1] = not_tr_coords[3*i+1] - cell[1];
coords[3*tr_num_atoms+2] = not_tr_coords[3*i+2] - cell[2];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
if ((ref[0] >= 0.0) && (ref[1] >= 0.0) && (ref[2] < 0.0))
// if x and y >= 0.0 A and z < 0.0 A
{
coords[3*tr_num_atoms+0] = not_tr_coords[3*i+0] - cell[0];
coords[3*tr_num_atoms+1] = not_tr_coords[3*i+1] - cell[1];
coords[3*tr_num_atoms+2] = not_tr_coords[3*i+2] + cell[2];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
if ((ref[0] >= 0.0) && (ref[1] < 0.0) && (ref[2] >= 0.0))
// if x and z >= 0.0 A and y < 0.0 A
{
coords[3*tr_num_atoms+0] = not_tr_coords[3*i+0] - cell[0];
coords[3*tr_num_atoms+1] = not_tr_coords[3*i+1] + cell[1];
coords[3*tr_num_atoms+2] = not_tr_coords[3*i+2] - cell[2];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
if ((ref[0] < 0.0) && (ref[1] >= 0.0) && (ref[2] >= 0.0))
// if y and z >= 0.0 A and x < 0.0 A
{
coords[3*tr_num_atoms+0] = not_tr_coords[3*i+0] + cell[0];
coords[3*tr_num_atoms+1] = not_tr_coords[3*i+1] - cell[1];
coords[3*tr_num_atoms+2] = not_tr_coords[3*i+2] - cell[2];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
if ((ref[0] < 0.0) && (ref[1] < 0.0) && (ref[2] >= 0.0))
// if x and y < 0.0 A and z >= 0.0 A
{
coords[3*tr_num_atoms+0] = not_tr_coords[3*i+0] + cell[0];
coords[3*tr_num_atoms+1] = not_tr_coords[3*i+1] + cell[1];
coords[3*tr_num_atoms+2] = not_tr_coords[3*i+2] - cell[2];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
if ((ref[0] < 0.0) && (ref[1] >= 0.0) && (ref[2] < 0.0))
// if x and z < 0.0 A and y >= 0.0 A
{
coords[3*tr_num_atoms+0] = not_tr_coords[3*i+0] + cell[0];
coords[3*tr_num_atoms+1] = not_tr_coords[3*i+1] - cell[1];
coords[3*tr_num_atoms+2] = not_tr_coords[3*i+2] + cell[2];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
if ((ref[0] >= 0.0) && (ref[1] < 0.0) && (ref[2] < 0.0))
// if x >= 0.0 A and y and z < 0.0 A
{
coords[3*tr_num_atoms+0] = not_tr_coords[3*i+0] - cell[0];
coords[3*tr_num_atoms+1] = not_tr_coords[3*i+1] + cell[1];
coords[3*tr_num_atoms+2] = not_tr_coords[3*i+2] + cell[2];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
if ((ref[0] < 0.0) && (ref[1] < 0.0) && (ref[2] < 0.0))
// if x and y and z < 0.0 A
{
coords[3*tr_num_atoms+0] = not_tr_coords[3*i+0] + cell[0];
coords[3*tr_num_atoms+1] = not_tr_coords[3*i+1] + cell[1];
coords[3*tr_num_atoms+2] = not_tr_coords[3*i+2] + cell[2];
label_mol[tr_num_atoms] = label_mol[i];
type_atoms[tr_num_atoms] = type_atoms[i];
tr_num_atoms++;
}
}
return 0;
}

133
statgen/src/graph.c Normal file
View File

@ -0,0 +1,133 @@
/* Library for graph structure analyze
* Usage:
* graph_analyze (N, connect, max_depth, isomorphism_class)
*/
#include <math.h>
#include <stdlib.h>
int check_cycle (const int N, const int *pn)
// function to return number of cycles
{
int cycle, i;
/* cycle - number of cycle
*/
cycle = 0;
for (i=1; i<N; i++)
cycle += i*pn[i];
// for linear (0.5*cycle == N-1)
cycle = 0.5 * cycle - (N - 1);
return cycle;
}
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, p, *vertex;
/* cur_N - current number of elements in submatrix
* cycle - if (cycle == 1) that cycle exist
* n - number of samples
* vertex - vertexes of subgraph
*/
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
n = pow (2, N);
for (i=0; i<n; i++)
{
cur_N = 0;
for (j=0; j<N; j++)
if ( i & (1 << j))
{
vertex[cur_N] = j;
cur_N++;
}
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++)
p += matrix[vertex[j]*N+vertex[k]];
if (p != 2)
cycle = 0;
}
// analyze subgraph
if (cycle == 1)
n_cycle[cur_N-3]++;
}
}
free (vertex);
return 0;
}
int check_tail (const int *pn)
// function to return number of tails
{
return pn[1];
}
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 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;
// 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]++;
}
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++)
iso[i+2] = n_cycle[i];
}
free (n_cycle);
free (pn);
return 1;
}

23
statgen/src/int2char.c Normal file
View File

@ -0,0 +1,23 @@
/* Library for converting integer to string
* Usage
* char = conv (number, position)
*/
char conv (const int fnumb, const 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];
}

467
statgen/src/main.c Normal file
View File

@ -0,0 +1,467 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// #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[])
{
char filename[256], tmp_str[2048];
int error, i, index, j, k, label[2];
float label_fl;
FILE *f_inp, *f_log;
char input[256], logfile[256], output[256];
float cell[3], *coords, *crit;
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
*
* cell - cell dimension
* coords - massive of coordinates
* crit - massive of criteria
*
* agl - massive of aglomerates
* connect - connectivity graph for all molecules
* from - start point
* 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
* num_of_inter - number of different interactions
* stat - massive of statistics
* stat_all - massive of summary statistics
* step - $(to - from + 1)
* to - finish point
* true_label_mol - massive of true numbers of molecule for atoms
* type_agl - massive of numbers of aglomerate types
* type_atoms - massive of atom types for atoms
* type_inter - type interaction (number of molecules for interaction)
* quiet - status of quiet-mode
*/
set_defaults (cell, &from, input, &log, &max_depth, &num_of_inter, output, &to,
&type_inter, &quiet);
// reading number of interactions
for (i=1; i<argc; i++)
if ((argv[i][0] == '-') && (argv[i][1] == 'r'))
num_of_inter++;
if (num_of_inter > 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<argc; i++)
{
if ((argv[i][0] == '-') && (argv[i][1] == 'h'))
{
sprintf (tmp_str, " statgen\n");
sprintf (tmp_str, "%sProgram for analyze molecular dynamic trajectories\n", tmp_str);
sprintf (tmp_str, "%sVersion : 1.0.0 License : GPL\n", tmp_str);
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 [ -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);
sprintf (tmp_str, "%s -c - cell size (float), A\n", tmp_str);
sprintf (tmp_str, "%s -a - atom types (integer). Format: 'ATOM1' or 'ATOM1,ATOM2' or etc\n", tmp_str);
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);
fputs (tmp_str, stdout);
return 0;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'i'))
// mask of input files
{
strcpy (input, argv[i+1]);
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 's'))
// steps
{
sscanf (argv[i+1], "%i,%i", &from, &to);
if (from > 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<strlen(argv[i+1]); j++)
if (argv[i+1][j] == ',')
type_inter++;
label_atom = (int *) malloc (type_inter * sizeof (int));
switch (type_inter)
{
case 1:
sscanf (argv[i+1], "%i", &label_atom[0]);
break;
case 2:
sscanf (argv[i+1], "%i,%i", &label_atom[0], &label_atom[1]);
break;
case 3:
sscanf (argv[i+1], "%i,%i,%i", &label_atom[0], &label_atom[1], &label_atom[2]);
break;
case 4:
sscanf (argv[i+1], "%i,%i,%i,%i", &label_atom[0], &label_atom[1], &label_atom[2], &label_atom[3]);
break;
}
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'r'))
// criteria
{
index = 0;
sscanf (&argv[i+1][index], "%i-%i:%f%s", &label[0], &label[1], &label_fl, tmp_str);
crit[16*num_of_inter+4*label[0]+label[1]] = label_fl;
crit[16*num_of_inter+4*label[1]+label[0]] = label_fl;
for (j=index; j<strlen(argv[i+1]); j++)
if (argv[i+1][j] == ',')
{
index = j+1;
sscanf (&argv[i+1][index], "%i-%i:%f%s", &label[0], &label[1], &label_fl, tmp_str);
crit[16*num_of_inter+4*label[0]+label[1]] = label_fl;
crit[16*num_of_inter+4*label[1]+label[0]] = label_fl;
}
num_of_inter++;
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'o'))
// output file
{
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
{
log = 1;
strcpy (logfile, argv[i+1]);
i++;
}
else if ((argv[i][0] == '-') && (argv[i][1] == 'q'))
// quiet mode
{
quiet = 1;
}
}
if (log == 1)
f_log = fopen (logfile, "w");
if (quiet != 1)
{
message (0, 0, argv[0], stdout);
message (0, 1, argv[0], stdout);
}
if (log == 1)
{
message (1, 0, argv[0], f_log);
message (1, 1, argv[0], f_log);
}
// error checking
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);
fputs (tmp_str, stderr);
if (log == 1)
fputs (tmp_str, f_log);
return 1;
}
if (quiet != 1)
message (0, 2, argv[0], stdout);
if (log == 1)
message (1, 2, argv[0], f_log);
// 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';
if (quiet != 1)
message (0, 3, filename, stdout);
if (log == 1)
message (1, 3, filename, f_log);
f_inp = fopen (filename, "r");
if (f_inp == NULL)
{
sprintf (tmp_str, "\nFile '%s' not found\nError", filename);
fputs (tmp_str, stderr);
if (log == 1)
fputs (tmp_str, f_log);
return 1;
}
fscanf (f_inp, "%i", &num_atoms);
fclose (f_inp);
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));
connect = (int *) malloc (2 * 2 * sizeof (int));
num_mol_agl = (int *) malloc (2 * sizeof (int));
stat = (int *) malloc (2 * sizeof (int));
stat_all = (int *) malloc (2 * sizeof (int));
// error checking
if ((coords == NULL) ||
(label_mol == NULL) ||
(true_label_mol == NULL) ||
(type_agl == NULL) ||
(type_atoms == NULL) ||
(agl == NULL) ||
(connect == NULL) ||
(num_mol_agl == NULL) ||
(stat == NULL) ||
(stat_all == NULL))
{
sprintf (tmp_str, "\nMemory error (error code: 17)\n");
fputs (tmp_str, stderr);
if (log == 1)
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\
%6cMask: %s;\n%6cFirst step: %i;\n%6cLast step: %i;\n%6cCell size: %.4f, %.4f, %.4f;\n\
%6cSelect atoms: %i", ' ', output, ' ', log, ' ', quiet, ' ', input, ' ', from,
' ' , to, ' ', cell[0], cell[1], cell[2], ' ' , label_atom[0]);
for (i=1; i<type_inter; i++)
sprintf (tmp_str, "%s,%i", tmp_str, label_atom[i]);
sprintf (tmp_str, "%s;\n", tmp_str);
for (i=0; i<num_of_inter; i++)
{
sprintf (tmp_str, "%s%6cInteraction: ", tmp_str, ' ');
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)
{
sprintf (tmp_str, "%34cOutput file: '%s';\n%34cLog: %i;\n%34cQuiet: %i;\n\
%34cMask: %s;\n%34cFirst step: %i;\n%34cLast step: %i;\n%34cCell size: %.4f, %.4f, %.4f;\n\
%34cSelect atoms: %i", ' ', output, ' ', log, ' ', quiet, ' ', input, ' ', from,
' ' , to, ' ', cell[0], cell[1], cell[2], ' ' , label_atom[0]);
for (i=1; i<type_inter; i++)
sprintf (tmp_str, "%s,%i", tmp_str, label_atom[i]);
sprintf (tmp_str, "%s;\n", tmp_str);
for (i=0; i<num_of_inter; i++)
{
sprintf (tmp_str, "%s%34cInteraction: ", tmp_str, ' ');
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, max_depth);
// main cycle
if (quiet != 1)
message (0, 6, argv[0], stdout);
if (log == 1)
message (1, 6, argv[0], f_log);
for (i=from; i<to+1; i++)
{
// reading coordinates
filename[k+1] = conv (i, 3);
filename[k+2] = conv (i, 2);
filename[k+3] = conv (i, 1);
filename[k+4] = '\0';
if (quiet != 1)
message (0, 7, filename, stdout);
if (log == 1)
message (1, 7, filename, f_log);
error = reading_coords (filename, type_inter, label_atom, cell, &num_mol,
&num_atoms, true_label_mol, label_mol, type_atoms, coords);
if (error != 1)
{
if (quiet != 1)
{
sprintf (tmp_str, "%6cNumber of molecules: %i\n%6cNumber of atoms: %i\n",
' ', num_mol, ' ', num_atoms);
message (0, 8, tmp_str, stdout);
}
if (log == 1)
{
sprintf (tmp_str, "%6cNumber of molecules: %i\n%34cNumber of atoms: %i\n",
' ', num_mol, ' ', num_atoms);
message (1, 8, tmp_str, f_log);
}
}
// resize dynamic arrays
agl = (int *) realloc (agl, num_mol * num_mol * sizeof (int));
connect = (int *) realloc (connect, num_mol * num_mol * sizeof (int));
num_mol_agl = (int *) realloc (num_mol_agl, num_mol * sizeof (int));
stat = (int *) realloc (stat, num_mol * sizeof (int));
if (i == from)
{
stat_all = (int *) realloc (stat_all, num_mol * sizeof (int));
for (j=0; j<num_mol; j++)
stat_all[j] = 0;
}
// error checking
if ((agl == NULL) ||
(connect == NULL) ||
(num_mol_agl == NULL) ||
(stat == NULL) ||
(stat_all == NULL))
{
sprintf (tmp_str, "\nMemory error (error code: 18)\n");
fputs (tmp_str, stderr);
if (log == 1)
fputs (tmp_str, f_log);
return 18;
}
if (quiet != 1)
message (0, 9, argv[0], stdout);
if (log == 1)
message (1, 9, argv[0], f_log);
// analyze
if (error == 0)
{
error = 1;
error = create_matrix (num_mol, num_atoms, label_mol, type_atoms, coords,
num_of_inter, crit, connect);
if (error == 0)
{
if (quiet != 1)
message (0, 10, argv[0], stdout);
if (log == 1)
message (1, 10, argv[0], f_log);
error = 1;
error = proc_matrix (num_mol, connect, num_mol_agl, agl, stat, stat_all);
if (error == 0)
{
if (quiet != 1)
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, max_depth, type_agl);
if (error == 0)
{
if (quiet != 1)
message (0, 12, output, stdout);
if (log == 1)
message (1, 12, output, f_log);
}
}
}
}
}
if (quiet != 1)
{
message (0, 13, argv[0], stdout);
message (0, 14, output, stdout);
}
if (log == 1)
{
message (1, 13, argv[0], f_log);
message (1, 14, output, f_log);
}
// tail
summary_statistic (output, step, num_mol, max_depth, type_agl, stat_all);
if (quiet != 1)
message (0, 15, argv[0], stdout);
if (log == 1)
message (1, 15, argv[0], f_log);
// free memory
free (agl);
free (connect);
free (coords);
free (crit);
free (label_mol);
free (num_mol_agl);
free (stat);
free (stat_all);
free (true_label_mol);
free (type_agl);
free (type_atoms);
if (quiet != 1)
message (0, 16, argv[0], stdout);
if (log == 1)
message (1, 16, argv[0], f_log);
if (log == 1)
fclose (f_log);
return 0;
}

84
statgen/src/messages.c Normal file
View File

@ -0,0 +1,84 @@
/* Library for printing messages at stdout
*
* Usage:
* message (log, mode, text, stdout)
*/
#include <stdio.h>
#include <time.h>
int message (const int log, const int mode, const char *text, FILE *stdout)
/* mode - number of message
* text - additional text
*/
{
char out[4096];
if (log == 1)
{
char time_str[256];
time_t t = time(NULL);
struct tm* aTm = localtime(&t);
sprintf(time_str, "[%04d-%02d-%02d %02d:%02d:%02d] [%2i]: ", aTm->tm_year+1900,
aTm->tm_mon+1, aTm->tm_mday, aTm->tm_hour, aTm->tm_min, aTm->tm_sec, mode);
fputs (time_str, stdout);
}
switch (mode)
{
case 0:
sprintf (out, "Starting program: '%s' (Ver.1.0.0)\n", text);
break;
case 1:
sprintf (out, "Checking errors\n");
break;
case 2:
sprintf (out, "Errors are not detected\n");
break;
case 3:
sprintf (out, "Initialization of variables from file '%s'\n", text);
break;
case 4:
break;
case 5:
sprintf (out, "Initial parametrs: \n%s", text);
break;
case 6:
sprintf (out, "Processing\n");
break;
case 7:
sprintf (out, "Open file: '%s'\n", text);
break;
case 8:
sprintf (out, "%s", text);
break;
case 9:
sprintf (out, "%6cSize of variables was changed successfully\n", ' ');
break;
case 10:
sprintf (out, "%6cConnectivity matrix was created successfully\n", ' ');
break;
case 11:
sprintf (out, "%6cConnectivity matrix was processed successfully\n", ' ');
break;
case 12:
sprintf (out, "%6cResult was printed to file '%s' successfully\n", ' ', text);
break;
case 13:
sprintf (out, "End of processing\n");
break;
case 14:
sprintf (out, "Printing summary statistic to file '%s'\n", text);
break;
case 15:
sprintf (out, "Free memory\n");
break;
case 16:
sprintf (out, "Exiting without errors\n");
break;
}
fputs (out, stdout);
return 0;
}

123
statgen/src/stat_print.c Normal file
View File

@ -0,0 +1,123 @@
/* Library for printing aglomerates
*
* Usage:
* printing_agl (input_file, output_file, number_of_molecules,
* true_label_molecules, num_of_molecules_in_aglomerates, aglomerates,
* statistic, max_depth, type_of_aglomerate)
*/
#include <stdio.h>
#include <stdlib.h>
// #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, const int max_depth, int *type_agl)
/* input - name of file with coordinates
* output - name of output file
* connect - connectivity graph for all molecules
* num_mol - number of molecules
* true_label_mol - massive of true numbers of molecule for atoms
* 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
*/
{
int i, *iso, j, k, *label_matrix, *matrix;
FILE *f_out;
/* iso - isomorphic graph in database
* label_matrix - massive of indexes of molecule
* matrix - connectivity graph
* f_out - output file
*/
iso = (int *) malloc (max_depth * sizeof (int));
f_out = fopen (output, "a");
// head
fprintf (f_out, "FILE=%s\nSTATISTIC\n| n | N |\n-----------------\n", input);
for (i=0; i<num_mol; i++)
if (stat[i] != 0)
fprintf (f_out, " %7i %7i \n", i+1, stat[i]);
fprintf (f_out, "-----------------\n");
// body
for (i=0; i<num_mol; i++)
if (num_mol_agl[i] > 0)
{
// creating connectivity graph
matrix = (int *) malloc (num_mol_agl[i] * num_mol_agl[i] * sizeof (int));
for (j=0; j<num_mol_agl[i]; j++)
for (k=0; k<num_mol_agl[i]; k++)
matrix[num_mol_agl[i]*j+k] = 0;
label_matrix = (int *) malloc (num_mol * sizeof (int));
if ((matrix == NULL) ||
(label_matrix == NULL))
return 1;
for (j=0; j<num_mol_agl[i]; j++)
label_matrix[agl[num_mol*i+j]] = j;
for (j=0; j<num_mol_agl[i]; j++)
for (k=j+1; k<num_mol_agl[i]; k++)
if (connect[num_mol*agl[num_mol*i+j]+agl[num_mol*i+k]] == 1)
{
matrix[label_matrix[agl[num_mol*i+j]]*num_mol_agl[i]+label_matrix[agl[num_mol*i+k]]] = 1;
matrix[label_matrix[agl[num_mol*i+k]]*num_mol_agl[i]+label_matrix[agl[num_mol*i+j]]] = 1;
}
// graph topology analyze
if (max_depth > 0)
graph_analyze (num_mol_agl[i], matrix, max_depth, iso);
// printing class of aglomerate
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]]);
for (k=0; k<num_mol_agl[i]; k++)
{
if (matrix[j*num_mol_agl[i]+k] == 1)
fprintf (f_out, "%i,", true_label_mol[agl[num_mol*i+k]]);
}
fprintf (f_out, "\n");
}
// free memory
free (matrix);
free (label_matrix);
}
fprintf (f_out, "---------------------------------------------------\n");
fclose (f_out);
free (iso);
return 0;
}

105
statgen/src/stat_select.c Normal file
View File

@ -0,0 +1,105 @@
/* Library for creating connectivity matrix
*
* Usage:
* create_matrix (number_of_molecules, number_of_atoms, label_molecule,
* type_atoms, coords, number_of_interactions, criteria, connect_matrix)
*/
#include <math.h>
#include <stdlib.h>
int create_matrix (const int num_mol, const int num_atoms, const int *label_mol,
const int *type_atoms, const float *coords, const int num_of_inter,
const float *crit, int *connect)
/* num_mol - number of molecules
* num_atoms - number of atoms
* label_mol - massive of numbers of molecule for atoms
* type_atoms - massive of atom types for atoms
* coords - massive of coordinates
* num_of_inter - number of different interactions
* crit - massive of criteria
* connect - connectivity graph for all molecules
*/
{
float r;
int cur_num_inter, i, j, k, l, num_inter, ***label_inter;
/* r - radius
* cur_num_inter - current number of true interactions
* num_inter - needed number of true interactions
* label_inter - temporary massive of true interactions
*/
label_inter = (int ***) malloc (num_mol * sizeof (int **));
for (i=0; i<num_mol; i++)
{
label_inter[i] = (int **) malloc (num_mol * sizeof (int *));
for (j=0; j<num_mol; j++)
{
label_inter[i][j] = (int *) malloc (16 * sizeof (int));
for (k=0; k<16; k++)
label_inter[i][j][k] = 0;
}
}
if (label_inter == NULL)
return 1;
// creating initial connectivity matrix
for (i=0; i<num_atoms*8; i++)
for (j=i+1; j<num_atoms*8; j++)
// if atoms from different molecules
if (label_mol[i] != label_mol[j])
{
r = sqrt (pow ((coords[3*i+0]-coords[3*j+0]), 2) +
pow ((coords[3*i+1]-coords[3*j+1]), 2) +
pow ((coords[3*i+2]-coords[3*j+2]), 2));
for (k=0; k<num_of_inter; k++)
if (crit[16*k+4*type_atoms[i]+type_atoms[j]] != 0.0)
if (r < crit[16*k+4*type_atoms[i]+type_atoms[j]])
{
label_inter[label_mol[i]][label_mol[j]][4*type_atoms[i]+type_atoms[j]] = 1;
label_inter[label_mol[i]][label_mol[j]][4*type_atoms[j]+type_atoms[i]] = 1;
label_inter[label_mol[j]][label_mol[i]][4*type_atoms[i]+type_atoms[j]] = 1;
label_inter[label_mol[j]][label_mol[i]][4*type_atoms[j]+type_atoms[i]] = 1;
}
}
for (i=0; i<num_mol; i++)
for (j=0; j<num_mol; j++)
connect[i*num_mol+j] = 0;
// processing of initial connectivity matrix
for (k=0; k<num_of_inter; k++)
{
// determination of the number of interactions
num_inter = 0;
for (l=0; l<16; l++)
if (crit[16*k+l] != 0.0)
num_inter++;
for (i=0; i<num_mol; i++)
for (j=i+1; j<num_mol; j++)
{
cur_num_inter = 0;
for (l=0; l<16; l++)
cur_num_inter += label_inter[i][j][l];
if (cur_num_inter == num_inter)
{
connect[i*num_mol+j] = 1;
connect[j*num_mol+i] = 1;
}
}
}
// free memory
for (i=0; i<num_mol; i++)
{
for (j=0; j<num_mol; j++)
free (label_inter[i][j]);
free (label_inter[i]);
}
free (label_inter);
return 0;
}

86
statgen/src/stat_sort.c Normal file
View File

@ -0,0 +1,86 @@
/* Library for processing connectivity matrix
*
* Usage:
* proc_matrix (number_of_molecules, connect_matrix,
* num_of_molecules_in_aglomerates, aglomerates, statistic, summary_statistic)
*/
#include <stdlib.h>
int proc_matrix (const int num_mol, const int *connect, int *num_mol_agl, int *agl,
int *stat, int *stat_all)
/* num_mol - number of molecules
* connect - connectivity graph for all molecules
* num_mol_agl - massive of numbers of molecule in aglomerates
* agl - massive of aglomerates
* stat - massive of statistics
* stat_all - massive of summary statistics
*/
{
int i, j, k, p, *bin;
/* p - weight / graph index
* bin - binary massive of labels
*/
// definition and zeroing
bin = (int *) malloc (num_mol * sizeof (int));
if (bin == NULL)
return 1;
for (i=0; i<num_mol; i++)
{
bin[i] = 1;
stat[i] = 0;
num_mol_agl[i] = 0;
for (j=0; j<num_mol; j++)
agl[num_mol*i+j] = 0;
}
// select non-bonded molecules
for (i=0; i<num_mol; i++)
{
p = 0;
for (j=0; j<num_mol; j++)
p += connect[i*num_mol+j];
if (p == 0)
{
bin[i] = 0;
stat[0]++;
stat_all[0]++;
}
}
// unwraping of connectivity matrix
p = 0;
for (i=0; i<num_mol; i++)
if (bin[i] == 1)
{
agl[num_mol*p+num_mol_agl[p]] = i;
num_mol_agl[p]++;
bin[i] = 0;
for (j=0; j<num_mol_agl[p]; j++)
for (k=0; k<num_mol; k++)
if ((connect[agl[num_mol*p+j]*num_mol+k] == 1) && (bin[k] == 1))
{
agl[num_mol*p+num_mol_agl[p]] = k;
num_mol_agl[p]++;
bin[k] = 0;
}
p++;
}
// filling statistic array
i = 0;
while (num_mol_agl[i] > 0)
{
stat[num_mol_agl[i]-1]++;
stat_all[num_mol_agl[i]-1]++;
i++;
}
free (bin);
return 0;
}

View File

@ -0,0 +1,82 @@
/* Library for summary statistic
* Usage:
* summary_statistic (filename, number_of_step, number_of_molecules,
* max_depth, type_of_aglomerate, summary_statistic)
*/
#include <stdio.h>
int summary_statistic (const char *filename, const int step, const int num_mol,
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
*/
{
float conc, p, pn, type[2], x, y;
int i, index;
FILE *f_out;
/* conc - concentrate of aglomerates
* p - probability of aglomerates
* pn - weight probability of aglomerates
* f_out - output file
*/
index = 0;
for (i=0; i<num_mol; i++)
if (stat_all[i] != 0)
index = i;
// head
f_out = fopen (filename, "a");
fprintf (f_out, "SUMMARY STATISTIC\n");
fprintf (f_out, "| n | N | C | p | pn |\n------------------------------------------------\n");
for (i=0; i<index+1; i++)
{
// calculating concentrates
x = stat_all[i];
y = step;
conc = x / y;
// calculating probabilityes
x = (i + 1) * stat_all[i];
y = step * num_mol;
p = x / y;
pn = (i + 1) * p;
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
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);
return 0;
}