/[ascend]/trunk/base/generic/packages/bisect.c
ViewVC logotype

Diff of /trunk/base/generic/packages/bisect.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1137 by johnpye, Fri Oct 27 07:18:21 2006 UTC revision 1138 by johnpye, Sun Jan 14 13:43:16 2007 UTC
# Line 13  Line 13 
13  #include <compiler/extcall.h>  #include <compiler/extcall.h>
14  #include "bisect.h"  #include "bisect.h"
15    
16  static int CheckArgTypes(struct gl_list_t *branch)  static int CheckArgTypes(struct gl_list_t *branch){
 {  
17    struct Instance *i;    struct Instance *i;
18    enum inst_t kind;    enum inst_t kind;
19    unsigned long len,c;    unsigned long len,c;
# Line 38  static int CheckArgTypes(struct gl_list_ Line 37  static int CheckArgTypes(struct gl_list_
37    return 0; /* all should be ok */    return 0; /* all should be ok */
38  }  }
39    
40  static int CheckArgVector(struct gl_list_t *branch)  static int CheckArgVector(struct gl_list_t *branch){
 {  
41    if (!branch) {    if (!branch) {
42      FPRINTF(stderr,"Empty arglists given\n");      FPRINTF(stderr,"Empty arglists given\n");
43      return 1;      return 1;
# Line 49  static int CheckArgVector(struct gl_list Line 47  static int CheckArgVector(struct gl_list
47    return 0;    return 0;
48  }  }
49    
50  /*********************************************************************\  /**
51   * This function expects 3 arguements; the calling protocol      This function expects 3 arguements; the calling protocol
52   * from ASCEND it expects to be invoked as:      from ASCEND it expects to be invoked as:
53   *  
54   * set_values(x1:array of generic_reals,      set_values(x1:array of generic_reals,
55   *            x2:array of generic_reals,                 x2:array of generic_reals,
56   *            m: generic_real);                 m: generic_real);
  *  
  * The dimension of both x1, and x2 are expected to be the same;  
  *  
 \*********************************************************************/  
57    
58  static int CheckArgs_SetValues(struct gl_list_t *arglist)      The dimension of both x1, and x2 are expected to be the same;
59  {  
60    */
61    static int CheckArgs_SetValues(struct gl_list_t *arglist){
62    struct gl_list_t *branch;    struct gl_list_t *branch;
63    unsigned long len, dim1, dim2;    unsigned long len, dim1, dim2;
64    char *error_msg = "all ok";    char *error_msg = "all ok";
# Line 113  static int CheckArgs_SetValues(struct gl Line 109  static int CheckArgs_SetValues(struct gl
109  }  }
110    
111    
112  int do_set_values_eval( struct Instance *i, struct gl_list_t *arglist)  int do_set_values_eval( struct Instance *i, struct gl_list_t *arglist, void *userdata){
 {  
113    unsigned long dimension,c;    unsigned long dimension,c;
114    struct gl_list_t *inputs, *outputs, *branch;    struct gl_list_t *inputs, *outputs, *branch;
115    double value,multiplier,calculated;    double value,multiplier,calculated;
# Line 141  int do_set_values_eval( struct Instance Line 136  int do_set_values_eval( struct Instance
136  }  }
137    
138    
139  /*********************************************************************\  /**
140   * This function expects 3 arguements; the calling protocol      This function expects 3 arguements; the calling protocol
141   * from ASCEND it expects to be invoked as:      from ASCEND it expects to be invoked as:
142   *  
143   * set_values(x1:array of generic_reals,      set_values(x1:array of generic_reals,
144   *            x2:array of generic_reals,                x2:array of generic_reals,
145   *             y:array of generic_reals);                 y:array of generic_reals);
146   *  
147   * The dimension of x1, x2 and y are expected to be the same;      The dimension of x1, x2 and y are expected to be the same;
  *  
 \*********************************************************************/  
148    
149  static int CheckArgs_Bisection(struct gl_list_t *arglist)  */
150  {  static int CheckArgs_Bisection(struct gl_list_t *arglist){
151    struct gl_list_t *branch;    struct gl_list_t *branch;
152    unsigned long len,c;    unsigned long len,c;
153    unsigned long dim1=0, dim2=0;    unsigned long dim1=0, dim2=0;
# Line 191  static int CheckArgs_Bisection(struct gl Line 184  static int CheckArgs_Bisection(struct gl
184    return 1;    return 1;
185  }  }
186    
187  int do_bisection_eval( struct Instance *i, struct gl_list_t *arglist)  int do_bisection_eval( struct Instance *i, struct gl_list_t *arglist, void *userdata){
 {  
188    unsigned long dimension,c;    unsigned long dimension,c;
189    struct gl_list_t *vector1, *vector2, *outputs;    struct gl_list_t *vector1, *vector2, *outputs;
190    double value1, value2, calculated;    double value1, value2, calculated;
# Line 216  int do_bisection_eval( struct Instance * Line 208  int do_bisection_eval( struct Instance *
208    return 0;    return 0;
209  }  }
210    
211  int Bisection (void)  int Bisection (void){
 {  
212    
213    char set_values_help[] =    char set_values_help[] =
214      "This function accepts 3 args, The first 2 arg vectors of equal\n\      "This function accepts 3 args, The first 2 arg vectors of equal\n"
215  length. The second is a multiplier to be applied to each element\n\      "length. The second is a multiplier to be applied to each element\n"
216  of the first vector to yield the second vector.\n\      "of the first vector to yield the second vector.\n"
217  Example: do_set_values(x[1..n], y[1..n], multiplier[1..n]).\n";      "Example: do_set_values(x[1..n], y[1..n], multiplier[1..n]).\n";
218    
219    char bisection_help[] =    char bisection_help[] =
220  "This function accepts 3 args, each of which must be vectors.\n\      "This function accepts 3 args, each of which must be vectors.\n"
221  It will bisect find the midpoint by bisection.\n\      "It will bisect find the midpoint by bisection.\n"
222  Example: do_bisection(x[1..n],x_par[1..n], y[1..n]). \n";      "Example: do_bisection(x[1..n],x_par[1..n], y[1..n]). \n";
223    
224    int result;    int result;
225    result = CreateUserFunctionMethod("do_set_values",    result = CreateUserFunctionMethod("do_set_values",
# Line 240  Example: do_bisection(x[1..n],x_par[1..n Line 231  Example: do_bisection(x[1..n],x_par[1..n
231    return result;    return result;
232  }  }
233    
 /*  
  * To compile for static linking do:  
  * gcc -c -I../compiler  -g -DHAVE_PACKAGES -o bisect.o bisect.c  
  *  
  * To compiler for dynamic linking do:  
  * gcc -c -I../compiler  -g -fpic -o bisect.o bisect.c  
  * ld -o libbisect.so.1.0 bisect.o  
  */  
   
   
   

Legend:
Removed from v.1137  
changed lines
  Added in v.1138

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22