ADMB Documentation  11.1.2547
 All Classes Files Functions Variables Typedefs Friends Defines
dmsort.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: dmsort.cpp 1919 2014-04-22 22:02:01Z johnoel $
00003  * Author: David Fournier
00004  *
00005  * Copyright (c) 2009-2012 ADMB Foundation
00006  */
00011 #include <fvar.hpp>
00012 
00017 dmatrix sort(const dmatrix& m, int column, int NSTACK)
00018 {
00019   ivector ind(m.rowmin(),m.rowmax());
00020   ivector ind1(m.rowmin(),m.rowmax());
00021   ivector ind2(m.rowmin(),m.rowmax());
00022   int i;
00023   for (i=m.rowmin();i<=m.rowmax();i++)
00024   {
00025     ind1(i)=m(i).indexmin();
00026     ind2(i)=m(i).indexmax();
00027   }
00028   sort(extract_column(m,column),ind);
00029   dmatrix tmp(m.rowmin(),m.rowmax(),ind1,ind2);
00030   for (i=m.rowmin();i<=m.rowmax();i++)
00031   {
00032     tmp(i)=m(ind(i));
00033   }
00034   return tmp;
00035 }