cat - send the contents of a file to stdout

Syntax:

cat(string filename)

Description:

Send the contents of filename to stdout.

Can be used by Gsharp Web Edition to output a GIF image.

Code sample:

imgfile = getenv("GsharpTmpFilesActualDir")+"zoom"+getpid()+".gif";

make_image(500, 400, imgfile);

echo("Content-type: image/gif"//"");

cat(imgfile);
remove(imgfile);

childrenof - children of an object

Syntax:

string childrenof(string parent)

Description:

childrenof returns the children of parent as a string array.

  • If parent has no children undef is returned

  • childrenof does not include the full path to the children. To get the full path just prepend with the name of the parent e.g.
    kids = parent+"."+childrenof($parent)
    or use the function all() - see below.

  • If only children of a certain type are required use all(objectClass, parent). all() will return grandchildren as well as children so may not be suited for looking for sub-menus without sub-sub-menus, but will work well with other object types like graphs and viewports. Note that all() returns the full path to each object, whereas childrenof just returns the name of each object.

Code sample:

function ExpertOptionsCB(string o, string d, float r)
  string MENU, OBJ;
  MENU = "gsharp_1.menubar.User";
  for OBJ in MENU+"."+childrenof($MENU)
    if (typeof($OBJ)<>"Button")  continue;
    if ($(OBJ).XuNuserData=undef)  continue;
    $(OBJ).XuNguiSensitive = ($(OBJ).XuNuserData=d);
  endfor
endfunction

if exists(gsharp_1.menubar.User) destroy gsharp_1.menubar.User;
create Menu gsharp_1.menubar.User;
create Button gsharp_1.menubar.User.Expert
 ( XuNguiLabel = "Switch on expert options",
   XuNguiCallback = "ExpertOptionsCB",
   XuNguiCallbackData = '"Expert"',
   XuNuserData = "Novice"
 );
create Button gsharp_1.menubar.User.Novice
 ( XuNguiLabel = "Switch off expert options",
   XuNguiCallback = "ExpertOptionsCB",
   XuNguiCallbackData = '"Novice"',
   XuNguiSensitive = false,
   XuNuserData = "Expert"
 );
create Separator gsharp_1.menubar.User.Separator;
create Button gsharp_1.menubar.User.Easy1
 ( XuNguiLabel = "Easy"
 );
create Button gsharp_1.menubar.User.Diff1
 ( XuNguiLabel = "Puzzling",
   XuNuserData = "Expert",
   XuNguiSensitive = false
 );
create Button gsharp_1.menubar.User.Diff2
 ( XuNguiLabel = "Tricky",
   XuNuserData = "Expert",
   XuNguiSensitive = false
 );

See also:

typeof, all, namelist

const - create constant

Syntax:

const type x[nx,ny,nz] = value

Description:

To specify that a dataset is constant and cannot be modified precede the declaration of the dataset with the keyword const and follow it with = value, where value is the required value.

  • const works with real datasets and with local variables. For more information on the difference see Creating Datasets in GSL syntax.

  • type is either float, string, date or time.

  • To make a dataset constant once it has already been created set its immutable resource to true e.g.

    set WORK.argv ( XuNimmutable = true );
  • To make a datest undestroyable set its XuNdestroyable resource to false e.g.

    set WORK.argv ( XuNdestroyable = false );

    but remember to do it before you make the dataset immutable!

  • Making a dataset constant can be useful for debugging if you have a dataset which is being modified when it shouldn't be. Make sure the dataset has been made immutable, and then as soon as the dateset is modified your script will stop with an error message.

Examples:

const float n = 10;
const string WORK.Templates = ("A", "B") // ("C", "D");

See also:

set

continue - continue with next iteration of loop

Syntax:

continue

Description:

Continue with the next iteration of a for or while loop

  • To break out n of the loop use break.

Code sample:

for PTR in all("Viewport")
  if ($(PTR).XuNuserData="keep")  continue;
  echo("Say goodbye to "+PTR);
  destroy $PTR;
endfor

See also:

break

cos - return cosine

Syntax:

float cos(float x)

Description:

Returns the cosine of each member in x.

  • x must be specified in radians. If it is in degrees use cos(x/180*pi)

  • values returned range from -1 to 1

Examples:

x

cos(x)


-π/2
0
π/2
π
3π/2

-1 



-1 

See also:

acos, tan, sin

cosh - return hyperbolic cosine

Syntax:

float cosh(float x)

Description:

Returns the hyperbolic cosine of each member in x.

  • x must be specified in radians. If it is in degrees use cosh(x/180*pi)

  • values returned range from -1 to 1

Examples:

x

cosh(x)

-1
0
1

1.54308 

1.54308 

See also:

cos

count - number of valid elements

Syntax:

float count(any x)

Description:

Returns the number of valid elements in x.

  • A valid element is any element not equal to undef

  • count(x) is equivalent to sum(x<>undef)

See also:

countx, sum

countx - number of valid elements in each column

Syntax:

float countx(any x)

Description:

Returns the number of valid elements in each column of x.

  • A valid element is any element not equal to undef

  • The results are returned as a column, if you prefer them as a row use transpose(countx(x))

  • To obtain the number of valid elements in each row of x use countx(transpose(x))

  • count(x) is equivalent to sumx(x<>undef)

See also:

count, sumx, transpose

create - create an object's and set its resources

Syntax:

create objectType object (resource = value, resource = value, ...)

Description:

Create an object's resources.

  • The object can either be specified with its full path or its path relative to the current object e.g. the object page_1.viewport_1.domain could be referenced as .domain_1 if page_1.viewport_1 is the current object. To set resources of the current object use ".".

  • If the object name will not be known until run time then create a string dataset containing the name of the object and precede it with a dollar symbol e.g.

    PTR = "page_1.viewport"+i;
    create Viewport $PTR
     ( XuNxRatio = 1
     );

    See the User Guide page on pointers for more details

Code sample:

create Viewport page_1.viewport
 ( XuNfirstDiagonalPoint = (10,10),
   XuNsecondDiagonalPoint = (90,90)
 );

See also:

set, destroy

crosssum - calculate sum of 2D irregular points within each gridbox

Syntax:

float crosssum(float x, float y, float z, float xclasses, float yclasses)

Description:

Returns the crosstable of x and y using the sum of z and the intervals defined by xclasses and yclasses.

  • Gsharp will group the points (x,y) using a grid whose location is defined by xclasses and yclasses. For example if xclasses=1//2//3, then four x classes are used: x<1, 1<x<2, 2<x<3 and x>3.

  • The corresponding z values are then summed within each gridbox.

  • The dataset returned is a grid with size(xclasses)+1 rows and size(yclasses)+1 columns.

Code sample:

lat=rnd(100);  long=rnd(100);  sales=rnd(100)*100;
classes = .25//.5//.75;
turnover = crosssum(long, lat, sales, classes, classes);
numSales = crosstable(long, lat, sales, classes, classes);
create Viewport page_1.viewport;
create Domain page_1.viewport.domain_2
   ( XuNshadingScale = "cyanYellowRed"
   );
set page_1.viewport.domain_2.legend
   ( XuNobjectEnabled = true
   );
create Graph page_1.viewport_2.domain_2.graph_2
   ( XuNgraphType = "grid",
     XuNcolorDataGrid = "turnover",
     XuNxData = "0//classes//1",
     XuNyData = "0//classes//1"
   );

See also:

crosstable, histosum, histogram, Irregular Grid graph type

crosstable - count number of 2D irregular points within each gridbox

Syntax:

float crosstable(float x, float y, float xclasses, float yclasses)

Description:

Returns the crosstable of x and y using the intervals defined by xclasses and yclasses.

  • crosstable works in the same way as crosssum except that crosstable counts the number of points in each gridbox, rather than summing the corresponding z values.

See also:

crosssum, histosum, histogram, Irregular Grid graph type

current_folder - return current folder

Syntax:

string current_folder()

Description:

Returns the current folder.

  • If no folders exist, undef is returned

  • WORK is the default folder

Code sample 1:

CURFOLD = current_folder();
scope DATA;
import_report("mydata.dat");
scope $CURFOLD;

Code sample 2:

FOLD = current_folder();
if exists($(FOLD).X) destroy X;

See also:

current_object, scope

current_object - return current object

Syntax:

string current_object()

Description:

Returns the full path name of the current object.

The current object is set using the scope command or by selecting it in the browser or on the canvas.

Code sample 1:

function CanvasCB(string o, string d, float r)
  string OBJ;
  if r<>XuCR_DOUBLE_CLICK return;
  OBJ = tokenize(current_object(),".");
  if size(OBJ)=1 return;
  ViewportSelected(OBJ[1]+"."+OBJ[2]);
endfunction

See also:

current_folder, typeof, scope

current_page - return current page

Syntax:

string current_page()

Description:

Returns the current page.

The current page is the page containing the current object. See above.

Code sample 1:

function AddViewport()
  string PAGE;
  PAGE = current_page();
  create Viewport $(PAGE).view1
   ( XuNfirstDiagonalPoint = (10,10),
     XuNsecondDiagonalPoint = (90,90)
   );
endfunction

See also:

scope, current_object

 

 

 

 

 

 

.