/* * Average fields: * * This program averages n input files and outputs the result. It * assumes that the inputs are all in single-precision IEEE-BE ("big * endian") format. Internally, the averaging is done in IEEE double * precision and the final result is converted back into IEEE-BE * immediately before being written. */ #include #include #include #include #include #include #include #include #include #include #include #define uint32 unsigned int #define BUF_SIZE 65536 #define htonl(A) ((((uint32)(A) & 0xff000000) >> 24) | \ (((uint32)(A) & 0x00ff0000) >> 8) | \ (((uint32)(A) & 0x0000ff00) << 8) | \ (((uint32)(A) & 0x000000ff) << 24)) #define bswap32(A) ( ((uint32)(A) >> 24) | \ (((uint32)(A) & 0x00ff0000) >> 8) | \ (((uint32)(A) & 0x0000ff00) << 8) | \ ((uint32)(A) << 24) ) int main( int argc, char** argv ) { char buff[BUF_SIZE]; int i; int nbytes; using namespace std; struct stat st; void * vptr; double * dptr; float * fptr; uint32 u32; if (argc < 4) { cerr << "\nError: at least three file names must be supplied." << endl; exit(1); } string fname(argv[1]); stat(fname.c_str(), &st); nbytes = st.st_size; cout << "The file \"" << fname << "\" has size: " << nbytes << " bytes" << endl; int ndouble = nbytes/4; dptr = new double[ndouble]; if (dptr == NULL) { cerr << "\nError: unable to allocate sufficient memory." << endl; exit(1); } for (int j=0; j