largest no.
dn123
08-04-2010, 01:54 AM
hello all
i have an ascii file in which there r contents like(for example)
a b 1
a b 2
a u 6
p q 8
t s 10
l m 9
i want to take this as an input file,and after the program execute, output looks like
a b 2
a u 6
p q 8
t s 10
l m 9
it means for each and every pair of 1 and 2 collum, i need largest no of third collum....
regards
dn123
davekw7x
08-04-2010, 02:41 PM
...file ...contents like(for example)
To make a program that reads the file, I think you must start with an exact specification. Saying it, "has contents like..." could actually make sense to us mere humans, but Boss Computer needs to know more if you expect it to the Right Thing every time.
So... Tell us exactly what the file format is.
For example:
Is it always two fields consisting of single lower case alphabetic characters followed another field consisting of an integer with a value from 1 to 99? Do the fields always occupy the same columns? (That's the way that Fortran programmers specified things back in the middle of the 20th century.)
Or...
Does each line in the file consist of three fields separated by one or more spaces? With the first two consisting of one to six alphabetic characters and the last field consisting of an integer with a value from zero to 99999?
Or what?
Have you written any code to read the lines? Anything at all?
Regards,
Dave
Footnote:
"Ya gotta have a plan..."
---davekw7x
dn123
08-09-2010, 06:27 AM
i have this data..(it is just a part of it)
(i need for each and every pair of lat,lon a single rain)
1col=i
2col=j
3col=lat
4col=lon
5col=rtemp
6col=rain
137 42 -1.196500 156.300598 0.041000 0.041000
138 42 -1.196500 156.300598 0.000000 0.041000
137 43 -1.196500 156.300598 0.000000 0.041000
138 43 -1.196500 156.300598 0.000000 0.041000
138 42 -1.196500 156.291595 0.000000 0.041000
139 42 -1.196500 156.291595 0.000000 0.041000
138 43 -1.196500 156.291595 0.000000 0.041000
139 43 -1.196500 156.291595 0.000000 0.041000
141 42 -1.196500 156.336594 0.000000 0.000000
142 42 -1.196500 156.336594 0.000000 0.000000
141 43 -1.196500 156.336594 0.000000 0.000000
142 43 -1.196500 156.336594 0.000000 0.000000
142 42 -1.196500 156.327591 0.000000 0.000000
143 42 -1.196500 156.327591 0.000000 0.000000
142 43 -1.196500 156.327591 0.000000 0.000000
143 43 -1.196500 156.327591 0.000000 0.000000
145 42 -1.196500 156.372604 0.000000 0.000000
146 42 -1.196500 156.372604 0.000000 0.000000
145 43 -1.196500 156.372604 0.000000 0.000000
146 43 -1.196500 156.372604 0.000000 0.000000
146 42 -1.196500 156.363602 0.000000 0.000000
147 42 -1.196500 156.363602 0.000000 0.000000
146 43 -1.196500 156.363602 0.000000 0.000000
147 43 -1.196500 156.363602 0.000000 0.000000
149 42 -1.196500 156.408600 0.000000 0.000000
150 42 -1.196500 156.408600 0.000000 0.000000
149 43 -1.196500 156.408600 0.000000 0.000000
150 43 -1.196500 156.408600 0.000000 0.000000
150 42 -1.196500 156.399597 0.000000 0.000000
121 46 -1.232500 156.156601 0.000000 0.000000
122 46 -1.232500 156.156601 0.000000 0.000000
121 47 -1.232500 156.156601 0.027000 0.027000
122 47 -1.232500 156.156601 0.000000 0.027000
122 46 -1.232500 156.147598 0.000000 0.027000
123 46 -1.232500 156.147598 0.000000 0.027000
122 47 -1.232500 156.147598 0.000000 0.027000
123 47 -1.232500 156.147598 0.098000 0.125000
125 45 -1.241500 156.192596 0.000000 0.000000
126 45 -1.241500 156.192596 0.000000 0.000000
125 46 -1.241500 156.192596 0.000000 0.000000
126 46 -1.241500 156.192596 0.000000 0.000000
126 45 -1.241500 156.183594 0.000000 0.000000
127 45 -1.241500 156.183594 0.000000 0.000000
126 46 -1.241500 156.183594 0.000000 0.000000
127 46 -1.241500 156.183594 0.000000 0.000000
125 46 -1.232500 156.192596 0.000000 0.000000
126 46 -1.232500 156.192596 0.000000 0.000000
125 47 -1.232500 156.192596 0.025000 0.025000
126 47 -1.232500 156.192596 0.013000 0.038000
126 46 -1.232500 156.183594 0.000000 0.038000
127 46 -1.232500 156.183594 0.000000 0.038000
126 47 -1.232500 156.183594 0.013000 0.051000
127 47 -1.232500 156.183594 0.000000 0.051000
129 45 -1.241500 156.228592 0.107000 0.107000
130 45 -1.241500 156.228592 0.129000 0.236000
129 46 -1.241500 156.228592 0.000000 0.236000
130 46 -1.241500 156.228592 0.000000 0.236000
130 45 -1.241500 156.219589 0.129000 0.365000
131 45 -1.241500 156.219589 0.093000 0.458000
130 46 -1.241500 156.219589 0.000000 0.458000
131 46 -1.241500 156.219589 0.000000 0.458000
129 46 -1.232500 156.228592 0.000000 0.458000
130 46 -1.232500 156.228592 0.000000 0.458000
129 47 -1.232500 156.228592 0.000000 0.458000
130 47 -1.232500 156.228592 0.071000 0.529000
130 46 -1.232500 156.219589 0.000000 0.529000
131 46 -1.232500 156.219589 0.000000 0.529000
130 47 -1.232500 156.219589 0.071000 0.600000
131 47 -1.232500 156.219589 0.000000 0.600000
133 45 -1.241500 156.264603 0.000000 0.000000
134 45 -1.241500 156.264603 0.000000 0.000000
133 46 -1.241500 156.264603 0.000000 0.000000
134 46 -1.241500 156.264603 0.000000 0.000000
134 45 -1.241500 156.255600 0.000000 0.000000
135 45 -1.241500 156.255600 0.000000 0.000000
134 46 -1.241500 156.255600 0.000000 0.000000
135 46 -1.241500 156.255600 0.056000 0.056000
133 46 -1.232500 156.264603 0.000000 0.056000
*************************************************
i wrote a program, which is
integer l,count
character*15 inp
character*15 fileout
real rr
real,dimension(100000)::lat,lon,rtemp,rain
integer,dimension(100000):: i,j
open(2,file='list',status='old')
5 read(2,'(a)',end=88)inp
fileout=inp(1:11)//'.txt'
open(9,file=fileout,status='unknown')
print*,inp
open(1,file=inp,status='old')
count=0
7 read(1,111,end=99)i(count),j(count),lat(count),
1 lon(count),rtemp(count),rain(count)
count=count+1
go to 7
99 continue
print*,count
do l=1,count
if (lon(l).ne.lon(l+1))then
write(9,110)i(l+1),j(l+1),lat(l+1),lon(l+1),rain(l +1)
endif
enddo
111 format(i3,1x,i3,1x,f11.6,1x,f11.6,1x,f11.6,1x,f12. 6)
110 format(i3,1x,i3,1x,f11.6,1x,f11.6,1x,f11.6)
go to 5
88 continue
stop
end
*****************************************
as i run this, i get an output what i want,except one problem which is in the last line of the output. which shows o in all collums...
davekw7x
08-09-2010, 02:16 PM
i have this data.....
i wrote a program,
That program could not have read that input file since the format statement for reading does not match the file. You still haven't given a file specification, so I'll just create my own file specification and I will use an input statement that will read lines from the particular test file that you posted. Let's face it: giving a particular input file example is not the same as giving a file specification that describe all kinds of files that you want to read, does it?
as i run this, i get an output what i want,except ...
That program does not do what you said you wanted to do in your first post.
Since you haven't given a program specification for whatever it is that you say you are getting now, and a large part of your program makes no sense to me, I'll just make up my own program specification also.
File specification:
Each line has two integer fields and four real fields. Fields are separated by space characters.
Program specification:
Read the six fields from each of the lines from the file and store each variable in its own array. There is a maximum of 1000000 lines.
Write out a file that does the following:
If one or more consecutive lines has the same value for the fourth field, just write the first line.
Now, I have no idea why you want to do this. See Footnote.
For example: Why would you store all of the lines in these huge arrays? Why not just save each unique line as it is read so that it can be used to compare with successive lines? Maybe you want to do something else with the arrays other than just printing the values that I guessed you wanted to use? Or what?
Oh, well...
Here's a way I might do something like you seem to be doing...
integer n, icount, ocount
real, dimension(100000)::lat, lon, rtemp, rain
integer, dimension(100000):: i, j
character*15 InputFileName
character*15 OutputFileName
data InputFileName /'list'/
data OutputFileName /'list.txt'/
open(8, file = InputFileName, status = 'old', err = 1000)
open(9, file = OutputFileName, err = 1001)
C Read a maximum of 100000 lines since that's the size of the arrays
C Will exit the loop with icount equal to one more than the number read
do icount = 1, 100000
read(8, *, end = 99) i(icount), j(icount), lat(icount),
1 lon(icount), rtemp(icount), rain(icount)
end do
99 icount = icount - 1
print *, icount, 'lines read from ', InputFileName
C Probably should check to make sure icount is greater than zero
write(9, 110) i(1), j(1), lat(1), lon(1), rain(1)
ocount = 1
do n = 2, icount
if (lon(n).ne.lon(n-1))then
write(9, 110) i(n), j(n), lat(n), lon(n), rain(n)
ocount = ocount + 1
end if
end do
print *, ocount, 'lines written to ', OutputFileName
stop
1000 print *, "Can't open file ", InputFileName, " for reading."
stop
1001 print *, "Can't open file ", OutputFileName, " for writing."
stop
110 format(i3, 1x, i3, 1x, f11.6, 1x, f11.6, 1x, f11.6, 1x, f12.6)
end
Console output from reading your data file:
78 lines read from list
21 lines written to list.txt
Output file 'list.txt'
137 42 -1.196500 156.300598 0.041000
138 42 -1.196500 156.291595 0.041000
141 42 -1.196500 156.336594 0.000000
142 42 -1.196500 156.327591 0.000000
145 42 -1.196500 156.372604 0.000000
146 42 -1.196500 156.363602 0.000000
149 42 -1.196500 156.408600 0.000000
150 42 -1.196500 156.399597 0.000000
121 46 -1.232500 156.156601 0.000000
122 46 -1.232500 156.147598 0.027000
125 45 -1.241500 156.192596 0.000000
126 45 -1.241500 156.183594 0.000000
125 46 -1.232500 156.192596 0.000000
126 46 -1.232500 156.183594 0.038000
129 45 -1.241500 156.228592 0.107000
130 45 -1.241500 156.219589 0.365000
129 46 -1.232500 156.228592 0.458000
130 46 -1.232500 156.219589 0.529000
133 45 -1.241500 156.264603 0.000000
134 45 -1.241500 156.255600 0.000000
133 46 -1.232500 156.264603 0.056000
Now, I'm guessing that this is not what you wanted, so here's the drill:
Post the exact code and the exact data file that you are using to test.
Tell us exactly what you expected.
Tell us exactly what you got.
Tell us exactly what you don't understand about the difference between what you expected and what you got.
Regards,
Dave
Footnote:
Are you going to use the data with some Numerical Recipes function or what?
dn123
08-11-2010, 01:05 AM
thanks a lot dave, for instat reply...
your program is working good and the result is same as i want.
but i have a new problem with the same data...
i want to sum the rtemp values for every pair of lat and lon.,
i mean look at the first four lines of data, lat and lon are same and rtemp(5 col) are different(0.041 ,0.0 ,0.0 ,0.0) values, if we sum these values we got(0.041+0.0+0.0+0.0) 0.041, for one pair of lat lon and so on...
i need an output like...
137 42 -1.196500 156.300598 0.041000
138 42 -1.196500 156.291595 0.000000
141 42 -1.196500 156.336594 0.000000
142 42 -1.196500 156.327591 0.000000....and so on
thanks again for helping me
regards
dn123