I'm trying to compile legacy Fortran code with fort77. The command:
fort77 -c leg_code.f leg_code.o
fails with:
Error on line XXX: syntax error
Line XXX reads:
CHARACTER(LEN=10) TREE(2,MAXF)
where MAXF is defined some lines above with:
INTEGER MAXF, MAXC
PARAMETER (MAXF=400, MAXC=20)
If I remove (LEN=10), the code compiles with no issues.
Anyone know the reason for this error?
As noted in the comments, the declaration statement
CHARACTER(LEN=10) TREE(2,MAXF)
is not valid in Fortran 77. This form, declaring a rank-2 array of character of length 10, was introduced to standard Fortran in the Fortran 90 revision.
To declare such a variable in Fortran 77 the alternative form
CHARACTER*10 TREE(2,MAXF)
or
CHARACTER TREE(2,MAXF)*10
would be required. Simply removing the (len=10), as in
CHARACTER TREE(2,MAXF)
declares the variable to be an array of character of length 1, but this is valid in Fortran 77.
Related
I am editing an old project that uses fixed form Fortran and compiling with IVF compiler. The current issue I have is with continuation lines in a list:
format(//, 10x,'*******************************************',/, &
10x,'* DIAGONALS OF THE RESIDUAL COV. MATRIX *',/, &
10x,'*******************************************',//, &
2x,'MEASUREMENT',7X,' RESIDUAL COVARIANCE', /)
For some reason, the ampersand is not working for me and I keep getting the error:
unrecognized token '&' skipped
For smaller lines, increasing the fixed form line length and making the two lines one worked but there are instances where the lines are too large for this. The code was written around 15 years ago and in fixed form Fortran but I am unfamiliar with Fortran and how the new compiler and settings affect the code.
Converting to free form causes a series of errors with other formatting and the code does not seem broken so I do not think converting to free form is necessary. I have tried other methods of indenting, such as an ampersand at the end of a line and at the beginning of next, an asterisk, and a slash that other forums suggested using and they produce the error:
error #5082: Syntax error, found END-OF-STATEMENT when expecting one
of: <HOLLERITH_CONSTANT> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM>
<CHARACTER_CONSTANT> ) ...
Is there some sort of formatting I am missing or is there any settings I could edit to fix these errors?
In fixed form Fortran, you continue a line with any character in column 6 of the next line, not an & at the end of the 1st line. Try:
format(//, 10x,'*******************************************',/,
c 10x,'* DIAGONALS OF THE RESIDUAL COV. MATRIX *',/,
c 10x,'*******************************************',//,
c 2x,'MEASUREMENT',7X,' RESIDUAL COVARIANCE', /)
Or use the compiler switch -free with .for or .f
Or use the compiler switch -fixed -132 with a .F90 .
In your case I would preserve the .f and cp that to .F90 and then explicitly have the makefile compile the .F90 ...
I normally use -fixed -132 with a .F90 as I often have -d-lines that I retain in the code, and I could not get -d-lines. To work with -free.
I need to run an old program found here: http://netlib.sandia.gov/conformal/ under the title "kirch1" in the list. I have absolutely no experience running fortran code, but I would like to do so from my Mac OS X 10.10 command line.
I know I have the 'gfortan' compiler installed on my system, but I'm not sure if this doesn't like this older code. When I run gfortran KIRCH1.f (this file is the one above) I get the following error:
KIRCH1.f:266.8:
x(2) = -1. + dx
1
Warning: Array reference at (1) is out of bounds (2 > 1) in dimension 1
KIRCH1.f:200.21:
common /param1/ nq2,c2,x2(20),z2(20),qwork2(460),betam2(20)
1
Warning: Padding of 4 bytes required before 'c2' in COMMON 'param1' at (1); reorder elements or use -fno-align-commons
KIRCH1.f:285.21:
common /param1/ nq,c,x(20),z(20),qwork(460),betam(20)
1
Warning: Padding of 4 bytes required before 'c' in COMMON 'param1' at (1); reorder elements or use -fno-align-commons
Undefined symbols for architecture x86_64:
"_gaussj_", referenced from:
_qinitx_ in ccoKtvwZ.o
"_ns01a_", referenced from:
_ksolv_ in ccoKtvwZ.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
This error seems to be do to the syntax in the code? I doubt there is anything wrong with the code itself, so I'm thinking its something to do with my systems interpretation of the code (for lack of a better way of phrasing this)
I have no fortran programming experience, I should mention. What am I doing wrong?
EDIT
As suggested by Ed Smith
I run gfortran sclibdbl.f KIRCH1.f but I still get the following warnings:
KIRCH1.f:266.8:
x(2) = -1. + dx
1
Warning: Array reference at (1) is out of bounds (2 > 1) in dimension 1
KIRCH1.f:200.21:
common /param1/ nq2,c2,x2(20),z2(20),qwork2(460),betam2(20)
1
Warning: Padding of 4 bytes required before 'c2' in COMMON 'param1' at (1); reorder elements or use -fno-align-commons
KIRCH1.f:285.21:
common /param1/ nq,c,x(20),z(20),qwork(460),betam(20)
1
Warning: Padding of 4 bytes required before 'c' in COMMON 'param1' at (1); reorder elements or use -fno-align-commons
The following compiled for me:
gfortran sclibdbl.f KIRCH1.f
where KIRCH1.f is the code from http://netlib.sandia.gov/conformal/kirch1 and sclibdb1.f is the code from http://netlib.org/conformal/sclibdbl.
You were just missing the required subroutines gaussj and ns01a which are referenced in the KIRCH1 source code but included in sclibdbl. The code from netlib.org/conformal/sclibdbl includes both the gaussj and ns01a subroutine (note the underscore is added to routine names by default in gfortran).
As #francescalus noted, it's modern fortran compiler and old school FORTRAN code. The warning is because modern fortran is far more explicit about array extents. In this code, x is passed with size 1 to yxtran() which is okay as passing is a reference to the start of array. When element 2 is accessed the modern fortran compiler gets worried. You can remove the two common block errors by adding the -fno-align-commons flag to the compiler. The x(1) error could be removed by replacing x(1) on line 258 with x(n-1). Personally, I wouldn't worry unless you notice problems/unexpected behavior when you run the code (especially as it's from netlib).
I'm trying to compile a simple operating system code we got on OS class. It works fine under Ubuntu but I'd like to compile it on OS X. The error I get is:
[compiling] arch/i386/arch/startup.S ...
arch/i386/arch/startup.S:8:Unknown pseudo-op: .extern
arch/i386/arch/startup.S:8:Rest of line ignored. 1st junk character valued 107 (k).
arch/i386/arch/startup.S:11:Expected comma after segment-name
arch/i386/arch/startup.S:13:Unknown pseudo-op: .global
arch/i386/arch/startup.S:13:Rest of line ignored. 1st junk character valued 97 (a).
This is the
source code of that file, and here is the makefile
So if anyone have an idea what to do I would appreciate it :)
As you're compiling using OS/X you'll be using X-Code's ancient version of as. This means you'll have to put up with some slightly older syntax. This other answer covers some of these problems.
At very least you're going to need to replace .global with .globl. You can remove .extern as all symbols are treated as external by default. For the section definition you should consult the gas manual; I believe the assembler is asking you to define the section flags.
I think it should be ".globl" not ".global"
Hi while i cross compile an startup.s file
(arm-none-eabi-as file.s)
(*-gcc)
I am getting in each commentary line some errors
- junk at end of line, first unrecognized character is /
when i delete the // some comment lines i get
errors about undefined symbols even i defined them at beginning of the file.
anyone know whats wrong?
If you want to use macros or C comments, then you have to preprocess the source file with the C preprocessor. The C preprocessor removes comments and interprets macros. The GNU assembler should run the C preprocessor automatically if the source file name ends with .S, with an uppercase 'S'.
(arm) Assembler does not support // comments or defines, you have to use .equ and # for comments. If you let gcc parse it you can put C isms like that into your assembler. Personally I avoid such C isms and keep the assembler clean. if you cannot do that or need includes with defines for example let gcc pre-process the file before sending it to gas.
I've been tasked with maintaing some legacy fortran code, and I'm having trouble getting it to compile with gfortran. I've written a fair amount of Fortran 95, but this is my first experience with Fortran 77. This snippet of code is the problematic one:
CHARACTER*22 IFILE, OFILE
IFILE='TEST.IN'
OFILE='TEST.OUT'
OPEN(5,FILE=IFILE,STATUS='NEW')
OPEN(6,FILE=OFILE,STATUS='NEW')
common/pabcde/nfghi
When I compile with gfortran file.FOR, all lines starting with the common statement are errors (e.g. Error: Unexpected COMMON statement at (1) for each following line until it hits the 25 error limit). I compiled with -Wall -pedantic, but fixing the warnings did not fix this problem.
The crazy thing is that if I comment out all 4 lines starting with IF='TEST.IN', the program compiles and works as expected, but I must comment out all of them. Leaving any of them uncommented gives me the same errors starting with the common statement. If I comment out the common statement, I get the same errors, just starting on the following line.
I am on OS X Leopard (not Snow Leopard) using gfortran. I've used this very system with gfortran extensively to write Fortran 95 programs, so in theory the compiler itself is sane. What the hell is going on with this code?
Edit: Compiling with g77 gives:
test.FOR: In program `MAIN__':
test.FOR:154:
IFILE='TEST.IN'
1
test.FOR:158: (continued):
common/pabcde/nfghi
2
Statement at (2) invalid in context established by statement at (1)
Er, what context is established at (1)?
I don't think you can put COMMON statements below the executable statements in FORTRAN 77, see the specification, Sec. 3.5.
Just move the COMMON statement close to the beginning of the procedure, before any executable statement.