Created
February 2, 2012 20:00
-
-
Save jjfajardo/1725431 to your computer and use it in GitHub Desktop.
Implementación del algoritmo de ordenación burbuja en Fortran90.
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
SUBROUTINE abrirfiles | |
INTEGER*4 long | |
CHARACTER*11 status,form | |
CHARACTER*72 cfile | |
CHARACTER*80 fname | |
!!Abrir archivos de lectura y escritura | |
iarg=iargc() | |
if(iarg.ne.1) STOP 'Exactamente introducir un argumento en la linea de comando' | |
CALL GETARG(1,cfile,long) | |
OPEN(1,FILE=cfile,STATUS='old',ERR=8000) | |
8003 READ(1,*,END=8001) iunit,fname,status,form | |
OPEN(iunit,FILE=fname,STATUS=status,FORM=form,iostat=ist,ERR=8002) | |
GOTO 8003 | |
8000 WRITE(*,*) 'Error al abrir !!!!',cfile | |
STOP | |
8002 WRITE(*,*) ' ERROR IN OPENING UNIT:',IUNIT | |
WRITE(*,*) ' FILENAME: ',FNAME,' STATUS: ',STATUS,' FORM:',FORM,ist | |
STOP 'OPEN FAILED' | |
8001 RETURN | |
END |
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
!Códigos correspondientes al trabajo realizado para el ISUM 2012. | |
! Test de rendimiento de los algoritmos de ordenamiento Quicksort, | |
! Mezcla y burbuja implementados en C++, Fortran y Python. | |
! Guanajuato, Guanajuato, México (14-16 de Marzo 2012) | |
! | |
! Programa: burbuja.f90 | |
! compilar: ifort -O burbuja.cpp -o burbuja | |
! Uso: $./burbuja 1000.dat | |
! El tamaño del array se toma del nombre del archivo (1000.dat) | |
! Salida: | |
! $Tamaño_array Tiempo_de_ejecución_del_algoritmo | |
! | |
subroutine burbuja(nelem,arreg) | |
integer :: nelem | |
real :: arreg(nelem) | |
real :: aux | |
integer :: i,j | |
if (nelem.lt.2) return | |
do i=1,nelem-1 | |
do j=1,nelem-i | |
if(arreg(j).gt.arreg(j+1)) then | |
aux=arreg(j) | |
arreg(j)=arreg(j+1) | |
arreg(j+1)=aux | |
endif | |
enddo | |
enddo | |
return | |
end | |
program ordena | |
integer :: n | |
real , allocatable :: v(:) | |
real :: inicio, final | |
call abrirfiles() | |
read(6,*) n | |
allocate(v(n)) | |
do i=1,n | |
read(5,*) v(i) | |
enddo | |
call cpu_time(inicio) | |
call burbuja(n,v) | |
call cpu_time(final) | |
write(*,100) n,(final-inicio) | |
100 format(I9,f16.4) | |
end program |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment