c Copyright (C) 2008-2014 Vincent Eymet c c KDISTRIBUTION is free software; you can redistribute it and/or modify c it under the terms of the GNU General Public License as published by c the Free Software Foundation; either version 3, or (at your option) c any later version. c KDISTRIBUTION is distributed in the hope that it will be useful, c but WITHOUT ANY WARRANTY; without even the implied warranty of c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the c GNU General Public License for more details. c You should have received a copy of the GNU General Public License c along with KDISTRIBUTION; if not, see c subroutine sort_gw(n,g,w) implicit none include 'max.inc' c c Purpose: to sort "g" and "w" arrays by ascending order of "g" c c Inputs: c + n: number of points in "g" and "w" arrays c c I/O: c + g: array of "n" values of "g" c + w: array of "n" values of "w" c integer n,i,j,f(Nqmx),p double precision g(Nqmx),w(Nqmx) double precision g_in(Nqmx),w_in(Nqmx) double precision g_out(Nqmx),w_out(Nqmx) double precision min c label integer strlen character*(Nchar_mx) label label='subroutine sort_gw' do i=1,n g_in(i)=g(i) w_in(i)=w(i) enddo do i=1,n f(i)=0 enddo c Debug c write(*,*) 'This is sort_gw' c do i=1,n c write(*,*) 'g(',i,')=',g(i),' w(',i,')=',w(i) c enddo c write(*,*) c Debug do i=1,n c Debug c write(*,*) 'Step number',i c do j=1,n c write(*,*) 'f(',j,')=',f(j) c enddo c Debug do j=1,n if (f(j).ne.1) then min=g_in(j) p=j goto 123 endif enddo 123 continue do j=1,n if ((g_in(j).lt.min).and.(f(j).eq.0)) then min=g_in(j) p=j endif enddo ! j c Debug c write(*,*) 'min=',min,' found at p=',p c Debug g_out(i)=g_in(p) w_out(i)=w_in(p) f(p)=1 c Debug c write(*,*) 'g_out(',i,')=',g_out(i),' w_out(',i,')=',w_out(i) c write(*,*) c Debug enddo ! i c Debug c write(*,*) 'Final:' c do i=1,n c write(*,*) 'g_out(',i,')=',g_out(i),' w_out(',i,')=',w_out(i) c enddo c Debug do i=1,n g(i)=g_out(i) w(i)=w_out(i) enddo return end