Created
November 27, 2010 03:01
-
-
Save rbonvall/717519 to your computer and use it in GitHub Desktop.
archivo-ordenar.f95
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program ordenar_archivo | |
implicit none | |
integer :: a, b, st | |
open (unit=10, file='a.txt', action='read') | |
do | |
read (10, *, iostat=st), a | |
if (st /= 0) exit | |
! lo que viene a continuacion es la manera que vimos para agregar un | |
! registro a un archivo ordenado (clase del 17 de noviembre) | |
open (unit=11, file='ordenados.txt', action='read') | |
open (unit=12, file='temp.txt', action='write') | |
do | |
read (11, *, iostat=st), b | |
if (st /= 0) exit | |
if (a < b) exit | |
write (12, *), b | |
end do | |
write (12, *), a | |
if (st == 0) then | |
write (12, *), b | |
end if | |
do | |
read (11, *, iostat=st), b | |
if (st /= 0) exit | |
write (12, *), b | |
end do | |
close (11) | |
close (12) | |
call unlink('ordenados.txt') | |
call rename('temp.txt', 'ordenados.txt') | |
end do | |
close (10) | |
end program ordenar_archivo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment