scope - set current object

Syntax: scope object
Description:

Make object the current object.

  • An object can also be selected by clicking on it in the canvas or in the browser.
  • object can either be a graphical object or a folder.
  • The current object can be retrieved with current_object() and the current folder with current_folder().
  • scope .. will make the parent of the current object the current object.
Sample code:
scope welcome_page;
repaint;
create Folder DATA;
scope DATA;
import_report("data.dat");
OLDPAGE = current_page();
scope page_1;
print;
scope $OLDPAGE;
for PAGE in all("Page")
  scope $PAGE;
  TileViewports();
endfor
See also:

current_object, current_folder, current_page

secondnumber - return minute part of a time

Syntax: float secondnumber(string t)
Description: Return the second part of each element of t.
  • t can either be a time dataset or a string in one of the formats supported by the function timeformat1.
Example: t minutenumber(t)
12:01:00
14:58:59
00
59
Sample code:
#This function calculates the angles of the hands of a clock       
function set_hands()
  T = time;
  SecondHand = secondnumber(T)*6;
  BigHand    = (360*minutenumber(T)+SecondHand)/60;
  LittleHand = (360*hournumber(T)+BigHand)/12;
endfunction     
See also:

hournumber, minutenumber, totime

secondrange - return time range

Syntax: time secondrange(string times, float hstep)
Description: Return a range of times which can be found within the extremes of times and are an integer multiple of hstep seconds since midnight
Example: times secondrange(times,6)
"12:03:20"
"12:03:41"
12:03:24
12:03:30
12:03:36
See also:

hourrange, minuterange, midhourrange

secsince - number of seconds since midnight

Syntax: float secsince(time t)
Description: Return the number of seconds since midnight for each element of t.
  • t can be a string in time format or a real time dataset.
  • secsince can be used to convert times to numbers for processing or for use with a user-defined axis.
  • If necessary the numbers can be converted back to dates with invsecsince
Examples: d secsince(d)
12:00:00
23:59:59
43200
86399 
Code sample:
nextMinute = invsecsince(secsince(time)+(1:3600));
See also: invsecsince

seed - set seed of random number generator

Syntax: float seed(float s)
Description: Set the seed of the random number generator
  • Set the seed to a constant value if you want to get reproducible random numbers
  • Use seed(secsince(time)) if you want to make sure the numbers are different every time
Code sample:
seed(0);
echo(rnd(10));
seed(0);
echo(rnd(10));
See also: rnd, normrnd, exprnd

set - set an object's resources

Syntax: set object (resource = value, resource = value, ...)
Description: Set an object's resources.
  • The syntax of the set command is identical to the create command except it begins set object rather than create objectType object. See the create comand for more details.
  • If you only want to set one resouce then it is easier to use an assignment statement e.g.

    page_1.XuNshowMargins = false;

    rather than

    set page_1 ( XuNshowMargins = false );

    N.B. You cannot use an assignment if you want to include units e.g.

    set page_1.viewport_2(XuNfirstDiagonalPoint = (1,1) mm);
  • You can use the set command to rename an object:
    set WORK.T1 ( XuNname = "Height" );
Code sample:
set textoption
 ( XuNsuperscriptChar = ">",
   XuNsubscriptChar = "<",
   XuNnewlineChar = "|"
 );
See also: create

set_messages - set status of message flags

Syntax: set_messages(float errors, float warnings, float information, float user)
Description: set_messages sets the state of each message flag.
  • All output in Gsharp is either an error, a warning, information or a user message
  • By default all message types are switched on.
  • Use get_messages to retrieve the current status.
  • The output of the echo and printf commands is controlled by the user flag.
Sample code 1:
#turn off user-defined messages
set_messages(,,,false);     
Sample code 2:
#temporarily turn off all messages
float e, w, i, u;
get_messages(e, w, i, u);
set_messages(false, false, false, false);
RunCodeSilently();
set_messages(e, w, i, u);     
See also:

get_messages

set_undef - set undefined value

Syntax: set_undef(float undefValue)
Description: Set the value used to represent undefined values.
  • The default value is 999.999.
  • set_undef() will return undef to its default value.
  • You can also use the if() command to change the data:

    mydata = if(mydata=-1, undef, mydata);

Example:
set_undef(-1);     
See also:

if

setdir - set working directory

Syntax: float setdir(string directory)
Description: Set the working directory to be directory.
  • Returns true if succesful, false if unsuccesful
  • directory can include environment variables
  • backslashes have a special meaning in GSL strings. Use "\\" if you need "\". e.g. "c:\\program files\\mydata". Gsharp will also accept a forward slash as a platform independent directory separator. e.g. "$UNIDIR/example/Gsharp" will work on both UNIX and Windows.
Code sample:
setdir(workingdir);
if (getdir()<>workingdir) then
  echo("Cannot set working directory to: "+workingdir);
endif     
See also:

getdir

setsensitive - set sensitivity of GUI object

Syntax: setsensitive(string object, string state)
Description: Set the sensitivity of object to be state.
  • state must either be "sensitive" or "insensitive"
  • You can also set $object.XuNguiSensitive
Code sample:
gsharp_1.commandtoolbar.Open.XuNguiSensitive = false;
setsensitive("gsharp_1.commandtoolbar.Open","sensitive");
See also:

getdir

showcode - show country code

Syntax: showcode(string pattern, string caseSensitive)
Description: Echo to the message area a list of countries and their codes that contain the string pattern.
  • If no pattern is specified all countries are listed. They are ordered alphabetically by country name
  • caseSensitive can be either "case" or "no_case" (default).
Sample code:
showcode("uni");     
Output:
Tunisia: "TUN"
United Arab Emirates: "UAE"
United States of America: "USA"     
See also:

getcountry, getcode, showcountry, import_worldmap, Country Codes

showcountry - show country code

Syntax: showcountry(string code)
Description: Echo to the message area the country who has the specified code
  • If no pattern is specified all countries are listed. They are ordered alphabetically by country code
  • Only one code can be specified at a time. To do more use:

    echo(getcountry("DEN"//"POL"));

Sample code:
showcountry("DEN");     
Output:
DEN: "Denmark"     
See also:

getcountry, getcode, showcode, import_worldmap, Country Codes

sign - return sign of number

Syntax: float sign(float x)
Description: Return the sign for each element of x
  • If an element is zero it returns zero
  • If an element is greater than zero it returns 1.0
  • If an element is less than zero it returns -1.0
Example:

x

sign(x)
-0.1
0
0.1
-1
0
1
See also:

abs

sin - return sine

Syntax: float sin(float x)
Description: Returns the sine of each member of x.
  • x must be specified in radians. If it is in degrees use sin(x/180*pi)
  • values returned range from -1 to 1
Examples: x sin(x)

-π/2
0
π/2
π
3π/2
 0
-1
 0
 1
  0 
-1 
See also: asin, tan, cos

sinh - return hyperbolic sine

Syntax: float sinh(float x)
Description: Returns the hyperbolic sine of each element of x.
  • x must be specified in radians. If it is in degrees use sin(x/180*pi)
  • values returned range from -1 to 1
See also: sin, tan, cos

size - return size of dataset

Syntax: float size(any x)
Description: Returns the total size of x
  • size(x) is equal to sizex(x)*sizey(x)*sizez(x)
Sample code: function float LineNumbers(float x)
  return mask(1:size(x),x);
endfunction

x = rnd(100); y = rnd(100);
linenums = LineNumbers(x>.9);

for i in linenums
  printf("x[%d] = %g, y[%d] = %g\n", i, x[i], i, y[i]);
endfor
  

See also: sizex, sizey, sizez, count

sizex, sizey, sizez - return dimensions of dataset

Syntax: float sizex(any x)
float sizey(any x)
float sizez(any x)
Description: sizex returns the number of rows in x
sizey returns the number of columns in x
sizez returns the number of planes in x
  • size(x) is equal to sizex(x)*sizey(x)*sizez(x)
Sample code:
grid = bilinear(rnd(9),rnd(9),rnd(9),20,20);
create Viewport page_1.viewport_1;
create Domain page_1.viewport_1.domain_1;
create Graph page_1.viewport_1.domain_1.graph_1
 ( XuNcolorDataGrid = "grid",
   XuNgraphType = "2DContour"
 );
repaint;
grid = slicex(grid,sizex(grid):1);
repaint;
grid = slicey(grid,sizey(grid):1);
repaint;
grid = transpose(grid); 
See also: size, count

slice - return slices of dataset

Syntax: any slice(any x, float rows, float columns, float planes)
Description: Return slices of x as specified by rows, columns and planes
  • slice(x, rows, columns, planes) is equivalent to:
    slicez(slicey(slicex(x,rows),columns),planes);
  • If rows, columns or planes equals 0 then all relevant slices are returned.
    slice(x,0,0,0) is equivalent to x.         
  • To return a single slice you can use array indexing instead of slice:

    block[,,1]  #first plane
    grid[,2]  #second column         
Examples:
slice(x,1,0,2)
return row 1 of plane 2
slice(x,1:3,1;3,0)
return first three rows and first three columns of all planes
slice(x,1,2,3)
return x[1,2,3]
slicex(x,0,1//3//5,1)
return columns 1, 3 and 5 of plane 1
Sample code 1:
grid = bilinear(rnd(9),rnd(9),rnd(9),19,19);
simplegrid = slice(grid,1//10//19,1//10//19,1);
Sample code 2:
#Extract small section of grid
grid = bilinear(rnd(9),rnd(9),rnd(9),59,59);
gridsection = slice(grid,23:29,32:40,1);
See also: slicex, slicey, slicez

slicex, slicey, slicez - return slices of dataset

Syntax: any slicex(any x, float rows)
any slicey(any x, float columns)
any slicez(any x, float planes)
Description: Return slices of x in the x, y and z directions
  • slicex(x, rows) is equivalent to:slice(x,rows,0,0);
  • slicex(x,0) returns the whole of x
  • slicex(x,1) returns the first row of x
  • slicex(x,1:10) returns the first ten rows of x
  • slicex(x,sizex(x):1) returns x with the rows in reverse order.

slicey and slicez work in the same way.

  • Use the function slice to slice in more than one direction at one time.
    slice(x, rows, columns, planes) is equivalent to:
    slicez(slicey(slicex(x,rows),columns),planes);
  • Use dropx, dropy and dropz to return x without the specified slices
  • slicex is very useful for indexing into an array of values. See Sample code 2
Sample code 1:
grid = bilinear(rnd(9),rnd(9),rnd(9),19,19);
invertgrid = slicex(grid,sizex(grid):1);
Sample code 2:
#Get random days
days = "Sun"//"Mon"//"Tue"//"Wed"//"Thu"//"Fri"//"Sat";
dayCodes = int(rnd(100)*7+1);
dayNames = slicex(days,dayCodes);
See also: slice, dropx, dropy, dropz

smooth - smooth interpolation

Syntax: float smooth(float x, float y, float xnodes, float smoothing)
Description: Calculate a cubic spline interpolation of the points (x,y). The new curve will fit the points, but will not necessarily pass through them.
  • A value is calculated for each x value in xnodes. If xnodes is a single value, n, then range(x,n) is used. If xnodes is not specified then range(x,33) is used
  • smoothing is an integer from 1 to 9 that controls the level of smoothing. The default value is 1.
  • Read more about the smooth function in How do I fit a line?
See also: spline, polyfit, linear, range

sort - sort dataset

Syntax: any sort(any x)
Description: Return an array of the sorted elements of x
  • x can be of any data type - float, string, date or time
  • To sort into descending order use:
    reverse(sort(x))
See also: sortby, unique, reverse

sortby - sort one dataset based on another dataset

Syntax: any sortby(any x, any y)
Description: Return the elements of x rearranged in the order that would put y into ascending order
  • x can be of any data type - float, string, date or time
  • This function is used to sort a group of datasets with corresponding elements:
    y = sortby(y,x);
    x = sort(x);

    It is important that the sort is performed last after all the sortby's.

  • If you have a dataset y containing the order that you would like to have x in - then use slicex:

    x = slicex(x,y);

Example:

x

y sortby(x,y)
1
2
3
3
1
2
2
3
1
See also: sort, unique, reverse, slicex

sphsemiv - See Kriging Interpolation

spline - spline interpolation

Syntax: float spline(float x, float y, float xnodes, float tension)
Description: Calculate a cubic spline interpolation of the points (x,y). The new curve will pass through all the original points.
  • A value is calculated for each x value in xnodes. If xnodes is a single value, n, then range(x,n) is used. If xnodes is not specified then range(x,33) is used
  • tension is an integer from 1 to 10 that controls the tautness of the line about the input points. The default value is 1.
  • Read more about the spline function in How do I fit a line?
See also: smooth, polyfit, linear, range

sprintf - write formatted text to string

Syntax: string sprintf(string format, any var1, any var2, ...)
Description: Return the formatted text as a string. The format is a C language format string.
  • See printf for details
See also:

printf, fprintf

sqrt - square root

Syntax: float sqrt(float x)
Description: Return the square root of each element of x
Examples: x sqrt(x)
0
1
2
 0
1
1.41421
Code Sample: x = rnd(10); y = rnd(10);
distanceFromOrigin = sqrt(x*x+y*y);
See also:

exp, log10

std, std1, stdx, std1x - standard deviations

Syntax: float std(float x)
float std1(float x)
float stdx(float x)
float std1x(float x)
Description: std - return the standard deviation of x.
std1 - return the standard deviation of x using the (N-1) method
stdx - return the standard deviation for each column of x
std1x - return the standard deviation for each column of x using the (N-1) method.
  • The standard deviation is the square root of the variance.
  • The variance is the sum of the squares of x-avg(x)
  • To find the standard deviation of each row of x use:
    stdx(transpose(x))
Examples: x std(x)
0
1
2
 0.816497

step - sequence of integers

Syntax: float step(float n)
1:n
Description: Return n sequential numbers starting with 1.0 with step 1.0
  • If n is a non-integer, nint(n) is used.
Example: step(4) 1:4
1
2
3
4

See also:

step2, nint

step2 - sequence of integers

Syntax: float step2(float n1, float n2)
n1:n2
Description: Return the sequence of integers beginning with n1 and ending with n2
  • If n1 or n2 is a non-integer then nint(n1) and nint(n2) are used.
Example: step2(4,6) 4:6
4
5
6
See also:

step, nint

stop - stop GSL execution

Syntax: stop
Description:

Stop executing GSL scripts.

  • Stops current script and outputs the current function stack.

  • If the current script has been exec()'ed by another script then stop will only stop the current script - execution will continue after the exec() command in the calling script.

  • If you want to quit Gsharp then you can either use the built-in callback GuiFileExit, which prompts for confirmation before quitting or the command quit, which quits without any questions.

Code Sample:
function deepDownInManyLayersOfFunctions()
  if not exists(WORK.mydata)  stop;
  CarryOn();
endfunction
See also: break, quit, GuiFileExit

strchr, strrchr, strstr - string searching

Syntax: string strchr(string s, string c)
string strrchr(string s, string c)
string strstr(string s, string s2)
Description: For each element of s return the remaining part of the string beginning with:
  • the first occurence of the character c - strchr
  • the last occurence of the character c - strrchr
  • the first occurence of the string s2 - strstr

If a match is not found then undef is returned for that element

  • Only the first character of the string c is recognized.
Examples:
strchr("This is it","i")
"is is it"
strrchr("This is it","i")
"it"
strstr("This is it"," is")
" is it"
strchr("C:\\Program Files\\Bob","\\")
"\\Bob"
See also:

strlen, substr, match

strlen - string length

Syntax: string strlen(string s)
Description: Return the length of each element of s
Examples: s strlen(s)
"Hello"
""
"C:\\"
5
0
3
See also:

strchr, strrchr, strstr, substr, match

strvalue - convert string to value

Syntax: float strvalue(string s)
Description: Convert each element of s into a number
  • If an element cannot be converted undef is returned for that element
Examples: s strvalue(s)
"1e2"
""
"4"
"1+1"
100
0
4
undef
See also:

valuestr

substr - substring

Syntax: string substr(string s, float n1, float n2)
Description: For each element of s return the substring beginning with the n1'th character and ending with the n2'th character.
  • If there are less than n1 characters in an element then undef is returned for that element.
  • If there are less then n2 characters in an element then the substring continues until the end of the string.
Examples: s substr(s,2,4)
"The whole string"
"he "
Code sample:

#drop first two characters of myarray
myarray = substr(s,3,1024);

See also:

strchr, strrchr, strstr, strlen, match

sum - sum

Syntax: float sum(float x)
Description: Return the sum of all elements of x
  • Any undef values are ignored
Examples: x sum(x)
2
undef
3
5
See also:

sumx

sumx - sum columns

Syntax: float sumx(float x)
Description: Return the sum of all elements in each column of x
  • Any undef values are ignored
  • The result is returned as a column dataset. If you would prefer a row dataset use:
    transpose(sumx(x))
  • To find the sum of each row use:
    sumx(transpose(x))
Examples: x sumx(x)
1   2   3
4   3   2
5
5
5
See also:

sum

system - perform system command

Syntax: system(string command)
Description: Run the specified operating system command.
  • To get output from the system command, pipe the output to a file and then read it in
  • Gsharp waits for the system command to exit before continuing execution
Examples:
system("dir > bob.dat");
system("dir > "+myfilename);       
system("runmodel "+arg1+" "+arg2+" "+arg3);     
See also:

os_type

 

 

 

 

 

 

 

 

.