Re: Allocatable Arrays As Outputs
- From: Reinhold Bader <Bader@xxxxxx>
- Date: Wed, 30 Jan 2008 17:43:22 +0100
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello,
Infinity77 schrieb:
Hi All,
first of all, please forgive my poor mastering of Fortran. I am
still a beginner who uses Fortran sporadically.
I have a subroutine in which I declare 4 output variables as
allocatable. This is because, a priori, I don't know their lengths
(they're all one-dimensional vectors), and I discover this information
only when I read a file which contains both their lengths and the data
used to fill these vectors.
My problem is, I don't know how to correctly "declare" these variables
in the main program, as I keep getting errors on assumed-shape/size
and dummy arguments. My knowledge of Fortran is so slim I can't find a
way to solve this problem.
I am attaching a simplified version of my small program (1 subroutine
+ the main) in which I have only 1 allocatable array. I have used my
google-fu but either I can't interpret correctly the problem or what I
am doing is completely wrong.
Thank you for all your suggestions.
Allocatable subroutine arguments may not be supported by every
compiler (while they are standard conforming in F2003, they're not
in Fortran 95 or earlier).
Even so, they require
a) an explicit interface (e.g., your subroutine ReadINSPEC should be
contained in a module, which in turn is use associated by the caller).
b) the actual argument to be an allocatable entity of same type, kind and rank.
Regards
Andrea.
subroutine ReadINSPEC(fileName, propertyNames)
use ReadECLIPSEBinary
implicit none
character (len=*), intent(in) :: filename
character (len=8), allocatable, intent(out) :: propertyNames(:)
integer numberOfProps
character (len=4) keywordType
character (len=8) keywordName
logical feof
open(unit=1, file=filename, form='UNFORMATTED',
convert='BIG_ENDIAN')
feof = .false.
while_loop: do while (.not.feof)
read(1, end=20, err=18) keywordName, numberOfProps,
keywordType
if (keywordName == 'NAME') then
allocate(propertyNames(numberOfProps))
call ReadECLIPSEData(1, numberOfProps,
stringVector=propertyNames)
exit while_loop
endif
18 continue
enddo while_loop
20 continue
deallocate(propertyNames)
close(1)
return
end subroutine ReadINSPEC
program main
! ???????
! I don't know if this is possible or not...
! ???????
character(len=14) :: fileName
character(len=8) :: propertyNames(:)
fileName = 'OPT_INJ.INSPEC'
call ReadINSPEC(fileName, propertyNames)
end program main
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org
iD8DBQFHoKkqFVLhKuD7VgsRAquSAJsEVNiqGhwEnj8IJwOOeIwO3EVtlQCfRIGG
Mmgc8VWKDt8NxWtiBWqWSwk=
=XerL
-----END PGP SIGNATURE-----
.
- Follow-Ups:
- Re: Allocatable Arrays As Outputs
- From: Craig Dedo
- Re: Allocatable Arrays As Outputs
- References:
- Allocatable Arrays As Outputs
- From: Infinity77
- Allocatable Arrays As Outputs
- Prev by Date: Allocatable Arrays As Outputs
- Next by Date: The concept of a record
- Previous by thread: Allocatable Arrays As Outputs
- Next by thread: Re: Allocatable Arrays As Outputs
- Index(es):
Relevant Pages
|
|