array.h 3.27 KB
Newer Older
kollo's avatar
kollo committed
1 2 3 4 5 6 7 8 9
/* ARRAY.H (c) Markus Hoffmann  */

/* This file is part of X11BASIC, the basic interpreter for Unix/X
 * ============================================================
 * X11BASIC is free software and comes with NO WARRANTY - read the file
 * COPYING for details
 */


kollo's avatar
kollo committed
10 11 12 13 14
ARRAY create_array(const int , const int ,const int *);
ARRAY recreate_array(const int , const int ,const int *, const ARRAY *);
ARRAY create_int_array(const int dimension,const  int *dimlist,const int value);
ARRAY create_float_array(const int dimension, const int *dimlist,const double value);
ARRAY create_string_array(const int dimension, const int *dimlist,const STRING *value);
kollo's avatar
kollo committed
15 16
ARRAY create_complex_array(const int dimension, const int *dimlist,const COMPLEX *value);
ARRAY create_arbint_array(const int dimension, const int *dimlist,ARBINT value);
kollo's avatar
kollo committed
17

kollo's avatar
kollo committed
18
ARRAY einheitsmatrix(const int ,const int ,const int *);
kollo's avatar
kollo committed
19
ARRAY array_const(const char *);
kollo's avatar
kollo committed
20 21
ARRAY double_array(const ARRAY *);
ARRAY einheitsmatrix(const int, const int, const int *);
kollo's avatar
kollo committed
22

kollo's avatar
kollo committed
23 24 25
ARRAY mul_array(ARRAY, ARRAY);
ARRAY trans_array(ARRAY);
ARRAY inv_array(ARRAY);
kollo's avatar
kollo committed
26 27
ARRAY convert_to_floatarray(const ARRAY *a);
ARRAY convert_to_intarray(const ARRAY *a);
kollo's avatar
kollo committed
28 29
ARRAY convert_to_complexarray(const ARRAY *a);
ARRAY convert_to_arbintarray(const ARRAY *a);
kollo's avatar
kollo committed
30
ARRAY get_subarray(ARRAY *arr,int *indexliste);
kollo's avatar
kollo committed
31
ARRAY convert_to_xarray(const ARRAY *a,int rt);
kollo's avatar
kollo committed
32 33 34 35 36

void array_add(ARRAY a1, ARRAY a2);
void array_sub(ARRAY a1, ARRAY a2);
void array_smul(ARRAY a1, double m);
void feed_array_and_free(int, ARRAY);
kollo's avatar
kollo committed
37 38 39
void free_array(ARRAY *arr);

/* Operieren auf Variablen */
kollo's avatar
kollo committed
40

kollo's avatar
kollo committed
41 42 43
void fill_string_array (const ARRAY *,const STRING );
void fill_int_array    (const ARRAY *,const int);
void fill_float_array  (const ARRAY *,const double);
kollo's avatar
kollo committed
44 45
void fill_complex_array  (const ARRAY *,const COMPLEX);
void fill_arbint_array  (const ARRAY *,const ARBINT);
kollo's avatar
kollo committed
46 47 48 49

STRING array_to_string(ARRAY inhalt);
ARRAY string_to_array(STRING in);
int make_indexliste(int dim, char *pos, int *index);
kollo's avatar
kollo committed
50 51 52 53 54 55
int check_indexliste(const ARRAY *a, const int *idx);
void anz2idx(int anz,const ARRAY *a,int *idx);


int    int_array_element   (const ARRAY *a, int *idx);
double float_array_element (const ARRAY *a, int *idx);
kollo's avatar
kollo committed
56
COMPLEX complex_array_element (const ARRAY *a, int *idx);
kollo's avatar
kollo committed
57 58
STRING string_array_element(const ARRAY *a, int *idx);
ARRAY  array_array_element (const ARRAY *a, int *idx);
kollo's avatar
kollo committed
59
void  arbint_array_element (const ARRAY *a, int *idx, ARBINT ret);
kollo's avatar
kollo committed
60

kollo's avatar
kollo committed
61

kollo's avatar
kollo committed
62
double array_det(const ARRAY *a);
kollo's avatar
kollo committed
63

64 65 66
int subarraydimf(int *,int);


kollo's avatar
kollo committed
67 68 69
/*  Kleinere Hilfsfunktionen als inline Makro*/


kollo's avatar
kollo committed
70
static inline int anz_eintraege(const ARRAY *a) {/* liefert Anzahl der Elemente in einem ARRAY */
kollo's avatar
kollo committed
71
  int anz=1,j;
kollo's avatar
kollo committed
72 73 74
  if(a->dimension>0 && a->pointer) {
    for(j=0;j<a->dimension;j++) anz=anz*((int *)a->pointer)[j];
  }
kollo's avatar
kollo committed
75 76 77
  return(anz);
}

kollo's avatar
kollo committed
78
static inline int do_dimension(const VARIABLE *v) {  /* liefert Anzahl der Elemente in einem ARRAY */
kollo's avatar
kollo committed
79 80 81 82 83 84
 /*  printf("DODIM?: vnr=%d \n",vnr); */
  if(v->typ & ARRAYTYP) return(anz_eintraege(v->pointer.a));
  else return(1);
}


kollo's avatar
kollo committed
85
static inline ARRAY nullmatrix(const int typ, const int dimension, const int *dimlist) {
kollo's avatar
kollo committed
86 87 88 89 90 91
  ARRAY ergebnis;
  if(typ & INTTYP)        ergebnis=create_int_array(dimension,dimlist,0);
  else if(typ & FLOATTYP) ergebnis=create_float_array(dimension,dimlist,0);
  else                    ergebnis=create_array(typ,dimension,dimlist);
  return(ergebnis);
}
kollo's avatar
kollo committed
92