| Gsharp Training Material | Home | Table of Contents |
Lesson 2 is designed for 1 day courses covering all aspects of Gsharp. For longer courses it is better to use the organised reference material and exercises which work systematically through all components of Gsharp. When time is short and the objective is to have done everything once rather than thoroughly then lesson 2 is the answer.
The steps continue to use less step by step instructions and more descriptions of required targets.
Enter the following command to initialise UNIRAS:
. /usr/local/uniras/7v0/base/uni.profile
This script will add $UNIDIR/bin to your path and set various environment variables concerning licensing, man pages, shared libraries and help pages. On holyrood this will be part of the standard uni.profile startup.
Gsharp has the following start-up options
The one tool we did not look at in lesson 1 was the DataManager.
The DataManager can be used for all parts of data handling, import, export, viewing, manipulation and interpolation.
Each piece of data in Gsharp is called a dataset.
Datasets come in four different types
and various dimensions
The DataManager already contains a string dataset called argv with a size of 3. It contains the arguments that Gsharp was started with.
Gsharp can read the following file types:
There are also GSL functions which can be used to read and write data. e.g. fopen(), fread(), fseek() and fwrite().
The following message appears: ``Import Report: 208 values
read into
T1, T2, T3''
The three datasets that you have read in, T1, T2 and T3 have been added to the DataManager. You can see that they are floats, that they contain 208 values and what is the minimum and maximum of each dataset.
x=T1; y=T2; z=T3
destroy T1,T2,T3
Gsharp contains almost 200 data operators for working with your data. They include
Generally, data operators will work on whole datasets at a time. x+3 will add 3 to every value in x. x+y will add the corresponding values of x and y.
both = x+y
xmax = max(x)
sinZ = sin(z)
Gsharp 2.1 includes some functions for retrieving coastlines and country borders from a Worldmaps database.
code is a 3 letter string as defined in Appendix B of the Gsharp User's Guide.
resolution is one of ``full'', ``reduced_1'', ..., ``reduced_4''
x is the name of the output Longitude dataset, default is Long
y is the name of the output Latitude dataset, default is Lat
getcode() and showcode() convert strings to codes.
showcode(``brit'') displays Great Britain (incl. Northern
Ireland): ``GBR''
getcode(``Great Britain (incl. Northern Ireland)'') returns
``GBR''
Convert country codes back to the country names.
import_worldmap(getcode("France''),"full'',"FRlong'',"FRlat'');
The french coastline (at full resolution) is read into the datasets FRlat and FRlong.
Gsharp contains 7 interpolation methods: spline, smooth, polyfit, bivariate, bilinear, regular and kriging.
They all have different uses.
For example, spline, smooth and polyfit take a set of (x,y) points and create a line based upon them.
Bivariate and bilinear take scattered (x,y,z) data and produce a regular 2d grid which can then be contoured.
xgrid = range(x,40);
ygrid = range(y,40);
range(x,n) returns a dataset of n equally spaced values with the same limits as x.
A dataset called grid has been added to the DataManager it is a float dataset of size 20 by 20. It contains an interpolated value for all of the grid nodes defined by xgrid and ygrid.
You will see that it has been logging all the actions you have been performing in the DataManager.
You will see that the DataManager is reset and all your data is deleted. Your commands are then performed in a fraction of the time it took you.
function readRRdata(string filename)
import_report(filename);
import_worldmap(getcode("France''),"full'',"FRlong'',"FRlat'');
x=T1; y=T2; z=T3;
destroy T1,T2,T3;
xgrid = range(x,20);
ygrid = range(y,20);
grid = bilinear(x,y,z,xgrid,ygrid,FRlong,FRlat);
endfunction
readRRdata(``rrfrance.dat''); #Your filename may differ
The function readRRdata() has one argument, a string called filename, which is used in the call to import_report.(). I have removed the commands made experimenting with data operators.
It is also possible to write your own data operators with GSL functions
function float percents(float x)
float minin, inrange;
minin = min(x);
inrange = max(x)-minin;
return (x - minin) / inrange * 100;
endfunction
The function percents() is passed a float dataset and returns a float dataset. The dataset is scaled so that the values range from 0 to 100. minin and inrange are local variables - they do not appear in the DataManager and are only visible within the percents() function.
if not exists(WORK.grid) then #Check to see if we need to create data
reset data;
fname = input_file(``Select RR file'', ``r'', true, ``rr*.dat'');
readRRdata(fname);
echo(fname," read and interpolated'');
endif
reset; # reset the graphics
Code to create the 3 viewports is added to the bottom of the ScriptBuilder
create Viewport page_1.contour
( XuNfirstDiagonalPoint = (5,10),
XuNsecondDiagonalPoint = (60,80)
);
create Viewport page_1.original
( XuNfirstDiagonalPoint = (65,50),
XuNsecondDiagonalPoint = (95,80)
);
create Viewport page_1.profile
( XuNfirstDiagonalPoint = (65,10),
XuNsecondDiagonalPoint = (95,40)
);
Select them each in turn and then click on the domain icon.
The Graph Gallery appears with MB3 over the graph icon. Scatter is the second graph type.
If you click on the [...] to the right of any resource, Gsharp will display a list of possible options.

and choose a line graph.
This will ensure that 1\xfb of Latitude is equal to 1\xfb of Longitude.

When drawing a coloured graph, Gsharp will calculate some class limits based on the limits of the data and will then assign a colour to each class using the default shading scale.
By default the classes are chosen so that an equal number of points can be found within each class. This means, of course, that our scatter plot and contour plot are using different classes - the colours represent different values.
Gsharp allows you full control over Classes and Colours via resources in the domain object.
classlimits = (1:20);
Your two plots are now using the same class limits and colour scales.
It's very easy to take slices through our grid dataset using the GSL functions slicex() and slicey().

for gslice=1 to 20 repaint; endfor
function DoProfile()
for gslice=1 to 40 repaint; endfor
endfunction
Hold down Control and drag your contour viewport with MB2 onto page_1

A workbox will appear around the plot.
Bring up the ScriptBuilder and delete all the graphics code that already exists at the bottom of the script builder. Do not delete the GSL functions you have defined.
Select Tools/Generate GSL.
File/Save
function View()
string choices;
choices = ``2D contour''//"3D Contour'';
if input_selection(``Select View'',choices,1)=choices[1] then
page_1.contour.XuNobjectEnabled = true;
page_1.contour3D.XuNobjectEnabled = false;
else
page_1.contour.XuNobjectEnabled = false;
page_1.contour3D.XuNobjectEnabled = true;
endif
endfunction
You should now be confident enough to start working with Gsharp.
If you want to run through the basics again, the Gsharp Getting Started Guide is a more complete introduction to the product.
Although much of the manual is reference material, there is also plenty of light reading, particularly if you wish to learn GSL.
The Gsharp examples are found in $UNIDIR/example/Gsharp and show much of the graphics functionality of Gsharp. They also include examples of GSL programming.
If you are having problems which you cannot find described in the Manual nor illustrated by a Gsharp Example then you may find a solution in the Gsharp FAQ
We'd love to hear of any problems that are missing from the FAQ.
If you are still struggling - get in touch.