Beispiel #1
0
void CMSaveSimulation::AddOutputVariable(const CMString& name)
{
	maxnamelength = cmmax(maxnamelength, (int)name.length());
	unsigned n = array->VariableIndex(name);
	if (n < array->Variables())
		arrayindex.Add(new CMIndexAndValue(n, array->GetVariableState(n)));
	n = _accum->VariableIndex(name);
	if (n < _accum->Variables())
		accumindex.Add(new CMIndexAndValue(n, _accum->GetVariableState(n)));
}
Beispiel #2
0
int CMPolynomial::translate_variable_arg(const CMString& str,int& tok,CMString& s)
{
	enum {_t=0,_s,_i,_h,_d,_w,_m,_y};

	s = str;
	int i,len = str.length();

	tok = ArrayIndex;

	for (i=0;i<len && str[i]<=L' ';i++);

	if (i==len)
		return XBadIndex;

	if (str[i] == L'_') {
		int toktype = -1;
		if (i+1 >= len)
			return XBadIndex;
		switch (str[i+1]) {
			case L't': case L'T': toktype = _t; break;
			case L's': case L'S': toktype = _s; break;
			case L'i': case L'I': toktype = _i; break;
			case L'h': case L'H': toktype = _h; break;
			case L'd': case L'D': toktype = _d; break;
			case L'w': case L'W': toktype = _w; break;
			case L'm': case L'M': toktype = _m; break;
			case L'y': case L'Y': toktype = _y; break;
		}
		if (toktype>=0) {
			if (i+2 >= len)
				return XBadIndex;
			if (str[i+2]<=L' ' || str[i+2]==L'+' || str[i+2]==L'-') {
         	int j;
				for (j=i+2;j<len && str[j]<=L' ';j++);
				if (j>=len || !(str[j]==L'+' || str[j]==L'-'))
					return XBadIndex;
				if (str[j] == L'-')
					tok = Lag + toktype;
				else
					tok = Fwd + toktype;
				s = str.c_str()+(j+1);
			}
		}
	}
	return -1;
}