date - return date

Syntax:

date date

Description:

Returns today's date.

  • You can also use today in exactly the same way.
  • As well as being a special string, date is also a variable type.
  • If you specify a note or title as today then the current date is used.

Example:

echo(date)

29/06/2001

See also:

today

dateformat1 - convert string to date

Syntax:

date dateformat1(string d)

Description:

Converts a string dataset to a date dataset.

  • input strings can be in any of the following formats: DD-MM-YY, DD-MM-YYYY, DD-MON-YY, DD-MON-YYYY, YYYYMMDD, DD/MM/YY, DD/MM/YYYY, DD/MM YYYY, DD MONTH YYYY, MONTH DD YYYY, YYYY-MM-DD, YYYY-MONTH-DD, YY-MONTH-DD, YY-MON-DD or YYYY-MON-DD

  • 2 digits years are assumed to be in the range 1950-2049

Examples:

d

dateformat1(d)

13/3/00
2000-Mar-13
20000313
Mar 13 2000
13 Mar 2000

13-MAR-2000
13-MAR-2000
13-MAR-2000
13-MAR-2000
13-MAR-2000

See also:

daysince, invdaysince

daynumber - extract day number from a date dataset

Syntax:

float daynumber(date d)

Description:

Extract the day number of a month from a date string

Examples:

d

daynumber(d)

13-MAR-2000
14-MAR-2000

13
14

See also:

todate

dayrange - extract day number from a date dataset

Syntax:

date dayrange(date d, float s)

Description:

Create a range of dates starting with the first day in d and continuing with every s'th day until the last day in d.

  • d can be a string in date format or a real date dataset.

  • The dates in d can be in any order.

Examples:

d

dayrange(d,2)

8/1/00
1/1/00

01-JAN-2000
03-JAN-2000
05-JAN-2000
07-JAN-2000

See also:

invdaysince

daysince - number of days since 1601

Syntax:

float daysince(date d)

Description:

Return the number of days since 1st January 1601 for each date in d.

  • d can be a string in date format or a real date dataset.

  • daysince can be used to convert dates to numbers for processing or for use with a user-defined axis.

  • If necessary the numbers can be converted back to dates with invdaysince

Examples:

d

daysince(d)

1/1/00
19-JAN-2000

145732
145750

Code sample:

next50days = invdaysince(daysince(today)+(1:50));

See also:

invdaysince

dbopt - Check for database license

Syntax:

float dbopt()

Description:

Returns true if database license is available.

  • Most licenses for Gsharp include the database option by default. To confirm this type the following command on the command line:

    echo(dbopt());

    It will output "1" if the database option has been licensed.

Code sample:

if (dbopt()=false) then
  echo("You do not have a license for the database option");
  quit();
endif

See also:

batch, version, webedition, appseat

define_device - register an output device with Gsharp

Syntax:

define_device(string device, string description, float papertype, float xsize, float ysize, float orientation, string plotFile, string plotCommand, float leftMargin, float rightMargin, float topMargin, float bottomMargin)

Description:

Their are two methods for creating output from Gsharp under Windows. Output can either be sent to one of the printers defined by Windows or output can be created using Gsharp's own device system. Gsharp supports hundreds of devices including PostScript, JPEG, TIFF, GIF, PNG and CGM. Each device must be defined before it can be used using the function define_device.

  • The file $UNIDIR/base/Gsharprc.gsl contains many calls to define all the popular devices. This file is executed as part of Gsharp initialisation. This file can be edited to add, edit or delete devices.

  • Additional calls to define_device can be made at any time.

  • device is the driver token e.g. "hposta4"

  • description is the string that will appear in the Output Image dialog.

  • papertype is one of:

    • 0 (custom),

    • 1 (A0), 2 (A1), 3 (A2), 4 (A3), 5 (A4), 6 (A5),

    • 7 (A), 8 (B), 9 (C), 10 (D), 11 (E),

    • 12 (legal) or 13 (executive).

  • xsize, ysize specify the size if papertype=0 (custom).

  • orientation is the default orientation, either 0 (landscape) or 1 (portrait)

  • plotFile is the default output filename

  • plotCommand is the default printCommand

  • leftMargin, rightMargin, topMargin and bottomMargin are used to specify the margin size in mm's. If they are not specified margin sizes are taken from $UNIDIR/base/UNIRAS.prf

Code sample:

define_device("hposta4" ,"PostScript: A4 (*.ps)",5);
define_device("hcposta4","Color PostScript: A4 (*.ps)",5);

destroy - destroy objects

Syntax:

destroy object, object, object, ...

Description:

destroy specified objects

  • Each object should be separated with a comma

  • Objects can be GUI objects or graphical objects

  • Pointers can be used to specify an object.

Code sample:

if exists(gsharp_1.MyDialog)  destroy gsharp_1.MyDialog;
function DestroyChildren(string PARENT)
  string OBJ;
  for OBJ in childrenof(PARENT)
    if (OBJ=undef)  continue;
    OBJ = PARENT+"."+OBJ;
    destroy $OBJ;
  endfor
endfunction
destroy x, y, z;

See also:

set, create

diff - return accumulation of array

Syntax:

float diff(float x)

Description:

Returns the difference between consecutive values in x.

  • The first value is x[1], the second is x[2]-x[1], the third x[3]-x[2] and so on ...

  • accum(diff(x) is equivalent to x

Examples:

x

diff(x)

1
1
1
2
2
4

1
0
0
1
0
2

See also:

accum

differentiate - differentiate y

Syntax:

float differentiate(float y)

Description:

Differentiate y using the following approximation:

dy/dx[n] = (y[n-2] - 8*y[n-1] + 8*y[n+1] - y[n+2]) / 12

  • The first two and last two points have their own special treatment

  • The approximation is exact for third degree polynomials

  • It is assumed that y values are 1 unit in x apart. If they are not use the expression: differentiate(accum(diff(y)/diff(x)))

Code sample:

x = range(-10//10,100);
y = cos(x);
y2 = differentiate(accum(diff(y)/diff(x)));
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 = "line",
     XuNxData = "x",
     XuNyData = "y"
   );
create Graph page_1.viewport_1.domain_1.graph_2
   ( XuNxData = "x",
     XuNyData = "y2"
   );

See also:

integrate, diff

dirlist - return list of subdirectories

Syntax:

string dirlist(string path)

Description:

Return as a string array the subdirectories of the directory path.

  • To specify a \ in path use either \\ or /

  • If no subdirectories exists undef is returned.

Code sample:

for dir in dirlist("$UNIDIR/example/Gsharp")
  PTR = "gsharp_1.menubar.Examples."+dir;
  create Menu $PTR;
endfor

See also:

filelist

div - integer division

Syntax:

float div(float x, float y)

Description:

Returns the integer division of x by y.

  • div(x,y)*y + mod(x,y) is equivalent to x

Examples:

x

div(x,2)

-3
-2
-1
0
1
2
3

-1 
-1 




Code sample:

reset all;
nx = 4;  ny=2;
vsize = (100,100)/(nx,ny);

for i=0 to nx*ny-1
  PTR = "page_1.view"+i;
  vorigin = (mod(i,nx),div(i,nx)) * vsize;
  create Viewport $PTR
   ( XuNfirstDiagonalPoint = vorigin + vsize*.1,
     XuNsecondDiagonalPoint = vorigin + vsize*.95
   );
  create Domain $(PTR).dom;
endfor

See also:

mod

dropx - return dataset without specified rows

Syntax:

float dropx(any x, float rows)

Description:

Return the dataset x without the specified rows

  • The function slicex can be used if you prefer to specify which rows to keep.

Examples:

x

dropx(x,1//3)

1
2
3
4
5

2
4

Code samples:
#remove first row
x = dropx(x,1);
#remove last row
x = dropx(x,sizex(x));
#remove every other row
x = dropx(x, (1:sizex(x))*2);

See also:

dropy, slicex, regular

dropy - return dataset without specified columns

Syntax:

float dropy(any x, float columns)

Description:

Return the dataset x without the specified columns

  • The function slicey can be used if you prefer to specify which columns to keep.

Examples:

x

dropy(x,1//3)

(1, 2, 3, 4, 5)
(6, 7, 8, 9, 10)

(2, 4, 5)
(7, 9, 10) 

See also:

dropx, slicey, regular

dropz - return dataset without specified planes

Syntax:

float dropz(any x, float planes)

Description:

Return the dataset x without the specified planes

  • The function slicez can be used if you prefer to specify which planes to keep.

See also:

slicez, dropx, dropy