7.7 Data changing

These functions change the data in some direction like differentiations, integrations and so on. The direction in which the change will applied is specified by the string parameter, which may contain ‘x’, ‘y’ or ‘z’ characters for 1-st, 2-nd and 3-d dimension correspondingly.

MGL command: cumsum dat 'dir'
Method on mglData: void CumSum (const char *dir)
Method on mglDataC: void CumSum (const char *dir)
C function: void mgl_data_cumsum (HMDT dat, const char *dir)
C function: void mgl_datac_cumsum (HADT dat, const char *dir)

Cumulative summation of the data in given direction or directions.

MGL command: integrate dat 'dir'
Method on mglData: void Integral (const char *dir)
Method on mglDataC: void Integral (const char *dir)
C function: void mgl_data_integral (HMDT dat, const char *dir)
C function: void mgl_datac_integral (HADT dat, const char *dir)

Integrates (like cumulative summation) the data in given direction or directions.

MGL command: diff dat 'dir'
Method on mglData: void Diff (const char *dir)
Method on mglDataC: void Diff (const char *dir)
C function: void mgl_data_diff (HMDT dat, const char *dir)
C function: void mgl_datac_diff (HADT dat, const char *dir)

Differentiates the data in given direction or directions.

MGL command: diff dat xdat ydat [zdat]
Method on mglData: void Diff (const mglDataA &x)
Method on mglData: void Diff (const mglDataA &x, const mglDataA &y)
Method on mglData: void Diff (const mglDataA &x, const mglDataA &y, const mglDataA &z)
Method on mglDataC: void Diff (const mglDataA &x)
Method on mglDataC: void Diff (const mglDataA &x, const mglDataA &y)
Method on mglDataC: void Diff (const mglDataA &x, const mglDataA &y, const mglDataA &z)
C function: void mgl_data_diff_par (HMDT dat, HCDT x, HCDTy, HCDTz)
C function: void mgl_datac_diff_par (HADT dat, HCDT x, HCDTy, HCDTz)

Differentiates the data specified parametrically in direction x with y, z=constant. Parametrical differentiation uses the formula (for 2D case): da/dx = (a_j*y_i-a_i*y_j)/(x_j*y_i-x_i*y_j) where a_i=da/di, a_j=da/dj denotes usual differentiation along 1st and 2nd dimensions. The similar formula is used for 3D case. Note, that you may change the order of arguments – for example, if you have 2D data a(i,j) which depend on coordinates {x(i,j), y(i,j)} then usual derivative along ‘x’ will be Diff(x,y); and usual derivative along ‘y’ will be Diff(y,x);.

MGL command: diff2 dat 'dir'
Method on mglData: void Diff2 (const char *dir)
Method on mglDataC: void Diff2 (const char *dir)
C function: void mgl_data_diff2 (HMDT dat, const char *dir)
C function: void mgl_datac_diff2 (HADT dat, const char *dir)

Double-differentiates (like Laplace operator) the data in given direction.

MGL command: sinfft dat 'dir'
Method on mglData: void SinFFT (const char *dir)
C function: void mgl_data_sinfft (HMDT dat, const char *dir)

Do Sine transform of the data in given direction or directions. The Sine transform is \sum a_j \sin(k j) (see http://en.wikipedia.org/wiki/Discrete_sine_transform#DST-I).

MGL command: cosfft dat 'dir'
Method on mglData: void CosFFT (const char *dir)
C function: void mgl_data_cosfft (HMDT dat, const char *dir)

Do Cosine transform of the data in given direction or directions. The Cosine transform is \sum a_j \cos(k j) (see http://en.wikipedia.org/wiki/Discrete_cosine_transform#DCT-I).

Method on mglDataC: void FFT (const char *dir)
C function: void mgl_datac_fft (HADT dat, const char *dir)

Do Fourier transform of the data in given direction or directions. If dir contain ‘i’ then inverse Fourier is used. The Fourier transform is \sum a_j \exp(i k j) (see http://en.wikipedia.org/wiki/Discrete_Fourier_transform).

MGL command: hankel dat 'dir'
Method on mglData: void Hankel (const char *dir)
Method on mglDataC: void Hankel (const char *dir)
C function: void mgl_data_hankel (HMDT dat, const char *dir)
C function: void mgl_datac_hankel (HADT dat, const char *dir)

Do Hankel transform of the data in given direction or directions. The Hankel transform is \sum a_j J_0(k j) (see http://en.wikipedia.org/wiki/Hankel_transform).

MGL command: wavelet dat 'dir' k
Method on mglData: void Wavelet (const char *dir, int k)
C function: void mgl_data_wavelet (HMDT dat, const char *dir, int k)

Apply wavelet transform of the data in given direction or directions. Parameter dir set the kind of wavelet transform: ‘d’ for daubechies, ‘D’ for centered daubechies, ‘h’ for haar, ‘H’ for centered haar, ‘b’ for bspline, ‘B’ for centered bspline. If string dir contain symbol ‘i’ then inverse wavelet transform is applied. Parameter k set the size of wavelet transform.

MGL command: swap dat 'dir'
Method on mglData: void Swap (const char *dir)
Method on mglDataC: void Swap (const char *dir)
C function: void mgl_data_swap (HMDT dat, const char *dir)
C function: void mgl_datac_swap (HADT dat, const char *dir)

Swaps the left and right part of the data in given direction (useful for Fourier spectrum).

MGL command: roll dat 'dir' num
Method on mglData: void Roll (char dir, num)
Method on mglDataC: void Roll (char dir, num)
C function: void mgl_data_roll (HMDT dat, char dir, num)
C function: void mgl_datac_roll (HADT dat, char dir, num)

Rolls the data along direction dir. Resulting array will be out[i] = ini[(i+num)%nx] if dir='x'.

MGL command: mirror dat 'dir'
Method on mglData: void Mirror (const char *dir)
Method on mglDataC: void Mirror (const char *dir)
C function: void mgl_data_mirror (HMDT dat, const char *dir)
C function: void mgl_datac_mirror (HADT dat, const char *dir)

Mirror the left-to-right part of the data in given direction. Looks like change the value index i->n-i. Note, that the similar effect in graphics you can reach by using options (see Command options), for example, surf dat; xrange 1 -1.

MGL command: sew dat ['dir'='xyz' da=2*pi]
Method on mglData: void Sew (const char *dir, mreal da=2*M_PI)
C function: void mgl_data_sew (HMDT dat, const char *dir, mreal da)

Remove value steps (like phase jumps after inverse trigonometric functions) with period da in given direction.

MGL command: smooth data ['dir'='xyz']
Method on mglData: void Smooth (const char *dir="xyz", mreal delta=0)
Method on mglDataC: void Smooth (const char *dir="xyz", mreal delta=0)
C function: void mgl_data_smooth (HMDT dat, const char *dir, mreal delta)
C function: void mgl_datac_smooth (HADT dat, const char *dir, mreal delta)

Smooths the data on specified direction or directions. String dirs specifies the dimensions which will be smoothed. It may contain characters:

  • xyz’ for smoothing along x-,y-,z-directions correspondingly,
  • 0’ does nothing,
  • 3’ for linear averaging over 3 points,
  • 5’ for linear averaging over 5 points,
  • d1’...‘d9’ for linear averaging over (2*N+1)-th points,
  • p1’...‘p9’ for parabolic averaging over (2*N+1)-th points,
  • ^’ for finding upper bound,
  • _’ for finding lower bound.

By default quadratic averaging over 5 points is used.

MGL command: envelop dat ['dir'='x']
Method on mglData: void Envelop (char dir='x')
C function: void mgl_data_envelop (HMDT dat, char dir)

Find envelop for data values along direction dir.

MGL command: diffract dat 'how' q
Method on mglDataC: void Diffraction (const char *how, mreal q)
C function: void mgl_datac_diffr (HADT dat, const char *how, mreal q)

Calculates one step of diffraction by finite-difference method with parameter q=\delta t/\delta x^2 using method with 3-d order of accuracy. Parameter how may contain:

  • xyz’ for calculations along x-,y-,z-directions correspondingly;
  • r’ for using axial symmetric Laplace operator for x-direction;
  • 0’ for zero boundary conditions;
  • 1’ for constant boundary conditions;
  • 2’ for linear boundary conditions;
  • 3’ for parabolic boundary conditions;
  • 4’ for exponential boundary conditions;
  • 5’ for gaussian boundary conditions.
MGL command: norm dat v1 v2 [sym=off dim=0]
Method on mglData: void Norm (mreal v1=0, mreal v2=1, bool sym=false, long dim=0)
C function: void mgl_data_norm (HMDT dat, mreal v1, mreal v2, int sym, long dim)

Normalizes the data to range [v1,v2]. If flag sym=true then symmetrical interval [-max(|v1|,|v2|), max(|v1|,|v2|)] is used. Modification will be applied only for slices >=dim.

MGL command: normsl dat v1 v2 ['dir'='z' keep=on sym=off]
Method on mglData: void NormSl (mreal v1=0, mreal v2=1, char dir='z', bool keep=true, bool sym=false)
C function: void mgl_data_norm_slice (HMDT dat, mreal v1, mreal v2, char dir, int keep, int sym)

Normalizes data slice-by-slice along direction dir the data in slices to range [v1,v2]. If flag sym=true then symmetrical interval [-max(|v1|,|v2|), max(|v1|,|v2|)] is used. If keep is set then maximal value of k-th slice will be limited by \sqrt{\sum a_ij(k)/\sum a_ij(0)}.

MGL command: keep dat 'dir' i [j=0]
Method on mglData: void Keep (const char *dir, long i, long j=0)
Method on mglDataC: void Keep (const char *dir, long i, long j=0)
C function: void mgl_data_keep (HMDT dat, const char *dir, long i, long j)
C function: void mgl_datac_keep (HADT dat, const char *dir, long i, long j=0)

Conserves phase/sign or amplitude (if dir contain ‘a’) of data along directions dir by fixing one at point {i,j} of the initial slice. The function is useful for removing common phase change of a complex data. See Sample ‘keep, for sample code and picture.

MGL command: limit dat val
Method on mglData: void Limit (mreal val)
Method on mglDataC: void Limit (mreal val)
C function: void mgl_data_limit (HMDT dat, mreal val)
C function: void mgl_datac_limit (HADT dat, mreal val)

Limits the data values to be inside the range [-val,val], keeping the original sign of the value (phase for complex numbers). This is equivalent to operation a[i] *= abs(a[i])<val?1.:val/abs(a[i]);.

MGL command: coil dat v1 v2 [sep=on]
Method on mglData: void Coil (mreal v1, mreal v2, bool sep=true)
C function: void mgl_data_coil (HMDT dat, mreal v1, mreal v2, int sep)

Project the periodical data to range [v1,v2] (like mod() function). Separate branches by NAN if sep=true.

MGL command: dilate dat [val=1 step=1]
Method on mglData: void Dilate (mreal val=1, long step=1)
C function: void mgl_data_dilate (HMDT dat, mreal val, long step)

Return dilated by step cells array of 0 or 1 for data values larger val.

MGL command: erode dat [val=1 step=1]
Method on mglData: void Erode (mreal val=1, long step=1)
C function: void mgl_data_erode (HMDT dat, mreal val, long step)

Return eroded by step cells array of 0 or 1 for data values larger val.

MGL command: mode dat mask 'how' kdx [iter=0]
Method on mglData: void Mode (const mglDataA &mask, const mglDataA &pot, const char *how, double kdx=0, long iter=0))
Method on mglData: void Mode (const mglDataA &mask, const char *how, double kdx=0, long iter=0))
Method on mglDataC: void Mode (const mglDataA &mask, const mglDataA &pot, const char *how, double kdx=0, long iter=0))
Method on mglDataC: void Mode (const mglDataA &mask, const char *how, double kdx=0, long iter=0))
C function: void mgl_data_mode (HMDT dat, HCDT mask, HCDT pot, const char *how, double kdx, long iter)
C function: void mgl_datac_mode (HADT dat, HCDT mask, HCDT pot, const char *how, double kdx, long iter)

Replace initial mode d by found mode solution for Poisson equation u_xx+pot*u=0 in waveguide with boundary defined by mask. If pot is absent (NULL) then zero values are used. Parameter how may contain following symbols (default is "xyz0"):

  • x’ for 1d case with ny*nz variants,
  • y’ for 2d case with nz variants,
  • 0’ for zero boundary: u[n] = 0,
  • 1’ for free boundary du/dx=0: u[n] = u[n-1],
  • 2’ for zero laplace boundary d^2u/dx^2=0: u[n] = 2*u[n-1]-u[n-2],
  • s’ for 2nd order boundary du/dx=k: u[n] = (4*u[n-1]-u[n-2]-2*kdx)/3,
  • r’ for radiation boundary du/dx=k*u: u[n]=(4*u[n-1]-u[n-2])/(3+2*kdx),
  • i’ for complex-valued radiation boundary du/dx=i*k*u: u[n]=(4*u[n-1]-u[n-2])/(3+2i*kdx),
  • c’ for cyclic boundary ( u[n] = u[0] ignore \a kdx),
  • +’ for focusing nonlinearity (i.e. equation is u_xx+pot*u + |u|^2 u=0),
  • -’ for defocusing nonlinearity (i.e. equation is u_xx+pot*u - |u|^2 u=0).

Parameter iter set maximal number of iterations (0 is automatic).