📄 codemodify2.c
字号:
/* codemodify.c (c) DJCM 95 Sep codemodify file old version of executable stored on neuron: wol/code/codemodify.old codemodify2 also checks for overlaps of 2 or greater - also known as four-cycles. Here called "overlaps" still has all the same behaviour as codemodify*/#include "./ansi/r.h"#include "./ansi/rand2.h"#include "./ansi/mynr.h"#include "./ansi/cmatrix.h"typedef struct { /* codemod_control */#include "codemod_var_str.h"} codemod_control ;static void print_usage ( char ** , FILE * , codemod_control * ) ;static void c_defaults ( codemod_control * ) ; static int process_command ( int , char ** , codemod_control * ) ;static int check_alist ( alist_matrix * , codemod_control * ) ;void main ( int , char ** ) ;/* MAIN */void main ( int argc, char *argv[] ){ FILE *fp ; alist_matrix a ; int *t , *x , *x2 , *t2 , *x3 , *t3 , *x4 ; int n , N , m , M ; int nn , x2w , x3w , tw , t2w ; int double_entry = 0 , overlap_count = 0 , my_doublets , doublet_count = 0 , triplet_count = 0 , x3_count = 0 , x3bad = 0, x4_count = 0 , x4bad = 0 , t3_count = 0 , t3bad = 0 ; int mult_tot = 0 , trip_tot = 0 , doub_tot = 0 , bad_loop_tot = 0 ; int three_or_more_doublets_tot = 0 , this_bad_loop ; int i , nactive = 0 , status=0 ; int this_overlap_count = 0 ; codemod_control c ; strcpy ( c.afile , "default" ) ; c_defaults ( &c ) ; if ( process_command (argc, argv, &c ) < 0 ) exit (0) ; if ( read_allocate_alist ( &a , c.afile ) < 0 ) exit (0) ; N = a.N ; M = a.M ; x = ivector ( 1 , a.N ) ; x2 = ivector ( 1 , a.N ) ; x3 = ivector ( 1 , a.N ) ; x4 = ivector ( 1 , a.N ) ; t = ivector ( 1 , a.M ) ; t2 = ivector ( 1 , a.M ) ; t3 = ivector ( 1 , a.M ) ; for ( n = 1 ; n <= N ; n ++ ) { /* main n loop */ if ( a.num_nlist[n] ) { nactive ++ ; for ( nn = 1 ; nn <= N ; nn ++ ) x[nn] = 0 ; x[n] = 1 ; alist_times_ivector_sparse ( &a , x , t ) ; /* check for repetitions in the list! */ for ( m = 1 ; m <= M ; m ++ ) { if ( t[m] > 1 ) { fprintf ( stderr , "Double Connection %d->%d \n", n , m ) ; double_entry ++ ; } } alist_transpose_ivector_sparse ( &a , t , x2 ) ; x2[n] = 0 ; /* if 'me' has got switched on, kill it */ if ( c.do_t2 || c.do_x3 || c.do_t3 || c.do_x4 ) { alist_times_ivector_sparse ( &a , x2 , t2 ) ; } if ( c.do_x3 || c.do_t3 || c.do_x4 ) { alist_transpose_ivector_sparse ( &a , t2 , x3 ) ; } if ( c.do_t3 || c.do_x4 ) { alist_times_ivector_sparse ( &a , x3 , t3 ) ; } if ( c.do_x4 ) { alist_transpose_ivector_sparse ( &a , t3 , x4 ) ; } /* compute weights */ x2w = 0 ; x3w = 0 ; tw = 0 ; t2w = 0 ; this_overlap_count = 0 ; for ( nn = 1 ; nn <= N ; nn ++ ) { x2w += x2[nn] ; if ( (x2[nn] > 1) && ( n < nn ) ) { fprintf ( stderr , "overlap cols %d %d\n" , n , nn ) ; overlap_count ++ ; this_overlap_count ++ ; } } if ( c.do_t2 ) { for ( m = 1 ; m <= M ; m ++ ) { tw += t[m] ; t2w += ( t2[m] > 0 ) ? 1 : 0 ; } if ( c.verbose >= 2 ) printf ( "%-4d %d rels %2d friends %3d inlaws %4d cousins\n" , n , tw , x2w , t2w , x3w ) ; /* look for nasty loops etc. */ /* 1: detect doublets - not necessarily a terrible thing */ doublet_count = 0 ; triplet_count = 0 ; for ( m = 1 ; m <= M ; m ++ ) { if ( ( t2[m] > 1 ) && ( ! t[m] ) ) { /* then it's a t2 bit of interest */ if ( t2[m] == 2 ) { if ( doublet_count > 0 ) { printf ( "%-4d -> MULTIPLE doublet at %5d " , n , m ) ; } else if ( c.verbose > 0 ) printf ( "%-4d -> doublet at %5d " , n , m ) ; } else { printf ( "%-4d -> TRIPLET %d at %5d " , n , t2[m] , m ) ; triplet_count ++ ; } doublet_count ++ ; } } if ( ( doublet_count > 0 && c.verbose > 0 ) || doublet_count > 1 || triplet_count > 0 ) { printf ( "\n" ) ; } if ( doublet_count > 0 ) { doub_tot ++ ; } if ( triplet_count > 0 ) { trip_tot ++ ; } /* 2: detect doublets that share an x2 bit */ if ( ( doublet_count > 1 ) && c.bl_search ) { /* go and see if these doublets interfere */ mult_tot ++ ; if ( doublet_count > 2 ) three_or_more_doublets_tot ++ ; this_bad_loop = 0 ; for ( nn = 1 ; nn <= N ; nn ++ ) { if ( x2[nn] ) { my_doublets = 0 ; for ( i = a.num_nlist[nn] ; i >= 1 ; i -- ) { m = a.nlist[nn][i] ; if ( t2[m] > 1 && !t[m] ) { my_doublets ++ ; } } if ( my_doublets >= 2 ) { printf ( "%-4d -> %d bad loops from %d\n" , n , my_doublets , nn ) ; this_bad_loop ++ ; } } } if ( this_bad_loop ) bad_loop_tot ++ ; } if ( c.do_x3 ) { x3_count = 0 ; for ( m = 1 ; m <= N ; m ++ ) { if ( ( x3[m] > 1 ) && ( ! x2[m] ) && ( ! x[m] ) ) { /* then it's of interest */ x3_count ++ ; } } if ( x3_count > 0 ) { x3bad ++ ; } } if ( c.do_t3 ) { t3_count = 0 ; for ( m = 1 ; m <= M ; m ++ ) { if ( ( t3[m] > 1 ) && ( ! t2[m] ) && ( ! t[m] ) ) { /* then it's of interest */ t3_count ++ ; } } if ( t3_count > 0 ) { t3bad ++ ; } } if ( c.do_x4 ) { x4_count = 0 ; for ( m = 1 ; m <= N ; m ++ ) { if ( ( x4[m] > 1 ) && ( ! x3[m] ) && ( ! x2[m] ) && ( ! x[m] ) ) { /* then it's of interest */ x4_count ++ ; } } if ( x4_count > 0 ) { x4bad ++ ; } } } /* end of if t2 */ if ( ( c.modify_overlaps && this_overlap_count ) || ( c.modify_triplets && triplet_count ) || ( c.modify_threeplus && ( doublet_count > 2 ) ) || ( c.modify_multiple && ( doublet_count > 1 ) ) || ( c.modify_doublets && ( doublet_count > 0 ) ) || ( c.mx3 && ( x3_count >= c.mx3 ) ) || ( c.mt3 && ( t3_count >= c.mt3 ) ) || ( c.mx4 && ( x4_count >= c.mx4 ) ) || ( c.modify_bad_loops && this_bad_loop ) ) { printf ( "zeroing %d\n" , n ) ; subtract_col_from_alist ( &a , n ) ; } } /* end of if active */ } /* end of n loop */ fprintf ( stderr , "-----------\n%d overlaps, %d double entries\n" , overlap_count , double_entry ) ; if ( c.do_t2 ) { printf ( "TOTALS: (%5d) %3d bad loops %3d doublets %3d multiple doublets %3d 'three or more' %3d triplets\n" , nactive , bad_loop_tot , doub_tot , mult_tot , three_or_more_doublets_tot , trip_tot ) ; fprintf ( stderr , "TOTALS: (%5d) %3d bad loops %3d doublets %3d multiple doublets %3d 'three or more' %3d triplets " , nactive , bad_loop_tot , doub_tot , mult_tot , three_or_more_doublets_tot , trip_tot ) ; } if ( c.do_x3 ) { fprintf ( stderr , "x3: %d " , x3bad ) ; } if ( c.do_t3 ) { fprintf ( stderr , "t3: %d " , t3bad ) ; } if ( c.do_x4 ) { fprintf ( stderr , "x4: %d " , x4bad ) ; } fprintf( stderr , "\n" ) ; fflush ( stderr ) ; if ( c.write ) { if ( c.strip ) { /* before writing, strip out blank columns */ for ( n = 1 ; n <= a.N ; n ++ ) { /* main n loop */ if ( a.num_nlist[n] == 0 ) { kill_blank_col_from_alist ( &a , n ) ; n -- ; /* knock off one so that next loop, n is the same */ } } status += check_alist ( &a , &c ) ; } fp = fopen ( c.aoutfile , "w" ) ; if ( !fp ) { fprintf ( stderr , "can't open %s\n" , c.aoutfile ) , exit (0) ; } write_alist ( fp , &a ) ; fclose ( fp ) ; }}static int check_alist ( alist_matrix *alist , codemod_control *c ){ int status = 0 ; int tmpi = 0 , n , m ; if ( c->verbose ) printf ( "Checking alist\n" ) ; /* every col should have more than 1 1 in it */ for ( n = 1 ; n <= alist->N ; n ++ ) { if ( alist->num_nlist[n] < c->min_per_col ) { tmpi ++ ; fprintf ( stderr , "%d(%d):" , n , alist->num_nlist[n] ) ; } } if ( tmpi > 0 ) { fprintf ( stderr , "Warning unchecked bits n : %d\n", tmpi ) ; status -- ; } /* every row should have more than 1 1 in it */ tmpi = 0 ; for ( m = 1 ; m <= alist->M ; m ++ ) { if ( alist->num_mlist[m] < c->min_per_row ) { tmpi ++ ; fprintf ( stderr , "%d(%d):" , m , alist->num_mlist[m] ) ; } } if ( tmpi > 0 ) { fprintf ( stderr , "Warning unchecked bits m : %d\n", tmpi ) ; status -= 10 ; } return status ; }static void c_defaults ( codemod_control *c ) {#include "codemod_var_def.c"}static int process_command ( int argc , char **argv , codemod_control *c ) { int p_usage = 0 ; int status = 0 ; int cs , i ; if ( argc < 1 ) { p_usage = 1 ; status -- ; }#define ERROR1 fprintf ( stderr , "arg to `%s' missing\n" , argv[i] ) ; \ status --#define ERROR2 fprintf ( stderr , "args to `%s' missing\n" , argv[i] ) ; \ status --#define ERRORREG fprintf ( stderr , "regtype must be defined before `%s'\n" , argv[i] ) ; \ status -- for (i = 1 ; i < argc; i++) { cs = 1 ; if ( strcmp (argv[i], "-V") == 0 ) { c->verbose = 1; }#include "codemod_var_clr.c" else { fprintf ( stderr , "arg `%s' not recognised\n" , argv[i] ) ; p_usage = 1 ; status -- ; } if ( cs == 0 ) { fprintf ( stderr , "arg at or before `%s' has incorrect format\n" , argv[i] ) ; p_usage = 1 ; status -- ; } } if ( p_usage ) print_usage ( argv , stderr , c ) ; return ( status ) ;}#undef ERROR1#undef ERROR2#undef ERRORREG#define DNT fprintf( fp, "\n ")#define NLNE fprintf( fp, "\n")static void print_usage ( char **argv , FILE * fp , codemod_control *c ){ fprintf( fp, "Usage: %s ",argv[0]); fprintf( fp, " [optional arguments]");#include "codemod_var_usg.c" return ;}/*<!-- hhmts start -->Last modified: Sat Aug 23 18:20:16 1997<!-- hhmts end -->*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -