void ModelInput::readInputFile(){ // Unwrap the reference: auto &domain = domainRef.get(); auto &solver = domain.getSolver(); if (not ifs.is_open()){ openInputFile(); } std::string dummy = ""; // header readParams(ifs, dummy); // gravitational acceleration readParams(ifs, solver->g); // total number of timesteps readParams(ifs, solver->tnts); // one timestep in seconds readParams(ifs, solver->dt); // output parameters: readParams(ifs, dummy, domain.qOutput->qts, domain.pts); closeInputFile(); }
JoystickTeleop::JoystickTeleop(): nh_private_("~") { cmd_vel_pub_ = nh_.advertise<geometry_msgs::Twist>("cmd_vel", 1, true); joy_sub_ = nh_.subscribe("joy", 1, &JoystickTeleop::joyCallback, this); readParams( nh_private_ ); }
int main(int argc, char ** argv) { ros::init(argc, argv, "visptracker"); ros::NodeHandle n; // read parameters first int camSizeX, camSizeY, trackerType; std::string camTopic, pubTopic; ROS_INFO("Reading parameters..."); readParams(camSizeX, camSizeY, trackerType, camTopic, pubTopic); ROS_INFO("Parameters loaded successfully!"); detectorTracker = new TrackLandingMark(camSizeX, camSizeY, (TrackerType)trackerType); ros::Subscriber sub = n.subscribe(camTopic, 100, imageCallback); trackerDataPub = n.advertise<kuri_mbzirc_challenge_1::TrackerData>(pubTopic, 1000); detectorTracker->setSampling(2, 2); detectorTracker->setLambda(0.001); detectorTracker->setIterationMax(200); detectorTracker->setPyramidal(4, 1); detectorTracker->enableTrackerDisplay(true); ros::spin(); return 0; }
CrossValidator::CrossValidator(ros::NodeHandle node_handle) : node_handle_(node_handle), monitor_io_(node_handle) { ROS_VERIFY(readParams()); // ROS_VERIFY(monitor_io_.initialize(std::string("/TaskRecorderManager/data_samples"), std::string("/TaskRecorderManager/data_samples"))); ROS_VERIFY(monitor_io_.initialize()); }
double RatesReader::arrenius(const char *rid, double t) { double k, Ea, Tp; readParams(rid, &k, &Ea, &Tp); return k * std::pow(t, Tp) * std::exp(-Ea / (Env::R() * t)); }
Server::Server(int snum, QObject *p) : QThread(p) { bValid = true; iServerNum = snum; #ifdef USE_BONJOUR bsRegistration = NULL; #endif #ifdef Q_OS_UNIX aiNotify[0] = aiNotify[1] = -1; #else hNotify = NULL; #endif qtTimeout = new QTimer(this); iCodecAlpha = iCodecBeta = 0; bPreferAlpha = false; qnamNetwork = NULL; readParams(); initialize(); foreach(const QHostAddress &qha, qlBind) { SslServer *ss = new SslServer(this); connect(ss, SIGNAL(newConnection()), this, SLOT(newClient()), Qt::QueuedConnection); if (! ss->listen(qha, usPort)) { log(QString("Server: TCP Listen on %1 failed: %2").arg(addressToString(qha,usPort), ss->errorString())); bValid = false; } else { log(QString("Server listening on %1").arg(addressToString(qha,usPort))); } qlServer << ss; }
LoadEstimator::LoadEstimator(ros::NodeHandle& node_handle) : node_handle_(node_handle) , estimate_update_count(0) , calib_wait_period_(0.1) , hand_mass(0) , hand_cog(0, 0, 0) , obj_mass_min(0.01) , sim(false) { //first read the parameters ROS_VERIFY(readParams()); going_ = true; num_input_data_ = 6; reset(); inertial_estimation_pub_ = node_handle_.advertise<arm_msgs::InertialParameters>("load_in_hand", 100); //Initialisation of markers representing centers of masses of hand+obj, hand only, object only initCogMarker(1, 0, 0, "cog_hand_obj", 0, cog_marker_); initCogMarker(0, 1, 0, "cog_hand", 1, cog_hand_marker_); initCogMarker(0, 0, 1, "cog_obj" , 2, cog_obj_marker_); cog_marker_pub_ = node_handle_.advertise<visualization_msgs::Marker>("cog_marker", 10); reset_srv = node_handle_.advertiseService("reset", &LoadEstimator::resetSrv, this); //The service reestimates empty hand mass and cog. Must be called when the hand is empty and static calib_srv = node_handle_.advertiseService("calibrate", &LoadEstimator::calibSrv, this); publisher_thread_ = boost::thread(boost::bind(&LoadEstimator::publish_inertial_data, this)); wrench_sub_ = node_handle_.subscribe(end_effector_state_topic_, 1, &LoadEstimator::endEffectorStateCallback, this); //Calling calibration thread (the thread executes procedure only once until calibration service is called) calibrate_thread_ = boost::thread(boost::bind(&LoadEstimator::calibrate, this)); }
bool RunPotentialParamsQueue::getWork() { if(!fs::exists(mySettings.queueFile)) return false; ip::file_lock lock(mySettings.queueFile.string().c_str()); ip::scoped_lock< ip::file_lock> lockQueue(lock); fs::fstream queueStream(mySettings.queueFile); std::stringstream takenWorkItems, originalContents; std::string line; size_t numParamsRead = 0; while(numParamsRead < myNumWorkItemsChunk) { if(!std::getline(queueStream, line)) break; bool takenWork = false; if(!line.empty() && line[0] != '#') { const boost::optional< Params> & params = readParams(line); if(params) { ++numParamsRead; myParamsQueue.push(*params); takenWorkItems << "#" << spl::os::getProcessId() << " " << line << "\n"; takenWork = true; } } if(!takenWork) originalContents << line << "\n"; } if(numParamsRead > 0) { // Save the rest of the file to buffer std::copy(std::istreambuf_iterator< char>(queueStream), std::istreambuf_iterator< char>(), std::ostreambuf_iterator< char>(originalContents)); // Go back to the start of the file queueStream.clear(); // Clear the EoF flag queueStream.seekg(0, std::ios::beg); // Write out the whole new contents // First the rest of the file std::copy(std::istreambuf_iterator< char>(originalContents), std::istreambuf_iterator< char>(), std::ostreambuf_iterator< char>(queueStream)); // Then the part of the queue that we're running std::copy(std::istreambuf_iterator< char>(takenWorkItems), std::istreambuf_iterator< char>(), std::ostreambuf_iterator< char>(queueStream)); } queueStream.close(); return numParamsRead > 0; }
RobotInterface::ParamList RobotInterface::XMLReader::Private::readParamsTag(TiXmlElement *paramsElem) { const std::string &valueStr = paramsElem->ValueStr(); if (valueStr.compare("params") != 0) { SYNTAX_ERROR(paramsElem->Row()) << "Expected \"params\". Found" << valueStr; } std::string filename; if (paramsElem->QueryStringAttribute("file", &filename) == TIXML_SUCCESS) { // yDebug() << "Found params file [" << filename << "]"; #ifdef WIN32 std::replace(filename.begin(), filename.end(), '/', '\\'); filename = path + "\\" + filename; #else // WIN32 filename = path + "/" + filename; #endif //WIN32 return readParamsFile(filename); } std::string robotName; if (paramsElem->QueryStringAttribute("robot", &robotName) != TIXML_SUCCESS) { SYNTAX_WARNING(paramsElem->Row()) << "\"params\" element should contain the \"robot\" attribute"; } if (robotName != robot.name()) { SYNTAX_WARNING(paramsElem->Row()) << "Trying to import a file for the wrong robot. Found" << robotName << "instead of" << robot.name(); } unsigned int build; #if TINYXML_UNSIGNED_INT_BUG if (paramsElem->QueryUnsignedAttribute("build", &build()) != TIXML_SUCCESS) { // No build attribute. Assuming build="0" SYNTAX_WARNING(paramsElem->Row()) << "\"params\" element should contain the \"build\" attribute [unsigned int]. Assuming 0"; } #else int tmp; if (paramsElem->QueryIntAttribute("build", &tmp) != TIXML_SUCCESS || tmp < 0) { // No build attribute. Assuming build="0" SYNTAX_WARNING(paramsElem->Row()) << "\"params\" element should contain the \"build\" attribute [unsigned int]. Assuming 0"; tmp = 0; } build = (unsigned)tmp; #endif if (build != robot.build()) { SYNTAX_WARNING(paramsElem->Row()) << "Import a file for a different robot build. Found" << build << "instead of" << robot.build(); } ParamList params; for (TiXmlElement* childElem = paramsElem->FirstChildElement(); childElem != 0; childElem = childElem->NextSiblingElement()) { ParamList childParams = readParams(childElem); for (ParamList::const_iterator it = childParams.begin(); it != childParams.end(); ++it) { params.push_back(*it); } } return params; }
KeyboardTeleop::KeyboardTeleop( struct termios &cooked, struct termios &raw, int &kfd ): nh_("~"), cooked_( cooked ), raw_( raw ), kfd_ ( kfd ) { cmd_vel_pub_ = nh_.advertise<geometry_msgs::Twist>("/cmd_vel", 1, true); readParams(nh_); }
core::Error readParams(const json::Array& params, T1* pValue1, T2* pValue2, T3* pValue3) { core::Error error = readParams(params, pValue1, pValue2) ; if (error) return error ; return readParam(params, 2, pValue3) ; }
void Bank::readModule( Element* element, ModuleData* data ) { element->GetAttribute( "id", &data->id_ ); element->GetAttribute( "label", &data->label_ ); element->GetAttribute( "catalog", (int*)&data->catalog_ ); element->GetAttribute( "poly", (int*)&data->polyphony_ ); element->GetAttribute( "x", &data->xPos_ ); element->GetAttribute( "y", &data->yPos_ ); element->GetAttribute( "collapsed", &data->collapsed_, false ); readParams( element, data ); readLinks( element, data ); }
int main(int argc, char **argv){ MultiFasta *fasta; Parameters param; param = readParams(argc, argv); fasta = readFasta(param.fastaname); multialign(fasta, param.kmersize, param.mindiagsize); printFasta(fasta); releaseFasta(fasta); return EXIT_SUCCESS; }
core::Error readParams(const json::Array& params, T1* pValue1, T2* pValue2, T3* pValue3, T4* pValue4, T5* pValue5) { core::Error error = readParams(params, pValue1, pValue2, pValue3, pValue4) ; if (error) return error ; return readParam(params, 4, pValue5) ; }
RobotInterface::Robot& RobotInterface::XMLReader::Private::readRobotTag(TiXmlElement *robotElem) { if (robotElem->ValueStr().compare("robot") != 0) { SYNTAX_ERROR(robotElem->Row()) << "Root element should be \"robot\". Found" << robotElem->ValueStr(); } if (robotElem->QueryStringAttribute("name", &robot.name()) != TIXML_SUCCESS) { SYNTAX_ERROR(robotElem->Row()) << "\"robot\" element should contain the \"name\" attribute"; } #if TINYXML_UNSIGNED_INT_BUG if (robotElem->QueryUnsignedAttribute("build", &robot.build()) != TIXML_SUCCESS) { // No build attribute. Assuming build="0" SYNTAX_WARNING(robotElem->Row()) << "\"robot\" element should contain the \"build\" attribute [unsigned int]. Assuming 0"; } #else int tmp; if (robotElem->QueryIntAttribute("build", &tmp) != TIXML_SUCCESS || tmp < 0) { // No build attribute. Assuming build="0" SYNTAX_WARNING(robotElem->Row()) << "\"robot\" element should contain the \"build\" attribute [unsigned int]. Assuming 0"; tmp = 0; } robot.build() = (unsigned)tmp; #endif if (robotElem->QueryStringAttribute("portprefix", &robot.portprefix()) != TIXML_SUCCESS) { SYNTAX_WARNING(robotElem->Row()) << "\"robot\" element should contain the \"portprefix\" attribute. Using \"name\" attribute"; robot.portprefix() = robot.name(); } // yDebug() << "Found robot [" << robot.name() << "] build [" << robot.build() << "] portprefix [" << robot.portprefix() << "]"; for (TiXmlElement* childElem = robotElem->FirstChildElement(); childElem != 0; childElem = childElem->NextSiblingElement()) { if (childElem->ValueStr().compare("device") == 0 || childElem->ValueStr().compare("devices") == 0) { DeviceList childDevices = readDevices(childElem); for (DeviceList::const_iterator it = childDevices.begin(); it != childDevices.end(); ++it) { robot.devices().push_back(*it); } } else { ParamList childParams = readParams(childElem); for (ParamList::const_iterator it = childParams.begin(); it != childParams.end(); ++it) { robot.params().push_back(*it); } } } return robot; }
int main(int argc, char *argv[]) { parameters p = readParams(argv[1]); p.xbinWidth = (p.xmax - p.xmin)/double(p.xbins); std::cout << "inbase " << p.inbase << "\n"; std::cout << "ext " << p.ext << "\n"; std::cout << "avgbase " << p.avgbase << "\n"; std::cout << "covbase " << p.covbase << "\n"; std::cout << "corbase " << p.corbase << "\n"; std::cout << "datapoints " << p.datapoints << "\n"; std::cout << "xvals " << p.xvals << "\n"; std::cout << "outformat " << p.outformat << "\n"; std::cout << "xmin " << p.xmin << "\n"; std::cout << "xbinWidth " << p.xbinWidth << "\n"; std::cout << "numMocks " << p.numMocks << "\n"; std::cout << "startNum " << p.startNum << "\n"; std::cout << "digits " << p.digits << "\n"; std::ifstream fin; std::ofstream fout; std::vector< double > mu(p.datapoints); std::vector< double > xvalues(p.datapoints); const int N = p.datapoints; double cov[N][N] = {0.0}; std::cout << "Finding the average values...\n"; for (int mock = p.startNum; mock <= p.numMocks; ++mock) { std::string infile = filename(p.inbase, mock, p.digits, p.ext); fin.open(infile.c_str(),std::ios::in); if (p.xvals == "true") { int i = 0; while (!fin.eof()) { double x, y; fin >> x >> y; if (x >= p.xmin && !fin.eof()) { mu[i] += y/p.numMocks; xvalues[i] = x; ++i; } } } else { for (int i = 0; i < N; ++i) {
int main(int argc, char** argv) { //destroy_params(); argc--; argv++; flags = 0; if (argc > 0) { readParams(argc, argv); } init_params(cam); train(); if ((flags & P_TREE) != 0) { printTree(ptree->get_root()); printf("\n\n"); } if ((flags & F_CHK) != 0) runTest(); predict(); destroy_params(); return (EXIT_SUCCESS); }
void Snoss2D::snoss2Dbatch( DataStation& data_station) { //------------------------LOAD PARAMETRS FROM TXT-----------------------------// int index_S=0; string readPathParams= "params.txt"; fstream readParams(readPathParams.c_str()); string a; getline(gotoLine(readParams,9),a); stringstream pars (a); pars>>A1>>A2>>sigm>>B1>>B2>>SIcrit; //------------------------INITIALIZE SNOSS(precip,snow)-------------------------// int p=0; for(int i = 0;i<data_station.data_loaded.size();i++) { data_station.data_loaded[i]; } }
RobotInterface::Action RobotInterface::XMLReader::Private::readActionTag(TiXmlElement* actionElem) { if (actionElem->ValueStr().compare("action") != 0) { SYNTAX_ERROR(actionElem->Row()) << "Expected \"action\". Found" << actionElem->ValueStr(); } Action action; if (actionElem->QueryValueAttribute<ActionPhase>("phase", &action.phase()) != TIXML_SUCCESS || action.phase() == ActionPhaseUnknown) { SYNTAX_ERROR(actionElem->Row()) << "\"action\" element should contain the \"phase\" attribute [startup|interrupt{1,2,3}|shutdown]"; } if (actionElem->QueryValueAttribute<ActionType>("type", &action.type()) != TIXML_SUCCESS || action.type() == ActionTypeUnknown) { SYNTAX_ERROR(actionElem->Row()) << "\"action\" element should contain the \"type\" attribute [configure|calibrate|attach|abort|detach|park|custom]"; } // yDebug() << "Found action [ ]"; #if TINYXML_UNSIGNED_INT_BUG if (actionElem->QueryUnsignedAttribute("level", &action.level()) != TIXML_SUCCESS) { SYNTAX_ERROR(actionElem->Row()) << "\"action\" element should contain the \"level\" attribute [unsigned int]"; } #else int tmp; if (actionElem->QueryIntAttribute("level", &tmp) != TIXML_SUCCESS || tmp < 0) { SYNTAX_ERROR(actionElem->Row()) << "\"action\" element should contain the \"level\" attribute [unsigned int]"; } action.level() = (unsigned)tmp; #endif for (TiXmlElement* childElem = actionElem->FirstChildElement(); childElem != 0; childElem = childElem->NextSiblingElement()) { ParamList childParams = readParams(childElem); for (ParamList::const_iterator it = childParams.begin(); it != childParams.end(); ++it) { action.params().push_back(*it); } } // yDebug() << action; return action; }
RobotInterface::Device RobotInterface::XMLReader::Private::readDeviceTag(TiXmlElement *deviceElem) { const std::string &valueStr = deviceElem->ValueStr(); if (valueStr.compare("device") != 0) { SYNTAX_ERROR(deviceElem->Row()) << "Expected \"device\". Found" << valueStr; } Device device; if (deviceElem->QueryStringAttribute("name", &device.name()) != TIXML_SUCCESS) { SYNTAX_ERROR(deviceElem->Row()) << "\"device\" element should contain the \"name\" attribute"; } // yDebug() << "Found device [" << device.name() << "]"; if (deviceElem->QueryStringAttribute("type", &device.type()) != TIXML_SUCCESS) { SYNTAX_ERROR(deviceElem->Row()) << "\"device\" element should contain the \"type\" attribute"; } device.params().push_back(Param("robotName", robot.portprefix().c_str())); for (TiXmlElement* childElem = deviceElem->FirstChildElement(); childElem != 0; childElem = childElem->NextSiblingElement()) { if (childElem->ValueStr().compare("action") == 0 || childElem->ValueStr().compare("actions") == 0) { ActionList childActions = readActions(childElem); for (ActionList::const_iterator it = childActions.begin(); it != childActions.end(); ++it) { device.actions().push_back(*it); } } else { ParamList childParams = readParams(childElem); for (ParamList::const_iterator it = childParams.begin(); it != childParams.end(); ++it) { device.params().push_back(*it); } } } // yDebug() << device; return device; }
core::Error readParams(const json::Array& params, T1* pValue1, T2* pValue2, T3* pValue3, T4* pValue4, T5* pValue5, T6* pValue6, T7* pValue7, T8* pValue8) { core::Error error = readParams(params, pValue1, pValue2, pValue3, pValue4, pValue5, pValue6, pValue7) ; if (error) return error ; return readParam(params, 7, pValue8) ; }
RobotInterface::Param RobotInterface::XMLReader::Private::readGroupTag(TiXmlElement* groupElem) { if (groupElem->ValueStr().compare("group") != 0) { SYNTAX_ERROR(groupElem->Row()) << "Expected \"group\". Found" << groupElem->ValueStr(); } Param group(true); if (groupElem->QueryStringAttribute("name", &group.name()) != TIXML_SUCCESS) { SYNTAX_ERROR(groupElem->Row()) << "\"group\" element should contain the \"name\" attribute"; } // yDebug() << "Found group [" << group.name() << "]"; ParamList params; for (TiXmlElement* childElem = groupElem->FirstChildElement(); childElem != 0; childElem = childElem->NextSiblingElement()) { ParamList childParams = readParams(childElem); for (ParamList::const_iterator it = childParams.begin(); it != childParams.end(); ++it) { params.push_back(*it); } } if (params.empty()) { SYNTAX_ERROR(groupElem->Row()) << "\"group\" cannot be empty"; } std::string groupString; for (ParamList::iterator it = params.begin(); it != params.end(); ++it) { if (!groupString.empty()) { groupString += " "; } groupString += "(" + it->name() + " " + it->value() + ")"; } group.value() = groupString; return group; }
RobotInterface::ParamList RobotInterface::XMLReader::Private::readSubDeviceTag(TiXmlElement *subDeviceElem) { if (subDeviceElem->ValueStr().compare("subdevice") != 0) { SYNTAX_ERROR(subDeviceElem->Row()) << "Expected \"subdevice\". Found" << subDeviceElem->ValueStr(); } ParamList params; //FIXME Param featIdParam; Param subDeviceParam; //FIXME featIdParam.name() = "FeatId"; subDeviceParam.name() = "subdevice"; //FIXME if (subDeviceElem->QueryStringAttribute("name", &featIdParam.value()) != TIXML_SUCCESS) { // SYNTAX_ERROR(subDeviceElem->Row()) << "\"subdevice\" element should contain the \"name\" attribute"; // } if (subDeviceElem->QueryStringAttribute("type", &subDeviceParam.value()) != TIXML_SUCCESS) { SYNTAX_ERROR(subDeviceElem->Row()) << "\"subdevice\" element should contain the \"type\" attribute"; } //FIXME params.push_back(featIdParam); params.push_back(subDeviceParam); // yDebug() << "Found subdevice [" << params.at(0).value() << "]"; for (TiXmlElement* childElem = subDeviceElem->FirstChildElement(); childElem != 0; childElem = childElem->NextSiblingElement()) { ParamList childParams = readParams(childElem); for (ParamList::const_iterator it = childParams.begin(); it != childParams.end(); ++it) { params.push_back(Param(it->name(), it->value())); } } // yDebug() << params; return params; }
bool CStreamProcessor::StartStreamingRequest( const SStreamReadParams& _readParams) { SStreamReadParams readParams(_readParams); readParams.m_pRequestProcessor = this; // make sure a valid receive processor is set! if (readParams.m_pReceiveProcessor == NULL) readParams.m_pReceiveProcessor = this; // start the actual read operation CStreamReadRequest* pRequest = STREAM_ENGINE->StartRead(readParams); if (pRequest) { // push request to open request on the receive processor CStreamProcessor* pProcessor = (CStreamProcessor*) pRequest->GetParams().m_pReceiveProcessor; pProcessor->PushOpenRequest(pRequest); return true; } return false; }
int main(int argc, char ** argv) { SDL_Surface *screen; if(readParams(argc,argv)) { return 0; } if(SDL_Init(SDL_INIT_EVERYTHING) < 0) { printf("Error: SDL_Init(SDL_INIT_EVERYTHING) < 0\n"); return -1; } screen=SDL_SetVideoMode(800,600,32,SDL_SWSURFACE|SDL_OPENGL); if(screen == 0) { printf("error: SDL_SetVideoMode() == 0\n"); return -1; } mousey=mousex=0; initODE(); initGL(); mainLoop(); closeODE(); SDL_Quit(); return 0; }
int main(int argc, char* argv[]) { int program = 0; // Get input file from first command line argument if(argc < 3){ // No input file given std::cerr << "Usage: ./drudeh [input_file] [basis_file]\n"; program = -1; } else { std::string ifname = argv[1]; // Input filename std::string bfname = argv[2]; // Basis filename std::string ofname = ifname; // Output file prefix std::size_t pos = ofname.find('.'); if (pos != std::string::npos) { // Cut off extension ofname.erase(pos, ofname.length()); } ofname += ".output"; // Open the input file std::ifstream input(ifname); // Check it opened successfully if (!input.is_open()){ std::cerr << "Failed to open input file.\n"; program = -1; } else { // Declare and read parameters int N; std::vector<double> mu, omega, q; N = readParams(input, mu, omega, q); // Make the zeta vector std::vector<double> zeta(N); for (int i = 0; i < N; i++) zeta[i] = 0.5*mu[i]*omega[i]; // Geometry Eigen::MatrixXd R(N-1, 3); // Rewind input file input.clear(); input.seekg(0, std::ios::beg); // Read in geometry readGeom(input, R, N); // Open basis file std::ifstream basis(bfname); // Check if opened successfully if (!basis.is_open()){ std::cerr << "Failed to open basis file.\n"; program = -1; } else { // Initialise array of basis functions std::vector<BasisFunction> bfs; // Read in the basis functions int nbfs = readBasis(basis, bfs, N, zeta, R); // Form and diagonalise hamiltonian matrix Eigen::MatrixXd D = hamiltonian(N, nbfs, bfs, R, mu, omega, q); // Find lowest non-zero eigenvalue //int i = 0; double lowest_eig = D(0); // while ( D(i) < 0.1 ) i++; // if ( i < nbfs ) //lowest_eig = D(i); // Open output file std::ofstream output(ofname); if (!output.is_open()){ std::cout << "Couldn't open output file.\n"; std::cout << "Total number of basis functions = " << nbfs << "\n"; std::cout << "Lowest eigenvalue = " << std::setprecision(15) << lowest_eig << "\n"; } else { output << "Total number of basis functions = " << nbfs << "\n"; output << "Lowest eigenvalue = "<< std::setprecision(15) << lowest_eig << "\n"; } } } } return program; }
int CMMDVMHost::run() { bool ret = m_conf.read(); if (!ret) { ::fprintf(stderr, "MMDVMHost: cannot read the .ini file\n"); return 1; } ret = ::LogInitialise(m_conf.getLogPath(), m_conf.getLogRoot(), m_conf.getLogDisplay()); if (!ret) { ::fprintf(stderr, "MMDVMHost: unable to open the log file\n"); return 1; } ::LogSetLevel(m_conf.getLogLevel()); LogInfo(HEADER1); LogInfo(HEADER2); LogInfo(HEADER3); LogMessage("MMDVMHost-%s is starting", VERSION); readParams(); ret = createModem(); if (!ret) return 1; createDisplay(); if (m_dmrEnabled) { ret = createDMRNetwork(); if (!ret) return 1; } CStopWatch stopWatch; stopWatch.start(); CDStarEcho* dstar = NULL; if (m_dstarEnabled) dstar = new CDStarEcho(2U, 10000U); CDMRControl* dmr = NULL; if (m_dmrEnabled) { unsigned int id = m_conf.getDMRId(); unsigned int colorCode = m_conf.getDMRColorCode(); unsigned int timeout = m_conf.getTimeout(); LogInfo("DMR Parameters"); LogInfo(" Id: %u", id); LogInfo(" Color Code: %u", colorCode); LogInfo(" Timeout: %us", timeout); dmr = new CDMRControl(id, colorCode, timeout, m_modem, m_dmrNetwork, m_display); } CYSFEcho* ysf = NULL; if (m_ysfEnabled) ysf = new CYSFEcho(2U, 10000U); unsigned char mode = MODE_IDLE; CTimer modeTimer(1000U, m_conf.getModeHang()); m_display->setIdle(); while (!m_killed) { unsigned char data[200U]; unsigned int len; bool ret; len = m_modem->readDStarData(data); if (dstar != NULL && len > 0U) { if (mode == MODE_IDLE && (data[0U] == TAG_HEADER || data[0U] == TAG_DATA)) { LogMessage("Mode set to D-Star"); mode = MODE_DSTAR; m_display->setDStar(); m_modem->setMode(MODE_DSTAR); modeTimer.start(); } if (mode != MODE_DSTAR) { LogWarning("D-Star data received when in mode %u", mode); } else { if (data[0U] == TAG_HEADER || data[0U] == TAG_DATA || data[0U] == TAG_EOT) { dstar->writeData(data, len); modeTimer.start(); } } } len = m_modem->readDMRData1(data); if (dmr != NULL && len > 0U) { if (mode == MODE_IDLE) { bool ret = dmr->processWakeup(data); if (ret) { LogMessage("Mode set to DMR"); mode = MODE_DMR; m_display->setDMR(); // This sets the mode to DMR within the modem m_modem->writeDMRStart(true); modeTimer.start(); } } else if (mode == MODE_DMR) { dmr->writeModemSlot1(data); modeTimer.start(); } else { LogWarning("DMR data received when in mode %u", mode); } } len = m_modem->readDMRData2(data); if (dmr != NULL && len > 0U) { if (mode == MODE_IDLE) { bool ret = dmr->processWakeup(data); if (ret) { LogMessage("Mode set to DMR"); mode = MODE_DMR; m_display->setDMR(); // This sets the mode to DMR within the modem m_modem->writeDMRStart(true); modeTimer.start(); } } else if (mode == MODE_DMR) { dmr->writeModemSlot2(data); modeTimer.start(); } else { LogWarning("DMR data received when in mode %u", mode); } } len = m_modem->readYSFData(data); if (ysf != NULL && len > 0U) { if (mode == MODE_IDLE && data[0U] == TAG_DATA) { LogMessage("Mode set to System Fusion"); mode = MODE_YSF; m_display->setFusion(); m_modem->setMode(MODE_YSF); modeTimer.start(); } if (mode != MODE_YSF) { LogWarning("System Fusion data received when in mode %u", mode); } else { if (data[0U] == TAG_DATA) { data[1U] = 0x00U; // FICH digest ysf->writeData(data, len); modeTimer.start(); } } } if (modeTimer.isRunning() && modeTimer.hasExpired()) { LogMessage("Mode set to Idle"); if (mode == MODE_DMR) m_modem->writeDMRStart(false); mode = MODE_IDLE; m_display->setIdle(); m_modem->setMode(MODE_IDLE); modeTimer.stop(); } if (dstar != NULL) { ret = dstar->hasData(); if (ret) { ret = m_modem->hasDStarSpace(); if (ret) { len = dstar->readData(data); if (mode != MODE_DSTAR) { LogWarning("D-Star echo data received when in mode %u", mode); } else { m_modem->writeDStarData(data, len); modeTimer.start(); } } } } if (dmr != NULL) { ret = m_modem->hasDMRSpace1(); if (ret) { len = dmr->readModemSlot1(data); if (len > 0U && mode == MODE_IDLE) { m_display->setDMR(); mode = MODE_DMR; } if (len > 0U && mode == MODE_DMR) { m_modem->writeDMRData1(data, len); modeTimer.start(); } } ret = m_modem->hasDMRSpace2(); if (ret) { len = dmr->readModemSlot2(data); if (len > 0U && mode == MODE_IDLE) { m_display->setDMR(); mode = MODE_DMR; } if (len > 0U && mode == MODE_DMR) { m_modem->writeDMRData2(data, len); modeTimer.start(); } } } if (ysf != NULL) { ret = ysf->hasData(); if (ret) { ret = m_modem->hasYSFSpace(); if (ret) { len = ysf->readData(data); if (mode != MODE_YSF) { LogWarning("System Fusion echo data received when in mode %u", mode); } else { m_modem->writeYSFData(data, len); modeTimer.start(); } } } } unsigned int ms = stopWatch.elapsed(); m_modem->clock(ms); modeTimer.clock(ms); if (dstar != NULL) dstar->clock(ms); if (dmr != NULL) dmr->clock(ms); if (ysf != NULL) ysf->clock(ms); stopWatch.start(); if (ms < 5U) { #if defined(WIN32) ::Sleep(5UL); // 5ms #else ::usleep(5000); // 5ms #endif } } LogMessage("MMDVMHost is exiting on receipt of SIGHUP1"); m_display->setIdle(); m_modem->close(); delete m_modem; m_display->close(); delete m_display; if (m_dmrNetwork != NULL) { m_dmrNetwork->close(); delete m_dmrNetwork; } delete dstar; delete dmr; delete ysf; return 0; }
int main(int argc, char *argv[]) { char outFileName[64],datFileName[64],moldyName[128]; char *str; // atom *atomPtr; int g,nstart,j,ak,count; FILE *fp; double charge; int moldyFlag = 0; // suppress creation of ..._moldy.in file int distPlotFlag = 0; // suppress creation of disList.dat /* Let's set the radii of certain elements by hand: */ // atRad = (double *)realloc(atRadf, 109*sizeof(double)); // covRad = (double *)realloc(covRadf,109*sizeof(double)); atRad = (double *)malloc(109*sizeof(double)); covRad = (double *)malloc(109*sizeof(double)); memcpy(atRad, atRadf,36*sizeof(double)); memcpy(covRad,covRadf,36*sizeof(double)); atRad[39-1]=2.27; covRad[39-1]=2.62; // Y atRad[57-1]=2.74; covRad[57-1]=1.69; // La atRad[71-1]=2.25; covRad[71-1]=1.56; // Lu if (argc < 2) sprintf(datFileName,"gb.gbm"); else strcpy(datFileName,argv[1]); // read a flag: if (argc > 2) { if (strncmp(argv[2],"-m",2) == 0) { moldyFlag = 1; // also write a moldy file! printf("Saving moldy input file!\n"); } } muls->nCellX = 1; muls->nCellY = 1; muls->nCellZ = 1; muls->ctiltx = 0; muls->ctilty = 0; muls->ctiltz = 0; superCell.atoms = NULL; superCell.natoms = 0; if (!readParams(datFileName)) exit(0); if (nGrains > 0) { // loop, until we find crystalline grains: for (g=0; g<nGrains; g++) if (grains[g].amorphFlag == CRYSTALLINE) break; /* make the crystalline part of the super cell */ if (g<nGrains) makeSuperCell(); /* if there is also an amorphous part, then add it now, and also write a * MD input file, so that the amorphous phase atoms can be relaxed */ for (g=0; g<nGrains; g++) if (grains[g].amorphFlag != CRYSTALLINE) break; if (g<nGrains) { if (moldyFlag) { sprintf(moldyName,"%s",datFileName); moldyName[strlen(datFileName)-4] = '\0'; strcat(moldyName,"_moldy.in"); if ((fp=fopen(moldyName,"w")) == NULL) { printf("Could not open moldy input file %s!\n",moldyName); exit(0); } } else { fp = NULL; } if (nGrains > 1) { writeFrameWork(fp,superCell); computeCenterofMass(); nstart = superCell.natoms; switch (grains[g].amorphFlag) { case 1: makeAmorphous(); break; case 2: makeSpecial(distPlotFlag); break; } writeAmorphous(fp,superCell,nstart,superCell.natoms); } else { switch (grains[g].amorphFlag) { case 1: makeAmorphous(); break; case 2: makeSpecial(distPlotFlag); break; } writeAmorphous(fp,superCell,0,superCell.natoms); } if (moldyFlag) fclose(fp); } } if (0) { // (moldyFlag) { /////////////////////////////////////////////////////////////// // write Moldy input file, without presence of amorphous phase: sprintf(moldyName,"%s",datFileName); moldyName[strlen(datFileName)-4] = '\0'; strcat(moldyName,"_moldy.in"); if ((fp=fopen(moldyName,"w")) == NULL) { printf("Could not open moldy input file %s!\n",moldyName); exit(0); } // writeFrameWork(fp,superCell); // computeCenterofMass(); // superCell2Moldy(fp,superCell); fclose(fp); } // end of: if moldyFlag ... strcpy(outFileName,datFileName); // atomPtr = readUnitCell(&natoms,fileName,&muls); // writePDB(atomPtr,nat /* reset the input file and advance to the next crystal row */ str = strchr(outFileName,'.'); if (str == NULL) str=outFileName+strlen(outFileName); sprintf(str,".cfg"); muls->ax = (float)superCell.ax; muls->by = (float)superCell.by; muls->c = (float)superCell.cz; superCell.natoms = removeVacancies(superCell.atoms,superCell.natoms); printf("will write cfg file to %s\n",outFileName); writeCFG(superCell.atoms, superCell.natoms, outFileName, muls); printf("wrote cfg file to %s\n",outFileName); /************************************************************** * find the charge for the Y-atoms, in order to remain neutral: */ charge = 0.0; if (0) { for (ak=0;ak<muls->atomKinds;ak++) { count =0; for (j=0;j<superCell.natoms;j++) { if (muls->Znums[ak] == superCell.atoms[j].Znum) count++; } printf("Z=%3d: %d\n",muls->Znums[ak],count); switch (muls->Znums[ak]) { case 7: charge += count*(-3.0); break; case 8: charge += count*(-2.0); break; case 38: charge += count*(2.0); break; case 22: charge += count*(4.0); break; case 14: charge += count* 4.0; break; } } } else { for (j=0;j<superCell.natoms;j++) { charge += superCell.atoms[j].q*superCell.atoms[j].occ; } } // printf("Total charge: %g, i.e. %g %s\n",charge,charge,(charge > 0) ? "holes" : "electrons"); printf("Total charge: %g",charge); if (charge > 0) printf(", i.e. %g holes\n",charge); if (charge < 0) printf(", i.e. %g electrons\n",-charge); delete(muls); return 0; }
int FaceDetectApp::start(int argc, char* argv[]) { readParams(argc, argv); if (openWebcamStream() == -1) return -1; return mainLoop(argc, argv); }
int CMMDVMHost::run() { bool ret = m_conf.read(); if (!ret) { ::fprintf(stderr, "MMDVMHost: cannot read the .ini file\n"); return 1; } ret = ::LogInitialise(m_conf.getLogPath(), m_conf.getLogRoot(), m_conf.getLogDisplay()); if (!ret) { ::fprintf(stderr, "MMDVMHost: unable to open the log file\n"); return 1; } ::LogSetLevel(m_conf.getLogLevel()); LogInfo(HEADER1); LogInfo(HEADER2); LogInfo(HEADER3); LogInfo(HEADER4); LogMessage("MMDVMHost-%s is starting", VERSION); readParams(); ret = createModem(); if (!ret) return 1; createDisplay(); if (m_dstarEnabled && m_conf.getDStarNetworkEnabled()) { ret = createDStarNetwork(); if (!ret) return 1; } if (m_dmrEnabled && m_conf.getDMRNetworkEnabled()) { ret = createDMRNetwork(); if (!ret) return 1; } CTimer dmrBeaconTimer(1000U, 4U); bool dmrBeaconsEnabled = m_dmrEnabled && m_conf.getDMRBeacons(); CStopWatch stopWatch; stopWatch.start(); CDStarControl* dstar = NULL; if (m_dstarEnabled) { std::string callsign = m_conf.getCallsign(); std::string module = m_conf.getDStarModule(); unsigned int timeout = m_conf.getTimeout(); bool duplex = m_conf.getDuplex(); LogInfo("D-Star Parameters"); LogInfo(" Callsign: %s", callsign.c_str()); LogInfo(" Module: %s", module.c_str()); LogInfo(" Timeout: %us", timeout); dstar = new CDStarControl(callsign, module, m_dstarNetwork, m_display, timeout, duplex); } CDMRControl* dmr = NULL; if (m_dmrEnabled) { unsigned int id = m_conf.getDMRId(); unsigned int colorCode = m_conf.getDMRColorCode(); unsigned int timeout = m_conf.getTimeout(); LogInfo("DMR Parameters"); LogInfo(" Id: %u", id); LogInfo(" Color Code: %u", colorCode); LogInfo(" Timeout: %us", timeout); dmr = new CDMRControl(id, colorCode, timeout, m_modem, m_dmrNetwork, m_display); } CYSFEcho* ysf = NULL; if (m_ysfEnabled) ysf = new CYSFEcho(2U, 10000U); m_modeTimer.setTimeout(m_conf.getModeHang()); setMode(MODE_IDLE); while (!m_killed) { unsigned char data[200U]; unsigned int len; bool ret; len = m_modem->readDStarData(data); if (dstar != NULL && len > 0U) { if (m_mode == MODE_IDLE) { bool ret = dstar->writeModem(data); if (ret) setMode(MODE_DSTAR); } else if (m_mode == MODE_DSTAR) { dstar->writeModem(data); m_modeTimer.start(); } else { LogWarning("D-Star modem data received when in mode %u", m_mode); } } len = m_modem->readDMRData1(data); if (dmr != NULL && len > 0U) { if (m_mode == MODE_IDLE) { bool ret = dmr->processWakeup(data); if (ret) setMode(MODE_DMR); } else if (m_mode == MODE_DMR) { dmr->writeModemSlot1(data); dmrBeaconTimer.stop(); m_modeTimer.start(); } else { LogWarning("DMR modem data received when in mode %u", m_mode); } } len = m_modem->readDMRData2(data); if (dmr != NULL && len > 0U) { if (m_mode == MODE_IDLE) { bool ret = dmr->processWakeup(data); if (ret) setMode(MODE_DMR); } else if (m_mode == MODE_DMR) { dmr->writeModemSlot2(data); dmrBeaconTimer.stop(); m_modeTimer.start(); } else { LogWarning("DMR modem data received when in mode %u", m_mode); } } len = m_modem->readYSFData(data); if (ysf != NULL && len > 0U) { if (m_mode == MODE_IDLE) { bool ret = ysf->writeData(data, len); if (ret) setMode(MODE_YSF); } else if (m_mode == MODE_YSF) { ysf->writeData(data, len); m_modeTimer.start(); } else { LogWarning("System Fusion modem data received when in mode %u", m_mode); } } if (m_modeTimer.isRunning() && m_modeTimer.hasExpired()) setMode(MODE_IDLE); if (dstar != NULL) { ret = m_modem->hasDStarSpace(); if (ret) { len = dstar->readModem(data); if (len > 0U) { if (m_mode == MODE_IDLE) { setMode(MODE_DSTAR); } else if (m_mode == MODE_DSTAR) { m_modem->writeDStarData(data, len); m_modeTimer.start(); } else { LogWarning("D-Star data received when in mode %u", m_mode); } } } } if (dmr != NULL) { ret = m_modem->hasDMRSpace1(); if (ret) { len = dmr->readModemSlot1(data); if (len > 0U) { if (m_mode == MODE_IDLE) { setMode(MODE_DMR); } else if (m_mode == MODE_DMR) { m_modem->writeDMRData1(data, len); dmrBeaconTimer.stop(); m_modeTimer.start(); } else { LogWarning("DMR data received when in mode %u", m_mode); } } } ret = m_modem->hasDMRSpace2(); if (ret) { len = dmr->readModemSlot2(data); if (len > 0U) { if (m_mode == MODE_IDLE) { setMode(MODE_DMR); } else if (m_mode == MODE_DMR) { m_modem->writeDMRData2(data, len); dmrBeaconTimer.stop(); m_modeTimer.start(); } else { LogWarning("DMR data received when in mode %u", m_mode); } } } } if (ysf != NULL) { ret = m_modem->hasYSFSpace(); if (ret) { len = ysf->readData(data); if (len > 0U) { if (m_mode == MODE_IDLE) { setMode(MODE_YSF); } else if (m_mode == MODE_YSF) { m_modem->writeYSFData(data, len); m_modeTimer.start(); } else { LogWarning("System Fusion data received when in mode %u", m_mode); } } } } if (m_dmrNetwork != NULL) { bool run = m_dmrNetwork->wantsBeacon(); if (dmrBeaconsEnabled && run && m_mode == MODE_IDLE) { setMode(MODE_DMR, false); dmrBeaconTimer.start(); } } unsigned int ms = stopWatch.elapsed(); m_modem->clock(ms); m_modeTimer.clock(ms); if (dstar != NULL) dstar->clock(ms); if (dmr != NULL) dmr->clock(ms); if (ysf != NULL) ysf->clock(ms); if (m_dstarNetwork != NULL) m_dstarNetwork->clock(ms); if (m_dmrNetwork != NULL) m_dmrNetwork->clock(ms); stopWatch.start(); dmrBeaconTimer.clock(ms); if (dmrBeaconTimer.isRunning() && dmrBeaconTimer.hasExpired()) { setMode(MODE_IDLE, false); dmrBeaconTimer.stop(); } if (ms < 5U) { #if defined(_WIN32) || defined(_WIN64) ::Sleep(5UL); // 5ms #else ::usleep(5000); // 5ms #endif } } LogMessage("MMDVMHost is exiting on receipt of SIGHUP1"); setMode(MODE_IDLE); m_modem->close(); delete m_modem; m_display->close(); delete m_display; if (m_dstarNetwork != NULL) { m_dstarNetwork->close(); delete m_dstarNetwork; } if (m_dmrNetwork != NULL) { m_dmrNetwork->close(); delete m_dmrNetwork; } delete dstar; delete dmr; delete ysf; return 0; }