Re: How to sort a vector and then append data
From: Jugoslav Dujic (jdujic_at_yahoo.com)
Date: 07/31/04
- Next message: David Frank: "Re: How to sort a vector and then append data"
- Previous message: Jugoslav Dujic: "Re: Newbie question: creating dll without the need of CVF 6.6 Runtime library"
- In reply to: joel GUERRERO: "Re: How to sort a vector and then append data"
- Next in thread: Dan Tex1: "Re: How to sort a vector and then append data"
- Reply: Dan Tex1: "Re: How to sort a vector and then append data"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 31 Jul 2004 12:20:45 +0200
joel GUERRERO wrote:
| Catherine Rees Lay <spamtrap@polyhedron.org.uk> wrote in message
| news:<0DsVbmDREhCBFw5N@spamtram.polyhedron.com>...
|| In article <bc7de858.0407291749.a785b3c@posting.google.com>, joel
|| GUERRERO <joegi.geo@yahoo.com> writes
||| Hi,
||| I'm not very experienced using fortran 90, and probably this will
||| looks a stupid question for you.
|||
||| I need to sort a vector and then append the missing data that is:
|||
||| Suppose that we have the following vector: 3 1 2 5 15
|||
||| I need to sort it, that is i need to get: 1 2 3 5 15
|||
||| and then append the missing numbers in order to get the following
||| vector:
|||
||| 1 2 3 -4- 5 -6- -7- -8- -9- -10- -11- -12- -13- -14- 15
|||
||| Hoper you can help me,
|||
||| Joel
||
|| OK, that's bizarre, because there's no need to do ANY sorting to get
|| your desired answer. Just find the maximum value in your vector,
|| allocate a new one that long, and set each element equal to its index.
|| Much more efficient than sorting. You'll also need the minimum value and
|| an offset if your minimum value isn't necessarily 1.
||
|| Of course, if this is a homework problem, you'll have to do it the way
|| you describe. Have a go first and you'll get lots of help here, ask
|| others to do the work for you and you generally won't.
||
|| Catherine.
|
| Hi you all,
|
| Thanks for your help. And it's not homework. I'm writing a program
| for tagging elements in an unstructured mesh, for a posteriori
| refinement.
| Probably I didn't explain myself very clear. The problem is after
| sorting I need to append data in the space between two no consecutive
| numbers. For instance let say that I need to append 1's in that
| space.
|
| That's:
|
| 1-3-2-5-15-8 then sort it:
|
| 1-2-3-5-8-15 and then append 1's
|
| 1-2-3-1-5-1-1-8-1-1-1-1-1-1-15
|
|
| I also need to remove repeated data from an array that is:
|
| 1-2-2-3-4-5-5-6-7-8-9-9-10 from this array i need to remove the
| repeated numbers in order to get:
|
| 1-2-3-4-5-6-7-8-9-10.
OK, with this clarification, you can have a variation on Jan's idea:
integer :: vector(5) = (/3,1,2,5,15/)
integer, allocatable :: new_vector(:)
integer :: i, a, b
integer, parameter:: default_value = 1
a = minval(vector)
b = maxval(vector)
allocate(new_vector(a:b))
new_vector = default_value !(1?)
new_vector(vector) = vector
As you can see in the last line, you can index new_vector with an array vector,
and
assign to it. There's no need for sorting. If there are repeated data, they will
simply be assigned the same value twice in the last line, thus achieving that
requirement also.
-- Jugoslav ___________ www.geocities.com/jdujic Please reply to the newsgroup. You can find my real e-mail on my home page above.
- Next message: David Frank: "Re: How to sort a vector and then append data"
- Previous message: Jugoslav Dujic: "Re: Newbie question: creating dll without the need of CVF 6.6 Runtime library"
- In reply to: joel GUERRERO: "Re: How to sort a vector and then append data"
- Next in thread: Dan Tex1: "Re: How to sort a vector and then append data"
- Reply: Dan Tex1: "Re: How to sort a vector and then append data"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|