Re: Allocatable Arrays As Outputs



-----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-----
.



Relevant Pages

  • 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 ... readkeywordName, numberOfProps, ...
    (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)
  • Re: Help Constructing Fictional Cross-Religious Movement
    ... You know how to do something in Fortran that I ... >don't know how to do despite being pretty familiar with it, COBOL ... > subroutine point ... >was finding a programming problem that seemed reasonably amenable to ...
    (rec.arts.sf.composition)
  • Re: Callbacks - Delphi and CVF
    ... | I have a FORTRAN DLL that does the computations and takes about hours ... | want to be able to access the callback functions address from every ... | subroutine in the fortran dll. ... SUBROUTINE ReportProgress ...
    (comp.lang.fortran)
  • Re: Callbacks - Delphi and CVF
    ... | I have a FORTRAN DLL that does the computations and takes about hours ... | want to be able to access the callback functions address from every ... | subroutine in the fortran dll. ... SUBROUTINE ReportProgress ...
    (comp.lang.fortran)