ExaGeoStat
ExaGeoStat is a parallel high performance unified framework for geostatistics on manycore systems.
core_dcmg.c
Go to the documentation of this file.
1 
20 #include "../include/exageostatcore.h"
21 
22 // This function converts decimal degrees to radians
23 static double deg2rad(double deg) {
24  return (deg * PI / 180);
25 }
26 // This function converts radians to decimal degrees
27 static double rad2deg(double rad) {
28  return (rad * 180 / PI);
29 }
39 static double distanceEarth(double lat1d, double lon1d, double lat2d, double lon2d) {
40  double lat1r, lon1r, lat2r, lon2r, u, v;
41  lat1r = deg2rad(lat1d);
42  lon1r = deg2rad(lon1d);
43  lat2r = deg2rad(lat2d);
44  lon2r = deg2rad(lon2d);
45  u = sin((lat2r - lat1r)/2);
46  v = sin((lon2r - lon1r)/2);
47  return 2.0 * earthRadiusKm * asin(sqrt(u * u + cos(lat1r) * cos(lat2r) * v * v));
48 }
49 
50 static double calculateDistance(double x1, double y1, double x2, double y2, int distance_metric) {
51 
52  if(distance_metric == 1)
53  return distanceEarth(x1, y1, x2, y2);
54  return sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2));
55 }
56 
57 /***************************************************************************/
95 void core_dcmg (double *A, int m, int n, int m0, int n0, location *l1, location *l2, double *localtheta, int distance_metric) {
96 
97  int i, j;
98  double l1x, l1y, l2x, l2y;
99  double expr = 0.0;
100  double con;
101  double sigma_square = localtheta[0];// * localtheta[0];
102 
103  con = pow(2,(localtheta[2]-1)) * tgamma(localtheta[2]);
104  con = 1.0/con;
105  con = sigma_square * con;
106 
107  for (j = 0; j < n; j++) {
108  l1x = l1->x[j+n0];
109  l1y = l1->y[j+n0];
110  for (i = 0; i < m; i++) {
111  l2x = l2->x[i+m0];
112  l2y = l2->y[i+m0];
113  expr = calculateDistance(l1x, l1y, l2x, l2y, distance_metric)/localtheta[1];
114  if(expr == 0)
115  A[i + j * m] = sigma_square; /* + 1e-4*/
116  else
117  A[i + j * m] = con*pow(expr, localtheta[2])*gsl_sf_bessel_Knu(localtheta[2],expr); // Matern Function
118 
119  }
120  }
121 
122 }
123 
124 
125 
126 
#define earthRadiusKm
Definition: MLE_misc.h:58
double * y
Values in Y dimension.
Definition: MLE_misc.h:83
void core_dcmg(double *A, int m, int n, int m0, int n0, location *l1, location *l2, double *localtheta, int distance_metric)
Definition: core_dcmg.c:95
double * x
Values in X dimension.
Definition: MLE_misc.h:82
#define PI
Definition: MLE_misc.h:54
#define A(m, n)
Definition: pdpotrf_diag.c:34