CS117: FORTRAN With Linux Tutorial - UC Santa Barbara

1y ago
7 Views
3 Downloads
3.43 MB
26 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Kaydence Vann
Transcription

CS117: FORTRAN with Linux TutorialLucas Bang1

Contents1 Introduction32 Where to Program33 Username and Password3.1 Changing Your Password . . . . . . . . . . . . . . . . . . . . . . . . . . . . .334 Logging in to Linux CentOS45 Setting Up Your Home Directory5.1 Your Home Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5.2 Creating a Directory for Your Programs . . . . . . . . . . . . . . . . . . . .5566 Working in the Terminal6.1 Starting the Terminal . . . . . . . . . . . . . . . . . . .6.2 Listing Directory Contents with the ls Command . . .6.3 Navigating Directories with the cd and pwd Commands6.4 Creating Directories with the mkdir command. . . . . .6.5 The clear Command . . . . . . . . . . . . . . . . . . .7 Completing the First Assignment7.1 Download the Files for Assignment 17.2 Getting Started with a Text Editor .7.3 Editing and Saving Source Code Files7.4 Compiling the Source Code . . . . .7.5 Running the Executable File . . . . .7.6 Submitting the Assignment . . . . .2.889101212.13131517182021

1IntroductionThis tutorial will help you get started writing your first FORTRAN programs. We will cover How to login and change your password in the Computer Science Programming Lab, Logging in and getting started in Linux, Basic Linux terminal command line operations, Writing, compiling, and executing your first program, and How to submit your programming assignments.2Where to ProgramThe Computer Science Department has a computer lab located in TBE B361 where youmay write all your programs. Later in the semester we will learn how to access the necessarysoftware remotely, or how to install it on your personal computer. For now, it is best towork on programming assignments in the lab. One benefit of this is that my office is rightdown the hall, in TBE B346. I am there often and will be available to answer questions.3Username and PasswordYou should have received your username and computer generated password for the lab atyour rebelmail email address. Your user name should be the same as your rebelmail loginname. If you did not receive this information, let me know immediately. You will need thisinformation to complete the assignments.3.1Changing Your PasswordYou were given a password consisting of random characters. It is a good idea to changeit to something you can remember! You can only change your password from theWindows operating system.To change your password:1. Log in to Windows with the username and password you received.(a) If the machine is already on Windows, log in with your credentials and you aregood to go onto Step 2.(b) If the machine is booted into CentOS already, restart the machine. When it boots,it will ask you to select an operating system. Use the arrow keys to highlightWindows and hit enter. Log in with your credentials.(c) If the machine is off, just turn it on. When it boots, it will ask you to select anoperating system. Use the arrow keys to highlight Windows and hit enter. Login with your credentials.3

2. You may have to wait a minute the first time you log in while your profile is generated. Once you are logged in, press Cntrl-Alt-Delete, select the option to changeyour password, and follow the directions. Choose something memorable as your newpassword.4Logging in to Linux CentOSOnce you have changed your password:1. Restart the machine.2. Now, when the machine boots up, use ther arrow keys to highlight CentOS and hitenter. You should choose CentOS from now on when logging in to work on assignments.3. Log in with your username and new password. You may need to scroll all the waydown to the bottom and click ‘other’ to reach the login prompt.4

55.1Setting Up Your Home DirectoryYour Home DirectoryWhen you log into CentOS, you should have a Home Directory accessible from the desktop.5

5.2Creating a Directory for Your ProgramsIt is recommended that you create a directory (folder) where you can save, store, and organizeall of your programs for this class. You can “right-click” to create a new folder. If you haveused almost any operating system to create file folders this should seem very simple, as it isthe same in Linux. I created a folder in my home directory called “cs117” where I will storeall my files.6

You should also create some individual folders for each assignment. For now, you can justmake two directories if you like, because we will illustrate the command line operations usedto create directories in the followign section. The assignments will all be numbered with twodigits: 01, 02, 03, . 14, 15. Keeping your files separate for each assignment will help youavoid confusion later when things get more complicated and we need multiple files for eachassignment.7

6Working in the TerminalYou can also accomplish many tasks by typing Linux commands. This section will show youhow to use the Terminal Command Line to create folders and files and navigate around yourhome directory.6.1Starting the TerminalYou can start the terminal by typing Cntrl-Alt-T. You can also open a terminal by clickingApplications System Tools Terminal.8

You should now have a terminal with a prompt where you can type commands.6.2Listing Directory Contents with the ls CommandWhen the terminal opens it starts up in youe home directory by defualt. You can type lsand hit enter and you should see a list of all the folders and any other files in your homedirectory. For instance, you can see the cs117 directory that we created earlier.9

6.3Navigating Directories with the cd and pwd CommandsIn order to ‘change directories’, you can type cd followed by the name of a directory. Forexample, to change to your cs117 directory, type cd cs117 and press enter. If you againuse the ls command, you should now get a list of any directories you created earlier to storeyour assignments.If you ever forget which directory you are in, you can use the pwd command, which standsfor present working directory.10

Sometimes it is useful to just “jump” all the way back up to your main directory. There isa quick shortcut for this – you can just type cd (the cd command followed by a tilde). Ifyou then type pwd or ls you can see that you are indeed back in the top directory.You can also easily go up just a single level in the directroy structure by using the commandcd . ( the cd command followed by two periods or ‘dots’). For instance, if we are in ourmain directory and move to the directory for your first assignment using cd cs117/01, youcan then move up just one level in the directory by typing cd . and pressing enter.11

6.4Creating Directories with the mkdir command.Instead of right clicking to create folders, you can also create folders using the mkdir command, which is short for make directory. If you are in your cs117 directory and want tocreate a folder to hold your files for assignment 03, you can use the command mkdir 03.If you use the ls command you should be able to see that the new directory has been created.6.5The clear CommandIf you want to clear the screen of old commands, just so that you don’t have to look at themanymore, you can use the clear command.12

7Completing the First AssignmentNow that you are a little more familiar with Linux, let’s get started working on our firstassignment.7.1Download the Files for Assignment 1Download and save the instructions and source code from the course announcements page.You will have to use the Firefox browser in the You will probably have to right-click and select “save file as”. You should save the file inyour assignment 01 directory.13

Make sure to save or move the files into the directory you created for the first assignment.14

7.2Getting Started with a Text EditorThere are a variety of text editors available in CentOS, but I think Gedit is the easiest touse when you are first starting out programming. Follow these directions to get started:1. Open Gedit by clicking Menu Accessories Gedit.2. You can set the syntax highlighting of Gedit so that it recognizes FORTRAN statments and color codes them for you. This helps you to recognize mistakes as you areprogramming. You can set this up from the menu in the bottom right corner of theGedit window.15

3. You can also enable other helpful programming tools, like showing the line numbersand highlighting matching parentheses by clicking Edit Preferences.4. Now you can look at real FORTRAN code! Click File Open, navigate to the sourcecode that you downloaded for Assignment 1, and open it.16

7.3Editing and Saving Source Code FilesNow that you have opened the file, all you need to do is edit it to include your name and theassignment number in the comments section. All of your future assignments should containthis information within the comments at the top of your files. Click Save after you havemade the changes.17

7.4Compiling the Source CodeIn order to compile the source code, go through the following steps.1. Open a terminal and use the cd command to navigate to the directory that containsthe source code. You can use the ls command to make sure the code file is there inthe right place. You might have a file with the same name that contains a tilde (sim)at the end. This is a backup file that gedit creates in case something happens and youlose your work in the original file for some reason. You can just ignore it.18

2. Enter the following command very carefully and hit enter.gfortran ast01.f95 -o ast01The command line argument gfortran calls the FORTRAN compiler. The next argument is the name of the file that you want to compile, ast01.f95. Then using the -oast01 option, you are telling the compiler to name the executable ast01. You couldactually give it any name you want, but it is usually a good idea to use a name thatcorresponds to the program you have written.After you compile your file, if you use the ls command again, you should see thatthere is a new file. This is the executable file created from your source code.19

7.5Running the Executable FileIn order to run the program, type ./ast01 on the command line and press enter.You should see something that resembles the following output.20

7.6Submitting the AssignmentWhen you want to submit an assignment you must first log into our server, which is namedbobby. To do this in the terminal, you typessh username@bobby.cs.unlv.edureplacing your username in the appropriate place.The first time you do this, it might ask you to accept an RSA fingerprint. Say yes and itwill connect. You will then have to enter your password. Although the characters do notshow up, once you have entered your password, hit enter.21

Once you are logged in, you should see bobby’s welcome screen.22

Now, use the cd command to navigate to the source code you want to submit. Then typesubmit ast01.f95 01 bangand hit enter.When using the submit command, you must enter the name of the file (ast01.f95), theassignment number (01), and the instructor name (bang), in that order.23

If you correctly enter everything, you should see a message that your code is successfullysubmitted.If you enter something incorrectly, you will see an error message that should give you somehint on how to fix it.24

You can submit as many time as you want, but only the last submission before the due datewill be graded. Once you are satisfied with your submission you can log out of bobby by justtyping logout and pressing enter.25

You’re all done. You can log out of the machine now.26

2. Enter the following command very carefully and hit enter. gfortran ast01.f95 -o ast01 The command line argument gfortran calls the FORTRAN compiler. The next argu-ment is the name of the le that you want to compile, ast01.f95. Then using the -o ast01 option, you are telling the compiler to name the executable ast01. You could

Related Documents:

Course focus on Fortran 90 (called Fortran for simplicity) Changes in later versions (mostly) not important for us ‣ Fortran 95: Minor revision of Fortran 90 ‣ Fortran 2003: Major additions to Fortran 95 ‣ Fortran 2008: Minor revision of Fortran 2003 gfortran compiler: ‣ Fortran 95: Completely supported

Fortran Evolution Fortran stands for FORmula TRANslation. The first compiler appeared in 1957 and the first official standard in 1972 which was given the name of Fortran 66'. This was updated in 1980 to Fortran 77, updated in 1991 to Fortran 90, updated in 1997 to Fortran 95, and further updated in 2004 to Fortran 2003. At each update some

INTRODUCTION TO ABSOFT FORTRAN Absoft Fortran is a complete implementation of the FORTRAN programming languages: FORTRAN 77, Fortran 90, and Fortran 95. It also completely implements ISO Technical Reports TR15580 and TR15581. The microprocessor-based computers of today are vastly more powerful and sophisticated than their predecessors.

Fortran is short for FORmula TRANslation and this guide is based on Fortran 90, which is a version agreed in 1990. Fortran 95, a later standard, was a minor revision of Fortran 90. The latest standard, Fortran 2003, is now supported by some compilers as well. Fortran was developed for general scientific computing and is a very

Build with the Composer Edition (Continued) Boost Fortran Application Performance INTEL FORTRAN COMPILER on Linux* using Intel Fortran Compiler (Higher is Better) Deliver superior Fortran application performance. Get extensive support for the latest Fortran standards (including full Fortran

Linux in a Nutshell Linux Network Administrator’s Guide Linux Pocket Guide Linux Security Cookbook Linux Server Hacks Linux Server Security Running Linux SELinux Understanding Linux Network Internals Linux Books Resource Center linux.oreilly.comis a complete catalog of O’Reilly’s books on Linux and Unix and related technologies .

Other Linux resources from O’Reilly Related titles Building Embedded Linux Systems Linux Device Drivers Linux in a Nutshell Linux Pocket Guide Running Linux Understanding Linux Network Internals Understanding the Linux Kernel Linux Books Resource Center linu

Dr. Alfredo López Austin [National University of Mexico (UNAM)] Golden Eagle Ballroom 3:00 pm 3:15 pm BREAK 3:15 pm 4:00 pm BREAKING THROUGH MEXICO'S PAST: DIGGING THE AZTECS WITH EDUARDO MATOS MOCTEZUMA Dr. David Carrasco (Harvard University) Golden Eagle Ballroom 4:00 pm 4:30 pm 4:30 pm 5:00 pm TLAMATINI AWARD PRESENTATION to Dr. Eduardo Matos Moctezuma (Bestowed by Dr. Rennie Schoepflin .