title: How to convert 2D array to 1D array in Fortran code?
body: <p>How do I convert r(i,j) to a 1D array so that I can sort the number easily?</p>
  
  <pre><code>program sort
    implicit none
    character CN*8,O*7
    integer j,iconf,nconf
    integer i,nbins,t
    integer n,nmax,ind,num,b
    parameter (n=216)
    double precision xbox,rq
    parameter (nmax=3091,nconf=1)
    double precision atom(nmax),id(nmax),ox(nmax),oy(nmax),oz(nmax)
    double precision xij,yij,zij,rij
    double precision r(n,n),A(n)
    open(unit=10,status='unknown',file='1000.gro')
     do iconf= 1,nconf
      write(*,*)iconf
       read(10,*)
       read(10,*)
     do i=1,n
       read(10,'(A8,A7,1i5,3f8.3)')CN,O,num,ox(i),oy(i),oz(i)
     enddo
       read(10,*)xbox        ! read the xbox for PBC
  
    open(unit=3,file='dist.txt')
  
     do i=1,n
      do j=1,n
     if(i .ne. j) then
     xij=ox(i)-ox(j)
     yij=oy(i)-oy(j)
     zij=oz(i)-oz(j)
     r(i,j)=dsqrt(xij**2 + yij**2 + zij**2)
        write(3,'(i3,2x,i3,4x,f17.15)') i,j, r(i,j)
      endif 
      enddo
      enddo
      enddo
      END
  </code></pre>
  
  <p>I have to calculate the distance and save this in array as <code>r (i,j)</code>. I want to convert <code>r(i,j)</code> to a 1 dimensional array, so that I can sort the <code>r(i,j)</code>easily. </p>