comparison util/ksvd utils/ompbox utils/omputils.c @ 137:9207d56c5547 ivand_dev

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