replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Read and Write Statements (I/O).
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Read and Write Statements (I/O).

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
Jim



Joined: 21 Jul 2006
Posts: 24
Location: USA

PostPosted: Mon Jan 31, 2011 1:48 pm    Post subject: Read and Write Statements (I/O). Reply with quote

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!

Very Happy
Back to top
View user's profile Send private message
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: D�sseldorf, Germany

PostPosted: Mon Jan 31, 2011 1:57 pm    Post subject: Reply with quote

You want to read 4 values but you define 5 in the format statement.
Try format(4I5).
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2402
Location: Yateley, Hants, UK

PostPosted: Mon Jan 31, 2011 3:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
IanLambley



Joined: 17 Dec 2006
Posts: 506
Location: Sunderland

PostPosted: Tue Feb 01, 2011 1:35 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2402
Location: Yateley, Hants, UK

PostPosted: Tue Feb 01, 2011 7:27 pm    Post subject: Reply with quote

Ian,

You've done 4I4, or do my eyes deceive me? Those fixed formats are hell on input!

Eddie
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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