Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Size Array

Subject: Size Array

From: edward kabanyas

Date: 12 Sep, 2011 11:32:11

Message: 1 of 8

Hi all,

I have a matlab code, but I wan to covert it to Fortran77, to be used in a main Fortran77 code. Assume A is an array, I have problem to convert size(A) in Malbab to Fortran77, are there any way to calculate the size of Array in Fortran77 ?? If I calculate the size of A manually, it really takes time if we have many input files such as climatology data.

If you have experience, thanks for sharing..

EDward

Subject: Size Array

From: dpb

Date: 12 Sep, 2011 12:53:03

Message: 2 of 8

On 9/12/2011 6:32 AM, edward kabanyas wrote:
...

> size(A) in Malbab to Fortran77, are there any way to calculate the size
> of Array in Fortran77 ??...

Arrays are static in F77, they have the size of the corresponding
DIMENSION statement (or alternate definition through REAL, etc., that
provides the dimensions).

In F95+ there are the LBOUND and UBOUND intrinsics that do what you want
sorta'; again unless it is an ALLOCATABLE array, the size is static.

What any given F77 compiler supports as an extension is another question
altogether.

--

Subject: Size Array

From: edward kabanyas

Date: 12 Sep, 2011 22:40:31

Message: 3 of 8

Hi dpb,

Thanks for reply. It seems no solution for Fortran77, thanks again..

Edward


dpb <none@non.net> wrote in message <j4kvc7$gmc$1@speranza.aioe.org>...
> On 9/12/2011 6:32 AM, edward kabanyas wrote:
> ...
>
> > size(A) in Malbab to Fortran77, are there any way to calculate the size
> > of Array in Fortran77 ??...
>
> Arrays are static in F77, they have the size of the corresponding
> DIMENSION statement (or alternate definition through REAL, etc., that
> provides the dimensions).
>
> In F95+ there are the LBOUND and UBOUND intrinsics that do what you want
> sorta'; again unless it is an ALLOCATABLE array, the size is static.
>
> What any given F77 compiler supports as an extension is another question
> altogether.
>
> --

Subject: Size Array

From: TideMan

Date: 12 Sep, 2011 22:56:45

Message: 4 of 8

On Sep 13, 10:40 am, "edward kabanyas" <djuky_...@yahoo.com> wrote:
> Hi dpb,
>
> Thanks for reply. It seems no solution for Fortran77, thanks again..
>
> Edward
>
>
>
>
>
>
>
> dpb <n...@non.net> wrote in message <j4kvc7$gm...@speranza.aioe.org>...
> > On 9/12/2011 6:32 AM, edward kabanyas wrote:
> > ...
>
> > > size(A) in Malbab to Fortran77, are there any way to calculate the size
> > > of Array in Fortran77 ??...
>
> > Arrays are static in F77, they have the size of the corresponding
> > DIMENSION statement (or alternate definition through REAL, etc., that
> > provides the dimensions).
>
> > In F95+ there are the LBOUND and UBOUND intrinsics that do what you want
> > sorta'; again unless it is an ALLOCATABLE array, the size is static.
>
> > What any given F77 compiler supports as an extension is another question
> > altogether.
>
> > --

I'm not sure how you plan to "calculate the size of A manually" in
Fortran 77.
As dpb points out, you need to know what it is to DIMENSION correctly.
But my recollection is that in Fortran 77 you can quite happily exceed
array bounds and it will simply return you the next piece of data
available in core.
Of course, in Fortran 90/95, there is the SIZE intrinsic.

Subject: Size Array

From: edward kabanyas

Date: 12 Sep, 2011 23:36:13

Message: 5 of 8

Hi TideMan,

Thanks for your reply.

>plan to "calculate the size of A manually" in
> Fortran 77.

It means I check the data size with my eye and then write/declare the size in the Fortran77, as below:

data nx,nt/1600,715/

>But my recollection is that in Fortran 77 you can quite happily exceed
> array bounds and it will simply return you the next piece of data
> available in core.

If I used for exmaple nt = 700 (the real data row is 715), my fortran only read the data until 700th row, or if I used nt = 1000 (the real data row is 715), EOF error occurs. So what do you mean your statement, "quite happily exceed" ?

Actually, checking the data size with my eye is O.K, but we have thousand input file, it will take time. It seems Fortran77 is not possible for automatic data analysis, for long record data, for many input file with different structure, isn't it ? Or I am too stupid..:)

Cheers
Edward


 <mulgor@gmail.com> wrote in message <83697c0a-e135-45b5-bce9-06a2f7491391@i14g2000prd.googlegroups.com>...
> On Sep 13, 10:40 am, "edward kabanyas" <djuky_...@yahoo.com> wrote:
> > Hi dpb,
> >
> > Thanks for reply. It seems no solution for Fortran77, thanks again..
> >
> > Edward
> >
> >
> >
> >
> >
> >
> >
> > dpb <n...@non.net> wrote in message <j4kvc7$gm...@speranza.aioe.org>...
> > > On 9/12/2011 6:32 AM, edward kabanyas wrote:
> > > ...
> >
> > > > size(A) in Malbab to Fortran77, are there any way to calculate the size
> > > > of Array in Fortran77 ??...
> >
> > > Arrays are static in F77, they have the size of the corresponding
> > > DIMENSION statement (or alternate definition through REAL, etc., that
> > > provides the dimensions).
> >
> > > In F95+ there are the LBOUND and UBOUND intrinsics that do what you want
> > > sorta'; again unless it is an ALLOCATABLE array, the size is static.
> >
> > > What any given F77 compiler supports as an extension is another question
> > > altogether.
> >
> > > --
>
> I'm not sure how you plan to "calculate the size of A manually" in
> Fortran 77.
> As dpb points out, you need to know what it is to DIMENSION correctly.
> But my recollection is that in Fortran 77 you can quite happily exceed
> array bounds and it will simply return you the next piece of data
> available in core.
> Of course, in Fortran 90/95, there is the SIZE intrinsic.

Subject: Size Array

From: dpb

Date: 13 Sep, 2011 00:24:33

Message: 6 of 8

On 9/12/2011 6:36 PM, edward kabanyas wrote:
> Hi TideMan,
>
> Thanks for your reply.
>
>> plan to "calculate the size of A manually" in
>> Fortran 77.
>
> It means I check the data size with my eye and then write/declare the
> size in the Fortran77, as below:
>
> data nx,nt/1600,715/
>
>> But my recollection is that in Fortran 77 you can quite happily exceed
>> array bounds and it will simply return you the next piece of data
>> available in core.
>
> If I used for exmaple nt = 700 (the real data row is 715), my fortran
> only read the data until 700th row, or if I used nt = 1000 (the real
> data row is 715), EOF error occurs. So what do you mean your statement,
> "quite happily exceed" ?

Referencing an out-of-bounds array element. Of course, one can compile
w/ bounds checking with every existent compiler.

And, of course, C is just as happy if not more so... :)

> Actually, checking the data size with my eye is O.K, but we have
> thousand input file, it will take time. It seems Fortran77 is not
> possible for automatic data analysis, for long record data, for many
> input file with different structure, isn't it ? Or I am too stupid..:)
...

I can't decipher the question (if there is one).

If you mean there's no automatic allocation in Fortran a la Matlab, yes,
that is true. That does _not_ mean one cannnot write code to handle
variable-length files or records, however.

I would ask why one would limit oneself to F77 when there are at least
two open source compilers that are F95+ which do include ALLOCATABLE
arrays an at least some of the other extended memory allocation on
assignment of the 2005 and 2008 Standards (altho I don't know how much
or if it is yet fully functional) as well as the commercial compilers.

--

Subject: Size Array

From: TideMan

Date: 13 Sep, 2011 00:49:33

Message: 7 of 8

On Sep 13, 12:24 pm, dpb <n...@non.net> wrote:
> On 9/12/2011 6:36 PM, edward kabanyas wrote:
>
>
>
>
>
>
>
>
>
> > Hi TideMan,
>
> > Thanks for your reply.
>
> >> plan to "calculate the size of A manually" in
> >> Fortran 77.
>
> > It means I check the data size with my eye and then write/declare the
> > size in the Fortran77, as below:
>
> > data nx,nt/1600,715/
>
> >> But my recollection is that in Fortran 77 you can quite happily exceed
> >> array bounds and it will simply return you the next piece of data
> >> available in core.
>
> > If I used for exmaple nt = 700 (the real data row is 715), my fortran
> > only read the data until 700th row, or if I used nt = 1000 (the real
> > data row is 715), EOF error occurs. So what do you mean your statement,
> > "quite happily exceed" ?
>
> Referencing an out-of-bounds array element.  Of course, one can compile
> w/ bounds checking with every existent compiler.
>
> And, of course, C is just as happy if not more so... :)
>
> > Actually, checking the data size with my eye is O.K, but we have
> > thousand input file, it will take time. It seems Fortran77 is not
> > possible for automatic data analysis, for long record data, for many
> > input file with different structure, isn't it ? Or I am too stupid..:)
>
> ...
>
> I can't decipher the question (if there is one).
>
> If you mean there's no automatic allocation in Fortran a la Matlab, yes,
> that is true.  That does _not_ mean one cannnot write code to handle
> variable-length files or records, however.
>
> I would ask why one would limit oneself to F77 when there are at least
> two open source compilers that are F95+ which do include ALLOCATABLE
> arrays an at least some of the other extended memory allocation on
> assignment of the 2005 and 2008 Standards (altho I don't know how much
> or if it is yet fully functional) as well as the commercial compilers.
>
> --

Well, way back then, when I was doing finite element programming
(using Fortran 4, I think), we used what we called "dynamic memory
allocation".
common x(100000)

i1=1
i2=i1+ndim
i3=i2+mdim
etc

Then
call sub(x(i1),x(i2),x(i3),ndim,mdim)

subroutine sub(u,v,w,n,m)
dimension u(n),v(n),w(m)
etc

Now, what I meant by "quite happily exceed", is that you could access
x(100001) (i.e., beyond the limit of x) and get a number, though there
was no guarantee what it would be.

Subject: Size Array

From: dpb

Date: 13 Sep, 2011 01:32:24

Message: 8 of 8

On 9/12/2011 7:49 PM, TideMan wrote:
> On Sep 13, 12:24 pm, dpb<n...@non.net> wrote:
...

>>>> But my recollection is that in Fortran 77 you can quite happily exceed
>>>> array bounds and it will simply return you the next piece of data
>>>> available in core.
>>
>>> If I used for exmaple nt = 700 (the real data row is 715), my fortran
>>> only read the data until 700th row, or if I used nt = 1000 (the real
>>> data row is 715), EOF error occurs. So what do you mean your statement,
>>> "quite happily exceed" ?
>>
>> Referencing an out-of-bounds array element. Of course, one can compile
>> w/ bounds checking with every existent compiler.
...

> Well, way back then, when I was doing finite element programming
> (using Fortran 4, I think), we used what we called "dynamic memory
> allocation".
> common x(100000)
>
> i1=1
> i2=i1+ndim
> i3=i2+mdim
> etc
>
> Then
> call sub(x(i1),x(i2),x(i3),ndim,mdim)
>
> subroutine sub(u,v,w,n,m)
> dimension u(n),v(n),w(m)
> etc
>
> Now, what I meant by "quite happily exceed", is that you could access
> x(100001) (i.e., beyond the limit of x) and get a number, though there
> was no guarantee what it would be.

Certainly, that would be a bounds error. But, every compiler today can
do runtime bounds checking (albeit at some performance cost).

It's not like that's anything unique to Fortran, either, and what does
that have to do w/ the OP's question?

The same scheme is workable today in Fortran but there are more
programmer-friendly ways in current Fortran (allocatable arrays being one).

--

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us