 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
pban92
Joined: 23 Nov 2009 Posts: 38
|
Posted: Wed Mar 09, 2011 5:02 pm Post subject: How to append inverted data |
|
|
Hello all,
I have a one column data file, let's say, containing,
1
2
3
4
5
Now I would like to invert (not sorting) the column and append with the existing one to a new file as in,
1
2
3
4
5
5
4
3
2
1
Could anybody give a hint on how to do that?
Many thanks! |
|
Back to top |
|
 |
brucebowler Guest
|
Posted: Wed Mar 09, 2011 6:46 pm Post subject: |
|
|
Let's assume the data is in an array called data and the number of samples is in a variable called n
Code: |
do i = 1,n
write (*,*) data(i)
enddo
do i = n,1,-1
write (*,*) data(i)
enddo
|
|
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Thu Mar 10, 2011 3:28 am Post subject: |
|
|
To include manageing the file reading: Code: | integer data(100),i,n, iostat
!
open (unit=11,file='old_data')
do i = 1,size(data)
read (11,fmt='(bn,i10)',iostat=iostat) data(i)
if (iostat == -1) exit
if (iostat/= 0) write (*,*) 'error reading number on line',i
end do
close (unit=11)
n = i-1
write (*,*) n,' numbers recovered from old_data'
!
open (unit=12,file='new_data')
do i = 1,n
write (12,fmt='(i0)') data(i)
end do
do i = n,1,-1
write (12,fmt='(i0)') data(i)
end do
close (unit=12)
!
end
|
|
|
Back to top |
|
 |
pban92
Joined: 23 Nov 2009 Posts: 38
|
Posted: Thu Mar 10, 2011 11:21 am Post subject: |
|
|
Did not realize "appending" is that simple to an output file! However, I am still unable to figure out how to do that within the code in the case below,
Code: | sum=0.
DO i = 1,n
sum(i) = sum(i)+1
END DO
! now to append
DO =n,1,-1
sum(i) = sum(i)
END DO |
Is it rightly done?
Many thanks ! |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|