Fortran Class Notes
Lecture 9 – Character Variable Manipulation
When we first discussed different types of variables, you probably wondered how
character variables (sometimes called “strings”) could be useful in engineering
After all, we’re usually not interested in writing things to the screen in a
fancy way or dealing with a lot of text data to solve problems.
But it turns out that some
common, very useful functions in Fortran require character inputs.
For these functions, it
helps to understand how to declare, store, and edit character variables.
You might also
need to convert real numbers or integers into character variables, or vice-versa.
following program contains some examples of these tools:
format(1x,'Please enter the filename you wish to open. ',$)
if (junk(1:1).eq.' ') then
write(*,*) 'This file appears to be empty.'
write(11,*) 'Hello, new file!'
write(*,*) 'This file starts with: ',junk
In this program, we want to let the user type in a file to be opened, rather than always
hardwiring the filename as before.
But the “open” command requires a character string