In troth, the Fortran programming language is well suited for those persons who are scientific and who engineer. Named so for the phrase “Formula Translation,” it is a language exquisite for programming machines.
If it please thee, Fortran was begun in the 1950s upon an honourable respect by IBM for applications of scientific and engineering. Fortran would prevail i’ th’ field from our ancient masters to this present day, as its virtue has been witnessed through th’ incessant use in demanding computational areas.
Avail thyself of this guide to establish Fortran within thy machine and maketh a well-appointed program out of it.
Before thou dost undertake this guide, thou must for thine avail taketh an Ubuntu 16.04 server exalted with a sudo non-root user, which thou wilt accomplish in reading “Initial Server Setup with Ubuntu 16.04.”
If thou findest that thou art not as familiar as thou wouldst lief with a terminal environment, thou may findest the article “An Introduction to the Linux Terminal” to be of good use.
We doth begin with amending our machine by making much use of the command that follows here:
- sudo apt-get update
Now to the next, we will furnish our machine with the GNU Fortran gfortran compiler that will make good work to compile sundry varieties of Fortran: Fortran 95, Fortran 2003, Fortran 2008. We shall now employ us the following command:
- sudo apt-get install gfortran
When the terminal doth prompt us with the request of whether we may find fair fortune in continuing, we shall press y
to carry on.
Upon finding the installation well-furnished, we may issue forth the following command:
- gfortran
As, in troth, we have not yet supplied our merry command with a Fortran file, we shall receive only the error that here follows and it may seem lamentable to thine eyes, yet this doth mean that the compiler has found itself well-installed:
Outputgfortran: fatal error: no input files
compilation terminated.
Now art thou ready to try thy compiler with a Fortran program.
Forsooth, with thy compiler having been prepared thou may be found ready to create a new file in the text editor of thy choosing, suchlike nano
. A program by any other name is just as computational; thou may call it OWorld
for instance. Fortran 2008 is that variant of the language most recent and stable, and as is wont to do, thou will use the extension .f08
to signify this.
- nano OWorld.f08
In good time, thou may now commence this pattern: begin first with the program
keyword and name the program
again whatsoever thou would fancy. The name passed to the program keyword and the name used for the program file need not match, and to here demonstrate we shall use OWorld
for the program file and o_world
with the program
keyword.
program o_world
Whilst at this fair point we will avail of no variables, as thou would achieve good acquaintance with Fortran by including this good phrase, prithee write implicit none
to allow thy compiler to check for well-declared variable types.
program o_world
implicit none
Yea, at this very moment, thou may issue forth and bid the program to print thine O, world!
greeting:
program o_world
implicit none
print *, "Good morrow, and well met, O world!"
The print
statement herein employed intakes parameters and deliveth them unto output. Thou likely taketh notice of the asterisk (*
), which kindly informs thy machine to output thy data that follows in a manner most profitable and suitable to the type of items that are therein contained in what may be a comma-delimited list or which character strings or variables make a part.
In thine own case, thou hast bestowed a character string singularly to the print
statement.
Lastly and finally, thou shall end the program right well with the end
statement. Here, thou doth do well to include the specific form of the unit, in this case program
, and to be most specific thou canst include the name of the unit (o_world
).
program o_world
implicit none
print *, "Good morrow, and well met, O world!"
end program o_world
Thou hast completed a great feat in this ending.
‘Tis that thou hast happily arrived at the last. Now thou canst compile the OWorld.f08
program
For to compile and meet successful fortune, issue forth the command that next comes:
- gfortran OWorld.f08
This command doth conceive an executable file, and thou may in thy machine discover it through the ls
command:
- ls
Outputa.out OWorld.f08
This new-come file must be bade to run, which thou must perforce accomplish through issuing this in writing to thy terminal:
- ./a.out
The program output at once will be delivered to thee:
Output Good morrow, and well met, O world!
With gratitude to kind fortune, thy program hast run most profitably.
If thou dost dislike the filename a.out
, thou can make a fine change quick to rename the file with a custom name:
- gfortran OWorld.f08 -o OWorld
Run it in the similar fashion as afore:
- ./OWorld
Thou shall find output that doth match:
Output Good morrow, and well met, O world!
Thou hast built and run a fine program!
Shall we at last conclude our survey of Fortran with prodigious satisfaction?
When thou dost undertake a new Fortran program, let thou keepest in mind:
!
)From here, it may please thou to read the culinary guide on “Fashioning Thy Turkey Supper.”
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
I want to submit for the DigitalOcean Technical Writer, Product Marketing opportunity and this piece ensnared me ;-) .
I did note the use of “thou” as an adjective throughout, as used in this example to modify “compiler”:
“Now art thou ready to try thou compiler with a Fortran program.”
Although “thou” most definitely operates agreeably as an adjective, would not “thine” as a more “pure” adjective - strictly in this and similar situations - work more efficaciously for such purposes? In the case above, “thou” reads almost as if one addressed the compiler itself. I render a most subjective claim here; I can state only that “thine” in such cases rings more true to my eyes and ears . . .
Thank you!
This is hilarious, that’s the best way to make a tutorial about fortran. Thanks!
Very helpful, thank you!
DO proves once again why its community is so strong and lively. Embrace the academia.
Coming from physics, I still remember my FORTRAN days!
" Cutting-edge research still universally involves Fortran… " From: https://arstechnica.com/science/2014/05/scientific-computings-future-can-any-coding-language-top-a-1950s-behemoth/
This comment has been deleted
rrrrr
This comment has been deleted
This comment has been deleted
VERILY, THOU HAST NOT UTILISED SUFFICIENT CAPITAL LETTERS.
This comment has been deleted