[Fortran] Problem with subroutine

In summary, the conversation is about an error occurring when running a program with multiple subroutines, specifically when using the readin subroutine to read constants from an infile. The error message mentions an undefined reference in the getg0.f file, and the conversation suggests that the issue may be related to the way inputs are being read. The conversation ends with a request for the code in the getg0.f file to be shown.
  • #1
selmayda
9
0
Hello everyone ;

I have tried to run a program which has many subrotines so I control each of them.But, when I run one of them, the below error message is seen;

/tmp/ccMqKR9L.o: In function `MAIN__':
getg0.f:(.text+0x73c): undefined reference to `readin_'
collect2: ld returned 1 exit status

subroutine readin is used to read some constant from an infile (5,*) . the other subroutine getg0.f use some constants from infile to calculate g.For example;
in getg0:
do 346 id = 1,Nd

mi(id) = 1.d0 / ( dexp ( ( Ed(id) / 2.d0 ) / T ) + 1.d0 )

346 continue

and Ed(id) values are readin from infile via readin.f.

readin.f
read(5,*) UU(1), UU(2), UU(3), UU(4), UU(5)
read(5,*) Ed(1), Ed(2), Ed(3), Ed(4), Ed(5)

infile
1.d0, 2.d0, 3.d0, 4.d0, 1d0
-7.24068, -5.32445, -6.63223, -6.40883, -7.66001

readin following
UU(1), UU(2), UU(3), UU(4), UU(5)
Ed(1), Ed(2), Ed(3), Ed(4), Ed(5)

can everyone help me about this error?

Thanks a lot
 
Last edited:
Technology news on Phys.org
  • #2
The error you show indicates that there's a problem in getg0.f, so show us the code in that file.
 
  • #3
Does the undefined reference error occur at link time or at load / run time (dynamic linking)? Any chance you misspelled readin (with an I) as readln (with an L) (or vice versa)?
 
  • #4
actually, when I write inputs by hand, there is no problem.However, when readin is read inputs from infile, the error message is seen so I think it is not related to getg0.

I control spelling and there is no problem.
 
  • #5
selmayda said:
/tmp/ccMqKR9L.o: In function `MAIN__':
getg0.f:(.text+0x73c): undefined reference to `readin_'
collect2: ld returned 1 exit status
The error message says that you have an undefined reference in getg0.f, so it seems reasonable to look there for a problem.

Please show us the code you have in getg0.f.
 

FAQ: [Fortran] Problem with subroutine

What is a subroutine in Fortran?

A subroutine in Fortran is a self-contained block of code that performs a specific task and can be called multiple times within a program. It is similar to a function but does not return a value.

Why am I getting an error when calling a subroutine in Fortran?

There could be several reasons for this error. It could be due to a misspelling of the subroutine name, incorrect arguments being passed, or the subroutine not being properly declared before being called. Check your code for any of these potential issues.

How do I pass arguments to a Fortran subroutine?

Arguments can be passed to a Fortran subroutine by using the CALL statement followed by the subroutine name and the arguments enclosed in parentheses. The subroutine must also have a corresponding dummy argument list in its declaration.

Can I use a subroutine from a different Fortran program?

Yes, a subroutine can be used in multiple Fortran programs by using the EXTERNAL statement in the calling program and the EXTERNAL attribute in the subroutine declaration. This allows the subroutine to be accessible to other programs without being compiled into them.

How can I debug a problem with a Fortran subroutine?

Debugging a problem with a Fortran subroutine can be done by using print statements or a debugger tool. Make sure to check for any incorrect variable values, array indices, or logic errors within the subroutine code.

Similar threads

Replies
4
Views
1K
Replies
59
Views
10K
Replies
8
Views
4K
Replies
5
Views
7K
Replies
2
Views
1K
Replies
4
Views
2K
Replies
7
Views
2K
Replies
54
Views
5K
Replies
20
Views
2K
Replies
6
Views
3K
Back
Top