program ordinavett ! ! legge un file di coppie di numeri e le ordina ! a x crescente ! i vettori passano ai sottoprogrammi in forma esplicita ! integer, parameter :: idim=10 real, dimension(idim) :: x,y integer :: n,i call readdati(x,y,n,idim) call ordina(x,y,n) do i=1,n write(6,'(2f8.2)')x(i),y(i) enddo end program ordinavett subroutine readdati (x,y,n,idim) integer, intent(OUT) :: n integer, intent(IN) :: idim real, dimension(1) :: x,y integer :: iend do i=1,idim read(5,*,iostat=iend)x(i),y(i) if(iend /= 0)exit enddo if(iend > 0)then write(6,*)'Errore di lettura :',iend stop endif if (i > idim)then write(6,*) 'errore :numero dati >= ',idim stop endif n=i-1 end subroutine readdati subroutine ordina (x,y,n) integer, intent(IN) :: n real, dimension(1),intent(OUT):: x,y real::t integer::i,j write(6,'(i2,10f5.1)')0,(x(i),i=1,n) do j = n-1, 1 , -1 do i=1,j if(x(i) > x(i+1)) then call scambio(x(i),x(i+1)) call scambio(y(i),y(i+1)) endif enddo write(6,'(i2,10f5.1)')j,(x(i),i=1,n) enddo end subroutine ordina subroutine scambio(v1,v2) implicit none real :: v1,v2,t t=v1 v1=v2 v2=t end subroutine scambio