Beispiel #1
0
int convert_anim(const char *infname)
{
	int i, bufsz;
	const struct aiScene *aiscn;
	struct goat3d *goat;
	char *outfname;

	bufsz = output_filename(0, 0, infname, "goatanim");
	outfname = alloca(bufsz);
	output_filename(outfname, bufsz, infname, "goatanim");
	printf("converting %s -> %s\n", infname, outfname);


	if(!(aiscn = aiImportFile(infname, ANM_PPFLAGS))) {
		fprintf(stderr, "failed to import %s\n", infname);
		return -1;
	}

	goat = goat3d_create();

	for(i=0; i<(int)aiscn->mRootNode->mNumChildren; i++) {
		process_node(goat, 0, aiscn->mRootNode->mChildren[i]);
	}

	for(i=0; i<aiscn->mNumAnimations; i++) {
		if(process_anim(goat, aiscn->mAnimations[i]) == -1) {
			return -1;
		}
	}

	goat3d_save_anim(goat, outfname);
	goat3d_free(goat);
	aiReleaseImport(aiscn);
	return 0;
}
Beispiel #2
0
      void go() override
         {
         const std::string comp_type = get_arg("type");

         std::unique_ptr<Botan::Transform> compress;

#if defined(BOTAN_HAS_COMPRESSION)
         compress.reset(Botan::make_compressor(comp_type, get_arg_sz("level")));
#endif

         if(!compress)
            {
            throw CLI_Error_Unsupported("Compression", comp_type);
            }

         const std::string in_file = get_arg("file");
         std::ifstream in(in_file);

         if(!in.good())
            {
            throw CLI_IO_Error("reading", in_file);
            }

         const std::string out_file = output_filename(in_file, comp_type);
         std::ofstream out(out_file);
         if(!in.good())
            {
            throw CLI_IO_Error("writing", out_file);
            }

         do_compress(*compress, in, out, get_arg_sz("buf-size"));
         }
Beispiel #3
0
void run_lexer_on_file( const std::string & filename ) {
    std::cout << "Parsing file " << filename << "..." << std::endl;

    llvm::SmallString<128> output_filename( filename );
    llvm::sys::path::replace_extension( output_filename, ".cpp.lex" );

    std::ofstream output( output_filename.c_str() );

    clang::CompilerInstance ci;
    ci.createDiagnostics(0, 0);
    
    clang::TargetOptions * targ_opts = new clang::TargetOptions();
    targ_opts->Triple = llvm::sys::getDefaultTargetTriple();
    clang::TargetInfo * targ = clang::TargetInfo::CreateTargetInfo( ci.getDiagnostics(), 
            *targ_opts );
    ci.setTarget( targ );
    
    ci.createFileManager();
    ci.createSourceManager( ci.getFileManager() );
    ci.createPreprocessor();
    const clang::FileEntry * file = ci.getFileManager().getFile( filename );
    ci.getSourceManager().createMainFileID( file );
    ci.getPreprocessor().EnterMainSourceFile();
    ci.getDiagnosticClient().BeginSourceFile( ci.getLangOpts(), &ci.getPreprocessor() );
    
    clang::Token tok;
    do {
        ci.getPreprocessor().Lex( tok );
        output << tok.getName() << '\n';
    } while( tok.isNot( clang::tok::eof ) );
    ci.getDiagnosticClient().EndSourceFile();
}
Beispiel #4
0
int convert(const char *infname)
{
	int i, bufsz;
	const struct aiScene *aiscn;
	struct goat3d *goat;
	char *outfname;

	bufsz = output_filename(0, 0, infname, "goat3d");
	outfname = alloca(bufsz);
	output_filename(outfname, bufsz, infname, "goat3d");
	printf("converting %s -> %s\n", infname, outfname);


	if(!(aiscn = aiImportFile(infname, SCE_PPFLAGS))) {
		fprintf(stderr, "failed to import %s\n", infname);
		return -1;
	}

	goat = goat3d_create();

	for(i=0; i<(int)aiscn->mNumMaterials; i++) {
		struct aiMaterial *aimat = aiscn->mMaterials[i];
		struct goat3d_material *mat = goat3d_create_mtl();

		process_material(mat, aimat);
		goat3d_add_mtl(goat, mat);
	}

	for(i=0; i<(int)aiscn->mNumMeshes; i++) {
		struct aiMesh *aimesh = aiscn->mMeshes[i];
		struct goat3d_mesh *mesh = goat3d_create_mesh();

		process_mesh(goat, mesh, aimesh);
		goat3d_add_mesh(goat, mesh);
	}

	for(i=0; i<(int)aiscn->mRootNode->mNumChildren; i++) {
		process_node(goat, 0, aiscn->mRootNode->mChildren[i]);
	}

	goat3d_save(goat, outfname);
	goat3d_free(goat);
	aiReleaseImport(aiscn);
	return 0;
}
void plot_output(
  double *t,      ///< time (I)
  double *xd,     ///< differential states (I)
  double *xa,     ///< algebraic states (I)
  double *u,      ///< controls (I)
  double *p_free,      ///< global model parameters (I)
  double *rwh,    ///< real work array (I)
  long   *iwh,     ///< integer work array (I)
  InfoPtr *info
){
	FILE *fp;
	stringstream output_filename("");
	// Filename
	char problemname[50];
	get_pname(problemname);
	output_filename << "./RES/" << problemname <<".plt";
	if (*t == 0)
		fp = fopen(output_filename.str().c_str(), "w");
	else
		fp = fopen(output_filename.str().c_str(), "a");
	if (!fp) {
		fprintf(stderr, "Error: Could not open file '%s'!\n",
				output_filename.str().c_str());
		return;
	}
	if (*t == 0) {
		// write header:
		/// Get names of model quantities.
		char **xd_name[1];  /* differential state names (O) */
		char **xa_name[1];  /* algebraic state names (O) */
		char **u_name[1];   /* control names (O) */
		char **h_name[1];   /* model stage duration names (O) */
		char **p_name[1];   /* global model parameter names (O) */
		char *of_name[1];   /* objective name (O) */
		get_names(xd_name, xa_name, u_name, h_name, p_name, of_name);
		fprintf(fp, "//time\t");
		for (int i = 0; i<NY; i++){
			fprintf(fp, "%s\t",xd_name[0][i]);
		}
		for (int i = 0; i<NU; i++){
			fprintf(fp, "%s\t",u_name[0][i]);
		}
		fprintf(fp, "\n");
	}
	fprintf(fp, "%e\t", *t);
	for (int i = 0; i<NY; i++){
		fprintf(fp, "%e\t",xd[i]);
	}
	for (int i = 0; i<NU; i++){
		fprintf(fp, "%e\t",u[i]);
	}

	fprintf(fp, "\n");
	// Close file
	fclose(fp);
}
Beispiel #6
0
      void go() override
         {
         const std::string comp_type = get_arg("type");
         const size_t buf_size = get_arg_sz("buf-size");
         const size_t comp_level = get_arg_sz("level");

         std::unique_ptr<Botan::Compression_Algorithm> compress;

         compress.reset(Botan::make_compressor(comp_type));

         if(!compress)
            {
            throw CLI_Error_Unsupported("Compression", comp_type);
            }

         const std::string in_file = get_arg("file");
         std::ifstream in(in_file, std::ios::binary);

         if(!in.good())
            {
            throw CLI_IO_Error("reading", in_file);
            }

         const std::string out_file = output_filename(in_file, comp_type);
         std::ofstream out(out_file, std::ios::binary);
         if(!in.good())
            {
            throw CLI_IO_Error("writing", out_file);
            }

         Botan::secure_vector<uint8_t> buf;

         compress->start(comp_level);

         while(in.good())
            {
            buf.resize(buf_size);
            in.read(reinterpret_cast<char*>(&buf[0]), buf.size());
            buf.resize(in.gcount());

            compress->update(buf);

            out.write(reinterpret_cast<const char*>(&buf[0]), buf.size());
            }

         buf.clear();
         compress->finish(buf);
         out.write(reinterpret_cast<const char*>(&buf[0]), buf.size());
         out.close();
         }
void getSokolovOfChainsBulk(string path, string input_name) {
  string input_filename(path);
  input_filename.append(input_name);

  std::ifstream input_file;
  input_file.open(input_filename);
  
  string line;
  getline (input_file, line);
  istringstream linestream(line);
  
  int L, l, m;
  long double eps;
  string output_name;
  linestream >> L >> l >> m >> eps >> output_name;
  
  string output_filename(path);
  output_filename.append(output_name);
  std::ofstream output_file;
  output_file.open(output_filename);
  output_file.close();
  
  int max_probs_count = 20;
  vector<long double> probs;
  probs.reserve(max_probs_count);

  int probs_count = 0;
  
  do {
    getline (input_file, line);
    if (!line.empty()) {
      vector<int> errors(readChainErrors(line));
      long double prob = GetSokolovBound(L, l, m, eps, errors);
      probs.push_back(prob);
      ++probs_count;
    }
    if ((probs_count == max_probs_count) or (input_file.eof())) {
      output_file.open(output_filename, std::ios::app);
      copy(probs.begin(), probs.end(), std::ostream_iterator<long double>(output_file, "\n"));
      output_file.close();
      probs.clear();
      probs.reserve(max_probs_count);
      probs_count = 0;
    }
    std::cout << probs.size() << "\n";
  } 
  while (!input_file.eof());
  input_file.close();
}
Beispiel #8
0
void
Transcoder::run()
{
	position_ = eta_ = audio_b_ = video_b_ = -1;
	stopping_ = false;
	pass_ = extra_args_.contains("--two-pass") ? 0 : -1;
	
	proc_.start(ffmpeg2theora(), QStringList() << "--frontend"
		<< extra_args_
		<< "--output" << output_filename()
		<< input_filename());

	if (proc_.waitForStarted())
		exec();
	else
		emit statusUpdate("Encoding failed to start");
}
static void write_log(gpr_timer_log *log) {
  size_t i;
  if (output_file == NULL) {
    output_file = fopen(output_filename(), "w");
  }
  for (i = 0; i < log->num_entries; i++) {
    gpr_timer_entry *entry = &(log->log[i]);
    if (gpr_time_cmp(entry->tm, gpr_time_0(entry->tm.clock_type)) < 0) {
      entry->tm = gpr_time_0(entry->tm.clock_type);
    }
    fprintf(output_file,
            "{\"t\": %" PRId64
            ".%09d, \"thd\": \"%d\", \"type\": \"%c\", \"tag\": "
            "\"%s\", \"file\": \"%s\", \"line\": %d, \"imp\": %d}\n",
            entry->tm.tv_sec, entry->tm.tv_nsec, entry->thd, entry->type,
            entry->tagstr, entry->file, entry->line, entry->important);
  }
}
int main(int argc, char **argv)
{
  try
  {
    TCLAP::CmdLine cmd("Centers a mesh", ' ', "1.0");

    TCLAP::ValueArg<std::string> log_filename("l","logfile", "Log file name (default is convert.log)", false, "convert.log", "string");
    cmd.add( log_filename );

    TCLAP::UnlabeledValueArg<std::string> input_filename( "input-filename", "Input file name", true, "", "InputFile"  );
    cmd.add( input_filename );

    TCLAP::UnlabeledValueArg<std::string> output_filename( "output-filename", "Output file name", true, "", "OutputFile"  );
    cmd.add( output_filename );

    cmd.parse( argc, argv );


    if ( !log_filename.getValue().empty() )
      viennamesh_log_add_logging_file(log_filename.getValue().c_str(), NULL);

    viennamesh::context_handle context;

    viennamesh::algorithm_handle mesh_reader = context.make_algorithm("mesh_reader");
    mesh_reader.set_input( "filename", input_filename.getValue() );
    mesh_reader.run();

    viennamesh::algorithm_handle center_mesh = context.make_algorithm("center_mesh");
    center_mesh.set_default_source(mesh_reader);
    center_mesh.run();

    viennamesh::algorithm_handle mesh_writer = context.make_algorithm("mesh_writer");
    mesh_writer.set_default_source(center_mesh);
    mesh_writer.set_input( "filename", output_filename.getValue() );
    mesh_writer.run();
  }
  catch (TCLAP::ArgException &e)  // catch any exceptions
  {
    std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
  }

  return 0;
}
int main(int argc, char* argv[]) {
    if (argc != 2) {
        std::cerr << "Usage: " << argv[0] << " INFILE\n";
        exit(1);
    }

    std::string output_format("SQLite");
    std::string input_filename(argv[1]);
    std::string output_filename("multipolygon.db");

    OGRDataSource* data_source = initialize_database(output_format, output_filename);

    osmium::area::ProblemReporterOGR problem_reporter(data_source);
    osmium::area::Assembler::config_type assembler_config(&problem_reporter);
    assembler_config.enable_debug_output();
    osmium::area::MultipolygonCollector<osmium::area::Assembler> collector(assembler_config);

    std::cerr << "Pass 1...\n";
    osmium::io::Reader reader1(input_filename);
    collector.read_relations(reader1);
    reader1.close();
    std::cerr << "Pass 1 done\n";

    index_type index_pos;
    index_type index_neg;
    location_handler_type location_handler(index_pos, index_neg);
    location_handler.ignore_errors();

    TestHandler test_handler(data_source);

    std::cerr << "Pass 2...\n";
    osmium::io::Reader reader2(input_filename);
    osmium::apply(reader2, location_handler, test_handler, collector.handler([&test_handler](const osmium::memory::Buffer& area_buffer) {
        osmium::apply(area_buffer, test_handler);
    }));
    reader2.close();
    std::cerr << "Pass 2 done\n";

    OGRDataSource::DestroyDataSource(data_source);
    OGRCleanupAll();
}
Beispiel #12
0
int main(int argc, char* argv[]) {
    if (argc != 2) {
        std::cerr << "Usage: " << argv[0] << " INFILE\n";
        exit(1);
    }

    std::string output_format("SQLite");
    std::string input_filename(argv[1]);
    std::string output_filename("testdata-overview.db");
    ::unlink(output_filename.c_str());

    osmium::io::Reader reader(input_filename);

    index_type index;
    location_handler_type location_handler(index);
    location_handler.ignore_errors();

    TestOverviewHandler handler(output_format, output_filename);

    osmium::apply(reader, location_handler, handler);
    reader.close();
}
int main(int argc, char** argv)
{
    if (argc != 3) {
        std::cerr << "Usage: urdf_to_collada input.urdf output.dae" << std::endl;
        return -1;
    }

	ros::init(argc, argv, "urdf_to_collada");

    std::string input_filename(argv[1]);
    std::string output_filename(argv[2]);

    urdf::Model robot_model;
    if( !robot_model.initFile(input_filename) ) {
        ROS_ERROR("failed to open urdf file %s",input_filename.c_str());
    }

    collada_urdf::WriteUrdfModelToColladaFile(robot_model, output_filename);
    std::cout << std::endl << "Document successfully written to " << output_filename << std::endl;

    return 0;
}
Beispiel #14
0
void dot_graph(const binspector_analyzer_t::structure_map_t& struct_map,
               const std::string&                            starting_struct,
               const boost::filesystem::path&                output_root)
{
    boost::filesystem::path     output_filename(output_root / "graph.gv");
    boost::filesystem::ofstream output(output_filename);
    dot_graph_t                 graph;

    assert (output);

    graph.name_m = "G";
    graph.type_m = "digraph";

    //graph.setting_vector_m.push_back("node [shape=box]");
    //graph.setting_vector_m.push_back("rankdir=TB");
    //graph.setting_vector_m.push_back("packMode=clust");
    graph.setting_vector_m.push_back("outputMode=nodesfirst");

    adobe::name_t starting_name(starting_struct.c_str());
    std::string   starting_id(name_map(starting_name));
    dot_node_t    node;

    node.attribute_map_m["label"] = starting_name.c_str();
    node.id_m = starting_id;

    graph.node_vector_m.push_back(node);

    graph_struct(struct_map,
                 starting_name,
                 starting_id,
                 binspector_analyzer_t::typedef_map_t(),
                 0,
                 graph);

    format_graph(graph, output);

    std::cerr << "File written to " << output_filename.string() << '\n';
}
Beispiel #15
0
int main(int argc, char* argv[]) {
    static struct option long_options[] = {
        {"help",   no_argument, 0, 'h'},
        {"format", required_argument, 0, 'f'},
        {0, 0, 0, 0}
    };

    std::string output_format("SQLite");

    while (true) {
        int c = getopt_long(argc, argv, "hf:", long_options, 0);
        if (c == -1) {
            break;
        }

        switch (c) {
        case 'h':
            print_help();
            exit(0);
        case 'f':
            output_format = optarg;
            break;
        default:
            exit(1);
        }
    }

    std::string input_filename;
    std::string output_filename("ogr_out");
    int remaining_args = argc - optind;
    if (remaining_args > 2) {
        std::cerr << "Usage: " << argv[0] << " [OPTIONS] [INFILE [OUTFILE]]" << std::endl;
        exit(1);
    } else if (remaining_args == 2) {
        input_filename =  argv[optind];
        output_filename = argv[optind+1];
    } else if (remaining_args == 1) {
        input_filename =  argv[optind];
    } else {
        input_filename = "-";
    }

    index_type index_pos;
    location_handler_type location_handler(index_pos);
    osmium::experimental::FlexReader<location_handler_type> exr(input_filename, location_handler, osmium::osm_entity_bits::object);

    MyOGRHandler ogr_handler(output_format, output_filename);

    while (auto buffer = exr.read()) {
        osmium::apply(buffer, ogr_handler);
    }

    exr.close();

    std::vector<const osmium::Relation*> incomplete_relations = exr.collector().get_incomplete_relations();
    if (!incomplete_relations.empty()) {
        std::cerr << "Warning! Some member ways missing for these multipolygon relations:";
        for (const auto* relation : incomplete_relations) {
            std::cerr << " " << relation->id();
        }
        std::cerr << "\n";
    }

    google::protobuf::ShutdownProtobufLibrary();
}
Beispiel #16
0
po::variables_map ParseCommandLineOptions(int argc, char* argv[])
{/*{{{*/

    ////////////////////////////////////////////////////////////////////////////////
    //{{{ record command line options
    string output_filename("EnsNVeBath");
    string command_opt("");
    for(int i=1; i<argc; ++i)
        command_opt += argv[i];
    cout << "Command line options recieved: " << command_opt << endl;
    output_filename += command_opt;
    //}}}
    ////////////////////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////////
    //{{{ Set path
    char *env_path = std::getenv("CCE_PROJ_PATH");
    if(env_path!=NULL)
    {
        PROJECT_PATH = env_path;
        cout << "PROJECT_PATH got from environment varialbe: ";
    }
    else
    {
        char pwd[500];
        getcwd(pwd, sizeof(pwd));
        PROJECT_PATH = pwd;
        cout << "PROJECT_PATH set as present working directory (pwd): ";
    }
    cout << PROJECT_PATH << endl;

    LOG_PATH    = PROJECT_PATH + "/dat/log/";
    INPUT_PATH  = PROJECT_PATH + "/dat/input/";
    OUTPUT_PATH = PROJECT_PATH + "/dat/output/";
    CONFIG_PATH = PROJECT_PATH + "/dat/config/";
    DEBUG_PATH  = PROJECT_PATH + "/dat/debug/";
    //}}}
    ////////////////////////////////////////////////////////////////////////////////


    ////////////////////////////////////////////////////////////////////////////////
    //{{{ Parse command line options
    po::variables_map para;
    po::options_description desc("Allowed options");
    desc.add_options()
        ("help,h", "Print help message")
        ("input,i",          po::value<string>()->default_value("None"),                 "Input file name (not used)")
        ("output,o",         po::value<string>()->default_value(output_filename),        "Output .mat file of results")
        ("logfile,l",        po::value<string>()->default_value("EnsembleCCE.conf"),     "Config. file of logging")
        
        ("position,P",       po::value<string>()->default_value("0.0 0.0 0.0"),          "Central spin position")
        ("state0,a",         po::value<int>()->default_value(0),                         "Central spin state index - a")
        ("state1,b",         po::value<int>()->default_value(1),                         "Central spin state index - b")

        ("cce,c",            po::value<int>()->default_value(3),                         "CCE order")
        ("cutoff,d",         po::value<double>()->default_value(300.0),                  "Cut-off distance of bath spins")
        ("polarization,z",   po::value<string>()->default_value("0.0 0.0 0.0"),          "bath spin polarization")
        ("dephasing_rate,r", po::value<double>()->default_value(10000.0),                "dephasing rate of bath spins")
        ("dephasing_axis,x", po::value<string>()->default_value("1.0 1.0 1.0"),          "dephasing axis of bath spins")

        ("length,L",         po::value<double>()->default_value(3.57),                   "size of unit cell in angstrom (default diamond)")
        ("num_cell,u",       po::value<int>()->default_value(8),                         "atom num in unit cell (default diamond)")
        ("concentration,C",  po::value<double>()->default_value(1.0),                    "bath concentration in ppm")
        ("max_number,M",     po::value<int>()->default_value(2000),                      "Max bath spin number")
        ("number,N",         po::value<int>()->default_value(100),                       "bath spin number")
        ("seed,D",           po::value<int>()->default_value(1),                         "bath seed")
        ("isotope",          po::value<string>()->default_value("E"),                    "bath spin isotope")

        ("nTime,n",          po::value<int>()->default_value(101),                       "Number of time points")
        ("start,s",          po::value<double>()->default_value(0.0),                    "Start time (in unit of sec.)")
        ("finish,f",         po::value<double>()->default_value(0.0002),                  "Finish time (in unit of sec.)")
        ("magnetic_field,B", po::value<string>()->default_value("0.1 0.1 0.1"),          "magnetic field vector in Tesla")
        ("pulse,p",          po::value<string>()->default_value("CPMG"),                 "Pulse name")
        ("pulse_num,m",      po::value<int>()->default_value(1),                         "Pulse number")
        ;

    po::store(parse_command_line(argc, argv, desc), para);
    ifstream ifs("config.cfg");
    if (ifs!=NULL)
        po::store(parse_config_file(ifs,desc),para);
    else
        cout << "No configure file found." << endl;
    po::notify(para);    

    PrintVariableMap(para);

    if (para.count("help")) {
        cout << desc;
        exit(0);
    }
    //}}}
    ////////////////////////////////////////////////////////////////////////////////
    return para;
}/*}}}*/
Beispiel #17
0
int
export_png_rgb_16(image *i, output *output)
{
	const char *fn;
	int shouldclose;
	png_structp png_ptr;
	png_infop info_ptr;
	png_uint_32 n, x, y, pi;
	pixelref src;
	colour rgb;
	png_bytep pp;
	uint16_t *bp;
	FILE *fp;
	pixel_converter_fn converter;
	
	converter = convert_pixels(i->format, PF_RGB, 16);
	if(!converter)
	{
		fprintf(stderr, "cannot locate a suitable format converter for RGB-16\n");
		return -1;
	}
	fn = output_filename(output, i, &shouldclose);
	fp = fopen(fn, "wb");
	if(!fp)
	{
		return -1;
	}
	png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
	if(!png_ptr)
	{
		return -1;
	}
	info_ptr = png_create_info_struct(png_ptr);
	if(!info_ptr)
	{
		return -1;
	}
	png_init_io(png_ptr, fp);
	png_set_IHDR(png_ptr, info_ptr, i->width, i->height, 16, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
	png_write_info(png_ptr, info_ptr);
	
	pp = (png_bytep) malloc(i->width * 3 * sizeof(uint16_t));
	bp = (uint16_t *) pp;
	src.pixel[0] = i->pixels[0];
	src.pixel[1] = i->pixels[1];
	src.pixel[2] = i->pixels[2];
	for(y = 0, pi = 0; y < i->height; y++)
	{
		for(n = 0, x = 0; x < i->width; x++, pi++)
		{
			converter(src, &rgb);
			src.pixel[0]++;
			src.pixel[1]++;
			src.pixel[2]++;
			bp[n] = htons(rgb.p.rgb.r);
			n++;
			bp[n] = htons(rgb.p.rgb.g);
			n++;
			bp[n] = htons(rgb.p.rgb.b);
			n++;
		}
		png_write_row(png_ptr, pp);
	}
	png_write_end(png_ptr, NULL);
	free(pp);
	fclose(fp);
	png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
	png_destroy_write_struct(&png_ptr, NULL);
	return 0;
}
int main(int argc, char **argv)
{
  try
  {
    TCLAP::CmdLine cmd("Clips elements based on a hyperplane", ' ', "1.0");

    TCLAP::ValueArg<std::string> log_filename("l","logfile", "Log file name (default is convert.log)", false, "convert.log", "string");
    cmd.add( log_filename );

    TCLAP::ValueArg<std::string> input_filetype("","inputtype", "Input file type. Can be\nauto - ViennaMesh automatically detects the file format (default)\nvtk - for VTK files\nmesh - for Netgen .mesh files\npoly - for Tetgen .poly files\ndeva - for GTS deva files", false, "auto", "string");
    cmd.add( input_filetype );

    TCLAP::ValueArg<std::string> output_filetype("","outputtype", "Output file type. Can be\nauto - ViennaMesh automatically detects the file format (default)\nvtk - for VTK files\nvmesh - for Vienna vmesh files", false, "auto", "string");
    cmd.add( output_filetype );


    TCLAP::ValueArg<std::string> hyperplane_point_string("p","hyperplane_point", "Point of the clip hyperplane", true, "", "string");
    cmd.add( hyperplane_point_string );

    TCLAP::ValueArg<std::string> hyperplane_normal_string("n","hyperplane_normal", "Normal vector of the clip hyperplane", true, "", "string");
    cmd.add( hyperplane_normal_string );


    TCLAP::UnlabeledValueArg<std::string> input_filename( "input-filename", "Input file name", true, "", "InputFile"  );
    cmd.add( input_filename );

    TCLAP::UnlabeledValueArg<std::string> output_filename( "output-filename", "Output file name", true, "", "OutputFile"  );
    cmd.add( output_filename );

    cmd.parse( argc, argv );


    viennamesh::logger().register_callback( new viennamesh::FileStreamCallback<viennamesh::FileStreamFormater>( log_filename.getValue() ) );

    viennamesh::algorithm_handle reader( new viennamesh::io::mesh_reader() );
    reader->set_input( "filename", input_filename.getValue() );
    if (input_filetype.isSet() && (input_filetype.getValue() != "auto"))
      reader->set_input( "file_type", input_filetype.getValue() );
    reader->run();


    viennamesh::dynamic_point hyperplane_point = viennamesh::dynamic_point_from_string( hyperplane_point_string.getValue() );
    viennamesh::dynamic_point hyperplane_normal = viennamesh::dynamic_point_from_string( hyperplane_normal_string.getValue() );


    viennamesh::algorithm_handle clip( new viennamesh::hyperplane_clip() );
    clip->set_input( "mesh", reader->get_output("mesh") );
    clip->set_input( "hyperplane_point", hyperplane_point );
    clip->set_input( "hyperplane_normal", hyperplane_normal );
    clip->run();


    viennamesh::algorithm_handle writer( new viennamesh::io::mesh_writer() );
    writer->set_input( "mesh", clip->get_output("mesh") );
    writer->set_input( "filename", output_filename.getValue() );
    if (output_filetype.isSet() && (output_filetype.getValue() != "auto"))
      writer->set_input( "file_type", output_filetype.getValue() );
    writer->run();
  }
  catch (TCLAP::ArgException &e)  // catch any exceptions
  {
    std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
  }

  return 0;
}
int main(int argc, char **argv)
{
  try
  {
    TCLAP::CmdLine cmd("Maps/Renames segments", ' ', "1.0");

    TCLAP::ValueArg<std::string> log_filename("l","logfile", "Log file name (default is convert.log)", false, "convert.log", "string");
    cmd.add( log_filename );

    TCLAP::ValueArg<std::string> input_filetype("","inputtype", "Input file type. Can be\nauto - ViennaMesh automatically detects the file format (default)\nvtk - for VTK files\nmesh - for Netgen .mesh files\npoly - for Tetgen .poly files\ndeva - for GTS deva files", false, "auto", "string");
    cmd.add( input_filetype );

    TCLAP::ValueArg<std::string> output_filetype("","outputtype", "Output file type. Can be\nauto - ViennaMesh automatically detects the file format (default)\nvtk - for VTK files\nvmesh - for Vienna vmesh files", false, "auto", "string");
    cmd.add( output_filetype );


    TCLAP::ValueArg<std::string> segment_mapping_string("m","segment-mapping", "Segment mapping. Syntax: \"src_id,dst_id;src_id,dst_id\"", true, "", "string");
    cmd.add( segment_mapping_string );


    TCLAP::UnlabeledValueArg<std::string> input_filename( "input-filename", "Input file name", true, "", "InputFile"  );
    cmd.add( input_filename );

    TCLAP::UnlabeledValueArg<std::string> output_filename( "output-filename", "Output file name", true, "", "OutputFile"  );
    cmd.add( output_filename );

    cmd.parse( argc, argv );


    viennamesh::logger().register_callback( new viennamesh::FileStreamCallback<viennamesh::FileStreamFormater>( log_filename.getValue() ) );

    viennamesh::algorithm_handle reader( new viennamesh::io::mesh_reader() );
    reader->set_input( "filename", input_filename.getValue() );
    if (input_filetype.isSet() && (input_filetype.getValue() != "auto"))
      reader->set_input( "file_type", input_filetype.getValue() );
    reader->run();




    std::map<int, int> segment_mapping;

    std::list<std::string> split_mappings = stringtools::split_string( segment_mapping_string.getValue(), ";" );
    for (std::list<std::string>::const_iterator mit = split_mappings.begin(); mit != split_mappings.end(); ++mit)
    {
      std::list<std::string> from_to = stringtools::split_string( *mit, "," );
      std::list<std::string>::const_iterator it = from_to.begin();

      if (it == from_to.end())
        continue;

      int src_segment_id = lexical_cast<int>(*it);

      ++it;
      if (it == from_to.end())
        continue;

      int dst_segment_id = lexical_cast<int>(*it);

      segment_mapping[src_segment_id] = dst_segment_id;
    }


    viennamesh::algorithm_handle map_segments( new viennamesh::map_segments() );
    map_segments->set_input( "mesh", reader->get_output("mesh") );
    map_segments->set_input( "segment_mapping", segment_mapping );
    map_segments->run();


    viennamesh::algorithm_handle writer( new viennamesh::io::mesh_writer() );
    writer->set_input( "mesh", map_segments->get_output("mesh") );
    writer->set_input( "quantities", reader->get_output("quantities") );
    writer->set_input( "filename", output_filename.getValue() );
    if (output_filetype.isSet() && (output_filetype.getValue() != "auto"))
      writer->set_input( "file_type", output_filetype.getValue() );
    writer->run();
  }
  catch (TCLAP::ArgException &e)  // catch any exceptions
  {
    std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
  }

  return 0;
}
Beispiel #20
0
int main() {
    //std::vector<int> items = {1,2,3,4,5,6,7,8,9,10};

    std::string filename("sampleEmbedding_200.txt");
    //std::string filename("iris.data");
    std::vector< std::vector<double> > items = load_data(filename);

    // generate similarity matrix
    unsigned int size = items.size();
    Eigen::MatrixXd m = Eigen::MatrixXd::Zero(size,size);
    std::cout << "------------" << std::endl;

    for (unsigned int i=0; i < size; i++) {
        for (unsigned int j=0; j < size; j++) {
            // generate similarity
            //int d = items[i] - items[j];
	    double d = eculidean_distance(items[i], items[j]);
            int similarity = exp(-d*d / 1);
            m(i,j) = similarity;
            m(j,i) = similarity;
        }
    }

    // the number of eigenvectors to consider. This should be near (but greater) than the number of clusters you expect. Fewer dimensions will speed up the clustering
    int numDims = size;

    // do eigenvalue decomposition
    SpectralClustering* c = new SpectralClustering(m, numDims);

    // whether to use auto-tuning spectral clustering or kmeans spectral clustering
    bool autotune = false;

    std::vector<std::vector<int> > clusters;
    if (autotune) {
        // auto-tuning clustering
        clusters = c->clusterRotate();
    } else {
        // how many clusters you want
        int numClusters = 10;
        clusters = c->clusterKmeans(numClusters);
    }

    // output clustered items
    // items are ordered according to distance from cluster centre
    for (unsigned int i=0; i < clusters.size(); i++) {
        std::cout << "Cluster " << i << ": " << "Item ";
        std::copy(clusters[i].begin(), clusters[i].end(), std::ostream_iterator<int>(std::cout, ", "));
        std::cout << std::endl;
    }
	std::map<int, int> sampleid_to_clusterid;
    for (unsigned int i = 0; i < clusters.size(); i++) {
    	for (unsigned int j = 0; j < clusters[i].size(); j++){
		sampleid_to_clusterid.insert(std::make_pair(clusters[i][j], i));
	}
    }
    
    std::string output_filename("sample_assignment.txt");

    std::ofstream out(output_filename.c_str(), std::ios::out);
    if(!out) {
    	std::cerr << "Can't open output file " << output_filename << std::endl;
    	return 0;
    }
    std::map<int, int>::iterator it;
    for(it = sampleid_to_clusterid.begin(); it != sampleid_to_clusterid.end(); it++) {
    	out << it->second << std::endl;
    }
    out.close();
   
}
void motion_output(long *imos, ///< index of model stage (I)
			long *imsn, ///< index of m.s. node on current model stage (I)
			double *ts, ///< time at m.s. node (I)
			double *te, ///< time at end of m.s. interval (I)
			double *sd, ///< differential states at m.s. node (I)
			double *sa, ///< algebraic states at m.s. node (I)
			double *u, ///< controls at m.s. node (I)
			double *udot, ///< control slopes at m.s. node (I)
			double *ue, ///< controls at end of m.s. interval (I)
			double *uedot, ///< control slopes at end of m.s. interval (I)
			double *p_free, ///< global model parameters (I)
			double *pr, ///< local i.p.c. parameters (I)
			double *ccxd, double *mul_ccxd, ///< multipliers of continuity conditions (I)
	#if defined(PRSQP) || defined(EXTPRSQP)
			double *ares, double *mul_ares,
	#endif
			double *rd, double *mul_rd, ///< multipliers of decoupled i.p.c. (I)
			double *rc, double *mul_rc, ///< multipliers of coupled i.p.c. (I)
			double *obj, double *rwh, ///< real work array (I)
			long *iwh ///< integer work array (I)
			) {
	FILE *fp;
	stringstream output_filename("");
	// Filename
	char problemname[50];
	get_pname(problemname);
	output_filename << "./RES/" << problemname <<".mot";
	if ((*imsn == 0) && (*imos == 0))
				fp = fopen(output_filename.str().c_str(), "w");
			else
				fp = fopen(output_filename.str().c_str(), "a");
			if (!fp) {
				fprintf(stderr, "Error: Could not open file '%s'!\n",
						output_filename.str().c_str());
				return;
			}
		/* Create and reset file when we're in the first MS-knot.
		 * otherwise just append data
		 */
		if ((*imsn == 0) && (*imos == 0)) {
			// write header:
			/// Get names of model quantities.
			char **xd_name[1];  /* differential state names (O) */
			char **xa_name[1];  /* algebraic state names (O) */
			char **u_name[1];   /* control names (O) */
			char **h_name[1];   /* model stage duration names (O) */
			char **p_name[1];   /* global model parameter names (O) */
			char *of_name[1];   /* objective name (O) */
			get_names(xd_name, xa_name, u_name, h_name, p_name, of_name);
			// Objective:
			fprintf(fp, "COT: %e\n", *obj);
			// Print parameters first:
			fprintf(fp, "//");
			for (int i = 0; i<NPFree; i++){
				fprintf(fp, "%s\t",p_name[0][i]);
			}
			fprintf(fp, "\n");
			for (int i = 0; i<NPFree; i++){
				fprintf(fp, "%e\t",p_free[i]);
			}
			fprintf(fp, "\n");
			// States and timing:
			fprintf(fp, "//imos\t");
			fprintf(fp, "imsn\t");
			fprintf(fp, "time\t");
			for (int i = 0; i<NY; i++){
				fprintf(fp, "%s\t",xd_name[0][i]);
			}
			for (int i = 0; i<NU; i++){
				fprintf(fp, "%s\t",u_name[0][i]);
			}
			fprintf(fp, "\n");
		}
		fprintf(fp, "%li\t", *imos);
		fprintf(fp, "%li\t", *imsn);
		fprintf(fp, "%e\t", *ts);
		for (int i = 0; i<NY; i++){
			fprintf(fp, "%e\t",sd[i]);
		}
		for (int i = 0; i<NU; i++){
			fprintf(fp, "%e\t",u[i]);
		}
		fprintf(fp, "\n");
		// Close file
		fclose(fp);
}
Beispiel #22
0
int main(int argc, char** argv)
{
    
    // abort if the user didn't pass the correct number of command line args
    if (argc != 4)
    {
        
        fprintf
        (
            stderr,
            "Error! Invalid command line arguments.\n"
            "Usage: %s [initial_grid.png] [output_pattern] [iterations]\n",
            argv[0]
        );
        
        return -1;
        
    } else if (argc > 4) {
        
        fprintf
        (
            stderr,
            "Warning! Ignoring all but the first 3 command line arguments\n"
            "Usage: %s [initial_grid.png] [output_pattern] [iterations]\n",
            argv[0]
        );
        
    }
    
    // detect the number of iterations
    unsigned iterations = atoi(argv[3]);
    if (iterations < 1)
    {
        fprintf(stderr, "Error! Iteration count must be at least 1\n");
        return -1;
    }
    
    unsigned width;
    unsigned height;
    
    // double buffered cell memory.
    // cell_grid_read is NULL to tell pngrw_read_file() to allocate new memory for us
    unsigned char* cell_grid_read = NULL;
    unsigned char* cell_grid_write;
    
    // attempt to load the inital cell grid.  cell_grid_read will be allocated
    unsigned bytes = pngrw_read_file(&cell_grid_read, &width, &height, argv[1]);
    if (bytes == 0)
        // error messages printed from inside pngrw_read_file()
        return -1;
    
    if (width < 1)
    {
        fprintf(stderr, "Error! %s must have a width >= 1\n", argv[1]);
        delete[] cell_grid_read;
        return -1;
    }
    
    if (height < 1)
    {
        fprintf(stderr, "Error! %s must have a height >= 1\n", argv[1]);
        delete[] cell_grid_read;
        return -1;
    }
    
    // we're double buffering, pngrw_read_file only allocated the input buffer
    cell_grid_write = new unsigned char[bytes];
    // need to init to 0 so valgrind won't complain (it can't track single-bit initializations)
    memset(cell_grid_write, 0, bytes);
    
    // simulate the cell grid for 'iterations' steps
    output_filename_t output_filename(argv[2], iterations);
    
    double start = get_timestamp();
    for (unsigned ix = 0; ix < iterations; ix++)
    {
        
        // simulate one time step (generation)
        recalculate_grid_cpu(cell_grid_write, cell_grid_read, width, height);
        
        // write the new cell grid to a png file
        pngrw_write_file
        (
            output_filename.str,
            cell_grid_write,
            width,
            height
        );
        
        output_filename.next_filename();
        
        // swap buffers
        unsigned char* swap = cell_grid_read;
        cell_grid_read = cell_grid_write;
        cell_grid_write = swap;
        
    }
    double elapsed_sec = get_timestamp() - start;
    
    // cleanup
    delete[] cell_grid_read;
    delete[] cell_grid_write;
    
    printf
    (
        "Success! Finished %s ~ %u iterations in %lf seconds ~ %lf cells/sec\n",
        argv[1],
        iterations,
        elapsed_sec,
        ((double)width * (double)height * (double)iterations) / elapsed_sec
    );
    
    return 0;
    
}
int main(int argc, char *argv[])
{
	int iOS = 0;
	char *pInputFile = NULL;
	char *pOutputFile = NULL;

	/*      Figure out arguments.
	 *      [REQUIRED] First argument is input file.
	 *      [OPTIONAL] Second argument is output file.
	 */
	if(argc > 1)    {
		FILE *pInputStream = NULL;
		FILE *pOutputStream = NULL;

		/*      Form respective filenames.
		 */
		pInputFile = input_filename(argv[1]);
		pOutputFile = output_filename(pInputFile, argc > 2 ? argv[2] : NULL);

		if(pInputFile == NULL)  {
			fprintf(stderr, "MANTOMAK:  Unable to form input filename\n");
			iOS = 1;
		}
		else    {
			pInputStream = fopen(pInputFile, "rb");
			if(pInputStream == NULL)        {
				fprintf(stderr, "MANTOMAK:  Unable to open input file %s\n", pInputFile);
				iOS = 1;
			}
		}
		if(pOutputFile == NULL) {
			fprintf(stderr, "MANTOMAK:  Unable to form output filename\n");
			iOS = 1;
		}
		else if(pInputStream != NULL)   {
			pOutputStream = fopen(pOutputFile, "wt");
			if(pOutputStream == NULL)       {
				fprintf(stderr, "MANTOMAK:  Unable to open output file %s\n", pOutputFile);
				iOS = 1;
			}
		}

		/*      Only do the real processing if our error code is not
		 *              already set.
		 */
		if(iOS == 0)    {
			iOS = input_to_output(pInputStream, pOutputStream);
		}

		if(pInputStream != NULL)        {
			fclose(pInputStream);
			pInputStream = NULL;
		}
		if(pOutputStream != NULL)       {
			fclose(pOutputStream);
			pOutputStream = NULL;
		}
	}
	else    {
		help();
		iOS = 1;
	}

	if(pInputFile)  {
		free(pInputFile);
		pInputFile = NULL;
	}
	if(pOutputFile) {
		free(pOutputFile);
		pOutputFile = NULL;
	}

	return(iOS);
}
Beispiel #24
0
int main(int argc, char* argv[]) {
    const auto& map_factory = osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>::instance();

    static struct option long_options[] = {
        {"help",                 no_argument, 0, 'h'},
        {"format",               required_argument, 0, 'f'},
        {"location_store",       required_argument, 0, 'l'},
        {"list_location_stores", no_argument, 0, 'L'},
        {0, 0, 0, 0}
    };

    std::string output_format { "SQLite" };
    std::string location_store { "sparse_mem_array" };

    while (true) {
        int c = getopt_long(argc, argv, "hf:l:L", long_options, 0);
        if (c == -1) {
            break;
        }

        switch (c) {
            case 'h':
                print_help();
                exit(0);
            case 'f':
                output_format = optarg;
                break;
            case 'l':
                location_store = optarg;
                break;
            case 'L':
                std::cout << "Available map types:\n";
                for (const auto& map_type : map_factory.map_types()) {
                    std::cout << "  " << map_type << "\n";
                }
                exit(0);
            default:
                exit(1);
        }
    }

    std::string input_filename;
    std::string output_filename("ogr_out");
    int remaining_args = argc - optind;
    if (remaining_args > 2) {
        std::cerr << "Usage: " << argv[0] << " [OPTIONS] [INFILE [OUTFILE]]" << std::endl;
        exit(1);
    } else if (remaining_args == 2) {
        input_filename =  argv[optind];
        output_filename = argv[optind+1];
    } else if (remaining_args == 1) {
        input_filename =  argv[optind];
    } else {
        input_filename = "-";
    }

    osmium::io::Reader reader(input_filename);

    std::unique_ptr<index_pos_type> index_pos = map_factory.create_map(location_store);
    index_neg_type index_neg;
    location_handler_type location_handler(*index_pos, index_neg);
    location_handler.ignore_errors();

    MyOGRHandler ogr_handler(output_format, output_filename);

    osmium::apply(reader, location_handler, ogr_handler);
    reader.close();

    int locations_fd = open("locations.dump", O_WRONLY | O_CREAT, 0644);
    if (locations_fd < 0) {
        throw std::system_error(errno, std::system_category(), "Open failed");
    }
    index_pos->dump_as_list(locations_fd);
    close(locations_fd);
}
int main(int argc, char **argv)
{
  try
  {
    TCLAP::CmdLine cmd("Geometrically transforms a mesh", ' ', "1.0");

    TCLAP::ValueArg<std::string> log_filename("l","logfile", "Log file name (default is convert.log)", false, "convert.log", "string");
    cmd.add( log_filename );

    TCLAP::ValueArg<std::string> input_filetype("","inputtype", "Input file type. Can be\nauto - ViennaMesh automatically detects the file format (default)\nvtk - for VTK files\nmesh - for Netgen .mesh files\npoly - for Tetgen .poly files\ndeva - for GTS deva files", false, "auto", "string");
    cmd.add( input_filetype );

    TCLAP::ValueArg<std::string> output_filetype("","outputtype", "Output file type. Can be\nauto - ViennaMesh automatically detects the file format (default)\nvtk - for VTK files\nvmesh - for Vienna vmesh files", false, "auto", "string");
    cmd.add( output_filetype );


    TCLAP::ValueArg<std::string> matrix_string("m","matrix", "Translate matrix", false, "", "string");
    cmd.add( matrix_string );

    TCLAP::ValueArg<double> scale("s","scale", "Scale the mesh", false, 0.0, "double");
    cmd.add( scale );

    TCLAP::ValueArg<std::string> translate_string("t","translate", "Translate the mesh", false, "", "string");
    cmd.add( translate_string );



    TCLAP::UnlabeledValueArg<std::string> input_filename( "input-filename", "Input file name", true, "", "InputFile"  );
    cmd.add( input_filename );

    TCLAP::UnlabeledValueArg<std::string> output_filename( "output-filename", "Output file name", true, "", "OutputFile"  );
    cmd.add( output_filename );

    cmd.parse( argc, argv );


    viennamesh::logger().register_callback( new viennamesh::FileStreamCallback<viennamesh::FileStreamFormater>( log_filename.getValue() ) );

    viennamesh::algorithm_handle reader( new viennamesh::io::mesh_reader() );
    reader->set_input( "filename", input_filename.getValue() );
    if (input_filetype.isSet() && (input_filetype.getValue() != "auto"))
      reader->set_input( "file_type", input_filetype.getValue() );
    reader->run();


    int dimension = lexical_cast<int>(reader->get_output("mesh")->get_property("geometric_dimension").first);

    viennamesh::algorithm_handle transform( new viennamesh::affine_transform() );

    viennamesh::dynamic_point matrix(dimension*dimension, 0.0);

    for (int i = 0; i < dimension; ++i)
      matrix[dimension*i+i] = 1.0;

    if ( matrix_string.isSet() )
    {
      matrix = stringtools::vector_from_string<double>( matrix_string.getValue() );
    }
    else if (scale.isSet())
    {
      for (int i = 0; i < dimension*dimension; ++i)
        matrix[i] *= scale.getValue();
    }

    viennamesh::dynamic_point translate( dimension, 0.0 );
    if ( translate_string.isSet() )
    {
      translate = stringtools::vector_from_string<double>( translate_string.getValue() );
    }

    transform->set_input( "mesh", reader->get_output("mesh") );
    transform->set_output( "mesh", reader->get_output("mesh") );
    transform->set_input( "matrix", matrix );
    transform->set_input( "translate", translate );

    transform->run();


    viennamesh::algorithm_handle writer( new viennamesh::io::mesh_writer() );
    writer->set_input( "mesh", transform->get_output("mesh") );
    writer->set_input( "quantities", reader->get_output("quantities") );
    writer->set_input( "filename", output_filename.getValue() );
    if (output_filetype.isSet() && (output_filetype.getValue() != "auto"))
      writer->set_input( "file_type", output_filetype.getValue() );
    writer->run();
  }
  catch (TCLAP::ArgException &e)  // catch any exceptions
  {
    std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
  }

  return 0;
}
/*********************************
 * Output Functions
 *********************************/
void figureview_output(long *imos, ///< index of model stage (I)
		long *imsn, ///< index of m.s. node on current model stage (I)
		double *ts, ///< time at m.s. node (I)
		double *te, ///< time at end of m.s. interval (I)
		double *sd, ///< differential states at m.s. node (I)
		double *sa, ///< algebraic states at m.s. node (I)
		double *u, ///< controls at m.s. node (I)
		double *udot, ///< control slopes at m.s. node (I)
		double *ue, ///< controls at end of m.s. interval (I)
		double *uedot, ///< control slopes at end of m.s. interval (I)
		double *p_free, ///< global model parameters (I)
		double *pr, ///< local i.p.c. parameters (I)
		double *ccxd, double *mul_ccxd, ///< multipliers of continuity conditions (I)
#if defined(PRSQP) || defined(EXTPRSQP)
		double *ares, double *mul_ares,
#endif
		double *rd, double *mul_rd, ///< multipliers of decoupled i.p.c. (I)
		double *rc, double *mul_rc, ///< multipliers of coupled i.p.c. (I)
		double *obj, double *rwh, ///< real work array (I)
		long *iwh ///< integer work array (I)
		) {
	FILE *fp;
	stringstream output_filename("");
	const char* fv_header_state_names = "# Time\n"
			"# LowerTrunk_TX\n"
			"# LowerTrunk_TY\n"
			"# LowerTrunk_RZ\n"
			"# UpperLeg_R_RZ\n"
			"# UpperLeg_R_TY\n"
			"# UpperLeg_L_RZ\n"
			"# UpperLeg_L_TY\n"
			"# LowerLeg_R_RZ\n"
			"# LowerLeg_R_TY\n"
			"# LowerLeg_L_RZ\n"
			"# LowerLeg_L_TY\n";
	// Filename
	output_filename << "./RES/" << figureview_file_name;

	/* Create and reset file when we're in the first MS-knot.
	 * otherwise just append data
	 */
	if ((*imsn == 0) && (*imos == 0)) {
		fp = fopen(output_filename.str().c_str(), "w");

		if (!fp) {
			fprintf(stderr, "Error: Could not open file '%s'!\n",
					output_filename.str().c_str());
			return;
		}

		// Write the header of the figureview file

		fprintf(
				fp,
				"# JAFV Format: DOF_0 DOF_1 ... DOF_N TAG0_x TAG0_y ... TAGN_z\n");
		fprintf(fp, "# Format for cal3dview:\n");

		fprintf(fp, "# MODEL hopper\n");
		fprintf(fp, "# SYMMETRIC_DATA\n");
		fprintf(fp, "# BEGIN_FORMAT\n");
		// the degrees of freedom
		fprintf(fp, "%s", fv_header_state_names);
		fprintf(fp, "# END_FORMAT\n");
		// More header information
		fprintf(
				fp,
				"#\n#\n# Articulating biped hopper\n#\n# Variables per frame: \n#\n# %d\n#\n",
				1 + NQ + 2);
	} else {
		fp = fopen(output_filename.str().c_str(), "a");

		if (!fp) {
			fprintf(stderr, "Error: Could not open file '%s'!\n",
					output_filename.str().c_str());
			return;
		}
	}

	// Write a line of data:
	fprintf(fp, "%e\t", *ts);
	fprintf(fp, "%e\t", sd[x]);
	fprintf(fp, "%e\t", sd[y]);
	fprintf(fp, "%e\t", sd[phi]);
	fprintf(fp, "%e\t", sd[alphaR]);
	fprintf(fp, "0\t");
	fprintf(fp, "%e\t", sd[alphaL]);
	fprintf(fp, "0\t");
	fprintf(fp, "0\t");
	fprintf(fp, "%e\t", 1 - sd[betaR]);
	fprintf(fp, "0\t");
	fprintf(fp, "%e\t", 1 - sd[betaL]);
	fprintf(fp, "\n");
	// Close file
	fclose(fp);
}