Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Dynamic formatting read statements

gillesc
Beginner
578 Views

Hello all,

I have a problem regarding setting a dynamic format statement. I believe examples will help explain better than I can explain it.

I have a code that writes out a set of data to a file, but the amount of data changes with each loopiterationso I write it this way

-----------------------

character*14 string

do

...Some calculations ...

string='( (F9.5))'

j = n * 2 ! For 2 sets of vectors

write(string(2:4),'(I3)')j

write(4,string)(ropls(i),i=1,n),(dfopls(i),i=1,n)

end do

------------------------

This code works fine. With each loop n can change from 1 to 100.

The next step reads in this data file, but since I can not figure out how to get the read to be formatted I set it as a generic read

-----------------------

do
400 format(f8.3,1x,i3,8(f8.3,1x))
read(4,400)dfopls_min,n,(trans(i),i=1,3),(q(i),i=1,4),rcontact
allocate(ropls(n),dfopls(n))
read(4,*)(ropls(i),i=1,n),(dfopls(i),i=1,n)
... Some calcs ...
deallocate(ropls,dfopls)
end do

-----------------------


Now the first set of data it reads fine, deallocates the arrays and attempts to read the next set but fails with a forrtl sever(59) I/O error. So, giving the format may alleviate this problem but I can not format the read the same way as the write. Trying to to the read the same way gives different errors and fails with the first read.

Thanks in advance

Chris

0 Kudos
2 Replies
jimdempseyatthecove
Honored Contributor III
578 Views

Have you considered writing out STRING to unit 4 prior to writing the data. Then reading it back in the input routine. i.e. store the format string along with the data?

Jim

0 Kudos
gillesc
Beginner
578 Views

Have you considered writing out STRING to unit 4 prior to writing the data. Then reading it back in the input routine. i.e. store the format string along with the data?

Jim

Jim,

Thanks, after a little work I seemed to do that successfully. It works now, that is what matters.

Best

Chris

0 Kudos
Reply