Hello, guys. I started with Fortran one week ago and came to the following problem...
Consider, I have one file named "r1.i" with this data inside: (assume that the underscore (_) is blank space)
TEXTTOBEREMOVED_MORETEXT_111_121_131
TEXTTOBEREMOVED_MORETEXT_112_122_132
TEXTTOBEREMOVED_MORETEXT_113_123_133
TEXTTOBEREMOVED_MORETEXT_114_124_134
I need to take the numbers at the end and copy them to another file, which I named "r2.i", so they will appear inside like this:
111_121_131
112_122_132
113_123_133
114_124_134
Here is my code:
When I run this program, it is doing its job, but it gives me the array with this format:
_________111_________121_________131
_________112_________122_________132
_________113_________123_________133
_________114_________124_________134
I need to remove those spaces, so I make "format (I3,1X,I3,1X,I3)" labeled 3. When I put the label 3 into "write (2,3)x(i),y(i),z(i)" and "print 3,x(i),y(i),z(i)", the array.exe prompts this row:
___________4_________121_________131
and it says: "array.exe has encountered a problem and needs to close. We are sorry for the inconvenience." etc.
Please, can you help me? How am I supposed to solve this error?
Thanks in advance!
Consider, I have one file named "r1.i" with this data inside: (assume that the underscore (_) is blank space)
TEXTTOBEREMOVED_MORETEXT_111_121_131
TEXTTOBEREMOVED_MORETEXT_112_122_132
TEXTTOBEREMOVED_MORETEXT_113_123_133
TEXTTOBEREMOVED_MORETEXT_114_124_134
I need to take the numbers at the end and copy them to another file, which I named "r2.i", so they will appear inside like this:
111_121_131
112_122_132
113_123_133
114_124_134
Here is my code:
Code:
program array
implicit none
character t1,t2
integer i,n
integer, allocatable :: x(:),y(:),z(:)
! FILES
open(1,file='r1.i',status='old')
open(2,file='r2.i',status='replace')
! ARRAY
allocate(x(n),y(n),z(n))
n=1000
do i=1,n
read (1,*,end=2) t1,t2,x(i),y(i),z(i)
write (2,*)x(i),y(i),z(i)
print *,x(i),y(i),z(i)
enddo
2 continue
close(2)
close(1)
end program array
When I run this program, it is doing its job, but it gives me the array with this format:
_________111_________121_________131
_________112_________122_________132
_________113_________123_________133
_________114_________124_________134
I need to remove those spaces, so I make "format (I3,1X,I3,1X,I3)" labeled 3. When I put the label 3 into "write (2,3)x(i),y(i),z(i)" and "print 3,x(i),y(i),z(i)", the array.exe prompts this row:
___________4_________121_________131
and it says: "array.exe has encountered a problem and needs to close. We are sorry for the inconvenience." etc.
Please, can you help me? How am I supposed to solve this error?
Thanks in advance!