Fortran_Lecture_9

Fortran_Lecture_9 - Fortran Class Notes Lecture 9 Character...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
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 applications. 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. The following program contains some examples of these tools: program lingo1 character*20 fname,junk write(*,10) 10 format(1x,'Please enter the filename you wish to open. ',$) read(*,*) fname open(unit=11,file=fname,status='unknown') junk=' ' read(11,*,end=12) junk 12 continue if (junk(1:1).eq.' ') then write(*,*) 'This file appears to be empty.' write(11,*) 'Hello, new file!' else write(*,*) 'This file starts with: ',junk end if close(11) stop end 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
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

Fortran_Lecture_9 - Fortran Class Notes Lecture 9 Character...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online