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!
26755 Discussions

passing type variables to subroutine already allocated

diedro
Beginner
138 Views

Dear all,

I have created the following TYPE variables:

 

 TYPE tPARAM      
    INTEGER                                  :: ncl                   
    REAL,  ALLOCATABLE,DIMENSION(:) :: SET      
 END TYPE tPARAM

then I allocate the following variables:

 TYPE(tPARAM),                DIMENSION(0:nParam)  :: PAR2HY

and

  DO iParam=0,nParam
     ncl = PARAM(iParam)%ncl
     ALLOCATE(PAR2HY(iParam)%SET(ncl))
  ENDDO

 

I would like to pass it to a subroutine as:

  SUBROUTINE PRINT_PARAMETRS(fileunit,fname,nParam,PARAM,eff)
  USE VARS_TYPE
  IMPLICIT NONE
  !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  INTEGER,                                   INTENT(IN) :: fileunit
  CHARACTER(100),                            INTENT(IN) :: fname 
  INTEGER,                                   INTENT(IN) :: nParam
  TYPE(tPARAM),                              INTENT(IN) :: PARAM
  REAL,                                      INTENT(IN) :: eff

 

Now the question:

The fact that I have also 

PAR2HY(iParam)%SET(ncl)

where also SET is allocate will give me some problems? If yes, how can I avoid it?

Thank a lot

0 Kudos
4 Replies
FortranFan
Honored Contributor II
138 Views

@diedro,

Given your original post, you shouldn't have a problem but you don't show much and nor is your code snippet a complete reproducer so one can't be sure.  However you are asking a basic question, so a few suggestions:

diedro
Beginner
138 Views

Dear FortranFan, Dear all,

if you want, I could send a fortran example code. This could really help me.

What do 

I will also look the links that you send me.

Thanks,

jimdempseyatthecove
Black Belt
138 Views

Your subroutine declarations appear incorrect. You are declaring nParam and PARAM which seem to imply PARAM is to be an array (with nParam things). Yet PARAM is declared as a single "thing" of type tPARAM. Did you intend for your code to read as:

SUBROUTINE PRINT_PARAMETRS(fileunit,fname,nParam,PARAM,eff)
USE VARS_TYPE
IMPLICIT NONE
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INTEGER,                                   INTENT(IN) :: fileunit
CHARACTER(100),                            INTENT(IN) :: fname 
INTEGER,                                   INTENT(IN) :: nParam
TYPE(tPARAM),                              INTENT(IN) :: PARAM(nParam)
REAL,                                      INTENT(IN) :: eff

Jim Dempsey

diedro
Beginner
138 Views

Deal all, Dear Jim,

really really thanks. I get it.

I have also to put nParam.

 

Now, my concerns even more then before are about PARAM it self. Indeed PARAM is a "Type" with allocated arguments:

ALLOCATE(PARAM(iParam)%SET(ncl))

outside the subroutine call.

What do you think?

Thank again,

Diego

Reply