LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-16-2010, 10:45 PM   #1
vjramana
Member
 
Registered: Sep 2009
Posts: 89

Rep: Reputation: 0
Question comparing data in array in FORTRAN


Hi experts,

I have two arrays of data, called data1.dat and data2.dat. each contains 60 data. What I want to do is to compare the data in each file and write the counting into bins. It goes like this. First, take the first data in data1.dat file and compare with the 60 data in data2.dat file. If there is any data which is same with the data in data1.dat then it count in bin. The total bins are also 60. Next it goes to the second data in data1.dat and compare with all the 60 data in data2.dat. If there is any data same then it add in second bin. And it repeats to all the data in data1.dat

I am not very sure how to write this code.

Can anyone help me?

Thank you in advance.

Vijay
 
Old 05-16-2010, 11:38 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Sounds like a job for a "for loop"

Have you tried this? How far did you get? Any problems/questions? Can you post any code?

Inquiring minds want to know
 
Old 05-17-2010, 12:49 PM   #3
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 572

Rep: Reputation: 120Reputation: 120
Any reason why you want to do it in fortran? Seems a bit overkill for a trivial problem.
 
Old 05-18-2010, 03:10 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
To compare arrays you might subtract them and check if the difference is /= 0. Using masks (take a look at the WHERE statement) you can easily count elements and store the results in an integer array of the same length.

As previously stated, it would be far more easy to help by seeing what have you tried so far. Moreover, we could have an idea of your fortran skills.
 
Old 10-14-2011, 04:29 PM   #5
hamedLB
LQ Newbie
 
Registered: Oct 2011
Posts: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by colucix View Post
To compare arrays you might subtract them and check if the difference is /= 0. Using masks (take a look at the WHERE statement) you can easily count elements and store the results in an integer array of the same length.

As previously stated, it would be far more easy to help by seeing what have you tried so far. Moreover, we could have an idea of your fortran skills.
I think using WHERE works better in fortran 90, if you don't want to compile your codes on a CRAY machine. In line with element by element comparison I suggest using:

(suppose you want to compare elements of A(g,m) and B(g,m)...)
(specifically I compare column "k" of A with column "t" of B)

check = 0

DO i = 1,g

if (A(i,k) /= A(i,t)) then
check = check + 1
EXIT
end if

END DO

then you can make use of check later. having changed check from 0 to 1 we can conclude matrix columns are not equal.

Its a lengthy line but it worked.

Good luck,
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
local dynamically allocated array in fortran otoomet Programming 5 10-21-2009 08:28 AM
[SOLVED] array of array in Fortran 90 aihaike Programming 2 07-13-2009 04:34 AM
PHP: Problems comparing data from a DB with data from http request eantoranz Programming 3 08-14-2008 07:55 PM
how to find extent of 1-dim array in fortran 90? johnpaulodonnell Programming 1 03-21-2007 11:42 AM
Fortran Array Tricks? RWild Programming 0 07-22-2003 01:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration