Silverfrost Forums

Welcome to our forums

Read and Write Statements (I/O).

31 Jan 2011 12:48 #7656

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!

😄

31 Jan 2011 12:57 #7657

You want to read 4 values but you define 5 in the format statement. Try format(4I5).

31 Jan 2011 2:55 #7658

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:

      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.

      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

1 Feb 2011 12:35 #7666

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:

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

1 Feb 2011 6:27 #7668

Ian,

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

Eddie

Please login to reply.