mathgl 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06c2518dd4b16e32817d24c3054fa990a7e28d24
4
- data.tar.gz: cab0f32cbff4470f915dbd23641e0e534c170d5a
3
+ metadata.gz: 88f676dd949dc3aad0984447f5a44be418f235a4
4
+ data.tar.gz: 7884864681617c80757b14e494c0cf5ebf0f7841
5
5
  SHA512:
6
- metadata.gz: 00e0c8554df34bdff058186560d5494494aea69ef4639e9f9c5c3e1ec6b5dadd1ae365f80c79ee27e31a36b9ad7d7f2e0764d1e97d50391d45cd17195e7c68fb
7
- data.tar.gz: 0ca0a37b016680e584f0f40a92f2ec630c346cbc4b6a7ad0904acff6528d2f5e2e61a88c4d7df991f5a0e885cf3d2d53b0e72fde3759785de2f556066e6eebea
6
+ metadata.gz: e4fdc6f900da1cdd5e7df788d559bd83a59d2679fdd28350fa41f5c0cc77c39fa6a7097388c6508805266e50db4f76556c69e69b7bb099eea240efe656574bb4
7
+ data.tar.gz: 226c6f868654dca0b0cafdc916667c31352c6f4ba2ab518bd4e9ea4eb8c45ee94b0d00eadcb971be88f80c7e3f506b6328fa0da1b9410a4dfd09ad53abd14967
data/.gitignore CHANGED
@@ -39,3 +39,4 @@ ext/mathgl/fltk.cxx
39
39
  ext/mathgl/glut.cxx
40
40
  ext/mathgl/mathgl.so
41
41
  ext/mathgl/Makefile
42
+ ext/mathgl/.RUBYARCHDIR.time
data/README.md CHANGED
@@ -7,6 +7,7 @@ MathGL is a library for scientific data visualization developed by Alexey Balaki
7
7
  (This package is under construction.)
8
8
 
9
9
  - [Plot Samples](https://github.com/masa16/ruby-mathgl-sample)
10
+ ([Single page](https://github.com/masa16/ruby-mathgl-sample/blob/master/single_page/README.md))
10
11
  - [API Document](http://masa16.github.io/ruby-mathgl/doc/frames.html)
11
12
  - [GitHub](https://github.com/masa16/ruby-mathgl)
12
13
  - [RubyGems](https://rubygems.org/gems/mathgl)
@@ -27,7 +28,7 @@ MathGL is a library for scientific data visualization developed by Alexey Balaki
27
28
 
28
29
  ## Usage
29
30
 
30
- Write to PNG
31
+ Write a plot to PNG file:
31
32
 
32
33
  require 'mathgl'
33
34
 
@@ -44,7 +45,7 @@ Write to PNG
44
45
  gr.instance_eval(&prc)
45
46
  gr.write_png("test.png","",false)
46
47
 
47
- Qt window:
48
+ Display a plot on Qt window:
48
49
 
49
50
  require 'mathgl'
50
51
 
data/ext/mathgl/data.i ADDED
@@ -0,0 +1,507 @@
1
+ /***************************************************************************
2
+ * data.i is part of Math Graphic Library
3
+ * Copyright (C) 2007-2012 Alexey Balakin <mathgl.abalakin@gmail.ru> *
4
+ * *
5
+ * This program is free software; you can redistribute it and/or modify *
6
+ * it under the terms of the GNU Library General Public License as *
7
+ * published by the Free Software Foundation; either version 3 of the *
8
+ * License, or (at your option) any later version. *
9
+ * *
10
+ * This program is distributed in the hope that it will be useful, *
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
+ * GNU General Public License for more details. *
14
+ * *
15
+ * You should have received a copy of the GNU Library General Public *
16
+ * License along with this program; if not, write to the *
17
+ * Free Software Foundation, Inc., *
18
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
+ ***************************************************************************/
20
+ //-----------------------------------------------------------------------------
21
+ #include <string>
22
+ class mglData
23
+ {
24
+ public:
25
+
26
+ long nx; ///< number of points in 1st dimensions ('x' dimension)
27
+ long ny; ///< number of points in 2nd dimensions ('y' dimension)
28
+ long nz; ///< number of points in 3d dimensions ('z' dimension)
29
+ mreal *a; ///< data array
30
+ std::string id; ///< column (or slice) names
31
+ bool link; ///< use external data (i.e. don't free it)
32
+
33
+ /// Initiate by other mglData variable
34
+ mglData(const mglData &d) { a=0; mgl_data_set(this,&d); } // NOTE: must be constructor for mglData& to exclude copy one
35
+ mglData(const mglData *d) { a=0; mgl_data_set(this, d); }
36
+ mglData(bool, mglData *d) // NOTE: Variable d will be deleted!!!
37
+ { if(d)
38
+ { nx=d->nx; ny=d->ny; nz=d->nz; a=d->a; d->a=0;
39
+ id=d->id; link=d->link; delete d; }
40
+ else { a=0; Create(1); } }
41
+ /// Initiate by flat array
42
+ mglData(int size, const float *d) { a=0; Set(d,size); }
43
+ mglData(int rows, int cols, const float *d) { a=0; Set(d,cols,rows); }
44
+ mglData(int size, const double *d) { a=0; Set(d,size); }
45
+ mglData(int rows, int cols, const double *d) { a=0; Set(d,cols,rows); }
46
+ mglData(const double *d, int size) { a=0; Set(d,size); }
47
+ mglData(const double *d, int rows, int cols) { a=0; Set(d,cols,rows); }
48
+ mglData(const float *d, int size) { a=0; Set(d,size); }
49
+ mglData(const float *d, int rows, int cols) { a=0; Set(d,cols,rows); }
50
+ /// Read data from file
51
+ mglData(const char *fname) { a=0; Read(fname); }
52
+ /// Allocate the memory for data array and initialize it zero
53
+ mglData(long xx=1,long yy=1,long zz=1) { a=0; Create(xx,yy,zz); }
54
+ /// Delete the array
55
+ virtual ~mglData() { if(!link && a) delete []a; }
56
+
57
+ inline mreal GetVal(long i, long j=0, long k=0) const
58
+ { return mgl_data_get_value(this,i,j,k);}
59
+ inline void SetVal(mreal f, long i, long j=0, long k=0)
60
+ { mgl_data_set_value(this,f,i,j,k); }
61
+ /// Get sizes
62
+ long GetNx() const { return nx; }
63
+ long GetNy() const { return ny; }
64
+ long GetNz() const { return nz; }
65
+
66
+ /// Link external data array (don't delete it at exit)
67
+ inline void Link(mreal *A, long NX, long NY=1, long NZ=1)
68
+ { mgl_data_link(this,A,NX,NY,NZ); }
69
+ inline void Link(mglData &d) { Link(d.a,d.nx,d.ny,d.nz); }
70
+ /// Allocate memory and copy the data from the gsl_vector
71
+ inline void Set(gsl_vector *m) { mgl_data_set_vector(this,m); }
72
+ /// Allocate memory and copy the data from the gsl_matrix
73
+ inline void Set(gsl_matrix *m) { mgl_data_set_matrix(this,m); }
74
+
75
+ /// Allocate memory and copy the data from the (float *) array
76
+ inline void Set(const float *A,long NX,long NY=1,long NZ=1)
77
+ { mgl_data_set_float(this,A,NX,NY,NZ); }
78
+ /// Allocate memory and copy the data from the (double *) array
79
+ inline void Set(const double *A,long NX,long NY=1,long NZ=1)
80
+ { mgl_data_set_double(this,A,NX,NY,NZ); }
81
+ /// Allocate memory and copy the data from the (float **) array
82
+ inline void Set(float const * const *A,long N1,long N2)
83
+ { mgl_data_set_float2(this,A,N1,N2); }
84
+ /// Allocate memory and copy the data from the (double **) array
85
+ inline void Set(double const * const *A,long N1,long N2)
86
+ { mgl_data_set_double2(this,A,N1,N2); }
87
+ /// Allocate memory and copy the data from the (float ***) array
88
+ inline void Set(float const * const * const *A,long N1,long N2,long N3)
89
+ { mgl_data_set_float3(this,A,N1,N2,N3); }
90
+ /// Allocate memory and copy the data from the (double ***) array
91
+ inline void Set(double const * const * const *A,long N1,long N2,long N3)
92
+ { mgl_data_set_double3(this,A,N1,N2,N3); }
93
+ /// Allocate memory and scanf the data from the string
94
+ inline void Set(const char *str,long NX,long NY=1,long NZ=1)
95
+ { mgl_data_set_values(this,str,NX,NY,NZ); }
96
+ /// Import data from abstract type
97
+ inline void Set(const mglData &dat) { mgl_data_set(this, &dat); }
98
+
99
+ /// Create or recreate the array with specified size and fill it by zero
100
+ inline void Create(long mx,long my=1,long mz=1)
101
+ { mgl_data_create(this,mx,my,mz); }
102
+ /// Rearange data dimensions
103
+ inline void Rearrange(long mx, long my=0, long mz=0)
104
+ { mgl_data_rearrange(this,mx,my,mz); }
105
+ /// Transpose dimensions of the data (generalization of Transpose)
106
+ inline void Transpose(const char *dim="yx")
107
+ { mgl_data_transpose(this,dim); }
108
+ /// Extend data dimensions
109
+ inline void Extend(long n1, long n2=0)
110
+ { mgl_data_extend(this,n1,n2); }
111
+ /// Reduce size of the data
112
+ inline void Squeeze(long rx,long ry=1,long rz=1,bool smooth=false)
113
+ { mgl_data_squeeze(this,rx,ry,rz,smooth); }
114
+ /// Crop the data
115
+ inline void Crop(long n1, long n2,char dir='x')
116
+ { mgl_data_crop(this,n1,n2,dir); }
117
+ /// Insert data rows/columns/slices
118
+ inline void Insert(char dir, long at=0, long num=1)
119
+ { mgl_data_insert(this,dir,at,num); }
120
+ /// Delete data rows/columns/slices
121
+ inline void Delete(char dir, long at=0, long num=1)
122
+ { mgl_data_delete(this,dir,at,num); }
123
+ /// Remove rows with duplicate values in column id
124
+ inline void Clean(long id)
125
+ { mgl_data_clean(this,id); }
126
+ /// Join with another data array
127
+ inline void Join(const mglData &d)
128
+ { mgl_data_join(this,&d); }
129
+
130
+ /// Modify the data by specified formula
131
+ inline void Modify(const char *eq,long dim=0)
132
+ { mgl_data_modify(this, eq, dim); }
133
+ /// Modify the data by specified formula
134
+ inline void Modify(const char *eq,const mglData &vdat, const mglData &wdat)
135
+ { mgl_data_modify_vw(this,eq,&vdat,&wdat); }
136
+ /// Modify the data by specified formula
137
+ inline void Modify(const char *eq,const mglData &vdat)
138
+ { mgl_data_modify_vw(this,eq,&vdat,0); }
139
+ /// Modify the data by specified formula assuming x,y,z in range [r1,r2]
140
+ inline void Fill(HMGL gr, const char *eq, const char *opt="")
141
+ { mgl_data_fill_eq(gr,this,eq,0,0,opt); }
142
+ inline void Fill(HMGL gr, const char *eq, const mglData &vdat, const char *opt="")
143
+ { mgl_data_fill_eq(gr,this,eq,&vdat,0,opt); }
144
+ inline void Fill(HMGL gr, const char *eq, const mglData &vdat, const mglData &wdat,const char *opt="")
145
+ { mgl_data_fill_eq(gr,this,eq,&vdat,&wdat,opt); }
146
+ /// Equidistantly fill the data to range [x1,x2] in direction dir
147
+ inline void Fill(mreal x1,mreal x2=NaN,char dir='x')
148
+ { mgl_data_fill(this,x1,x2,dir); }
149
+ /// Fill the data by interpolated values of vdat parametrically depended on xdat,ydat,zdat for x,y,z in range [p1,p2] using global spline
150
+ inline void RefillGS(const mglData &xdat, const mglData &vdat, mreal x1, mreal x2,long sl=-1)
151
+ { mgl_data_refill_gs(this,&xdat,&vdat,x1,x2,sl); }
152
+ /// Fill the data by interpolated values of vdat parametrically depended on xdat,ydat,zdat for x,y,z in range [p1,p2]
153
+ inline void Refill(const mglData &xdat, const mglData &vdat, mreal x1, mreal x2,long sl=-1)
154
+ { mgl_data_refill_x(this,&xdat,&vdat,x1,x2,sl); }
155
+ inline void Refill(const mglData &xdat, const mglData &vdat, mglPoint p1, mglPoint p2,long sl=-1)
156
+ { mgl_data_refill_x(this,&xdat,&vdat,p1.x,p2.x,sl); }
157
+ inline void Refill(const mglData &xdat, const mglData &ydat, const mglData &vdat, mglPoint p1, mglPoint p2,long sl=-1)
158
+ { mgl_data_refill_xy(this,&xdat,&ydat,&vdat,p1.x,p2.x,p1.y,p2.y,sl); }
159
+ inline void Refill(const mglData &xdat, const mglData &ydat, const mglData &zdat, const mglData &vdat, mglPoint p1, mglPoint p2)
160
+ { mgl_data_refill_xyz(this,&xdat,&ydat,&zdat,&vdat,p1.x,p2.x,p1.y,p2.y,p1.z,p2.z); }
161
+ /// Fill the data by interpolated values of vdat parametrically depended on xdat,ydat,zdat for x,y,z in axis range of gr
162
+ inline void Refill(HMGL gr, const mglData &xdat, const mglData &vdat, long sl=-1, const char *opt="")
163
+ { mgl_data_refill_gr(gr,this,&xdat,0,0,&vdat,sl,opt); }
164
+ inline void Refill(HMGL gr, const mglData &xdat, const mglData &ydat, const mglData &vdat, long sl=-1, const char *opt="")
165
+ { mgl_data_refill_gr(gr,this,&xdat,&ydat,0,&vdat,sl,opt); }
166
+ inline void Refill(HMGL gr, const mglData &xdat, const mglData &ydat, const mglData &zdat, const mglData &vdat, const char *opt="")
167
+ { mgl_data_refill_gr(gr,this,&xdat,&ydat,&zdat,&vdat,-1,opt); }
168
+ /// Set the data by triangulated surface values assuming x,y,z in axis range of gr
169
+ inline void Grid(HMGL gr, const mglData &x, const mglData &y, const mglData &z, const char *opt="")
170
+ { mgl_data_grid(gr,this,&x,&y,&z,opt); }
171
+ /// Set the data by triangulated surface values assuming x,y,z in range [p1, p2]
172
+ inline void Grid(const mglData &xdat, const mglData &ydat, const mglData &vdat, mglPoint p1, mglPoint p2)
173
+ { mgl_data_grid_xy(this,&xdat,&ydat,&vdat,p1.x,p2.x,p1.y,p2.y); }
174
+ /// Put value to data element(s)
175
+ inline void Put(mreal val, long i=-1, long j=-1, long k=-1)
176
+ { mgl_data_put_val(this,val,i,j,k); }
177
+ /// Put array to data element(s)
178
+ inline void Put(const mglData &dat, long i=-1, long j=-1, long k=-1)
179
+ { mgl_data_put_dat(this,&dat,i,j,k); }
180
+ /// Set names for columns (slices)
181
+ inline void SetColumnId(const char *ids)
182
+ { mgl_data_set_id(this,ids); }
183
+ /// Make new id
184
+ inline void NewId() { id.clear(); }
185
+
186
+ /// Read data from tab-separated text file with auto determining size
187
+ inline bool Read(const char *fname)
188
+ { return mgl_data_read(this,fname); }
189
+ /// Read data from text file with specifeid size
190
+ inline bool Read(const char *fname,long mx,long my=1,long mz=1)
191
+ { return mgl_data_read_dim(this,fname,mx,my,mz); }
192
+ /// Save whole data array (for ns=-1) or only ns-th slice to text file
193
+ inline void Save(const char *fname,long ns=-1) const
194
+ { mgl_data_save(this,fname,ns); }
195
+ /// Export data array (for ns=-1) or only ns-th slice to PNG file according color scheme
196
+ inline void Export(const char *fname,const char *scheme,mreal v1=0,mreal v2=0,long ns=-1) const
197
+ { mgl_data_export(this,fname,scheme,v1,v2,ns); }
198
+ /// Import data array from PNG file according color scheme
199
+ inline void Import(const char *fname,const char *scheme,mreal v1=0,mreal v2=1)
200
+ { mgl_data_import(this,fname,scheme,v1,v2); }
201
+ /// Read data from tab-separated text files with auto determining size which filenames are result of sprintf(fname,templ,t) where t=from:step:to
202
+ inline bool ReadRange(const char *templ, double from, double to, double step=1, bool as_slice=false)
203
+ { return mgl_data_read_range(this,templ,from,to,step,as_slice); }
204
+ /// Read data from tab-separated text files with auto determining size which filenames are satisfied to template (like "t_*.dat")
205
+ inline bool ReadAll(const char *templ, bool as_slice=false)
206
+ { return mgl_data_read_all(this, templ, as_slice); }
207
+ /// Read data from text file with size specified at beginning of the file
208
+ inline bool ReadMat(const char *fname, long dim=2)
209
+ { return mgl_data_read_mat(this,fname,dim); }
210
+ /// Read data array from HDF file (parse HDF4 and HDF5 files)
211
+ inline int ReadHDF(const char *fname,const char *data)
212
+ { return mgl_data_read_hdf(this,fname,data); }
213
+ /// Save data to HDF file
214
+ inline void SaveHDF(const char *fname,const char *data,bool rewrite=false) const
215
+ { mgl_data_save_hdf(this,fname,data,rewrite); }
216
+ /// Put HDF data names into buf as '\t' separated.
217
+ inline static int DatasHDF(const char *fname, char *buf, long size)
218
+ { return mgl_datas_hdf(fname,buf,size); }
219
+
220
+ /// Get column (or slice) of the data filled by formulas of named columns
221
+ inline mglData Column(const char *eq) const
222
+ { return mglData(true,mgl_data_column(this,eq)); }
223
+ /// Get momentum (1D-array) of data along direction 'dir'. String looks like "x1" for median in x-direction, "x2" for width in x-dir and so on.
224
+ inline mglData Momentum(char dir, const char *how) const
225
+ { return mglData(true,mgl_data_momentum(this,dir,how)); }
226
+ /// Get sub-array of the data with given fixed indexes
227
+ inline mglData SubData(long xx,long yy=-1,long zz=-1) const
228
+ { return mglData(true,mgl_data_subdata(this,xx,yy,zz)); }
229
+ inline mglData SubData(const mglData &xx, const mglData &yy, const mglData &zz) const
230
+ { return mglData(true,mgl_data_subdata_ext(this,&xx,&yy,&zz)); }
231
+ inline mglData SubData(const mglData &xx, const mglData &yy) const
232
+ { return mglData(true,mgl_data_subdata_ext(this,&xx,&yy,0)); }
233
+ inline mglData SubData(const mglData &xx) const
234
+ { return mglData(true,mgl_data_subdata_ext(this,&xx,0,0)); }
235
+ /// Get trace of the data array
236
+ inline mglData Trace() const
237
+ { return mglData(true,mgl_data_trace(this)); }
238
+ /// Create n-th points distribution of this data values in range [v1, v2]
239
+ inline mglData Hist(long n,mreal v1=0,mreal v2=1, long nsub=0) const
240
+ { return mglData(true,mgl_data_hist(this,n,v1,v2,nsub)); }
241
+ /// Create n-th points distribution of this data values in range [v1, v2] with weight w
242
+ inline mglData Hist(const mglData &w, long n,mreal v1=0,mreal v2=1, long nsub=0) const
243
+ { return mglData(true,mgl_data_hist_w(this,&w,n,v1,v2,nsub)); }
244
+ /// Get array which is result of summation in given direction or directions
245
+ inline mglData Sum(const char *dir) const
246
+ { return mglData(true,mgl_data_sum(this,dir)); }
247
+ /// Get array which is result of maximal values in given direction or directions
248
+ inline mglData Max(const char *dir) const
249
+ { return mglData(true,mgl_data_max_dir(this,dir)); }
250
+ /// Get array which is result of minimal values in given direction or directions
251
+ inline mglData Min(const char *dir) const
252
+ { return mglData(true,mgl_data_min_dir(this,dir)); }
253
+ /// Get the data which is direct multiplication (like, d[i,j] = this[i]*a[j] and so on)
254
+ inline mglData Combine(const mglData &dat) const
255
+ { return mglData(true,mgl_data_combine(this,&dat)); }
256
+ /// Resize the data to new size of box [x1,x2]*[y1,y2]*[z1,z2]
257
+ inline mglData Resize(long mx,long my=0,long mz=0, mreal x1=0,mreal x2=1, mreal y1=0,mreal y2=1, mreal z1=0,mreal z2=1) const
258
+ { return mglData(true,mgl_data_resize_box(this,mx,my,mz,x1,x2,y1,y2,z1,z2)); }
259
+ /// Get array which values is result of interpolation this for coordinates from other arrays
260
+ inline mglData Evaluate(const mglData &idat, bool norm=true) const
261
+ { return mglData(true,mgl_data_evaluate(this,&idat,0,0,norm)); }
262
+ inline mglData Evaluate(const mglData &idat, const mglData &jdat, bool norm=true) const
263
+ { return mglData(true,mgl_data_evaluate(this,&idat,&jdat,0,norm)); }
264
+ inline mglData Evaluate(const mglData &idat, const mglData &jdat, const mglData &kdat, bool norm=true) const
265
+ { return mglData(true,mgl_data_evaluate(this,&idat,&jdat,&kdat,norm)); }
266
+ /// Find roots for set of nonlinear equations defined by textual formula
267
+ inline mglData Roots(const char *func, char var='x') const
268
+ { return mglData(true,mgl_data_roots(func, this, var)); }
269
+ /// Find correlation with another data arrays
270
+ inline mglData Correl(const mglData &dat, const char *dir) const
271
+ { return mglData(true,mgl_data_correl(this,&dat,dir)); }
272
+ /// Find auto correlation function
273
+ inline mglData AutoCorrel(const char *dir) const
274
+ { return mglData(true,mgl_data_correl(this,this,dir)); }
275
+
276
+ /// Cumulative summation the data in given direction or directions
277
+ inline void CumSum(const char *dir) { mgl_data_cumsum(this,dir); }
278
+ /// Integrate (cumulative summation) the data in given direction or directions
279
+ inline void Integral(const char *dir) { mgl_data_integral(this,dir); }
280
+ /// Differentiate the data in given direction or directions
281
+ inline void Diff(const char *dir) { mgl_data_diff(this,dir); }
282
+ /// Differentiate the parametrically specified data along direction v1 with v2=const
283
+ inline void Diff(const mglData &v1, const mglData &v2)
284
+ { mgl_data_diff_par(this,&v1,&v2,0); }
285
+ /// Differentiate the parametrically specified data along direction v1 with v2,v3=const
286
+ inline void Diff(const mglData &v1, const mglData &v2, const mglData &v3)
287
+ { mgl_data_diff_par(this,&v1,&v2,&v3); }
288
+ /// Double-differentiate (like Laplace operator) the data in given direction
289
+ inline void Diff2(const char *dir) { mgl_data_diff2(this,dir); }
290
+
291
+ /// Swap left and right part of the data in given direction (useful for Fourier spectrum)
292
+ inline void Swap(const char *dir) { mgl_data_swap(this,dir); }
293
+ /// Roll data along direction dir by num slices
294
+ inline void Roll(char dir, long num) { mgl_data_roll(this,dir,num); }
295
+ /// Mirror the data in given direction (useful for Fourier spectrum)
296
+ inline void Mirror(const char *dir) { mgl_data_mirror(this,dir); }
297
+ /// Sort rows (or slices) by values of specified column
298
+ inline void Sort(long idx, long idy=-1) { mgl_data_sort(this,idx,idy); }
299
+
300
+ /// Set as the data envelop
301
+ inline void Envelop(char dir='x')
302
+ { mgl_data_envelop(this,dir); }
303
+ /// Remove phase jump
304
+ inline void Sew(const char *dirs="xyz", mreal da=2*Pi)
305
+ { mgl_data_sew(this,dirs,da); }
306
+ /// Smooth the data on specified direction or directions
307
+ inline void Smooth(const char *dirs="xyz",mreal delta=0)
308
+ { mgl_data_smooth(this,dirs,delta); }
309
+ /// Normalize the data to range [v1,v2]
310
+ inline void Norm(mreal v1=0,mreal v2=1,bool sym=false,long dim=0)
311
+ { mgl_data_norm(this,v1,v2,sym,dim); }
312
+ /// Normalize the data to range [v1,v2] slice by slice
313
+ inline void NormSl(mreal v1=0,mreal v2=1,char dir='z',bool keep_en=true,bool sym=false)
314
+ { mgl_data_norm_slice(this,v1,v2,dir,keep_en,sym); }
315
+
316
+ /// Apply Hankel transform
317
+ inline void Hankel(const char *dir) { mgl_data_hankel(this,dir); }
318
+ /// Apply Sin-Fourier transform
319
+ inline void SinFFT(const char *dir) { mgl_data_sinfft(this,dir); }
320
+ /// Apply Cos-Fourier transform
321
+ inline void CosFFT(const char *dir) { mgl_data_cosfft(this,dir); }
322
+ /// Fill data by 'x'/'k' samples for Hankel ('h') or Fourier ('f') transform
323
+ inline void FillSample(const char *how)
324
+ { mgl_data_fill_sample(this,how); }
325
+
326
+ /// Return an approximated x-value (root) when dat(x) = val
327
+ inline mreal Solve(mreal val, bool use_spline=true, long i0=0) const
328
+ { return mgl_data_solve_1d(this, val, use_spline, i0); }
329
+ /// Return an approximated value (root) when dat(x) = val
330
+ inline mglData Solve(mreal val, char dir, bool norm=true) const
331
+ { return mglData(true,mgl_data_solve(this, val, dir, 0, norm)); }
332
+ inline mglData Solve(mreal val, char dir, const mglData &i0, bool norm=true) const
333
+ { return mglData(true,mgl_data_solve(this, val, dir, &i0, norm)); }
334
+
335
+ /// Interpolate by cubic spline the data to given point x=[0...nx-1], y=[0...ny-1], z=[0...nz-1]
336
+ inline mreal Spline(mreal x,mreal y=0,mreal z=0) const
337
+ { return mgl_data_spline(this, x,y,z); }
338
+ /// Interpolate by cubic spline the data to given point x,\a y,\a z which normalized in range [0, 1]
339
+ inline mreal Spline1(mreal x,mreal y=0,mreal z=0) const
340
+ { return mgl_data_spline(this, x*(nx-1),y*(ny-1),z*(nz-1)); }
341
+ /// Interpolate by linear function the data to given point x=[0...nx-1], y=[0...ny-1], z=[0...nz-1]
342
+ inline mreal Linear(mreal x,mreal y=0,mreal z=0) const
343
+ { return mgl_data_linear(this,x,y,z); }
344
+ /// Interpolate by line the data to given point x,\a y,\a z which normalized in range [0, 1]
345
+ inline mreal Linear1(mreal x,mreal y=0,mreal z=0) const
346
+ { return mgl_data_linear(this,x*(nx-1),y*(ny-1),z*(nz-1)); }
347
+
348
+ /// Interpolate by cubic spline the data and return its derivatives at given point x=[0...nx-1], y=[0...ny-1], z=[0...nz-1]
349
+ inline mreal Spline(mglPoint &dif, mreal x,mreal y=0,mreal z=0) const
350
+ { return mgl_data_spline_ext(this, x,y,z, &(dif.x),&(dif.y), &(dif.z)); }
351
+ /// Interpolate by cubic spline the data and return its derivatives at given point x,\a y,\a z which normalized in range [0, 1]
352
+ inline mreal Spline1(mglPoint &dif, mreal x,mreal y=0,mreal z=0) const
353
+ { mreal res=mgl_data_spline_ext(this, x*(nx-1),y*(ny-1),z*(nz-1), &(dif.x),&(dif.y), &(dif.z));
354
+ dif.x*=nx>1?nx-1:1; dif.y*=ny>1?ny-1:1; dif.z*=nz>1?nz-1:1; return res; }
355
+ /// Interpolate by linear function the data and return its derivatives at given point x=[0...nx-1], y=[0...ny-1], z=[0...nz-1]
356
+ inline mreal Linear(mglPoint &dif, mreal x,mreal y=0,mreal z=0) const
357
+ { return mgl_data_linear_ext(this,x,y,z, &(dif.x),&(dif.y), &(dif.z)); }
358
+ /// Interpolate by line the data and return its derivatives at given point x,\a y,\a z which normalized in range [0, 1]
359
+ inline mreal Linear1(mglPoint &dif, mreal x,mreal y=0,mreal z=0) const
360
+ { mreal res=mgl_data_linear_ext(this,x*(nx-1),y*(ny-1),z*(nz-1), &(dif.x),&(dif.y), &(dif.z));
361
+ dif.x*=nx>1?nx-1:1; dif.y*=ny>1?ny-1:1; dif.z*=nz>1?nz-1:1; return res; }
362
+
363
+ /// Get information about the data (sizes and momentum) to string
364
+ inline const char *PrintInfo() const { return mgl_data_info(this); }
365
+ /// Print information about the data (sizes and momentum) to FILE (for example, stdout)
366
+ inline void PrintInfo(FILE *fp) const
367
+ { if(fp) { fprintf(fp,"%s",mgl_data_info(this)); fflush(fp); } }
368
+ /// Get maximal value of the data
369
+ inline mreal Maximal() const { return mgl_data_max(this); }
370
+ /// Get minimal value of the data
371
+ inline mreal Minimal() const { return mgl_data_min(this); }
372
+ /// Get maximal value of the data which is less than 0
373
+ inline mreal MaximalNeg() const { return mgl_data_neg_max(this); }
374
+ /// Get minimal value of the data which is larger than 0
375
+ inline mreal MinimalPos() const { return mgl_data_pos_min(this); }
376
+ /// Get maximal value of the data and its position
377
+ inline mreal Maximal(long &i,long &j,long &k) const
378
+ { return mgl_data_max_int(this,&i,&j,&k); }
379
+ /// Get minimal value of the data and its position
380
+ inline mreal Minimal(long &i,long &j,long &k) const
381
+ { return mgl_data_min_int(this,&i,&j,&k); }
382
+ /// Get maximal value of the data and its approximated position
383
+ inline mreal Maximal(mreal &x,mreal &y,mreal &z) const
384
+ { return mgl_data_max_real(this,&x,&y,&z); }
385
+ /// Get minimal value of the data and its approximated position
386
+ inline mreal Minimal(mreal &x,mreal &y,mreal &z) const
387
+ { return mgl_data_min_real(this,&x,&y,&z); }
388
+ /// Get "energy" and find first (median) and second (width) momenta of data
389
+ inline mreal Momentum(char dir,mreal &m,mreal &w) const
390
+ { return mgl_data_momentum_val(this,dir,&m,&w,0,0); }
391
+ /// Get "energy and find 4 momenta of data: median, width, skewness, kurtosis
392
+ inline mreal Momentum(char dir,mreal &m,mreal &w,mreal &s,mreal &k) const
393
+ { return mgl_data_momentum_val(this,dir,&m,&w,&s,&k); }
394
+ /// Find position (after specified in i,j,k) of first nonzero value of formula
395
+ inline mreal Find(const char *cond, long &i, long &j, long &k) const
396
+ { return mgl_data_first(this,cond,&i,&j,&k); }
397
+ /// Find position (before specified in i,j,k) of last nonzero value of formula
398
+ inline mreal Last(const char *cond, long &i, long &j, long &k) const
399
+ { return mgl_data_last(this,cond,&i,&j,&k); }
400
+ /// Find position of first in direction 'dir' nonzero value of formula
401
+ inline long Find(const char *cond, char dir, long i=0, long j=0, long k=0) const
402
+ { return mgl_data_find(this,cond,dir,i,j,k); }
403
+ /// Find if any nonzero value of formula
404
+ inline bool FindAny(const char *cond) const
405
+ { return mgl_data_find_any(this,cond); }
406
+
407
+ /// Copy data from other mglData variable
408
+ inline const mglData &operator=(const mglData &d)
409
+ { if(this!=&d) mgl_data_set(this,&d); return d; }
410
+ inline mreal operator=(mreal val)
411
+ { mgl_data_fill(this,val,val,'x'); return val; }
412
+ /// Multiply the data by other one for each element
413
+ inline void operator*=(const mglData &d) { mgl_data_mul_dat(this,&d); }
414
+ /// Divide the data by other one for each element
415
+ inline void operator/=(const mglData &d) { mgl_data_div_dat(this,&d); }
416
+ /// Add the other data
417
+ inline void operator+=(const mglData &d) { mgl_data_add_dat(this,&d); }
418
+ /// Subtract the other data
419
+ inline void operator-=(const mglData &d) { mgl_data_sub_dat(this,&d); }
420
+ /// Multiply each element by the number
421
+ inline void operator*=(mreal d) { mgl_data_mul_num(this,d); }
422
+ /// Divide each element by the number
423
+ inline void operator/=(mreal d) { mgl_data_div_num(this,d); }
424
+ /// Add the number
425
+ inline void operator+=(mreal d) { mgl_data_add_num(this,d); }
426
+ /// Subtract the number
427
+ inline void operator-=(mreal d) { mgl_data_sub_num(this,d); }
428
+ };
429
+ //-----------------------------------------------------------------------------
430
+ /// Integral data transformation (like Fourier 'f' or 'i', Hankel 'h' or None 'n') for amplitude and phase
431
+ inline mglData mglTransformA(const mglData &am, const mglData &ph, const char *tr)
432
+ { return mglData(true,mgl_transform_a(&am,&ph,tr)); }
433
+ /// Integral data transformation (like Fourier 'f' or 'i', Hankel 'h' or None 'n') for real and imaginary parts
434
+ inline mglData mglTransform(const mglData &re, const mglData &im, const char *tr)
435
+ { return mglData(true,mgl_transform(&re,&im,tr)); }
436
+ /// Apply Fourier transform for the data and save result into it
437
+ inline void mglFourier(mglData &re, mglData &im, const char *dir)
438
+ { mgl_data_fourier(&re,&im,dir); }
439
+ /// Short time Fourier analysis for real and imaginary parts. Output is amplitude of partial Fourier (result will have size {dn, floor(nx/dn), ny} for dir='x'
440
+ inline mglData mglSTFA(const mglData &re, const mglData &im, long dn, char dir='x')
441
+ { return mglData(true, mgl_data_stfa(&re,&im,dn,dir)); }
442
+ //-----------------------------------------------------------------------------
443
+ /// Saves result of PDE solving (|u|^2) for "Hamiltonian" ham with initial conditions ini
444
+ inline mglData mglPDE(HMGL gr, const char *ham, const mglData &ini_re, const mglData &ini_im, mreal dz=0.1, mreal k0=100,const char *opt="")
445
+ { return mglData(true, mgl_pde_solve(gr,ham, &ini_re, &ini_im, dz, k0,opt)); }
446
+ /// Saves result of PDE solving for "Hamiltonian" ham with initial conditions ini along a curve ray (must have nx>=7 - x,y,z,px,py,pz,tau or nx=5 - x,y,px,py,tau)
447
+ inline mglData mglQO2d(const char *ham, const mglData &ini_re, const mglData &ini_im, const mglData &ray, mreal r=1, mreal k0=100)
448
+ { return mglData(true, mgl_qo2d_solve(ham, &ini_re, &ini_im, &ray, r, k0, 0, 0)); }
449
+ inline mglData mglQO2d(const char *ham, const mglData &ini_re, const mglData &ini_im, const mglData &ray, mglData &xx, mglData &yy, mreal r=1, mreal k0=100)
450
+ { return mglData(true, mgl_qo2d_solve(ham, &ini_re, &ini_im, &ray, r, k0, &xx, &yy)); }
451
+ /// Saves result of PDE solving for "Hamiltonian" ham with initial conditions ini along a curve ray (must have nx>=7 - x,y,z,px,py,pz,tau or nx=5 - x,y,px,py,tau)
452
+ inline mglData mglQO3d(const char *ham, const mglData &ini_re, const mglData &ini_im, const mglData &ray, mreal r=1, mreal k0=100)
453
+ { return mglData(true, mgl_qo3d_solve(ham, &ini_re, &ini_im, &ray, r, k0, 0, 0, 0)); }
454
+ inline mglData mglQO3d(const char *ham, const mglData &ini_re, const mglData &ini_im, const mglData &ray, mglData &xx, mglData &yy, mglData &zz, mreal r=1, mreal k0=100)
455
+ { return mglData(true, mgl_qo3d_solve(ham, &ini_re, &ini_im, &ray, r, k0, &xx, &yy, &zz)); }
456
+ /// Finds ray with starting point r0, p0 (and prepares ray data for mglQO2d)
457
+ inline mglData mglRay(const char *ham, mglPoint r0, mglPoint p0, mreal dt=0.1, mreal tmax=10)
458
+ { return mglData(true, mgl_ray_trace(ham, r0.x, r0.y, r0.z, p0.x, p0.y, p0.z, dt, tmax)); }
459
+ /// Saves result of ODE solving (|u|^2) for "Hamiltonian" ham with initial conditions ini
460
+ inline mglData mglODE(const char *df, const char *var, const mglData &ini, mreal dt=0.1, mreal tmax=10)
461
+ { return mglData(true, mgl_ode_solve_str(df,var, &ini, dt, tmax)); }
462
+ /// Calculate Jacobian determinant for D{x(u,v), y(u,v)} = dx/du*dy/dv-dx/dv*dy/du
463
+ inline mglData mglJacobian(const mglData &x, const mglData &y)
464
+ { return mglData(true, mgl_jacobian_2d(&x, &y)); }
465
+ /// Calculate Jacobian determinant for D{x(u,v,w), y(u,v,w), z(u,v,w)}
466
+ inline mglData mglJacobian(const mglData &x, const mglData &y, const mglData &z)
467
+ { return mglData(true, mgl_jacobian_3d(&x, &y, &z)); }
468
+ /// Do something like Delone triangulation
469
+ inline mglData mglTriangulation(const mglData &x, const mglData &y, const mglData &z)
470
+ { return mglData(true,mgl_triangulation_3d(&x,&y,&z)); }
471
+ inline mglData mglTriangulation(const mglData &x, const mglData &y)
472
+ { return mglData(true,mgl_triangulation_2d(&x,&y)); }
473
+ //-----------------------------------------------------------------------------
474
+ /// Get sub-array of the data with given fixed indexes
475
+ inline mglData mglSubData(const mglData &dat, long xx, long yy=-1, long zz=-1)
476
+ { return mglData(true,mgl_data_subdata(&dat,xx,yy,zz)); }
477
+ inline mglData mglSubData(const mglData &dat, const mglData &xx, const mglData &yy, const mglData &zz)
478
+ { return mglData(true,mgl_data_subdata_ext(&dat,&xx,&yy,&zz)); }
479
+ inline mglData mglSubData(const mglData &dat, const mglData &xx, const mglData &yy)
480
+ { return mglData(true,mgl_data_subdata_ext(&dat,&xx,&yy,0)); }
481
+ inline mglData mglSubData(const mglData &dat, const mglData &xx)
482
+ { return mglData(true,mgl_data_subdata_ext(&dat,&xx,0,0)); }
483
+ //-----------------------------------------------------------------------------
484
+ /// Prepare coefficients for global spline interpolation
485
+ inline mglData mglGSplineInit(const mglData &xdat, const mglData &ydat)
486
+ { return mglData(true,mgl_gspline_init(&xdat, &ydat)); }
487
+ /// Evaluate global spline (and its derivatives d1, d2 if not NULL) using prepared coefficients \a coef
488
+ inline mreal mglGSpline(const mglData &coef, mreal dx, mreal *d1=0, mreal *d2=0)
489
+ { return mgl_gspline(&coef, dx, d1,d2); }
490
+ //-----------------------------------------------------------------------------
491
+ /// Wrapper class for expression evaluating
492
+ class mglExpr
493
+ {
494
+ HMEX ex;
495
+ mglExpr(const mglExpr &){} // copying is not allowed
496
+ const mglExpr &operator=(const mglExpr &t){return t;} // copying is not allowed
497
+ public:
498
+ mglExpr(const char *expr) { ex = mgl_create_expr(expr); }
499
+ ~mglExpr() { mgl_delete_expr(ex); }
500
+ /// Return value of expression for given x,y,z variables
501
+ inline double Eval(double x, double y=0, double z=0)
502
+ { return mgl_expr_eval(ex,x,y,z); }
503
+ /// Return value of expression differentiation over variable dir for given x,y,z variables
504
+ inline double Diff(char dir, double x, double y=0, double z=0)
505
+ { return mgl_expr_diff(ex,dir, x,y,z); }
506
+ };
507
+ //-----------------------------------------------------------------------------