简体   繁体   中英

How do I pass a character array to a subroutine in Fortran? [on hold]

I want to pass a 1-D character array from my main routine to a subroutine with a static size. I also pass the character length and the dimension of the array. When I try to create the array in the subroutine with the passed dimensions, I get only the first row of this array. If I fill in the dimensions by myself, all is working fine. Can anybody tell me what the problem is? Thank you very much.

For example

PROGRAM main

IMPLICIT  NONE
INTEGER :: length 
INTEGER :: size
CHARACTER(LEN = 100), DIMENSION(20) :: array


length = 100
size = 20
CALL somefunction(array,length,size)

STOP 
END

SUBROUTINE somefunction(ARRAY,LENGTH,SIZE)
IMPLICIT NONE
INTEGER :: LENGTH
INTEGER :: SIZE
CHARACTER(LEN = LENGTH), DIMENSION(SIZE) :: ARRAY

RETURN
END

Thank you @Vladimir F to give the hint, how do I check the size of the Array. I added the arrays to the watchlist of Visual Studios 2015 and checked the dimensions there. In the main program the dimension in the watchlist fits with the real dimensions, but not in the subroutine. So the program passes the array right, but you can´t see it in the watchlist of Visual Studio 2015.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM