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

help

help

(OP)
Hi all,

I have two files
111
112
113
111
114
&
115
115
116
117
117
118

I wanted to compare each value from file 1 with all values in file 2 and write the outputs if file1(i)+3==file2. my code is

open(11,file='f1')
i=1
32 read(11,*,end=98)file1(i)
open (12,file='f2')
31 read(12,*,end=99)file2
if(file1(i)+3.eq.file2)then
write(*,*)file1(i),file2,i
end if
go to 31
99 continue
close(12)
i=i+1
go to 32
98 continue
end program test

output is

112 115 2
112 115 2
113 116 3
114 117 5
114 117 5

the third col is array index I am looking how this array index can be made continuous ie 1,2,3 instead 2,3,5

Thanks in advance

RE: help

And what should be your desired output?

RE: help

Like this ?

CODE

112 115 1
112 115 2
113 116 3
114 117 4
114 117 5 

RE: help

(OP)
Actually it should be

1 instead 2
1 2
2 3
3 5
3 5

Thanks

Charls Antony

RE: help

Then you have to store the value of previous file2 in file2_old and then increment the index only when file .ne. file2_old

I tried it a do got

CODE

$ acharls
         112         115           1
         112         115           1
         113         116           2
         114         117           3
         114         117           3 

RE: help

Please do not use 'go-to', there still is a place for 'go-to', but this is not one of them. Please use a do-loop.

Second, please do not keep opening and closing files inside a loop, this is totally unnecessary; simply read all the data into the arrays ahead of the loops and that is it.

The reason why you currently have a repeated "index" is because your 'i' currently represent the index of the iterm from file 1...and because such item finds two matches from file 2, well, it prints the same number twice.

RE: help

(OP)
Hi,

Thanks mikrom & salgerman. I solved it.

Charls


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