7.6 Make another data

MGL command: subdata RES dat xx [yy=all zz=all]
Method on mglData: mglData SubData (mreal xx, mreal yy=-1, mreal zz=-1) const
Method on mglDataC: mglData SubData (mreal xx, mreal yy=-1, mreal zz=-1) const
C function: HMDT mgl_data_subdata (HCDT dat, mreal xx, mreal yy, mreal zz)

Extracts sub-array data from the original data array keeping fixed positive index. For example SubData(-1,2) extracts 3d row (indexes are zero based), SubData(4,-1) extracts 5th column, SubData(-1,-1,3) extracts 4th slice and so on. If argument(s) are non-integer then linear interpolation between slices is used. In MGL version this command usually is used as inline one dat(xx,yy,zz). Function return NULL or create empty data if data cannot be created for given arguments.

MGL command: subdata RES dat xdat [ydat zdat]
Method on mglData: mglData SubData (const mglDataA &xx, const mglDataA &yy, const mglDataA &zz) const
Method on mglDataC: mglData SubData (const mglDataA &xx, const mglDataA &yy, const mglDataA &zz) const
Method on mglData: mglData SubData (const mglDataA &xx, const mglDataA &yy) const
Method on mglDataC: mglData SubData (const mglDataA &xx, const mglDataA &yy) const
Method on mglData: mglData SubData (const mglDataA &xx) const
Method on mglDataC: mglData SubData (const mglDataA &xx) const
C function: HMDT mgl_data_subdata_ext (HCDT dat, HCDT xx, HCDT yy, HCDT zz)
C function: HADT mgl_datac_subdata_ext (HCDT dat, HCDT xx, HCDT yy, HCDT zz)

Extracts sub-array data from the original data array for indexes specified by arrays xx, yy, zz (indirect access). This function work like previous one for 1D arguments or numbers, and resulting array dimensions are equal dimensions of 1D arrays for corresponding direction. For 2D and 3D arrays in arguments, the resulting array have the same dimensions as input arrays. The dimensions of all argument must be the same (or to be scalar 1*1*1) if they are 2D or 3D arrays. In MGL version this command usually is used as inline one dat(xx,yy,zz). Function return NULL or create empty data if data cannot be created for given arguments. In C function some of xx, yy, zz can be NULL.

MGL command: column RES dat 'eq'
Method on mglData: mglData Column (const char *eq) const
Method on mglDataC: mglData Column (const char *eq) const
C function: HMDT mgl_data_column (HCDT dat, const char *eq)

Get column (or slice) of the data filled by formula eq on column ids. For example, Column("n*w^2/exp(t)");. The column ids must be defined first by idset function or read from files. In MGL version this command usually is used as inline one dat('eq'). Function return NULL or create empty data if data cannot be created for given arguments.

MGL command: resize RES dat mx [my=1 mz=1]
Method on mglData: mglData Resize (int mx, int my=0, int mz=0, mreal x1=0, mreal x2=1, mreal y1=0, mreal y2=1, mreal z1=0, mreal z2=1) const
Method on mglDataC: mglData Resize (int mx, int my=0, int mz=0, mreal x1=0, mreal x2=1, mreal y1=0, mreal y2=1, mreal z1=0, mreal z2=1) const
C function: HMDT mgl_data_resize (HCDT dat, int mx, int my, int mz)
C function: HMDT mgl_data_resize_box (HCDT dat, int mx, int my, int mz, mreal x1, mreal x2, mreal y1, mreal y2, mreal z1, mreal z2)

Resizes the data to new size mx, my, mz from box (part) [x1,x2] x [y1,y2] x [z1,z2] of original array. Initially x,y,z coordinates are supposed to be in [0,1]. If one of sizes mx, my or mz is 0 then initial size is used. Function return NULL or create empty data if data cannot be created for given arguments.

MGL command: evaluate RES dat idat [norm=on]
MGL command: evaluate RES dat idat jdat [norm=on]
MGL command: evaluate RES dat idat jdat kdat [norm=on]
Method on mglData: mglData Evaluate (const mglDataA &idat, bool norm=true) const
Method on mglData: mglData Evaluate (const mglDataA &idat, const mglDataA &jdat, bool norm=true) const
Method on mglData: mglData Evaluate (const mglDataA &idat, const mglDataA &jdat, const mglDataA &kdat, bool norm=true) const
Method on mglDataC: mglData Evaluate (const mglDataA &idat, bool norm=true) const
Method on mglDataC: mglData Evaluate (const mglDataA &idat, const mglDataA &jdat, bool norm=true) const
Method on mglDataC: mglData Evaluate (const mglDataA &idat, const mglDataA &jdat, const mglDataA &kdat, bool norm=true) const
C function: HMDT mgl_data_evaluate (HCDT dat, HCDT idat, HCDT jdat, HCDT kdat, int norm)

Gets array which values is result of interpolation of original array for coordinates from other arrays. All dimensions must be the same for data idat, jdat, kdat. Coordinates from idat, jdat, kdat are supposed to be normalized in range [0,1] (if norm=true) or in ranges [0,nx], [0,ny], [0,nz] correspondingly. Function return NULL or create empty data if data cannot be created for given arguments.

MGL command: section RES dat ids ['dir'='y' val=nan]
MGL command: section RES dat id ['dir'='y' val=nan]
Method on mglData: mglData Section (const mglDataA &ids, const char *dir='y', mreal val=NAN) const
Method on mglData: mglData Section (long id, const char *dir='y', mreal val=NAN) const
Method on mglDataC: mglData Section (const mglDataA &ids, const char *dir='y', mreal val=NAN) const
Method on mglDataC: mglData Section (long id, const char *dir='y', mreal val=NAN) const
C function: HMDT mgl_data_section (HCDT dat, HCDT ids, const char *dir, mreal val)
C function: HMDT mgl_data_section_val (HCDT dat, long id, const char *dir, mreal val)
C function: HADT mgl_datac_section (HCDT dat, HCDT ids, const char *dir, mreal val)
C function: HADT mgl_datac_section_val (HCDT dat, long id, const char *dir, mreal val)

Gets array which is id-th section (range of slices separated by value val) of original array dat. For id<0 the reverse order is used (i.e. -1 give last section). If several ids are provided then output array will be result of sequential joining of sections.

MGL command: solve RES dat val 'dir' [norm=on]
MGL command: solve RES dat val 'dir' idat [norm=on]
Method on mglData: mglData Solve (mreal val, char dir, bool norm=true) const
Method on mglData: mglData Solve (mreal val, char dir, const mglDataA &idat, bool norm=true) const
C function: HMDT mgl_data_solve (HCDT dat, mreal val, char dir, HCDT idat, int norm)

Gets array which values is indexes (roots) along given direction dir, where interpolated values of data dat are equal to val. Output data will have the sizes of dat in directions transverse to dir. If data idat is provided then its values are used as starting points. This allows one to find several branches by consequentive calls. Indexes are supposed to be normalized in range [0,1] (if norm=true) or in ranges [0,nx], [0,ny], [0,nz] correspondingly. Function return NULL or create empty data if data cannot be created for given arguments. See Solve sample, for sample code and picture.

MGL command: roots RES 'func' ini ['var'='x']
MGL command: roots RES 'func' ini ['var'='x']
Method on mglData: mglData Roots (const char *func, char var) const
C function: HMDT mgl_data_roots (const char *func, HCDT ini, char var)
C function: mreal mgl_find_root_txt (const char *func, mreal ini, char var)

Find roots of equation ’func’=0 for variable var with initial guess ini. Secant method is used for root finding. Function return NULL or create empty data if data cannot be created for given arguments.

MGL command: roots RES 'funcs' 'vars' ini
Method on mglData: mglData MultiRoots (const char *funcs, const char *vars) const
Method on mglDataC: mglDataC MultiRoots (const char *funcs, const char *vars) const
C function: HMDT mgl_find_roots_txt (const char *func, const char *vars, HCDT ini)
C function: HADT mgl_find_roots_txt_c (const char *func, const char *vars, HCDT ini)

Find roots of system of equations ’funcs’=0 for variables vars with initial guesses ini. Secant method is used for root finding. Function return NULL or create empty data if data cannot be created for given arguments.

MGL command: detect RES dat lvl dj [di=0 minlen=0]
Method on mglData: mglData Detect (mreal lvl, mreal dj, mreal di=0, mreal minlen=0) const
C function: HMDT mgl_data_detect (HCDT dat, mreal lvl, mreal dj, mreal di, mreal minlen)

Get curves {x,y}, separated by NAN values, for local maximal values of array dat as function of x-coordinate. Noises below lvl amplitude are ignored. Parameter dj (in range [0,ny]) set the "attraction" y-distance of points to the curve. Similarly, di continue curve in x-direction through gaps smaller than di points. Curves with minimal length smaller than minlen will be ignored.

MGL command: hist RES dat n v1 v2 [nsub=0]
MGL command: hist RES dat wdat n v1 v2 [nsub=0]
Method on mglData: mglData Hist (int n, mreal v1=0, mreal v2=1, int nsub=0) const
Method on mglData: mglData Hist (const mglDataA &w, int n, mreal v1=0, mreal v2=1, int nsub=0) const
Method on mglDataC: mglData Hist (int n, mreal v1=0, mreal v2=1, int nsub=0) const
Method on mglDataC: mglData Hist (const mglDataA &w, int n, mreal v1=0, mreal v2=1, int nsub=0) const
C function: HMDT mgl_data_hist (HCDT dat, int n, mreal v1, mreal v2, int nsub)
C function: HMDT mgl_data_hist_w (HCDT dat, HCDT w, int n, mreal v1, mreal v2, int nsub)

Creates n-th points distribution of the data values in range [v1, v2]. Array w specifies weights of the data elements (by default is 1). Parameter nsub define the number of additional interpolated points (for smoothness of histogram). If nsub<0 then linear interpolation is used instead of spline one. Function return NULL or create empty data if data cannot be created for given arguments. See also histl, Data manipulation

MGL command: histl RES dat n v1 v2
MGL command: histl RES dat wdat n v1 v2
Method on mglData: mglData HistL (int n, mreal v1=0, mreal v2=1) const
Method on mglData: mglData HistL (const mglDataA &w, int n, mreal v1=0, mreal v2=1) const
Method on mglDataC: mglData HistL (int n, mreal v1=0, mreal v2=1) const
Method on mglDataC: mglData HistL (const mglDataA &w, int n, mreal v1=0, mreal v2=1) const
C function: HMDT mgl_data_hist_l (HCDT dat, HCDT w, int n, mreal v1, mreal v2)

Creates n-th points distribution of the data values in range [v1, v2] using linear interpolation between data points. Array w specifies weights of the data elements (by default is 1). Function return NULL or create empty data if data cannot be created for given arguments. See also hist, Data manipulation

MGL command: momentum RES dat 'how' ['dir'='z']
Method on mglData: mglData Momentum (char dir, const char *how) const
Method on mglDataC: mglData Momentum (char dir, const char *how) const
C function: HMDT mgl_data_momentum (HCDT dat, char dir, const char *how)

Gets momentum (1d-array) of the data along direction dir. String how contain kind of momentum. The momentum is defined like as res_k = \sum_ij how(x_i,y_j,z_k) a_ij/ \sum_ij a_ij if dir=‘z’ and so on. Coordinates ‘x’, ‘y’, ‘z’ are data indexes normalized in range [0,1]. Function return NULL or create empty data if data cannot be created for given arguments.

MGL command: sum RES dat 'dir'
Method on mglData: mglData Sum (const char *dir) const
Method on mglDataC: mglData Sum (const char *dir) const
C function: HMDT mgl_data_sum (HCDT dat, const char *dir)

Gets array which is the result of summation in given direction or direction(s). Function return NULL or create empty data if data cannot be created for given arguments.

MGL command: max RES dat 'dir'
Method on mglData: mglData Max (const char *dir) const
Method on mglDataC: mglData Max (const char *dir) const
C function: HMDT mgl_data_max_dir (HCDT dat, const char *dir)

Gets array which is the maximal data values in given direction or direction(s). Function return NULL or create empty data if data cannot be created for given arguments.

MGL command: min RES dat 'dir'
Method on mglData: mglData Min (const char *dir) const
Method on mglDataC: mglData Min (const char *dir) const
C function: HMDT mgl_data_min_dir (HCDT dat, const char *dir)

Gets array which is the maximal data values in given direction or direction(s). Function return NULL or create empty data if data cannot be created for given arguments.

MGL command: minmax RES dat
Method on mglData: mglData MinMax () const
C function: HMDT mgl_data_minmax (HCDT dat)

Gets positions of local maximums and minimums. Function return NULL or create empty data if there is no minimums and maximums.

MGL command: conts RES val dat
Method on mglData: mglData Conts (mreal val) const
C function: HMDT mgl_data_conts (mreal val, HCDT dat)

Gets coordinates of contour lines for dat[i,j]=val. NAN values separate the the curves. Function return NULL or create empty data if there is contour lines.

MGL command: combine RES adat bdat
Method on mglData: mglData Combine (const mglDataA &a) const
Method on mglDataC: mglData Combine (const mglDataA &a) const
C function: HMDT mgl_data_combine (HCDT dat, HCDT a)

Returns direct multiplication of arrays (like, res[i,j] = this[i]*a[j] and so on). Function return NULL or create empty data if data cannot be created for given arguments.

MGL command: trace RES dat
Method on mglData: mglData Trace () const
Method on mglDataC: mglData Trace () const
C function: HMDT mgl_data_trace (HCDT dat)

Gets array of diagonal elements a[i,i] (for 2D case) or a[i,i,i] (for 3D case) where i=0...nx-1. Function return copy of itself for 1D case. Data array must have dimensions ny,nz >= nx or ny,nz = 1. Function return NULL or create empty data if data cannot be created for given arguments.

MGL command: correl RES adat bdat 'dir'
Method on mglData: mglData Correl (const mglDataA &b, const char *dir) const
Method on mglData: mglData AutoCorrel (const char *dir) const
Method on mglDataC: mglDataC Correl (const mglDataA &b, const char *dir) const
Method on mglDataC: mglDataC AutoCorrel (const char *dir) const
C function: HMDT mgl_data_correl (HCDT a, HCDT b, const char *dir)
C function: HADT mgl_datac_correl (HCDT a, HCDT b, const char *dir)

Find correlation between data a (or this in C++) and b along directions dir. Fourier transform is used to find the correlation. So, you may want to use functions swap or norm before plotting it. Function return NULL or create empty data if data cannot be created for given arguments.

Method on mglDataC: mglData Real () const
C function: HMDT mgl_datac_real (HCDT dat)

Gets array of real parts of the data.

Method on mglDataC: mglData Imag () const
C function: HMDT mgl_datac_imag (HCDT dat)

Gets array of imaginary parts of the data.

Method on mglDataC: mglData Abs () const
C function: HMDT mgl_datac_abs (HCDT dat)

Gets array of absolute values of the data.

Method on mglDataC: mglData Arg () const
C function: HMDT mgl_datac_arg (HCDT dat)

Gets array of arguments of the data.

MGL command: pulse RES dat 'dir'
Method on mglData: mglData Pulse (const char *dir) const
C function: HMDT mgl_data_pulse (HCDT dat, const char *dir)

Find pulse properties along direction dir: pulse maximum (in column 0) and its position (in column 1), pulse width near maximum (in column 3) and by half height (in column 2), energy in first pulse (in column 4). NAN values are used for widths if maximum is located near the edges. Note, that there is uncertainty for complex data. Usually one should use square of absolute value (i.e. |dat[i]|^2) for them. So, MathGL don’t provide this function for complex data arrays. However, C function will work even in this case but use absolute value (i.e. |dat[i]|). Function return NULL or create empty data if data cannot be created for given arguments. See also max, min, momentum, sum. See Pulse properties, for sample code and picture.

MGL command: first RES dat 'dir' val
Method on mglData: mglData First (const char *dir, mreal val) const
Method on mglDataC: mglData First (const char *dir, mreal val) const
C function: HMDT mgl_data_first_dir (HCDT dat, const char *dir, mreal val)

Get array of positions of first value large val. For complex data the absolute value is used. See also last.

MGL command: last RES dat 'dir' val
Method on mglData: mglData Last (const char *dir, mreal val) const
Method on mglDataC: mglData Last (const char *dir, mreal val) const
C function: HMDT mgl_data_last_dir (HCDT dat, const char *dir, mreal val)

Get array of positions of last value large val. For complex data the absolute value is used. See also first.

C function: HMDT mgl_formula_calc (const char *str, long n, ...)
C function: HADT mgl_formula_calc_c (const char *str, long n, ...)

Evaluate formula str for the given list of n data arrays of type HCDT. Variable names correspond to data names. You need to delete returned data array after usage! See also fill.