I have a really simple Fortran program in a file test.f90:
program test
real :: x
x=12
write(*,*) x
end program test
I compile it with
gfortran -g test.f90
Then I try with gdb:
gdb a.out
break 4 if a == 12
but I get
A syntax error in expression, near `= 12'.
I found several docs and forums saying this should work, but it doesn't...
What is the correct syntax for this simple condition?
I use gdb 7.6.1.
The documentation for gdb has the following to say about Fortran support:
GDB can be used to debug programs written in Fortran, but it currently supports only the features of Fortran 77 language.
As the logical conditional x == 12 is Fortran 90 pedigree you can instead write
break 4 if x.eq.12
Related
I am trying to run Fortran in SublimeText on Windows 10.
I have installed MinGW and so I expected to have gfortran installed. But it doesn't work in SublimeText 3 even though there is a possibility to build with gfortran. My code is like this:
program Hi
write(*,*) "Hello"
end program Hi
But it gives me this error:
gfortran: error: 'C:\Users\Steven\Documents\Hi.f90': Invalid argument
When I try to run it in cmd, it does nothing
Can anyone help me to make it run?
I have a Fortran program I am debuging. I have a list of varables and one of the expected variables is almost double its expected value.
So I compiled the program, with debug flags, and commenced debugging:
the program name is hfock
$gdb hfock
(gdb) break hfock
(gdb) run
Starting program: /home/e/Desktop/hfock hfock
Breakpoint 1, hfock () at hfock.f:16
16 ZETA1 = 2.173171
(gdb) s
17 ZETA2 = 1.188530
(gdb) s
18 WRITE (*, '( "Zeta1:", F7.4 / "Zeta2:", F7.4 )' ) ZETA1, ZETA2
(gdb) s
Zeta1: 2.1732
Zeta2: 1.1885
21 PLUS=ZETA1+ZETA2
(gdb) s
22 PROD=ZETA1*ZETA2
(gdb) s
23 DIFF=ZETA1-ZETA2
(gdb) s
24 S12=8.*PROD**1.5/PLUS**3
(gdb) s
__powf (x=2.58287883, y=1.5) at w_powf.c:26
26 w_powf.c: No such file or directory.
The corresponding (24,25,26) lines of code are:
S12=8.*PROD**1.5/PLUS**3
T11=0.5*ZETA1**2
T22=0.5*ZETA2**2
I think this might be a math library, or glibc related error, but I'm not sure what the error means, or how to fix it.This is fortran, why is it calling a C library? do I need to include a library? or install a missing dependency?
full program source here:
http://pastebin.com/waeEFSBZ
** is in Fortran exponential operator. Exponentiation is implemented in glibc w_powf.c. Gdb can't find this file in your sources. This is not an error, rather diagnostic.
The error means that the source file w_powf.c is not available on your system. It's not related to your program apparently. You can safely ignore that error.
Note that the lines you mention have the operator ** which I suppose is implemented in that file, so it's just telling you that there is no access to the source code of the implementation of that operator.
I am simply using gdb to step through a code line by line to learn how it is working and what it is doing. It worked fine the first time I did this, but now the next command is not working right. Sometimes it goes forward, sometimes it goes backwards. It doesn't make sense. Every time I do this it seems to be the same pattern. Below is an example. Anyone know what is wrong?
Note: This is an old Mac with old program versions (That I do not have the power to update)
Please be explicit. I am fairly new to linux and programming in general.
Thanks!
Reading symbols for shared libraries ... done
(gdb) b main
Breakpoint 1 at 0x2730: file ../../../../gcc-3.4.6/libf2c/libF77/pow_zi.c, line 14.
(gdb) r
Starting program: /Users/kevin/project/ConstU/main
nReading symbols for shared libraries +. done
Error in re-setting breakpoint 1:
Function "main" not defined.
Re-enabling shared library breakpoints: 1
Breakpoint 1, 0x00002730 in main () at main.c:34
34 {
(gdb) n
main () at main.c:42
42 for (i=0;i<DpDIM;i++) {
(gdb) n
34 {
(gdb) n
35 runstart=clock();
(gdb) n
39 Init=ReadInit(&CaseDim);/*reads in initial valies from initfile*/
(gdb) n
35 runstart=clock();
(gdb) n
39 Init=ReadInit(&CaseDim);/*reads in initial valies from initfile*/
(gdb)
Anyone know what is wrong?
The symptoms you've described are very common when debugging programs built with optimization: the compiler re-arranges code in such a way that instructions from different lines become intermixed.
Make sure you compile without any -O flags, or add -O0 at the end of your compilation lines.
here is part of the make file: CC = gcc CFLAGS = -g -O2
That would do it: remove -O2 and your debugging would go much easier.
I have a Fortran code that I have to run but unfortunately I don't have any experience with Fortran. I tried to run the code using different Fortran version and nothing works.
Here is the link for the code: http://cpc.cs.qub.ac.uk/summaries/adpw.
It would be great if someone could tell me which Fortran version should I use.
Here are the details:
When I try to run with gfortran:
gfortran numcbas.f < numcbas_c.data
Segmentation fault: 11
and when I run with g77:
g77 numcbas.f < numcbas_c.data
ld: warning: -macosx_version_min not specified, assuming 10.10
ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in __start from /usr/lib/crt1.o.
To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
And here is start of the code:
program NUMCBAS
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
MAIN DRIVING ROUTINE
CHARACTER*120 TITLE
DIMENSION IBUG(3),HRXS(10),IRXS(10)
COMMON /BASCON/ HRX(10),IRX(10),NIX,IRA
DATA TITLE /' '/
DATA HRXS/1.D-02,2.D-02,2.605D-02,7*0.D0/
DATA IRXS/30,120,500,7*0/,IBUG/3*0/
INTEGER :: NFTA=6,LUNUMB=13, LVAL=0
DOUBLE PRECISION :: BTOL=0.2D0, TINY=1.D-11
DOUBLE PRECISION :: ECMAX=10.D0, RLIM=10.D0, CHARGE=0.D0
NAMELIST /INPUT/ TITLE,LUNUMB,NIX,IRX,HRX,lval,IBUG,BTOL,
* TINY,ECMAX,RLIM,CHARGE
WRITE (6,1000)
and the input file:
&INPUT
TITLE='IONIC TARGET',
lval=0, ECMAX = 5.00D0,
RLIM = 12.0D0, CHARGE=1.0D0,/
It seems to me you are completely misunderstanding tho processes of compilation and running.
These lines are suspicious:
gfortran numcbas.f < numcbas_c.data
g77 numcbas.f < numcbas_c.data
There is no reason to redirect a data file to the compiler command. The compiler first has to create an executable program which you then can run with your data. Normally, a file ./a.out is created and you then run it
./a.out < some_data_to_stdin
It is very strange that you get a Segmentation fault from running gfortran without any other error message. Are you sure the commands you show above are exactly what you are running?
I'm very new to Fortran and I'm trying to compile a code written in Fortran 77. It's a simple code but it won't compile on my machine (Windows 7 Home Basic, 64 Bit). I'm using the MinGW Command Prompt and the error message comes up:
C:\fortran_project>g77 circle.f -o circle.exe
C:\Users\xx\AppData\Local\Temp\ccoPxaaa.s: Assembler messages:
C:\Users\xx\AppData\Local\Temp\ccoPxaaa.s:50: Error: invalid instruction suffix for `push'
C:\Users\xx\AppData\Local\Temp\ccoPxaaa.s:54: Error: invalid instruction suffix for `push'
etc....
Here's the code I tried to compile. It's in Fortran 77
program circle
real r, area
C This program reads a real number r and prints
C the area of a circle with radius r.
write (*,*) 'Give radius r:'
read (*,*) r
area = 3.14159*r*r
write (*,*) 'Area = ', area
stop
end
Why the error? I'm guessing it's because I use a 64bit machine. How do I compile this on my machine and obtain a reasonable output?
I made it work using windows 7 (64 bit) and the mingw compiler.
Try:
~>gfortran circle.f -o circle.exe