//----------------------------------------------------------------------------- void MGL_EXPORT mgl_data_fill_eq(HMGL gr, HMDT d, const char *eq, HCDT vdat, HCDT wdat, const char *opt) { if(vdat && vdat->GetNN()!=d->GetNN()) return; // incompatible dimensions if(wdat && wdat->GetNN()!=d->GetNN()) return; gr->SaveState(opt); std::wstring s = d->Name(); d->Name(L"u"); mglDataV x(d->nx,d->ny,d->nz, gr->Min.x,gr->Max.x,'x'); x.Name(L"x"); mglDataV y(d->nx,d->ny,d->nz, gr->Min.y,gr->Max.y,'y'); y.Name(L"y"); mglDataV z(d->nx,d->ny,d->nz, gr->Min.z,gr->Max.z,'z'); z.Name(L"z"); mglDataV i(d->nx,d->ny,d->nz, 0,d->nx-1,'x'); i.Name(L"i"); mglDataV j(d->nx,d->ny,d->nz, 0,d->ny-1,'y'); j.Name(L"j"); mglDataV k(d->nx,d->ny,d->nz, 0,d->nz-1,'z'); k.Name(L"k"); mglDataV r(d->nx,d->ny,d->nz); r.Name(L"#$mgl"); mglData v(vdat), w(wdat); v.Name(L"v"); w.Name(L"w"); std::vector<mglDataA*> list; list.push_back(&x); list.push_back(&y); list.push_back(&z); list.push_back(&r); list.push_back(d); list.push_back(&v); list.push_back(&w); list.push_back(&i); list.push_back(&j); list.push_back(&k); d->Move(mglFormulaCalc(eq,list)); d->Name(s.c_str()); gr->LoadState(); }
//----------------------------------------------------------------------------- // convert substrings to arguments void mglParser::FillArg(mglGraph *gr, int k, std::wstring *arg, mglArg *a) { register long n; for(n=1;n<k;n++) { mglDataA *v; mglNum *f; a[n-1].type = -1; if(arg[n][0]=='|') a[n-1].type = -1; else if(arg[n][0]=='\'') // this is string (simplest case) { a[n-1].type = 1; std::wstring &w=arg[n],f; wchar_t buf[32]; long i,i1,ll=w.length(); for(i=1;i<ll;i++) { if(w[i]=='\'') { if(i==ll-1) continue; i++; i1 = i; if(w[i1]==',') i1++; if(w[i1]==0) continue; for(;i<ll && w[i]!='\'';i++); if(i>i1) { if(w[i1]=='!') { HADT d = mglFormulaCalcC(w.substr(i1+1,i-i1-(w[i]=='\''?1:0)), this, DataList); mreal di = imag(d->a[0]), dr = real(d->a[0]); if(di>0) mglprintf(buf,32,L"%g+%gi",dr,di); else if(di<0) mglprintf(buf,32,L"%g-%gi",dr,-di); // TODO use \u2212 ??? else mglprintf(buf,32,L"%g",dr); a[n-1].w += buf; delete d; } else { HMDT d = mglFormulaCalc(w.substr(i1,i-i1-(w[i]=='\''?1:0)), this, DataList); mglprintf(buf,32,L"%g",d->a[0]); a[n-1].w += buf; delete d; } } } else a[n-1].w += w[i]; } } else if(arg[n][0]=='{') { // this is temp data mglData *u=new mglData; std::wstring s = arg[n].substr(1,arg[n].length()-2); a[n-1].w = u->s = L"/*"+s+L"*/"; a[n-1].type = 0; ParseDat(gr, s, *u); a[n-1].d = u; u->temp=true; DataList.push_back(u); } else if((v = FindVar(arg[n].c_str()))!=0) // try to find normal variables (for data creation) { a[n-1].type=0; a[n-1].d=v; a[n-1].w=v->s; } else if((f = FindNum(arg[n].c_str()))!=0) // try to find normal number (for data creation) { a[n-1].type=2; a[n-1].d=0; a[n-1].v=f->d; a[n-1].c=f->c; a[n-1].w = f->s; } else if(arg[n][0]=='!') // complex array is asked { // parse all numbers and formulas by unified way HADT d = mglFormulaCalcC(arg[n].substr(1), this, DataList); if(d->GetNN()==1) { if(CheckForName(arg[n].substr(1))) { a[n-1].type = 2; a[n-1].v = d->v(0); a[n-1].c = d->a[0]; } else { a[n-1].type = 0; a[n-1].d = AddVar(arg[n].c_str()); } delete d; } else { a[n-1].w = L"/*"+arg[n]+L"*/"; d->temp=true; DataList.push_back(d); a[n-1].type = 0; a[n-1].d = d; } } else { // parse all numbers and formulas by unified way HMDT d = mglFormulaCalc(arg[n], this, DataList); if(d->GetNN()==1) { if(CheckForName(arg[n])) { a[n-1].type = 2; a[n-1].c = a[n-1].v = d->v(0); } else { a[n-1].type = 0; a[n-1].d = AddVar(arg[n].c_str()); } delete d; } else { a[n-1].w = L"/*"+arg[n]+L"*/"; d->temp=true; DataList.push_back(d); a[n-1].type = 0; a[n-1].d = d; } } } }