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

Function with character argument

pwalkergeoalgorithms
705 Views
I am trying to recompile some legacy FORTRAN developed on a PC in the 90-s. The program aborts at the return statement when the following function is called (all the other code was commented out):

subroutine WrtHdr(lu,message)

implicit none

integer lu

character*(*) message

return

end


The call is:


character*100 temp_string

integer i_out

i_out = 6

temp_string = 'NEW SECTION'

call WrtHdr(i_out,temp_string)


What could be the problem with this code? Thanks.

0 Kudos
4 Replies
Kevin_D_Intel
Employee
704 Views

There's more at play here. The small snippet compiles/runs fine.

Can you tell us what compiler version (-V) and compiler options were used and showthe actual abort error message?
0 Kudos
jimdempseyatthecove
Honored Contributor III
705 Views

Try changing " end" to "end subroutine" (note left adjust of text)

Jim
0 Kudos
pwalkergeoalgorithms
705 Views

Try changing " end" to "end subroutine" (note left adjust of text)

Jim
I did this, but nothing seemed to change. I think it is a debugger issue. Please see my other reply. - Thanks PW
0 Kudos
pwalkergeoalgorithms
705 Views

There's more at play here. The small snippet compiles/runs fine.

Can you tell us what compiler version (-V) and compiler options were used and showthe actual abort error message?

I managed to get the code working by cloning the function, renaming it, calling the cloned function. In the process I deleted all the blank spaces in the code and replaced the deleted blanks with spaces. - Could the debugger be sensitive to spurious characters in the code?

The code executed after I did this. I noticed that when I step into the code with gdb, then execution fails when I step into the function. If I step over the function, then the program terminates properly. -

The failure occurs when a breakpoint is set atWrtSectionHdrand I step into the function, and then step intoWrtMessageXas follows:

Console output:

This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys030

Loading program into debugger

sharedlibrary apply-load-rules all

Program loaded.

run

[Switching to process 11466]

Running

Starting test

Data Formatters temporarily unavailable, will re-try after a 'continue'. (Attempt to take address of value not located in memory.)

Current language: auto; currently fortran

The Debugger has exited due to signal 11 (SIGSEGV).The Debugger has exited due to signal 11 (SIGSEGV).

(gdb)


------- In this case the execution stopped at WriteMessageX in WriteSectionHdr - the code is below:


program test

implicit none

integer i_out

character*100 temp_string

write(6,*) "Starting test"

i_out = 6

temp_string = 'NEW SECTION'

c call WrtNewHdr(i_out,temp_string) ! I cloned the code and ran the cloned code here

call WrtSectionHdr(i_out,temp_string)

write(6,*) "Ending test"

end


subroutine WrtSectionHdr(lu,message)

implicit none

integer lu

character*(*) message

call WrtMessageX(lu,message) ! exits here with code 11

return

end subroutine



subroutine WrtMessageX(lu,message) ! I clonedWrtMessage for testing

C Write a message to the logical unit lu

implicit none

integer lu

character*512 message

integer iend

write(lu,*) message

return

c iend = index(message,char(26))

c if (lu.ne.0) then

c if (iend.eq.0) then

c write(lu,*) message

c else

c write(lu,*) message(1:iend)

c end if

c end if

c

c return

end subroutine


However, the execution ends normally when I step across the function at the break point:


This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys032

Loading program into debugger

sharedlibrary apply-load-rules all

Program loaded.

run

[Switching to process 11488]

Running

Starting test

Data Formatters temporarily unavailable, will re-try after a 'continue'. (Attempt to take address of value not located in memory.)

NEW SECTION

Current language: auto; currently fortran

Ending test


-----


I did not set up a rule for compiling the include files, assuming this is not important because they are called from the fortran. the linker complains, for example

[WARN]warning: no rule to process file '$(PROJECT_DIR)/NUMBERS.INC' of type sourcecode.pascal for architecture i386


....... I could not find the text output that lists the compiler settings used in the build results window, but any ideas about what might be happening would be appreciated - Thanks. PW



0 Kudos
Reply