Skip to content

Instantly share code, notes, and snippets.

@dakcarto
Last active January 3, 2016 06:49
Show Gist options
  • Save dakcarto/8425453 to your computer and use it in GitHub Desktop.
Save dakcarto/8425453 to your computer and use it in GitHub Desktop.
Homebrew taudem patch
diff --git a/Node.cpp b/Node.cpp
index 50444b5..248dbfc 100644
--- a/Node.cpp
+++ b/Node.cpp
@@ -39,7 +39,7 @@ email: dtarb@usu.edu
// This software is distributed from http://hydrology.usu.edu/taudem/
#include "Node.h"
-#include "stdlib.h"
+#include <stdlib.h>
//Merge: used to union pixels/cells/nodes together in the same set
void merge( Node *A, Node *B) {
diff --git a/PeukerDouglas.cpp b/PeukerDouglas.cpp
index faa05c2..4ecfb2f 100644
--- a/PeukerDouglas.cpp
+++ b/PeukerDouglas.cpp
@@ -7,39 +7,72 @@
May 23, 2010
*/
-
-/* Copyright (C) 2010 David Tarboton, Utah State University
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-version 2, 1991 as published by the Free Software Foundation.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-A copy of the full GNU General Public License is included in file
-gpl.html. This is also available at:
-http://www.gnu.org/copyleft/gpl.html
-or from:
-The Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.
-
-If you wish to use or incorporate this program (or parts of it) into
-other software that does not meet the GNU General Public License
-conditions contact the author to request permission.
-David G. Tarboton
-Utah State University
-8200 Old Main Hill
-Logan, UT 84322-8200
-USA
-http://www.engineering.usu.edu/dtarb/
-email: dtarb@usu.edu
-*/
-
-// This software is distributed from http://hydrology.usu.edu/taudem/
-
+
+
+/* Copyright (C) 2010 David Tarboton, Utah State University
+
+
+
+This program is free software; you can redistribute it and/or
+
+modify it under the terms of the GNU General Public License
+
+version 2, 1991 as published by the Free Software Foundation.
+
+
+
+This program is distributed in the hope that it will be useful,
+
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+
+GNU General Public License for more details.
+
+
+
+A copy of the full GNU General Public License is included in file
+
+gpl.html. This is also available at:
+
+http://www.gnu.org/copyleft/gpl.html
+
+or from:
+
+The Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+
+Boston, MA 02111-1307, USA.
+
+
+
+If you wish to use or incorporate this program (or parts of it) into
+
+other software that does not meet the GNU General Public License
+
+conditions contact the author to request permission.
+
+David G. Tarboton
+
+Utah State University
+
+8200 Old Main Hill
+
+Logan, UT 84322-8200
+
+USA
+
+http://www.engineering.usu.edu/dtarb/
+
+email: dtarb@usu.edu
+
+*/
+
+
+
+// This software is distributed from http://hydrology.usu.edu/taudem/
+
+
+
#include <mpi.h>
#include <math.h>
#include <queue>
@@ -48,7 +81,7 @@ email: dtarb@usu.edu
#include "createpart.h"
#include "tiffIO.h"
#include "shape/shapefile.h"
-#include "ctime"
+#include <ctime>
using namespace std;
@@ -115,7 +148,8 @@ int peukerdouglas(char *felfile, char *ssfile,float *p)
for(x=0; x <elevnx; x++)
{
// NEED function in linearpart to evaluate whether is on edge.
- // Suggestion **->isOnEdge(x,y) to return true if on edge of global domain or adjacent to a no data value, otherwise to return false.
+ // Suggestion **->isOnEdge(x,y) to return true if on edge of global domain or adjacent to a no data value, otherwise to return false.
+
// FIX code below to if on a global edge or adjacent to a no-data value do first "if block"
if(rank == 0 && y == 0 || rank == (size-1) && y == (elevny-1) )
@@ -129,7 +163,8 @@ int peukerdouglas(char *felfile, char *ssfile,float *p)
ss->setData(x,y,(short)0);
}
else
- { // THIS is for all the remainder of cells
+ { // THIS is for all the remainder of cells
+
ss->setData((long)x, (long)y, (short)1); // Initializing to 1 for all non edge grid cells
@@ -157,9 +192,12 @@ int peukerdouglas(char *felfile, char *ssfile,float *p)
selev->setData(x,y,elevwsum);
}
}
- }
-
- //-- Put smoothed elevations back in elevation grid--
+ }
+
+
+
+ //-- Put smoothed elevations back in elevation grid--
+
for(y=0; y < elevny; y++)
{
for(x=0; x < elevnx; x++)
@@ -176,9 +214,11 @@ int peukerdouglas(char *felfile, char *ssfile,float *p)
emax =elev->getData(x,y,floatTemp1);
iomax=0;
jomax=0;
- bound=0; /* .false. */
+ bound=0; /* .false. */
+
- /* --FIRST PASS FLAG MAX ELEVATION IN GROUP OF FOUR */
+ /* --FIRST PASS FLAG MAX ELEVATION IN GROUP OF FOUR */
+
for(ik=0; ik<2; ik++)
for(jk=1-ik; jk < 2; jk++)
{
@@ -191,9 +231,11 @@ int peukerdouglas(char *felfile, char *ssfile,float *p)
jomax=jk;
}
}
- /* c---Unflag max pixel */
+ /* c---Unflag max pixel */
+
ss->setData(x+jomax,y+iomax,(short)0);
- /* c---Unflag pixels where the group of 4 touches a boundary */
+ /* c---Unflag pixels where the group of 4 touches a boundary */
+
if(bound == 1)
{
for(ik=0; ik < 2; ik++)
@@ -202,7 +244,8 @@ int peukerdouglas(char *felfile, char *ssfile,float *p)
ss->setData(x+jk,y+ik,(short)0);
}
}else{
- /* i.e. unflag flats. */
+ /* i.e. unflag flats. */
+
for(ik=0; ik < 2; ik++)
for(jk=0; jk< 2; jk++)
{
diff --git a/commonLib.h b/commonLib.h
index a3c31a2..af10de4 100644
--- a/commonLib.h
+++ b/commonLib.h
@@ -41,7 +41,7 @@ email: dtarb@usu.edu
#define COMMON_H
#include <cmath>
#include <float.h>
-#include "mpi.h"
+#include <mpi.h>
#define MCW MPI_COMM_WORLD
#define MAX_STRING_LENGTH 255
diff --git a/linearpart.h b/linearpart.h
index ed090e2..1a3e29e 100644
--- a/linearpart.h
+++ b/linearpart.h
@@ -38,7 +38,7 @@ email: dtarb@usu.edu
// This software is distributed from http://hydrology.usu.edu/taudem/
-#include "mpi.h"
+#include <mpi.h>
#include "partition.h"
#include "commonLib.h"
#include <queue>
diff --git a/tiffTest.cpp b/tiffTest.cpp
index 968ac24..4c76cc3 100644
--- a/tiffTest.cpp
+++ b/tiffTest.cpp
@@ -5,59 +5,106 @@
May 23, 2010
*/
-
-/* Copyright (C) 2010 David Tarboton, Utah State University
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-version 2, 1991 as published by the Free Software Foundation.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-A copy of the full GNU General Public License is included in file
-gpl.html. This is also available at:
-http://www.gnu.org/copyleft/gpl.html
-or from:
-The Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.
-
-If you wish to use or incorporate this program (or parts of it) into
-other software that does not meet the GNU General Public License
-conditions contact the author to request permission.
-David G. Tarboton
-Utah State University
-8200 Old Main Hill
-Logan, UT 84322-8200
-USA
-http://www.engineering.usu.edu/dtarb/
-email: dtarb@usu.edu
-*/
-
-// This software is distributed from http://hydrology.usu.edu/taudem/
-
-#include "tiffIO.h"
-#include "commonLib.h"
-#include "stdint.h"
-#include "mpi.h"
-
+
+
+/* Copyright (C) 2010 David Tarboton, Utah State University
+
+
+
+This program is free software; you can redistribute it and/or
+
+modify it under the terms of the GNU General Public License
+
+version 2, 1991 as published by the Free Software Foundation.
+
+
+
+This program is distributed in the hope that it will be useful,
+
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+
+GNU General Public License for more details.
+
+
+
+A copy of the full GNU General Public License is included in file
+
+gpl.html. This is also available at:
+
+http://www.gnu.org/copyleft/gpl.html
+
+or from:
+
+The Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+
+Boston, MA 02111-1307, USA.
+
+
+
+If you wish to use or incorporate this program (or parts of it) into
+
+other software that does not meet the GNU General Public License
+
+conditions contact the author to request permission.
+
+David G. Tarboton
+
+Utah State University
+
+8200 Old Main Hill
+
+Logan, UT 84322-8200
+
+USA
+
+http://www.engineering.usu.edu/dtarb/
+
+email: dtarb@usu.edu
+
+*/
+
+
+
+// This software is distributed from http://hydrology.usu.edu/taudem/
+
+
+
+#include "tiffIO.h"
+
+#include "commonLib.h"
+
+#include <stdint.h>
+
+#include <mpi.h>
+
+
+
#include "linearpart.h"
#include "createpart.h"
-int main(){
- MPI_Init(NULL, NULL);
- {
- // Program used to test Tiffio. Provide any format in.tif file.
- // Compile with type in the line below either SHORT_TYPE, LONG_TYPE or FLOAT_TYPE
- // Then the output in out.tif should be the input data changed to the designated type
+int main(){
+
+ MPI_Init(NULL, NULL);
+
+ {
+
+ // Program used to test Tiffio. Provide any format in.tif file.
+
+ // Compile with type in the line below either SHORT_TYPE, LONG_TYPE or FLOAT_TYPE
+
+ // Then the output in out.tif should be the input data changed to the designated type
+
// Code to repeat memory allocation many times to test linearpart.h code for trapping exception
// in memory allocation
tiffIO infile("logan/logan.tif",FLOAT_TYPE);
- //tiffIO infile("gsl100.tif",FLOAT_TYPE);
- //long cols = infile.getTotalX();
- //long rows = infile.getTotalY();
+ //tiffIO infile("gsl100.tif",FLOAT_TYPE);
+
+ //long cols = infile.getTotalX();
+
+ //long rows = infile.getTotalY();
+
// //Create partition and read data
//tdpartition* elevDEM[10000];
//float dx,dy;
@@ -80,43 +127,83 @@ int main(){
//long cols = infile.getTotalX();
//long rows = infile.getTotalY();
- //DATA_TYPE type = infile.getDatatype();
- //tiffIO fel("fs_small.tif",FLOAT_TYPE);
- //if(!fel.compareTiff(infile))
- //printf("Mismatch\n");
-
- //void *inarray;
- //void* nd = infile.getNodata();
- //if(type == SHORT_TYPE){
- // inarray = new short[rows*cols];
- // short ndv= *(short *)nd;
- // printf("No data: %d\n",ndv);
- //}
- //else if(type == LONG_TYPE){
- // inarray = new long[rows*cols];
- // long ndv= *(long *)nd;
- // printf("No data: %ld\n",ndv);
- //}
- //else if(type == FLOAT_TYPE){
- // inarray = new float[rows*cols];
- //}
-
- //infile.read(0, 0, rows, cols, inarray);
- printf("Char Size %d\n",sizeof(char));
- printf("Short Size %d\n",sizeof(short));
- printf("Int Size %d\n",sizeof(int));
- printf("Long Size %d\n",sizeof(long));
- printf("Long Long Size %d\n",sizeof(long long));
- printf("Float Size %d\n",sizeof(float));
- printf("Double Size %d\n",sizeof(double));
- printf("Long Double Size %d\n",sizeof(long double));
- printf("int32_t %d\n",sizeof(int32_t));
- printf("int64_t %d\n",sizeof(int64_t));
-
- // float nd = 1.0f;
- //tiffIO outfile("out.tif", type, nd, infile);
- //outfile.write(0, 0, rows, cols, inarray);
- }
- MPI_Finalize();
- return 0;
-}
+ //DATA_TYPE type = infile.getDatatype();
+
+ //tiffIO fel("fs_small.tif",FLOAT_TYPE);
+
+ //if(!fel.compareTiff(infile))
+
+ //printf("Mismatch\n");
+
+
+
+ //void *inarray;
+
+ //void* nd = infile.getNodata();
+
+ //if(type == SHORT_TYPE){
+
+ // inarray = new short[rows*cols];
+
+ // short ndv= *(short *)nd;
+
+ // printf("No data: %d\n",ndv);
+
+ //}
+
+ //else if(type == LONG_TYPE){
+
+ // inarray = new long[rows*cols];
+
+ // long ndv= *(long *)nd;
+
+ // printf("No data: %ld\n",ndv);
+
+ //}
+
+ //else if(type == FLOAT_TYPE){
+
+ // inarray = new float[rows*cols];
+
+ //}
+
+
+
+ //infile.read(0, 0, rows, cols, inarray);
+
+ printf("Char Size %d\n",sizeof(char));
+
+ printf("Short Size %d\n",sizeof(short));
+
+ printf("Int Size %d\n",sizeof(int));
+
+ printf("Long Size %d\n",sizeof(long));
+
+ printf("Long Long Size %d\n",sizeof(long long));
+
+ printf("Float Size %d\n",sizeof(float));
+
+ printf("Double Size %d\n",sizeof(double));
+
+ printf("Long Double Size %d\n",sizeof(long double));
+
+ printf("int32_t %d\n",sizeof(int32_t));
+
+ printf("int64_t %d\n",sizeof(int64_t));
+
+
+
+ // float nd = 1.0f;
+
+ //tiffIO outfile("out.tif", type, nd, infile);
+
+ //outfile.write(0, 0, rows, cols, inarray);
+
+ }
+
+ MPI_Finalize();
+
+ return 0;
+
+}
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment