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

Subroutine interface problem with pointer

jaeger0
Beginner
308 Views
I Observed some Times problems calling subroutines with pointers to a type as argument. See the simplified source code above.
The point is, that I have a valid pointer PatItem, before I call the subroutine DataBase_Pat_FindCorrespondingImage
Inside the subroutine, PatItem becomes invalid, and the program crashes.
If I put DataBase_Pat_FindCorrespondingImage into a module, than everithing is fine.
Has anybody an Idea what could be the problem ??

Subroutine DataBase_Pat_FindCorrespondingImage(PatItem,StuItem,SerItem) !Image3D_Dim,pixel_spacing, StuItem,SerItem)
use VSIM_MESSAGE
implicit none
! input variables
type(dbPatItem),pointer,intent(in):: PatItem ! Patient to look for an image
integer(2) Image3D_dim(3) ! image dimensions (x,y,z)
REAL(8) pixel_spacing(3) ! x,y,z
! output variables
integer(2) iErr ! Error flag
type(dbStuItem),pointer,intent(out):: StuItem ! Pointer to the study with the right serie
type(dbSerItem),pointer,intent(out):: SerItem ! Poiinter to the serie containing the found image

! PatItem has strange values
nullify(StuItem) ! crash
nullify(SerItem)

...
end subroutine

Subroutine Test(dbase,pat_id,stu_Uid,ser_Uid)
type(dbPatList) dbase ! database containing information where to find the block-images
character*(*) pat_id ! patient id
character*(*) stu_Uid ! study unique identifier
character*(*) ser_Uid ! serie unique identifier



type(dbPatItem),pointer:: PatItem ! Patient to look for an image

call dbPatList_FindItem (dbase%pat_list, pat_id, foundPat,PatItem) ! check if Patient is already in database
! PatItem is associated and contains valid values
call DataBase_Pat_FindCorrespondingImage(iErr, PatItem,VSIM_Image%Image3D_Dim,VSIM_Image%pixel_spacing, StuItem,SerItem)



end Test

0 Kudos
1 Reply
IanH
Honored Contributor II
308 Views
If a procedure has a dummy argument that is a pointer then an explicit interface must be available in the calling scope.

When you put DataBase_Pat_FindCorrespondingImage into a module that explicit interface is automatically created for you and made availble in any scope that USE's the module.

If you don't want to have that procedure in a module then you will need to manually create the corresponding INTERFACE block.
0 Kudos
Reply