/** * \brief Main function in astro namespace */ int main(int argc, char *argv[]) { int c; double gamma = 1.0; double minimum = -1.; double maximum = -1.; bool force = false; // parse the command line int longindex; while (EOF != (c = getopt_long(argc, argv, "df?hm:M:g:", longopts, &longindex))) switch (c) { case 'd': debuglevel = LOG_DEBUG; break; case 'f': force = true; break; case 'g': gamma = std::stod(optarg); break; case 'm': minimum = std::stod(optarg); break; case 'M': maximum = std::stod(optarg); break; case '?': case 'h': usage(argv[0]); return EXIT_SUCCESS; break; default: throw std::runtime_error("unknown option"); } // two more arguments are required: infile and outfile if (2 != argc - optind) { std::string msg("wrong number of arguments"); debug(LOG_ERR, DEBUG_LOG, 0, "%s", msg.c_str()); throw std::runtime_error(msg); } std::string infilename(argv[optind++]); std::string outfilename(argv[optind]); debug(LOG_DEBUG, DEBUG_LOG, 0, "calibrate %s to %s", infilename.c_str(), outfilename.c_str()); // read the infile FITSin infile(infilename); ImagePtr image = infile.read(); // convert pixels according to luminance ConstPixelValueAdapter<double> from(image); // get the minimum and maximum values from the input image if (maximum < 0) { maximum = Max<double, double>()(from); } if (minimum < 0) { minimum = Min<double, double>()(from); } debug(LOG_DEBUG, DEBUG_LOG, 0, "min = %f, max = %f", minimum, maximum); // clamping filter ClampingAdapter<double, double> ca(from, minimum, maximum); // rescaling double scale = 1. / (maximum - minimum); RescalingAdapter<double> ra(ca, minimum, scale); // gamma correction GammaAdapter<double> ga(ra, gamma); // rescale back to the range 0-255 RescalingAdapter<double> ra2(ga, 0, 255.); // create image from last adapter Image<double> *outimage = new Image<double>(ra2); ImagePtr outimageptr(outimage); // remove previous file if (force) { unlink(outfilename.c_str()); } // after all the calibrations have been performed, write the output // file FITSout outfile(outfilename); outfile.write(outimageptr); // that's it return EXIT_SUCCESS; }
QString KStars::getDSSURL( double RA_J2000, double Dec_J2000, float width, float height ) { dms ra( RA_J2000 ), dec( Dec_J2000 ); return KSUtils::getDSSURL( ra, dec, width, height ); }
B jtxlinit(J jt){A x;I*s; GA(x,INT,20*LKC,2,0); s=AS(x); s[0]=20; s[1]=LKC; ra(x); jt->flkd=x; R 1; }
ParticleSystem::Ptr ParticleSystem::create(Particle::Type type, MessageBus& mb) { auto ps = std::make_unique<ParticleSystem>(mb); switch (type) { case Particle::Type::Trail: { const float scale = Util::Random::value(2.f, 4.f); ScaleAffector sa({ scale, scale }); ps->addAffector<ScaleAffector>(sa); ForceAffector fa({ 0.f, -190.f }); ps->addAffector<ForceAffector>(fa); ps->setEmitRate(Util::Random::value(0.5f, 2.5f)); ps->setBlendMode(sf::BlendAdd); ps->setEmitRate(3.f); ps->setRandomInitialVelocity(trailVelocities); ps->start(1u, Util::Random::value(0.2f, 1.f)); } break; case Particle::Type::Echo: { ScaleAffector sa({ 1.6f, 1.6f }); ps->addAffector<ScaleAffector>(sa); ps->setBlendMode(sf::BlendAdd); ps->setParticleLifetime(0.95f); ps->followParent(true); } break; case Particle::Type::Sparkle: { sparkPositions = createPoints(sf::Vector2f(), 20, 18.f); ps->setParticleLifetime(0.6f); ps->setParticleSize({ 10.f, 10.f }); ps->setRandomInitialVelocity(sparkVelocities); ps->setRandomInitialPosition(sparkPositions); ps->setBlendMode(sf::BlendAdd); ScaleAffector sa({ 2.f, 2.f }); ps->addAffector(sa); RotateAffector ra(140.f); ps->addAffector(ra); } break; case Particle::Type::Ident: { identPositions = createPoints({}, 20, 20.f); ps->setParticleLifetime(0.6f); ps->setParticleSize({ 20.f, 20.f }); ps->setInitialVelocity({ 0.f, 0.f }); ps->setRandomInitialPosition(identPositions); ps->setBlendMode(sf::BlendAdd); ps->followParent(true); ps->setEmitRate(7.f); ps->start(); } default: break; } return std::move(ps); }
int TotalLagrangianFD8NodeBrick::addInertiaLoadToUnbalance(const Vector &accel) { // Check for a quick return if (rho == 0.0) return 0; static Vector ra(NumElemDof); int i, j; for (i=0; i<NumNodes; i++) { const Vector &RA = theNodes[i]->getRV(accel); if ( RA.Size() != NumDof ) { opserr << "TotalLagrangianFD8NodeBrick::addInertiaLoadToUnbalance(): matrix and vector sizes are incompatable \n"; return (-1); } for (j=0; j<NumDof; j++) { ra(i*NumDof +j) = RA(j); } } this->getMass(); if (Q == 0) Q = new Vector(NumElemDof); Q->addMatrixVector(1.0, M, ra, -1.0); return 0; }
void static spam_ra(t_stack *stack, int min) { while ((stack->a_end->data != min && stack->number_in_a > 1) || (stack->a_begin->data != min && stack->number_in_a <= 1)) ra(stack, 1); }
QQuickStateOperation::ActionList QQuickParentChange::actions() { Q_D(QQuickParentChange); if (!d->target || !d->parent) return ActionList(); ActionList actions; QQuickAction a; a.event = this; actions << a; if (d->xString.isValid()) { bool ok = false; qreal x = d->xString.value.numberLiteral(&ok); if (ok) { QQuickAction xa(d->target, QLatin1String("x"), x); actions << xa; } else { QQmlBinding *newBinding = new QQmlBinding(d->xString.value, d->target, qmlContext(this)); QQmlProperty property(d->target, QLatin1String("x")); newBinding->setTarget(property); QQuickAction xa; xa.property = property; xa.toBinding = QQmlAbstractBinding::getPointer(newBinding); xa.fromValue = xa.property.read(); xa.deletableToBinding = true; actions << xa; } } if (d->yString.isValid()) { bool ok = false; qreal y = d->yString.value.numberLiteral(&ok); if (ok) { QQuickAction ya(d->target, QLatin1String("y"), y); actions << ya; } else { QQmlBinding *newBinding = new QQmlBinding(d->yString.value, d->target, qmlContext(this)); QQmlProperty property(d->target, QLatin1String("y")); newBinding->setTarget(property); QQuickAction ya; ya.property = property; ya.toBinding = QQmlAbstractBinding::getPointer(newBinding); ya.fromValue = ya.property.read(); ya.deletableToBinding = true; actions << ya; } } if (d->scaleString.isValid()) { bool ok = false; qreal scale = d->scaleString.value.numberLiteral(&ok); if (ok) { QQuickAction sa(d->target, QLatin1String("scale"), scale); actions << sa; } else { QQmlBinding *newBinding = new QQmlBinding(d->scaleString.value, d->target, qmlContext(this)); QQmlProperty property(d->target, QLatin1String("scale")); newBinding->setTarget(property); QQuickAction sa; sa.property = property; sa.toBinding = QQmlAbstractBinding::getPointer(newBinding); sa.fromValue = sa.property.read(); sa.deletableToBinding = true; actions << sa; } } if (d->rotationString.isValid()) { bool ok = false; qreal rotation = d->rotationString.value.numberLiteral(&ok); if (ok) { QQuickAction ra(d->target, QLatin1String("rotation"), rotation); actions << ra; } else { QQmlBinding *newBinding = new QQmlBinding(d->rotationString.value, d->target, qmlContext(this)); QQmlProperty property(d->target, QLatin1String("rotation")); newBinding->setTarget(property); QQuickAction ra; ra.property = property; ra.toBinding = QQmlAbstractBinding::getPointer(newBinding); ra.fromValue = ra.property.read(); ra.deletableToBinding = true; actions << ra; } } if (d->widthString.isValid()) { bool ok = false; qreal width = d->widthString.value.numberLiteral(&ok); if (ok) { QQuickAction wa(d->target, QLatin1String("width"), width); actions << wa; } else { QQmlBinding *newBinding = new QQmlBinding(d->widthString.value, d->target, qmlContext(this)); QQmlProperty property(d->target, QLatin1String("width")); newBinding->setTarget(property); QQuickAction wa; wa.property = property; wa.toBinding = QQmlAbstractBinding::getPointer(newBinding); wa.fromValue = wa.property.read(); wa.deletableToBinding = true; actions << wa; } } if (d->heightString.isValid()) { bool ok = false; qreal height = d->heightString.value.numberLiteral(&ok); if (ok) { QQuickAction ha(d->target, QLatin1String("height"), height); actions << ha; } else { QQmlBinding *newBinding = new QQmlBinding(d->heightString.value, d->target, qmlContext(this)); QQmlProperty property(d->target, QLatin1String("height")); newBinding->setTarget(property); QQuickAction ha; ha.property = property; ha.toBinding = QQmlAbstractBinding::getPointer(newBinding); ha.fromValue = ha.property.read(); ha.deletableToBinding = true; actions << ha; } } return actions; }
void main() { int sss,q,ll,gd=DETECT,p,gm,area,a=(450-(50*5)),d,cat=77,ch,dh,eh,t1,t2,t12,t22,len,cc,hh; char *str,*str1,*tim; initgraph(&gd,&gm,""); p=1; front(); dr: viewport(); q=menu(); if(q==3) { arun: hh=help(); if(hh==1) { how(); goto arun; } if(hh==2) { select(); goto arun; } if(hh==3) { credit(); goto arun; } if(hh==4) { design(); goto arun; } if(hh==5) goto dr; } if(q==2) { rr: ll=sivakumar(); if(ll==1) { p=m2(); goto rr; } if(ll==2) { a=speed(); viewport(); goto rr; } if(ll==3) { topscore(); goto rr; } if(ll==4) goto dr; } if(q==4) exit(0); if(q==1) { names(); hide(); viewport(); x[0]=85; x[1]=70; x[2]=55; x[3]=40; y[0]=y[1]=y[2]=y[3]=35; setcolor(4); rectangle(24,19,626,396); ra(); setcolor(15); setfillstyle(1,10); bar(32,32,43,43); area=imagesize(30,30,45,45); buff=malloc(area); getimage(30,30,45,45,buff); putimage(30,30,buff,XOR_PUT); setpos(0,0); setfillstyle(1,0); bar(100,100,500,350); prakash(p); level=p; putimage(40,35,buff,XOR_PUT); putimage(55,35,buff,XOR_PUT); putimage(70,35,buff,XOR_PUT); putimage(85,35,buff,XOR_PUT); textcolor(GREEN+BLINK); len=0; status("Game Play: Arrow keys Menu: Esc Pause (or) Play: Others key"); while(1) { sss=getpixel(5,5); if(sss!=0); { setfillstyle(SOLID_FILL,0); bar(0,0,15,15); } if(((i-4)%11==0)&&(bon==0)&&(len!=(i-4))) { len=(i-4); gettime(&t); bonous(); bon=1; t1=t.ti_sec; cc=10; } gettime(&t); if((t1!=t.ti_sec)&&(bon==1)) { cc--; t1=t.ti_sec; itoa(cc,tim,10); setfillstyle(SOLID_FILL,0); bar(470,0,530,18); outtextxy(500,0,tim); } if((cc==0)&&(bon==1)) { putimage(xc1,yc1,f2,XOR_PUT); bar(470,0,530,18); bon=0; } gotoxy(68,1); setcolor(6); itoa(score,str,10); setfillstyle(1,0); settextstyle(3,0,1); if(strcmp(str,str1)!=0) { bar(80,400,350,450); outtextxy(100,420,"Score : "); outtextxy(180,420,str); strcpy(str1,str); } if(kbhit()) { // ch=getch(); dh=getch(); cat=dh; } else { arrange(x,y,i); if(set==0) food(); if(cat!=dupli) cat=lock(cat,dupli); switch(cat) { case 72: if(y[1]==20) y[0]=380; else y[0]=y[1]-15; x[0]=x[1]; d=getpixel(x[0]+8,y[0]+8); if((d==10)||(d==14)) doctor(); if((d==4)&&(bon==1)) { i++; sound(1000); delay(90); nosound(); bon=0; score+=(cc*10); putimage(xc1,yc1,f2,XOR_PUT); putimage(x[0],y[0],buff,XOR_PUT); putimage(x[i],y[i],buff,XOR_PUT); setfillstyle(SOLID_FILL,0); bar(470,0,530,18); } else if(d==15) { i++; set=0; sound(800); delay(40); score+=bb; nosound(); putimage(x[0],y[0],buff,XOR_PUT); } else { putimage(x[0],y[0],buff,XOR_PUT); putimage(x[i-1],y[i-1],buff,XOR_PUT); } delay(a); break; case 80: if(y[1]==380) y[0]=20; else y[0]=y[1]+15; x[0]=x[1]; d=getpixel(x[0]+8,y[0]+8); if((d==10)||(d==14)) doctor(); if((d==4)&&(bon==1)) { i++; sound(1000); delay(90); nosound(); bon=0; score+=(cc*10); putimage(xc1,yc1,f2,XOR_PUT); putimage(x[0],y[0],buff,XOR_PUT); putimage(x[i],y[i],buff,XOR_PUT); setfillstyle(SOLID_FILL,0); bar(470,0,530,18); } else if(d==15) { i++; score+=bb; sound(800); delay(40); set=0; nosound(); putimage(x[0],y[0],buff,XOR_PUT); } else { putimage(x[0],y[0],buff,XOR_PUT); putimage(x[i-1],y[i-1],buff,XOR_PUT); } delay(a); break; case 75: if(x[1]==25) x[0]=610; else x[0]=x[1]-15; y[0]=y[1]; d=getpixel(x[0]+8,y[0]+8); if((d==10)||(d==14)) doctor(); if((d==4)&&(bon==1)) { i++; sound(1000); delay(90); nosound(); bon=0; score+=(cc*10); putimage(xc1,yc1,f2,XOR_PUT); putimage(x[0],y[0],buff,XOR_PUT); putimage(x[i],y[i],buff,XOR_PUT); setfillstyle(SOLID_FILL,0); bar(470,0,530,18); } else if(d==15) { i++; sound(800); delay(40); set=0; nosound(); score+=bb; putimage(x[0],y[0],buff,XOR_PUT); } else { putimage(x[0],y[0],buff,XOR_PUT); putimage(x[i-1],y[i-1],buff,XOR_PUT); } delay(a); break; case 77: if(x[1]==610) x[0]=25; else x[0]=x[1]+15; y[0]=y[1]; d=getpixel(x[0]+8,y[0]+8); if((d==10)||(d==14)) doctor(); if((d==4)&&(bon==1)) { i++; sound(1000); delay(90); nosound(); bon=0; score+=(cc*10); putimage(xc1,yc1,f2,XOR_PUT); putimage(x[0],y[0],buff,XOR_PUT); putimage(x[i],y[i],buff,XOR_PUT); setfillstyle(SOLID_FILL,0); bar(470,0,530,18); } else if(d==15) { i++; set=0; sound(800); delay(40); score+=bb; nosound(); putimage(x[0],y[0],buff,XOR_PUT); } else { putimage(x[0],y[0],buff,XOR_PUT); putimage(x[i-1],y[i-1],buff,XOR_PUT); } delay(a); break; case 27: goto dx; // break; } dupli=cat; } } } dx: call(); }
// Rationnel Rationnel& Rationnel::powFonction(const Entier& e){ Rationnel ra((int)pow(numerateur, e.GetVal()), (int)pow(denominateur, e.GetVal())); ra.Simplifier(); return ra; }
"%05d%05d %09.5lf %+09.5lf%6.1f%6.2f%5.2f%3d%2d%5s %c;%7.2f%4.0f"; static char *form10 = "%05d%05d %09.5lf %+09.5lf%6.1f%6.2f%5.2f%3d%2d%s %c;%7.2f%4.0f"; static char *form30 = "%05d%05d %09.5lf %+09.5lf%6.1f%6.2f%5.2f%3d%2d%5s%s %c;%7.2f%4.0f"; static char *form1 = "%05d%05d%s %s%6.1f%6.2f%5.2f%3d%2d%5s %c;%7.2f%4.0f"; static char *form11 = "%05d%05d%s %s%6.1f%6.2f%5.2f%3d%2d%s %c;%7.2f%4.0f"; static char *form31 = "%05d%05d%s %s%6.1f%6.2f%5.2f%3d%2d%5s%s %c;%7.2f%4.0f"; static char *formol = /* To get original GSC format */ "%05d%05d %09.5lf %+09.5lf %5.1f %5.2f %4.2f %2d %1d %s %1c"; static char *entete="\ GSC-id ra (2000) dec pos-e mag mag-e b c pl mu d' pa"; static char *entete10="\ GSC-id ra (2000) dec pos-e mag mag-e b c epoch mu d' pa"; static char *entete30="\ GSC-id ra (2000) dec pos-e mag mag-e b c pl epoch mu d' pa"; static char *entete1="\ GSC-id ra (2000) dec pos-e mag mag-e b c pl mu d' pa"; static char *entete11="\ GSC-id ra (2000) dec pos-e mag mag-e b c epoch mu d' pa"; static char *entete31="\ GSC-id ra (2000) dec pos-e mag mag-e b c pl epoch mu d' pa"; static char *entete2="\ GSC-id ra (2000) dec mag d' pa"; static char *entete3="\ GSC-id ra (2000) dec mag d' pa";
//private ParticleSystem& ParticleController::addSystem(Particle::Type type) { m_systems.emplace_back(type); ParticleSystem& particleSystem = m_systems.back(); switch (type) { case Particle::Type::Splat: { particleSystem.setTexture(m_textureResource.get("res/textures/particles/gear.png")); particleSystem.setNormalMap(m_textureResource.get("res/textures/particles/gear_normal.png")); particleSystem.setRandomInitialVelocity(splatVelocities); particleSystem.setShader(m_shaderResource.get(Shader::Type::Metal)); ForceAffector fa({ 0.f, 3500.f }); //gravity particleSystem.addAffector(fa); RotateAffector ra(380.f); particleSystem.addAffector(ra); ScaleAffector sa({ 5.5f, 5.5f }); particleSystem.addAffector(sa); } break; case Particle::Type::Splash: { particleSystem.setTexture(m_textureResource.get("res/textures/particles/water_splash.png")); particleSystem.setNormalMap( m_textureResource.get("res/textures/particles/water_splash_normal.png")); particleSystem.setShader(m_shaderResource.get(Shader::Type::WaterDrop)); particleSystem.setColour({ 96u, 172u, 222u, 190u }); particleSystem.setParticleLifetime(1.2f); particleSystem.setParticleSize({ 4.f, 9.f }); particleSystem.setRandomInitialVelocity(splashVelocities); ForceAffector fa({ 0.f, 1500.f }); //gravity particleSystem.addAffector(fa); ScaleAffector sa({ 1.f, 8.5f }); particleSystem.addAffector(sa); particleSystem.setBlendMode(sf::BlendAlpha); } break; case Particle::Type::Puff: particleSystem.setTexture(m_textureResource.get("res/textures/particles/dust_puff.png")); particleSystem.setShader(m_shaderResource.get(Shader::Type::FlatShaded)); particleSystem.setParticleLifetime(1.f); particleSystem.setParticleSize({ 10.f, 10.f }); particleSystem.setRandomInitialVelocity(puffVelocities); { ForceAffector fa({ 0.f, -20.f }); particleSystem.addAffector(fa); ScaleAffector sa({ 4.f, 2.f }); particleSystem.addAffector(sa); RotateAffector ra(40.f); particleSystem.addAffector(ra); } break; case Particle::Type::PlayerOneDie: //TODO p1 and p2 are rather similar.... { auto texture = m_textureResource.get("res/textures/particles/player_one_particle.png"); particleSystem.setTexture(m_textureResource.get("res/textures/particles/player_one_particle.png")); particleSystem.setShader(m_shaderResource.get(Shader::Type::FlatShaded)); particleSystem.setParticleLifetime(2.f); particleSystem.setParticleSize(sf::Vector2f(texture.getSize())); particleSystem.setInitialVelocity({ 12.f, -100.f }); ForceAffector fa({ 0.f, 20.f }); particleSystem.addAffector(fa); } break; case Particle::Type::PlayerTwoDie: { auto texture = m_textureResource.get("res/textures/particles/player_two_particle.png"); particleSystem.setTexture(m_textureResource.get("res/textures/particles/player_two_particle.png")); particleSystem.setShader(m_shaderResource.get(Shader::Type::FlatShaded)); particleSystem.setParticleLifetime(2.f); particleSystem.setParticleSize(sf::Vector2f(texture.getSize())); particleSystem.setInitialVelocity({ 12.f, -100.f }); ForceAffector fa({ 0.f, 20.f }); particleSystem.addAffector(fa); } break; case Particle::Type::Smoke: { particleSystem.setTexture(m_textureResource.get("res/textures/particles/dust_puff.png")); particleSystem.setShader(m_shaderResource.get(Shader::Type::FlatShaded)); particleSystem.setParticleLifetime(3.f); particleSystem.setParticleSize({ 10.f, 10.f }); particleSystem.setRandomInitialVelocity(smokeVelocities); particleSystem.setEmitRate(20.f); ForceAffector fa({ 10.f, -60.f }); particleSystem.addAffector(fa); ScaleAffector sa({ 10.f, 10.f }); particleSystem.addAffector(sa); RotateAffector ra(40.f); particleSystem.addAffector(ra); } break; case Particle::Type::Sparkle: particleSystem.setTexture(m_textureResource.get("res/textures/particles/sparkle.png")); particleSystem.setShader(m_shaderResource.get(Shader::Type::FlatShaded)); particleSystem.setParticleLifetime(0.5f); particleSystem.setParticleSize({ 10.f, 10.f }); particleSystem.setRandomInitialVelocity(sparkVelocities); { ForceAffector fa({ 0.f, 20.f }); particleSystem.addAffector(fa); ScaleAffector sa({ 2.f, 2.f }); particleSystem.addAffector(sa); RotateAffector ra(140.f); particleSystem.addAffector(ra); } break; default: break; } return particleSystem; }
//This function outputs Prno2Vreg after Dex register allocation. bool DexRegion::process(OptCtx * oc) { if (getIRList() == NULL) { return true; } OC_show_comp_time(*oc) = g_show_comp_time; g_indent = 0; if (!g_silence) { LOG("DexRegion process %s", getRegionName()); } //note("\n==---- REGION_NAME:%s ----==", getRegionName()); prescan(getIRList()); PassMgr * passmgr = initPassMgr(); HighProcess(*oc); MiddleProcess(*oc); ASSERT0(getPassMgr()); PRSSAMgr * ssamgr = (PRSSAMgr*)passmgr->queryPass(PASS_PR_SSA_MGR); if (ssamgr != NULL && ssamgr->isSSAConstructed()) { ssamgr->destruction(); } if (!g_retain_pass_mgr_for_region) { //Destroy PassMgr. destroyPassMgr(); } if (!is_function()) { return true; } /////////////////////////////////////// //DO NOT REQUEST PASS AFTER THIS LINE// /////////////////////////////////////// BBList * bbl = getBBList(); if (bbl->get_elem_count() == 0) { return true; } ASSERT0(verifyIRandBB(bbl, this)); RefineCtx rf; RC_insert_cvt(rf) = false; //Do not insert cvt for DEX code. refineBBlist(bbl, rf); ASSERT0(verifyIRandBB(bbl, this)); if (g_do_dex_ra) { Prno2Vreg * original_prno2vreg = getDex2IR()->getPR2Vreg(); RA ra(this, getTypeIndexRep(), getParamNum(), getOrgVregNum(), getDex2IR()->getVreg2PR(), original_prno2vreg, &m_var2pr); LOG("\t\tdo DEX Register Allcation for '%s'", getRegionName()); ra.perform(*oc); updateRAresult(ra, *getPrno2Vreg()); } else { //Do not allocate register. getPrno2Vreg()->clean(); getPrno2Vreg()->copy(*getDex2IR()->getPR2Vreg()); } return true; }
RZ(x=nfs(n,u)); LOCNAME(g)=x; LOCPATH(g)=ra(1==n&&'z'==*u?vec(BOX,0L,0L):zpath); symbis(x,g,jt->stloc); break; case 1: /* numbered locale */ ASSERT(0<=jt->stmax,EVLOCALE); sprintf(s,FMTI,n); RZ(x=nfs(strlen(s),s)); LOCNAME(g)=x; LOCPATH(g)=ra(zpath); ++jt->stused; m=AN(jt->stnum); if(m<jt->stused){ x=ext(1,jt->stnum); y=ext(1,jt->stptr); RZ(x&&y); jt->stnum=x; jt->stptr=y; nv=m+AV(jt->stnum); pv=m+AAV(jt->stptr); DO(AN(x)-m, *nv++=-1; *pv++=0;); } pv=AAV(jt->stptr); DO(AN(jt->stnum), if(!pv[i]){pv[i]=ra(g); *(i+AV(jt->stnum))=n; break;}); jt->stmax=n<IMAX?MAX(jt->stmax,1+n):-1; break; case 2: /* local symbol table */ ; } R g; } /* create locale, named (0==k) or numbered (1==k) */ B jtsymbinit(J jt){A q;I n=40; jt->locsize[0]=3; /* default hash table size for named locales */ jt->locsize[1]=2; /* default hash table size for numbered locales */ RZ(symext(0)); /* initialize symbol pool */ GA(q,SYMB,ptab[3],1,0); jt->stloc=q; RZ(q=apv(n,-1L,0L)); jt->stnum=q; GA(q,INT,n,1,0); jt->stptr=q; memset(AV(q),C0,n*SZI);
static float timeRendering(Options &options, const SbViewportRegion &vpr, SoSeparator *&root) // ////////////////////////////////////////////////////////////// { SbTime timeDiff, startTime; int frameIndex; SoTransform *sceneTransform; SoGLRenderAction ra(vpr); SoNodeList noCacheList; SoSeparator *newRoot; // clear the window glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // // reset autocaching threshold before each experiment // done by replacing every separator in the scene graph // with a new one // newRoot = (SoSeparator *) replaceSeparators(root); newRoot->ref(); newRoot->renderCaching = SoSeparator::OFF; // get a list of separators marked as being touched by the application newRoot->getByName(NO_CACHE_NAME, noCacheList); // find the transform node that spins the scene SoNodeList xformList; newRoot->getByName(SCENE_XFORM_NAME, xformList); sceneTransform = (SoTransform *) xformList[0]; if (options.noMaterials) { // nuke material node removeNodes(newRoot, SoMaterial::getClassTypeId()); removeNodes(newRoot, SoPackedColor::getClassTypeId()); removeNodes(newRoot, SoBaseColor::getClassTypeId()); } if (options.noXforms) { // nuke transforms removeNodes(newRoot, SoTransformation::getClassTypeId()); } if (options.noTextures || options.oneTexture) { // override texture node removeNodes(newRoot, SoTexture2::getClassTypeId()); if (options.oneTexture) { // texture node with simple texture static unsigned char img[] = { 255, 255, 0, 0, 255, 255, 0, 0, 0, 0, 255, 255, 0, 0, 255, 255 }; SoTexture2 *overrideTex = new SoTexture2; overrideTex->image.setValue(SbVec2s(4, 4), 1, img); newRoot->insertChild(overrideTex, 1); } } if (options.noFill) { // draw as points SoDrawStyle *overrideFill = new SoDrawStyle; overrideFill->style.setValue(SoDrawStyle::POINTS); overrideFill->lineWidth.setIgnored(TRUE); overrideFill->linePattern.setIgnored(TRUE); overrideFill->setOverride(TRUE); newRoot->insertChild(overrideFill, 0); // cull backfaces so that extra points don't get drawn SoShapeHints *cullBackfaces = new SoShapeHints; cullBackfaces->shapeType = SoShapeHints::SOLID; cullBackfaces->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE; cullBackfaces->setOverride(TRUE); newRoot->insertChild(cullBackfaces, 0); } if (options.noVtxXforms) { // draw invisible SoDrawStyle *overrideVtxXforms = new SoDrawStyle; overrideVtxXforms->style.setValue(SoDrawStyle::INVISIBLE); overrideVtxXforms->setOverride(TRUE); newRoot->insertChild(overrideVtxXforms, 0); } if (options.noLights) { // set lighting model to base color SoLightModel *baseColor = new SoLightModel; baseColor->model = SoLightModel::BASE_COLOR; newRoot->insertChild(baseColor, 0); } for (frameIndex = 0; ; frameIndex++) { // wait till autocaching has kicked in then start timing if (frameIndex == NUM_FRAMES_AUTO_CACHING) startTime = SbTime::getTimeOfDay(); // stop timing and exit loop when requisite number of // frames have been drawn if (frameIndex == options.numFrames + NUM_FRAMES_AUTO_CACHING) { glFinish(); timeDiff = SbTime::getTimeOfDay() - startTime; break; } // if not frozen, update realTime and destroy labelled caches if (! options.freeze) { // update realTime SoSFTime *realTime = (SoSFTime *) SoDB::getGlobalField("realTime"); realTime->setValue(SbTime::getTimeOfDay()); // touch the separators marked NoCache for (int i=0; i<noCacheList.getLength(); i++) ((SoSeparator *) noCacheList[i])->getChild(0)->touch(); } // Rotate the scene sceneTransform->rotation.setValue(SbVec3f(1, 1, 1), frameIndex * 2 * M_PI / options.numFrames); if (! options.noClear) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ra.apply(newRoot); } // Get rid of newRoot newRoot->unref(); return (timeDiff.getValue() / options.numFrames); }
/************************************************************************* Processing functions test *************************************************************************/ static void testprocessing(int nkind, int nin, int nhid1, int nhid2, int nout, int ec, int passcount, bool& err) { mlpensemble ensemble; mlpensemble ensemble2; bool zeronet; double a1; double a2; int pass; int i; bool allsame; int rlen; ap::real_1d_array x1; ap::real_1d_array x2; ap::real_1d_array y1; ap::real_1d_array y2; ap::real_1d_array ra; ap::real_1d_array ra2; double v; // // Prepare network // a1 = 0; a2 = 0; if( nkind==2 ) { a1 = 1000*ap::randomreal()-500; a2 = 2*ap::randomreal()-1; } if( nkind==3 ) { a1 = 1000*ap::randomreal()-500; a2 = a1+(2*ap::randominteger(2)-1)*(0.1+0.9*ap::randomreal()); } // // Initialize arrays // x1.setbounds(0, nin-1); x2.setbounds(0, nin-1); y1.setbounds(0, nout-1); y2.setbounds(0, nout-1); // // Main cycle // for(pass = 1; pass <= passcount; pass++) { createensemble(ensemble, nkind, a1, a2, nin, nhid1, nhid2, nout, ec); // // Same inputs leads to same outputs // for(i = 0; i <= nin-1; i++) { x1(i) = 2*ap::randomreal()-1; x2(i) = x1(i); } for(i = 0; i <= nout-1; i++) { y1(i) = 2*ap::randomreal()-1; y2(i) = 2*ap::randomreal()-1; } mlpeprocess(ensemble, x1, y1); mlpeprocess(ensemble, x2, y2); allsame = true; for(i = 0; i <= nout-1; i++) { allsame = allsame&&y1(i)==y2(i); } err = err||!allsame; // // Same inputs on original network leads to same outputs // on copy created using MLPCopy // unsetensemble(ensemble2); mlpecopy(ensemble, ensemble2); for(i = 0; i <= nin-1; i++) { x1(i) = 2*ap::randomreal()-1; x2(i) = x1(i); } for(i = 0; i <= nout-1; i++) { y1(i) = 2*ap::randomreal()-1; y2(i) = 2*ap::randomreal()-1; } mlpeprocess(ensemble, x1, y1); mlpeprocess(ensemble2, x2, y2); allsame = true; for(i = 0; i <= nout-1; i++) { allsame = allsame&&y1(i)==y2(i); } err = err||!allsame; // // Same inputs on original network leads to same outputs // on copy created using MLPSerialize // unsetensemble(ensemble2); mlpeserialize(ensemble, ra, rlen); ra2.setbounds(0, rlen-1); for(i = 0; i <= rlen-1; i++) { ra2(i) = ra(i); } mlpeunserialize(ra2, ensemble2); for(i = 0; i <= nin-1; i++) { x1(i) = 2*ap::randomreal()-1; x2(i) = x1(i); } for(i = 0; i <= nout-1; i++) { y1(i) = 2*ap::randomreal()-1; y2(i) = 2*ap::randomreal()-1; } mlpeprocess(ensemble, x1, y1); mlpeprocess(ensemble2, x2, y2); allsame = true; for(i = 0; i <= nout-1; i++) { allsame = allsame&&y1(i)==y2(i); } err = err||!allsame; // // Different inputs leads to different outputs (non-zero network) // for(i = 0; i <= nin-1; i++) { x1(i) = 2*ap::randomreal()-1; x2(i) = 2*ap::randomreal()-1; } for(i = 0; i <= nout-1; i++) { y1(i) = 2*ap::randomreal()-1; y2(i) = y1(i); } mlpeprocess(ensemble, x1, y1); mlpeprocess(ensemble, x2, y2); allsame = true; for(i = 0; i <= nout-1; i++) { allsame = allsame&&y1(i)==y2(i); } err = err||allsame; // // Randomization changes outputs (when inputs are unchanged, non-zero network) // for(i = 0; i <= nin-1; i++) { x1(i) = 2*ap::randomreal()-1; x2(i) = 2*ap::randomreal()-1; } for(i = 0; i <= nout-1; i++) { y1(i) = 2*ap::randomreal()-1; y2(i) = y1(i); } mlpecopy(ensemble, ensemble2); mlperandomize(ensemble2); mlpeprocess(ensemble, x1, y1); mlpeprocess(ensemble2, x1, y2); allsame = true; for(i = 0; i <= nout-1; i++) { allsame = allsame&&y1(i)==y2(i); } err = err||allsame; // // Normalization properties // if( nkind==1 ) { // // Classifier network outputs are normalized // for(i = 0; i <= nin-1; i++) { x1(i) = 2*ap::randomreal()-1; } mlpeprocess(ensemble, x1, y1); v = 0; for(i = 0; i <= nout-1; i++) { v = v+y1(i); err = err||y1(i)<0; } err = err||fabs(v-1)>1000*ap::machineepsilon; } if( nkind==2 ) { // // B-type network outputs are bounded from above/below // for(i = 0; i <= nin-1; i++) { x1(i) = 2*ap::randomreal()-1; } mlpeprocess(ensemble, x1, y1); for(i = 0; i <= nout-1; i++) { if( a2>=0 ) { err = err||y1(i)<a1; } else { err = err||y1(i)>a1; } } } if( nkind==3 ) { // // R-type network outputs are within [A1,A2] (or [A2,A1]) // for(i = 0; i <= nin-1; i++) { x1(i) = 2*ap::randomreal()-1; } mlpeprocess(ensemble, x1, y1); for(i = 0; i <= nout-1; i++) { err = err||y1(i)<ap::minreal(a1, a2)||y1(i)>ap::maxreal(a1, a2); } } } }
/***********************************************************************//** * @brief Read model from XML element * * @param[in] xml XML element. * * @exception GException::model_invalid_parnum * Invalid number of model parameters found in XML element. * @exception GException::model_invalid_parnames * Invalid model parameter names found in XML element. * * Reads the radial source location and position angle information from an * XML element in the following format * * <spatialModel type="..."> * <parameter name="RA" scale="1" value="83.63" min="-360" max="360" free="1"/> * <parameter name="DEC" scale="1" value="22.01" min="-90" max="90" free="1"/> * ... * </spatialModel> * * or * * <spatialModel type="..."> * <parameter name="GLON" scale="1" value="83.63" min="-360" max="360" free="1"/> * <parameter name="GLAT" scale="1" value="22.01" min="-90" max="90" free="1"/> * ... * </spatialModel> * ***************************************************************************/ void GModelSpatialRadial::read(const GXmlElement& xml) { // Determine number of parameter nodes in XML element int npars = xml.elements("parameter"); // Verify that XML element has at least 2 parameters if (xml.elements() < 2 || npars < 2) { throw GException::model_invalid_parnum(G_READ, xml, "Radial model requires at least 2 parameters."); } // Extract model parameters bool has_glon = false; bool has_glat = false; int npar[2] = {0, 0}; for (int i = 0; i < npars; ++i) { // Get parameter element const GXmlElement* par = xml.element("parameter", i); // Handle RA/GLON if (par->attribute("name") == "RA") { m_ra.read(*par); npar[0]++; } else if (par->attribute("name") == "GLON") { m_ra.read(*par); npar[0]++; has_glon = true; } // Handle DEC/GLAT else if (par->attribute("name") == "DEC") { m_dec.read(*par); npar[1]++; } else if (par->attribute("name") == "GLAT") { m_dec.read(*par); npar[1]++; has_glat = true; } } // endfor: looped over all parameters // Check if we have to convert GLON/GLAT into RA/DEC if (has_glon && has_glat) { GSkyDir dir; dir.lb_deg(ra(), dec()), m_ra.value(dir.ra_deg()); m_dec.value(dir.dec_deg()); } else if (has_glon || has_glat) { throw GException::model_invalid_parnames(G_READ, xml, "Require either \"RA\"/\"DEC\" or \"GLON\"/\"GLAT\"."); } // Verify that all parameters were found if (npar[0] != 1 || npar[1] != 1) { throw GException::model_invalid_parnames(G_READ, xml, "Require \"RA\"/\"DEC\" and \"GLON\"/\"GLAT\" parameters."); } // Return return; }
void ShearCatalog::writeFits(std::string file) const { Assert(int(_id.size()) == size()); Assert(int(_pos.size()) == size()); Assert(int(_sky.size()) == size()); Assert(int(_noise.size()) == size()); Assert(int(_flags.size()) == size()); Assert(int(_shear.size()) == size()); Assert(int(_nu.size()) == size()); Assert(int(_cov.size()) == size()); Assert(int(_meas_galorder.size()) == size()); Assert(int(_shape.size()) == size()); const int ngals = size(); bool output_psf = _params.read("shear_output_psf",false); // ! means overwrite existing file CCfits::FITS fits("!"+file, CCfits::Write); const int nFields= output_psf ? 20 : 17; std::vector<string> col_names(nFields); std::vector<string> col_fmts(nFields); std::vector<string> col_units(nFields); std::vector<BVec> interp_psf; if (output_psf) { Assert(_fitpsf); interp_psf.resize( ngals,BVec(_fitpsf->getPsfOrder(),_fitpsf->getSigma())); for(int i=0;i<ngals;++i) interp_psf[i] = (*_fitpsf)(_pos[i]); } col_names[0] = _params.get("shear_id_col"); col_names[1] = _params.get("shear_x_col"); col_names[2] = _params.get("shear_y_col"); col_names[3] = _params.get("shear_sky_col"); col_names[4] = _params.get("shear_noise_col"); col_names[5] = _params.get("shear_flags_col"); col_names[6] = _params.get("shear_ra_col"); col_names[7] = _params.get("shear_dec_col"); col_names[8] = _params.get("shear_shear1_col"); col_names[9] = _params.get("shear_shear2_col"); col_names[10] = _params.get("shear_nu_col"); col_names[11] = _params.get("shear_cov00_col"); col_names[12] = _params.get("shear_cov01_col"); col_names[13] = _params.get("shear_cov11_col"); col_names[14] = _params.get("shear_order_col"); col_names[15] = _params.get("shear_sigma_col"); col_names[16] = _params.get("shear_coeffs_col"); if (output_psf) { col_names[17] = _params.get("shear_psforder_col"); col_names[18] = _params.get("shear_psfsigma_col"); col_names[19] = _params.get("shear_psfcoeffs_col"); } col_fmts[0] = "1J"; // id col_fmts[1] = "1D"; // x col_fmts[2] = "1D"; // y col_fmts[3] = "1D"; // sky col_fmts[4] = "1D"; // noise col_fmts[5] = "1J"; // flags col_fmts[6] = "1D"; // ra col_fmts[7] = "1D"; // dec col_fmts[8] = "1D"; // shear1 col_fmts[9] = "1D"; // shear2 col_fmts[10] = "1D"; // nu col_fmts[11] = "1D"; // cov00 col_fmts[12] = "1D"; // cov01 col_fmts[13] = "1D"; // cov11 col_fmts[14] = "1J"; // order col_fmts[15] = "1D"; // sigma int ncoeff = _shape[0].size(); dbg<<"ncoeff = "<<ncoeff<<std::endl; col_fmts[16] = ConvertibleString(ncoeff) + "D"; // shapelet coeffs dbg<<"colfmts[16] = "<<col_fmts[16]<<std::endl; if (output_psf) { col_fmts[17] = "1J"; // psforder col_fmts[18] = "1D"; // psfsigma int npsf_coeff = interp_psf[0].size(); dbg<<"npsf_coeff = "<<npsf_coeff<<std::endl; col_fmts[19] = ConvertibleString(npsf_coeff) + "D"; // psf coeffs dbg<<"col_fmts[19] = "<<col_fmts[19]<<std::endl; } col_units[0] = "None"; // id col_units[1] = "Pixels"; // x col_units[2] = "Pixels"; // y col_units[3] = "ADU"; // sky col_units[4] = "ADU^2"; // noise col_units[5] = "None"; // flags col_units[6] = "Deg"; // ra col_units[7] = "Deg"; // dec col_units[8] = "None"; // shear1 col_units[9] = "None"; // shear2 col_units[10] = "None"; // nu col_units[11] = "None"; // cov00 col_units[12] = "None"; // cov01 col_units[13] = "None"; // cov11 col_units[14] = "None"; // order col_units[15] = "Arcsec";// sigma col_units[16] = "None"; // coeffs if (output_psf) { col_units[17] = "None"; // order col_units[18] = "Arcsec";// sigma col_units[19] = "None"; // coeffs } dbg<<"Before Create table"<<std::endl; CCfits::Table* table; table = fits.addTable("shearcat",ngals,col_names,col_fmts,col_units); // Header keywords #ifdef USE_TMV std::string tmvVers = tmv::TMV_Version(); #else std::string tmvVers = "Eigen"; #endif std::string wlVers = GetWlVersion(); table->addKey("tmvvers", tmvVers, "version of TMV code"); table->addKey("wlvers", wlVers, "version of weak lensing code"); std::string str; double dbl; int intgr; // if wlserun= is sent we'll put it in the header. This allows us to // associate some more, possibly complicated, metadata with this file if ( _params.keyExists("wlserun") ) { WriteParamToTable(_params, table, "wlserun", str); } WriteParamToTable(_params, table, "noise_method", str); WriteParamToTable(_params, table, "dist_method", str); WriteParamToTable(_params, table, "shear_aperture", dbl); WriteParamToTable(_params, table, "shear_max_aperture", dbl); WriteParamToTable(_params, table, "shear_gal_order", intgr); WriteParamToTable(_params, table, "shear_gal_order2", intgr); WriteParamToTable(_params, table, "shear_min_gal_size", dbl); WriteParamToTable(_params, table, "shear_f_psf", dbl); // data // make vector copies for writing std::vector<double> x(ngals); std::vector<double> y(ngals); std::vector<double> ra(ngals); std::vector<double> dec(ngals); std::vector<double> shear1(ngals); std::vector<double> shear2(ngals); std::vector<double> cov00(ngals); std::vector<double> cov01(ngals); std::vector<double> cov11(ngals); for(int i=0;i<ngals;++i) { x[i] = _pos[i].getX(); y[i] = _pos[i].getY(); // internally we use arcseconds ra[i] = _skypos[i].getX()/3600.; dec[i] = _skypos[i].getY()/3600.; shear1[i] = real(_shear[i]); shear2[i] = imag(_shear[i]); cov00[i] = _cov[i](0,0); cov01[i] = _cov[i](0,1); cov11[i] = _cov[i](1,1); } int startRow=1; table->column(col_names[0]).write(_id,startRow); table->column(col_names[1]).write(x,startRow); table->column(col_names[2]).write(y,startRow); table->column(col_names[3]).write(_sky,startRow); table->column(col_names[4]).write(_noise,startRow); table->column(col_names[5]).write(_flags,startRow); table->column(col_names[6]).write(ra,startRow); table->column(col_names[7]).write(dec,startRow); table->column(col_names[8]).write(shear1,startRow); table->column(col_names[9]).write(shear2,startRow); table->column(col_names[10]).write(_nu,startRow); table->column(col_names[11]).write(cov00,startRow); table->column(col_names[12]).write(cov01,startRow); table->column(col_names[13]).write(cov11,startRow); table->column(col_names[14]).write(_meas_galorder,startRow); for (int i=0; i<ngals; ++i) { int row = i+1; // MJ: meas_galorder keeps track of the order of the shapelet that // was actually measured. It is <= the full order of the shapelet // vector, but the higher order terms are set to zero. // Since we can't have different numbers of columns for each row, // we have to write out the full shapelet order for all rows // including the zeros. // //long border = _shape[i].getOrder(); //table->column(col_names[14]).write(&border,1,row); double bsigma = _shape[i].getSigma(); table->column(col_names[15]).write(&bsigma,1,row); // There is a bug in the CCfits Column::write function that the // first argument has to be S* rather than const S*, even though // it is only read from. // Hence the const_cast. double* ptr = const_cast<double*>(TMV_cptr(_shape[i].vec())); table->column(col_names[16]).write(ptr, ncoeff, 1, row); } if (output_psf) { for (int i=0; i<ngals; ++i) { int row = i+1; long psfOrder = interp_psf[i].getOrder(); double psfSigma = interp_psf[i].getSigma(); table->column(col_names[17]).write(&psfOrder,1,row); table->column(col_names[18]).write(&psfSigma,1,row); double* ptr = TMV_ptr(interp_psf[i].vec()); Assert(interp_psf[i].size() == interp_psf[0].size()); int npsf_coeff = interp_psf[i].size(); table->column(col_names[19]).write(ptr, npsf_coeff, 1, row); } } }