Silverfrost Forums

Welcome to our forums

How to append inverted data

9 Mar 2011 4:02 #7890

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!

10 Mar 2011 2:28 #7891

To include manageing the file reading: 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

10 Mar 2011 10:21 #7893

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,

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 !

Please login to reply.