src/Level2/TrnsTable1D.cc
// sosi - General for any matrix.  Put into class matrix when time permits.
General for any matrix.  Put into class matrix when time permits.
General for any matrix . Put into class matrix when time permits .
vector<int> TTable1D::Sort(int k, int type, int colf) const
  {
  int      nvals = rows();		
  if(colf) nvals = cols();		
  double *vals;				
  vals = new double[nvals];		
  vector<int> indx;			
  if(type > 0)  type = 1;		
  else if(type) type = 2;
  int i=0,j=0;				
  for(i=0; i<nvals; i++)		
    { 					
    indx.push_back(i); 			
    switch(type)
      {
      case 0:					
      default:					
        if(colf) vals[i] = getRe(k,i);		
        else     vals[i] = getRe(i,k);
        break;
      case 1:					
        if(colf) vals[i] = norm(get(k,i));	
        else     vals[i] = norm(get(i,k));	
        break;
      case 2:					
        if(colf) vals[i] = getIm(k,i);		
        else     vals[i] = getIm(i,k);		
        break;
      }
    }
  double maxval;			
  int maxind;				
  for(i=0; i<nvals; i++)		
    {					
    maxval = vals[i];			
    maxind = i;				
    for(j=i+1; j<nvals; j++)		
      {
      if(vals[j] > maxval)		
        {				
        maxval = vals[j];		
        maxind = j;			
        }
      }
    vals[maxind] = vals[i];		
    j = indx[maxind];			
    indx[maxind] = indx[i];		
    indx[i] = j;			
    }
  delete [] vals;			
  return indx;				
  }
vector < int > TTable1D :: Sort ( int k , int type , int colf ) const { int nvals = rows ( ) ; if ( colf ) nvals = cols ( ) ; double * vals ; vals = new double [ nvals ] ; vector < int > indx ; if ( type > 0 ) type = 1 ; else if ( type ) type = 2 ; int i = 0 , j = 0 ; for ( i = 0 ; i < nvals ; i ++ ) { indx . push_back ( i ) ; switch ( type ) { case 0 : default : if ( colf ) vals [ i ] = getRe ( k , i ) ; else vals [ i ] = getRe ( i , k ) ; break ; case 1 : if ( colf ) vals [ i ] = norm ( get ( k , i ) ) ; else vals [ i ] = norm ( get ( i , k ) ) ; break ; case 2 : if ( colf ) vals [ i ] = getIm ( k , i ) ; else vals [ i ] = getIm ( i , k ) ; break ; } } double maxval ; int maxind ; for ( i = 0 ; i < nvals ; i ++ ) { maxval = vals [ i ] ; maxind = i ; for ( j = i + 1 ; j < nvals ; j ++ ) { if ( vals [ j ] > maxval ) { maxval = vals [ j ] ; maxind = j ; } } vals [ maxind ] = vals [ i ] ; j = indx [ maxind ] ; indx [ maxind ] = indx [ i ] ; indx [ i ] = j ; } delete [ ] vals ; return indx ; }
sosi - General for any matrix.
sosi - General for any matrix .
//			Initial Setup For Sorting // Number of values to be sorted // Sort the columns based on values // Array of values to be sorted // Allocate the array of values // Allocate vector to return // Insure type = { 0, 1, 2 } //		Copy Column Or Row That Will Be Sorting Key // Array indices we'll use // First fill array vals with values  // we want to sort & initialize the // vector of sorted indices we return // Sorting real values // so copy either the specified // row or column real values // Sorting norms // so copy either the specified // row or column norm values // Sorting imaginary values // so copy either the specified // row or column imaginary vals //	   Sort Column Or Row And Put Sorted Indices Into Return Vector // Value for maximum // Value of index at maximum // Now begin the sorting // by looping over the values // Assume this is maximum // This is it's index // Now compare with all others // 	If we find a larger one //	then we set it as the maximum //	--> Store the bigger value //	--> Store the big value index // Move value we started with to max // Here is the index of largest value // Copy current index to largest spot // Copy index of largest to current spot //       Sorting Is Complete, Clean Up & Return Vector Of Sorted Indices // Delete the values // Return vector of indices