File: gsort.c

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (113 lines) | stat: -rw-r--r-- 4,854 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*-----------------------------------------------------------------------------------*/
/* Written by  Jean-Philippe Chancelier Copyright (C) ENPC 1998-2001                 *
 * Modified (restructuration and bug fix) by Allan Cornet  INRIA 2006                */
/*-----------------------------------------------------------------------------------*/ 
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "Math.h"

#include "../os_specific/men_Sutils.h"
/*-----------------------------------------------------------------------------------*/ 
extern void sciqsort();
extern void GlobalSortchar(char * *a,int *ind,int flag,int n,int p,char dir);
extern void LexiColchar(char * *a,int *ind,int flag,int n,int p,char dir);
extern void LexiRowchar(char * *a,int *ind,int flag,int n,int p,char dir);
extern void RowSortchar(char * *a,int *ind,int flag,int n,int p,char dir);
extern void ColSortchar(char * *a,int *ind,int flag,int n,int p,char dir);
extern void GlobalSortdouble(double *a,int *ind,int flag,int n,int p,char dir);
extern void LexiColint(int *a,int *ind,int flag,int n,int p,char dir);
extern void LexiRowint(int *a,int *ind,int flag,int n,int p,char dir);
extern void RowSortdouble(double *a,int *ind,int flag,int n,int p,char dir);
extern void ColSortdouble(double *a,int *ind,int flag,int n,int p,char dir);
/*-----------------------------------------------------------------------------------*/ 
/******************************************************
 * General sort routine for Scilab 
 * xI is the transmitted table to sort ( if table is int ) 
 * xD is the transmitted table to sort ( if table is double ) 
 * ind is the int table to store the permutation 
 *     (which is to be initialized and changed )
 * iflag == if 1 ind is to be computed if 0 ind is ignored 
 * m,n : matrix size 
 * type : the operation ( see the interface ) 
 * iord : 'i' or 'd' : increasind or decreasing sort 
 ******************************************************/
int C2F(gsort)(int *xI, double *xD, int *ind, int *iflag, int *m, int *n, char *type, char *iord)
{

  switch ( type[0])
    {
    case 'r' :  ColSortdouble(xD,ind,*iflag,*m,*n,iord[0]);break;
    case 'c' :  RowSortdouble(xD,ind,*iflag,*m,*n,iord[0]);break;
    case 'l' :  
      if ( type[1] == 'r' ) 
	CNAME(LexiRow,int)(xI,ind,*iflag,*m,*n,iord[0]);
      else
	CNAME(LexiCol,int)(xI,ind,*iflag,*m,*n,iord[0]);
      break;
    case 'g' : 
    default :  GlobalSortdouble(xD,ind,*iflag,*m,*n,iord[0]);break;
    }
  return(0);
}
/*-----------------------------------------------------------------------------------*/ 
/******************************************************
 * General sort routine for Scilab 
 * The version for Scilab strings 
 * iflag == if 1 ind is to be computed if 0 ind is ignored 
 * m,n : matrix size 
 * type : the operation ( see the interface ) 
 * iord : 'i' or 'd' : increasind or decreasing sort 
 ******************************************************/
void C2F(gsorts_old)(int *value, int *ptrv, int *m, int *n, int *res, int *ptrres, int *ierr, int *ind, int *iflag, char *type, char *iord)
{
  char **data;
  int i,nv;
  int maxchars= *ierr;
  *ierr=0;
  nv = *m*(*n);
  /* conversion of scilab characters into strings */
  ScilabMStr2CM(value,&nv,ptrv,&(data),ierr);
  if ( *ierr == 1) return;
  switch ( type[0])
    {
    case 'r' :  ColSortchar(data,ind,*iflag,*m,*n,iord[0]);break;
    case 'c' :  RowSortchar(data,ind,*iflag,*m,*n,iord[0]);break;
    case 'l' :  
      if ( type[1] == 'r' ) 
				LexiRowchar(data,ind,*iflag,*m,*n,iord[0]);
      else
				LexiColchar(data,ind,*iflag,*m,*n,iord[0]);
      break;
    case 'g' : 
    default :  GlobalSortchar(data,ind,*iflag,*m,*n,iord[0]);break;
    }
  ScilabCM2MStr(data,nv,res,ptrres,maxchars,ierr);
  for (i=0;i< nv ;i++) FREE(data[i]); FREE(data);
}
/*-----------------------------------------------------------------------------------*/ 
/******************************************************
 * General sort routine for Scilab strings 
 * iflag == if 1 ind is to be computed if 0 ind is ignored 
 * m,n : matrix size 
 * type : the operation ( see the interface ) 
 * iord : 'i' or 'd' : increasind or decreasing sort 
 ******************************************************/
void C2F(gsorts)(char **data, int *ind, int *iflag, int *m, int *n, char *type, char *iord)
{

  switch ( type[0])
    {
    case 'r' :  ColSortchar(data,ind,*iflag,*m,*n,iord[0]);break;
    case 'c' :  RowSortchar(data,ind,*iflag,*m,*n,iord[0]);break;
    case 'l' :  
      if ( type[1] == 'r' ) 
		LexiRowchar(data,ind,*iflag,*m,*n,iord[0]);
      else
		LexiColchar(data,ind,*iflag,*m,*n,iord[0]);
      break;
    case 'g' : 
    default :  GlobalSortchar(data,ind,*iflag,*m,*n,iord[0]);break;
    }
}
/*-----------------------------------------------------------------------------------*/