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).
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...

Similar threads

Back
Top