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

Trapping shape mismatch

abhimodak
New Contributor I
760 Views

Hi

I am wondering if there is a compiler option to trap a "shape" mismatch such as 1-D array being passed but subroutine declares it as a 2-D array or vice cersa.

For example,

Program Trap

Implicit None

Real :: A(10)

Call Test(A)

End Program Trap

Subroutine Test(B)

Implicit None

Real :: B(2,2)

B = 1.0

End Subroutine Test

Abhi

0 Kudos
4 Replies
Steven_L_Intel1
Employee
760 Views

That particular mismatch would be detected if you used /gen-interface /warn:interface . or if you used explicit interfaces (a good idea.)

0 Kudos
TimP
Honored Contributor III
760 Views
Quoting - abhimodak

Hi

I am wondering if there is a compiler option to trap a "shape" mismatch such as 1-D array being passed but subroutine declares it as a 2-D array or vice cersa.

For example,

Program Trap

Implicit None

Real :: A(10)

Call Test(A)

End Program Trap

Subroutine Test(B)

Implicit None

Real :: B(2,2)

B = 1.0

End Subroutine Test

Abhi

This appears to be a legitimate combination of legacy and more recent Fortran, although I would hope not normal practice. It should even work, if used correctly (4 elements of a set to 1.0, rest undefined). If you would use f90 module subroutine or interface block, you could rule out this confusing usage.

0 Kudos
abhimodak
New Contributor I
760 Views

Steve and Tim

Thanks for your answers. However, I did test the module and explicit interface before posting. (Sorry, I should have been more clear about it) and it does not trap the shape mismatch.

In fact, it kind of surprised me when this was NOT trapped. Although I have to survive through a lot of legacy code, I try my best to adhere to F2003 standard and corresponding best practices. But I must be missing something in this example.

Below is my sample program and corresponding log. For testing, I used the default "Debug" mode that has warn and gen interfaces. I am using WinXPP 64 bit, Xeon processor, VS 2005, and compiler 11.0.039 Beta as well as 10.1.024. There is no compilation error.

Module TestModule

Implicit None

Contains

Subroutine TestSub(B)
Implicit None
Real(8) :: B(2,2)
B = 1.0d0
End Subroutine TestSub

End Module TestModule

Program Test_ShapeMatching

Use TestModule

Implicit None

Real(8) :: A(9)

Interface
Subroutine AnotherTest(B)
Implicit None
Real(8) :: B(2,2)
End Subroutine AnotherTest
End Interface

A = 0.0d0

Call TestSub(A)
Print *, A

Call AnotherTest(A)
Print *, A

End program Test_ShapeMatching

Subroutine AnotherTest(B)
Implicit None
Real(8) :: B(2,2)
B = 1.0
End Subroutine AnotherTest

====

Build log:

Build Log

Build started: Project: Test_ShapeMatching, Configuration: Debug|Win32

Output
Deleting intermediate files and output files for project 'Test_ShapeMatching', configuration 'Debug|Win32'.
Compiling with Intel Fortran 11.0.039 [IA-32]...
ifort /nologo /debug:full /Od /gen-interfaces /stand:f95 /warn:interfaces /module:"Debug" /object:"Debug" /traceback /check:bounds /libs:static /threads /dbglibs /c /Qvc8 /Qlocation,link,"C:Program Files (x86)Microsoft Visual Studio 8VCbin" "C:AbhiMySourceTestsTest_ShapeMatchingTest_ShapeMatching.f90"
Linking...
Link /OUT:"DebugTest_ShapeMatching.exe" /INCREMENTAL:NO /NOLOGO /MANIFEST /MANIFESTFILE:"C:AbhiMySourceTestsTest_ShapeMatchingdebugtest_shapematching.exe.intermediate.manifest" /DEBUG /PDB:"C:AbhiMySourceTestsTest_ShapeMatchingdebugtest_shapematching.pdb" /SUBSYSTEM:CONSOLE /IMPLIB:"C:AbhiMySourceTestsTest_ShapeMatchingdebugtest_shapematching.lib" "DebugTest_ShapeMatching.obj"
Link: executing 'link'

Embedding manifest...
mt.exe /nologo /outputresource:"C:AbhiMySourceTestsTest_ShapeMatchingdebugtest_shapematching.exe;#1" /manifest "C:AbhiMySourceTestsTest_ShapeMatchingdebugtest_shapematching.exe.intermediate.manifest"

Test_ShapeMatching - 0 error(s), 0 warning(s)
0 Kudos
abhimodak
New Contributor I
760 Views

I just wanted to make "noise" by saying that making the interface explicit (either using module or using an explicit interface) does not trap shape mismatch error. I put in the code and the build log in my previous post.

Abhi

0 Kudos
Reply