Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

counting numbers from a line

Status
Not open for further replies.

niloy112

Programmer
Mar 5, 2013
7
CA
Say I have 12 number 2,2,2,2,3,4,5,6,7,0,0,0.i want to count the number of 2 from the first end and 0 from the last end ….how can I do it in fortran? say I have 5 lines…and I will have to count the number from each line…as an example I am giving a set of numbers..
2,2,2,2,3,4,5,6,7,0,0,0
2,2,2,6,3,4,5,6,9,0,0,0
2,2,2,2,3,4,5,7,7,0,0,0
2,2,2,5,3,4,5,5,7,0,0,0
2,2,2,7,3,4,5,3,7,0,0,0
Here the answer will be
Number of 2= 4, number of 0=3
Number of 2= 3, number of 0=3
Number of 2= 4, number of 0=3
Number of 2= 3, number of 0=3
Number of 2= 3, number of 0=3
Thank in advance
 
A few questions

1) Are they all single digit numbers or can they be a variable number of digits?
2) Can the number of digits on a line vary? What is the max?

If it is all single digits and the number of digits doesn't vary, you can read it into an array with format 12(I1,1X) and then just go through with a do loop counting the 2s and 0s. Use and end=label to break out when you hit end of file.

 
thanks for your reply.
No these are not single valued. It may vary like 0.987 or 0.675
yes the number of digits in a line may vary..A line can be written in this way:
0,0,0,0,0.98,0.96,0.45
1.45, 1.8,2,2,2,
this is a single line but written in in two line
thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top