 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
Jim
Joined: 21 Jul 2006 Posts: 24 Location: USA
|
Posted: Mon Jan 31, 2011 1:48 pm Post subject: Read and Write Statements (I/O). |
|
|
Can someone assist me with opening a file and reading data from same? I am using the following read statement and compiling with FTN95 but I am not successful in reading the data.
READ(5,101) NUMNP,NUMEL,NEN,NTIM
101 FORMAT(5I5)
If someone has examples of OPEN, READ and WRITE statements that I could modify for my use, please post for me.
Thanks!
 |
|
Back to top |
|
 |
Wilfried Linder
Joined: 14 Nov 2007 Posts: 314 Location: D�sseldorf, Germany
|
Posted: Mon Jan 31, 2011 1:57 pm Post subject: |
|
|
You want to read 4 values but you define 5 in the format statement.
Try format(4I5). |
|
Back to top |
|
 |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2402 Location: Yateley, Hants, UK
|
Posted: Mon Jan 31, 2011 3:55 pm Post subject: |
|
|
Jim,
Unit 5 is one of the traditional numbers that meant "card reader" and later "console". You would be better off with a bigger number, especially reading from a file. (0, 1, 5 and 6 are likely to be dodgy!).
Before you can read from a file, you need an OPEN statement. How about:
Code: | OPEN (UNIT=25, FILE='DATAFILE.DAT',STATUS='OLD') |
Then, you can read more or less as you wrote. I wouldn't worry about having 5I5 instead of 4I5. You don't even need a FORMAT on input especially, just so long as the numbers are separated by blanks or commas.
Code: | READ(25,*) NUMNP, NUMEL, NEN, NTIM |
It looks very much as though you are beginning a time-stepping finite element program here - lots of people on the forum are into FE!
In the OPEN statement you can have a whole bunch of other stuff dealing with (for example) what you do if the file can't be opened etc.
If you get round to using Clearwin+, you will be able to use the Windows interface to give your users a standard way of selecting files.
Eddie |
|
Back to top |
|
 |
IanLambley
Joined: 17 Dec 2006 Posts: 506 Location: Sunderland
|
Posted: Tue Feb 01, 2011 1:35 pm Post subject: |
|
|
If you use a 4I5 format for inputting 4 integer variables, then really these should be spaced as such in the input file and right justified within each field otherwise you get strange results. For example:
Code: |
IIIIiiiiIIIIiiii
3 3 3 3
|
will give the four values as 3, 30, 3030, 0
There are at least two things you can do:
1. Put a coma between each input value and avoid trailing spaces.
2. Do as Eddie says and use *, and then it does not matter what type of variable you are reading, but for character values, enclose them in apostrophes.
Regards
Ian |
|
Back to top |
|
 |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2402 Location: Yateley, Hants, UK
|
Posted: Tue Feb 01, 2011 7:27 pm Post subject: |
|
|
Ian,
You've done 4I4, or do my eyes deceive me? Those fixed formats are hell on input!
Eddie |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|