Can't compile Fortran code - fortran

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

Related

Sublimetext 3 doesn't work with gfortran

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?

Fortran error: "end of file" while reading character in namelist

I am writing a Fortran application, and I get this problem. When I define a namelist as following:
CHARACTER(100) :: INPUT_DIR, OUTPUT_DIR, ROOT_DIR
NAMELIST /IODIR/ INPUT_DIR, OUTPUT_DIR
and then I read IODIR from file as:
READ(FUNIT,IODIR, ERR=99)
The data in file is:
&IODIR INPUT_DIR="Input", OUTPUT_DIR="Output" /
But it get error
"End of file".
It seems like the length of variables is longer than their defined in file. I don't know how to set delimiter for the character variable, or read an unknown character in namelist. I use GNU Fortran to build.
I had the same problem with the online gfortan compiler, same result from an installed version. This problem is all over the web, so on the basis of using reliable sources I:
Installed gfortran in Windows 10 Bash - all good.
Installed gfortran in Cygwin - all good.

gdb if condition syntax error

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

Fortran running error

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?

Loading dted data using gdal with g++ in solaris 10?

I want to load Digital Terrain Elevation(DTED) data using gdal using g++ in solaris 10. In solaris 10, the application with cc compiler loads the data successfully, but when I am using netbeans and g++. the application successfully reads Digital Terrain Elevation(DTED) data but application crashes at GetGeoTranformation(double *) when I print GDALdataset->getDriver()->GetDescription(). This function is working fine in cc. If I comment the line, the application crashes at GDALDataset->GetRasterBand(1), and error prints ld.so.1 fatal reallocation error symbol_ZN11GDALDataset13GetRasterBandIOEi reference symbol not found
Would you mind posting a part of the code which uses GDAL? There could be a few issues. Off the top of my head...
GDAL GetRasterBand starts at 1 when indexing. It seems like your snippet you provided does that.
GDAL requires that you initialize the drivers with GDALAllRegister().
Most GDAL functions return NULL when they return without data. You may want to test that before passing it into another function to prevent potential seg faults.
What does cc point to? I would check the symbolic link with something like
which cc
ls -la /usr/bin/cc (Solaris is Unix, not Linux so forgive me if I am wrong).