range - return range of numbers

Syntax: float range(float x, float nx)
Description: Return nx evenly distributed numbers with the same limits as x
  • The range function is useful for creating an array of points to interpolate data onto. The default points for many of the interpolation routines is range(inputPoints, 33)
Examples: d range(d,4)
0
3
0
1
2
3
Code Sample 1: #Create circle
i = range(0//2*pi,360);
x = sin(i);
y = cos(i);
Code Sample 2: #linear regression
xnodes = range(x,2);
yvals = polyfit(x,y,xnodes,1);
See also: nicerange, range2

range2 - return range of numbers

Syntax: float range2(float start, float end, float step)
Description: Return a range of numbers starting with start, ending with end and with an interval of step
  • The first number will always be start
  • It makes no difference if step is positive or negative
  • For step values of 1 or -1 it is easier to use the colon to specify a range e.g. 0:10 or 5:-5
Examples: range2(0, 100, 50)

0
50
100

range2(50, -50, 50) 50
0
-50
range2(-50, 50, 50) -50
0
50
See also: nicerange, range

ransemiv - See Kriging Interpolation

recalc - calculate all unspecified resources

Syntax: recalc
Description: The values of a number of resources in Gsharp are not evaluated until the plot is repainted. For example when you first create a domain the X minimum is 0 and the X maximum is 100. When you create a graph (without repainting) the limits stay the same. When you repaint, Gsharp will choose some sensible limits for you and set the resource.

recalc calculates these resources without physically repainting the screen.

This can be useful, if you want to find out the resources from your first domain so that you can use them when you create your second domain. You could also use repaint, but the page would repaint halfway through your script. See the example below.

  •  recalc should not be followed by parentheses i.e. "()".
Code Sample:
X = rnd(9);
Y = rnd(9);
Z = rnd(9);
gridx = range(X,40);
gridy = range(Y,40);
grid = bivariate(X,Y,Z,gridx,gridy);
classlims = range(Z,40);
create Viewport page_1.viewport_1;
create Domain page_1.viewport_1.domain_1
 ( XuNclassData = "classlims",
   XuNclassType = "limits"
 );
create Graph page_1.viewport_1.domain_1.graph_1
 ( XuNcolorDataGrid = "grid",
   XuNgraphType = "2DContour",
   XuNxData = "gridx",
   XuNyData = "gridy"
 );
recalc;
create Domain page_1.viewport_1.domain_2
 ( XuNxMinimum = page_1.viewport_1.domain_1.XuNxMinimum,
   XuNxMaximum = page_1.viewport_1.domain_1.XuNxMaximum,
   XuNyMinimum = page_1.viewport_1.domain_1.XuNyMinimum,
   XuNyMaximum = page_1.viewport_1.domain_1.XuNyMaximum,
   XuNclassData = "classlims",
   XuNclassType = "limits"
 );
create Graph page_1.viewport_1.domain_2.graph_1
 ( XuNcolorData = "Z",
   XuNgraphType = "scatter",
   XuNxData = "X",
   XuNyData = "Y"
 );
See also:

repaint

redim - change dimension of dataset

Syntax: any redim(any x, float nrows, float ncols, float nplanes)
Description: The function returns x adjusted to have dimension [nrows, ncols, nplanes]. The original structure of x is maintained.
  • x can be of any dataset type.
  • redim is a little slower than reshape as it must modify the internal order of the data in order maintain the original structure of the data.
  • Any additional rows, columns or planes are filled with undef values
  • Any unused rows, columns or planes are discarded.

 

Example:

redim( (0,1)//(2,3), 3, 3, 1)

  0      1    undef
  2      3    undef
undef  undef  undef
Code Sample:
#This function will set WORK.grid[x,y] = z
#It will increase the size of WORK.grid if necessary


function AddElement(float x, float y, float z)
  nx = max2(x, sizex(WORK.grid));
  ny = max2(y, sizey(WORK.grid));
  WORK.grid = redim(WORK.grid, nx, ny, 1);
  WORK.grid[x,y] = z;
endfunction


WORK.grid = 0;
AddElement(2, 3, 3.141592);
AddElement(1, 6, 0.718);
echo(WORK.grid);
See also:

reshape, transpose, slicex, slicey

regular - interpolate surface onto new grid

Syntax: float regular(float grid, float xgrid, float ygrid, float newxgrid, float newygrid, float xregion, float yregion, float xbarrier, float ybarrier)
Description: Interpolate the surface defined by grid, xgrid and ygrid onto the grid defined by nx and ny. It is also possible to define a region using xregion, yregion and a barrier using xbarrier, ybarrier.
  • grid is a 2D array defining the value at each location of the grid
  • The x location of the grid is defined like so:
    • If newxgrid is an array then newxgrid is used.
    • If newxgrid is a single value n, then range(xgrid,n) is used
    • If newxgrid is not specified, range(xgrid,33) is used.
  • The y location of the grid is determined in a similar way.
  • xregion and yregion can be used to specify a region to interpolate within.
    • Each region must be specified as a closed polygon
    • Each region must be separated by an (undef,undef) point
    • It is also possible to interpolate over the entire grid and then apply the region what the grid is plotted. This has the advantage that the plot will contour right up to the edges of the region, rather than leaving a jagged edge.
  • xbarrier and ybarrier can be used to specify a barrier in the interpolation. This ensures that the interpolation on one side of the barrier is unaffected by the values of points on the other side of the barrier.

regular is useful for creating a simplified surface for faster rendering and interaction. See example below:

Code Sample:
x = rnd(39); y = rnd(39); z = rnd(39);
xgrid = range(x,50);  ygrid = range(y,50);
grid = bilinear(x, y, z, xgrid, ygrid);       
#Create simple version of grid/xgrid/ygrid
xsimple = range(xgrid,5);  ysimple = range(ygrid,5);
simplegrid = regular(grid,xgrid,ygrid,xsimple,ysimple);       
reset;
create Viewport page_1.viewport_1
   ( XuNfirstDiagonalPoint = (2,4.0801) %,
     XuNsecondDiagonalPoint = (49,95.0166) %,
     XuNzRatio = 0.5
   );
create Domain page_1.viewport_1.domain_1;
create Graph page_1.viewport_1.domain_1.graph_1
   ( XuNgraphType = "3DContour",
     XuNxData = "xgrid",
     XuNyData = "ygrid",
     XuNzDataGrid = "grid"
   );

create Viewport page_1.viewport_2
   ( XuNfirstDiagonalPoint = (52,4.0801) %,
     XuNsecondDiagonalPoint = (99,95.0166) %,
     XuNzRatio = 0.5
   );
create Domain page_1.viewport_2.domain_1;
create Graph page_1.viewport_2.domain_1.graph_1
   ( XuNgraphType = "3DContour",
     XuNxData = "xsimple",
     XuNyData = "ysimple",
     XuNzDataGrid = "simplegrid"
   );     
See also:

bilinear, bivariate, range

remove - remove a file

Syntax: float remove(string filename)
Description:

remove the file specified by filename.

  • filename cannot contain wildcards and only one file can be removed at a time.
Code Sample:
for filename in filelist("*.fold")
  remove(filename);
endfor
See also:

filelist, rename, getdir, system

rename - rename a file

Syntax: float rename(string oldName, string newName)
Description:

rename the file oldName as newName.

  • If oldName and newName are in different directories the file is effectively moved.
  • rename returns 0 on success. -1 if oldName does not exist.
  • Both oldName and newName can contain an absolute folder name or a folder name relative to the current folder (returned by getdir).
Code Sample:
setdir("$UNIDIR/example/Gsharp");
rename("samples/barcharts.gsl","barcharts.gsl");
See also:

filelist, remove, getdir, system

rename_dataset - rename a dataset

Syntax: rename_dataset(string oldName, string newName)
Description:

The dataset specified by oldName is given the name newName

  • You could also use something like:
    set WORK.A1 ( XuNname = "Titles" );
Code Sample:
rename_dataset("WORK.T1", "INPUT.Height");
rename_dataset("A1", "Titles");

repaint - calculate all unspecified resources

Syntax: repaint
Description: repaint renders the current plot on the canvas.
  • repaint should not be followed by parentheses i.e. "()".
  • Gsharp will normally auto-repaint whenever the graphics are modified
  • It can also be set to auto-repaint whenever the data is modified. Modify these options by clicking the right-mouse button on the page. 
Code Sample:
angle = 0:360;  x=0;
create Viewport page_1.viewport
   ( XuNxRatio = 1,
     XuNyRatio = 1,
     XuNfirstDiagonalPoint = (1,1),
     XuNsecondDiagonalPoint = (99,99)
   );
create Domain page_1.viewport.dom3d
   ( XuNgraphClearance = false,
     XuN3DXAxis = false,
     XuN3DYAxis = false,
     XuN3DZAxis = false
   );
create Graph page_1.viewport.dom3d.g1
   ( XuNgraphType = "3DLine",
     XuNxData = "sin(angle)",
     XuNyData = "cos(angle)",
     XuNzData = "angle"
   );
echo("Press the stop button when you've had enough");
for ang in (120:1000)/300
  x = x + .03;
  page_1.viewport.XuNelevationPlane = cos(x)*90;
  angle = (0:360)*ang;
  repaint;
endfor
See also:

recalc

repeatx, repeaty, repeatz - repeat a row, repeat a column, repeat a plane

Syntax: any repeatx(any x, float nrows)
any repeaty(any x, float ncols)
any repeatz(any x, float nplanes)
Description: repeatx returns the row x repeat nrows times.
repeaty returns the column x repeat ncols times.
repeatz returns the grid x repeat nplanes times.
  • x can be of any dataset type.
  • if the x passed to repeatx is a column it is converted to a row.
  • if the x passed to repeaty is a row it is converted to a column.
Examples:

x

repeatx(x,3)

1  2  3 1  2  3
1  2  3
1  2  3

x

repeaty(x,3)

1
2
3
1  1  1
2  2  2
3  3
Code Sample:
#Take a grid with xgrid, ygrid and convert to an XYZ scatter plot
x=rnd(39); y=rnd(39); z=rnd(39);
xgrid = range(x,50);  ygrid = range(y,30);
grid = bilinear(x,y,z,xgrid,ygrid);       
gridx = repeaty(xgrid,size(ygrid));
gridy = repeatx(ygrid,size(xgrid));       
X = list(gridx);  Y = list(gridy);  Z = list(grid);       
create Viewport page_1.viewport_1;
create Domain page_1.viewport_1.domain_1;
create Graph page_1.viewport_1.domain_1.graph_1
   ( XuNgraphType = "scatter",
     XuNcolorData = "Z",
     XuNxData = "X",
     XuNyData = "Y"
   );
create Viewport page_1.viewport_2
   ( XuNfirstDiagonalPoint = (43.6475,91.9714) %,
     XuNsecondDiagonalPoint = (95.8535,37.2867) %
   );
create Domain page_1.viewport_2.domain_2;
create Graph page_1.viewport_2.domain_2.graph_2
   ( XuNgraphType = "2DContour",
     XuNcolorDataGrid = "grid",
     XuNxData = "xgrid",
     XuNyData = "ygrid"
   );     
See also:

list

reset - reset Gsharp

Syntax: reset <blank> | data | graphics | names | all
Description:

reset Gsharp.

  • If the destroyable resource of an object is set to false then it will not be destroyed by the reset command.
  • When Gsharp tries to destroy all pages, page_1 is only recreated if all pages are destroyed. See above.
  • The same applies to reset data and the WORK folder.
  • If Gsharp recreates the WORK folder it will also create a new argv dataset
  • The exact consequence of each version of reset is described in the table below:
reset data

Destroy all folders (and recreate the WORK folder)
Reset default dataset names to T1 and A1
Reset the interpolatation menus.

reset names Reset default dataset names to T1 and A1

reset page

Reset current page

reset graphics

Destroy all pages (and recreate page_1)
Reset color tables and shading scales
Reset object templates
reset all

All of the above plus:
Reset clipboard and trash

Reset projection settings
Reset hardcopy and reload device list
Reset file import and export dialogs

 

Code Sample:
function CreateTemplate()
  reset graphics;
  create Viewport page_1.template;
  ...
endfunction
reset data;
import_report("mydata.dat");
See also:

destroy

reshape - change dimension of dataset

Syntax: any reshape(any x, float nrows, float ncols, float nplanes)
Description: The function returns x reshaped to have dimension [nrows, ncols, nplanes].
  • x can be of any dataset type.
  • reshape is very fast as the internal order of the data is not modified - Gsharp just changes the recorded dimensions.
  • if size(x)<nrows*ncols*nplanes then the returned value is padded out with undef values
  • if size(x)>nrows*ncols*nplanes then the extra values are discarded.

Gsharp stores a 3D block in the following order - first by column, then by row and then by plane. So for example block[2,2,2] is stored in this order:

block[1,1,1]
block[2,1,1]
block[1,2,1]
block[2,2,1]
block[1,1,2]
block[2,1,2]
block[1,2,2]
block[2,2,2]

  • N.B. reshape can be used to convert an array of regularly spaced data into a grid so that it can be contoured. It is better to reshape than  interpolate this sort of data as interpolating it into a grid would introduce inaccuracies.
Example:

reshape(1:26,3,3,3)

1st plane 2nd plane 3rd plane
1  4  7
2  5  8
3  6  9 
10  13  16
11  14  17
12  15  18
19   22     25  
20   23     26  
21   24  undef
Code Sample:
/*
 * import data
 */
home = "$UNIDIR/example/Gsharp/";
import_ascii(home + "bluntx.dat",,,,,,"gridX",,,,,"vertical");
import_ascii(home + "blunty.dat",,,,,,"gridY",,,,,"vertical");
import_ascii(home + "density.dat",,,,,,"density",,,,,"vertical");

gridX = reshape(gridX,40,32,1);
gridY = reshape(gridY,40,32,1);
density = reshape(density,40,32,1);     
See also:

list, transpose, slicex, slicey

reverse - reverse order of dataset

Syntax: any reverse(any x)
Description: The function returns x with the elements in the reverse order
  • x can be of any dataset type.
Example: x reverse(x)
1
2
3
3
2
1
Code Sample:
x = rnd(100);
descending = reverse(sort(x));     
See also:

list, transpose

rnd - random numbers

Syntax: float rnd(float n)
Description: Return n numbers randomly distributed between 0 and 1
  • To produce n numbers randomly distributed between a and b use:
    rnd(n)*(b-a)+a;
  • To produce n random integers between 1 and k use:
    int(rnd(n)*k+1);
Examples:
stockPrice = 100+accum(rnd(100)-0.4);
newgrid = bivariate(rnd(10),rnd(10),rnd(10),40,40);
pos = (rnd(1)*100,rnd(1)*100);     
See also:

normrnd, exprnd

round - return nearest integer to float

Syntax: float round(float x)
Description:

Exactly the same as nint()

See also: nint

 

 

 

 

.