Skip to content
Snippets Groups Projects
Commit c77ca108 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

Experimental code NSpecial::export_p2d for new style 2D plots;

generalizations and corrections here and there.
parent a47f88f6
No related branches found
No related tags found
No related merge requests found
...@@ -639,6 +639,9 @@ bool frida_command(string cmd) ...@@ -639,6 +639,9 @@ bool frida_command(string cmd)
} else if (cmd == "_t") { } else if (cmd == "_t") {
NSpecial::Test(); NSpecial::Test();
} else if (cmd == "p2d") { // new after 2.3.6b, undocumented
NSpecial::export_p2d(SMem::instance()->overwrite);
} else if (cmd == "qui" || cmd == "quit") { } else if (cmd == "qui" || cmd == "quit") {
exit(0); exit(0);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <yaml-cpp/yaml.h> #include <yaml-cpp/yaml.h>
#include "../readplus/ask.hpp" #include "../readplus/ask.hpp"
#include "../trivia/file_ops.hpp"
#include "../trivia/yaml_out.hpp" #include "../trivia/yaml_out.hpp"
#include "file_out.hpp" #include "file_out.hpp"
...@@ -47,13 +48,8 @@ void NFileOut::save(string fmt, bool allow_overwrite) ...@@ -47,13 +48,8 @@ void NFileOut::save(string fmt, bool allow_overwrite)
// document file save // document file save
f->log_action("fs " + outfnam + " # " + triv::time2strg(time(0))); f->log_action("fs " + outfnam + " # " + triv::time2strg(time(0)));
// prevent unintended overwriting // prevent unintended overwriting
if (!allow_overwrite) { if (!allow_overwrite && triv::file_exists(outfnam))
FILE* file; throw "file " + outfnam + " exists, use command modifier '!' to overwrite";
if ((file = fopen(outfnam.c_str(), "r"))) {
fclose(file);
throw "file " + outfnam + " exists, use fso to overwrite";
}
}
// save file // save file
if (fmt == "yda") { if (fmt == "yda") {
std::ofstream ofs; std::ofstream ofs;
......
...@@ -158,6 +158,14 @@ string CObjVecObj::to_s(int maxlen, int minlen, int prec) const ...@@ -158,6 +158,14 @@ string CObjVecObj::to_s(int maxlen, int minlen, int prec) const
return ret; return ret;
} }
vector<double> CObjVecObj::to_rvec() const
{
vector<double> ret(size());
for (int i = 0; i < v.size(); ++i)
ret[i] = v[i]->to_r();
return ret;
}
//************************************************************************************************** //**************************************************************************************************
// CObjVecInt // CObjVecInt
//************************************************************************************************** //**************************************************************************************************
......
...@@ -153,6 +153,7 @@ public: ...@@ -153,6 +153,7 @@ public:
inline string result_info() const { return to_s(); } inline string result_info() const { return to_s(); }
inline RObj to_obj(int i) const { return v[i]; } inline RObj to_obj(int i) const { return v[i]; }
string to_s(int maxlen = 12, int minlen = 1, int prec = 6) const; string to_s(int maxlen = 12, int minlen = 1, int prec = 6) const;
vector<double> to_rvec() const;
RObj to_vecnum() const; RObj to_vecnum() const;
}; };
......
...@@ -102,6 +102,14 @@ void COlo::check_integrity() const ...@@ -102,6 +102,14 @@ void COlo::check_integrity() const
RObj COlo::z(int j, int iz) const { return V[j]->z[iz]; } RObj COlo::z(int j, int iz) const { return V[j]->z[iz]; }
//! Return vector of iz-th z-variables.
RObjVecObj COlo::zvec(int iz) const {
PObjVecObj ret(new CObjVecObj(nJ()));
for (size_t j=0; j<nJ(); ++j)
ret->v[j] = V[j]->z[iz];
return ret;
}
//************************************************************************************************** //**************************************************************************************************
//* COld/COlc (member functions that are similar for both classes) //* COld/COlc (member functions that are similar for both classes)
......
...@@ -47,6 +47,7 @@ public: ...@@ -47,6 +47,7 @@ public:
int nJ() const { return V.size(); } int nJ() const { return V.size(); }
int nZ() const { return ZCo.size(); } int nZ() const { return ZCo.size(); }
RObj z(int j, int iz) const; RObj z(int j, int iz) const;
RObjVecObj zvec(int iz) const;
virtual PSlice copy_slice(int j) const = 0; virtual PSlice copy_slice(int j) const = 0;
virtual POlo new_POlo() const = 0; virtual POlo new_POlo() const = 0;
virtual CCoord coord(const CGenus& genus) const = 0; virtual CCoord coord(const CGenus& genus) const = 0;
......
...@@ -9,10 +9,14 @@ ...@@ -9,10 +9,14 @@
#include "defs.hpp" #include "defs.hpp"
#include <fstream>
#include <vector>
#include <fftw3.h> #include <fftw3.h>
#include <boost/format.hpp>
#include "../trivia/file_ops.hpp"
#include "../trivia/vector_ops.hpp"
#include "../readplus/ask.hpp"
#include "fsel.hpp" #include "fsel.hpp"
#include "loop.hpp" #include "loop.hpp"
#include "mem.hpp" #include "mem.hpp"
...@@ -21,6 +25,9 @@ ...@@ -21,6 +25,9 @@
#include "slice.hpp" #include "slice.hpp"
#include "special.hpp" #include "special.hpp"
using boost::format;
using std::vector;
namespace NSpecial namespace NSpecial
{ {
void q_eval(double* par, int m_dat, double* fvec, void* data, int* info); void q_eval(double* par, int m_dat, double* fvec, void* data, int* info);
...@@ -97,3 +104,38 @@ void NSpecial::Test() ...@@ -97,3 +104,38 @@ void NSpecial::Test()
} }
SMem::instance()->mem_store(move(fout)); SMem::instance()->mem_store(move(fout));
} }
//! Experimental 2d plot
void NSpecial::export_p2d(bool allow_overwrite)
{ // EMBEDDED_DIALOG
string outfnam;
FileIterator fiter(SFSel::instance()->selD());
while (COld* f = fiter.nextD()) {
size_t m = f->nJ();
if (m<2)
throw "2d plot requires at least 2 slices";
// query output file name
outfnam = wask("Export to (.p2d)", f->name);
if (outfnam == "")
return;
f->name = outfnam;
outfnam += ".p2d";
// document file save
if (!allow_overwrite && triv::file_exists(outfnam))
throw "file " + outfnam + " exists, use flag ! to overwrite";
std::ofstream ofs;
ofs.open(outfnam, std::ofstream::out);
vector<double> zval = f->zvec(0)->to_rvec();
vector<double> zlim = triv::histogram_limits(zval);
for (size_t j=0; j<m; ++j) {
const CSpec* s = f->VS(j);
vector<double> xlim = triv::histogram_limits(s->x);
for (size_t i=0; i<s->size(); ++i)
ofs << ( format("%13.7g wx %13.7g wx %13.7g wz %13.7g wz %13.7g wy p2d\n")
% xlim[i] % xlim[i+1] % zlim[j] % zlim[j+1] % s->y[i] );
ofs << "\n";
}
ofs.close();
}
}
...@@ -20,6 +20,7 @@ namespace NSpecial ...@@ -20,6 +20,7 @@ namespace NSpecial
{ {
void FourierCosine(); void FourierCosine();
void Test(); void Test();
void export_p2d(bool allow_overwrite);
template <typename T> complex<T> pssc(T z) template <typename T> complex<T> pssc(T z)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment