Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Reading and writing formatted files

h-faber
Beginner
721 Views
Hi,
I have some trouble reading and writing a formatted file with direct access. I have

open (iu_dat,FILE=name,STATUS='unknown',access='direct',

* form='formatted',recl=210)

The problem is that when reading the file with

read (iu_dat,6,rec=irec)art,abarb,dm1,dm2,ipas,blaenge,thg,is,iz,

* tng,ischalt,thf,tnf,tneb,bez_neben,tr,ir,rauhwert,iragenr,

* i_1,i_2,i_3,i_4,i_5,i_6,i_7,i_8,i_9,i_10,

* i_11,i_12,i_13,i_14,i_15,

* x_1,x_2,x_3,x_4,x_5,x_6,x_7,x_8,x_9,x_10

6 format(a5,a2,f7.2,f7.2,i2,f7.2,f7.2,i3,i3,f7.2,i3,f7.2,f7.2,f7.2,

* a4,f7.2,i3,f4.1,i2,15(i2),10(f7.2))

etc. I get problems with the carriage returns. In my art (a5) I get the escape sequence for carriage return+linefeed (= 0D 0A) plus the values which really interest me. Instead of 'BIS ' I get something like '__BIS'.Because of this carriage return all further reading gets corrupted - there are 2 characters too much. As I use formatted access and direct formatted with a record length of 210, the current behaviour is far from what I want. I tried to change the record length to 212 to capture the 0D 0A but as the file contents gets modified and rewritten, then the CR is missing.

I assume that file reading in such a way is nothing unusual so I hope someone here has an idea for a solution.

0 Kudos
9 Replies
greldak
Beginner
721 Views
You're not reading the whole record in - have you missed some variables off of your read statement?
You could try changing your record length to 194 or add 16x to the end of the format statement.
0 Kudos
h-faber
Beginner
721 Views


craig.mitchell@mottmac.com wrote:
You're not reading the whole record in - have you missed some variables off of your read statement?
You could try changing your record length to 194 or add 16x to the end of the format statement.


The defined record length is 210. That is how it is written into the file. Then 211+212 are 0D+0A=CR+LF. The problem is, when I set the record length to read to 212, the CR/LF gets lost when I write the data back into this file. Instead of several lines I get one long line withhundreds of columns. The dataset is not seperated by CR/LF then.
0 Kudos
Steven_L_Intel1
Employee
721 Views
Intel Fortran, by default, does not write CR-LFs at the end of direct access records and doesn't expect to see them there. Set the option Compatibility..PowerStation..General to get the behavior you want.
0 Kudos
h-faber
Beginner
721 Views
For the record:
It is the option "Use Other PowerStation Run-time Behavior" which has to be set to YES. (Under Fortran - Compatibility)

Thanks a bunch, Steve!
0 Kudos
Intel_C_Intel
Employee
721 Views

Sorry, I'm not shure whether my registration did work correct. Do I have the same ID and password as at the intel registration?

My question:

Is there no other way to write (formatted) direct access files which can beviewed also in an normal editor?

Thanks

George

0 Kudos
Steven_L_Intel1
Employee
721 Views
It should be the same ID and password.

You want the records to end in a CR-LF terminator. You can do that for direct access files either by enabling the PowerStation option as shown earlier or by writing the CR-LF yourself at the end of each record (CHAR(13)//CHAR(10))
0 Kudos
gfedo
Beginner
721 Views

Is it possible to remove my e-mail address from you common area? See the article before.I did use the address as login name as I remember. That was not ok I think. In the last time I get more and more spam mails.

thanks

George

0 Kudos
TimP
Honored Contributor III
721 Views
Instructions for changing your login name are on the forum home page
http://softwareforums.intel.com/ISN/Community/en-US/Forums/
0 Kudos
Steven_L_Intel1
Employee
721 Views
Unfortunately, the current forum software does not change the name associated with previous posts. The only option is to delete them. Let me know if you want that done.
0 Kudos
Reply