Beispiel #1
0
// ---------------------------------------------------------------------------
//  XMLFormatter: Constructors and Destructor
// ---------------------------------------------------------------------------
XMLFormatter::XMLFormatter( const   char* const             outEncoding
                            , const char* const             docVersion
                            ,       XMLFormatTarget* const  target
                            , const EscapeFlags             escapeFlags
                            , const UnRepFlags              unrepFlags
                            ,       MemoryManager* const    manager)
    : fEscapeFlags(escapeFlags)
    , fOutEncoding(0)
    , fTarget(target)
    , fUnRepFlags(unrepFlags)
    , fXCoder(0)  
    , fAposRef(0)
    , fAposLen(0)
    , fAmpRef(0)    
    , fAmpLen(0)    
    , fGTRef(0)
    , fGTLen(0)
    , fLTRef(0)
    , fLTLen(0)
    , fQuoteRef(0)
    , fQuoteLen(0) 
    , fIsXML11(false)
    , fMemoryManager(manager)
{
    // Transcode the encoding string
    fOutEncoding = XMLString::transcode(outEncoding, fMemoryManager);

    // Try to create a transcoder for this encoding
    XMLTransService::Codes resCode;
    fXCoder = XMLPlatformUtils::fgTransService->makeNewTranscoderFor
    (
        fOutEncoding
        , resCode
        , kTmpBufSize
        , fMemoryManager
    );

    if (!fXCoder)
    {
        fMemoryManager->deallocate(fOutEncoding); //delete [] fOutEncoding;
        ThrowXMLwithMemMgr1
        (
            TranscodingException
            , XMLExcepts::Trans_CantCreateCvtrFor
            , outEncoding
            , fMemoryManager
        );
    }

    XMLCh* const tmpDocVer = XMLString::transcode(docVersion, fMemoryManager);
    ArrayJanitor<XMLCh> jname(tmpDocVer, fMemoryManager);
    fIsXML11 = XMLString::equals(tmpDocVer, XMLUni::fgVersion1_1);
}
Beispiel #2
0
/*
 * Generate code for creating netCDF from in-memory structure.
 */
void
gen_ncjava(const char *filename)
{
    int idim, ivar, iatt, maxdims;
    int ndims, nvars, natts, ngatts;

    ndims = listlength(dimdefs);
    nvars = listlength(vardefs);
    natts = listlength(attdefs);
    ngatts = listlength(gattdefs);

    /* Construct the main class */
    codeline("import java.util.*;");
    codeline("import ucar.ma2.*;");
    codeline("import ucar.nc2.*;");
    codeline("import ucar.nc2.NetcdfFile.*;");

    codeline("");
    codepartial("public class ");
    codeline(mainname);
    codeline("{");

    /* Now construct the main procedure*/

    codeline("");
    codeline("static public void main(String[] argv) throws Exception");
    codeline("{");

    /* create necessary declarations */

    if(ndims > 0) {
	codeline("");
	codelined(1,"/* dimension lengths */");
	for(idim = 0; idim < ndims; idim++) {
	    Symbol* dsym = (Symbol*)listget(dimdefs,idim);
	    if(dsym->dim.declsize == NC_UNLIMITED) {
		bbprintf0(stmt,"%sfinal int %s_len = 0;\n",
			indented(1),jname(dsym));
	    } else {
		bbprintf0(stmt,"%sfinal int %s_len = %lu;\n",
			indented(1),
			jname(dsym),
			(unsigned long) dsym->dim.declsize);
	    }
	    codedump(stmt);
	}
    }
    codeflush();

    maxdims = 0;	/* most dimensions of any variable */
    for(ivar = 0; ivar < nvars; ivar++) {
      Symbol* vsym = (Symbol*)listget(vardefs,ivar);
      if(vsym->typ.dimset.ndims > maxdims)
	maxdims = vsym->typ.dimset.ndims;
    }

    codeline("");
#ifdef EXCEPTWRAP
    codelined(1,"try {");
#endif

    /* create netCDF file, uses NC_CLOBBER mode */
    codeline("");
    codelined(1,"/* enter define mode */");

    bbprintf0(stmt,
                "%sNetcdfFileWriteable ncfile = NetcdfFileWriteable.createNew(\"%s\", %s);\n",
		 indented(1),filename,(nofill_flag?"false":"true"));
    codedump(stmt);
    codeflush();
    
    /* define dimensions from info in dims array */
    if(ndims > 0) {
	codeline("");
	codelined(1,"/* define dimensions */");
        for(idim = 0; idim < ndims; idim++) {
            Symbol* dsym = (Symbol*)listget(dimdefs,idim);
	    if(dsym->dim.declsize == NC_UNLIMITED) {
                bbprintf0(stmt,"%sDimension %s_dim = ncfile.addUnlimitedDimension(\"%s\");\n",
                    indented(1),jname(dsym),jescapifyname(dsym->name));
	    } else {
                bbprintf0(stmt,"%sDimension %s_dim = ncfile.addDimension(\"%s\", %s_len);\n",
                    indented(1),jname(dsym),jescapifyname(dsym->name), jname(dsym));
	    }
            codedump(stmt);
       }
       codeflush();
    }

    /* define variables from info in vars array */
    if(nvars > 0) {
        codeline("");
        codelined(1,"/* define variables */");
        for(ivar = 0; ivar < nvars; ivar++) {
            Symbol* vsym = (Symbol*)listget(vardefs,ivar);
            Symbol* basetype = vsym->typ.basetype;
            Dimset* dimset = &vsym->typ.dimset;
            codeline("");
            bbprintf0(stmt,"%sArrayList %s_dimlist = new ArrayList();\n",
                                        indented(1),jname(vsym));
            codedump(stmt);
            if(dimset->ndims > 0) {
                for(idim = 0; idim < dimset->ndims; idim++) {
                    Symbol* dsym = dimset->dimsyms[idim];
                    bbprintf0(stmt,"%s%s_dimlist.add(%s_dim);\n",
                            indented(1),jname(vsym),jname(dsym));
                    codedump(stmt);
                }
	    }
            bbprintf0(stmt,
                            "%sncfile.addVariable(\"%s\", DataType.%s, %s_dimlist);\n",
			    indented(1),
                            jescapifyname(vsym->name),
                            jtypeallcaps(basetype->typ.typecode),
                            jname(vsym));
            codedump(stmt);
        }
        codeflush();
    }
        
    /* Define the global attributes*/
    if(ngatts > 0) {
        codeline("");
        codelined(1,"/* assign global attributes */");
        for(iatt = 0; iatt < ngatts; iatt++) {
            Symbol* gasym = (Symbol*)listget(gattdefs,iatt);
            genj_defineattr(gasym);            
        }
        codeline("");
        codeflush();
    }
    
    /* Define the variable specific attributes*/
    if(natts > 0) {
        codeline("");
        codelined(1,"/* assign per-variable attributes */");
        for(iatt = 0; iatt < natts; iatt++) {
            Symbol* asym = (Symbol*)listget(attdefs,iatt);
            genj_defineattr(asym);
        }
        codeline("");
        codeflush();
    }

    codelined(1,"ncfile.create();"); /* equiv to nc_enddef */

    if(!header_only) {
        /* Load values into those variables with defined data */
        if(nvars > 0) {
            codeline("");
            codelined(1,"/* assign variable data */");
            for(ivar = 0; ivar < nvars; ivar++) {
                Symbol* vsym = (Symbol*)listget(vardefs,ivar);
                if(vsym->data != NULL) genj_definevardata(vsym);
            }
            codeline("");
        }
    }

    codeflush();

}
void SBCollisionManager::start()
{
#ifndef SB_NO_ODE_PHYSICS
	_singleChrCapsuleMode = getBoolAttribute("singleChrCapsuleMode");
	float jointBVLenRadRatio = (float)(getDoubleAttribute("jointBVLenRadRatio"));

	SR_CLIP(jointBVLenRadRatio, 0.001f, 1000.0f);
	_jointBVLenRadRatio = jointBVLenRadRatio;

	SBScene* scene = SmartBody::SBScene::getScene();
	SBSteerManager* steerManager = scene->getSteerManager();
	_characterRadius = (float) steerManager->getDoubleAttribute("initialConditions.radius");
	double sceneScale = scene->getDoubleAttribute("scale");
	if (sceneScale != 0.0)
	{
		_characterRadius *= (float) (1.0 / sceneScale);
	}
	_positions.clear();
	_velocities.clear();
	if (!collisionSpace)
	{
		collisionSpace = new ODECollisionSpace();

	}
	const std::vector<std::string>& characterNames = scene->getCharacterNames();
	for (std::vector<std::string>::const_iterator iter = characterNames.begin();
		 iter != characterNames.end();
		 iter++)
	{
		_positions.insert(std::pair<std::string, SrVec>((*iter), SrVec()));
		_velocities.insert(std::pair<std::string, SrVec>((*iter), SrVec()));
		SBCharacter* character = scene->getCharacter(*iter);
		if (!character->getGeomObject() || character->getGeomObject()->geomType() == "null") // no collision geometry setup for the character
		{
			if(_singleChrCapsuleMode)
			{
				//SBGeomObject* obj = new SBGeomCapsule()			
				SrBox bbox = character->getBoundingBox();	
				float yoffset = bbox.getMinimum().y - character->get_world_offset().get_translation().y;
				SrVec size = SrVec(0,_characterRadius,0);
				SBGeomObject* obj = createCollisionObject(character->getGeomObjectName(),"capsule",size,SrVec(0,yoffset,0),SrVec(0,yoffset+character->getHeight(),0));
				obj->attachToObj(character);
				addObjectToCollisionSpace(character->getGeomObjectName());
				//new SBGeomCapsule(SrVec(0,yoffset,0),SrVec(0,yoffset+character->getHeight(),0),_characterRadius);
				//character->setGeomObject(obj);
				//collisionSpace->addCollisionObjects(obj);
			}
			else // create collision capsules based on skel bones
			{
				LOG(character->getName().c_str());
				SkSkeleton* sk = character->getSkeleton();
				const std::vector<SkJoint*>& origJnts = sk->joints();
				sk->update_global_matrices();
				std::vector<SkJoint*> jnt_excld_list;
				for(unsigned int i=0; i<origJnts.size(); i++)
				{
					SkJoint* j = origJnts[i];
					SrString jname(j->jointName().c_str());
					if(jname.search("world_offset")>=0) { jnt_excld_list.push_back(j); continue; } // skip world_offset
					if(jname.search("face")>=0) { jnt_excld_list.push_back(j); continue; }
					if(jname.search("brow")>=0) { jnt_excld_list.push_back(j); continue; }
					if(jname.search("eye")>=0)  { jnt_excld_list.push_back(j); continue; }
					if(jname.search("nose")>=0) { jnt_excld_list.push_back(j); continue; }
					if(jname.search("lid")>=0)  { jnt_excld_list.push_back(j); continue; }
					if(jname.search("jaw")>=0)  { jnt_excld_list.push_back(j); continue; }
					if(jname.search("tongue")>=0) { jnt_excld_list.push_back(j); continue; }
					if(jname.search("lip")>=0)    { jnt_excld_list.push_back(j); continue; }
					if(jname.search("cheek")>=0)  { jnt_excld_list.push_back(j); continue; }
					if(jname.search("finger")>=0) { jnt_excld_list.push_back(j); continue; }
					if(jname.search("thumb")>=0)  { jnt_excld_list.push_back(j); continue; }
					if(jname.search("index")>=0)  { jnt_excld_list.push_back(j); continue; }
					if(jname.search("middle")>=0) { jnt_excld_list.push_back(j); continue; }
					if(jname.search("pinky")>=0)  { jnt_excld_list.push_back(j); continue; }
					if(jname.search("ring")>=0)   { jnt_excld_list.push_back(j); continue; }
				}
				std::string chrName = character->getGeomObjectName();
				float chrHeight = character->getHeight();
				for(unsigned int i=0; i<origJnts.size(); i++)
				{
					SkJoint* j = origJnts[i];
					if(isJointExcluded(j, jnt_excld_list)) continue;
					SrString jname(j->jointName().c_str());
					for(int k=0; k<j->num_children(); k++)
					{
						SkJoint* j_ch = j->child(k);
						if(isJointExcluded(j_ch, jnt_excld_list)) continue;
						const SrVec& offset = j_ch->offset();
						float offset_len = offset.norm();
						float radius = offset_len / jointBVLenRadRatio;
						if(offset_len < 0.03*chrHeight) continue; // skip short bones
						std::string colObjName = chrName + ":" + j->jointName();
						if(k>0) colObjName = colObjName + ":" + boost::lexical_cast<std::string>(k);
						SBGeomObject* obj = createCollisionObject(colObjName,"capsule",SrVec(0, radius, 0),SrVec::null,offset);
						LOG("SBColMan: col primitive added: %s, len: %f, radius: %f", colObjName.c_str(), offset_len, radius);
						obj->attachToObj(dynamic_cast<SBTransformObjInterface*>(j));
						addObjectToCollisionSpace(colObjName);
					}
				}
			}
		}
	}

	const std::vector<std::string>& pawnNames = scene->getPawnNames();
	for (std::vector<std::string>::const_iterator iter = pawnNames.begin();
		 iter != pawnNames.end(); iter++)
	{
		SBPawn* pawn = scene->getPawn(*iter);
		if(pawn->getGeomObject()->geomType() != "null")
		{
			//SBGeomObject* obj = pawn->getGeomObject();
			SBGeomObject* obj = createCollisionObject(pawn->getGeomObjectName(),pawn->getGeomObject()->geomType(),pawn->getGeomObject()->getGeomSize(),SrVec::null,SrVec::null);
			obj->attachToObj(pawn);

			addObjectToCollisionSpace(pawn->getGeomObjectName());
		}
	}
#endif
}
Beispiel #4
0
/*
 * Generate code for creating netCDF from in-memory structure.
 */
void
gen_ncjava_std(const char *filename)
{
    int idim, ivar, iatt, maxdims;
    int ndims, nvars, natts, ngatts, ngrps, ntyps;
    char* cmode_string;

    jcode = bbNew();
    bbSetalloc(jcode,C_MAX_STMT);

    ndims = listlength(dimdefs);
    nvars = listlength(vardefs);
    natts = listlength(attdefs);
    ngatts = listlength(gattdefs);
    ngrps = listlength(grpdefs);
    ntyps = listlength(typdefs);

    /* Construct the main class */
    jline("import java.util.*;");
    jline("import ucar.ma2.*;");
    jline("import ucar.nc2.*;");
    jline("import ucar.nc2.NetcdfFile.*;");

    jline("");
    jpartial("public class ");
    jline(mainname);
    jline("{");

    /* Now construct the main procedure*/

    jline("");
    jline("static public void main(String[] argv) throws Exception");
    jline("{");


    /* create necessary declarations */

    if (ndims > 0) {
	jline("");
	jlined(1,"/* dimension lengths */");
	for(idim = 0; idim < ndims; idim++) {
	    Symbol* dsym = (Symbol*)listget(dimdefs,idim);
	    if (dsym->dim.size == NC_UNLIMITED) {
		nprintf(stmt,sizeof(stmt),"%sfinal int %s_len = 0;",
			indented(1),jname(dsym));
	    } else {
		nprintf(stmt,sizeof(stmt),"%sfinal int %s_len = %lu;",
			indented(1),
			jname(dsym),
			(unsigned long) dsym->dim.size);
	    }
	    jline(stmt);
	}
    }
    jflush();

    maxdims = 0;	/* most dimensions of any variable */
    for(ivar = 0; ivar < nvars; ivar++) {
      Symbol* vsym = (Symbol*)listget(vardefs,ivar);
      if(vsym->typ.dimset.ndims > maxdims)
	maxdims = vsym->typ.dimset.ndims;
    }

    jline("");
#ifdef DOTHROW
    jlined(1,"try {");
#endif

    /* create netCDF file, uses NC_CLOBBER mode */
    jline("");
    jlined(1,"/* enter define mode */");

    if (!cmode_modifier) {
	cmode_string = "NC_CLOBBER";
    } else if (cmode_modifier & NC_64BIT_OFFSET) {
	cmode_string = "NC_CLOBBER|NC_64BIT_OFFSET";
    } else {
        derror("unknown cmode modifier");
	cmode_string = "NC_CLOBBER";
    }

    nprintf(stmt,sizeof(stmt),
                "NetcdfFileWriteable ncfile = NetcdfFileWriteable.createNew(\"%s\", %s);",
		 filename,(nofill_flag?"false":"true"));
    jlined(1,stmt);
    jflush();
    
    /* define dimensions from info in dims array */
    if (ndims > 0) {
	jline("");
	jlined(1,"/* define dimensions */");
        for(idim = 0; idim < ndims; idim++) {
            Symbol* dsym = (Symbol*)listget(dimdefs,idim);
	    if(dsym->dim.size == NC_UNLIMITED) {
                nprintf(stmt,sizeof(stmt),"Dimension %s_dim = ncfile.addUnlimitedDimension(\"%s\");",
                    jname(dsym),jescapifyname(dsym->name));
	    } else {
                nprintf(stmt,sizeof(stmt),"Dimension %s_dim = ncfile.addDimension(\"%s\", %s_len);",
                    jname(dsym),jescapifyname(dsym->name), jname(dsym));
	    }
            jlined(1,stmt);
       }
       jflush();
    }

    /* define variables from info in vars array */
    if (nvars > 0) {
        jline("");
        jlined(1,"/* define variables */");
        for(ivar = 0; ivar < nvars; ivar++) {
            Symbol* vsym = (Symbol*)listget(vardefs,ivar);
            Symbol* basetype = vsym->typ.basetype;
            Dimset* dimset = &vsym->typ.dimset;
            jline("");
            nprintf(stmt,sizeof(stmt),"ArrayList %s_dimlist = new ArrayList();",
                                        jname(vsym));
            jlined(1,stmt);
            if(dimset->ndims > 0) {
                for(idim = 0; idim < dimset->ndims; idim++) {
                    Symbol* dsym = dimset->dimsyms[idim];
                    nprintf(stmt,sizeof(stmt),"%s_dimlist.add(%s_dim);",
                            jname(vsym),jname(dsym));
                    jlined(1,stmt);
                }
	    }
            nprintf(stmt,sizeof(stmt),
                            "ncfile.addVariable(\"%s\", DataType.%s, %s_dimlist);",
                            jescapifyname(vsym->name),
                            jtypeallcaps(basetype->typ.typecode),
                            jname(vsym));
            jlined(1,stmt);
        }
        jflush();
    }
        
    /* Define the global attributes*/
    if(ngatts > 0) {
        jline("");
        jlined(1,"/* assign global attributes */");
        for(iatt = 0; iatt < ngatts; iatt++) {
            Symbol* gasym = (Symbol*)listget(gattdefs,iatt);
            genjstd_defineattribute(gasym);            
        }
        jline("");
        jflush();
    }
    
    /* Define the variable specific attributes*/
    if(natts > 0) {
        jline("");
        jlined(1,"/* assign per-variable attributes */");
        for(iatt = 0; iatt < natts; iatt++) {
            Symbol* asym = (Symbol*)listget(attdefs,iatt);
            genjstd_defineattribute(asym);
        }
        jline("");
        jflush();
    }

    jlined(1,"ncfile.create();"); /* equiv to nc_enddef */

    /* Load values into those variables with defined data */

    if(nvars > 0) {
        jline("");
        jlined(1,"/* assign variable data */");
        for(ivar = 0; ivar < nvars; ivar++) {
            Symbol* vsym = (Symbol*)listget(vardefs,ivar);
            if(vsym->data != NULL) genjstd_definevardata(vsym);
        }
        jline("");
        /* compute the max actual size of the unlimited dimension*/
        if(usingclassic) computemaxunlimited();
    }
    jflush();

}
Beispiel #5
0
int main(int argc, char** argv)
{
    DynareParams params(argc, argv);
    if (params.help) {
        params.printHelp();
        return 0;
    }
    if (params.version) {
        printf("Dynare++ v. %s. Copyright (C) 2004-2011, Ondra Kamenik\n",
               DYNVERSION);
        printf("Dynare++ comes with ABSOLUTELY NO WARRANTY and is distributed under\n");
        printf("GPL: modules integ, tl, kord, sylv, src, extern and documentation\n");
        printf("LGPL: modules parser, utils\n");
        printf(" for GPL  see http://www.gnu.org/licenses/gpl.html\n");
        printf(" for LGPL see http://www.gnu.org/licenses/lgpl.html\n");
        return 0;
    }
    THREAD_GROUP::max_parallel_threads = params.num_threads;

    try {
        // make journal name and journal
        std::string jname(params.basename);
        jname += ".jnl";
        Journal journal(jname.c_str());

        // make dynare object
        Dynare dynare(params.modname, params.order, params.ss_tol, journal);
        // make list of shocks for which we will do IRFs
        vector<int> irf_list_ind;
        if (params.do_irfs_all)
            for (int i = 0; i < dynare.nexog(); i++)
                irf_list_ind.push_back(i);
        else
            irf_list_ind = ((const DynareNameList&)dynare.getExogNames()).selectIndices(params.irf_list);

        // write matlab files
        FILE* mfd;
        std::string mfile1(params.basename);
        mfile1 += "_f.m";
        if (NULL == (mfd=fopen(mfile1.c_str(), "w"))) {
            fprintf(stderr, "Couldn't open %s for writing.\n", mfile1.c_str());
            exit(1);
        }
        ogdyn::MatlabSSWriter writer0(dynare.getModel(), params.basename.c_str());
        writer0.write_der0(mfd);
        fclose(mfd);

        std::string mfile2(params.basename);
        mfile2 += "_ff.m";
        if (NULL == (mfd=fopen(mfile2.c_str(), "w"))) {
            fprintf(stderr, "Couldn't open %s for writing.\n", mfile2.c_str());
            exit(1);
        }
        ogdyn::MatlabSSWriter writer1(dynare.getModel(), params.basename.c_str());
        writer1.write_der1(mfd);
        fclose(mfd);

        // open mat file
        std::string matfile(params.basename);
        matfile += ".mat";
        mat_t* matfd = Mat_Create(matfile.c_str(), NULL);
        if (matfd == NULL) {
            fprintf(stderr, "Couldn't open %s for writing.\n", matfile.c_str());
            exit(1);
        }

        // write info about the model (dimensions and variables)
        dynare.writeMat(matfd, params.prefix);
        // write the dump file corresponding to the input
        dynare.writeDump(params.basename);


        system_random_generator.initSeed(params.seed);

        tls.init(dynare.order(),
                 dynare.nstat()+2*dynare.npred()+3*dynare.nboth()+
                 2*dynare.nforw()+dynare.nexog());

        Approximation app(dynare, journal, params.num_steps, params.do_centralize, params.qz_criterium);
        try {
            app.walkStochSteady();
        } catch (const KordException& e) {
            // tell about the exception and continue
            printf("Caught (not yet fatal) Kord exception: ");
            e.print();
            JournalRecord rec(journal);
            rec << "Solution routine not finished (" << e.get_message()
                << "), see what happens" << endrec;
        }

        std::string ss_matrix_name(params.prefix);
        ss_matrix_name += "_steady_states";
        ConstTwoDMatrix(app.getSS()).writeMat(matfd, ss_matrix_name.c_str());

        // check the approximation
        if (params.check_along_path || params.check_along_shocks
                || params.check_on_ellipse) {
            GlobalChecker gcheck(app, THREAD_GROUP::max_parallel_threads, journal);
            if (params.check_along_shocks)
                gcheck.checkAlongShocksAndSave(matfd, params.prefix,
                                               params.getCheckShockPoints(),
                                               params.getCheckShockScale(),
                                               params.check_evals);
            if (params.check_on_ellipse)
                gcheck.checkOnEllipseAndSave(matfd, params.prefix,
                                             params.getCheckEllipsePoints(),
                                             params.getCheckEllipseScale(),
                                             params.check_evals);
            if (params.check_along_path)
                gcheck.checkAlongSimulationAndSave(matfd, params.prefix,
                                                   params.getCheckPathPoints(),
                                                   params.check_evals);
        }

        // write the folded decision rule to the Mat-4 file
        app.getFoldDecisionRule().writeMat(matfd, params.prefix);

        // simulate conditional
        if (params.num_condper > 0 && params.num_condsim > 0) {
            SimResultsDynamicStats rescond(dynare.numeq(), params.num_condper, 0);
            ConstVector det_ss(app.getSS(),0);
            rescond.simulate(params.num_condsim, app.getFoldDecisionRule(), det_ss, dynare.getVcov(), journal);
            rescond.writeMat(matfd, params.prefix);
        }

        // simulate unconditional
        //const DecisionRule& dr = app.getUnfoldDecisionRule();
        const DecisionRule& dr = app.getFoldDecisionRule();
        if (params.num_per > 0 && params.num_sim > 0) {
            SimResultsStats res(dynare.numeq(), params.num_per, params.num_burn);
            res.simulate(params.num_sim, dr, dynare.getSteady(), dynare.getVcov(), journal);
            res.writeMat(matfd, params.prefix);

            // impulse response functions
            if (! irf_list_ind.empty()) {
                IRFResults irf(dynare, dr, res, irf_list_ind, journal);
                irf.writeMat(matfd, params.prefix);
            }
        }

        // simulate with real-time statistics
        if (params.num_rtper > 0 && params.num_rtsim > 0) {
            RTSimResultsStats rtres(dynare.numeq(), params.num_rtper, params.num_burn);
            rtres.simulate(params.num_rtsim, dr, dynare.getSteady(), dynare.getVcov(), journal);
            rtres.writeMat(matfd, params.prefix);
        }

        Mat_Close(matfd);

    } catch (const KordException& e) {
        printf("Caugth Kord exception: ");
        e.print();
        return e.code();
    } catch (const TLException& e) {
        printf("Caugth TL exception: ");
        e.print();
        return 255;
    } catch (SylvException& e) {
        printf("Caught Sylv exception: ");
        e.printMessage();
        return 255;
    } catch (const DynareException& e) {
        printf("Caught Dynare exception: %s\n", e.message());
        return 255;
    } catch (const ogu::Exception& e) {
        printf("Caught ogu::Exception: ");
        e.print();
        return 255;
    } catch (const ogp::ParserException& e) {
        printf("Caught parser exception: %s\n", e.message());
        return 255;
    }

    return 0;
}