Пример #1
0
 void Marshaller::marshal(Object* obj) {
   if(obj == Qnil) {
     stream << "n" << endl;
   } else if(obj == Qtrue) {
     stream << "t" << endl;
   } else if(obj == Qfalse) {
     stream << "f" << endl;
   } else if(obj->fixnum_p()) {
     set_int(obj);
   } else if(obj->symbol_p()) {
     set_symbol((Symbol*)obj);
   } else if(kind_of<Bignum>(obj)) {
     set_bignum(as<Bignum>(obj));
   } else if(kind_of<String>(obj)) {
     set_string(as<String>(obj));
   } else if(kind_of<SendSite>(obj)) {
     set_sendsite(as<SendSite>(obj));
   } else if(kind_of<Array>(obj)) {
     set_array(as<Array>(obj));
   } else if(kind_of<Tuple>(obj)) {
     set_tuple(as<Tuple>(obj));
   } else if(kind_of<Float>(obj)) {
     set_float(as<Float>(obj));
   } else if(kind_of<InstructionSequence>(obj)) {
     set_iseq(as<InstructionSequence>(obj));
   } else if(kind_of<CompiledMethod>(obj)) {
     set_cmethod(as<CompiledMethod>(obj));
   } else {
     Exception::type_error(state, "unknown object");
   }
 }
Пример #2
0
	value& value::operator=(const value& aOther) {
		switch (aOther.mType)
		{
		case CHAR_T:
			set_char(aOther.mChar);
			break;
		case BOOL_T:
			set_bool(aOther.mBool);
			break;
		case UNSIGNED_T:
			set_unsigned(aOther.mUnsigned);
			break;
		case SIGNED_T:
			set_signed(aOther.mSigned);
			break;
		case FLOAT_T:
			set_float(aOther.mFloat);
			break;
		case POINTER_T:
			set_pointer(aOther.mPointer);
			break;
		case STRING_T:
			set_string(*static_cast<const c_string*>(aOther.mPointer));
			break;
		case ARRAY_T:
			set_array(*static_cast<const container<value>*>(aOther.mPointer));
			break;
		case OBJECT_T:
			set_object(*static_cast<const std::map<c_string, value>*>(aOther.mPointer));
			break;
		default:
			break;
		}
		return *this;
	}
void main() {
	int *array;
	array = malloc(SIZE * sizeof(int));
	int value = 8888;
	set_array(array, value);
	print_array(array);
}
Пример #4
0
int main(int argc, char const *argv[])
{
	#define size 50
	#define r (size/2)
	double pi = 3.14159265359;
	double theta;
	char sqaure[size+1][size];
	int length = size*size;
	set_array((char *)sqaure,length);
	int x,y;
	for (int i = 0; i <= 100; i++)
	{
		theta = pi/(double)50*i;
		x = r + r*cos(theta);
		y = r + r*sin(theta);
		sqaure[x][y] = '*';
	}
	for (int i = 0; i < size; i+=2)   //quick fix,for print with doesn't match height.
	{
		for (int j = 0; j < size; j++)
		{
			printf("%c",sqaure[i][j]);
		}
		printf("\n");
	}
	return 0;
}
Пример #5
0
// put in new data, and put the command
void DispCmdTriangle::putdata(const float *p1, const float *p2, 
                              const float *p3, VMDDisplayList *dobj) {
  int i;
  float tmp1[3], tmp2[3], tmp3[3];  // precompute the normal for
  for (i=0; i<3; i++) {             //   faster drawings later
     tmp1[i] = p2[i] - p1[i];
     tmp2[i] = p3[i] - p2[i];
  }
  cross_prod( tmp3, tmp1, tmp2);  
  vec_normalize(tmp3);
  set_array(p1, p2, p3, tmp3, tmp3, tmp3, dobj);
}
Пример #6
0
long sort_testnm(int n, int m, void (*sort_func)(int*, int))
    {
    long t1, t2, t;
    int *a;
    a = set_array(a, n, m);
    t1 = get_tick();
    sort_func(a, n);
    t2 = get_tick();
    t = diff_tick(t1, t2);
    if (!is_sorted(a, n))
	t = -1;
    free(a);
    return t;
    }
Пример #7
0
/*
 * Parse the given string and find the array items in config file.
 *
 * @param context	The main context pointer
 * @param token  	The parse token value
 * @param rest   	String to parse
 * @return 0 and 1 for success and failure
 */
static int
parse_array(build_image_context *context, parse_token token, char *rest)
{
	u_int32_t index;
	u_int32_t value;

	assert(context != NULL);
	assert(rest != NULL);

	/* Parse the index. */
	rest = parse_u32(rest, &index);
	if (rest == NULL)
		return 1;

	/* Parse the closing bracket. */
	if (*rest != ']')
		return 1;
	rest++;

	/* Parse the equals sign.*/
	if (*rest != '=')
		return 1;
	rest++;

	/* Parse the value based on the field table. */
	switch (token) {
	case token_attribute:
		rest = parse_u32(rest, &value);
		break;
	case token_dev_type:
		rest = parse_enum(context,
				rest,
				s_devtype_table_t20,
				&value);
		break;

	default:
	/* Unknown token */
		return 1;
	}

	if (rest == NULL)
		return 1;

	/* Store the result. */
	return set_array(context, index, token, value);
}
Пример #8
0
void SignalFrame::insert( std::vector<std::string>& input )
{
  // extract:   variable_name:type=value   or   variable_name:array[type]=value1,value2
  boost::regex expression(  "([[:word:]]+)(\\:([[:word:]]+)(\\[([[:word:]]+)\\])?=(.*))?"  );
  boost::match_results<std::string::const_iterator> what;

  boost_foreach (const std::string& arg, input)
  {

    std::string name;
    std::string type;
    std::string subtype; // in case of array<type>
    std::string value;

    if (regex_search(arg,what,expression))
    {
      name=what[1];
      type=what[3];
      subtype=what[5];
      value=what[6];

      //CFinfo << name << ":" << type << (subtype.empty() ? std::string() : std::string("["+subtype+"]"))  << "=" << value << CFendl;

      if(type == "array")
      {
        set_array(name, subtype, value, " ; ");
      }
      else
      {
        set_option(name, type, value);
      }
    }
    else
      throw ParsingFailed(FromHere(), "Could not parse [" + arg + "].\n"+
                          "Format should be:\n"
                          " -  for simple types:  variable_name:type=value\n"
                          " -  for array types:   variable_name:array[type]=value1,value2\n"
                          "  with possible type: [bool,unsigned,integer,real,string,uri]");
  }
Пример #9
0
int
py_shader_param_set(PyShaderParamObject *self, PyObject *val)
{
	const struct ShaderParam *p = self->param;

	int ok = 0;
	if (PyObject_TypeCheck(val, &py_mat_type)) {
		ok = set_mat(p, val);
	} else if (PyObject_TypeCheck(val, &py_vec_type)) {
		ok = set_vec(p, val);
	} else if (PyFloat_Check(val)) {
		ok = set_float(p, val);
	} else if (PyLong_Check(val)) {
		ok = set_int(p, val);
	} else if (PyObject_TypeCheck(val, &py_array_type)) {
		ok = set_array(p, (PyArrayObject*)val);
	} else {
		PyErr_Format(
			PyExc_TypeError,
			"unsupported type '%s' for shader param '%s'",
			Py_TYPE(val)->tp_name,
			p->name
		);
		return 0;
	}

	if (!ok) {
		PyErr_Format(
			PyExc_RuntimeError,
			"failed to set shader param '%s'",
			p->name
		);
		error_print_tb();
		error_clear();
		return 0;
	}

	return 1;
}
Пример #10
0
void DispCmdTriangle::putdata(const float *p1, const float *p2,const float *p3,
			      const float *n1, const float *n2,const float *n3,
                              VMDDisplayList *dobj) {
  set_array(p1,p2,p3,n1,n2,n3,dobj);
}
Пример #11
0
/* Parse command line & set command arguments. Returns the index of
 * non-option arguments, -1 if there is an error.
 */
int
parse_args(const char **argv,
    int what,			/* OF_CMDLINE or OF_SET */
    bool *setargsp)
{
	static char cmd_opts[NELEM(options) + 5]; /* o:T:\0 */
	static char set_opts[NELEM(options) + 6]; /* A:o;s\0 */
	char set, *opts;
	const char *array = NULL;
	Getopt go;
	size_t i;
	int optc, sortargs = 0, arrayset = 0;

	/* First call? Build option strings... */
	if (cmd_opts[0] == '\0') {
		char *p = cmd_opts, *q = set_opts;

		/* see cmd_opts[] declaration */
		*p++ = 'o';
		*p++ = ':';
#if !defined(MKSH_SMALL) || defined(TIOCSCTTY)
		*p++ = 'T';
		*p++ = ':';
#endif
		/* see set_opts[] declaration */
		*q++ = 'A';
		*q++ = ':';
		*q++ = 'o';
		*q++ = ';';
		*q++ = 's';

		for (i = 0; i < NELEM(options); i++) {
			if (options[i].c) {
				if (options[i].flags & OF_CMDLINE)
					*p++ = options[i].c;
				if (options[i].flags & OF_SET)
					*q++ = options[i].c;
			}
		}
		*p = '\0';
		*q = '\0';
	}

	if (what == OF_CMDLINE) {
		const char *p = argv[0], *q;
		/* Set FLOGIN before parsing options so user can clear
		 * flag using +l.
		 */
		if (*p != '-')
			for (q = p; *q; )
				if (*q++ == '/')
					p = q;
		Flag(FLOGIN) = (*p == '-');
		opts = cmd_opts;
	} else if (what == OF_FIRSTTIME) {
		opts = cmd_opts;
	} else
		opts = set_opts;
	ksh_getopt_reset(&go, GF_ERROR|GF_PLUSOPT);
	while ((optc = ksh_getopt(argv, &go, opts)) != -1) {
		set = (go.info & GI_PLUS) ? 0 : 1;
		switch (optc) {
		case 'A':
			if (what == OF_FIRSTTIME)
				break;
			arrayset = set ? 1 : -1;
			array = go.optarg;
			break;

		case 'o':
			if (what == OF_FIRSTTIME)
				break;
			if (go.optarg == NULL) {
				/* lone -o: print options
				 *
				 * Note that on the command line, -o requires
				 * an option (ie, can't get here if what is
				 * OF_CMDLINE).
				 */
				printoptions(set);
				break;
			}
			i = option(go.optarg);
			if ((enum sh_flag)i == FARC4RANDOM) {
				warningf(true, "Do not use set ±o arc4random,"
				    " it will be removed in the next version"
				    " of mksh!");
				return (0);
			}
			if ((i != (size_t)-1) && set == Flag(i))
				/* Don't check the context if the flag
				 * isn't changing - makes "set -o interactive"
				 * work if you're already interactive. Needed
				 * if the output of "set +o" is to be used.
				 */
				;
			else if ((i != (size_t)-1) && (options[i].flags & what))
				change_flag((enum sh_flag)i, what, set);
			else {
				bi_errorf("%s: bad option", go.optarg);
				return (-1);
			}
			break;

#if !defined(MKSH_SMALL) || defined(TIOCSCTTY)
		case 'T':
			if (what != OF_FIRSTTIME)
				break;
#ifndef TIOCSCTTY
			errorf("no TIOCSCTTY ioctl");
#else
			change_flag(FTALKING, OF_CMDLINE, 1);
			chvt(go.optarg);
			break;
#endif
#endif

		case '?':
			return (-1);

		default:
			if (what == OF_FIRSTTIME)
				break;
			/* -s: sort positional params (AT&T ksh stupidity) */
			if (what == OF_SET && optc == 's') {
				sortargs = 1;
				break;
			}
			for (i = 0; i < NELEM(options); i++)
				if (optc == options[i].c &&
				    (what & options[i].flags)) {
					change_flag((enum sh_flag)i, what, set);
					break;
				}
			if (i == NELEM(options))
				internal_errorf("parse_args: '%c'", optc);
		}
	}
	if (!(go.info & GI_MINUSMINUS) && argv[go.optind] &&
	    (argv[go.optind][0] == '-' || argv[go.optind][0] == '+') &&
	    argv[go.optind][1] == '\0') {
		/* lone - clears -v and -x flags */
		if (argv[go.optind][0] == '-')
			Flag(FVERBOSE) = Flag(FXTRACE) = 0;
		/* set skips lone - or + option */
		go.optind++;
	}
	if (setargsp)
		/* -- means set $#/$* even if there are no arguments */
		*setargsp = !arrayset && ((go.info & GI_MINUSMINUS) ||
		    argv[go.optind]);

	if (arrayset && (!*array || *skip_varname(array, false))) {
		bi_errorf("%s: is not an identifier", array);
		return (-1);
	}
	if (sortargs) {
		for (i = go.optind; argv[i]; i++)
			;
		qsort(&argv[go.optind], i - go.optind, sizeof(void *),
		    xstrcmp);
	}
	if (arrayset)
		go.optind += set_array(array, arrayset > 0 ? true : false,
		    argv + go.optind);

	return (go.optind);
}
Пример #12
0
/*
 * Parse command line and set command arguments. Returns the index of
 * non-option arguments, -1 if there is an error.
 */
int
parse_args(const char **argv,
    /* OF_CMDLINE or OF_SET */
    int what,
    bool *setargsp)
{
	static const char cmd_opts[] =
#define SHFLAGS_NOT_SET
#define SHFLAGS_OPTCS
#include "sh_flags.gen"
#undef SHFLAGS_NOT_SET
	    ;
	static const char set_opts[] =
#define SHFLAGS_NOT_CMD
#define SHFLAGS_OPTCS
#include "sh_flags.gen"
#undef SHFLAGS_NOT_CMD
	    ;
	bool set;
	const char *opts;
	const char *array = NULL;
	Getopt go;
	size_t i;
	int optc, arrayset = 0;
	bool sortargs = false;
	bool fcompatseen = false;

	if (what == OF_CMDLINE) {
		const char *p = argv[0], *q;
		/*
		 * Set FLOGIN before parsing options so user can clear
		 * flag using +l.
		 */
		if (*p != '-')
			for (q = p; *q; )
				if (*q++ == '/')
					p = q;
		Flag(FLOGIN) = (*p == '-');
		opts = cmd_opts;
	} else if (what == OF_FIRSTTIME) {
		opts = cmd_opts;
	} else
		opts = set_opts;
	ksh_getopt_reset(&go, GF_ERROR|GF_PLUSOPT);
	while ((optc = ksh_getopt(argv, &go, opts)) != -1) {
		set = tobool(!(go.info & GI_PLUS));
		switch (optc) {
		case 'A':
			if (what == OF_FIRSTTIME)
				break;
			arrayset = set ? 1 : -1;
			array = go.optarg;
			break;

		case 'o':
			if (what == OF_FIRSTTIME)
				break;
			if (go.optarg == NULL) {
				/*
				 * lone -o: print options
				 *
				 * Note that on the command line, -o requires
				 * an option (ie, can't get here if what is
				 * OF_CMDLINE).
				 */
				printoptions(set);
				break;
			}
			i = option(go.optarg);
			if ((i == FPOSIX || i == FSH) && set && !fcompatseen) {
				/*
				 * If running 'set -o posix' or
				 * 'set -o sh', turn off the other;
				 * if running 'set -o posix -o sh'
				 * allow both to be set though.
				 */
				Flag(FPOSIX) = 0;
				Flag(FSH) = 0;
				fcompatseen = true;
			}
			if ((i != (size_t)-1) && (set ? 1U : 0U) == Flag(i))
				/*
				 * Don't check the context if the flag
				 * isn't changing - makes "set -o interactive"
				 * work if you're already interactive. Needed
				 * if the output of "set +o" is to be used.
				 */
				;
			else if ((i != (size_t)-1) && (OFF(i) & what))
				change_flag((enum sh_flag)i, what, set);
			else {
				bi_errorf("%s: %s", go.optarg, "bad option");
				return (-1);
			}
			break;

#ifdef KSH_CHVT_FLAG
		case 'T':
			if (what != OF_FIRSTTIME)
				break;
#ifndef KSH_CHVT_CODE
			errorf("no TIOCSCTTY ioctl");
#else
			change_flag(FTALKING, OF_CMDLINE, true);
			chvt(&go);
			break;
#endif
#endif

		case '?':
			return (-1);

		default:
			if (what == OF_FIRSTTIME)
				break;
			/* -s: sort positional params (AT&T ksh stupidity) */
			if (what == OF_SET && optc == 's') {
				sortargs = true;
				break;
			}
			for (i = 0; i < NELEM(options); i++)
				if (optc == OFC(i) &&
				    (what & OFF(i))) {
					change_flag((enum sh_flag)i, what, set);
					break;
				}
			if (i == NELEM(options))
				internal_errorf("parse_args: '%c'", optc);
		}
	}
	if (!(go.info & GI_MINUSMINUS) && argv[go.optind] &&
	    (argv[go.optind][0] == '-' || argv[go.optind][0] == '+') &&
	    argv[go.optind][1] == '\0') {
		/* lone - clears -v and -x flags */
		if (argv[go.optind][0] == '-') {
			Flag(FVERBOSE) = 0;
			change_xtrace(0, false);
		}
		/* set skips lone - or + option */
		go.optind++;
	}
	if (setargsp)
		/* -- means set $#/$* even if there are no arguments */
		*setargsp = !arrayset && ((go.info & GI_MINUSMINUS) ||
		    argv[go.optind]);

	if (arrayset) {
		const char *ccp = NULL;

		if (*array)
			ccp = skip_varname(array, false);
		if (!ccp || !(!ccp[0] || (ccp[0] == '+' && !ccp[1]))) {
			bi_errorf("%s: %s", array, "is not an identifier");
			return (-1);
		}
	}
	if (sortargs) {
		for (i = go.optind; argv[i]; i++)
			;
		qsort(&argv[go.optind], i - go.optind, sizeof(void *),
		    xstrcmp);
	}
	if (arrayset)
		go.optind += set_array(array, tobool(arrayset > 0),
		    argv + go.optind);

	return (go.optind);
}
Пример #13
0
/*--------------------------------------------------------------------------*/
int fuzzygridder2d(double *x, double *y, double *data, unsigned int n,
                   unsigned int nx, unsigned int ny,
                   double xmin, double xmax, double ymin, double ymax,
                   double *odata, double *norm, double wx, double wy,
                   int flags)
{
    double *gnorm;
    unsigned int offset, offsetx1, offsetx2, offsety1, offsety2;
    unsigned int ntot = nx * ny;  /* total number of points on the grid */
    unsigned int noutofbounds = 0;  /* number of points out of bounds */

    double fractionx, fractiony, dwx, dwy;  /* variables for the fuzzy part */
    double dx = delta(xmin, xmax, nx);
    double dy = delta(ymin, ymax, ny);

    unsigned int i, j, k;  /* loop indices */

    /* initialize data if requested */
    if (!(flags & NO_DATA_INIT)) {
        set_array(odata, ntot, 0.);
    }

    /* check if normalization array is passed */
    if (norm == NULL) {
        gnorm = malloc(sizeof(double) * (nx * ny));
        if (gnorm == NULL) {
            fprintf(stderr, "XU.FuzzyGridder2D(c): Cannot allocate memory for"
                            " normalization buffer!\n");
            return -1;
        }
        /* initialize memory for norm */
        set_array(gnorm, nx * ny, 0.);
    }
    else {
        if (flags & VERBOSE) {
            fprintf(stdout, "XU.FuzzyGridder2D(c): use user provided buffer "
                            "for normalization data\n");
        }
        gnorm = norm;
    }

    /* calculate the fuzzy spread in number of bin sizes */
    dwx = wx / dx;
    dwy = wy / dy;
    if (flags & VERBOSE) {
        fprintf(stdout, "XU.FuzzyGridder2D(c): fuzzyness: %f %f %f %f\n",
                wx, wy, dwx, dwy);
    }
    /* the master loop over all data points */
    for (i = 0; i < n; i++) {
        /* if data point is nan ignore it */
        if (!isnan(data[i])) {
            /* if the x and y values are outside the grids boundaries
             * continue with the next point */
            if ((x[i] < xmin) || (x[i] > xmax)) {
                noutofbounds++;
                continue;
            }
            if ((y[i] < ymin) || (y[i] > ymax)) {
                noutofbounds++;
                continue;
            }
            /* compute the linear offset and distribute the data to the bins */
            if ((x[i] - wx / 2.) <= xmin) {
                offsetx1 = 0;
            }
            else {
                offsetx1 = gindex(x[i] - wx / 2., xmin, dx);
            }
            offsetx2 = gindex(x[i] + wx / 2., xmin, dx);
            offsetx2 = offsetx2 < nx ? offsetx2 : nx - 1;
            if ((y[i] - wy / 2.) <= ymin) {
                offsety1 = 0;
            }
            else {
                offsety1 = gindex(y[i] - wy / 2., ymin, dy);
            }
            offsety2 = gindex(y[i] + wy / 2., ymin, dy);
            offsety2 = offsety2 < ny ? offsety2 : ny - 1;

            for(j = offsetx1; j <= offsetx2; j++) {
                if (offsetx1 == offsetx2) {
                    fractionx = 1.;
                }
                else if (j == offsetx1) {
                    fractionx = (j + 1 - (x[i] - wx / 2. - xmin + dx / 2.) / dx) / dwx;
                }
                else if (j == offsetx2) {
                    fractionx = ((x[i] + wx / 2. - xmin + dx / 2.) / dx - j) / dwx;
                }
                else {
                    fractionx = 1 / dwx;
                }

                for(k = offsety1; k <= offsety2; k++) {
                    if (offsety1 == offsety2) {
                        fractiony = 1.;
                    }
                    else if (k == offsety1) {
                        fractiony = (k + 1 - (y[i] - wy / 2. - ymin + dy / 2.) / dy) / dwy;
                    }
                    else if (k == offsety2) {
                        fractiony = ((y[i] + wy / 2. - ymin + dy / 2.) / dy - k) / dwy;
                    }
                    else {
                        fractiony = 1 / dwy;
                    }

                    offset = j * ny + k;
                    odata[offset] += data[i]*fractionx*fractiony;
                    gnorm[offset] += fractionx*fractiony;
                }
            }
        }
    }

    /* perform normalization */
    if (!(flags & NO_NORMALIZATION)) {
        if (flags & VERBOSE)
            fprintf(stdout, "XU.FuzzyGridder2D(c): perform normalization\n");

        for (i = 0; i < nx * ny; i++) {
            if (gnorm[i] > 1.e-16) {
                odata[i] = odata[i] / gnorm[i];
            }
        }
    }

    /* free the norm buffer if it has been locally allocated */
    if (norm == NULL) {
        free(gnorm);
    }

    /* warn the user in case more than half the data points where out
     * of the gridding area */
    if (noutofbounds > n / 2) {
        fprintf(stdout,"XU.FuzzyGridder2D(c): more than half of the datapoints"
                        " out of the data range, consider regridding with"
                        " extended range!\n");
    }

    return 0;
}
Пример #14
0
/*--------------------------------------------------------------------------*/
int gridder2d(double *x, double *y, double *data, unsigned int n,
              unsigned int nx, unsigned int ny,
              double xmin, double xmax, double ymin, double ymax,
              double *odata, double *norm, int flags)
{
    double *gnorm;
    unsigned int offset;
    unsigned int ntot = nx * ny;  /* total number of points on the grid */
    unsigned int noutofbounds = 0;  /* number of points out of bounds */

    double dx = delta(xmin, xmax, nx);
    double dy = delta(ymin, ymax, ny);

    unsigned int i;  /* loop index */

    /* initialize data if requested */
    if (!(flags & NO_DATA_INIT)) {
        set_array(odata, ntot, 0.);
    }

    /* check if normalization array is passed */
    if (norm == NULL) {
        gnorm = malloc(sizeof(double) * (nx * ny));
        if (gnorm == NULL) {
            fprintf(stderr, "XU.Gridder2D(c): Cannot allocate memory for "
                            "normalization buffer!\n");
            return -1;
        }
        /* initialize memory for norm */
        set_array(gnorm, nx * ny, 0.);
    }
    else {
        if (flags & VERBOSE) {
            fprintf(stdout, "XU.Gridder2D(c): use user provided buffer for "
                            "normalization data\n");
        }
        gnorm = norm;
    }

    /* the master loop over all data points */
    for (i = 0; i < n; i++) {
        /* if data point is nan ignore it */
        if (!isnan(data[i])) {
            /* if the x and y values are outside the grids boundaries
             * continue with the next point */
            if ((x[i] < xmin) || (x[i] > xmax)) {
                noutofbounds++;
                continue;
            }
            if ((y[i] < ymin) || (y[i] > ymax)) {
                noutofbounds++;
                continue;
            }
            /* compute the linear offset and set the data */
            offset = gindex(x[i], xmin, dx) * ny + gindex(y[i], ymin, dy);

            odata[offset] += data[i];
            gnorm[offset] += 1.;
        }
    }

    /* perform normalization */
    if (!(flags & NO_NORMALIZATION)) {
        if (flags & VERBOSE)
            fprintf(stdout, "XU.Gridder2D(c): perform normalization ...\n");

        for (i = 0; i < nx * ny; i++) {
            if (gnorm[i] > 1.e-16) {
                odata[i] = odata[i] / gnorm[i];
            }
        }
    }

    /* free the norm buffer if it has been locally allocated */
    if (norm == NULL) {
        free(gnorm);
    }

    /* warn the user in case more than half the data points where out
     * of the gridding area */
    if (noutofbounds > n / 2) {
        fprintf(stdout,"XU.Gridder2D(c): more than half of the datapoints out "
                        "of the data range, consider regridding with extended "
                        "range!\n");
    }

    return 0;
}
Пример #15
0
/* parse command line & set command arguments.  returns the index of
 * non-option arguments, -1 if there is an error.
 */
int
parse_args(char **argv,
        int     what,           /* OF_CMDLINE or OF_SET */
        int     *setargsp)
{
        static char cmd_opts[NELEM(options) + 3]; /* o:\0 */
        static char set_opts[NELEM(options) + 5]; /* Ao;s\0 */
        char *opts;
        char *array = (char *) 0;
        Getopt go;
        int i, optc, set, sortargs = 0, arrayset = 0;

        /* First call?  Build option strings... */
        if (cmd_opts[0] == '\0') {
                char *p, *q;

                /* see cmd_opts[] declaration */
                strlcpy(cmd_opts, "o:", sizeof cmd_opts);
                p = cmd_opts + strlen(cmd_opts);
                /* see set_opts[] declaration */
                strlcpy(set_opts, "A:o;s", sizeof set_opts);
                q = set_opts + strlen(set_opts);
                for (i = 0; i < NELEM(options); i++) {
                        if (options[i].c) {
                                if (options[i].flags & OF_CMDLINE)
                                        *p++ = options[i].c;
                                if (options[i].flags & OF_SET)
                                        *q++ = options[i].c;
                        }
                }
                *p = '\0';
                *q = '\0';
        }

        if (what == OF_CMDLINE) {
                opts = cmd_opts;
        } else
                opts = set_opts;
        ksh_getopt_reset(&go, GF_ERROR|GF_PLUSOPT);
        while ((optc = ksh_getopt(argv, &go, opts)) != -1) {
                set = (go.info & GI_PLUS) ? 0 : 1;
                switch (optc) {
                  case 'A':
                        arrayset = set ? 1 : -1;
                        array = go.optarg;
                        break;

                  case 'o':
                        if (go.optarg == (char *) 0) {
                                /* lone -o: print options
                                 *
                                 * Note that on the command line, -o requires
                                 * an option (ie, can't get here if what is
                                 * OF_CMDLINE).
                                 */
                                printoptions(set);
                                break;
                        }
                        i = option(go.optarg);
                        if (i >= 0 && set == Flag(i))
                                /* Don't check the context if the flag
                                 * isn't changing - makes "set -o interactive"
                                 * work if you're already interactive.  Needed
                                 * if the output of "set +o" is to be used.
                                 */
                                ;
                        else if (i >= 0 && (options[i].flags & what))
                                change_flag((enum sh_flag) i, what, set);
                        else {
                                bi_errorf("%s: bad option", go.optarg);
                                return -1;
                        }
                        break;

                  case '?':
                        return -1;

                  default:
                        /* -s: sort positional params (at&t ksh stupidity) */
                        if (what == OF_SET && optc == 's') {
                                sortargs = 1;
                                break;
                        }
                        for (i = 0; i < NELEM(options); i++)
                                if (optc == options[i].c
                                    && (what & options[i].flags))
                                {
                                        change_flag((enum sh_flag) i, what,
                                                set);
                                        break;
                                }
                        if (i == NELEM(options)) {
                                internal_errorf(1, "parse_args: `%c'", optc);
                                return -1; /* not reached */
                        }
                }
        }
        if (!(go.info & GI_MINUSMINUS) && argv[go.optind] &&
                (argv[go.optind][0] == '-' || argv[go.optind][0] == '+') &&
                argv[go.optind][1] == '\0')
        {
                /* lone - clears -v and -x flags */
                if (argv[go.optind][0] == '-' && !Flag(FPOSIX))
                        Flag(FVERBOSE) = Flag(FXTRACE) = 0;
                /* set skips lone - or + option */
                go.optind++;
        }
        if (setargsp)
                /* -- means set $#/$* even if there are no arguments */
                *setargsp = !arrayset && ((go.info & GI_MINUSMINUS) ||
                        argv[go.optind]);

        if (arrayset && (!*array || *skip_varname(array, false))) {
                bi_errorf("%s: is not an identifier", array);
                return -1;
        }
        if (sortargs) {
                for (i = go.optind; argv[i]; i++)
                        ;
                qsortp((void **) &argv[go.optind], (size_t) (i - go.optind),
                        xstrcmp);
        }
        if (arrayset) {
                set_array(array, arrayset, argv + go.optind);
                for (; argv[go.optind]; go.optind++)
                        ;
        }

        return go.optind;
}
Пример #16
0
int main()
{
   set_array(4);
}
Пример #17
0
	value::value(const container<value>& aValue) :
		mPointer(nullptr),
		mType(VOID_T)
	{
		set_array(aValue);
	}