Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
For the latest information on Intel’s response to the Log4j/Log4Shell vulnerability, please see Intel-SA-00646

Error in Fortran Derived Type

mic_esp96
Novice
361 Views

Good morning devs, I am building a derived type to kind of "simulate" a dinamic-rank array. However this is just the very first version of this.

 

Here it is the code:

module MyBisp
   implicit none

   type bvals
      real, allocatable :: vals(:)  !column values
   end type

   type Bisp
      type (bvals), allocatable :: bvals(:)  !row values.
   end type Bisp

   type B3D
      type (Bisp), allocatable :: ndims(:,:,:)
      contains
      procedure :: init => init_dims3
      procedure :: all => all_bisp
   end type B3D



   type PSD2D
      type (bvals), allocatable :: ndims(:,:)
      contains
      procedure :: init => init_dims2
      procedure :: all => all_psd
   end type PSD2D

   contains

   subroutine init_dims3(self,n)
      implicit none
      class (B3D), intent(inout) :: self
      integer, intent(in) :: n
      integer :: istat
      allocate(self%ndims(n,n,n),stat=istat)
      if (istat.ne.0) call errall('B3D_init_dims3',istat,'b%ndims')
      ! self%ndims(:,:,:)  = 0.d0
   end subroutine

   subroutine init_dims2(self,n)
      implicit none
      class (PSD2D), intent(inout) :: self
      integer, intent(in) :: n
      integer :: istat
      allocate(self%ndims(n,n),stat=istat)
      if (istat.ne.0) call errall('PSD2D_init_dims2',istat,'psd%ndims')
      ! self%ndims(:,:)  = 0.d0
   end subroutine


   subroutine all_bisp(self,i,j,k,n)
      implicit none
      class (B3D), intent(inout) :: self
      integer, intent(in) :: i,j,k,n
      integer :: istat
      if (.not.allocated(self%ndims)) write(*,'(a)'), '  ERROR (b3d): "ndims" not allocated !'
      allocate(self%ndims(i,j,k)%bvals(n)%vals(n),stat=istat)
      if (istat.ne.0) call errall('B3D_all_bisp',istat,'b%ndims%bvals%vals')
      ! self%ndims(:,:,:)%bvals(:)%nvals(:)  = 0.d0
   end subroutine

   subroutine all_psd(self,i,j,n)
      implicit none
      class (PSD2D), intent(inout) :: self
      integer, intent(in) :: i,j,n
      integer :: istat
      if (.not.allocated(self%ndims)) write(*,'(a)'), '  ERROR (psd2d): "ndims" not allocated !'
      allocate(self%ndims(i,j)%vals(n),stat=istat)
      if (istat.ne.0) call errall('PSD2D_all_psd',istat,'psd%ndims%vals')
      ! self%ndims(:,:)%bvals(:)%nvals(:)  = 0.d0
   end subroutine

end module

 

which is then called within a subroutine of the main program:

 

type (PSD2D) :: psdfb,psdfmb,psdrmb,psdrb
type (B3D)   :: bfb,bfmb,brmb,brb

.
.
.

   if (bsaExtended.eq.1) then 
      itmp=sbvdat_NDOF 
   else 
      itmp=crenum_NUMNP 
   end if

   ! INIT BISPs & PSDs
   psdfb%init(itmp)
   psdrb%init(itmp)
   bfb%init(itmp)
   brb%init(itmp)
   psdfmb%init(stabil_NVAP)
   psdrmb%init(stabil_NVAP)
   bfmb%init(stabil_NVAP)
   brmb%init(stabil_NVAP)

   do i=1,stabil_NVAP
      do j=1,stabil_NVAP
         psdfmb%all(i,j,bsa_numfrqs)
         psdrmb%all(i,j,bsa_numfrqs)
         do k=1,stabil_NVAP
            bfmb%all(i,j,k,bsa_numfrqs)
            brmb%all(i,j,k,bsa_numfrqs)
         enddo
      enddo
   enddo

   do i=1,itmp
      do j=1,itmp
         psdfb%all(i,j,bsa_numfrqs)
         psdrb%all(i,j,bsa_numfrqs)
         do k=1,itmp
            bfb%all(i,j,k,bsa_numfrqs)
            brb%all(i,j,k,bsa_numfrqs)
         enddo
      enddo
   enddo
   ...

 

I'm facing some errors, which I cannot well understand.

 

In the version you see here attached, I get the following errror:

error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: % . = =>

 

at each line where I call both procedures INIT and ALL.

 

If I add ALLOCATABLE in the 4 module's subroutines CLASS declaration, I also have:

 error #8263: The passed-object dummy argument must be a scalar, nonpointer, nonallocatable dummy data object.   [SELF]

 

I cannot see what I am doing wrong..

 

Thank to everyone.

0 Kudos
1 Solution
mecej4
Black Belt
335 Views

You seem to have overlooked the fact that in Fortran, unlike in C, etc., calling a procedure requires the word CALL to come before the procedure name and argument list.

View solution in original post

2 Replies
mecej4
Black Belt
336 Views

You seem to have overlooked the fact that in Fortran, unlike in C, etc., calling a procedure requires the word CALL to come before the procedure name and argument list.

View solution in original post

mic_esp96
Novice
293 Views

Thanks @mecej4 , I supposed that that kind of calling could have had a different syntax, while it is not the case (thinking that the "call" word was hidden behind the "%" syntax..). Thanks, now it works.

Reply