annotate solvers/SMALL_ompGabor/omputils.c @ 234:c96880c0c47c

renamed file.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Thu, 19 Apr 2012 17:21:05 +0100
parents 31d2864dfdd4
children
rev   line source
ivan@140 1 /**************************************************************************
ivan@140 2 *
ivan@140 3 * File name: omputils.c
ivan@140 4 *
ivan@140 5 * Ron Rubinstein
ivan@140 6 * Computer Science Department
ivan@140 7 * Technion, Haifa 32000 Israel
ivan@140 8 * ronrubin@cs
ivan@140 9 *
ivan@140 10 * Last Updated: 18.8.2009
ivan@140 11 *
ivan@140 12 *************************************************************************/
ivan@140 13
ivan@140 14 #include "omputils.h"
ivan@140 15 #include <math.h>
ivan@140 16
ivan@140 17
ivan@140 18 const char FULL_GAMMA_STR[] = "full";
ivan@140 19 const char SPARSE_GAMMA_STR[] = "sparse";
ivan@140 20
ivan@140 21
ivan@140 22 /* convert seconds to hours, minutes and seconds */
ivan@140 23
ivan@140 24 void secs2hms(double sectot, int *hrs, int *mins, double *secs)
ivan@140 25 {
ivan@140 26 *hrs = (int)(floor(sectot/3600)+1e-2);
ivan@140 27 sectot = sectot - 3600*(*hrs);
ivan@140 28 *mins = (int)(floor(sectot/60)+1e-2);
ivan@140 29 *secs = sectot - 60*(*mins);
ivan@140 30 }
ivan@140 31
ivan@140 32
ivan@140 33 /* quicksort, public-domain C implementation by Darel Rex Finley. */
ivan@140 34 /* modification: sorts the array data[] as well, according to the values in the array vals[] */
ivan@140 35
ivan@140 36 #define MAX_LEVELS 300
ivan@140 37
ivan@140 38 void quicksort(mwIndex vals[], double data[], mwIndex n) {
ivan@140 39
ivan@140 40 long piv, beg[MAX_LEVELS], end[MAX_LEVELS], i=0, L, R, swap ;
ivan@140 41 double datapiv;
ivan@140 42
ivan@140 43 beg[0]=0;
ivan@140 44 end[0]=n;
ivan@140 45
ivan@140 46 while (i>=0) {
ivan@140 47
ivan@140 48 L=beg[i];
ivan@140 49 R=end[i]-1;
ivan@140 50
ivan@140 51 if (L<R) {
ivan@140 52
ivan@140 53 piv=vals[L];
ivan@140 54 datapiv=data[L];
ivan@140 55
ivan@140 56 while (L<R)
ivan@140 57 {
ivan@140 58 while (vals[R]>=piv && L<R)
ivan@140 59 R--;
ivan@140 60 if (L<R) {
ivan@140 61 vals[L]=vals[R];
ivan@140 62 data[L++]=data[R];
ivan@140 63 }
ivan@140 64
ivan@140 65 while (vals[L]<=piv && L<R)
ivan@140 66 L++;
ivan@140 67 if (L<R) {
ivan@140 68 vals[R]=vals[L];
ivan@140 69 data[R--]=data[L];
ivan@140 70 }
ivan@140 71 }
ivan@140 72
ivan@140 73 vals[L]=piv;
ivan@140 74 data[L]=datapiv;
ivan@140 75
ivan@140 76 beg[i+1]=L+1;
ivan@140 77 end[i+1]=end[i];
ivan@140 78 end[i++]=L;
ivan@140 79
ivan@140 80 if (end[i]-beg[i] > end[i-1]-beg[i-1]) {
ivan@140 81 swap=beg[i]; beg[i]=beg[i-1]; beg[i-1]=swap;
ivan@140 82 swap=end[i]; end[i]=end[i-1]; end[i-1]=swap;
ivan@140 83 }
ivan@140 84 }
ivan@140 85 else {
ivan@140 86 i--;
ivan@140 87 }
ivan@140 88 }
ivan@140 89 }