Commit 1e80f6da authored by Giovanni La Mura's avatar Giovanni La Mura
Browse files

Start migrating LFFFT to C++

parent f70fe40d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -6,6 +6,16 @@
#define INCLUDE_TRA_SUBS_H_
#endif

//Structures for TRAPPING (that will probably move to Commons)
struct cil {
  int le, nlem, nlemt, mxmpo, mxim;
};

struct ccr {
  double cof, cimu;
};
//End of TRAPPING structures

//Externally defined subroutines
extern std::complex<double> dconjg(std::complex<double> z);
extern void sphar(
+0 −1
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ using namespace std;
 *  \param data_file: `string` Name of the input data file.
 *  \param output_path: `string` Directory to write the output files in.
 */
//void frfme(string data_file, string output_path) {
int main() {
  string data_file = "../../test_data/trapping/DFRFME";
  string output_path = ".";

src/trapping/lffft.cpp

0 → 100644
+85 −0
Original line number Diff line number Diff line
#include <cstdio>
#include <fstream>
#include <regex>
#include <string>
#include <complex>
#ifndef INCLUDE_PARSERS_H_
#include "../include/Parsers.h"
#endif
//#ifndef INCLUDE_SPH_SUBS_H_
//#include "../include/sph_subs.h"
//#endif
#ifndef INCLUDE_TRA_SUBS_H_
#include "../include/tra_subs.h"
#endif

using namespace std;

/*! \brief C++ implementation of FRFME
 *
 *  \param data_file: `string` Name of the input data file.
 *  \param output_path: `string` Directory to write the output files in.
 */
int main() {
  string data_file = "../../test_data/trapping/DLFFFT";
  string output_path = ".";
  double ****zpv = NULL, *ac = NULL;
  complex<double> *ws = NULL;
  double *fffe = NULL, *fffs = NULL;
  double *ffte = NULL, *ffts = NULL;
  double *xv = NULL, *yv = NULL, *zv = NULL;
  complex<double> *wsl = NULL;
  complex<double> **am0m = NULL;
  complex<double> **amd = NULL;
  int **indam = NULL;
  complex<double> *tmsm = NULL, *tmse = NULL, *tms = NULL;
  int jft, jss, jtw;
  int is, le;
  double vks, exris;

  int num_lines = 0;
  string *file_lines = load_file(data_file, &num_lines);
  regex re = regex("-?[0-9]+");
  smatch m;
  string str_target = file_lines[0];
  for (int mi = 0; mi < 3; mi++) {
    regex_search(str_target, m, re);
    if (mi == 0) jft = stoi(m.str());
    else if (mi == 1) jss = stoi(m.str());
    else if (mi == 2) jtw = stoi(m.str());
    str_target = m.suffix().str();
  } // mi loop
  string ttms_name = output_path + "/c_TTMS";
  fstream ttms;
  ttms.open(ttms_name, ios::in | ios::binary);
  if (ttms.is_open()) {
    ttms.read(reinterpret_cast<char *>(&is), sizeof(int));
    ttms.read(reinterpret_cast<char *>(&le), sizeof(int));
    ttms.read(reinterpret_cast<char *>(&vks), sizeof(double));
    ttms.read(reinterpret_cast<char *>(&exris), sizeof(double));
    const int nlem = le * (le + 2);
    const int nlemt = nlem + nlem;
    printf("DEBUG: is = %d\n", is);
    printf("DEBUG: le = %d\n", le);
    printf("DEBUG: vks = %lE\n", vks);
    printf("DEBUG: exris = %lE\n", exris);
  } else {
    printf("ERROR: could not open TTMS file.\n");
  }
  // Clean up memory
  if (ac != NULL) delete[] ac;
  if (ws != NULL) delete[] ws;
  if (fffe != NULL) delete[] fffe;
  if (ffte != NULL) delete[] ffte;
  if (fffs != NULL) delete[] fffs;
  if (ffts != NULL) delete[] ffts;
  if (xv != NULL) delete[] xv;
  if (yv != NULL) delete[] yv;
  if (zv != NULL) delete[] zv;
  if (wsl != NULL) delete[] wsl;
  if (tmsm != NULL) delete[] tmsm;
  if (tmse != NULL) delete[] tmse;
  if (tms != NULL) delete[] tms;
  printf("Done.\n");
  return 0;
}