#include #include #include #include #include struct { float phi1, Phi, phi2; float ci, iq, fit, avgIQ; int phase, ds; } data[3000][3000]; int round2( double x ) { double fl, ce; fl = floor( x ); ce = ceil( x ); if( fabs( fl-x ) < fabs( ce-x ) ) return fl; else return ce; } char lineBuffer[200]; int ReadFileInfo(FILE *oimStream, int *xmax, int *ymax, double *stepSize ) { double x, y, dxmax; long count; *stepSize = 0; dxmax = 0; *xmax = 0; while( fgets( lineBuffer, 200, oimStream ) != NULL ) { if( lineBuffer[0] == '#' ) { if( strcmp( lineBuffer, "# GRID: SqrGrid" ) == 0 ) { printf("\nThe file is already a square grid file.\nProgram terminated."); return 0; } count = 0; continue; } if( sscanf( lineBuffer, "%*lf %*lf %*lf %lf %lf %*lf %*lf %*i %*i %*lf %*lf", &x, &y ) != 2 ) return 0; if( *stepSize == 0 && x != 0 ) *stepSize = x; if( x > dxmax ) { dxmax = x; (*xmax)++; } count++; } (*xmax)++; *ymax = (int)(count / *xmax ); return 1; } int main(int argc, char* argv[]) { int xx, yy, zz, xlimit, ylimit, zlimit, xlimitOut, xOut; double stepSize; char zFilename[50], zOutFilename[50], filename[50]; FILE *inStream, *outStream; int zStartNumber, zEndNumber; printf( "\nFilenames must have the format ""root_xxx.ang""" "\nwith xxx indicating a 3-digit integer" "\nEnter oim map filename-root, the start integer and the end integer number of the files: " ); scanf( "%s %i %i", filename, &zStartNumber, &zEndNumber ); zlimit = zEndNumber-zStartNumber+1; //read the first data file and get all necessary start data sprintf( zFilename, "%s_%03i.ang", filename, zStartNumber ); if( (inStream = fopen( zFilename, "r" )) == NULL ) { printf( "\nCan't open %s", zFilename ); exit( 1 ); } if( ReadFileInfo( inStream, &xlimit, &ylimit, &stepSize ) == 0 ) { printf( "\nWrong file format in %s", filename ); exit( 1 ); } fclose( inStream ); for( zz=0; zz