Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28630 Discussions

Error in subroutine: return statement is invalid in the main program

jurmich
Beginner
2,113 Views

We've implemented a hudge program with mixed languages in MSDEV (Microsoft Powerstation Fortran). The main language is Fortran (about 1400 files) and the co-language is C (about 400 files).

After portation to the Visual Studio 2005 (solution with 2 projects, C-files in static library) we tried to compile with Fortran Compiler 10.1 Thereon we've got in the Fortran subroutine:

subroutine send_phasenknoten ()
c ----------------------------------------------------------------------
implicit none
include "aliases.f"
include "new_commands.com"
include "sdv.com"
include "intv.com"
include "phasen.rec"
integer blen, i, j, laenge, opos
character bkopf*12, kuerzel*21, baum*41
c --------------------------------------------------------------------------
call init_pha_str ()
opos = sdb_pos
sdb_pos = 5
call mk_baumkopf (bkopf, blen)
do i = 1, phasen_free-1, phasen_reclen
do j = 1, phasen_reclen
ph_phasenrecord(j) = phasen(i+j-1)
enddo
if (ph_baum(1:blen) .eq. bkopf(1:blen) .and. laenge(ph_baum) .eq. blen+4) then
if (ph_inbetrieb .lt. intv_bis .and. ph_ausserdienst .gt. intv_von) then
write (baum, '(2A)') ph_baum(1:blen+4), char(0)
j = laenge (ph_phasenkuerzel)
write (kuerzel, '(2A)') ph_phasenkuerzel(1:j), char(0)
call add_pha_str (kuerzel, j)
call add_pha_str (baum, j)
endif
endif
enddo
sdb_pos = opos
call send_pha_str ()
c --------------------------------------------------------------------------
return
end


following failure-report below:

Compiling with Intel Fortran Compiler 10.1.029 [IA-32]...
ifort /nologo /debug:full /Od /I"../INC" /gen-interfaces /extend_source:132 /fpscomp:filesfromcmd /fpscomp:ioformat /fpscomp:ldio_spacing /fpscomp:logicals /fpscomp:general /warn:interfaces /module:&quotC:\jurij\Merkur450\Debug/" /object:&quotC:\jurij\Merkur450\Debug/" /traceback /check:bounds /libs:dll /threads /dbglibs /4Yportlib /c /extfor:f /Qvc8 /Qlocation,link,&quotC:\Programme\Microsoft Visual Studio 8\VC\bin" &quotC:\jurij\Merkur450\v450\send_phasenknoten.f"
C:\jurij\Merkur450\v450\send_phasenknoten.f(33) : Error: A RETURN statement is invalid in the main program.


Juri

0 Kudos
6 Replies
acobulareddy
Beginner
2,113 Views
what is that you want to return to your main program from this sub program? Seems there is nothing going back to your main program from this sub program because send_phasenknotenis no where assigned in your subroutine. so, return statement is invalid for this subroutine.
here is an exp how return works
main program
a = fun1()
end
sub fun1
fun1 = 30
return
end
this way a will get value of 30 from subroutine fun1.
Let me know if your problem is not clarified
Chandra.
Quoting - jurmich

We've implemented a hudge program with mixed languages in MSDEV (Microsoft Powerstation Fortran). The main language is Fortran (about 1400 files) and the co-language is C (about 400 files).

After portation to the Visual Studio 2005 (solution with 2 projects, C-files in static library) we tried to compile with Fortran Compiler 10.1 Thereon we've got in the Fortran subroutine:

subroutine send_phasenknoten ()
c ----------------------------------------------------------------------
implicit none
include "aliases.f"
include "new_commands.com"
include "sdv.com"
include "intv.com"
include "phasen.rec"
integer blen, i, j, laenge, opos
character bkopf*12, kuerzel*21, baum*41
c --------------------------------------------------------------------------
call init_pha_str ()
opos = sdb_pos
sdb_pos = 5
call mk_baumkopf (bkopf, blen)
do i = 1, phasen_free-1, phasen_reclen
do j = 1, phasen_reclen
ph_phasenrecord(j) = phasen(i+j-1)
enddo
if (ph_baum(1:blen) .eq. bkopf(1:blen) .and. laenge(ph_baum) .eq. blen+4) then
if (ph_inbetrieb .lt. intv_bis .and. ph_ausserdienst .gt. intv_von) then
write (baum, '(2A)') ph_baum(1:blen+4), char(0)
j = laenge (ph_phasenkuerzel)
write (kuerzel, '(2A)') ph_phasenkuerzel(1:j), char(0)
call add_pha_str (kuerzel, j)
call add_pha_str (baum, j)
endif
endif
enddo
sdb_pos = opos
call send_pha_str ()
c --------------------------------------------------------------------------
return
end


following failure-report below:

Compiling with Intel Fortran Compiler 10.1.029 [IA-32]...
ifort /nologo /debug:full /Od /I"../INC" /gen-interfaces /extend_source:132 /fpscomp:filesfromcmd /fpscomp:ioformat /fpscomp:ldio_spacing /fpscomp:logicals /fpscomp:general /warn:interfaces /module:&quotC:jurijMerkur450Debug/" /object:&quotC:jurijMerkur450Debug/" /traceback /check:bounds /libs:dll /threads /dbglibs /4Yportlib /c /extfor:f /Qvc8 /Qlocation,link,&quotC:ProgrammeMicrosoft Visual Studio 8VCbin" &quotC:jurijMerkur450v450send_phasenknoten.f"
C:jurijMerkur450v450send_phasenknoten.f(33) : Error: A RETURN statement is invalid in the main program.


Juri

0 Kudos
jurmich
Beginner
2,113 Views
From this sub program i dont want any return to the main program. This subroutine only handles global variables assigned in COMMON block.
Quoting - acobulareddy
what is that you want to return to your main program from this sub program? Seems there is nothing going back to your main program from this sub program because send_phasenknotenis no where assigned in your subroutine. so, return statement is invalid for this subroutine.
here is an exp how return works
main program
a = fun1()
end
sub fun1
fun1 = 30
return
end
this way a will get value of 30 from subroutine fun1.
Let me know if your problem is not clarified
Chandra.

0 Kudos
anthonyrichards
New Contributor III
2,113 Views
ARETURN statement is perfectly valid in a SUBROUTINE, which I see is what you have defined. You appear to be building something, not just compiling the particular subroutine you show. Are you building an .EXE, a .LIB or a .DLL? If you have a Fortran MAIN program, perhaps you are missing an 'END' statement, so the end of the main program code is not found. Just a guess.

0 Kudos
Steven_L_Intel1
Employee
2,113 Views

I would guess that one of the include files has an END statement that makes all the following code look like part of a main program.

0 Kudos
jurmich
Beginner
2,113 Views
You are right, we have deleted the superfluous END statement in included file.

Thanks

Juri
0 Kudos
acobulareddy
Beginner
2,113 Views
Please check whether there is RETURN in your MAIN FORTRAN PROGRAM. main program doenst return any value.
0 Kudos
Reply