[pktools] 84/375: call by reference in applySrf

Bas Couwenberg sebastic at xs4all.nl
Wed Dec 3 21:54:02 UTC 2014


This is an automated email from the git hooks/post-receive script.

sebastic-guest pushed a commit to branch upstream-master
in repository pktools.

commit aaceeb07023620ba1c81613e9bb97725976f1331
Author: Pieter Kempeneers <kempenep at gmail.com>
Date:   Thu Mar 28 15:12:56 2013 +0100

    call by reference in applySrf
---
 src/algorithms/Filter.h            | 10 ++++++----
 src/fileclasses/FileReaderAscii.cc | 28 ++++++++++++++++------------
 src/fileclasses/FileReaderAscii.h  |  4 ++--
 3 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/src/algorithms/Filter.h b/src/algorithms/Filter.h
index d072c29..02afce4 100644
--- a/src/algorithms/Filter.h
+++ b/src/algorithms/Filter.h
@@ -55,11 +55,11 @@ public:
   void morphology(const ImgReaderGdal& input, ImgWriterGdal& output, const std::string& method, int dim, short down=1, int offset=0);
   void doit(const ImgReaderGdal& input, ImgWriterGdal& output, short down=1, int offset=0);
 
-  template<class T> double applySrf(const vector<double> &wavelengthIn, const vector<T>& input, const Vector2d<double>& srf, const std::string& interpolationType, T output, double delta=1.0, bool normalize=false, bool verbose=false);
+  template<class T> double applySrf(const vector<double> &wavelengthIn, const vector<T>& input, const Vector2d<double>& srf, const std::string& interpolationType, T& output, double delta=1.0, bool normalize=false, bool verbose=false);
   template<class T> double applySrf(const vector<double> &wavelengthIn, const Vector2d<T>& input, const Vector2d<double>& srf, const std::string& interpolationType, vector<T>& output, double delta=1.0, bool normalize=false, int down=1, bool verbose=false);
 
   // void applySrf(const vector<double> &wavelengthIn, const ImgReaderGdal& input, const vector< Vector2d<double> > &srf, const std::string& interpolationType, ImgWriterGdal& output, bool verbose=false);
-  template<class T> void applyFwhm(const vector<double> &wavelengthIn, const vector<double>& input, const vector<double> &wavelengthOut, const vector<double> &fwhm, const std::string& interpolationType, vector<double>& output, bool verbose=false);
+  template<class T> void applyFwhm(const vector<double> &wavelengthIn, const vector<T>& input, const vector<double> &wavelengthOut, const vector<double> &fwhm, const std::string& interpolationType, vector<T>& output, bool verbose=false);
   template<class T> void applyFwhm(const vector<double> &wavelengthIn, const Vector2d<T>& input, const vector<double> &wavelengthOut, const vector<double> &fwhm, const std::string& interpolationType, Vector2d<T>& output, int down=1, bool verbose=false);
   // void applyFwhm(const vector<double> &wavelengthIn, const ImgReaderGdal& input, const vector<double> &wavelengthOut, const vector<double> &fwhm, const std::string& interpolationType, ImgWriterGdal& output, bool verbose=false);
 // int fir(double* input, int nbandIn, vector<double>& output, int startBand, const string& wavelength, const string& fwhm, bool verbose);
@@ -104,7 +104,7 @@ private:
 
 //input[band], output
 //returns wavelength for which srf is maximum
-  template<class T> double Filter::applySrf(const vector<double> &wavelengthIn, const vector<T>& input, const Vector2d<double>& srf, const std::string& interpolationType, T output, double delta, bool normalize, bool verbose)
+  template<class T> double Filter::applySrf(const vector<double> &wavelengthIn, const vector<T>& input, const Vector2d<double>& srf, const std::string& interpolationType, T& output, double delta, bool normalize, bool verbose)
 {  
   assert(srf.size()==2);//[0]: wavelength, [1]: response function
   int nband=srf[0].size(); 
@@ -155,6 +155,8 @@ private:
   vector<double> product(wavelength_fine.size());
   stat.interpolateUp(wavelengthIn,input,wavelength_fine,interpolationType,input_fine,verbose);
 
+  if(verbose)
+    std::cout << "input_fine.size(): " << input_fine.size() << std::endl;
   for(int iband=0;iband<input_fine.size();++iband)
     product[iband]=input_fine[iband]*srf_fine[iband];
 
@@ -265,7 +267,7 @@ private:
   return(srf[0][maxIndex]);
 }
 
-template<class T> void Filter::applyFwhm(const vector<double> &wavelengthIn, const vector<double>& input, const vector<double> &wavelengthOut, const vector<double> &fwhm, const std::string& interpolationType, vector<double>& output, bool verbose){
+template<class T> void Filter::applyFwhm(const vector<double> &wavelengthIn, const vector<T>& input, const vector<double> &wavelengthOut, const vector<double> &fwhm, const std::string& interpolationType, vector<T>& output, bool verbose){
   double delta=1;//1 nm resolution
   vector<double> stddev(fwhm.size());
   for(int index=0;index<fwhm.size();++index)
diff --git a/src/fileclasses/FileReaderAscii.cc b/src/fileclasses/FileReaderAscii.cc
index b5419ab..9a43672 100644
--- a/src/fileclasses/FileReaderAscii.cc
+++ b/src/fileclasses/FileReaderAscii.cc
@@ -55,9 +55,8 @@ void FileReaderAscii::close(){
   //  m_ifstream.clear();
 }
 
-unsigned int FileReaderAscii::nrOfCol(bool checkCols){
+unsigned int FileReaderAscii::nrOfCol(bool checkCols, bool verbose){
   reset();
-  bool verbose=false;
   unsigned int totalCol=0;
   unsigned int nrow=0;
   if(m_fs>' '&&m_fs<='~'){//field separator is a regular character (minimum ASCII code is space, maximum ASCII code is tilde)
@@ -67,7 +66,7 @@ unsigned int FileReaderAscii::nrOfCol(bool checkCols){
     while(getline(m_ifstream,csvRecord)){//read a line
       std::istringstream csvstream(csvRecord);
       std::string item;
-      int ncol=0;
+      unsigned int ncol=0;
       bool isComment=false;
       while(getline(csvstream,item,m_fs)){//read a column
         if(verbose)
@@ -87,8 +86,10 @@ unsigned int FileReaderAscii::nrOfCol(bool checkCols){
           break;
       }
       if(verbose)
-        std::cout << std::endl;
-      if(checkCols){
+        std::cout << std::endl << "number of columns: " << ncol << std::endl;
+      if(!totalCol)
+        totalCol=ncol;
+      else if(checkCols){
         if(totalCol!=ncol){
           std::ostringstream ess;
           ess << "Error: different number of cols found in line " << nrow << " (" << ncol << "!=" << totalCol << ")" << std::endl;
@@ -109,7 +110,7 @@ unsigned int FileReaderAscii::nrOfCol(bool checkCols){
         std::cout << spaceRecord << std::endl;
       std::istringstream lineStream(spaceRecord);
       std::string item;
-      int ncol=0;
+      unsigned int ncol=0;
       bool isComment=false;
       while(lineStream >> item){
         if(verbose)
@@ -130,7 +131,9 @@ unsigned int FileReaderAscii::nrOfCol(bool checkCols){
       }
       if(verbose)
         std::cout << std::endl << "number of columns: " << ncol << std::endl;
-      if(checkCols){
+      if(!totalCol)
+        totalCol=ncol;
+      else if(checkCols){
         if(totalCol!=ncol){
           std::ostringstream ess;
           ess << "Error: different number of cols found in line " << nrow << " (" << ncol << "!=" << totalCol << ")" << std::endl;
@@ -142,11 +145,11 @@ unsigned int FileReaderAscii::nrOfCol(bool checkCols){
       ++nrow;
     }
   }
+  return totalCol;
 }
 
-unsigned int FileReaderAscii::nrOfRow(bool checkCols){
+unsigned int FileReaderAscii::nrOfRow(bool checkCols, bool verbose){
   reset();
-  bool verbose=false;
   unsigned int totalCol=0;
   unsigned int nrow=0;
   unsigned int ncomment=0;
@@ -157,7 +160,7 @@ unsigned int FileReaderAscii::nrOfRow(bool checkCols){
     while(getline(m_ifstream,csvRecord)){//read a line
       std::istringstream csvstream(csvRecord);
       std::string item;
-      int ncol=0;
+      unsigned int ncol=0;
       bool isComment=false;
       while(getline(csvstream,item,m_fs)){//read a column
         if(verbose)
@@ -200,7 +203,7 @@ unsigned int FileReaderAscii::nrOfRow(bool checkCols){
         std::cout << spaceRecord << std::endl;
       std::istringstream lineStream(spaceRecord);
       std::string item;
-      int ncol=0;
+      unsigned int ncol=0;
       bool isComment=false;
       while(lineStream >> item){
         if(verbose)
@@ -229,9 +232,10 @@ unsigned int FileReaderAscii::nrOfRow(bool checkCols){
           ess << "Error: different number of cols found in line " << nrow << " (" << ncol << "!=" << totalCol << ")" << std::endl;
           throw(ess.str());
         }
-        ++nrow;
       }
+      ++nrow;
     }
   }
+  return nrow;
 }
 
diff --git a/src/fileclasses/FileReaderAscii.h b/src/fileclasses/FileReaderAscii.h
index 5dcd430..feab76c 100644
--- a/src/fileclasses/FileReaderAscii.h
+++ b/src/fileclasses/FileReaderAscii.h
@@ -40,8 +40,8 @@ public:
   void setMinRow(int minRow){m_minRow=minRow;};
   void setMaxRow(int maxRow){m_maxRow=maxRow;};
   void setComment(char comment){m_comment=comment;};
-  unsigned int nrOfCol(bool checkCols=false);
-  unsigned int nrOfRow(bool checkCols=false);
+  unsigned int nrOfCol(bool checkCols=false, bool verbose=false);
+  unsigned int nrOfRow(bool checkCols=false, bool verbose=false);
   template<class T> unsigned int readData(std::vector<std::vector<T> > &dataVector, const std::vector<int> &cols, bool verbose=false);
   template<class T> unsigned int readData(std::vector<T> &dataVector, int col, bool verbose=false);
   protected:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/pktools.git



More information about the Pkg-grass-devel mailing list