Skip to content

Commit

Permalink
Added Qt Creator project to compile binary
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfoose committed Jul 31, 2015
1 parent 150806b commit f6127bb
Show file tree
Hide file tree
Showing 2 changed files with 214 additions and 0 deletions.
38 changes: 38 additions & 0 deletions qt_project/freeimodpoly.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp \
$$PWD/../freeimodpoly.cpp
HEADERS += \
$$PWD/../freeimodpoly.h

INCLUDEPATH += $$PWD/../../../Vespucci/MinGW_libs/include
DEPENDPATH += $$PWD/../../../Vespucci/MinGW_libs/include

INCLUDEPATH += $$PWD/../FreeIModPoly
DEPENDPATH += $$PWD/../FreeIModPoly

#Armadillo
win32: LIBS += -L$$PWD/../../../Vespucci/MinGW_libs/lib/ -larmadillo
win32-g++: PRE_TARGETDEPS += $$PWD/../../../Vespucci/MinGW_libs/lib/libarmadillo.a

#HDF5
win32: LIBS += -L$$PWD/../../../Vespucci/MinGW_libs/lib/ -lhdf5
wind32-g++: PRE_TARGETDEPS += $$PWD/../../../Vespucci/MinGW_libs/lib/libhdf5.a

#ARPACK-NG
win32: LIBS += -L$$PWD/../../../Vespucci/MinGW_libs/lib/ -larpack
win32-g++: PRE_TARGETDEPS += $$PWD/../../../Vespucci/MinGW_libs/lib/libarpack.a

#OpenBLAS (linked dynamically because arpack links it dynamically)
win32: LIBS += -L$$PWD/../../../Vespucci/MinGW_libs/lib/ -llibopenblas
win32-g++: PRE_TARGETDEPS += $$PWD/../../../Vespucci/MinGW_libs/lib/libopenblas.dll.a

#Libgfortran
win32: LIBS += -L$$PWD/../MinGW_libs/lib/$$PWD/../../../Vespucci/MinGW_libs/lib/ -lgfortran
win32-g++: PRE_TARGETDEPS += $$PWD/../../../Vespucci/MinGW_libs/lib/libgfortran.a



176 changes: 176 additions & 0 deletions qt_project/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
// Copyright (C) 2015 Wright State University
// Author: Daniel P. Foose
// This file is part of FreeIModPoly.
//
// FreeIModPoly is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or (at
// your option) any later version.
//
// FreeIModPoly 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.
//
// You should have received a copy of the GNU General Public License
// along with Octave; see the file LICENSE. If not, see
// <http://www.gnu.org/licenses/>.
//
// FreeIModPoly: A free software implementation of the Vancouver Raman Algorithm
// Please cite DOI: 10.1366/000370207782597003 and this project (see CITATION)
// The author of this implementation is not associated with the authors of the
// algorithm.

#include <iostream>
#include <string>
#include "freeimodpoly.h"
#include <algorithm>

using namespace std;
///
/// \brief main
/// \param argc
/// \param argv
/// \return
/// How to call: freeimodpoly order max_it threshold infile outfile outtype transpose
/// Valid outtypes:
/// "txt" - whitespace-delimited text
/// "csv" - comma-delimited text\
///
/// Default outfile is infile with _corrected appended to name (including old extension)
/// The file is structured in columns: abscissa baseline corrected for single spectra
/// Baseline and corrected are stored in separate files "_baseline, _corrected"
/// Default format is csv
///
/// Program crashes on invalid input, but I'm not going to do anything about it
/// If you need to transpose, you've got to specify all parameters, sorry.
int main(int argc, char* argv[])
{
string infilename, outfilename, blfilename;
unsigned int poly_order, max_it;
double threshold;
file_type outtype;
string outtype_text;
bool transpose = false;
//parse commandline parameters:
switch (argc){
case 1: case 2: case 3: case 4:
cerr << "No spectrum file specified" << endl;
return 1;
case 5:
infilename = string(argv[4]);
outfilename = infilename + "_corrected.csv";
blfilename = infilename + "_baseline.csv";
poly_order = atof(argv[1]);
max_it = atof(argv[2]);
threshold = atof(argv[3]);
outtype = csv_ascii;
break;
case 6:
infilename = string(argv[4]);
outfilename = string(argv[5]);
blfilename = outfilename + "_baseline.csv";
poly_order = atof(argv[1]);
max_it = atof(argv[2]);
threshold = atof(argv[3]);
outtype = csv_ascii;
break;
case 7:
infilename = string(argv[4]);
outfilename = string(argv[5]);
blfilename = outfilename + "_baseline.csv";
poly_order = atof(argv[1]);
max_it = atof(argv[2]);
threshold = atof(argv[3]);
outtype_text = string(argv[6]);
transform(outtype_text.begin(), outtype_text.end(), outtype_text.begin(), ::tolower);
outtype = (outtype_text == "txt" ? raw_ascii : csv_ascii);
break;
case 8: default:
infilename = string(argv[4]);
outfilename = string(argv[5]);
blfilename = outfilename + "_baseline.csv";
poly_order = atof(argv[1]);
max_it = atof(argv[2]);
threshold = atof(argv[3]);
outtype_text = string(argv[6]);
transform(outtype_text.begin(), outtype_text.end(), outtype_text.begin(), ::tolower);
outtype = (outtype_text == "txt" ? raw_ascii : csv_ascii);
transpose = true;
break;
}

using namespace arma;
mat spec_file;
spec_file.load(infilename);
vec abscissa;
mat spectra;
try{
abscissa = spec_file.col(0);
spectra = spec_file.cols(1, spec_file.n_cols - 1);
}catch(std::exception e){
cerr << "Spectrum could not be loaded" << endl;
return 1;
}
if(transpose){
inplace_trans(spectra);
inplace_trans(abscissa);
}

if (spectra.n_cols == 1){
vec baseline, corrected;
mat out_mat(spectra.n_rows, 3);
double err;
int iter;
try{
iter = FreeIModPoly::IModPoly(spectra.col(0),
abscissa,
baseline,
corrected,
err, poly_order, max_it, threshold);
}catch(exception e){cerr << "exception thrown!" << endl; return 2;}
out_mat.col(0) = abscissa;
out_mat.col(1) = baseline;
out_mat.col(3) = corrected;
cout << "Final error: " << err << endl;
if (iter >= max_it)
cout << "Did not converge in " << iter << " iterations." << endl;
else{
cout << "Converged in " << iter << " iterations." << endl;
}
bool ok = out_mat.save(outfilename, outtype);
if (ok){return 0;}
else{cout << "Save failed!" << endl; return 3;}
}

else{
mat error_report (spectra.n_cols, 2);
mat corrected_spectra(spectra.n_rows, spectra.n_cols + 1);
mat baselines(spectra.n_rows, spectra.n_cols + 1);
baselines.col(0) = abscissa;
corrected_spectra.col(0) = abscissa;
for (uword i = 0; i < spectra.n_cols; ++i){
double err;
vec spectrum = spectra.col(i);
vec baseline, corrected;
int iter = FreeIModPoly::IModPoly(spectrum, abscissa,
baseline, corrected, err,
poly_order, max_it, threshold);
baselines.col(i+1) = baseline;
corrected_spectra.col(i+1) = corrected;
error_report(i, 1) = err;
error_report(i, 2) = (double) (iter < max_it);
}
bool blok = baselines.save("bl_" + outfilename, outtype);
bool csok = corrected_spectra.save("cs_" + outfilename, outtype);
bool erok = error_report.save("er_" + outfilename, outtype);
cout << (blok ? "Saved baseline\n" : "Saving baslines failed\n")
<< (csok ? "Saved corrected\n" : "Saving spectra failed\n")
<< (erok ? "Saved error report\n" : "Saving error report failed\n");

if(!(blok && csok && erok)){return 3;}
else{return 0;}

}
}

0 comments on commit f6127bb

Please sign in to comment.