INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

doubt

doubt

(OP)
Hi all,
I have some difficulty in processing a data.
I have 3 files each file has data(100x1).
while processing I derived 5 variables from data(100x1). ie a(2,10),b(2,10),c(2,10)...
Then I tried to sort each 10 values. my sorting subroutine take 1-D array (x(n)), so here I saved each 10 data to x(n) before passing to subroutine. Then I called subroutine 5 times (ie for five variables)
do i=1,2
do j=1,10
x1(j)=a(i,j)
.
.
x5(j)=e(i,j)

call sort(x1)
.
.
call sort(x5)
end do
end do
is there any alternative so that I need to call subroutine only once. ie some additional loop so that variables keep on changing.
my entire fortran code contain many such situations (different subroutines) and original data is large (30000 data points).

Thanks in advance
Charls

RE: doubt

Go onto google and type "FORTRAN SORT", there are hundreds of examples of bubble sorts and free library routines to sort an array. Also if you want to do it yourself, a bubble sort is very easy to implement

Bill
Lead Application Developer
New York State, USA

RE: doubt

(OP)
Hi Bill,

I am sorry, It is not about sorting but "calling subroutine multiple times", as u can see I used call 5 times for 5 variables.
This can be simplified somehow ?. like in a do loop, hence I write "call" only once in the program and variables(a,b,c..) get repeated through do loop (I am not sure this make sense).I hope the doubt is more clear now?.

regards,

Charls

RE: doubt

IMO instead what you wrotre above

CODE

do i=1,2
  do j=1,10
     x1(j)=a(i,j)
     .
     . 
     x5(j)=e(i,j) 

     call sort(x1)
     . 
     . 
     call sort(x5) 
  end do
end do 
it should be

CODE

do i=1,2
  do j=1,10
     x1(j)=a(i,j)
     .
     . 
     x5(j)=e(i,j) 
  end do
  call sort(x1)
  . 
  . 
  call sort(x5) 
end do 
But what do you do with the arrays x1, x2, .., x5 after sorting ?
Do you need them in further processing or do you store them back into a, b, .., e ?

RE: doubt

There are plenty of tricks one can do with arrays in Fortran, I definitely recommend you seek some documentation on that.

I have not tested any of the code below, but...

With your arrays as they are, I believe you should be able to skip the 1-D 'X' arrays and do something like:

CODE --> Fortran

real :: a(2,10), b(2,10), c(2,10), d(2,10), e(2,10)
    do j = 1,2
        call sort( a(j,:) )
        call sort( b(j,:) )
        call sort( c(j,:) )
        call sort( d(j,:) )
        call sort( e(j,:) )
    end do 

Or, you could glue all those 2-D matrices into a single 3-D array and do something like:

CODE --> Fortran

real :: f(5,2,10)
    do i = 1,5
        do j = 1,2
            call sort( f(i,j,:) )
        end do  
    end do 

Or, you could keep a good track of your indeces and glue all those rectangular 2-D matrices into a single square one:

CODE --> Fortran

real :: g(10,10)
    do j = 1,10
        call sort( g(j,:) )
    end do 

Anyway, play around.

RE: doubt

(OP)
salgerman,

I tried second method. Exactly what I was searching.

Thanks salgerman, mikrom & bill.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close