Exemplo n.º 1
0
uint64_t Julian_Date_of_Year(float year)
{
    /* The function Julian_Date_of_Year calculates the Julian Date  */
    /* of Day 0.0 of {year}. This function is used to calculate the */
    /* Julian Date of any date by using Julian_Date_of_Year, DOY,   */
    /* and Fraction_of_Day. */

    /* Astronomical Formulae for Calculators, Jean Meeus, */
    /* pages 23-25. Calculate Julian Date of 0.0 Jan year */
    uint64_t out = 0LL;
    long A, B, i;
    float jdoy;
    year=year-1;
    i=year/100;
    printVar("i", i);
    A=i;
    i=A/4;
    B=2-A+i;
    printVar("B", B);
    i=365.25*year;
    i+=30.6001*14;
    printVar("i", i);
    printVar("B", B);
    out += i;
    out += B;
    return out;
}
Exemplo n.º 2
0
void DebugPrint::printVar(bool flag)
{
	//basically true or false.
	if(flag)
	{
		printVar("true");
	}
	else
	{
		printVar("false");
	}
}
Exemplo n.º 3
0
void printTle(PredicThirteen::tle_t *tle)
{
    printVar("Epoch", tle->epoch_year * 1000 + tle->epoch_day);
    printVar("Drag",tle->xndt2o);
    printVar("Drag2",tle->xndd6o);
    printVar("Bstar",tle->bstar);
    printVar("Inclination",tle->xincl);
    printVar("RA",tle->xnodeo);
    printVar("EO",tle->eo);
    printVar("Omega",tle->omegao);
    printVar("Xmo",tle->xmo);
    printVar("Xno",tle->xno);
}
Exemplo n.º 4
0
void DebugPrint::printVar(void* vector3,int vecType)
{
	Ogre::Vector3 tmpO;
	btVector3 tmpB;
	float x,y,z;
	switch(vecType)
	{
	case OGRE:
		tmpO = *((Ogre::Vector3*)vector3);
		x = tmpO.x;
		y = tmpO.y;
		z = tmpO.z;
		break;
	case BULLET:
		tmpB = *((btVector3*)vector3);
		x = tmpB.x();
		y = tmpB.y();
		z = tmpB.z();
		break;
	default:
		//invalid type, exit.
		return;
		break;
	};

	//convert numbers into string
	convStream << x;
	convStream << ",";
	convStream << y;
	convStream << ",";
	convStream << z;
	convString = convStream.str();
	printVar();
}
Exemplo n.º 5
0
PredicThirteen::geodetic_t PredicThirteen::calc(PredicThirteen::tle_t t){
    printTle(&t);
    DEBUG_PRINTLN("----------------------------------------");
    PredicThirteen::vector_t zero_vector={0,0,0,0};
    PredicThirteen::vector_t pos = zero_vector;
    PredicThirteen::vector_t vel = zero_vector;
    PredicThirteen::geodetic_t geo = {0,0,0,0};

    jul_utc = daynum +723244000000LL;
    jul_epoch=Julian_Date_of_Epoch(t.epoch_year, t.epoch_day);
    printUint64("TestNum", (uint64_t) 11118562939LL);
    printUint64("daynum", daynum);
    printUint64("jul_utc",jul_utc);
    printUint64("jul_epoch",jul_epoch);
    tsince =   ((jul_utc - jul_epoch)/1000000.0) * minday;


    select_ephemeris(&t);

    SGP4(tsince, &t, &pos, &vel);
    Convert_Sat_State(&pos, &vel);   
    Magnitude(&vel);        
    printVar("jul_utc", jul_utc);
    Calculate_LatLonAlt(jul_utc, &pos, &geo);
    printVector(&pos);
    printVector(&vel);
    printGeo(&geo);
    LAT = geo.lat;
    LON = geo.lon;
    Serial.print("LAT: ");
    Serial.println(LAT);
    Serial.print("LON: ");
    Serial.println(LON);
    return geo;
}
Exemplo n.º 6
0
void printVMarg(struct vmarg* arg){
	switch(arg->type){
		case label_a: printf("00, %d\t",arg->val);break; //	label_a
		case global_a: printf("01, %d:\t",arg->val);printVar(arg->val);break; //global_a
		case formal_a: printf("02, %d:\t",arg->val);printVar(arg->val);break; //formal_a
		case local_a: printf("03, %d:\t",arg->val);printVar(arg->val);break; //	local_a
		case number_a: printf("04, %d:\t",arg->val);printDouble(numConsts[arg->val]);break; //	number_a
		case string_a: printf("05, %d:%s\t",arg->val, stringConsts[arg->val]);break; //	string_a
		case bool_a: printf("06, %c\t",arg->val);break; //	bool_a
		case nil_a: /*printf("\t(nil_a)\t");*/break; //nil_a
		case userfunc_a: printf("08, %d:  %s\t",arg->val, userFuncs[arg->val].id);break; //	userfunc_a
		case libfunc_a: printf("09, %d:  %s\t",arg->val, namedLibfuncs[arg->val]);break; //	libfunc_a
		case retval_a: printf("10, retval\t");break; //	retval_a
		default: ;//printf("Asserting for arg->val=%d\n",arg->val);assert(0);
	}
}
Exemplo n.º 7
0
void DebugPrint::printVar(float num)
{
	//convert into string...
	convStream << num;
	convString = convStream.str();
	//conversion done, send to std::string overload
	printVar();
}
Exemplo n.º 8
0
// Converter para string para envio
unsigned char char_toString(unsigned char *dest, unsigned char *ptr){
	unsigned int i = 1;
	unsigned int j = 0;
	unsigned int index = 0;
		
	if( *ptr<0 ){ // por o sinal negativo
		*dest = '-';
		*ptr *= -1;
		++index;
	}
	index += printVar(*ptr, dest+index);
	++ptr;
	if( *ptr ){
		*( dest + index++ ) = '.';
		index += printVar(*ptr, dest+index);
	}
	return index;
}
Exemplo n.º 9
0
void DebugPrint::printVar(int integer)
{
	//convert into string.
	//clear the stream first.
	convStream.clear();
	convStream << integer;
	convString = convStream.str();
	//conversion done, moving on.
	printVar();	
}
Exemplo n.º 10
0
void select_ephemeris(PredicThirteen::tle_t *tle)
{
    /* Selects the apropriate ephemeris type to be used */
    /* for predictions according to the data in the TLE */
    /* It also processes values in the tle set so that  */
    /* they are apropriate for the sgp4/sdp4 routines   */

    float ao, xnodp, dd1, dd2, delo, temp, a1, del1, r1;

    /* Preprocess tle set */
    tle->xnodeo*=deg2rad;
    tle->omegao*=deg2rad;
    tle->xmo*=deg2rad;
    tle->xincl*=deg2rad;
    temp=twopi/minday/minday;
    tle->xno=tle->xno*temp*minday;
    printVar("xno", tle->xno);
    tle->xndt2o*=temp;
    tle->xndd6o=tle->xndd6o*temp/minday;
    tle->bstar/=ae;

    /* Period > 225 minutes is deep space */
    dd1=(xke/tle->xno);
    printVar("dd1", dd1);
    dd2=tothrd;
    a1=pow(dd1,dd2);
    r1=cos(tle->xincl);
    dd1=(1.0-tle->eo*tle->eo);
    temp=ck2*1.5f*(r1*r1*3.0-1.0)/pow(dd1,1.5);
    del1=temp/(a1*a1);
    ao=a1*(1.0-del1*(tothrd*.5+del1*(del1*1.654320987654321+1.0)));
    delo=temp/(ao*ao);
    xnodp=tle->xno/(delo+1.0);
    printVar("xnodp", xnodp);

    /* Select a deep-space/near-earth ephemeris */

    if (twopi/xnodp/minday>=0.15625)
        SetFlag(DEEP_SPACE_EPHEM_FLAG);
    else
        ClearFlag(DEEP_SPACE_EPHEM_FLAG);
}
Exemplo n.º 11
0
void printThreadVars(std::ostream& os, Thread thread){
  Goal goal = thread->parent;
  VarRecord r = goal->vars.ptr();
  while (r != 0 && r->vars != thread->vars) r = r->parent;
  if (r != 0){
    Schema s = r->inten->schema;
    for (int i = 0; i < s->varcount; i++){
      printVar(os, r->vars[i]);
    }
  }
}
Exemplo n.º 12
0
void printvar_(int * Nch) 
{ char fname[20];
  FILE*f;
  
  sprintf(fname,"%d.tmptxt",getpid());
  f=fopen(fname,"w");
  printVar(f);
  fclose(f);
  fortreread_(Nch,fname,strlen(fname));
  unlink(fname); 
}
Exemplo n.º 13
0
// Converter para string para envio
unsigned char float_toChar(unsigned char *dest, float *ptr, unsigned char precision){
	
	unsigned int index = 0;
	int v_int;
	
	v_int = *ptr;
	if( v_int<0 ){ // por o sinal negativo
		*dest = '-';
		v_int *= -1;
		++index;
	}
	index += printVar(v_int, dest+index);
	switch( precision ){
		case 0:
			break;
		case 1:
			precision = 0x0A; //10
			break;
		case 2:
			precision = 0x64; //100
			break;
		default:
			precision = 0;
	}
			
	v_int = (*ptr-v_int) * precision;
	if( v_int ){
		*( dest + index++ ) = '.';
		if( v_int>0 && v_int<10 && precision>10 ){
			while( precision>10 ){
				*( dest + index++ ) = '0';
				precision /= 10;
			}
			*( dest + index++ ) = v_int + '0';
		}
		else
			index += printVar(v_int, dest+index);
	}

	return index;
}
Exemplo n.º 14
0
void printChoices(std::ostream& os, Goal goal, Choice choice){
  if (choice == 0) return;
  printChoices(os, goal, choice->parent);
  os << iendl;
  // printThreadAt(os, choice->thread, choice->pc);
  Thread thread = choice->thread;
  os << thread->constr->name;
  os << ind;
  for (int i = 0; i < thread->inten->schema->varcount; i++){
    printVar(os, thread->vars[i]);
  }
  VarRecord r = goal->vars.ptr();
  while (r != 0 && r->index != choice->varmark)
    r = r->parent;
  if (r != 0){
    os << iendl << "choosen " << r->inten->schema->name << ind;
    for (int i = 0; i < r->inten->schema->varcount; i++){
      printVar(os, r->vars[i]);
    }
    os << unind;
  }
  os << unind;
} 
Exemplo n.º 15
0
void SGP4(float tsince, PredicThirteen::tle_t * tle, PredicThirteen::vector_t * pos, PredicThirteen::vector_t * vel)
{
    /* This function is used to calculate the position and velocity */
    /* of near-earth (period < 225 minutes) satellites. tsince is   */
    /* time since epoch in minutes, tle is a pointer to a tle_t     */
    /* structure with Keplerian orbital elements and pos and vel    */
    /* are vector_t structures returning ECI satellite position and */ 
    /* velocity. Use Convert_Sat_State() to convert to km and km/s. */

    static float aodp, aycof, c1, c4, c5, cosio, d2, d3, d4, delmo,
                 omgcof, eta, omgdot, sinio, xnodp, sinmo, t2cof, t3cof, t4cof,
                 t5cof, x1mth2, x3thm1, x7thm1, xmcof, xmdot, xnodcf, xnodot, xlcof;

    float cosuk, sinuk, rfdotk, vx, vy, vz, ux, uy, uz, xmy, xmx, cosnok,
          sinnok, cosik, sinik, rdotk, xinck, xnodek, uk, rk, cos2u, sin2u,
          u, sinu, cosu, betal, rfdot, rdot, r, pl, elsq, esine, ecose, epw,
          cosepw, x1m5th, xhdot1, tfour, sinepw, capu, ayn, xlt, aynl, xll,
          axn, xn, beta, xl, e, a, tcube, delm, delomg, templ, tempe, tempa,
          xnode, tsq, xmp, omega, xnoddf, omgadf, xmdf, a1, a3ovk2, ao,
          betao, betao2, c1sq, c2, c3, coef, coef1, del1, delo, eeta, eosq,
          etasq, perigee, pinvsq, psisq, qoms24, s4, temp, temp1, temp2,
          temp3, temp4, temp5, temp6, theta2, theta4, tsi;

    int i;

    DEBUG_PRINTLN("----------------------------------------");
    printTle(tle);


    /* Initialization */

    if (isFlagClear(SGP4_INITIALIZED_FLAG))
    {
        SetFlag(SGP4_INITIALIZED_FLAG);

        /* Recover original mean motion (xnodp) and   */
        /* semimajor axis (aodp) from input elements. */

        a1=pow(xke/tle->xno,tothrd);
        printVar("a1", a1);
        cosio=cos(tle->xincl);
        printVar("Tle->xincl", tle->xincl);
        theta2=cosio*cosio;
        x3thm1=3*theta2-1.0;
        printVar("theta2",theta2);
        printVar("cosio",cosio);
        eosq=tle->eo*tle->eo;
        betao2=1.0-eosq;
        betao=sqrt(betao2);
        del1=1.5*ck2*x3thm1/(a1*a1*betao*betao2);
        ao=a1*(1.0-del1*(0.5*tothrd+del1*(1.0+134.0/81.0*del1)));
        delo=1.5*ck2*x3thm1/(ao*ao*betao*betao2);
        xnodp=tle->xno/(1.0+delo);
        aodp=ao/(1.0-delo);

        printVar("aodp", aodp);
        DEBUG_PRINTLN("----------------------------------------");        


        /* For perigee less than 220 kilometers, the "simple"     */
        /* flag is set and the equations are truncated to linear  */
        /* variation in sqrt a and quadratic variation in mean    */
        /* anomaly.  Also, the c3 term, the delta omega term, and */
        /* the delta m term are dropped.                          */

        if ((aodp*(1-tle->eo)/ae)<(220/xkmper+ae))
            SetFlag(SIMPLE_FLAG);

        else
            ClearFlag(SIMPLE_FLAG);

        /* For perigees below 156 km, the      */
        /* values of s and qoms2t are altered. */

        s4=s;
        qoms24=qoms2t;
        perigee=(aodp*(1-tle->eo)-ae)*xkmper;
        printVar("perigee", perigee);

        if (perigee<156.0)
        {
            if (perigee<=98.0)
                s4=20;
            else
                s4=perigee-78.0;

            qoms24=pow((120-s4)*ae/xkmper,4);
            s4=s4/xkmper+ae;
        }
        DEBUG_PRINTLN("----------------------------------------");


        pinvsq=1/(aodp*aodp*betao2*betao2);
        tsi=1/(aodp-s4);
        eta=aodp*tle->eo*tsi;
        etasq=eta*eta;
        printVar("etasq",etasq);
        eeta=tle->eo*eta;
        psisq=fabs(1-etasq);
        coef=qoms24*pow(tsi,4);
        coef1=coef/pow(psisq,3.5);
        printVar("coef1",coef1);
        c2=coef1*xnodp*(aodp*(1+1.5*etasq+eeta*(4+etasq))+0.75*ck2*tsi/psisq*x3thm1*(8+3*etasq*(8+etasq)));
        printVar("xnodp", xnodp);
        printVar("etasq",etasq);
        printVar("eeta",eeta);
        printVar("ck2",ck2);
        printVar("tsi",tsi);
        printVar("psisq",psisq);
        printVar("x3thm1",x3thm1);
        printVar("c2",c2);
        c1=tle->bstar*c2;
        printVar("c1*1000000",c1*1000000);
        printVar("BSTAR: ", tle->bstar);
        sinio=sin(tle->xincl);
        a3ovk2=-xj3/ck2*pow(ae,3);
        c3=coef*tsi*a3ovk2*xnodp*ae*sinio/tle->eo;
        x1mth2=1-theta2;
        printVar("x1mth2", x1mth2);
        DEBUG_PRINTLN("----------------------------------------");
        DEBUG_PRINTLN("----------------------------------------");


        c4=2*xnodp*coef1*aodp*betao2*(eta*(2+0.5*etasq)+tle->eo*(0.5+2*etasq)-2*ck2*tsi/(aodp*psisq)*(-3*x3thm1*(1-2*eeta+etasq*(1.5-0.5*eeta))+0.75*x1mth2*(2*etasq-eeta*(1+etasq))*cos(2*tle->omegao)));
        c5=2*coef1*aodp*betao2*(1+2.75*(etasq+eeta)+eeta*etasq);

        theta4=theta2*theta2;
        temp1=3*ck2*pinvsq*xnodp;
        temp2=temp1*ck2*pinvsq;
        temp3=1.25*ck4*pinvsq*pinvsq*xnodp;
        xmdot=xnodp+0.5*temp1*betao*x3thm1+0.0625*temp2*betao*(13-78*theta2+137*theta4);
        x1m5th=1-5*theta2;
        omgdot=-0.5*temp1*x1m5th+0.0625*temp2*(7-114*theta2+395*theta4)+temp3*(3-36*theta2+49*theta4);
        xhdot1=-temp1*cosio;
        xnodot=xhdot1+(0.5*temp2*(4-19*theta2)+2*temp3*(3-7*theta2))*cosio;
        omgcof=tle->bstar*c3*cos(tle->omegao);
        xmcof=-tothrd*coef*tle->bstar*ae/eeta;
        xnodcf=3.5*betao2*xhdot1*c1;
        t2cof=1.5*c1;
        printVar("t2cof*1000000", t2cof*1000000);
        xlcof=0.125*a3ovk2*sinio*(3+5*cosio)/(1+cosio);
        aycof=0.25*a3ovk2*sinio;
        delmo=pow(1+eta*cos(tle->xmo),3);
        sinmo=sin(tle->xmo);
        x7thm1=7*theta2-1;
        printVar("x7thm1", x7thm1);

        if (isFlagClear(SIMPLE_FLAG))
        {
            c1sq=c1*c1;
            d2=4*aodp*tsi*c1sq;
            temp=d2*tsi*c1/3;
            d3=(17*aodp+s4)*temp;
            d4=0.5*temp*aodp*tsi*(221*aodp+31*s4)*c1;
            t3cof=d2+2*c1sq;
            t4cof=0.25*(3*d3+c1*(12*d2+10*c1sq));
            t5cof=0.2*(3*d4+12*c1*d3+6*d2*d2+15*c1sq*(2*d2+c1sq));
        }
    }

    /* Update for secular gravity and atmospheric drag. */
    xmdf=tle->xmo+xmdot*tsince;
    omgadf=tle->omegao+omgdot*tsince;
    xnoddf=tle->xnodeo+xnodot*tsince;
    omega=omgadf;
    xmp=xmdf;
    tsq=tsince*tsince;
    printVar("tsince*1000000", tsince*1000000);
    printVar("tsq", tsq);        

    xnode=xnoddf+xnodcf*tsq;
    tempa=1-c1*tsince;
    tempe=tle->bstar*c4*tsince;
    templ=t2cof*tsq;
    printVar("templ", templ);


    if (isFlagClear(SIMPLE_FLAG))
    {
        delomg=omgcof*tsince;
        delm=xmcof*(pow(1+eta*cos(xmdf),3)-delmo);
        temp=delomg+delm;
        xmp=xmdf+temp;
        omega=omgadf-temp;
        tcube=tsq*tsince;
        tfour=tsince*tcube;
        tempa=tempa-d2*tsq-d3*tcube-d4*tfour;
        tempe=tempe+tle->bstar*c5*(sin(xmp)-sinmo);
        templ=templ+t3cof*tcube+tfour*(t4cof+tsince*t5cof);
        printVar("templ", templ);
    }

    a=aodp*pow(tempa,2);
    e=tle->eo-tempe;
    xl=xmp+omega+xnode+xnodp*templ;
    beta=sqrt(1-e*e);
    xn=xke/pow(a,1.5);

    /* Long period periodics */
    axn=e*cos(omega);
    temp=1/(a*beta*beta);
    xll=temp*xlcof*axn;
    aynl=temp*aycof;
    xlt=xl+xll;
    ayn=e*sin(omega)+aynl;

    /* Solve Kepler's Equation */
    capu=FMod2p(xlt-xnode);
    temp2=capu;
    i=0;

    do
    {
        sinepw=sin(temp2);
        cosepw=cos(temp2);
        temp3=axn*sinepw;
        temp4=ayn*cosepw;
        temp5=axn*cosepw;
        temp6=ayn*sinepw;
        epw=(capu-temp4+temp3-temp2)/(1-temp5-temp6)+temp2;

        if (fabs(epw-temp2)<= e6a)
            break;

        temp2=epw;

    } while (i++<10);

    /* Short p2eriod preliminary quantities */
    ecose=temp5+temp6;
    esine=temp3-temp4;
    elsq=axn*axn+ayn*ayn;
    temp=1-elsq;
    pl=a*temp;
    r=a*(1-ecose);
    temp1=1/r;
    rdot=xke*sqrt(a)*esine*temp1;
    rfdot=xke*sqrt(pl)*temp1;
    temp2=a*temp1;
    betal=sqrt(temp);
    temp3=1/(1+betal);
    cosu=temp2*(cosepw-axn+ayn*esine*temp3);
    sinu=temp2*(sinepw-ayn-axn*esine*temp3);
    u=AcTan(sinu,cosu);
    sin2u=2*sinu*cosu;
    cos2u=2*cosu*cosu-1;
    temp=1/pl;
    temp1=ck2*temp;
    temp2=temp1*temp;

    /* Update for short periodics */
    rk=r*(1-1.5*temp2*betal*x3thm1)+0.5*temp1*x1mth2*cos2u;
    uk=u-0.25*temp2*x7thm1*sin2u;
    xnodek=xnode+1.5*temp2*cosio*sin2u;
    xinck=tle->xincl+1.5*temp2*cosio*sinio*cos2u;
    rdotk=rdot-xn*temp1*x1mth2*sin2u;
    rfdotk=rfdot+xn*temp1*(x1mth2*cos2u+1.5*x3thm1);

    /* Orientation vectors */
    sinuk=sin(uk);
    cosuk=cos(uk);
    sinik=sin(xinck);
    cosik=cos(xinck);
    sinnok=sin(xnodek);
    cosnok=cos(xnodek);
    xmx=-sinnok*cosik;
    xmy=cosnok*cosik;
    ux=xmx*sinuk+cosnok*cosuk;
    uy=xmy*sinuk+sinnok*cosuk;
    uz=sinik*sinuk;
    vx=xmx*cosuk-cosnok*sinuk;
    vy=xmy*cosuk-sinnok*sinuk;
    vz=sinik*cosuk;

    /* Position and velocity */
    pos->x=rk*ux;
    pos->y=rk*uy;
    pos->z=rk*uz;
    vel->x=rdotk*ux+rfdotk*vx;
    vel->y=rdotk*uy+rfdotk*vy;
    vel->z=rdotk*uz+rfdotk*vz;

    DEBUG_PRINTLN("----------------------------------------");
    DEBUG_PRINT("Position: ");
    printVector(pos);
    DEBUG_PRINT("Velocity; ");
    printVector(vel);

    /* Phase in radians */
    phase=xlt-xnode-omgadf+twopi;

    if (phase<0.0)
        phase+=twopi;

    phase=FMod2p(phase);
}
Exemplo n.º 16
0
int printModelInfo(DATA *data, const char *filename, const char *plotfile, const char *plotFormat, const char *method, const char *outputFormat, const char *outputFilename)
{
  static char buf[256];
  FILE *fout = fopen(filename, "w");
  FILE *plotCommands;
  time_t t;
  int i;
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(NO_PIPE)
  plotCommands = fopen(plotfile, "w");
#else
  plotCommands = popen("gnuplot", "w");
#endif
  if(!plotCommands)
    WARNING1(LOG_UTIL, "Plots of profiling data were disabled: %s\n", strerror(errno));

  ASSERT2(fout, "Failed to open %s: %s\n", filename, strerror(errno));

  if(plotCommands) {
    fputs("set terminal svg\n", plotCommands);
    fputs("set nokey\n", plotCommands);
    fputs("set format y \"%g\"\n", plotCommands);
    /* The column containing the time spent to calculate each step */
    printPlotCommand(plotCommands, plotFormat, "Execution time of global steps", data->modelData.modelFilePrefix, data->modelData.modelDataXml.nFunctions+data->modelData.modelDataXml.nProfileBlocks, -1, 999, "");
  }
  /* The doctype is needed for id() lookup to work properly */
  fprintf(fout, "<!DOCTYPE doc [\
  <!ELEMENT simulation (modelinfo, variables, functions, equations)>\
  <!ATTLIST variable id ID #REQUIRED>\
  <!ELEMENT equation (refs)>\
  <!ATTLIST equation id ID #REQUIRED>\
  <!ELEMENT profileblocks (profileblock*)>\
  <!ELEMENT profileblock (refs, ncall, time, maxTime)>\
  <!ELEMENT refs (ref*)>\
  <!ATTLIST ref refid IDREF #REQUIRED>\
  ]>\n");
  if(time(&t) < 0)
  {
    WARNING1(LOG_UTIL, "time() failed: %s", strerror(errno));
    fclose(fout);
    return 1;
  }
  if(!strftime(buf, 250, "%Y-%m-%d %H:%M:%S", localtime(&t)))
  {
    WARNING(LOG_UTIL, "strftime() failed");
    fclose(fout);
    return 1;
  }
  fprintf(fout, "<simulation>\n");
  fprintf(fout, "<modelinfo>\n");
  indent(fout, 2); fprintf(fout, "<name>");printStrXML(fout,data->modelData.modelName);fprintf(fout,"</name>\n");
  indent(fout, 2); fprintf(fout, "<prefix>");printStrXML(fout,data->modelData.modelFilePrefix);fprintf(fout,"</prefix>\n");
  indent(fout, 2); fprintf(fout, "<date>");printStrXML(fout,buf);fprintf(fout,"</date>\n");
  indent(fout, 2); fprintf(fout, "<method>");printStrXML(fout,data->simulationInfo.solverMethod);fprintf(fout,"</method>\n");
  indent(fout, 2); fprintf(fout, "<outputFormat>");printStrXML(fout,data->simulationInfo.outputFormat);fprintf(fout,"</outputFormat>\n");
  indent(fout, 2); fprintf(fout, "<outputFilename>");printStrXML(fout,outputFilename);fprintf(fout,"</outputFilename>\n");
  indent(fout, 2); fprintf(fout, "<outputFilesize>%ld</outputFilesize>\n", (long) fileSize(outputFilename));
  indent(fout, 2); fprintf(fout, "<overheadTime>%f</overheadTime>\n", rt_accumulated(SIM_TIMER_OVERHEAD));
  indent(fout, 2); fprintf(fout, "<preinitTime>%f</preinitTime>\n", rt_accumulated(SIM_TIMER_PREINIT));
  indent(fout, 2); fprintf(fout, "<initTime>%f</initTime>\n", rt_accumulated(SIM_TIMER_INIT));
  indent(fout, 2); fprintf(fout, "<eventTime>%f</eventTime>\n", rt_accumulated(SIM_TIMER_EVENT));
  indent(fout, 2); fprintf(fout, "<outputTime>%f</outputTime>\n", rt_accumulated(SIM_TIMER_OUTPUT));
  indent(fout, 2); fprintf(fout, "<linearizeTime>%f</linearizeTime>\n", rt_accumulated(SIM_TIMER_LINEARIZE));
  indent(fout, 2); fprintf(fout, "<totalTime>%f</totalTime>\n", rt_accumulated(SIM_TIMER_TOTAL));
  indent(fout, 2); fprintf(fout, "<totalStepsTime>%f</totalStepsTime>\n", rt_total(SIM_TIMER_STEP));
  indent(fout, 2); fprintf(fout, "<numStep>%d</numStep>\n", (int) rt_ncall_total(SIM_TIMER_STEP));
  indent(fout, 2); fprintf(fout, "<maxTime>%.9f</maxTime>\n", rt_max_accumulated(SIM_TIMER_STEP));
  fprintf(fout, "</modelinfo>\n");

  fprintf(fout, "<modelinfo_ext>\n");
  indent(fout, 2); fprintf(fout, "<odeTime>%f</odeTime>\n", rt_accumulated(SIM_TIMER_FUNCTION_ODE));
  indent(fout, 2); fprintf(fout, "<odeTimeTicks>%lu</odeTimeTicks>\n", rt_ncall(SIM_TIMER_FUNCTION_ODE));
  fprintf(fout, "</modelinfo_ext>\n");

  fprintf(fout, "<profilingdataheader>\n");
  printProfilingDataHeader(fout, data);
  fprintf(fout, "</profilingdataheader>\n");

  fprintf(fout, "<variables>\n");
  for(i=0;i<data->modelData.nVariablesReal;++i){
    printVar(fout, 2, &(data->modelData.realVarsData[i].info));
  }
  for(i=0;i<data->modelData.nParametersReal;++i){
    printVar(fout, 2, &data->modelData.realParameterData[i].info);
  }
  for(i=0;i<data->modelData.nVariablesInteger;++i){
    printVar(fout, 2, &data->modelData.integerVarsData[i].info);
  }
  for(i=0;i<data->modelData.nParametersInteger;++i){
    printVar(fout, 2, &data->modelData.integerParameterData[i].info);
  }
  for(i=0;i<data->modelData.nVariablesBoolean;++i){
    printVar(fout, 2, &data->modelData.booleanVarsData[i].info);
  }
  for(i=0;i<data->modelData.nParametersBoolean;++i){
    printVar(fout, 2, &data->modelData.booleanParameterData[i].info);
  }
  for(i=0;i<data->modelData.nVariablesString;++i){
    printVar(fout, 2, &data->modelData.stringVarsData[i].info);
  }
  for(i=0;i<data->modelData.nParametersString;++i){
    printVar(fout, 2, &data->modelData.stringParameterData[i].info);
  }
  fprintf(fout, "</variables>\n");

  fprintf(fout, "<functions>\n");
  printFunctions(fout, plotCommands, plotFormat, data->modelData.modelFilePrefix, data);
  fprintf(fout, "</functions>\n");

  fprintf(fout, "<equations>\n");
  printEquations(fout, data->modelData.modelDataXml.nEquations, &data->modelData.modelDataXml);
  fprintf(fout, "</equations>\n");

  fprintf(fout, "<profileblocks>\n");
  printProfileBlocks(fout, plotCommands, plotFormat, data);
  fprintf(fout, "</profileblocks>\n");

  fprintf(fout, "</simulation>\n");

  fclose(fout);
  if(plotCommands) {
    const char *omhome = data->simulationInfo.OPENMODELICAHOME;
    char *buf = NULL;
    int genHtmlRes;
    buf = (char*)malloc(230 + 2*strlen(plotfile) + 2*(omhome ? strlen(omhome) : 0));
    assert(buf);
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(NO_PIPE)
    if(omhome) {
#if defined(__MINGW32__) || defined(_MSC_VER)
      sprintf(buf, "%s/lib/omc/libexec/gnuplot/binary/gnuplot.exe %s", omhome, plotfile);
#else
      sprintf(buf, "gnuplot %s", plotfile);
#endif
      fclose(plotCommands);
      if(0 != system(buf)) {
        WARNING1(LOG_UTIL, "Plot command failed: %s\n", buf);
      }
    }
#else
    if(0 != pclose(plotCommands)) {
      WARNING(LOG_UTIL, "Warning: Plot command failed\n");
    }
#endif
    if(omhome)
    {
#if defined(__MINGW32__) || defined(_MSC_VER)
      char *xsltproc;
      sprintf(buf, "%s/lib/omc/libexec/xsltproc/xsltproc.exe", omhome);
      xsltproc = strdup(buf);
#else
      const char *xsltproc = "xsltproc";
#endif
      sprintf(buf, "%s -o %s_prof.html %s/share/omc/scripts/default_profiling.xsl %s_prof.xml", xsltproc, data->modelData.modelFilePrefix, omhome, data->modelData.modelFilePrefix);
#if defined(__MINGW32__) || defined(_MSC_VER)
      free(xsltproc);
#endif
      genHtmlRes = system(buf);
    }
    else
    {
      strcpy(buf, "OPENMODELICAHOME missing");
      genHtmlRes = 1;
    }
    if(genHtmlRes)
    {
      WARNING1(LOG_STDOUT, "Failed to generate html version of profiling results: %s\n", buf);
    }
    INFO2(LOG_STDOUT, "Time measurements are stored in %s_prof.html (human-readable) and %s_prof.xml (for XSL transforms or more details)", data->modelData.modelFilePrefix, data->modelData.modelFilePrefix);
    free(buf);
  }
  return 0;
}
Exemplo n.º 17
0
void OCamlSource::contextMenuEvent( QContextMenuEvent *event )
{
    QTextCursor current_cur = textCursor();
    QTextCursor mouse_position = cursorForPosition( event->pos() );
    QTextCursor cur = mouse_position;
    if ( current_cur.hasSelection() )
        cur = current_cur;

    _breakpoint_line   = mouse_position.blockNumber() + 1;
    _breakpoint_column = mouse_position.position() - mouse_position.block().position() + 1;
    if ( ! cur.hasSelection() )
    {
        cur.select(QTextCursor::WordUnderCursor);
        setTextCursor(cur);
    }
    _selected_text = cur.selectedText();

    QAction *breakAct = new QAction( tr( "&Set Breakpoint at line %1 column %2" )
            .arg( QString::number(mouse_position.blockNumber()+1))
            .arg( QString::number(mouse_position.columnNumber()+1))
            , this );
    breakAct->setStatusTip( tr( "Set a breakpoint to the current location" ) );
    connect( breakAct, SIGNAL( triggered() ), this, SLOT( newBreakpoint() ) );

    QAction *displayAct = NULL;
    if ( cur.hasSelection() )
    {
        displayAct = new QAction( tr( "&Display '%1'" )
                .arg( _selected_text )
                , this );
        connect( displayAct, SIGNAL( triggered() ), this, SLOT( displayVar() ) );
    }

    QAction *printAct = NULL;
    if ( cur.hasSelection() )
    {
        printAct = new QAction( tr( "&Print '%1'" )
                .arg( _selected_text )
                , this );
        connect( printAct, SIGNAL( triggered() ), this, SLOT( printVar() ) );
    }
    QAction *watchAct = NULL;
    if ( cur.hasSelection() )
    {
        watchAct = new QAction( tr( "&Watch '%1'" )
                .arg( _selected_text )
                , this );
        connect( watchAct, SIGNAL( triggered() ), this, SLOT( watchVar() ) );
    }

    QMenu *menu = createStandardContextMenu();

    menu->addAction( breakAct );
    if (displayAct)
        menu->addAction( displayAct );
    if (printAct)
        menu->addAction( printAct );
    if (watchAct)
        menu->addAction( watchAct );
    menu->exec( event->globalPos() );

    delete breakAct;
    if (displayAct)
        delete displayAct;
    if (printAct)
        delete printAct;
    if (watchAct)
        delete watchAct;
    delete menu;
}
Exemplo n.º 18
0
void DebugPrint::printVar(const char* strPtr)
{
	//makes it easy for us.
	convString.assign(strPtr);
	printVar();
}
Exemplo n.º 19
0
void printGlobals(std::ostream& os, Machine mach){
  for (int i = 0; i < mach->globalCount; i++){
    printVar(os, mach->globals[i]);
  }
}
Exemplo n.º 20
0
void ValPrinter::print(std::ostream& os, Value val){
  if (maxDepth >= 0 && depth >= maxDepth){
    os << "...";
    return;
  }
  // if (!val->ground) os << "!";
  switch (val->kind) {
  case ValueData::TERM: {
    TermData const * dat = static_cast<TermData const *>(val);
    char const * name = dat->cons->name;
    bool escape = false;
    int mixcnt = 0;
    while (*name){
      switch (*name){
      case '\\':
	escape = true;
	break;
      case '_':
	if (!escape) mixcnt++;
      default:
	escape = false;
      }
      name++;
    }
    if (mixcnt == dat->cons->arity){
      name = dat->cons->name;
      mixcnt = 0;
      escape = false;
      while (*name){
	switch (*name){
	case '\\':
	  escape = true;
	  os << *name;
	  break;
	case '_':
	  if (!escape){
	    depth++;
	    print(os, dat->args[mixcnt++]);
	    depth--;
	  } else {
	    os << *name;
	    escape = false;
	  }
	  break;
	default:
	  os << *name;
	  escape = false;
	}
	name++;
      }
    } else {
      os << dat->cons->name;
      depth++;
      printList(os, dat->cons->arity, dat->args, "(", ",", ")");
      depth--;
    }
    break;
  }
  case ValueData::VAR: {
    printVar(os, static_cast<VarData*>(val));
    break;
  }
  case ValueData::SET: {
    SetData const * dat = static_cast<SetData const*>(val);
    if (dat->ecount == 0 && dat->icount == 0){
      os << "{}";
      break;
    } 
    if (dat->ecount > 0){
      printList(os, dat->ecount, dat->extens, "{", ",", "}");
    } 
    if (dat->icount > 0){
      for (int i = 0; i < dat->icount; i++){
	if (i != 0 || dat->ecount > 0) os << "+";
	printInten(os, dat->intens[i]);
      }
    }
    break;
  }
  default: {
    OtherData * dat = static_cast<OtherData *>(val);
    dat->print(os,this);
  }
  }
}