예제 #1
0
int main(int argc, char **)
{
    printf("// auto generated\n"
           "// DO NOT EDIT.\n\n");
    if ( argc > 1 )
        makeTable(pp_keywords);
    else
        makeTable(keywords);
    return 0;
}
예제 #2
0
TableRopeScene::TableRopeScene(fs::path ropeFile, bool telekinesis) : GrabbingScene(telekinesis) {
//  vector<double> firstJoints = doubleVecFromFile((KNOT_DATA / "init_joints_train.txt").string());
//  ValuesInds vi = getValuesInds(firstJoints);
//  setupDefaultROSRave();
//  pr2m->pr2->setDOFValues(vi.second, vi.first);
  vector<int> indices(1,pr2m->pr2->robot->GetJointIndex("torso_lift_joint"));
  vector<double> values(1, .31);
  pr2m->pr2->setDOFValues(indices, values);
  vector<btVector3> tableCornersWorld = toBulletVectors(floatMatFromFile((KNOT_DATA / "table_corners.txt").string())) * METERS;
  vector<btVector3> controlPointsWorld = toBulletVectors(floatMatFromFile(ropeFile.string())) * METERS;

  PlotPoints::Ptr corners(new PlotPoints(20));
  corners->setPoints(tableCornersWorld);
  env->add(corners);

  m_table = makeTable(tableCornersWorld, .1*GeneralConfig::scale);
  float seglen = controlPointsWorld[0].distance(controlPointsWorld[1]);

//  m_rope.reset(new CapsuleRope(controlPointsWorld, fmin(seglen/4.1,.0075*METERS)));
  m_rope.reset(new CapsuleRope(controlPointsWorld, .0075*METERS));
  env->add(m_rope);
  env->add(m_table);
  setGrabBodies(m_rope->children);
  
  
}
예제 #3
0
void interactive()
{
	HashTable* ht = makeTable(22);
	for (unsigned i = 0; i < 27; ++i) {
		ht = insertTable(ht, namen[i], rand() % 100);
	}
	printHashTable(ht);
	while (1) {
		unsigned i;
		printf( "Insert (2) or search (1) or delete (0)? " );
		scanf(  "%u", &i );
		if (i == 2) {
			printf( "Name: " );
			char* name = getline();
			unsigned telNr;
			printf( "Telephone-Nr.: " );
			scanf("%u", &telNr);
			ht = insertTable(ht, name, telNr);
			printHashTable(ht);
		} else if (i == 1) {
			printf( "Name: " );
			char* name = getline();
			unsigned* telNr = searchTable(ht, name);
			printf( "Telephone-Nr.: %u\n", *telNr );
		} else {
			printf( "Name: " );
			char* name = getline();
			deleteTable(ht, name);
			printHashTable(ht);
		}
	}
}
예제 #4
0
void HuffmanCoder::makeTable(Node* root, std::vector<std::vector<bool> > &table, std::vector<bool> &code)
{

    if (!root->isLeaf()) {
        code.push_back(0);
        makeTable(root->left_child_, table, code);
        code.push_back(1);
        makeTable(root->right_child_, table, code);
    }
    else {
        unsigned char c = root->symbol_;
        if (code.empty())
            code.push_back(0);
        table[c] = code;
    }
    code.pop_back();
}
예제 #5
0
파일: tests.c 프로젝트: SaidinWoT/hash
bool test_duplicate_insert_overrides() {
    Table * t = makeTable();
    hset(t, "Key", "A");
    hset(t, "Key", "B");
    char* returned = hget(t, "Key");
    ASSERT(returned != 0, "Table returned null on duplicate insert");
    ASSERT(returned[0] != 'A', "Table returned old value on duplicate insert");
    ASSERT(returned[0] == 'B', "Table returned wrong value on duplicate insert");
    freeTable(t); 
    return true;
}
예제 #6
0
int main()
{
	int rows;
	int cols;
	int c;
	//scanf("%d %d\n", &rows, &cols);
	scanf("%d", &rows);
	scanf("%d", &cols);
	while ((c = getchar()) != '\n');
	if(rows < 0 || cols < 0)				//error check for senseless lengths of rows or columns
	{
		fprintf(stderr,"Error: Invalid number of columns or rows.");
		exit(2);
	}
	else
	{
		rows = rows + 2;					//rows and cols incremented to add border around
		cols = cols + 2;
		int **table = makeTable(rows, cols);
		int tableFilled = fillTable(table, rows, cols);
		if(tableFilled == 0)
		{
			int **workTable = makeWorkTable(table, rows, cols);
			int temp = 1;
			if(findStartPos(table, workTable, rows, cols))
			{
				fillTableWithPaths(workTable, rows, cols);
				temp = findEndPos(table, workTable, rows, cols);
			}
			
			if(temp == 0 || temp == 1)
			{
				int i, j;
				for(i = 1; i < rows - 1; i++)				//print the maze with the path and without the border
				{
					for(j = 1; j < cols - 1; j++)
					{
						printf("%c", table[i][j]);
					}
					printf("%s", "\n");
				}
			}
			freeSpace(table, workTable, rows);
		}
		else
		{
			fprintf(stderr,"Error: Invalid input with the specified rows and columns.");
			exit(2);
		}
	}
	return 0;
}
예제 #7
0
QString TableMakerHTML::getHTMLCode()
{
    QString value;
    value = QString("<html>\n<body>\n") + QString("<h1>Results:</h1>\n");
    if (protons.is_set){
        value += QString("<h2>Protons:</h2>\n");
        value += makeTable(protons);
        if (!cProtons.empty())
            value += makeCoeff(cProtons);
    }
    if (deutrons.is_set){
        value += QString("<h2>Deutrons:</h2>\n");
        value += makeTable(deutrons);
        if (!cDeutrons.empty())
            value += makeCoeff(cDeutrons);
    }
    if (tritons.is_set){
        value += QString("<h2>Tritons:</h2>\n");
        value += makeTable(tritons);
        if (!cTritons.empty())
            value += makeCoeff(cTritons);
    }
    if (He3s.is_set){
        value += QString("<h2>Helium-3:</h2>\n");
        value += makeTable(He3s);
        if (!cHe3s.empty())
            value += makeCoeff(cHe3s);
    }
    if (alphas.is_set){
        value += QString("<h2>Alphas:</h2>\n");
        value += makeTable(alphas);
        if (!cAlphas.empty())
            value += makeCoeff(cAlphas);
    }
    value += "</body>\n";
    value += "</html>";
    return value;
}
예제 #8
0
int *findShortestEndPos(int** workTable, int rows, int cols)
{
	int endPos = 0;
	int i;
	int j;
	for(i = 0; i < rows; i++)
	{
		for(j = 0; j < cols; j++)
		{
			if(workTable[i][j] == end)
			{
				endPos++;
			}
		}
	}
	numOfEnds = endPos;
	if(endPos != 0)
	{
		endPosArr = makeTable(endPos,3);		//table of endPos [{i, j, shortestLength},..]
		int counter = 0;
		for(i = 0; i < rows; i++)
		{
			for(j = 0; j < cols; j++)
			{
				if(workTable[i][j] == end)
				{
					endPosArr[counter][0] = i;
					endPosArr[counter][1] = j;
					endPosArr[counter][2] = findShortestDistNeighbor(workTable, i, j);
					counter++;
				}
			}
		}
		int* minEndPos = endPosArr[0];
		int min = endPosArr[0][2];
		for(i = 1; i < endPos; i++)
		{
			if((endPosArr[i][2] < min || min < 0) && endPosArr[i][2] >= 0)
			{
				minEndPos = endPosArr[i];
				min = endPosArr[i][2];
			}
		}
		if(minEndPos[2] >= 0)
		{
			return minEndPos;
		}
	}
	return NULL;
}
void hgLoadItemAttr(char *db, char* table, char* itemAttrFile)
/* hgLoadItemAttr - load an itemAttr table. */
{
struct sqlConnection *conn = sqlConnect(db);
struct itemAttr* itemAttrs;
char tabFile[PATH_LEN];
safef(tabFile, sizeof(tabFile), "%s.%s", table, "tab");

itemAttrs = loadAttrFile(itemAttrFile);
writeTabFile(itemAttrs, tabFile);
makeTable(conn, table);
sqlLoadTabFile(conn, tabFile, table, SQL_TAB_FILE_ON_SERVER);
sqlDisconnect(&conn);
unlink(tabFile);
}
예제 #10
0
파일: tests.c 프로젝트: SaidinWoT/hash
bool test_remove() {
    Table * t = makeTable();
    hset(t, "Key", "A");

    char *returned = hget(t, "Key");

    ASSERT(returned != 0, "Table returned null after setting");

    hdel(t, "Key");
    
    returned = hget(t, "Key");
    //missing key returns empty string?
    ASSERT(returned[0] == 0, "Table returned non-null");

    return true;
}
예제 #11
0
파일: tests.c 프로젝트: SaidinWoT/hash
bool test_segfault_during_delete() {
    Table * t = makeTable();
    char * key1 = "0";
    char * key2 = "8";

    ASSERT( (hash(key1) % t->size) == (hash(key2) % t->size), "Keys will not collide. Update keys for this test.")

    hset(t, key1, "asdf");
    hset(t, key2, "asdf");

    hdel(t, key2);
    hdel(t, key1); // This segfaults

    freeTable(t);

    return true;
}
예제 #12
0
TupleBox::TupleBox(value::Tuple* t) :
    Gtk::Dialog("Tuple", true, true),
    mValue(t)
{
    add_button(Gtk::Stock::APPLY, Gtk::RESPONSE_APPLY);
    add_button(Gtk::Stock::OK, Gtk::RESPONSE_CANCEL);

    mScroll = new Gtk::ScrolledWindow();
    mScroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
    get_vbox()->pack_start(*mScroll);

    mTable = new Gtk::Table(mValue->size(), 1, true);
    mScroll->add(*mTable);
    makeTable();
    resize(300, 200);

    show_all();
}
예제 #13
0
void HuffmanCoder::startCompressing()
{

    std::vector<unsigned int> freqs_arr(number_of_symbols_, 0);
	countFreqs(freqs_arr);
	
    std::unique_ptr<Node> p_root = Tree::makeTree(freqs_arr);

    std::vector<bool> code;
    std::vector<std::vector<bool> > sym_table(number_of_symbols_);

    makeTable(p_root.get(), sym_table, code);

    writeHeaderToOutput(freqs_arr);

    writeCompressedData(sym_table);



}
예제 #14
0
파일: MatrixBox.cpp 프로젝트: SJasson/vle
MatrixBox::MatrixBox(value::Matrix* m) :
    Gtk::Dialog(_("Matrix"), true, true),
    mValue(m)
{
    add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    add_button(Gtk::Stock::OK, Gtk::RESPONSE_APPLY);

    mBackup = mValue->clone();

    mScroll = new Gtk::ScrolledWindow();
    mScroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
    get_vbox()->pack_start(*mScroll);

    mTable = new Gtk::Table(m->rows(), m->columns(), true);
    mScroll->add(*mTable);
    makeTable();
    resize(300, 200);

    show_all();
}
예제 #15
0
TableRopeScene::TableRopeScene(const vector<btVector3> &tableCornersWorld_, const vector<btVector3>& controlPointsWorld, bool telekinesis) : GrabbingScene(telekinesis), tableCornersWorld(tableCornersWorld_) {
  vector<int> indices(1,pr2m->pr2->robot->GetJointIndex("torso_lift_joint"));
  vector<double> values(1, .31);
  pr2m->pr2->setDOFValues(indices, values);
  PlotPoints::Ptr corners(new PlotPoints(20));
  corners->setPoints(tableCornersWorld);
  env->add(corners);

  m_table = makeTable(tableCornersWorld, .1*GeneralConfig::scale);
  float seglen = controlPointsWorld[0].distance(controlPointsWorld[1]);

  m_rope.reset(new CapsuleRope(
    controlPointsWorld,
    .005*METERS, // radius
    .5, // angStiffness
    1, // angDamping
    .9, // linDamping
    .8, // angLimit
    .9 // linStopErp
  ));
  env->add(m_rope);
  env->add(m_table);
  setGrabBodies(m_rope->children);
}
예제 #16
0
void AnalogView::InitObject(BRect rt, int cpu)
{
	rt.OffsetTo(B_ORIGIN);
	param.cpu = cpu;

	system_info		sysInfo;
	
	get_system_info(&sysInfo);
	oldActiveTime = sysInfo.cpu_infos[cpu].active_time; 
	oldSystemTime = system_time();
	nowCPUTime = 0;
	oldCPUTime = -1;

	param.panelLength = rt.Width() / 2 - 3 * 7;
	param.needle = (rt.Width() / 2 - 3 * 7) * 0.93;
	param.meterCenter.Set(rt.Width() / 2, param.panelLength + 3 * 8);
	makeTable();
	
	makePanel(rt);

	SetViewColor(216, 216, 216);
	SetLowColor(216, 216, 216);
	SetHighColor(0, 0, 0);
}
예제 #17
0
void textTable() {

  TString histname = "sbs_eff_EtDet_EtaDet";
  TString infile[4] = {"root_electroneff_WenuOff_eta_et.root", 
		       "root_electroneff_WenuOn_eta_et.root",
		       "root_electroneff_ZeeOff_eta_et.root",
		       "root_electroneff_ZeeOn_eta_et.root"};


//   TString infile[40] = {"root_electroneff_1_eta_et.root",
// 			"root_electroneff_2_eta_et.root", 
// 			"root_electroneff_3_eta_et.root",
// 			"root_electroneff_4_eta_et.root",
// 			"root_electroneff_5_eta_et.root",
// 			"root_electroneff_6_eta_et.root",
// 			"root_electroneff_7_eta_et.root",
// 			"root_electroneff_8_eta_et.root",
// 			"root_electroneff_101_eta_et.root",
// 			"root_electroneff_102_eta_et.root", 
// 			"root_electroneff_103_eta_et.root",
// 			"root_electroneff_104_eta_et.root",
// 			"root_electroneff_105_eta_et.root",
// 			"root_electroneff_106_eta_et.root",
// 			"root_electroneff_107_eta_et.root",
// 			"root_electroneff_108_eta_et.root",
// 			"root_electroneff_201_eta_et.root",
// 			"root_electroneff_202_eta_et.root", 
// 			"root_electroneff_203_eta_et.root",
// 			"root_electroneff_204_eta_et.root",
// 			"root_electroneff_205_eta_et.root",
// 			"root_electroneff_206_eta_et.root",
// 			"root_electroneff_207_eta_et.root",
// 			"root_electroneff_208_eta_et.root",
// 			"root_electroneff_301_eta_et.root",
// 			"root_electroneff_302_eta_et.root", 
// 			"root_electroneff_303_eta_et.root",
// 			"root_electroneff_304_eta_et.root",
// 			"root_electroneff_305_eta_et.root",
// 			"root_electroneff_306_eta_et.root",
// 			"root_electroneff_307_eta_et.root",
// 			"root_electroneff_308_eta_et.root",
// 			"root_electroneff_401_eta_et.root",
// 			"root_electroneff_402_eta_et.root", 
// 			"root_electroneff_403_eta_et.root",
// 			"root_electroneff_404_eta_et.root",
// 			"root_electroneff_405_eta_et.root",
// 			"root_electroneff_406_eta_et.root",
// 			"root_electroneff_407_eta_et.root",
// 			"root_electroneff_408_eta_et.root"};
  
  // auxiliary variables
  TString tablefile = "";
  TString rootfile  = "";

  TString pname[4] = { "table-WenuOff.txt", 
		       "table-WenuOn.txt", 
		       "table-ZeeOff.txt", 
		       "table-ZeeOn.txt"};

//   TString pname[40] = { "elec-eff-table-WenuSelection-A1.txt", 
// 		       "elec-eff-table-WenuSelection-A2.txt",
// 		       "elec-eff-table-WenuSelection-A3.txt",
// 		       "elec-eff-table-WenuSelection-B1.txt",
// 		       "elec-eff-table-WenuSelection-B2.txt",
// 		       "elec-eff-table-WenuSelection-B3.txt",
// 		       "elec-eff-table-ZeeSelection-A.txt",
// 		       "elec-eff-table-ZeeSelection-B.txt",
// 		       "elec-eff-table-WenuSelection-A1-noId.txt", 
// 		       "elec-eff-table-WenuSelection-A2-noId.txt",
// 		       "elec-eff-table-WenuSelection-A3-noId.txt",
// 		       "elec-eff-table-WenuSelection-B1-noId.txt",
// 		       "elec-eff-table-WenuSelection-B2-noId.txt",
// 		       "elec-eff-table-WenuSelection-B3-noId.txt",
// 		       "elec-eff-table-ZeeSelection-A-noId.txt",
// 		       "elec-eff-table-ZeeSelection-B-noId.txt",
// 		       "elec-eff-table-WenuSelection-A1-noTrackIso.txt", 
// 		       "elec-eff-table-WenuSelection-A2-noTrackIso.txt",
// 		       "elec-eff-table-WenuSelection-A3-noTrackIso.txt",
// 		       "elec-eff-table-WenuSelection-B1-noTrackIso.txt",
// 		       "elec-eff-table-WenuSelection-B2-noTrackIso.txt",
// 		       "elec-eff-table-WenuSelection-B3-noTrackIso.txt",
// 		       "elec-eff-table-ZeeSelection-A-noTrackIso.txt",
// 		       "elec-eff-table-ZeeSelection-B-noTrackIso.txt",
// 		       "elec-eff-table-WenuSelection-A1-noIso.txt", 
// 		       "elec-eff-table-WenuSelection-A2-noIso.txt",
// 		       "elec-eff-table-WenuSelection-A3-noIso.txt",
// 		       "elec-eff-table-WenuSelection-B1-noIso.txt",
// 		       "elec-eff-table-WenuSelection-B2-noIso.txt",
// 		       "elec-eff-table-WenuSelection-B3-noIso.txt",
// 		       "elec-eff-table-ZeeSelection-A-noIso.txt",
// 			"elec-eff-table-ZeeSelection-B-noIso.txt",
// 			"elec-eff-table-WenuSelection-A1-noSigmaEtaEta.txt", 
// 		       "elec-eff-table-WenuSelection-A2-noSigmaEtaEta.txt",
// 		       "elec-eff-table-WenuSelection-A3-noSigmaEtaEta.txt",
// 		       "elec-eff-table-WenuSelection-B1-noSigmaEtaEta.txt",
// 		       "elec-eff-table-WenuSelection-B2-noSigmaEtaEta.txt",
// 		       "elec-eff-table-WenuSelection-B3-noSigmaEtaEta.txt",
// 		       "elec-eff-table-ZeeSelection-A-noSigmaEtaEta.txt",
// 		       "elec-eff-table-ZeeSelection-B-noSigmaEtaEta.txt"};


  for(int i=0; i<4; i++) {

    tablefile =  pname[i];
    rootfile  = infile[i];
    makeTable (rootfile, histname, tablefile);
  }
  
}
예제 #18
0
파일: main.c 프로젝트: DLuCJ/miscellaneous
int main() {

  printf("Hello\n");
  printf("Enter a command followed by a number between 0 and 999 inclusive to perform operation on hash table\n");
  printf("Valid commands are: insert #, delete #, search #, list #.\n");
  printf("Enter searchlist to print entire table\n");
  printf("Enter term to print table and exit .\n");
  
  Hashtable * newTable = makeTable(10);
  char * regex = " \n";

  char str [100];
  while(1) {
  
    printf("Enter: ");
    char * result = fgets(str, 100, stdin);
    char * token1 = strtok(result, regex);
    char * token2 = strtok(NULL, regex);
    
    long long val;
    if(token2 != NULL) {
      char * end_ptr = 0;
      val = strtoll(token2,&end_ptr,10);
      if((end_ptr != 0 && *end_ptr != '\n' && *end_ptr != '\0') || overflow(val)){
	printf("Error: invalid input. %s is outside valid range (0 - 999)\n", token2);
	continue;
      }
    }

    if(token1 == NULL) {
      printf("Error: invalid input. \n");
      continue;
    } else if(strcasecmp(token1,"searchlist") == 0) {
      hashListFull(newTable);
    } else if(strcasecmp(token1, "term") == 0) {
      hashListFull(newTable);
      term(newTable);
      printf("You've been terminated\n");
      break;
    } else if(strcasecmp(token1,"insert") == 0) {
      if(token2 == NULL) {
        printf("Error: No number listed\n");
        continue;
      }
      if(hashInsert(val,newTable)) {
	printf("True \n");
      } else {
	printf("False \n");
      }
    }else if(strcasecmp(token1,"search") == 0) {
      if(token2 == NULL) {
        printf("Error: No number listed\n");
        continue;
      }
      if(search(val,newTable)) {
	printf("True\n");
      } else {
	printf("False\n");
      }
    }else if(strcasecmp(token1,"delete") == 0){
      if(token2 == NULL) {
        printf("Error: No number listed\n");
        continue;
      }
      if(hashDelete(val,newTable)) {
	printf("True \n");
      } else {
	printf("False\n");
      }
    }else if(strcasecmp(token1, "list") == 0) {
      if(token2 == NULL) {
	printf("Error: No index listed\n");
	continue;
      }  
      if(isNull(hash(val),newTable)) {
	printf("False\n");
      }else {
	printf("List #%i :", hash(val));
	hashList(hash(val),newTable);
	printf("\n");
      }  
    }else{
      printf("Error: invalid input. %s is not recognized keyword: insert, search,list,delete\n", token1);
      continue;
    }
  }
  
  return 0;
}
예제 #19
0
void compareEleEffPlots() {
     
  for(int i=0; i<4; i++) {  makeTable(i);  }   
}
예제 #20
0
int main(int argc, char *argv[]) {

  // command line options
  GeneralConfig::scale = 10;
  SceneConfig::enableIK = SceneConfig::enableHaptics = false;
  SceneConfig::enableRobot = true;
  
  Parser parser;
  parser.addGroup(TrackingConfig());
  parser.addGroup(RecordingConfig());
  parser.addGroup(GeneralConfig());
  parser.addGroup(BulletConfig());
  parser.addGroup(SceneConfig());
  parser.read(argc,argv);


  // comm stuff
  initComm();
  FileSubscriber pcSub("kinect","pcd");
  CloudMessage cloudMsg;
  FileSubscriber ropeSub("rope_pts","pcd");
  CloudMessage ropeMsg;
  FileSubscriber labelSub("labels","png");
  ImageMessage labelMsg;
  FileSubscriber endSub("rope_ends","txt");
  VecVecMessage<float> endMsg;
  FileSubscriber jointSub("joint_states","txt");
  Retimer<VectorMessage<double> > retimer(&jointSub);


  Scene scene;
  PR2Manager pr2m(scene);
  MonitorForGrabbing lMonitor(pr2m.pr2->robot->GetManipulators()[5], scene.env->bullet->dynamicsWorld);
  MonitorForGrabbing rMonitor(pr2m.pr2->robot->GetManipulators()[7], scene.env->bullet->dynamicsWorld);

  vector<double> firstJoints = doubleVecFromFile(filePath("data000000000000.txt", "joint_states").string());
  ValuesInds vi = getValuesInds(firstJoints);
  pr2m.pr2->setDOFValues(vi.second, vi.first);

  // get kinect transform
  KinectTrans kinectTrans(pr2m.pr2->robot);
  kinectTrans.calibrate(btTransform(btQuaternion(0.669785, -0.668418, 0.222562, -0.234671), btVector3(0.263565, -0.038203, 1.762524)));
  CoordinateTransformer CT(kinectTrans.getKinectTrans());

  // load table
  /////////////// load table
  vector<btVector3> tableCornersCam = toBulletVectors(floatMatFromFile(onceFile("table_corners.txt").string()));
  vector<btVector3> tableCornersWorld = CT.toWorldFromCamN(tableCornersCam);
  BulletObject::Ptr table = makeTable(tableCornersWorld, .1*GeneralConfig::scale);
  table->setColor(1,1,1,.25);

  // load rope
  vector<btVector3> ropePtsCam = toBulletVectors(floatMatFromFile(onceFile("init_rope.txt").string()));
  CapsuleRope::Ptr rope(new CapsuleRope(CT.toWorldFromCamN(ropePtsCam), .0075*METERS));

  // plots
  PointCloudPlot::Ptr kinectPts(new PointCloudPlot(2));
  CorrPlots corrPlots;

  // setup scene
  if (TrackingConfig::showKinect) scene.env->add(kinectPts);
  scene.env->add(rope);
  scene.env->add(table);
  if (TrackingConfig:: showLines) scene.env->add(corrPlots.m_lines);
  lMonitor.setBodies(rope->children);
  rMonitor.setBodies(rope->children);

  // recording
  ScreenRecorder* rec;
  if (RecordingConfig::record != DONT_RECORD){
    rec = new ScreenRecorder(scene.viewer);
  }


  // end tracker
  vector<RigidBodyPtr> rope_ends;
  rope_ends.push_back(rope->bodies[0]);
  rope_ends.push_back(rope->bodies[rope->bodies.size()-1]);
  MultiPointTrackerRigid endTracker(rope_ends,scene.env->bullet->dynamicsWorld);
  TrackerPlotter trackerPlotter(endTracker);
  //scene.env->add(trackerPlotter.m_fakeObjects[0]);
  //scene.env->add(trackerPlotter.m_fakeObjects[1]);

  scene.startViewer();
  scene.setSyncTime(true);

  scene.idle(true);

  vector<double> oldvals, newvals;
  int count=0;
  while (pcSub.recv(cloudMsg)) {
    ENSURE(ropeSub.recv(ropeMsg));
    vector<btVector3> obsPts = CT.toWorldFromCamN(toBulletVectors(ropeMsg.m_data));
    ENSURE(labelSub.recv(labelMsg));
    cv::Mat labels = toSingleChannel(labelMsg.m_data);
    ENSURE(endSub.recv(endMsg));
    vector<btVector3> newEnds = CT.toWorldFromCamN(toBulletVectors(endMsg.m_data));
    endTracker.update(newEnds);
    trackerPlotter.update();

    ColorCloudPtr cloudCam  = cloudMsg.m_data;
    ColorCloudPtr cloudWorld(new ColorCloud());
    pcl::transformPointCloud(*cloudCam, *cloudWorld, CT.worldFromCamEigen);
    kinectPts->setPoints1(cloudWorld);
    cout << "loaded cloud " << count << endl;
    count++;


    VectorMessage<double>* jointMsgPtr = retimer.msgAt(cloudMsg.getTime());
    vector<double> currentJoints = jointMsgPtr->m_data;
    ValuesInds vi = getValuesInds(currentJoints);
    newvals = vi.first;
    if (oldvals.size()==0) {
      cout << "first one" << endl;
      oldvals = newvals;
    }


    CT.reset(kinectTrans.getKinectTrans());


    cv::Mat ropeMask = toSingleChannel(labels) == 1;

    for (int iter=0; iter<TrackingConfig::nIter; iter++) {
      cout << "iteration " << iter << endl;

      pr2m.pr2->setDOFValues(vi.second, interpolateBetween(oldvals, newvals, (iter+0.00001)/TrackingConfig::nIter));

      vector<btVector3> estPts = rope->getNodes();
      Eigen::MatrixXf ropePtsCam = toEigenMatrix(CT.toCamFromWorldN(estPts));
      vector<float> pVis = calcVisibility(rope->bodies, scene.env->bullet->dynamicsWorld, CT.worldFromCamUnscaled.getOrigin()*METERS, TrackingConfig::sigA*METERS, TrackingConfig::nSamples); 
      colorByVisibility(rope, pVis);
      SparseArray corr = toSparseArray(calcCorrProb(toEigenMatrix(estPts), toEigenMatrix(obsPts), toVectorXf(pVis), TrackingConfig::sigB*METERS, TrackingConfig::outlierParam),TrackingConfig::cutoff);
      corrPlots.update(estPts, obsPts, corr);
      vector<btVector3> impulses = calcImpulsesSimple(estPts, obsPts, corr, TrackingConfig::impulseSize);
      applyImpulses(impulses, rope);

      if (RecordingConfig::record == EVERY_ITERATION || 
	  RecordingConfig::record == FINAL_ITERATION && iter==TrackingConfig::nIter-1)
	    rec->snapshot();

      lMonitor.update();
      rMonitor.update();

      scene.step(DT);
    }
    oldvals = newvals;

  }
}
예제 #21
0
파일: hencode.c 프로젝트: mduhon/CPE357
int main(int argc, char *argv[]) {

unsigned char *buf;
int inFile, num, elem, outFile;
node *head;
node *arr[charMax];
node *indexArr[charMax];

    head = NULL;
    elem = 0;
    buf = malloc(RW_MAX * sizeof(unsigned char));
    if(!buf) {
        perror("malloc");
        exit(4);
    }
    if( argc < 2 ) {
        printf("Usage: inFile [outFile]\n");
        exit(1);
    }
    else { 
        if((inFile = open(argv[1],  O_RDONLY, S_IRUSR )) < 0) {
            perror("can't open inFile");
            exit(2);
        }
        
        if(argc == 3) {
            if((outFile = open(argv[2],  O_WRONLY | O_TRUNC | O_CREAT,
                               S_IRUSR | S_IWUSR )) < 0) {
                perror("can't open outFile");
                exit(2);
            }
        }else if(argc == 2) {
            outFile = STDOUT_FILENO;
        }
        while((num=read(inFile, buf, RW_MAX)) > 0) {
            head = addChars(head, buf, num, &elem);
        }
        
        if(!head) {
            if((write(outFile, &num, sizeof(int))) < 0) {
                 perror("write");
                exit(3);
             }
             if(close(inFile)){
                perror("close");
                exit(47);
            }
            if(close(outFile)){
                perror("close");
                exit(47);
            }
        }else {
            if(elem > charMax)
                elem = charMax;
            makeTable(head, arr);
            arrSort(arr, elem);
            head = createTree(head);
            traverseTree(head);
            arrangeCharArr(arr, indexArr,  elem);

/* prints the table to the start of the file */
            if(head) {
                printTable(arr, elem, outFile);
                lseek(inFile, 0, 0);
                while((num=read(inFile, buf, RW_MAX)) > 0) {
                    encode(buf, num, outFile, indexArr);  
                }
            }
            if(close(inFile)){
                perror("close");
                exit(47);
            }
            if(close(outFile)){
                perror("close");
                exit(47);
            }
        }
    }
    for(num = 0; num < elem; num++) {
        free(arr[num]);
    }
    free(buf);
    return 0; 
}
void MainWindow::start()
{
    mainScreen=new QStackedWidget();
    widget=new QWidget(this);
    widgetKeys=new QWidget(this);
    widget2=new QWidget(this);
    widgetTop=new QWidget(this);
//    camera=new QCameraControllerWidget(this);
    layout=new QGridLayout();
    layout2=new QGridLayout();
    layoutTop=new QGridLayout();
    amount=new QTextEdit(this);
    price=new QTextEdit(this);
    go=new QPushButton(this);
    buy=new QRadioButton(this);
    sell=new QRadioButton(this);
    market = new QComboBox(this);
    exchange = new QComboBox(this);
    exchange->addItem(tr("Bitmarket"));
    exchange->addItem(tr("Bitmaszyna"));
    widget->setLayout(layout);
    widgetTop->setLayout(layoutTop);
    mainScreen->addWidget(widget);
    mainScreen->addWidget(widgetKeys);
//    mainScreen->addWidget(camera);
    mainScreen->setCurrentIndex(0);
    setCentralWidget(mainScreen);
//    setCentralWidget(camera);
    //qview = new QQuickView();
    //qview->setResizeMode(QQuickView::SizeRootObjectToView);
    //qview->rootContext()->setContextProperty("closeView", closeView());
    //qview->setSource(QUrl("qrc:///camera.qml"));
    /*Table model;
    MyModel model2;
    model2.setData(model2.index(0,0), "Data 1", MyModel::price);
    model2.setData(model2.index(0,0), "Data 1", MyModel::amount);
    model2.setData(model2.index(1,0), "Data 2", MyModel::price);
    model2.setData(model2.index(1,0), "Data 2", MyModel::amount);
    qview->engine()->rootContext()->setContextProperty("theModel", &model);
    qview->engine()->rootContext()->setContextProperty("themodel2", &model2);
    qview->setSource(QUrl("qrc:///main.qml"));
    if ((width()==200)||(width()==640)) {
        resize(360,600);
        qview->resize(360,600);
    }*/
    /*QWidget *container = QWidget::createWindowContainer(qview);
    QSize ss;
    ss.setWidth(width());
    ss.setHeight(height());
    container->setMinimumSize(ss);
    container->setMaximumSize(ss);
    container->setFocusPolicy(Qt::TabFocus);
    mainScreen->addWidget(container);*/
    //widgetLayout->addWidget(container);
    //log(QString::number(width()).toStdString());
    //view->show();
    scalex=width()/480.0;
    scaley=height()/800.0;
    font.setPixelSize(12*scaley);
    font2.setPixelSize(16*scaley);
    buy->setChecked(true);
    buy->setText("Kup");
    buy->setFont(font2);
    sell->setText("Sprzedaj");
    sell->setFont(font2);
    go->setText("Wykonaj");
    go->setFont(font2);
    bidtable=makeTable();
    asktable=makeTable();
    populate();
    layout->setContentsMargins(0,0,0,0);
    layout2->setContentsMargins(0,0,0,0);
    layoutTop->setContentsMargins(0,0,0,0);
    widget2->setLayout(layout2);
    widget2->setFixedHeight(70*scaley);
    widgetTop->setFixedHeight(50*scaley);
    buy->setFixedWidth(120*scalex);
    sell->setFixedWidth(120*scalex);
    amount->setFixedWidth(100*scalex);
    amount->setFixedHeight(36*scalex);
    price->setFixedWidth(100*scalex);
    price->setFixedHeight(36*scalex);
    go->setFixedWidth(100*scalex);
    layoutTop->addWidget(exchange,0,0);
    layoutTop->addWidget(market,0,1);
    layout2->addWidget(buy,0,0);
    layout2->addWidget(sell,1,0);
    layout2->addWidget(amount,0,1,2,1);
    layout2->addWidget(price,0,2,2,1);
    layout2->addWidget(go,0,3,2,1);
    layout->addWidget(widgetTop,0,1);
    layout->addWidget(asktable,1,1);
    layout->addWidget(widget2,2,0,1,3);
    layout->addWidget(bidtable,3,1);
    connect(exchange,SIGNAL(currentIndexChanged(int)),this,SLOT(changeEx(int)));
    connect(market,SIGNAL(currentIndexChanged(int)),this,SLOT(changeMarket(int)));
    menu=menuBar()->addMenu(tr("Menu"));
    trade = new QAction(tr("&Trade"), this);
    trade->setStatusTip(tr("Trade"));
    connect(trade, SIGNAL(triggered()), this, SLOT(tradeWindow()));
    menu->addAction(trade);
    keys = new QAction(tr("&Keys"), this);
    keys->setStatusTip(tr("Keys"));
    connect(keys, SIGNAL(triggered()), this, SLOT(keysWindow()));
    menu->addAction(keys);
    exit = new QAction(tr("&Exit"), this);
    exit->setStatusTip(tr("Exit"));
    connect(exit, SIGNAL(triggered()), this, SLOT(quit()));
    menu->addAction(exit);
    /*
    camera=new QCamera(this);
    QCameraViewfinder *camview = new QCameraViewfinder(this);
    camera->setViewfinder(camview);
    mainScreen->addWidget(camview);
    setCentralWidget(camview);
    camera->start();*/
    //keysWindow();
    /*
    Table model;
    QQmlApplicationEngine engine;
    engine.rootContext()->setContextProperty("themodel", &model);
    engine.load(QUrl("qrc:/main.qml"));
    QList<QObject*> temp = engine.rootObjects();
    QObject *topLevel = temp.value(0);
    QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
    if ( !window ) {
        qWarning("Error: Your root item has to be a Window.");
        //return -1;
     }
    window->show();*/
    //QZXing qr;
    //log(":"+qr.decodeImageFromFile("qr2.png").toStdString());
    //log(":"+QString::number(qr.getProcessTimeOfLastDecoding()).toStdString());
/*    model=new QStandardItemModel(4, 4);
    for (int row = 0; row < 4; ++row) {
        for (int column = 0; column < 4; ++column) {
            QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column));
            model->setItem(row, column, item);
        }
    }*/
}
예제 #23
0
int main(){

  RooFitResult f1 = getRes();

  RooArgList final_std_list = f1.floatParsFinal();

  Float_t a_std[14];
  a_std[0] = ((RooAbsReal*)final_std_list.find("Kst2z1430_amp"))->getVal();
  a_std[1] = ((RooAbsReal*)final_std_list.find("Kst2z1430_phase"))->getVal();
  a_std[2] = ((RooAbsReal*)final_std_list.find("Kstm1430_amp"))->getVal();
  a_std[3] = ((RooAbsReal*)final_std_list.find("Kstm1430_phase"))->getVal();
  a_std[4] = ((RooAbsReal*)final_std_list.find("Kstminus_amp"))->getVal();
  a_std[5] = ((RooAbsReal*)final_std_list.find("Kstminus_phase"))->getVal();
  a_std[6] = ((RooAbsReal*)final_std_list.find("Kstz1430_amp"))->getVal();
  a_std[7] = ((RooAbsReal*)final_std_list.find("Kstz1430_phase"))->getVal();
  a_std[8] = ((RooAbsReal*)final_std_list.find("Kstzero_amp"))->getVal();
  a_std[9] = ((RooAbsReal*)final_std_list.find("Kstzero_phase"))->getVal();
  a_std[10] = ((RooAbsReal*)final_std_list.find("Rho1700_amp"))->getVal();
  a_std[11] = ((RooAbsReal*)final_std_list.find("Rho1700_phase"))->getVal();
  a_std[12] = ((RooAbsReal*)final_std_list.find("c1"))->getVal();
  a_std[13] = ((RooAbsReal*)final_std_list.find("c2"))->getVal();

  Float_t err_std[14];
  err_std[0] = ((RooRealVar*)final_std_list.find("Kst2z1430_amp"))->getError();
  err_std[1] = ((RooRealVar*)final_std_list.find("Kst2z1430_phase"))->getError();
  err_std[2] = ((RooRealVar*)final_std_list.find("Kstm1430_amp"))->getError();
  err_std[3] = ((RooRealVar*)final_std_list.find("Kstm1430_phase"))->getError();
  err_std[4] = ((RooRealVar*)final_std_list.find("Kstminus_amp"))->getError();
  err_std[5] = ((RooRealVar*)final_std_list.find("Kstminus_phase"))->getError();
  err_std[6] = ((RooRealVar*)final_std_list.find("Kstz1430_amp"))->getError();
  err_std[7] = ((RooRealVar*)final_std_list.find("Kstz1430_phase"))->getError();
  err_std[8] = ((RooRealVar*)final_std_list.find("Kstzero_amp"))->getError();
  err_std[9] = ((RooRealVar*)final_std_list.find("Kstzero_phase"))->getError();
  err_std[10] = ((RooRealVar*)final_std_list.find("Rho1700_amp"))->getError();
  err_std[11] = ((RooRealVar*)final_std_list.find("Rho1700_phase"))->getError();
  err_std[12] = ((RooRealVar*)final_std_list.find("c1"))->getError();
  err_std[13] = ((RooRealVar*)final_std_list.find("c2"))->getError();

  Float_t stat_matrix[14][14];
  Float_t TOT_matrix[14][14];
  Float_t TOT_syst_matrix[14][14];

  for(Int_t j=0;j<14;j++){
    for(Int_t k=0;k<14;k++){
      stat_matrix[j][k] = f1.correlation( *((RooAbsReal*)final_std_list.at(j)) , *((RooAbsReal*)final_std_list.at(k)) )*err_std[j]*err_std[k];
      TOT_matrix[j][k] = stat_matrix[j][k];
      TOT_syst_matrix[j][k] = 0.;
    }
  }

  /*
  TFile f("toynomix_theRes.root");
  RooFitResult *toyres = (RooFitResult*)f.Get("nll");
  RooArgList toy_std_list = toyres->floatParsFinal();
  Float_t toy_std[14];
  toy_std[0] = ((RooAbsReal*)toy_std_list.find("Kst2z1430_amp"))->getVal();
  toy_std[1] = ((RooAbsReal*)toy_std_list.find("Kst2z1430_phase"))->getVal();
  toy_std[2] = ((RooAbsReal*)toy_std_list.find("Kstm1430_amp"))->getVal();
  toy_std[3] = ((RooAbsReal*)toy_std_list.find("Kstm1430_phase"))->getVal();
  toy_std[4] = ((RooAbsReal*)toy_std_list.find("Kstminus_amp"))->getVal();
  toy_std[5] = ((RooAbsReal*)toy_std_list.find("Kstminus_phase"))->getVal();
  toy_std[6] = ((RooAbsReal*)toy_std_list.find("Kstz1430_amp"))->getVal();
  toy_std[7] = ((RooAbsReal*)toy_std_list.find("Kstz1430_phase"))->getVal();
  toy_std[8] = ((RooAbsReal*)toy_std_list.find("Kstzero_amp"))->getVal();
  toy_std[9] = ((RooAbsReal*)toy_std_list.find("Kstzero_phase"))->getVal();
  toy_std[10] = ((RooAbsReal*)toy_std_list.find("Rho1700_amp"))->getVal();
  toy_std[11] = ((RooAbsReal*)toy_std_list.find("Rho1700_phase"))->getVal();
  toy_std[12] = ((RooAbsReal*)toy_std_list.find("c1"))->getVal();
  toy_std[13] = ((RooAbsReal*)toy_std_list.find("c2"))->getVal();

  Float_t err_toy_std[14];
  err_toy_std[0] = ((RooRealVar*)toy_std_list.find("Kst2z1430_amp"))->getError();
  err_toy_std[1] = ((RooRealVar*)toy_std_list.find("Kst2z1430_phase"))->getError();
  err_toy_std[2] = ((RooRealVar*)toy_std_list.find("Kstm1430_amp"))->getError();
  err_toy_std[3] = ((RooRealVar*)toy_std_list.find("Kstm1430_phase"))->getError();
  err_toy_std[4] = ((RooRealVar*)toy_std_list.find("Kstminus_amp"))->getError();
  err_toy_std[5] = ((RooRealVar*)toy_std_list.find("Kstminus_phase"))->getError();
  err_toy_std[6] = ((RooRealVar*)toy_std_list.find("Kstz1430_amp"))->getError();
  err_toy_std[7] = ((RooRealVar*)toy_std_list.find("Kstz1430_phase"))->getError();
  err_toy_std[8] = ((RooRealVar*)toy_std_list.find("Kstzero_amp"))->getError();
  err_toy_std[9] = ((RooRealVar*)toy_std_list.find("Kstzero_phase"))->getError();
  err_toy_std[10] = ((RooRealVar*)toy_std_list.find("Rho1700_amp"))->getError();
  err_toy_std[11] = ((RooRealVar*)toy_std_list.find("Rho1700_phase"))->getError();
  err_toy_std[12] = ((RooRealVar*)toy_std_list.find("c1"))->getError();
  err_toy_std[13] = ((RooRealVar*)toy_std_list.find("c2"))->getError();

  Float_t stat_toy_matrix[14][14];

  for(Int_t j=0;j<14;j++){
    for(Int_t k=0;k<14;k++){
      stat_toy_matrix[j][k] = toyres->correlation( *((RooAbsReal*)toy_std_list.at(j)) , *((RooAbsReal*)toy_std_list.at(k)) )*err_toy_std[j]*err_toy_std[k];
    }
  }
  */

  //create the systematics matrx, the last element is the number of systematics scenarios
  Float_t sys_matrix[14][14][TOT_syst];
  Int_t index = 0;

  //loop over all the systematics and fill the matrix
  for(Int_t i=0;i<numsyst;i++){

    if(i < first_alone && i % 2 != 0) continue;

    RooFitResult fsyst = getRes(i);
    RooArgList final_syst_list = fsyst.floatParsFinal();

    Float_t a_syst[14];
    Float_t a_syst_plus[14];

    a_syst[0] = ((RooAbsReal*)final_syst_list.find("Kst2z1430_amp"))->getVal();
    a_syst[1] = ((RooAbsReal*)final_syst_list.find("Kst2z1430_phase"))->getVal();
    if(i != slot_LASS){
      a_syst[2] = ((RooAbsReal*)final_syst_list.find("Kstm1430_amp"))->getVal();
      a_syst[3] = ((RooAbsReal*)final_syst_list.find("Kstm1430_phase"))->getVal();
      a_syst[6] = ((RooAbsReal*)final_syst_list.find("Kstz1430_amp"))->getVal();
      a_syst[7] = ((RooAbsReal*)final_syst_list.find("Kstz1430_phase"))->getVal();
    }
    else{
      a_syst[2] = a_std[2];
      a_syst[3] = a_std[3];
      a_syst[6] = a_std[6];
      a_syst[7] = a_std[7];
    }
    a_syst[4] = ((RooAbsReal*)final_syst_list.find("Kstminus_amp"))->getVal();
    a_syst[5] = ((RooAbsReal*)final_syst_list.find("Kstminus_phase"))->getVal();
    a_syst[8] = ((RooAbsReal*)final_syst_list.find("Kstzero_amp"))->getVal();
    a_syst[9] = ((RooAbsReal*)final_syst_list.find("Kstzero_phase"))->getVal();
    if(i != slot_rho){
      a_syst[10] = ((RooAbsReal*)final_syst_list.find("Rho1700_amp"))->getVal();
      a_syst[11] = ((RooAbsReal*)final_syst_list.find("Rho1700_phase"))->getVal();
    }
    else{
      a_syst[10] = a_std[10];
      a_syst[11] = a_std[11];
    }
    a_syst[12] = ((RooAbsReal*)final_syst_list.find("c1"))->getVal();
    a_syst[13] = ((RooAbsReal*)final_syst_list.find("c2"))->getVal();
    
    if(i<first_alone){
      RooFitResult fsyst_plus = getRes(i+1);
      RooArgList final_syst_plus_list = fsyst_plus.floatParsFinal();
      a_syst_plus[0] = ((RooAbsReal*)final_syst_plus_list.find("Kst2z1430_amp"))->getVal();
      a_syst_plus[1] = ((RooAbsReal*)final_syst_plus_list.find("Kst2z1430_phase"))->getVal();
      a_syst_plus[2] = ((RooAbsReal*)final_syst_plus_list.find("Kstm1430_amp"))->getVal();
      a_syst_plus[3] = ((RooAbsReal*)final_syst_plus_list.find("Kstm1430_phase"))->getVal();
      a_syst_plus[6] = ((RooAbsReal*)final_syst_plus_list.find("Kstz1430_amp"))->getVal();
      a_syst_plus[7] = ((RooAbsReal*)final_syst_plus_list.find("Kstz1430_phase"))->getVal();
      a_syst_plus[4] = ((RooAbsReal*)final_syst_plus_list.find("Kstminus_amp"))->getVal();
      a_syst_plus[5] = ((RooAbsReal*)final_syst_plus_list.find("Kstminus_phase"))->getVal();
      a_syst_plus[8] = ((RooAbsReal*)final_syst_plus_list.find("Kstzero_amp"))->getVal();
      a_syst_plus[9] = ((RooAbsReal*)final_syst_plus_list.find("Kstzero_phase"))->getVal();
      a_syst_plus[10] = ((RooAbsReal*)final_syst_plus_list.find("Rho1700_amp"))->getVal();
      a_syst_plus[11] = ((RooAbsReal*)final_syst_plus_list.find("Rho1700_phase"))->getVal();
      a_syst_plus[12] = ((RooAbsReal*)final_syst_plus_list.find("c1"))->getVal();
      a_syst_plus[13] = ((RooAbsReal*)final_syst_plus_list.find("c2"))->getVal();
    }
    
    for(Int_t l=0;l<14;l++){
      for(Int_t m=0;m<14;m++){
	if(i<first_alone){
	  sys_matrix[l][m][index] = (a_syst[l] - a_std[l])*(a_syst[m] - a_std[m])/2. + (a_syst_plus[l] - a_std[l])*( a_syst_plus[m] - a_std[m])/2.;
	  TOT_matrix[l][m] += sys_matrix[l][m][index];
	  TOT_syst_matrix[l][m] += sys_matrix[l][m][index];
	}
	else{
	  sys_matrix[l][m][index] = (a_syst[l]-a_std[l])*(a_syst[m]-a_std[m]);
	  TOT_matrix[l][m] += sys_matrix[l][m][index];
	  TOT_syst_matrix[l][m] += sys_matrix[l][m][index];
	}
      }
    }

    index++;
  } //end of loop over the systematics

  //for(Int_t l=0;l<14;l++){
  //  cov_matrix[l][l] += 0.03*0.03*err_std[l]*err_std[l];
  //}

  //statistical covariance matrix
  makeStatMatrix(stat_matrix);
  //systematics covariance matrix
  makeStatMatrix(TOT_syst_matrix);
  //total covariance matrix
  makeStatMatrix(TOT_matrix);

  //summary table of all systematics contributions
  makeTable(sys_matrix,err_std);
  //summary of the sum of all systematics
  makeTable_TOT(TOT_syst_matrix,err_std);

  //write for toy generation
  writeMatrix(stat_matrix,TOT_matrix);
  make_part(sys_matrix,err_std);

  return 0;
}
예제 #24
0
int main(int argc,char **argv)
{
  FILE *fpi,*fpo;
  char buf[576*2*2];

  static REAL bc[] =
  {1.0,  0,1.0,  0,1.0,  0,1.0,  0,1.0,  0,1.0,  0,1.0,  0,1.0,  0,1.0,  0};

  init(14);
  makeTable(bc,44100);

  if (argc != 3 && argc != 4) exit(-1);

  fpi = fopen(argv[1],"r");
  fpo = fopen(argv[2],"w");

  if (!fpi || !fpo) exit(-1);

  /* generate wav header */

  {
    short word;
    int dword;

    fwrite("RIFF",4,1,fpo);
    dword = 0;
    fwrite(&dword,4,1,fpo);

    fwrite("WAVEfmt ",8,1,fpo);
    dword = 16;
    fwrite(&dword,4,1,fpo);
    word = 1;
    fwrite(&word,2,1,fpo);  /* format category, PCM */
    word = 2;
    fwrite(&word,2,1,fpo);  /* channels */
    dword = 44100;
    fwrite(&dword,4,1,fpo); /* sampling rate */
    dword = 44100*2*2;
    fwrite(&dword,4,1,fpo); /* bytes per sec */
    word = 4;
    fwrite(&word,2,1,fpo);  /* block alignment */
    word = 16;
    fwrite(&word,2,1,fpo);  /* ??? */

    fwrite("data",4,1,fpo);
    dword = 0;
    fwrite(&dword,4,1,fpo);
  }

  preamp = 65536;
  maxamp = 0;

  if (argc == 4) {
    preamp = 32767*65536/atoi(argv[3]);
    fprintf(stderr,"preamp = %d\n",preamp);
  }

  for(;;)
    {
      int n,m;

      n = fread(buf,1,576*2*2,fpi);
      if (n <= 0) break;
      m = modifySamples((short *)buf,n/4,2);
      fwrite(buf,4,m,fpo);
    }

#if 0
  for(;;)
    {
      int n = flushbuf((short *)buf,576);
      if (n == 0) break;
      fwrite(buf,4,n,fpo);
    }
#endif

  {
    short word;
    int dword;
    int len = ftell(fpo);

    fseek(fpo,4,SEEK_SET);
    dword = len-8;
    fwrite(&dword,4,1,fpo);

    fseek(fpo,40,SEEK_SET);
    dword = len-44;
    fwrite(&dword,4,1,fpo);
  }

  if (maxamp != 0) {
    fprintf(stderr,"maxamp = %d\n",maxamp);
  }

  quit();
}
예제 #25
0
파일: index.c 프로젝트: Qued79/Indexer
int main (int argc, char* argv[]){
	
	if(argc!=3){printf("Bad input - incorrect number of arguments\n");return 1;}
	FILE *file= fopen(argv[2],"r");
	if(file==NULL){printf("file/directory given to index does not exist\n");return 1;}
	fclose(file);/*only opened it to check that it existed*/
	file = fopen(argv[1],"r");
	if(file!=NULL){/*Handle the case of being given an output file that already exists. Prompt user for action*/
		char a[15];
		fclose(file);
		printf("Output file exists. Would you like to overwrite it? [y/n]:   ");
		scanf("%c",a);
		if(a[0]!='y'){return 1;}
		     }
	
	
	FILE *outfile= fopen(argv[1],"w+");/*Open the outfile for real this time*/
	table = makeTable();
	ftw(argv[2],applyme,100);/*The ftw function applies the given method [applyme] recursively across directories [and to all files in them]*/
	

	struct Node* curr = table->keylist;
	if(curr==NULL){deleteTable(table); fclose(outfile); return 0;}
	struct Node* next = curr->next; 	
	int size=1,j=0;
	while(next!=NULL){/*Walk across the keylist to get the number of elements in the hashtable - Really only necessary for the output at the end, but helpful for building sortMe*/
		size++;
		curr=next;
		next=curr->next;
	}	
	
	struct hashnode *sortMe[size];/*Will contain the list of hashnodes to be sorted by qsort and then output*/	
	curr = table->keylist;
	for(j=0;j<size;j++){/*Populate the sortMe list*/
		sortMe[j] = search(((struct hashnode*)(curr->data))->key,table);
		curr=curr->next;
	}
	
	qsort(sortMe,size,(sizeof(struct hashnode*)),compareHashNodes);
	
	/*Output in JSON format. This is ugly, but don't blame me, blame JSON*/
	fprintf(outfile,"{\"list\" : [\n");
	for(j=0;j<size;j++){
		if(j==0){fprintf(outfile,"\t\"%s\" : [\n",(sortMe[j]->word));
			fprintf(outfile,"\t\t{\"%s\" : %d}",(sortMe[j]->path),(sortMe[j]->frequency));
			if(j+1==size){fprintf(outfile,"\t]}\n]}\n");break;}
			continue;
			}
		if(strcmp((sortMe[j-1]->word),(sortMe[j]->word))!=0){fprintf(outfile,"\t\"%s\" : [",(sortMe[j]->word));}
		if(strcmp((sortMe[j]->word),(sortMe[j+1]->word))==0){fprintf(outfile,"\n\t\t{\"%s\" : %d},",(sortMe[j]->path),(sortMe[j]->frequency));}
		else{fprintf(outfile,"\n\t\t{\"%s\" : %d}\n\t\t]},\n\n",(sortMe[j]->path),(sortMe[j]->frequency));}
		if(j+2==size){
		if(strcmp((sortMe[j]->word),(sortMe[j+1]->word))!=0){fprintf(outfile,"\t\"%s\" : [",(sortMe[j+1]->word));}	
		fprintf(outfile,"\n\t\t{\"%s\" : %d}",(sortMe[j+1]->path),(sortMe[j+1]->frequency));
		fprintf(outfile,"\n\t]}\n]}\n"); break;}
	}
		
	deleteTable(table);/*Chain reaction data clearing*/
	fclose(outfile);/*Close the output file to finish*/
	
}