//program file name #include #include #include #include using namespace std; //define large arrays as global. float v1[1202][1202]; //raster data 1 float v2[1202][1202]; //raster data 2 int main(int argc, char *argv[]) { int i, j; char rn[128]; //region name char vn[128]; //variable name char un[128]; //name of the unit int dt; //type of data (not in use) int xas, yas; //number of elements float xs, ys; //size of the region char str[128]; //separator //initializing two raster data as zero. for (j=0; j<=1201; j++) { for (i=0; i<=1201; i++) { v1[i][j] = 0; v2[i][j] = 0; } } //exit if the number of arguments is not 1. if (argc != 2) { cerr << "Usage: mrproc \n"; return 1; } //open the input file. exit if an error occurs. ifstream fin(argv[1]); if (!fin) { cerr << "Cannot open file.\n"; return 1; } //read data. fin.getline(rn, 80); fin.getline(vn, 80); fin.getline(un, 80); fin >> dt >> xas >> yas; fin >> xs >> ys >> str; for (j=1; j<=yas; j++) { for (i=1; i<=xas; i++) { fin >> v1[i][j]; } } fin.close(); //make extrapolation along the four edges of the data. for (j=1; j<=yas; j++) { v1[0][j] = v1[1][j] * 2 - v1[2][j]; v1[xas + 1][j] = v1[xas][j] * 2 - v1[xas - 1][j]; } for (i=1; i<=xas; i++) { v1[i][0] = v1[i][1] * 2 - v1[i][2]; v1[i][yas + 1] = v1[i][yas] * 2 - v1[i][yas - 1]; } v1[0][0] = v1[1][1] * 2 - v1[2][2]; v1[xas + 1][0] = v1[xas][1] * 2 - v1[xas - 1][2]; v1[0][yas + 1] = v1[1][yas] * 2 - v1[2][yas - 1]; v1[xas + 1][yas + 1] = v1[xas][yas] * 2 - v1[xas - 1][yas - 1]; //operation of data. for (j=1; j<=yas; j++) { for (i=1; i<=xas; i++) { //write the procedure of operation you want to do here. //in the example below, Laplacian operation is implemented. v2[i][j] = v1[i][j] * 4 - v1[i][j-1] - v1[i-1][j] - v1[i+1][j] - v1[i][j+1]; } } //add operation to the variable name. strcat(vn, "-Laplacian"); //output the results of operation. //when you want to save them in a file, please redirect it. cout << rn << "\n" << vn << "\n" << un << "\n" ; cout << dt << "\n" << xas << "\n" << yas << "\n"; cout << xs << "\n" << ys << "\n" << str << "\n"; for (j=1; j<=yas; j++) { for (i=1; i<=xas; i++) { cout << v2[i][j] << "\n"; } } return 0; } //end of the program.