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.

Printing an array in the same line

ssragunath
Beginner
3,036 Views
Hello,
I am a new user who migrated to CVF from C++. I am trying to WRITE someelements of an array in a single output line.
CHARACTER*10 ARRAYC(100)
REAL*8 ARRAYINT(100)
INTEGER ii1
i.e I want ARRAYC(1), ARRAYC(2), ARRAYC(3) .... ARRAYC(ii1)in a single line followed by ARRAYINT(1), ARRAYUNT(2), ARRAYINT(3).....ARRAYINT(ii1)in the second line.In this example, my target output file should beonly 2 lines.'ii1' is not fixed. It takes any values from1 to 100.
I need to do it to port the output data to a spreadsheet application. If I couldformat the WRITE statement so that CHARACTER*10 and INTEGER will be of same width in the output file that would be great (spreadsheet will recognize it better). Can someone please help me with this. I tried implicit do statements but every single WRITE begins with a new line in output. I also thought about creating a very big CHARACTER array and concatenating the values and printing the final resulting string to a single line.Can someone please help me to do it in the correct way?
Thanks.
0 Kudos
5 Replies
ssragunath
Beginner
3,036 Views

I was able to print all the elements of an array in the same line by hard codingsize of array.

INTEGER ii1, Records

WRITE(3,'(40A25)') (EqRecords(ii1),ii1 = 1,Records)

In this case I know that there are only 40 Elements in the Array. The compiler does not allow me to do WRITE(3,'(RecordsA25)'). Can someone please tell me how to do this?

0 Kudos
Jugoslav_Dujic
Valued Contributor II
3,036 Views
You can simply use e.g.
WRITE(3,'(1000A25)') (EqRecords(ii1),ii1 = 1,Records)
which enables you to write up to 1000 elements. You're not required to match the number of actual entries with the number in the format -- the latter may be bigger.
I think -- but I'm not sure -- that the following will also work:
WRITE(3,'((A25))') (EqRecords(ii1),ii1 = 1,Records)
(note the extra brackets)-- there's an obscure rule that when the format string is "exhausted", the formatting "returns" to the last bracket encountered -- if I remember correctly.
There's also non-standard (DEC/CVF/IVF extension) <> form:
WRITE(3,'(A25)') (EqRecords(ii1),ii1 = 1,Records)
I recommend against it unless it's really inavoidable.
Jugoslav
0 Kudos
bsully
Beginner
3,036 Views

I am getting an access violation when using this.

900 format((f5.1,2x))
901 format((f7.1,2x))

So, I should say

900 format(1000(f5.1,2x))
901 format(1000(f7.1,2x))

?

Thanks!


0 Kudos
bsully
Beginner
3,036 Views
It didn't work ....

Message Edited by bsully on 04-13-2004 06:10 AM

0 Kudos
Jugoslav_Dujic
Valued Contributor II
3,036 Views
bsully, it's hard to deduce what's happening without seeing the actual code. On first glance, it appears that the problem is in I/O list rather than in format string itself -- check whether the variables in I/O list are properly allocated and/or of the right type.
Jugoslav
0 Kudos
Reply