/*****************************************************

  Copyright (C) 2011, 2012 Andrea Nobile

  

*******************************************************/

#include <stdlib.h>
#include <stdio.h>


static double *arr;
static   int *iarr;


static int cmpdbl(void *va, void *vb)
{
  
  double a, b;
  int ia, ib;

  ia = *((int*)va);
  ib = *((int*)vb);

  a = arr[ia];
  b = arr[ib];

  if(a > b) return 1;
  else if(a==b) return 0;
  else return -1;


}

#ifndef __COMPAR_FN_T
# define __COMPAR_FN_T
typedef int (*__compar_fn_t) (__const void *, __const void *);
#endif

void sorteigs(double *norms, int *sortedidx, int sz)
{
  
  int i;
  
  arr = norms;
  iarr = sortedidx;

  for(i=0;i<sz;i++) {
    iarr[i]=i;
  }
  
  qsort(sortedidx, sz, sizeof(int), (__compar_fn_t)cmpdbl); 
  
}
