How to get first digit of a double precision number?

  • Thread starter Thread starter aaron2
  • Start date Start date
  • Tags Tags
    Precision
aaron2
Messages
5
Reaction score
0
EDIT: Sorry, forgot to mention 'FORTRAN' in the subject line...

Hi, I'm new to fortran but I'm trying to generate the first 1476 terms of the fibonacci sequence, then examine the first digit of each term and store the number of 1s, 2s, 3s, ..., 9s that occur into an array. I have it to where it prints all of the terms to a text file, and I was going to try to read the first number from each new line.

However, it has been several hours and I have not been able to use this method, so I've decided to just get the first digit of the real number before actually writing it to the text document. Then, it's just a matter of reading the text document line by line without having to deal with all of the formatting business.

So, my question boils down to extracting the first digit of a double precision number (real*8) and storing it into an integer. Any ideas of how to do this?
 
on Phys.org
For the file, you could read in each line as a text string, then parse that string to find the "first" digit.
 
Jeff Reid said:
For the file, you could read in each line as a text string, then parse that string to find the "first" digit.

Yeah, I just started trying that. Currently I'm looking into how to find the first character of a string in fortran..
 
I think you use the : operator:

print *,'first character is ' // ch(1:1)
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
24K
Replies
19
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
1K
Replies
4
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 13 ·
Replies
13
Views
5K
  • Sticky
  • · Replies 13 ·
Replies
13
Views
9K