-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool-skyfit.cpp
160 lines (152 loc) · 7.41 KB
/
tool-skyfit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include "busybox.hpp"
#include "tfield_io.hpp"
#include "fitting.hpp"
#include "filtering.hpp"
#include "newdisplay.hpp"
#include "files.hpp"
#include "lib-png.hpp"
#include "filepath.hpp"
#include <iomanip>
int skyfit_tool_main(int argc,char **argv){
if (argc==1){
std::cout << "USO:" << std::endl;
std::cout << " programa timestep fichero.txt fichero1.vf fichero2.vf ... fichero_n.vf" << std::endl;
return 1;
}
double timestep;
const unsigned int entries = 13;// 9+4
std::stringstream(argv[1]) >> timestep;
std::string outfile = std::string(argv[2]);
std::vector<std::string> paths(argv+3,argv+argc);
std::vector<float> data;
data.resize(paths.size()*entries);
// template <typename T>
//rcl::pair<rcl::tpoint<T>,rcl::tpoint<T> > get_skyrmion_sizes(const rcl::tfield<rcl::tvector<T> >& mag)
for (unsigned int idx=0;idx<paths.size();idx++){
std::string infile = paths[idx];
rcl::ffield mag;
rcl::load_vecfile(mag,infile);
rcl::pair<rcl::tpoint<float>,rcl::tpoint<float> > fit = rcl::get_skyrmion_sizes(mag);
std::cout << infile << std::endl;
data[entries*idx+0] = (idx-2) * timestep;
data[entries*idx+1] = fit.x().x()*mag.getsize().x();
data[entries*idx+2] = fit.x().y()*mag.getsize().y();
data[entries*idx+3] = fit.y().x()*mag.getsize().x();
data[entries*idx+4] = fit.y().y()*mag.getsize().x();
if (idx>1) {
data[entries*idx+5] = (data[entries*idx+1] - data[entries*(idx-1)+1])/timestep;
data[entries*idx+6] = (data[entries*idx+2] - data[entries*(idx-1)+2])/timestep;
data[entries*idx+7] = (data[entries*idx+3] - data[entries*(idx-1)+3])/timestep;
data[entries*idx+8] = (data[entries*idx+4] - data[entries*(idx-1)+4])/timestep;
data[entries*idx+9] = std::sqrt(std::pow((data[entries*idx+1] - data[entries*(idx-1)+1]),2) + std::pow((data[entries*idx+2] - data[entries*(idx-1)+2]),2));
data[entries*idx+10] = data[entries*(idx-1)+10] + data[entries*idx+9] ;
data[entries*idx+11] = data[entries*idx+9]/timestep;
data[entries*idx+12] = data[entries*idx+10]/(data[entries*idx+0]+timestep);
}
else{
data[entries*idx+10] =0;
data[entries*idx+9] = 0;
}
}
std::fstream ofs(outfile,std::fstream::out|std::fstream::binary);
for (unsigned int idx=2;idx<paths.size();idx++){
ofs << std::setw(12) << data[entries*idx+0] << ' ';
ofs << std::setw(12) << data[entries*idx+1] << ' ';
ofs << std::setw(12) << data[entries*idx+2] << ' ';
ofs << std::setw(12) << data[entries*idx+3] << ' ';
ofs << std::setw(12) << data[entries*idx+4] << ' ';
ofs << std::setw(12) << data[entries*idx+5] << ' ';
ofs << std::setw(12) << data[entries*idx+6] << ' ';
ofs << std::setw(12) << data[entries*idx+7] << ' ';
ofs << std::setw(12) << data[entries*idx+8] << ' ';
ofs << std::setw(12) << data[entries*idx+9] << ' ';
ofs << std::setw(12) << data[entries*idx+10] << ' ';
ofs << std::setw(12) << data[entries*idx+11] << ' ';
ofs << std::setw(12) << data[entries*idx+12] << std::endl;
}
return 0;
}
static rcl::reg_app reg1("skyfit_tool",skyfit_tool_main);
int skyfit_zoom_tool_main(int argc,char **argv){
if (argc==1){
std::cout << "USO:" << std::endl;
std::cout << " programa timestep fichero.txt fichero1.vf fichero2.vf ... fichero_n.vf" << std::endl;
return 1;
}
double timestep;
const unsigned int entries = 13;// 9+4
std::stringstream(argv[1]) >> timestep;
std::string outfile = std::string(argv[2]);
std::vector<std::string> paths(argv+3,argv+argc);
std::vector<float> data;
data.resize(paths.size()*entries);
// template <typename T>
//rcl::pair<rcl::tpoint<T>,rcl::tpoint<T> > get_skyrmion_sizes(const rcl::tfield<rcl::tvector<T> >& mag)
for (unsigned int idx=0;idx<paths.size();idx++){
std::string infile = paths[idx];
rcl::ffield mag;
rcl::load_vecfile(mag,infile);
rcl::FilePath fp(infile);
rcl::pair<rcl::tpoint<float>,rcl::tpoint<float> > fit = rcl::get_skyrmion_sizes(mag);
rcl::Flat_Neel_Skyrmion<float> fsky;
fsky.getnodes() = rcl::utriad(mag.getnodes().y(),mag.getnodes().y(),1);
fsky.getcells() = rcl::ftriad(0.5,0.5,1);
fsky.getpos() = rcl::fpoint(0.25*mag.getnodes().y(),0.25*mag.getnodes().y());
fsky.getrdw() = fit.y();
rcl::ffield sfit = fsky.render_field();
rcl::image32 skyplot_full(mag.getnodes().x()+mag.getnodes().y(),mag.getnodes().y());
rcl::image32 skyplot_mag = rcl::display_field(mag,0,"nrainbow");
rcl::image32 skyplot_sky = rcl::display_field(sfit,0,"urainbow");
skyplot_full.put(skyplot_mag,rcl::upoint(0,0));
skyplot_full.put(skyplot_sky,rcl::upoint(mag.getnodes().x(),0));
std::vector<unsigned char> vfdata;
std::vector<unsigned char> pngdata;
//rcl::crush_vf(vfdata,fsky.render_field(),rcl::vf_crush_cfg(1,1,0));
rcl::encode_png(pngdata,skyplot_full);
float hpeak=0,lpeak=1;
for (unsigned int idx=0;idx<sfit.size();idx++) if (sfit[idx].norm2()>hpeak) hpeak=sfit[idx].norm2();
for (unsigned int idx=0;idx<sfit.size();idx++) if (sfit[idx].norm2()<lpeak) lpeak=sfit[idx].norm2();
rcl::save_file(fp.GetRoot()+".s.png",pngdata);
//rcl::save_file(fp.GetRoot()+".s.vf",vfdata);
std::cout << infile << " r="<< fsky.getrdw().x() << " , d=" << fsky.getrdw().y() ;
std::cout << " @ " <<fsky.getpos().x() << "," << fsky.getpos().y() ;
std::cout << " peaks=" << lpeak << "," << hpeak << "(" << hpeak-lpeak << ")" << std::endl;
data[entries*idx+0] = (idx-2) * timestep;
data[entries*idx+1] = fit.x().x()*mag.getsize().x();
data[entries*idx+2] = fit.x().y()*mag.getsize().y();
data[entries*idx+3] = fit.y().x()*mag.getsize().x();
data[entries*idx+4] = fit.y().y()*mag.getsize().x();
if (idx>1) {
data[entries*idx+5] = (data[entries*idx+1] - data[entries*(idx-1)+1])/timestep;
data[entries*idx+6] = (data[entries*idx+2] - data[entries*(idx-1)+2])/timestep;
data[entries*idx+7] = (data[entries*idx+3] - data[entries*(idx-1)+3])/timestep;
data[entries*idx+8] = (data[entries*idx+4] - data[entries*(idx-1)+4])/timestep;
data[entries*idx+9] = std::sqrt(std::pow((data[entries*idx+1] - data[entries*(idx-1)+1]),2) + std::pow((data[entries*idx+2] - data[entries*(idx-1)+2]),2));
data[entries*idx+10] = data[entries*(idx-1)+10] + data[entries*idx+9] ;
data[entries*idx+11] = data[entries*idx+9]/timestep;
data[entries*idx+12] = data[entries*idx+10]/(data[entries*idx+0]+timestep);
}
else{
data[entries*idx+10] =0;
data[entries*idx+9] = 0;
}
}
std::fstream ofs(outfile,std::fstream::out|std::fstream::binary);
for (unsigned int idx=2;idx<paths.size();idx++){
ofs << std::setw(12) << data[entries*idx+0] << ' ';
ofs << std::setw(12) << data[entries*idx+1] << ' ';
ofs << std::setw(12) << data[entries*idx+2] << ' ';
ofs << std::setw(12) << data[entries*idx+3] << ' ';
ofs << std::setw(12) << data[entries*idx+4] << ' ';
ofs << std::setw(12) << data[entries*idx+5] << ' ';
ofs << std::setw(12) << data[entries*idx+6] << ' ';
ofs << std::setw(12) << data[entries*idx+7] << ' ';
ofs << std::setw(12) << data[entries*idx+8] << ' ';
ofs << std::setw(12) << data[entries*idx+9] << ' ';
ofs << std::setw(12) << data[entries*idx+10] << ' ';
ofs << std::setw(12) << data[entries*idx+11] << ' ';
ofs << std::setw(12) << data[entries*idx+12] << std::endl;
}
return 0;
}
static rcl::reg_app reg2("skyfit_tool_zoom",skyfit_zoom_tool_main);