File: sparse.c

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (98 lines) | stat: -rw-r--r-- 1,853 bytes parent folder | download
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
/* Copyright INRIA */
#include <string.h>

#ifdef __STDC__
#include <stdlib.h>
#else
#include <malloc.h>
#endif

#include "../machine.h"

#include "sparse.h"

#define FREE(x) if (x  != NULL) free((char *) x);

Sparse *NewSparse(it,m,n,nel)
     int *m,*n,*nel,*it;
{
  Sparse *loc;
  loc = (Sparse *) malloc((unsigned) sizeof(Sparse));
  if ( loc == (Sparse *) 0)
    {
      return((Sparse *) 0);
    }
  loc->m = *m;
  loc->n = *n;
  loc->it = *it;
  loc->nel = *nel;
  loc->mnel = (int*) malloc((unsigned) (*m)*sizeof(int));
  if ( loc->mnel == (int *) 0)
    {
      FREE(loc);
      return((Sparse *) 0);
    }
  loc->icol = (int*) malloc((unsigned) (*nel)*sizeof(int));
  if ( loc->icol == (int *) 0)
    {
      FREE(loc->mnel);
      FREE(loc);
      return((Sparse *) 0);
    }
  loc->xr =  (double*) malloc((unsigned) (*nel)*sizeof(double));
  if ( loc->xr == (double *) 0)
    {
      FREE(loc->icol);
      FREE(loc->mnel);
      FREE(loc);
      return((Sparse *) 0);
    }

  if ( *it == 1) 
    {
      loc->xi =  (double*) malloc((unsigned) (*nel)*sizeof(double));
      if ( loc->xi == (double *) 0)
	{
	  FREE(loc->xr);
	  FREE(loc->icol);
	  FREE(loc->mnel);
	  FREE(loc);
	  return((Sparse *) 0);
	}
    }
  return(loc);
}

FreeSparse(x)
     Sparse *x;
{
  if ( x->it == 1 ) FREE(x->xi);
  FREE(x->xr);
  FREE(x->icol);
  FREE(x->mnel);
  FREE(x);
}

/*******************************************
 * intersci external function for sparse 
 *******************************************/

int C2F(csparsef)(x,mnel,icol,xr,xi)
     Sparse **x;
     int *mnel,*icol;
     double *xr,*xi;
{
  int i;
  for ( i=0 ; i < (*x)->m ; i++) 
    mnel[i] = (*x)->mnel[i];
  for ( i=0 ; i < (*x)->nel ; i++) 
    {
      icol[i] = (*x)->icol[i];
      xr[i] = (*x)->xr[i];
      if ( (*x)->it == 1 )xi[i] = (*x)->xi[i];
    }
  FreeSparse(*x);
}