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
|
#include <stack-c.h>
int ex2c(double * a, int * ma, int * na,
double * b, int * mb, int * nb)
{
int i;
for (i = 0; i < (*ma) * (*na); i++)
{
a[i] = 2 * a[i];
}
for (i = 0; i < (*mb) * (*nb); i++)
{
b[i] = 3 * b[i];
}
return(0);
}
int sci_optional_parameters(char * fname)
{
int m1, n1, l1;
// optional names must be stored in alphabetical order in opts
static rhs_opts opts[] = {{ -1, "v1", "d", 0, 0, 0},
{ -1, "v2", "d", 0, 0, 0},
{ -1, NULL, NULL, 0, 0}
};
int minrhs = 1, maxrhs = 1;
int minlhs = 1, maxlhs = 3;
int nopt, iopos, res;
char buffer_name[csiz]; // csiz used for character coding
nopt = NumOpt();
CheckRhs(minrhs, maxrhs + nopt);
CheckLhs(minlhs, maxlhs);
// first non optional argument
GetRhsVar( 1, "c", &m1, &n1, &l1);
if (get_optionals(fname, opts) == 0)
{
return 0;
}
// default values if optional arguments are not given: v1=[99] and v2=[3]
sciprint("number of optional parameters = %d\n", NumOpt());
sciprint("first optional parameters = %d\n", FirstOpt());
sciprint("FindOpt(v1) = %d\n", FindOpt("v1", opts));
sciprint("FindOpt(v2) = %d\n", FindOpt("v2", opts));
if (IsOpt(1, buffer_name))
{
sciprint("parameter 1 is optional: %s\n", buffer_name);
}
if (IsOpt(2, buffer_name))
{
sciprint("parameter 2 is optional: %s\n", buffer_name);
}
if (IsOpt(3, buffer_name))
{
sciprint("parameter 3 is optional: %s\n", buffer_name);
}
iopos = Rhs;
if (opts[0].position == -1)
{
iopos++;
opts[0].position = iopos;
opts[0].m = 1;
opts[0].n = 1;
opts[0].type = "d";
CreateVar(opts[0].position, opts[0].type, &opts[0].m, &opts[0].n, &opts[0].l);
*stk(opts[0].l) = 99.0;
}
if (opts[1].position == -1)
{
iopos++ ;
opts[1].position = iopos;
opts[1].m = 1;
opts[1].n = 1;
opts[1].type = "d";
CreateVar(opts[1].position, opts[1].type, &opts[1].m, &opts[1].n, &opts[1].l);
*stk(opts[1].l) = 3;
}
ex2c(stk(opts[0].l), &opts[0].m, &opts[0].n,
stk(opts[1].l), &opts[1].m, &opts[1].n);
// return the first argument (unchanged ) then v1 and v2
LhsVar(1) = 1;
LhsVar(2) = opts[0].position;
LhsVar(3) = opts[1].position;
return 0;
}
|