Allocatable Arrays As Outputs



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.

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
.



Relevant Pages

  • Re: Allocatable Arrays As Outputs
    ... please forgive my poor mastering of Fortran. ... I am attaching a simplified version of my small program (1 subroutine ... readkeywordName, numberOfProps, ... Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org ...
    (comp.lang.fortran)
  • Re: Allocatable Arrays As Outputs
    ... I don't know how to correctly "declare" these variables ... I am attaching a simplified version of my small program (1 subroutine ... readkeywordName, numberOfProps, ... you can still allocate memory as you ...
    (comp.lang.fortran)
  • Re: Allocatable Arrays As Outputs
    ... please forgive my poor mastering of Fortran. ... I don't know how to correctly "declare" these variables ... I am attaching a simplified version of my small program (1 subroutine ... Even though the Fortran 95 standard does not support allocatable arrays as procedure arguments, function results, or components of derived types, they are part of Fortran 2003. ...
    (comp.lang.fortran)
  • Re: Help! Bug that I can not figure out
    ... Fortran however doesn't do optional arguments like ... The first thing that the subroutine does is read ... C Declare the C function ... INTERFACE!emrl ...
    (comp.lang.fortran)
  • Re: Fortran based MEX w/ COMMON/SAVE
    ... I believe dat (pointer to the array) and the ... SAVE at the begining of each subroutine is a bit unusual to me. ... > to unload it if there isn't a Fortran END or STOP statement. ... interaction w/ Matlab). ...
    (comp.soft-sys.matlab)