Since no normal numeric data type will offer you 200 or more digits of precision, I presume you mean you want to read a variable-length string of characters of known length but which is written to multiple records of up to 70 characters. That part is easily done:
CHARACTER*1 STRVAR(300) !Or whatever maximum length you need
INTEGER LENGTH
...
LENGTH= ..... !However determined
READ(8,'(70A1)') (STRVAR(I),I=1,LENGTH)
The format spec calls for 70 repetitions of 1-character fields, used one per I/O list item; when the format is exhausted, it repeats starting with a new line, per Fortran specs regarding Format usage (repetition rules get more complicated when there are nested parentheses with repeat counts; see the Fortran manual). If only part of the final record used by the READ is needed, the rest is ignored, and a subsequent READ will begin with a new record.
A subsequent WRITE can use the same format, and as many records as needed will be written, at 70 characters per record.
Validation of characters read as being digits must be done one at a time, in a loop, testing each against an array of ten characters, initialized to the digits 0-9, unless you have a function available that does essentially the same thing.
If, for some reason, you really would like the long string to be a single variable of the needed length, its definition and use would change:
CHARACTER*300 STRVAR
....
READ(8,'(A70)') (STRVAR(I:I+MIN(69,LENGTH-I)),I=1,LENGTH,70)
Hope this helps.
Dick Russell
-----Original Message-----
From: Stenson Matthew [mailto:[log in to unmask]]
Sent: Wednesday, July 02, 2003 7:37 PM
To: [log in to unmask]
Subject: Formatted read
Hi,
I have to read and write to a specific file format for a particular project but have been unable to find a simple solution.
I want to read data from a flat text file in the format of 70 digits wide and as many rows as needed to make up the current length of the number. For example if the number is currently 100 digits long then the text file will contain two rows the first 70 digits long and the second 30. If the current number length is 200 digits then the text file will contain 2 x rows of 70 digits and 1 row of 60 digits.
The main problem I have is that there is no delimiter between each digit so one row subset would look like this 53251682579520706284777. I need to be able to read each digit separately and add it as an element to a 1d array and then write it back from the 1d array to the same format.
Is there way of formatting read and write statements to do this?
Cheers,
Matt Stenson
-----------------------------------------
*****************Internet Email Confidentiality Footer******************
Privileged/Confidential Information may be contained in this message.
If you are not the addressee indicated in this message (or responsible
for delivery of the message to such person), you may not copy or deliver
this message to anyone. In such case, you should destroy this message
and notify the sender by reply email. Please advise immediately if you
or your employer do not consent to Internet email for messages of this
kind. Opinions, conclusions and other information in this message that
do not relate to the official business of The Shaw Group Inc. or its
subsidiaries shall be understood as neither given nor endorsed by it.
________________________________________________________________________
The Shaw Group Inc.
http://www.shawgrp.com
|