/* sort_per.c -- sort perturbed ELS's by their perturbations */ #include #include "ios.h" /* using the input/output service module */ #define ERR_NO_UNPERTURBED 1 #define ERR_FILE_LONG 2 #define MAXRECNO 5000 static FILE * outfile; static int Key [MAXRECNO]; static long int Start [MAXRECNO]; static int Pitch [MAXRECNO]; static int SortPointer [MAXRECNO]; static int Counter [125]; static int Recno; static void first_pass (void); static void second_pass (void); void main ( int argc, char * argv [] ) { long int TextLength; int WordLength; char * from; int flag; if ( argc < 3 ) err_command_line ( "sort infile outfile" ); open_input_file ( argv [1] ); get_line_sure ( & from ); sscanf ( from, "%d %ld", &WordLength, &TextLength ); first_pass (); flag = 1; if ( Counter [62] == 0 ) { flag = 0; printf ( "warning: no unperturbed ELS's\n" ); } outfile = open_output_file ( argv [2] ); fprintf ( outfile, "[ %3d%7ld ]\n", WordLength, TextLength ); second_pass (); if ( flag ) exit (0); exit ( ERR_NO_UNPERTURBED ); } static void first_pass (void) { int keyno, x, y, z, n; long int start; int pitch; char * from; keyno = 0; for ( n=0; n<125; n++ ) Counter [n] = 0; while ( 0 <= get_line ( & from ) ) { if ( 5 != sscanf ( from, "%d %d %d %ld %d", &x,&y,&z, &start, &pitch ) ) break; if ( keyno >= MAXRECNO ) { printf ( "too long input file\n" ); exit ( ERR_FILE_LONG ); } n = 25 * x + 5 * y + z; Key [keyno] = n; ++ Counter [ 62 + n ]; Start [keyno] = start; Pitch [keyno] = pitch; keyno++; } Recno = keyno; } static void second_pass (void) { int n, k, k0, i, keyno, x, y, z; k = 0; for ( n=0; n<125; n++ ) { k0 = k; k += Counter [n]; Counter [n] = k0; } for ( keyno = 0; keyno < Recno; keyno++ ) { k = 62 + Key [keyno]; SortPointer [ Counter [k] ++ ] = keyno; } k0 = -1; for ( keyno = 0; keyno <= Recno; keyno++ ) { if ( keyno < Recno ) { n = SortPointer [keyno]; k = 62 + Key [n]; } else k = 124; while ( k0 < k ) { i = ++k0; z = ( i % 5 ) - 2; i = i / 5; y = ( i % 5 ) - 2; i = i / 5; x = i - 2; fprintf ( outfile, "[*** %2d %2d %2d ]\n", x, y, z ); } if ( keyno < Recno ) fprintf ( outfile, "[ %6ld %5d ]\n", Start [n], Pitch [n] ); } } /* end of sort_per.c */