/* meudon.c This programme converts Meudon (convex) sets with (unsupported) BLANKs to standard GIPSY BLANKs. Meudon uses 0xff7ffffe (?), while standard GIPSY uses 0xff800000 (-Inf) or 0xff7fffff (-FLT_MAX). The suggested mode of operation is as follows: 1) you have imported GIPSY sets from the Meudon convex. You should compile this programme (p meudon.c) and run it as follows: meudon set1_from_meudon.descr [set2_from_meudon.descr ... ] 2) you are at Meudon and want to convert all Meudon sets to `supported' GIPSY sets. You first should obtain the latest sources and compile them on all architectures with -DBLANK2 on the c compiler command line (so put it in $gip_loc/setup). Then compile this programme (p meudon.c) and run it as above. */ #include "ctype.h" #include "stdio.h" #include "stdlib.h" #include "string.h" #define SIZE 4096 int main( int argc, char *argv[] ) { int n = 1; int ftype = OS_FLOATING_TYPE; long ib, ob; if ( argc == 1 ) { fprintf( stdout, "Usage: meudon [fptype] set.descr [ set.descr [..] ]\n\n" ); fprintf( stdout, "This programme converts Meudon (convex) sets to standard GIPSY sets.\n" ); fprintf( stdout, "The main thing is to convert the Meudon (unsupported) BLANK to\n" ); fprintf( stdout, "standard GIPSY BLANKs.\n"); fprintf( stdout, "There are to fptypes possible: 0 IEEE with BLANK = -Inf.\n" ); fprintf( stdout, " 5 IEEE with BLANK = -FLT_MAX.\n" ); fprintf( stdout, "The default will be the local fptype.\n\n" ); fprintf( stdout, "Example: meudon *.descr\n\n" ); fprintf( stdout, "Notes: You should only run this programme once on a set!\n\n" ); return( EXIT_SUCCESS ); } ib = 0xff7ffffe; if ( ( strlen( argv[1] ) == 1 ) && isdigit( argv[1][0] ) ) { n = 2; ftype = atoi( argv[1] ); } if ( ftype == 0 ) { ob = 0xff800000; } else if ( ftype == 5 ) { ob = 0xff7fffff; } else { fprintf( stderr, "Can only convert to FLOATING POINT TYPE 0 or 5!\n" ); return( EXIT_FAILURE ); } if ( OS_INTEGER_TYPE == 1 ) { union { unsigned char b[sizeof( unsigned long )]; unsigned long l; } in, ou; int k; in.l = ib; for ( k = 0; k < sizeof( unsigned long ); k++) { ou.b[sizeof( unsigned long ) - k - 1] = in.b[k]; } ib = ou.l; in.l = ob; for ( k = 0; k < sizeof( unsigned long ); k++) { ou.b[sizeof( unsigned long ) - k - 1] = in.b[k]; } ob = ou.l; } for ( ; n < argc; n++ ) { char *e; char image[FILENAME_MAX]; if ((e = strstr( argv[n], ".descr" )) && strlen( e ) == 6) { FILE *d; unsigned char bi, bo; d = fopen( argv[n] , "rb+" ); if ( d == NULL ) { fprintf( stderr, "Cannot open %s!\n", argv[n] ); } else { fseek( d, 12, SEEK_SET ); fread( &bi, 1, 1, d ); if ( bi != 0x00 ) { fprintf( stderr, "Can only convert from FLOATING POINT TYPE 0!\n" ); fclose( d ); d = NULL; } } if ( d != NULL ) { fseek( d, 12, SEEK_SET ); bo = ftype; fwrite( &bo, 1, 1, d ); fclose( d ); fprintf( stdout, "Modified %s\n", argv[n] ); strncpy( image, argv[n], strlen( argv[n] ) - 6 ); image[strlen( argv[n] ) - 6] = 0; strcat( image, ".image" ); d = fopen( image, "rb+" ); } if ( d != NULL ) { unsigned long buffer[SIZE]; unsigned long done = 0; unsigned long left; unsigned long mods = 0; fseek( d, 0, SEEK_END ); left = ftell( d ) / sizeof( unsigned long ); while (left) { int j; int nb, nr, nt, nw; fseek( d, done * sizeof( unsigned long ), SEEK_SET ); nt = ( left > SIZE ? SIZE : left ); nr = fread( buffer, sizeof( unsigned long ), nt, d ); if ( nr != nt ) { fprintf( stderr, "Error reading %s!\n", image ); break; } for ( nb = j = 0; j < nt; j++ ) { if ( buffer[j] == ib ) { nb++; buffer[j] = ob; } } if (nb) { fseek( d, done * sizeof( unsigned long ), SEEK_SET ); nw = fwrite( buffer, sizeof( unsigned long ), nt, d ); if ( nw != nt ) { fprintf( stderr, "Error writing %s!\n", image ); break; } mods += nb; } left -= nt; done += nt; } fclose( d ); if (!left) { fprintf( stdout, "Modified %s (%d blanks)\n", image, mods ); } } } } return( EXIT_SUCCESS ); }