Advanced Labs UNIX - Gnome Desktop - GEdit BASICS

This computer exercise will introduce you to logging in to the computer lab workstation via the Linux (UNIX) operating system, the Gnome , and the GEdit . You should keep a record of your computer work in your lab notebook , with notes as to what procedures worked and which ones gave problems, and printouts of files. The computer stations are located in Thornton room 123 (obtain door code and password from department secretary). Please close the door if you are the last to leave.

1. Logging On. You will work from a computer using the Linux operating system (or possibly from a Windows PC, in which case normal Windows procedures apply; in that cae, follow instructions in Appendix A). (You are strongly encouraged to use a Linux computer if available since some familiarity with UNIX may be helpful later in your career.) Press the space bar to make the screen activate. You should see a log-in screen; proceed to enter your user name and then your password. From there, the Gnome “desktop” should open up (may take a while). Next, open a terminal window by clicking on the menu choice Applications>Accessories>Terminal . (From the Applications menu, you can also run a variety of other useful programs, such as the Gedit text editor and standard office applications from OpenOffice, such as the “Writer” word processor (similar to Microsoft Word) or the “Impress” presentation program (similar to PowerPoint); more on this later.)

At this point, you should be seeing a UNIX operating system command prompt (something like th123-2:yourname% ;); that is, UNIX is waiting for you to tell it what to do. Some useful UNIX commands:

ls Lists the files in your directory cd dirname Change directory. Without a “dirname”, will return you to your home directory. cd / will take you to the root directory. pwd “Present working directory” – shows what directory you are in mkdir dirname Makes a sub-directory named “dirname” in the current directory cat filename Displays the file on the screen; lpr filename Prints the file contents on the laser printer or lp -dhp1_1 filename [The laser printer you will be using is located near the front of TH123] cp file1 file2 Copies contents of file1 into file2 rm filename Removes that file man commandname Shows the manual page(s) for that command (type q at end of file to exit) who Shows who is logged on to the system

You might want to try some of these commands before proceeding with this tutorial. Ask the instructor or other users if you need help.

2. Gnome Desktop. Our Linux workstations use a Graphical User Interface called Gnome, which lets you have several different viewing windows into the computer. Try moving the mouse around the workspace to see how the pointer responds. The buttons on the mouse have the following general assignment:

LEFT BUTTON: "Select" RIGHT BUTTON: "Menu"

You can use the mouse to open and close windows, move windows, and change the size of windows in the same way as in Windows XP or Vista. In particular, the three buttons in the top right corner of the window allow you to close the window and exit by pressing the "X", expand the window to full screen by clicking on the middle button, or reduce the window to a taskbar button by clicking on the left-most button. [These buttons may not appear until you run a program later on.] To move a window, put the mouse pointer on the upper window border, press and hold the SELECT button, drag the window to the new location, and release the SELECT button. To resize, put the mouse pointer on a corner or border of the window until you see a two-headed arrow and follow the above procedure. You can reopen a window which was previously reduced to a button by putting the mouse pointer on the button and clicking the SELECT button. At this point, you can close the command window.

3. GEdit. One of the useful things we can do within the is to use GEdit, a modern mouse-based text and program editor that is much like a word processor (and could serve as a (slightly awkward) one for writing your reports). Use the menu sequence Applications>Accessories>Text Editor to start GEdit. A text editing window should appear with a list of menu names at the top and a small indicator where text will be entered. Try entering some sample text, using the backspace key to fix mistakes, using the mouse to insert new text in the middle of old, using some of the edit menu functions (put the mouse pointer on the menu name, left click, get the highlight bar on the item you want, and then release the mouse button), etc.

After you have experimented a bit, erase any text you have entered and then enter the following set of data values (with the three values on each line separated by spaces):

0 8 3 1 20 3 13 110 3 17 190 3 21 230 3 28 215 3 48 215 3 51 225 3

Make sure there is no "empty line" at the end of the file - that is, be sure the end of the file cursor position is just after the last "3", NOT at the beginning of a new line.

We want to save this data set in a data file called first.dat . Pull down the "file" menu title and click with the left mouse button on "save as". A line for entry of the filename will appear. Move the mouse pointer to the beginning of this line and type in first.dat . Then click on "save". You should also print a copy of the file first.dat and paste the copy in your lab notebook.

Now let's prepare a second file. Erase the existing data. You can do this by dragging the pointer to the end of the text (mouse button held down) and then releasing the button. When all the text is selected, put the mouse pointer on the "edit" menu title, pull down the menu, and click the left mouse button on "cut". Gone! (You might want to experiment with "undo"; if so, be sure the screen is clear when you're finally done.)

You will now write a MATLAB command script which will be used later on to do graphics in MATLAB. I have added some comments; please do NOT type in these comments. Enter the following: load first.dat; %Reads in the data file "first.dat" into a matrix called first x = first(:,1); %Make an array of x-axis values from data matrix column 1 y = first(:,2); %Make an array of y-values from data matrix column 2

Comp-2 e = first(:,3); %Gets error bar value array from data matrix column 3 errorbar (x,y,e,e,'*'); %Plot x-y data with y-errorbars given by array e; * symbol at points xlabel ('Age (years)') %Label the x-axis ylabel ('Weight (pounds)') %Label the y-axis title ('Weight versus Age') %Add a title to the plot

Now save this set of text lines under the filename firstplt.m . We will use this command script file along with the data file in a later exercise. It would be good to print out a copy of this MATLAB script, or “m file”, and paste it in your lab notebook. We can now leave the text editor. Click on the "X" button at the top corner.

You might want to do a ls command (at the UNIX prompt in a terminal window) to be sure that your new files have been stored; you might also want to try a cat command to view your new files. (On some computer systems, the files you create will not be in your home directory, but rather in a “my documents” directory. Check with the instructor if you have trouble finding your files.) You could print the files, if not already done, using the command " lpr firstplt.m" if you like. [An alternate print command is " lp -dhp1_1 firstplt.m" ] You could also print your files directly from GEdit.

To finish up, exit any programs you've been running (including the terminal window) by clicking on the corner "X" . We now can log off by following the menu sequence System>Log Out . ------Appendix A: Notepad and the MATLAB Text Editor

If you are working on a Windows PC (likely Windows XP), you can use the Notepad text editor to perform the same functions as GEdit. Run it from the “Start” menu; follow the sequence Accessories>Notepad.

MATLAB has a useful and handy built-in text editor (the MATLAB Editor/Debugger). The MATLAB text editor is similar to other text editors, but it is especially suited for creating MATLAB-specific files (called M-files, or .m files).

There are a number of different features that the MATLAB text editor offers. One such feature is (i.e., comments are green, command lines are black, and other constructs will use other colors), making it easier to read the script. Another is that it automatically append the ".m" suffix when saving script files, so you don't need to append it yourself The MATLAB text editor also offers extensive debugging functionality as well (i.e., finding and fixing errors in scripts). In this tutorial, we will not go into the debugging functionality of the MATLAB editor, but you can find examples in the Help Browser of MATLAB.

To start the MATLAB text editor, first start MATLAB from the Start menu, or from a MATLAB icon on the desktop. Then, simply type “edit” at the command prompt. Another way to invoke the editor is to select File->New->M-file from the MATLAB desktop menu bar. You should see the editor open with a new, empty document. If you want to start the editor up with an existing file (e.g., a script file you have partially completed), then you can either type at the command prompt “edit”, followed by the name of the file, or select File->Open... from the MATLAB Desktop, and then choose the file you want to open from the Open dialogue box. The way you use the MATLAB text editor is essentially the same as how you would use Windows Notepad, GEdit, or other simple text editors.

Comp-3 When you are done editing, save your script file. The default file type for saving files is a script file, or "M-- file", with an ".m" extension. If you are preparing a data file with the MATLAB editor, you need to choose the "all files" as the file type and put on your own extension (probably .dat; for example, signal1.dat ).

Note that MATLAB's editor will save files to a "working" directory within MATLAB, which may not be the same as your home directory. If you want to open files with the MATLAB editor, or run scripts you have written, the files need to be in the MATLAB "working" directory, or else there needs to be a path to your home directory specified in the MATLAB path list. See the references for more on paths and the "pathtool" command. ------Appendix B - Instructions for Use of OpenOffice Applications

You may later want to use OpenOffice Writer for doing lab reports, so here are some instructions on how to run it.

From the Gnome desktop, follow the menu sequence Applications>Office>WordProcessor. A window for the Writer word processing application should open. All the usual menus are there for saving and opening files, inserting figures, etc.

If you want to insert an equation or formula, follow the menu sequence Insert>Object>Formula. The equation editor window should open near the bottom of the screen, and a floating “Selection” window should also appear, as well as a small box in your document where the formula will be displayed.

The equation editor uses a markup language (similar to TeX) to represent parts of an equation. For example, %beta creates the Greek character beta ( β). It is useful to learn some of this markup language, since MATLAB uses a similar approach for putting special characters in axis labels of plots.

The attached pages provide more guidance on how to enter formulas. You don’t need to read or work through this now, but can refer back to it when you need to write an equation in a lab report.

Comp-4