Fortran_Fortran Structure and Style - Wikibooks, Open Books for an Open World

1
Fortran/Fortran structure and style Style Older versions of Fortran had strict guidelines on how a program was formatted. However new versions, especially Fortran 90 and above have modernized, allowing more flexibility. Originally Fortran required all statements to be in ALL CAPS, and in fact the language itself was called FORTRAN (in caps). It remains a bit customary, though completely unnecessary, to put Fortran commands in ALL CAPS. PROGRAM test IMPLICIT NONE INTEGER four four = 4 WRITE (*,*) four END PROGRAM Whitespace and empty lines usually won't matter in F90 or above, but in rare cases errors will pop up. However, unlike many other languages such as C, C++, and Java, the line delimiter ';' is optional, so each line of code may stay on its own line! Structure There is a GOTO command, but don't use it too much. Use DO loops early and often. Encapsulate your code into functions and subroutines making it easier to program at higher levels, and allowing others to understand whats going on. Comment your code well. Don't comment every line, but explain how everything works. Retrieved from "http://en.wikibooks.org/w/index.php? title=Fortran/Fortran_structure_and_style&oldid=2124554" This page was last modified on 23 June 2011, at 00:42. Text is available under the Creative Commons AttributionShareAlike License.; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy.

Transcript of Fortran_Fortran Structure and Style - Wikibooks, Open Books for an Open World

  • 3/23/2015 Fortran/FortranstructureandstyleWikibooks,openbooksforanopenworld

    http://en.wikibooks.org/wiki/Fortran/Fortran_structure_and_style 1/1

    Fortran/FortranstructureandstyleStyle

    OlderversionsofFortranhadstrictguidelinesonhowaprogramwasformatted.Howevernewversions,especiallyFortran90andabovehavemodernized,allowingmoreflexibility.

    OriginallyFortranrequiredallstatementstobeinALLCAPS,andinfactthelanguageitselfwascalledFORTRAN(incaps).Itremainsabitcustomary,thoughcompletelyunnecessary,toputFortrancommandsinALLCAPS.

    PROGRAMtestIMPLICITNONEINTEGERfourfour=4WRITE(*,*)fourENDPROGRAM

    Whitespaceandemptylinesusuallywon'tmatterinF90orabove,butinrarecaseserrorswillpopup.However,unlikemanyotherlanguagessuchasC,C++,andJava,thelinedelimiter''isoptional,soeachlineofcodemaystayonitsownline!

    Structure

    ThereisaGOTOcommand,butdon'tuseittoomuch.UseDOloopsearlyandoften.Encapsulateyourcodeintofunctionsandsubroutinesmakingiteasiertoprogramathigherlevels,andallowingotherstounderstandwhatsgoingon.Commentyourcodewell.Don'tcommenteveryline,butexplainhoweverythingworks.

    Retrievedfrom"http://en.wikibooks.org/w/index.php?title=Fortran/Fortran_structure_and_style&oldid=2124554"

    Thispagewaslastmodifiedon23June2011,at00:42.TextisavailableundertheCreativeCommonsAttributionShareAlikeLicense.additionaltermsmayapply.Byusingthissite,youagreetotheTermsofUseandPrivacyPolicy.

    http://creativecommons.org/licenses/by-sa/3.0/http://wikimediafoundation.org/wiki/Privacy_policyhttp://wikimediafoundation.org/wiki/Terms_of_Usehttp://en.wikibooks.org/w/index.php?title=Fortran/Fortran_structure_and_style&oldid=2124554