-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsed2grad.cpp
executable file
·55 lines (50 loc) · 1.22 KB
/
sed2grad.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "smattpl.h"
#include "RWFile.h"
#include <math.h>
int main(int argc, char * argv[])
{
if( argc<2 )
{
cerr << "Converts the file with a gradient transformation " << endl;
cerr << "using the followint formula:" << endl;
cerr << "sqrt( ((bi1,j−bi−1,j))^2 + (b(i,j1)−b(i,j−1))^2 )" << endl;
cerr << "Usage: sed2grad input output" << endl;
exit(1);
}
simplmat<double> data;
RWFile file;
file.ReadSeed(argv[1], data);
int dimX = data.getRows();
int dimY = data.getCols();
int i,j;
// Convierte a Gradiente
//
//
int grad = 1; // atoi(argv[3]);
if( grad)
{
simplmat<double> ndat(dimX,dimY);
double xx,yy;
for(i=0; i<dimX; i++)
for( j=0; j<dimY; j++)
{
if(i==dimX-1)
xx = data(i, j) - data(i-1,j);
else if(i==0)
xx = data(i+1, j) - data(i,j);
else
xx = data(i+1, j) - data(i-1,j);
if(j==dimY-1)
yy = data(i, j) - data(i,j-1);
else if(j==0)
yy = data(i, j+1) - data(i,j);
else
yy = data(i, j+1) - data(i,j-1);
ndat(i,j)=sqrt( xx*xx + yy*yy );
}
for(i=0; i<dimX; i++)
for( j=0; j<dimY; j++)
data(i,j)=ndat(i,j);
}
file.WriteSeed(argv[2],data);
}