Skip to content
Snippets Groups Projects
Commit a53cbb3a authored by Giovanni La Mura's avatar Giovanni La Mura
Browse files

Implement command-line options for input and output

parent b440fbb7
Branches
Tags
No related merge requests found
...@@ -16,16 +16,19 @@ using namespace std; ...@@ -16,16 +16,19 @@ using namespace std;
* *
*/ */
//! \brief C++ implementation of CLU /*! \brief C++ implementation of CLU
void cluster() { *
printf("INFO: making legacy configuration ...\n"); * \param config_file: `string` Name of the configuration file.
ScattererConfiguration *conf = ScattererConfiguration::from_dedfb("../../test_data/cluster/DEDFB"); * \param data_file: `string` Name of the input data file.
conf->write_formatted("c_OEDFB_clu"); * \param output_path: `string` Directory to write the output files in.
conf->write_binary("c_TEDF_clu"); */
delete conf; void cluster(string config_file, string data_file, string output_path) {
printf("INFO: reading binary configuration ...\n"); printf("INFO: making legacy configuration...");
ScattererConfiguration *sconf = ScattererConfiguration::from_binary("c_TEDF_clu"); ScattererConfiguration *sconf = ScattererConfiguration::from_dedfb(config_file);
GeometryConfiguration *gconf = GeometryConfiguration::from_legacy("../../test_data/cluster/DCLU"); sconf->write_formatted(output_path + "/c_OEDFB_clu");
sconf->write_binary(output_path + "/c_TEDF_clu");
GeometryConfiguration *gconf = GeometryConfiguration::from_legacy(data_file);
printf(" done.\n");
if (sconf->number_of_spheres == gconf->number_of_spheres) { if (sconf->number_of_spheres == gconf->number_of_spheres) {
// Shortcuts to variables stored in configuration objects // Shortcuts to variables stored in configuration objects
int nsph = gconf->number_of_spheres; int nsph = gconf->number_of_spheres;
...@@ -78,7 +81,7 @@ void cluster() { ...@@ -78,7 +81,7 @@ void cluster() {
C1_AddOns *c1ao = new C1_AddOns(c4); C1_AddOns *c1ao = new C1_AddOns(c4);
// End of add-ons initialization // End of add-ons initialization
C6 *c6 = new C6(c4->lmtpo); C6 *c6 = new C6(c4->lmtpo);
FILE *output = fopen("c_OCLU", "w"); FILE *output = fopen((output_path + "/c_OCLU").c_str(), "w");
int jer = 0, lcalc = 0; int jer = 0, lcalc = 0;
complex<double> arg(0.0, 0.0), ccsam(0.0, 0.0); complex<double> arg(0.0, 0.0), ccsam(0.0, 0.0);
int max_ici = 0; int max_ici = 0;
...@@ -226,7 +229,8 @@ void cluster() { ...@@ -226,7 +229,8 @@ void cluster() {
double vk = 0.0; // NOTE: Not really sure it should be initialized at 0 double vk = 0.0; // NOTE: Not really sure it should be initialized at 0
fprintf(output, " REFR. INDEX OF EXTERNAL MEDIUM=%15.7lE\n", exri); fprintf(output, " REFR. INDEX OF EXTERNAL MEDIUM=%15.7lE\n", exri);
fstream tppoan; fstream tppoan;
tppoan.open("c_TPPOAN", ios::out | ios::binary); string tppoan_name = output_path + "/c_TPPOAN";
tppoan.open(tppoan_name.c_str(), ios::out | ios::binary);
if (tppoan.is_open()) { if (tppoan.is_open()) {
tppoan.write(reinterpret_cast<char *>(&iavm), sizeof(int)); tppoan.write(reinterpret_cast<char *>(&iavm), sizeof(int));
tppoan.write(reinterpret_cast<char *>(&isam), sizeof(int)); tppoan.write(reinterpret_cast<char *>(&isam), sizeof(int));
...@@ -244,6 +248,7 @@ void cluster() { ...@@ -244,6 +248,7 @@ void cluster() {
fprintf(output, " \n"); fprintf(output, " \n");
} }
for (int jxi488 = 1; jxi488 <= nxi; jxi488++) { for (int jxi488 = 1; jxi488 <= nxi; jxi488++) {
printf("INFO: running scale iteration...\n");
int jaw = 1; int jaw = 1;
fprintf(output, "========== JXI =%3d ====================\n", jxi488); fprintf(output, "========== JXI =%3d ====================\n", jxi488);
double xi = sconf->scale_vec[jxi488 - 1]; double xi = sconf->scale_vec[jxi488 - 1];
...@@ -293,20 +298,25 @@ void cluster() { ...@@ -293,20 +298,25 @@ void cluster() {
} }
if (jer != 0) break; if (jer != 0) break;
} // i132 loop } // i132 loop
printf("INFO: initializing matrix...");
cms(am, c1, c1ao, c4, c6); cms(am, c1, c1ao, c4, c6);
ccsam = summat(am, 960, 960); printf(" done.\n");
printf("DEBUG: after CMS CCSAM = (%lE,%lE)\n", ccsam.real(), ccsam.imag()); //ccsam = summat(am, 960, 960);
//printf("DEBUG: after CMS CCSAM = (%lE,%lE)\n", ccsam.real(), ccsam.imag());
int ndit = 2 * nsph * c4->nlim; int ndit = 2 * nsph * c4->nlim;
printf("INFO: inverting matrix...");
lucin(am, mxndm, ndit, jer); lucin(am, mxndm, ndit, jer);
ccsam = summat(am, 960, 960); printf(" done.\n");
printf("DEBUG: after LUCIN CCSAM = (%lE,%lE)\n", ccsam.real(), ccsam.imag()); //ccsam = summat(am, 960, 960);
//printf("DEBUG: after LUCIN CCSAM = (%lE,%lE)\n", ccsam.real(), ccsam.imag());
if (jer != 0) break; // jxi488 loop: goes to memory clean if (jer != 0) break; // jxi488 loop: goes to memory clean
ztm(am, c1, c1ao, c4, c6, c9); ztm(am, c1, c1ao, c4, c6, c9);
if (sconf->idfc >= 0) { if (sconf->idfc >= 0) {
if (jxi488 == gconf->jwtm) { if (jxi488 == gconf->jwtm) {
int is = 1; int is = 1;
fstream ttms_file; fstream ttms_file;
ttms_file.open("c_TTMS", ios::out | ios::binary); string ttms_name = output_path + "/c_TTMS";
ttms_file.open(ttms_name.c_str(), ios::out | ios::binary);
if (ttms_file.is_open()) { if (ttms_file.is_open()) {
ttms_file.write(reinterpret_cast<char *>(&is), sizeof(int)); ttms_file.write(reinterpret_cast<char *>(&is), sizeof(int));
ttms_file.write(reinterpret_cast<char *>(&lm), sizeof(int)); ttms_file.write(reinterpret_cast<char *>(&lm), sizeof(int));
...@@ -340,7 +350,7 @@ void cluster() { ...@@ -340,7 +350,7 @@ void cluster() {
double csch = 0.0, qschu = 0.0, pschu = 0.0, s0mag = 0.0; double csch = 0.0, qschu = 0.0, pschu = 0.0, s0mag = 0.0;
std::complex<double> s0(0.0, 0.0); std::complex<double> s0(0.0, 0.0);
scr0(vk, exri, c1, c1ao, c3, c4); scr0(vk, exri, c1, c1ao, c3, c4);
printf("DEBUG: after SCR0 TFSAS = (%lE, %lE)\n", c3->tfsas.real(), c3->tfsas.imag()); //printf("DEBUG: after SCR0 TFSAS = (%lE, %lE)\n", c3->tfsas.real(), c3->tfsas.imag());
double sqk = vk * vk * sconf->exdc; double sqk = vk * vk * sconf->exdc;
aps(zpv, c4->li, nsph, c1, sqk, gaps); aps(zpv, c4->li, nsph, c1, sqk, gaps);
rabas(inpol, c4->li, nsph, c1, tqse, tqspe, tqss, tqsps); rabas(inpol, c4->li, nsph, c1, tqse, tqspe, tqss, tqsps);
...@@ -533,7 +543,7 @@ void cluster() { ...@@ -533,7 +543,7 @@ void cluster() {
complex<double> s0m = c1ao->fsacm[ilr210 - 1][ilr210 - 1] * exri; complex<double> s0m = c1ao->fsacm[ilr210 - 1][ilr210 - 1] * exri;
double qschum = s0m.imag() * csch; double qschum = s0m.imag() * csch;
double pschum = s0m.real() * csch; double pschum = s0m.real() * csch;
double s0magm = sqrt((s0m.real() + s0m.imag()) * (s0m.real() - s0m.imag())) * cs0; double s0magm = abs(s0m) * cs0;
double rfinrm = c1ao->fsacm[ilr210 - 1][ilr210 - 1].real() / c3->tfsas.real(); double rfinrm = c1ao->fsacm[ilr210 - 1][ilr210 - 1].real() / c3->tfsas.real();
double extcrm = c1ao->fsacm[ilr210 - 1][ilr210 - 1].imag() / c3->tfsas.imag(); double extcrm = c1ao->fsacm[ilr210 - 1][ilr210 - 1].imag() / c3->tfsas.imag();
if (inpol == 0) { if (inpol == 0) {
...@@ -871,7 +881,7 @@ void cluster() { ...@@ -871,7 +881,7 @@ void cluster() {
} // jph484 loop } // jph484 loop
th += thstp; th += thstp;
} // jth486 loop } // jth486 loop
printf("INFO: done jxi488 iteration.\n"); printf("INFO: done scale.\n");
} // jxi488 loop } // jxi488 loop
tppoan.close(); tppoan.close();
} else { // In case TPPOAN could not be opened. Should never happen. } else { // In case TPPOAN could not be opened. Should never happen.
...@@ -958,5 +968,5 @@ void cluster() { ...@@ -958,5 +968,5 @@ void cluster() {
} }
delete sconf; delete sconf;
delete gconf; delete gconf;
printf("Done.\n"); printf("Finished: output written to %s.\n", (output_path + "/c_OCLU").c_str());
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <cstdio> #include <cstdio>
#include <string> #include <string>
#ifndef INCLUDE_CONFIGURATION_H_ #ifndef INCLUDE_CONFIGURATION_H_
#include "include/Configuration.h" #include "../include/Configuration.h"
#endif #endif
using namespace std; using namespace std;
......
...@@ -65,8 +65,8 @@ public: ...@@ -65,8 +65,8 @@ public:
*/ */
class GeometryConfiguration { class GeometryConfiguration {
//! Temporary work-around to allow cluster() and sphere() peeking in. //! Temporary work-around to allow cluster() and sphere() peeking in.
friend void cluster(); friend void cluster(std::string, std::string, std::string);
friend void sphere(); friend void sphere(std::string, std::string, std::string);
protected: protected:
//! \brief Number of spherical components. //! \brief Number of spherical components.
int number_of_spheres; int number_of_spheres;
...@@ -191,8 +191,8 @@ public: ...@@ -191,8 +191,8 @@ public:
*/ */
class ScattererConfiguration { class ScattererConfiguration {
//! Temporary work-around to allow cluster() and sphere() peeking in. //! Temporary work-around to allow cluster() and sphere() peeking in.
friend void cluster(); friend void cluster(std::string, std::string, std::string);
friend void sphere(); friend void sphere(std::string, std::string, std::string);
protected: protected:
//! \brief Matrix of dielectric parameters with size [NON_TRANS_LAYERS x N_SPHERES x LAYERS]. //! \brief Matrix of dielectric parameters with size [NON_TRANS_LAYERS x N_SPHERES x LAYERS].
std::complex<double> ***dc0_matrix; std::complex<double> ***dc0_matrix;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <cstdio> #include <cstdio>
#include <string> #include <string>
#ifndef INCLUDE_CONFIGURATION_H_ #ifndef INCLUDE_CONFIGURATION_H_
#include "include/Configuration.h" #include "../include/Configuration.h"
#endif #endif
using namespace std; using namespace std;
......
...@@ -11,18 +11,18 @@ ...@@ -11,18 +11,18 @@
using namespace std; using namespace std;
//! \brief C++ implementation of SPH /*! \brief C++ implementation of SPH
void sphere() { *
* \param config_file: `string` Name of the configuration file.
* \param data_file: `string` Name of the input data file.
* \param output_path: `string` Directory to write the output files in.
*/
void sphere(string config_file, string data_file, string output_path) {
complex<double> arg, s0, tfsas; complex<double> arg, s0, tfsas;
double th, ph; double th, ph;
printf("INFO: making legacy configuration ...\n"); printf("INFO: making legacy configuration ...\n");
ScattererConfiguration *conf = ScattererConfiguration::from_dedfb("../../test_data/sphere/DEDFB"); ScattererConfiguration *sconf = ScattererConfiguration::from_dedfb(config_file);
conf->write_formatted("c_OEDFB_sph"); GeometryConfiguration *gconf = GeometryConfiguration::from_legacy(data_file);
conf->write_binary("c_TEDF_sph");
delete conf;
printf("INFO: reading binary configuration ...\n");
ScattererConfiguration *sconf = ScattererConfiguration::from_binary("c_TEDF_sph");
GeometryConfiguration *gconf = GeometryConfiguration::from_legacy("../../test_data/sphere/DSPH");
if (sconf->number_of_spheres == gconf->number_of_spheres) { if (sconf->number_of_spheres == gconf->number_of_spheres) {
int isq, ibf; int isq, ibf;
double *argi, *args, *gaps; double *argi, *args, *gaps;
...@@ -71,7 +71,7 @@ void sphere() { ...@@ -71,7 +71,7 @@ void sphere() {
argi = new double[1]; argi = new double[1];
args = new double[1]; args = new double[1];
gaps = new double[2]; gaps = new double[2];
FILE *output = fopen("c_OSPH", "w"); FILE *output = fopen((output_path + "/c_OSPH").c_str(), "w");
fprintf(output, " READ(IR,*)NSPH,LM,INPOL,NPNT,NPNTTS,ISAM\n"); fprintf(output, " READ(IR,*)NSPH,LM,INPOL,NPNT,NPNTTS,ISAM\n");
fprintf( fprintf(
output, output,
...@@ -179,7 +179,8 @@ void sphere() { ...@@ -179,7 +179,8 @@ void sphere() {
double exri = sqrt(sconf->exdc); double exri = sqrt(sconf->exdc);
fprintf(output, " REFR. INDEX OF EXTERNAL MEDIUM=%15.7lE\n", exri); fprintf(output, " REFR. INDEX OF EXTERNAL MEDIUM=%15.7lE\n", exri);
fstream tppoan; fstream tppoan;
tppoan.open("c_TPPOAN_sph", ios::binary|ios::out); string tppoan_name = output_path + "/c_TPPOAN_sph";
tppoan.open(tppoan_name.c_str(), ios::binary|ios::out);
if (tppoan.is_open()) { if (tppoan.is_open()) {
int imode = 10; int imode = 10;
tppoan.write(reinterpret_cast<char *>(&imode), sizeof(int)); tppoan.write(reinterpret_cast<char *>(&imode), sizeof(int));
...@@ -205,6 +206,7 @@ void sphere() { ...@@ -205,6 +206,7 @@ void sphere() {
fprintf(output, " \n"); fprintf(output, " \n");
} }
for (int jxi488 = 0; jxi488 < sconf->number_of_scales; jxi488++) { for (int jxi488 = 0; jxi488 < sconf->number_of_scales; jxi488++) {
printf("INFO: running scale iteration...\n");
int jxi = jxi488 + 1; int jxi = jxi488 + 1;
fprintf(output, "========== JXI =%3d ====================\n", jxi); fprintf(output, "========== JXI =%3d ====================\n", jxi);
double xi = sconf->scale_vec[jxi488]; double xi = sconf->scale_vec[jxi488];
...@@ -259,7 +261,8 @@ void sphere() { ...@@ -259,7 +261,8 @@ void sphere() {
// This is the condition that writes the transition matrix to output. // This is the condition that writes the transition matrix to output.
int is = 1111; int is = 1111;
fstream ttms; fstream ttms;
ttms.open("c_TTMS_sph", ios::binary | ios::out); string ttms_name = output_path + "/c_TTMS_sph";
ttms.open(ttms_name.c_str(), ios::binary | ios::out);
if (ttms.is_open()) { if (ttms.is_open()) {
ttms.write(reinterpret_cast<char *>(&is), sizeof(int)); ttms.write(reinterpret_cast<char *>(&is), sizeof(int));
ttms.write(reinterpret_cast<char *>(&(gconf->l_max)), sizeof(int)); ttms.write(reinterpret_cast<char *>(&(gconf->l_max)), sizeof(int));
...@@ -281,7 +284,7 @@ void sphere() { ...@@ -281,7 +284,7 @@ void sphere() {
double cs0 = 0.25 * vk * vk * vk / half_pi; double cs0 = 0.25 * vk * vk * vk / half_pi;
//printf("DEBUG: cs0 = %lE\n", cs0); //printf("DEBUG: cs0 = %lE\n", cs0);
sscr0(tfsas, nsph, gconf->l_max, vk, exri, c1); sscr0(tfsas, nsph, gconf->l_max, vk, exri, c1);
printf("DEBUG: TFSAS = (%lE,%lE)\n", tfsas.real(), tfsas.imag()); //printf("DEBUG: TFSAS = (%lE,%lE)\n", tfsas.real(), tfsas.imag());
double sqk = vk * vk * sconf->exdc; double sqk = vk * vk * sconf->exdc;
aps(zpv, gconf->l_max, nsph, c1, sqk, gaps); aps(zpv, gconf->l_max, nsph, c1, sqk, gaps);
rabas(gconf->in_pol, gconf->l_max, nsph, c1, tqse, tqspe, tqss, tqsps); rabas(gconf->in_pol, gconf->l_max, nsph, c1, tqse, tqspe, tqss, tqsps);
...@@ -519,6 +522,7 @@ void sphere() { ...@@ -519,6 +522,7 @@ void sphere() {
} // jph484 loop on elevation } // jph484 loop on elevation
th += gconf->in_theta_step; th += gconf->in_theta_step;
} // jth486 loop on azimuth } // jth486 loop on azimuth
printf("INFO: done scale.\n");
} //jxi488 loop on scales } //jxi488 loop on scales
tppoan.close(); tppoan.close();
} else { // In case TPPOAN could not be opened. Should never happen. } else { // In case TPPOAN could not be opened. Should never happen.
...@@ -568,7 +572,7 @@ void sphere() { ...@@ -568,7 +572,7 @@ void sphere() {
delete[] tqss; delete[] tqss;
delete[] tqspe; delete[] tqspe;
delete[] tqsps; delete[] tqsps;
printf("Done.\n"); printf("Finished: output written to %s.\n", (output_path + "/c_OSPH").c_str());
} else { // NSPH mismatch between geometry and scatterer configurations. } else { // NSPH mismatch between geometry and scatterer configurations.
throw UnrecognizedConfigurationException( throw UnrecognizedConfigurationException(
"Inconsistent geometry and scatterer configurations." "Inconsistent geometry and scatterer configurations."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment