Newbie Question (Was: Newbie Question...) 
Author Message
 Newbie Question (Was: Newbie Question...)

Thanks to everyone for all the suggestion. Every one of them has
enlightned me a lot. I suppose I will use the "find" subroutine I
wrote modifiied as Jugoslav suggested (in a module), or the function
proposed by David (the solution proposed by David is far more
intuitive and useful than mine).
I still have some problem with the PACK function (as suggested by Paul
& Richard & Michel), but maybe is because here at work I only have
digital visual fortran 6.0 (Mathworks says that is enormously bugged),
or maybe because I'm so stupid I've made mistakes again... So I have
to try at home. After the declaration:

write(*,*) pack((/(i, i = 1,size(in_1))/),(in_1 /= 0))

My compiler keeps giving me the error:

D:\temp\find.f90
D:\temp\find.f90(87) : Error: The shapes of the arguments do not
conform. [PACK]
write(*,*) pack((/(i, i = 1,size(in_1))/),(in_1 /= 0))

Thanks to everyone for your help.



Mon, 27 Feb 2006 00:49:24 GMT  
 Newbie Question (Was: Newbie Question...)

Quote:

> write(*,*) pack((/(i, i = 1,size(in_1))/),(in_1 /= 0))

> My compiler keeps giving me the error:

> D:\temp\find.f90
> D:\temp\find.f90(87) : Error: The shapes of the arguments do not
> conform. [PACK]
> write(*,*) pack((/(i, i = 1,size(in_1))/),(in_1 /= 0))

That's because they don't match.  Referring back to your original
code, I see that in_1 has rank 2.  The expression (in_1 /= 0)
will have the same shape as in_1.

But the array constructor (/(i, i = 1,size(in_1))/) has rank 1.
and so can never match the shape of anything of rank 2.

Rank matters.  It is part of shape.  Note that the shape of an
array is itself an array, always of rank 1.  The size of the
shape is the rank of the array.

An array declared as x(1) is not the same thing as a scalar x.
Likewise, an array declared as x(n,1) or x(1,n) is not the same as
an array declared x(n).  They have the same number of elements,
but their shape is not the same because their rank is different.
The shape of an array declared as x(n) is (/ n /).  The shape of
an array declared as x(n,1) is (/ n, 1 /).  Note the difference.

--
Richard Maine                       |  Good judgment comes from experience;
email: my first.last at org.domain  |  experience comes from bad judgment.
org: nasa, domain: gov              |        -- Mark Twain



Mon, 27 Feb 2006 01:34:35 GMT  
 Newbie Question (Was: Newbie Question...)

Quote:


> > write(*,*) pack((/(i, i = 1,size(in_1))/),(in_1 /= 0))

> > My compiler keeps giving me the error:

> > D:\temp\find.f90
> > D:\temp\find.f90(87) : Error: The shapes of the arguments do not
> > conform. [PACK]
> > write(*,*) pack((/(i, i = 1,size(in_1))/),(in_1 /= 0))

> That's because they don't match.  Referring back to your original
> code, I see that in_1 has rank 2.  The expression (in_1 /= 0)
> will have the same shape as in_1.

> But the array constructor (/(i, i = 1,size(in_1))/) has rank 1.
> and so can never match the shape of anything of rank 2.

The easy fix (well, it's easy now that I looked it up) is to use

( (/in_1/) /=0)

as the second argument to PACT.  This "constructs" a temporary
1D array that has the elements of in_1 in storage order.

Dick Hendrickson

- Show quoted text -

Quote:
> Rank matters.  It is part of shape.  Note that the shape of an
> array is itself an array, always of rank 1.  The size of the
> shape is the rank of the array.

> An array declared as x(1) is not the same thing as a scalar x.
> Likewise, an array declared as x(n,1) or x(1,n) is not the same as
> an array declared x(n).  They have the same number of elements,
> but their shape is not the same because their rank is different.
> The shape of an array declared as x(n) is (/ n /).  The shape of
> an array declared as x(n,1) is (/ n, 1 /).  Note the difference.

> --
> Richard Maine                       |  Good judgment comes from experience;
> email: my first.last at org.domain  |  experience comes from bad judgment.
> org: nasa, domain: gov              |        -- Mark Twain



Mon, 27 Feb 2006 03:40:42 GMT  
 Newbie Question (Was: Newbie Question...)

Quote:

> The easy fix (well, it's easy now that I looked it up) is to use

> ( (/in_1/) /=0)

> as the second argument to PACT.  This "constructs" a temporary
> 1D array that has the elements of in_1 in storage order.

Ooo.  Tricky (anyway, I think so).  I'd forgotten about that
particular feature of arrays in array constructors.

--
Richard Maine                       |  Good judgment comes from experience;
email: my first.last at org.domain  |  experience comes from bad judgment.
org: nasa, domain: gov              |        -- Mark Twain



Mon, 27 Feb 2006 03:50:46 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Subject: Re: Newbie question (was Re: I am new)

2. Simple Newbie Question: What am I doing wrong?

3. Not a newbie, but a newbie question...

4. Trivial Newbie Question (Newbie)

5. Newbie Question: Realbasic Question

6. Yet another question on system calls(newbie question)

7. question on event-generated errors (was Re: newbie TkCon question)

8. Newbie Newbie, we are all Newbie to something

9. I am a stupid newbie.

10. HELP, I am Clarion Newbie

11. Help, I am a Clarion Newbie

12. Problem with file I/O on solaris .I am a newbie to fortran

 

 
Powered by phpBB® Forum Software