|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
mike.smartcam
Joined: 02 Aug 2014 Posts: 40 Location: Lancashire, United Kingdom
|
Posted: Mon Jan 19, 2015 7:52 pm Post subject: READ Statement question |
|
|
Hi Group,
The following code is designed to read data from a file:
Code: | * FILE: READ_ID.FOR
* SUBROUTINE TO READ FIRST TO RECORD OF A FILE
***********************************************************************
SUBROUTINE READ_ID(UNIT,NUM,ERROR)
IMPLICIT NONE
INTEGER NUM,UNIT
CHARACTER *60 STRING
LOGICAL ERROR
ERROR = .FALSE.
READ(UNIT,'(A)',ERR=99)STRING
READ(UNIT,*,ERR=99)NUM
RETURN
99 PRINT*,'ERROR in reading file header.'
ERROR = .TRUE.
RETURN
END |
Can anyone tell me please what is the purpose of '(A)' in the following code line:
Code: | READ(UNIT,'(A)',ERR=99)STRING |
Thanks for any comments. _________________ Regards
Mike |
|
Back to top |
|
|
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Mon Jan 19, 2015 8:43 pm Post subject: |
|
|
Code: |
READ(UNIT,'(A)',ERR=99)STRING
|
means the same as
Code: |
READ(UNIT,10,ERR=99)STRING
10 FORMAT(A)
|
The format specifier A means read a string of 60 characters then advance to the next record. It is 60 because the variable STRING is of length 60.
If you just want to skip read a record, as in your code STRING isn't actually used, you can use an empty format specifier and no data items, like this:
Code: |
READ(UNIT,'()',ERR=99)
|
_________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Last edited by davidb on Mon Jan 19, 2015 8:50 pm; edited 1 time in total |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Mon Jan 19, 2015 8:50 pm Post subject: |
|
|
You can read string variables using a list directed input statement, instead of using the A format specifier. However, if the input line contains one or more blanks, the string read ends at the first blank even if the string variable can hold more. For example, if the input line is 'Setting Environment' and the character variable has size 30, reading with list-directed I/O gives 'Setting' whereas the A format gives the entire input string. |
|
Back to top |
|
|
mike.smartcam
Joined: 02 Aug 2014 Posts: 40 Location: Lancashire, United Kingdom
|
Posted: Tue Jan 27, 2015 4:13 pm Post subject: |
|
|
Thank you for the clarification. _________________ Regards
Mike |
|
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
|