Fortran Read File in Fortran & Rewritecross.dat

  • Thread starter Thread starter marlh
  • Start date Start date
  • Tags Tags
    File Fortran
AI Thread Summary
The discussion revolves around reading and rewriting data from a file named "cross.dat" into a new file called "cross_new.dat" using a Fortran program. The provided Fortran code snippet demonstrates how to read six floating-point numbers from the original file and write them in a specified format to the new file. The format used is "e12.7", which outputs numbers in scientific notation with an 'E' character. A user seeks assistance on how to modify the output format to eliminate the 'E', preferring a representation like "1.000000-5" instead of "1.000000E-5". The conversation highlights the importance of precise data formatting in scientific computing.
marlh
Messages
12
Reaction score
0
I'm trying to read the next data text file :cross.dat

1.000000-5 0.000000+0 2.530000-2 0.000000+0 7.712958+1 0.000000+0
2.250000+3 0.000000+0 2.250000+3 1.838880+1 2.300000+3 1.936710+1
2.500000+3 1.986000+1 2.650000+3 1.843220+1 2.900000+3 1.832230+1
3.000000+3 1.816280+1 3.150000+3 1.834270+1 3.250000+3 1.872690+1

(datatable is sigma form nndc.bnl.gov)
then, i write them in new file: rewritecross.dat

1.000000-5 0.000000+0
2.530000-2 0.000000+0
7.712958+1 0.000000+0
2.250000+3 0.000000+0
2.250000+3 1.838880+1
2.300000+3 1.936710+1
2.500000+3 1.986000+1
2.650000+3 1.843220+1
2.900000+3 1.832230+1
3.000000+3 1.816280+1
3.150000+3 1.834270+1
3.250000+3 1.872690+1

Please, help me solution it. Thanks.
 
Technology news on Phys.org
Quick and dirty solution:
Code:
program readdata

  implicit none
  integer :: i
  real :: x(6)

  open(10,file="cross.dat",status="old")
  open(11,file="cross_new.dat")

  do i = 1,4
     read(10,*) x
     write(11,99) x(1:2)
     write(11,99) x(3:4)
     write(11,99) x(5:6)
99 format(e12.7,1x,e12.7)
  end do

  close(10)
  close(11)


end program readdata

Compile with
Code:
gfortran -O3 -o readdata readdata.f90
 
  • Like
Likes 1 person
Thanks PF Patron!
That's nice solution. I have one more question about format: do you know how to remove letter 'E' in result (This looks like 1.000000-5 replace 1.000000E-5).
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Back
Top