[GRASS-SVN] r61234 - grass-addons/grass7/imagery/i.destripe

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jul 10 09:21:42 PDT 2014


Author: ychemin
Date: 2014-07-10 09:21:41 -0700 (Thu, 10 Jul 2014)
New Revision: 61234

Modified:
   grass-addons/grass7/imagery/i.destripe/fourier.c
   grass-addons/grass7/imagery/i.destripe/main.c
Log:
bug fixed, working now

Modified: grass-addons/grass7/imagery/i.destripe/fourier.c
===================================================================
--- grass-addons/grass7/imagery/i.destripe/fourier.c	2014-07-10 16:17:42 UTC (rev 61233)
+++ grass-addons/grass7/imagery/i.destripe/fourier.c	2014-07-10 16:21:41 UTC (rev 61234)
@@ -1,16 +1,28 @@
 #include<stdio.h>
 #include<math.h>
 #include <grass/gis.h>
+#include <grass/raster.h>
 
 #define PI 3.1415926
-#define HARMONIC_MAX 50000
+#define HARMONIC_MAX 5000
 
 
-void fourier(DCELL *t_sim,DCELL *inrast,int length,int harmonic_number){
-	int u, t, col;
+void fourier(DCELL *outrast,DCELL *inrast,int length,int harmonic_number){
+	int u, t, col, original_length, count=0;
 	double t_obs[HARMONIC_MAX] = {0.0};
-	for (col = 0; col < length; col++)
-		t_obs[col] = (double) inrast[col];
+	double t_sim[HARMONIC_MAX] = {0.0};
+	for (col = 0; col < length; col++){
+		if (Rast_is_d_null_value(&((DCELL *) inrast)[col])){
+			Rast_set_d_null_value(&outrast[col],1);
+		} else {
+			t_obs[count] = (double) inrast[col];
+			outrast[col] = 0.0;
+			count++;
+		}
+	}
+	//Adjust length to actual count without null values
+	original_length=length;
+	length = count;
 	double fcos[HARMONIC_MAX] = {0.0};
 	double fsin[HARMONIC_MAX] = {0.0};
 	double fm[HARMONIC_MAX] = {0.0};
@@ -21,11 +33,11 @@
 	//t is temporal dimension
 	for (u=0;u<harmonic_number;u++){
 		for (t=0;t<length;t++){
-			fcos[u] = fcos[u]+t_obs[t]*cos(2*PI*u*t/length);
-			fsin[u] = fsin[u]+t_obs[t]*sin(2*PI*u*t/length);
+			fcos[u] += t_obs[t]*cos(2*PI*u*t/length);
+			fsin[u] += t_obs[t]*sin(2*PI*u*t/length);
 		}
-		fcos[u]	= fcos[u]/length;
-		fsin[u]	= fsin[u]/length;
+		fcos[u]	/= length;
+		fsin[u]	/= length;
 		fm[u]	= pow(pow(fcos[u],2)+pow(fsin[u],2),0.5);
 		fp[u]	= atan2(fcos[u],fsin[u]);
 	}
@@ -34,4 +46,13 @@
 			t_sim[t] = t_sim[t]+fm[u]*(cos((2*PI*u*t/length)-fp[u])+sin((2*PI*u*t/length)+fp[u]));
 		}
 	}
+	count=0;
+	for (col = 0; col < original_length; col++){
+		if (Rast_is_d_null_value(&((DCELL *) outrast)[col])){
+			/*Do nothing*/
+		} else {
+			outrast[col] = (DCELL) t_sim[count];
+			count++;
+		}
+	}
 }

Modified: grass-addons/grass7/imagery/i.destripe/main.c
===================================================================
--- grass-addons/grass7/imagery/i.destripe/main.c	2014-07-10 16:17:42 UTC (rev 61233)
+++ grass-addons/grass7/imagery/i.destripe/main.c	2014-07-10 16:21:41 UTC (rev 61234)
@@ -21,7 +21,7 @@
 #include <grass/raster.h>
 #include <grass/glocale.h>
 
-void fourier(double *t_sim,double *t_obs,int length,int harmonic_number); 
+void fourier(DCELL *t_sim,DCELL *t_obs,int length,int harmonic_number); 
 
 int main(int argc, char *argv[]) 
 {
@@ -35,8 +35,7 @@
     char *result;	/*output raster name */
     int infd, outfd, ha;
     char *in;
-    void *inrast;
-    DCELL * outrast;
+    DCELL *inrast, *outrast;
     CELL val1, val2;
     
     /************************************/ 
@@ -67,7 +66,6 @@
     in = input1->answer;
     ha = atoi(input2->answer);
     result = output->answer;
-    
     /***************************************************/ 
     infd = Rast_open_old(in, "");
     inrast = Rast_allocate_d_buf();



More information about the grass-commit mailing list