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.

Variable formatting question

noelandres17
Beginner
1,000 Views
Hi,

I am trying to port a Fortran code from Windows to Linux. It was compiled using the Windows Fortran compiler. I am using the Intel Linux Fortran compiler. There is a construct used in the code that apparently has been deprecated and is no longer valid Fortran. The Intel compiler does not let it go through (as it should not) and I need to find the way to do it using current Fortran practices. The original code looks like this:

npred=SIZE(xpred1,dim=1)
10 FORMAT(1x,e16.8)
WRITE(1,10) (((peta_xtheta(ii,i,j),ii=1,npred),i=1,idim),j=1,len_pvals)

Basically, the format statement depends on the value of the integer "npred". I came up with something in the internet that looks like this:

CHARACTER*80 FMT
...
npred=SIZE(xpred1,dim=1)
WRITE(FMT,((1x,,I0,e16.8))) npred
WRITE(1,FMT) (((peta_xtheta(ii,i,j),ii=1,npred),i=1,idim), j=1,len_pvals)

However, that does not seems to work. Here is the error message from the Intel Compiler:

gpred_vcf_nocal.f90(207): error #5078: Unrecognized token '?' skipped
WRITE(FMT,((1x,,I0,e16.8))) npred
--------------------^
gpred_vcf_nocal.f90(207): error #5078: Unrecognized token '(?' skipped
WRITE(FMT,((1x,,I0,e16.8))) npred
---------------------^
gpred_vcf_nocal.f90(207): error #5143: Missing mandatory separating blank
WRITE(FMT,((1x,,I0,e16.8))) npred
-------------------------^
gpred_vcf_nocal.f90(207): error #5078: Unrecognized token '?' skipped
WRITE(FMT,((1x,,I0,e16.8))) npred
---------------------------^
gpred_vcf_nocal.f90(207): error #5078: Unrecognized token '?' skipped
WRITE(FMT,((1x,,I0,e16.8))) npred
--------------------------------^
gpred_vcf_nocal.f90(207): error #5078: Unrecognized token '?' skipped
WRITE(FMT,((1x,,I0,e16.8))) npred
---------------------------------------^
gpred_vcf_nocal.f90(207): error #5078: Unrecognized token '?' skipped
WRITE(FMT,((1x,,I0,e16.8))) npred
-----------------------------------------^
gpred_vcf_nocal.f90(207): error #5276: Unbalanced parentheses
WRITE(FMT,((1x,,I0,e16.8))) npred
------------------------------------------^
gpred_vcf_nocal.f90(207): error #5082: Syntax error, found IDENTIFIER 'X' when expecting one of: * ) :: , ; + . - (/ [ : ] /) ' ** / // > .LT. ...
WRITE(FMT,((1x,,I0,e16.8))) npred
-------------------------^
compilation aborted for gpred_vcf_nocal.f90 (code 1)
make: *** [gpred_vcf_nocal.o] Error 1

If anyone can help, it would be appreciated. Thanks,

Noel
0 Kudos
5 Replies
IanH
Honored Contributor III
1,000 Views
The variable format things were never valid fortran. That said, I'm a little surprised that the linux variant of the fortran compiler doesn't accept that particular extension - the extension is described in the docs that come with the linux compiler.

But what you are proposing to do instead is a far better way to go anyway.

You are almost there - the problem is that the example you've cut and pasted is using quote characters that are not the ones that are typically generated in an editor when you hit the ' and " keys on your keyboard - probably because of an attempt by a browser or web server to format the example to make it look nicer (or perhaps the source code has gone via a word processor). The compiler doesn't recognize these strange quotes - hence the plethora of errors.

Go through the code and replace by " and by '. Be mindful that there may be some other characters that have come across that are not just the boring "ascii" characters that typically comprise source code and that sometimes editors will change the encoding of a file when they encounter such characters.
0 Kudos
Steven_L_Intel1
Employee
1,000 Views
Intel Fortran for Linux certainly does support the VFE extension. After all, we created it back in the DEC days. If you have a test case, and not just a fragment, please post it and include the error messages.

[plain][sblionel@f90srv34 ~/project]$ cat t.f90
integer :: a(4) = [1,2,3,4]
n = size(a)
print 101, a
101 format(I5)
end
[sblionel@f90srv34 ~/project]$ ifort t.f90
[sblionel@f90srv34 ~/project]$ ./a.out
    1    2    3    4
[sblionel@f90srv34 ~/project]$ 
[/plain]
0 Kudos
nvaneck
New Contributor I
1,000 Views
I tried this once and it worked fine, but apparently it takes a lot of code as the size of my program grew to much, so I avoid it now.
0 Kudos
anthonyrichards
New Contributor III
1,000 Views


program VARFORMAT

INTEGER II,I,J
REAL*8 PETA_XTHETA(3,3,3)
CHARACTER*8 FMT(3)
! divide the format into 8-character sections...
DATA FMT/8H(10X, ,8H ,8HE16.8) / ! Blanks are used to fill remaining character spaces

peta_xtheta=9
IDIM=3
len_pvals=3
NPRED=3
WRITE(FMT(2),'(I8)') NPRED
WRITE(6,'(''FMT= '',3A8)') FMT
WRITE(6,FMT) (((peta_xtheta(ii,i,j),ii=1,npred),i=1,idim), j=1,len_pvals)

PAUSE
end program VARFORMAT


OUTPUT:

FMT= (10X, 3E16.8)
0.90000000E+01 0.90000000E+01 0.90000000E+01
0.90000000E+01 0.90000000E+01 0.90000000E+01
0.90000000E+01 0.90000000E+01 0.90000000E+01
0.90000000E+01 0.90000000E+01 0.90000000E+01
0.90000000E+01 0.90000000E+01 0.90000000E+01
0.90000000E+01 0.90000000E+01 0.90000000E+01
0.90000000E+01 0.90000000E+01 0.90000000E+01
0.90000000E+01 0.90000000E+01 0.90000000E+01
0.90000000E+01 0.90000000E+01 0.90000000E+01
Fortran Pause - Enter command or to continue.

Alternatively:

program varformat2

INTEGER II,I,J
REAL*8 PETA_XTHETA(3,3,3)
CHARACTER*8 FSTART, FMIDDLE, FEND
CHARACTER*24 FMT

FSTART="(10X,"
FMIDDLE=" "
FEND="E16.8)"

peta_xtheta=9
NPRED=3
IDIM=3
len_pvals=3
WRITE(FMIDDLE,'(I8)') NPRED
FMT=FSTART//FMIDDLE//FEND
WRITE(6,'(''FMT= '',A24)') FMT
WRITE(6,FMT) (((peta_xtheta(ii,i,j),ii=1,npred),i=1,idim), j=1,len_pvals)

PAUSE

end program varformat2

OUTPUT:

FMT= (10X, 3E16.8)
0.90000000E+01 0.90000000E+01 0.90000000E+01
0.90000000E+01 0.90000000E+01 0.90000000E+01
0.90000000E+01 0.90000000E+01 0.90000000E+01
0.90000000E+01 0.90000000E+01 0.90000000E+01
0.90000000E+01 0.90000000E+01 0.90000000E+01
0.90000000E+01 0.90000000E+01 0.90000000E+01
0.90000000E+01 0.90000000E+01 0.90000000E+01
0.90000000E+01 0.90000000E+01 0.90000000E+01
0.90000000E+01 0.90000000E+01 0.90000000E+01
Fortran Pause - Enter command or to continue.
0 Kudos
noelandres17
Beginner
1,000 Views

All,

I was wrong, the Intel Linux compiler does indeed support the <> construct. I decided to change the code nonetheless to the way I was trying first. The problem was that the quotes used were not the standard ones. After I switched them like "IanH" kindly suggested, the compiler errors were gone. Thanks for the replies everyone.

Noel

0 Kudos
Reply