Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
2 Views

passing type variables to subroutine already allocated

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
Highlighted
Valued Contributor III
2 Views

@diedro,

@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:

0 Kudos
Highlighted
Beginner
2 Views

Dear FortranFan, Dear all,

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,

0 Kudos
Highlighted
2 Views

Your subroutine declarations

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

0 Kudos
Highlighted
Beginner
2 Views

Deal all, Dear Jim,

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

0 Kudos