# Problem on reading dataset with variable decimal places as it is using fortran

• Fortran
fortranuser
Hi all,
I have attached my text file(tab delimited).
I am planning to read those dataset into real array of (30,38). The dataset has variable decimal places like 312.66, 0, 535.696 ,456122.758.
With the following codes,

WRITE(*,20)((X(I,J),i=1,30),j=1,38)

20 format(58(f12.3x,2x))

I was able to read the original txt file and stored those data into real array of (30,38) and then it was written in new txt file.

The problem is that because of the format(58(f12.3x,2x)) the data set in latter file got changed(now each data set has 3 decimal places)
Is it possible to make data in latter file similar to original text file

Mentor
When you read the original data, it's converted from decimal to binary and stored as binary inside your program. The binary data has no "memory" of the original number of decimal places.

If you really need to preserve the original number of decimal places on output, you should read the data as character strings, then convert the strings to binary numeric data using Fortran's "internal read" technique. Do your calculations using the converted data, but write the original data back out using the character strings.

fortranuser
When you read the original data, it's converted from decimal to binary and stored as binary inside your program. The binary data has no "memory" of the original number of decimal places.

If you really need to preserve the original number of decimal places on output, you should read the data as character strings, then convert the strings to binary numeric data using Fortran's "internal read" technique. Do your calculations using the converted data, but write the original data back out using the character strings.

hi jtbell,
Thanks for writing me. I have written the program just to test which is as follow
PROGRAM CHAR_ARRAY

character(10):: data
real::a
print*,a
END
I gave 45.2 to data and output was 45.200001.
so still the problem is same.

gsal
Well, what jtbell said was to write the original data back out by using the original 'character' variable you read it into...not using your internal 'real' variables.

fortranuser
Well, what jtbell said was to write the original data back out by using the original 'character' variable you read it into...not using your internal 'real' variables.

hi gsal
I carefully read to jtbell again and finally understood what you and he wants me to do.
Thanks both of you.Problem is no more.