13.07.2015 Views

Fortran 90/95 Programming Manual

Fortran 90/95 Programming Manual

Fortran 90/95 Programming Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Fortran</strong> <strong>90</strong>/<strong>95</strong> <strong>Programming</strong> <strong>Manual</strong>Examples:In the following examples, b denotes a blank character.trim (“bbStringbb”) gives “bbString”adjustl (“bbTanja”) gives “Tanjabb”adjustr (“Wordbbbbb”) gives “bbbbbWord”index (“Tanja van Mourik”, “van”) yields 7.len_trim (Tanjabbbb) yields 5.In the following example the program reads a file and uses the intrinsic index to searchfor the occurrence of the word “energy”:!! Example for reading an output fileprogram readoutimplicit noneinteger, parameter :: linelength = 120character (len=linelength) :: lineinteger :: ierroropen (unit=10, file="test.dat", action ="read", status="old", iostat=ierror)if ( ierror /= 0 ) thenprint * , "Failed to open test.dat!"stopend ifreadfile : doread (unit=10, fmt="(a)", iostat=ierror) lineif (ierror < 0 ) thenprint * , "end of file reached"exit readfileelse if (ierror > 0) thenprint * , "Error during read"exit readfileelse! line has been read successfully! check if it contains energyif (index (line, "energy") > 0) thenprint * , "energy found!"exit readfileend ifend ifend do readfileclose (unit=12)end program readout54

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!