Re: Allocating arrays inside a subroutine.




Timothy Hume wrote:
Hi,

I'm wondering if someone could point me in the right direction with this
problem. I'm a new Fortran 90/95 user, but am familiar with 77.

I want to create a Fortran 90 subroutine that reads data from a file, and
returns it in an array, which is one of the arguments to the subroutine.
Something like this:

SUBROUTINE READ_DATA(FILENAME, DATA_ARRAY)
CHARACTER(LEN=128), INTENT(IN) :: FILENAME
REAL, DIMENSION(:), INTENT(OUT) :: DATA_ARRAY
.
.
.
END SUBROUTINE READ_DATA

Minor point -- I suggest declaring FILENAME as

CHARACTER(LEN=*), INTENT(IN) :: FILENAME

because it does not rely on the passed FILENAME having exactly 128
characters. This was discussed in the message

From: Richard Maine <nos...@xxxxxxxxxxxxx>
Newsgroups: comp.lang.fortran
Subject: Re: variable length strings
Date: 18 Aug 2004 13:42:25 -0700

.



Relevant Pages

  • Re: Allocating arrays inside a subroutine.
    ... I'm a new Fortran 90/95 user, ... subroutine read_data (filename, data_array) ... if your compiler supports the F2003 ALLOCATABLE array ...
    (comp.lang.fortran)
  • Re: Allocating arrays inside a subroutine.
    ... I'm a new Fortran 90/95 user, ... which is one of the arguments to the subroutine. ... once I've opened up FILENAME and read some header records. ... (here you allocate DATA_ARRAY once you read the necessary headers ...
    (comp.lang.fortran)
  • Re: beginner with mex
    ... I have a code which reads a file in fortran and creates a 4 ... The file is in mixed format and I dont ... mex subroutine and call it from matlab. ... you're going to hardwire the filename into the Fortran routine? ...
    (comp.soft-sys.matlab)
  • Re: Allocating arrays inside a subroutine.
    ... Timothy Hume wrote: ... I'm a new Fortran 90/95 user, ... which is one of the arguments to the subroutine. ... thought I could do this by passing an unallocated array to the subroutine, ...
    (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)