replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - How to append inverted data
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to append inverted data

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
pban92



Joined: 23 Nov 2009
Posts: 38

PostPosted: Wed Mar 09, 2011 5:02 pm    Post subject: How to append inverted data Reply with quote

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
View user's profile Send private message
brucebowler
Guest





PostPosted: Wed Mar 09, 2011 6:46 pm    Post subject: Reply with quote

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

PostPosted: Thu Mar 10, 2011 3:28 am    Post subject: Reply with quote

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
View user's profile Send private message
pban92



Joined: 23 Nov 2009
Posts: 38

PostPosted: Thu Mar 10, 2011 11:21 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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