Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
	ros::init(argc, argv, "open_loop_playback");

	if (2 != argc)
	{
		std::cout << "Usage: open_loop_playback <file>" << std::endl;
		return 1;
	}

	ros::NodeHandle nh;
	ros::Publisher vel_pub = nh.advertise<geometry_msgs::Twist>("cmd_vel", 1);

	// Open file
	std::ifstream my_file(argv[1]);

	// Read values
	ros::Rate r(10);
	while(my_file.good() && ros::ok())
	{
		double lin_speed, ang_speed;
		my_file >> lin_speed >> ang_speed;
		geometry_msgs::Twist t;
		t.linear.x = lin_speed;
		t.angular.z = ang_speed;
		vel_pub.publish(t);
		r.sleep();
		ros::spinOnce();
	}

	// Close file
	my_file.close();

	return 0;
}
Ejemplo n.º 2
0
// initialize output files
void OutputWrapperTXT::init_output_files()
{
  filename_cq = col->getSaveDirName() + "/ConservedQuantities.txt";
  if (vct->get_rank() == 0) {
    ofstream my_file(filename_cq.c_str());
    my_file.close();
  }
  // Distribution functions
  if(do_write_velocity_distribution())
  {
    const int nDistributionBins = get_number_of_distribution_bins();
    filename_ds = col->getSaveDirName() + "/DistributionFunctions.txt";
    if (vct->get_rank() == 0) {
      ofstream my_file(filename_ds.c_str());
      my_file.close();
    }
  }

  // set virtual satellite traces
  //
  if(do_write_virtual_satellite_traces())
  {
    filename_cqsat = col->getSaveDirName()
      + "/VirtualSatelliteTraces"
      + to_string(vct->get_rank())
      + ".txt";
    // if(vct->get_rank()==0)
    ofstream my_file(filename_cqsat.c_str(), fstream::binary);
    const int nsat = get_number_of_satellites_per_direction();
    const int nx0 = grid->get_nxc_r();
    const int ny0 = grid->get_nyc_r();
    const int nz0 = grid->get_nzc_r();
    for (int isat = 0; isat < nsat; isat++)
    for (int jsat = 0; jsat < nsat; jsat++)
    for (int ksat = 0; ksat < nsat; ksat++)
    {
      int i1 = 1 + isat * nx0 / nsat + nx0 / nsat / 2;
      int i2 = 1 + jsat * ny0 / nsat + ny0 / nsat / 2;
      int i3 = 1 + ksat * nz0 / nsat + nz0 / nsat / 2;
      my_file << grid->getXC(i1) << "\t"
              << grid->getYC(i2) << "\t"
              << grid->getZC(i3) << endl;
    }
    my_file.close();
  }
}
bool  FileExists(std::string path)
{
	std::ifstream my_file(path);
	if (my_file.good())
	{
	  my_file.close();
	  return true;
	}
	return false;
}
Ejemplo n.º 4
0
void OutputWrapperTXT::append_to_velocity_distribution(
  int cycle, int is, double maxVel, long long *VelocityDist)
{
  ofstream my_file(filename_ds.c_str(), fstream::app);
  my_file << cycle << "\t" << is << "\t" << maxVel;
  const int nbins = get_number_of_distribution_bins();
  for (int i = 0; i < nbins; i++)
    my_file << "\t" << VelocityDist[i];
  my_file << endl;
  my_file.close();
}
Ejemplo n.º 5
0
void Parser::close(){
	string relation_name = tokenizer.pop();
	string file_name = relation_name + ".db";
	ifstream my_file(file_name);
	if (my_file.is_open()){
		my_file.close();
	}
	else{
		throw runtime_error("The file was never open in the first place.");
	}
}
void print_MatrixToFile(std::string& file_name, Matrix& m)
{
	std::ofstream my_file(file_name.c_str());
    for( int i=0; i<m.rows(); ++i)
	{
		for( int j=0; j<m.cols(); ++j)
		{
		    my_file << m[i][j] <<",";
		}
		my_file << std::endl;
	}
} 
Ejemplo n.º 7
0
std::vector<int> FileReader::read_file_content(std::string file)
{
	std::vector<int> nums;
	std::fstream my_file(file, std::ios_base::in);

	int a;

	while(my_file >> a)
	{
		nums.push_back(a);
	}

	return nums;
}
Ejemplo n.º 8
0
void OutputWrapperTXT::append_conserved_quantities(int cycle,
      double total_energy, double bogus_momentum,
      double Eenergy, double Benergy, double gas_energy)
{
  if (vct->get_rank() == 0) {
    ofstream my_file(filename_cq.c_str(), fstream::app);
    my_file << cycle << "\t"
      << "\t" << total_energy
      << "\t" << bogus_momentum
      << "\t" << Eenergy
      << "\t" << Benergy
      << "\t" << gas_energy << endl;
    my_file.close();
  }
}
Ejemplo n.º 9
0
bool
MyBattery::updateStatus()
{
    QFile   my_file("/proc/apm");

    if (!my_file.open(IO_ReadOnly))
        return false;

    QString str;
    if(my_file.readLine(str, 100)<1)
        return false;

    float   buf_float[2];
    int     buf_int[6];

    memset(buf_float, 0, sizeof(buf_float));
    memset(buf_int, 0, sizeof(buf_int));

    /*
    printf("STR:%s", (const char*)str);
    */
    sscanf(str, "%f %f 0x%02x 0x%02x 0x%02x 0x%02x %d%% %d",
            &buf_float[0], &buf_float[1],
            &buf_int[0], &buf_int[1], &buf_int[2], &buf_int[3],
            &buf_int[4], &buf_int[5] );
    /*
    printf("%f %f %d %d %d %d %d %d\n",
            buf_float[0], buf_float[1],
            buf_int[0], buf_int[1], buf_int[2], buf_int[3], buf_int[4],
            buf_int[5]);
            */

    m_acStatus = buf_int[1];
    if (m_acStatus!=0)
        m_percent = 100;
    else
        m_percent = buf_int[4];

    my_file.close();

    return true;
}
Ejemplo n.º 10
0
// this assumes 4 species used in a certain way
//
void OutputWrapperTXT::append_to_satellite_traces(const Grid3DCU *grid,
    const_arr3_double Bx, const_arr3_double By, const_arr3_double Bz,
    const_arr3_double Ex, const_arr3_double Ey, const_arr3_double Ez,
    const_arr4_double Jxs,const_arr4_double Jys,const_arr4_double Jzs,
    const_arr4_double rhons)
{
  assert(do_write_virtual_satellite_traces());
  ofstream my_file(filename_cqsat.c_str(), fstream::app);
  const int nx0 = grid->get_nxc_r();
  const int ny0 = grid->get_nyc_r();
  const int nz0 = grid->get_nzc_r();
  const int nsat = get_number_of_satellites_per_direction();
  for (int isat = 0; isat < nsat; isat++)
  for (int jsat = 0; jsat < nsat; jsat++)
  for (int ksat = 0; ksat < nsat; ksat++)
  {
    const int i1 = 1 + isat * nx0 / nsat + nx0 / nsat / 2;
    const int i2 = 1 + jsat * ny0 / nsat + ny0 / nsat / 2;
    const int i3 = 1 + ksat * nz0 / nsat + nz0 / nsat / 2;
    my_file << Bx.get(i1, i2, i3) << "\t"
            << By.get(i1, i2, i3) << "\t"
            << Bz.get(i1, i2, i3) << "\t";
    my_file << Ex.get(i1, i2, i3) << "\t"
            << Ey.get(i1, i2, i3) << "\t"
            << Ez.get(i1, i2, i3) << "\t";
    my_file << Jxs.get(0, i1, i2, i3) + Jxs.get(2, i1, i2, i3) << "\t"
            << Jys.get(0, i1, i2, i3) + Jys.get(2, i1, i2, i3) << "\t"
            << Jzs.get(0, i1, i2, i3) + Jzs.get(2, i1, i2, i3) << "\t";
    my_file << Jxs.get(1, i1, i2, i3) + Jxs.get(3, i1, i2, i3) << "\t"
            << Jys.get(1, i1, i2, i3) + Jys.get(3, i1, i2, i3) << "\t"
            << Jzs.get(1, i1, i2, i3) + Jzs.get(3, i1, i2, i3) << "\t";
    my_file << rhons.get(0, i1, i2, i3) + rhons.get(2, i1, i2, i3) << "\t";
    my_file << rhons.get(1, i1, i2, i3) + rhons.get(3, i1, i2, i3) << "\t";
  }
  my_file << endl;
  my_file.close();
}
void print_result(std::string& file_name, std::vector<double>& x_grid, std::vector<double>& y_grid, Matrix& m)
{
	std::ofstream my_file(file_name.c_str());

	//! y_grid
	my_file << ",";

	my_file.precision(10);
	for( int j=0; j<m.cols(); ++j)
	{
	    my_file << y_grid[j] <<",";
	}
	my_file << std::endl;

    for( int i=0; i<m.rows(); ++i)
	{
		my_file << x_grid[i]<<",";
		for( int j=0; j<m.cols(); ++j)
		{
		    my_file << m[i][j] <<",";
		}
		my_file << std::endl;
	}
} 
Ejemplo n.º 12
0
int main(int argc, char **argv) {

    gtConverter::gtWorker w;
    const optional_vm optionalVm = getQcCLIoptions(argc,argv);
    if (!optionalVm) {
        return EXIT_FAILURE;
    }
    const auto vm = optionalVm.get();

    std::string infile,outfile,intype,outtype;

    //Set and verify all parameters.

    if (vm.count("echo") || vm.count("convert")) {
        if (vm.count("in")) {
            infile = vm["in"].as<std::string>();
            std::ifstream my_file(infile.c_str());
            if (!my_file.good()) {
                std::cerr << "Error: Input file not readable." << std::endl;
                return EXIT_FAILURE;
            }
        } else {
            std::cerr << "Error: Please specify an input file." << std::endl;
            return EXIT_FAILURE;
        }

        if (vm.count("intype")) {
            intype = vm["intype"].as<std::string>();
            if (! cmpNoCase(intype,"tdat") && ! cmpNoCase(intype,"csv")) {
                std::cerr << "Error: Input type not valid." << std::endl;
                return EXIT_FAILURE;
            }
        } else if (filetype(infile,"csv")) {
            std::cout << "Notice:Assuming filetype csv for input." << std::endl;
            intype = "csv";
        } else if (filetype(infile,"tdat")) {
            std::cout << "Notice:Assuming filetype tdat for input." << std::endl;
            intype = "tdat";
        }

        if (intype=="") {
            std::cerr << "Error: Please specify an input type." << std::endl;
            return EXIT_FAILURE;
        }
    }

    if (vm.count("convert")) {
        if (vm.count("out")) {
            outfile = vm["out"].as<std::string>();
            std::ifstream my_file(outfile.c_str());
            if (my_file.good()) {
                std::cout << "Warning: Overwriting old output file." << std::endl;
            }
        } else {
            std::cerr << "Error: Please specify an output file." << std::endl;
            return EXIT_FAILURE;
        }


        if (vm.count("outtype")) {
            outtype = vm["outtype"].as<std::string>();
            if (! cmpNoCase(outtype,"tdat") && ! cmpNoCase(outtype,"csv")) {
                std::cerr << "Error: Output type not valid." << std::endl;
                return EXIT_FAILURE;
            }
        } else if (filetype(outfile,"csv")) {
            std::cout << "Notice:Assuming filetype csv for output." << std::endl;
            outtype = "csv";
        } else if (filetype(outfile,"tdat")) {
            std::cout << "Notice:Assuming filetype tdat for output." << std::endl;
            outtype = "tdat";
        }

        if (outtype=="") {
            std::cerr << "Error: Please specify an output type." << std::endl;
            return EXIT_FAILURE;
        }
    }

    //Run echo'ing of files
    if (vm.count("echo")) {
        if (cmpNoCase(intype,"tdat")) {
            w.printTDatFile(infile);
        } else if (cmpNoCase(intype,"csv")) {
            //uhm, this is basically a cat command, but well... :)
            std::copy(infile.begin(), infile.end(), std::ostream_iterator<char>(std::cout, ""));
        }
    }

    //Run file conversion
    else if (vm.count("convert")) {
        if (cmpNoCase(intype,"tdat") && cmpNoCase(outtype,"csv")) {
            std::string csv = w.TDatToCSV(infile,false);
            std::ofstream ostream(outfile.c_str(), std::ofstream::binary);
            ostream.write(csv.c_str(),csv.size());
            ostream.close();
        } else {
            std::cout << "Sorry, the specified conversion from "<<intype << " to " << outtype << " is not implemented yet." <<
                      std::endl;
            return EXIT_FAILURE;
        }
    }

    //Nothing to run?
    else {

        std::cerr << "Error: No action specified. Exiting..." << std::endl;
        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}
Ejemplo n.º 13
0
int UHD_SAFE_MAIN(int argc, char *argv[]){



    if (uhd::set_thread_priority_safe(1,true)) {
       std::cout << "set priority went well " << std::endl;
    };


    //variables to be set by po
    std::string args;
    double seconds_in_future;
    size_t total_num_samps;
    double tx_rate, freq, LOoffset;
    float gain;
    bool demoMode, use_8bits;
    bool use_external_10MHz; 
    std::string filename;
    uhd::tx_streamer::sptr tx_stream;
    uhd::device_addr_t dev_addr;
    uhd::usrp::multi_usrp::sptr dev;
    uhd::stream_args_t stream_args;

    //setup the program options
    po::options_description desc("Allowed options");
    desc.add_options()
      ("help", "help message")
      ("args", po::value<std::string>(&args)->default_value(""), "simple uhd device address args")
      ("secs", po::value<double>(&seconds_in_future)->default_value(3), "number of seconds in the future to transmit")
      ("nsamps", po::value<size_t>(&total_num_samps)->default_value(37028), "total number of samples to transmit")//9428
      ("txrate", po::value<double>(&tx_rate)->default_value(100e6/4), "rate of outgoing samples")
      ("freq", po::value<double>(&freq)->default_value(70e6), "rf center frequency in Hz")
      ("LOoffset", po::value<double>(&LOoffset)->default_value(0), "Offset between main LO and center frequency")
      ("demoMode",po::value<bool>(&demoMode)->default_value(true), "demo mode")
      ("10MHz",po::value<bool>(&use_external_10MHz)->default_value(false), 
       "external 10MHz on 'REF CLOCK' connector (true=1=yes)")
      ("filename",po::value<std::string>(&filename)->default_value("codedData.dat"), "input filename")
      ("gain",po::value<float>(&gain)->default_value(0), "gain of transmitter(0-13) ")
      ("8bits",po::value<bool>(&use_8bits)->default_value(false), "Use eight bits/sample to increase bandwidth")
    ;

    
    
    po::variables_map vm;
    po::store(po::parse_command_line(argc, argv, desc), vm);
    po::notify(vm);

    
    //print the help message
    if (vm.count("help")){
      std::cout << boost::format("tx %s") % desc << std::endl;
      return ~0;
    }
    
 ///////////////////////////////////////////////////////////////// START PROCESSING /////////////////////////////////////////////////////////////////////
    
    std::complex<int16_t> *buffer0;
    buffer0 = new std::complex<int16_t>[total_num_samps];
    std::complex<int16_t> *buffer1;
    buffer1 = new std::complex<int16_t>[total_num_samps];
    std::complex<int16_t> *buffer2;
    buffer2 = new std::complex<int16_t>[total_num_samps];
    std::complex<int16_t> *buffer3;
    buffer3 = new std::complex<int16_t>[total_num_samps];
    std::complex<int16_t> *buffer4;
    buffer4 = new std::complex<int16_t>[total_num_samps];

    
    int16_t *aux0;
    aux0 = new int16_t[2*total_num_samps];
    int16_t *aux1;
    aux1 = new int16_t[2*total_num_samps];
    int16_t *aux2;
    aux2 = new int16_t[2*total_num_samps];
    int16_t *aux3;
    aux3 = new int16_t[2*total_num_samps];
    int16_t *aux4;
    aux4 = new int16_t[2*total_num_samps];
    
    //generate the picture as grayscale
    int r=system("octave image_transmition.m &");
    if(r){
      std::cout<<" loading picture - check!\n";
    }
    
    int nPicRaw = 16384;//size of the image in grayscale 128*128
    double nBinPac = 27200;//size of binary data in one packet
 

    //loading picture as grayscale
    int16_t pictureRaw[nPicRaw];
    std::ifstream ifs( "data_toSend.dat", std::ifstream::in );
    ifs.read((char * )pictureRaw,nPicRaw*sizeof(int16_t));
    ifs.close();  
    
    //converting grayscale to binary and XOR with pseudonoise
    itpp::bvec picBinInter = prepairPic(pictureRaw,nPicRaw);//transforms grayscale in binary data

    //cutting the large binary data into 5 packets
    bvec dataBinTmp0;
    dataBinTmp0.ins(dataBinTmp0.length(),picBinInter.get(0,(nBinPac-1)));
    bvec dataBinTmp1;
    dataBinTmp1.ins(dataBinTmp1.length(),picBinInter.get(nBinPac,(2*nBinPac-1)));
    bvec dataBinTmp2;
    dataBinTmp2.ins(dataBinTmp2.length(),picBinInter.get(2*nBinPac,(3*nBinPac-1)));
    bvec dataBinTmp3;
    dataBinTmp3.ins(dataBinTmp3.length(),picBinInter.get(3*nBinPac,(4*nBinPac-1)));
    bvec dataBinTmp4;
    dataBinTmp4.ins(dataBinTmp4.length(),picBinInter.get(4*nBinPac,picBinInter.length()));
    dataBinTmp4.ins(dataBinTmp4.length(),randb(nBinPac-dataBinTmp4.length())); //filling the last packet with random data

    //saving the binary picture
    it_file my_file("binPicture.it");
    my_file << Name("picBinInter") << picBinInter;
    my_file.flush();
    my_file.close();
    
    
    //processing each packet
    tx_funct(aux0,dataBinTmp0,dataBinTmp0.length());
    tx_funct(aux1,dataBinTmp1,dataBinTmp1.length());
    tx_funct(aux2,dataBinTmp2,dataBinTmp2.length());
    tx_funct(aux3,dataBinTmp3,dataBinTmp3.length());
    tx_funct(aux4,dataBinTmp4,dataBinTmp4.length());
    
    //filling the output buffer
    for(int i=0,count1=0;i<(int)(2*total_num_samps);i=i+2){
      buffer0[count1]=std::complex<short>(aux0[i],aux0[i+1]);
      buffer1[count1]=std::complex<short>(aux1[i],aux1[i+1]);
      buffer2[count1]=std::complex<short>(aux2[i],aux2[i+1]);
      buffer3[count1]=std::complex<short>(aux3[i],aux3[i+1]);
      buffer4[count1]=std::complex<short>(aux4[i],aux4[i+1]);
      count1++;
    }
 
    
   
    // Save data to file to check what was sent
    std::ofstream ofs( "sent0.dat" , std::ifstream::out );
    ofs.write((char * ) buffer0, 2*total_num_samps*sizeof(int16_t));
    ofs.flush();
    ofs.close();
    // Save data to file to check what was sent
    std::ofstream ofs1( "sent1.dat" , std::ifstream::out );
    ofs1.write((char * ) buffer1, 2*total_num_samps*sizeof(int16_t));
    ofs1.flush();
    ofs1.close();
    // Save data to file to check what was sent
    std::ofstream ofs2( "sent2.dat" , std::ifstream::out );
    ofs2.write((char * ) buffer2, 2*total_num_samps*sizeof(int16_t));
    ofs2.flush();
    ofs2.close();
    // Save data to file to check what was sent
    std::ofstream ofs3( "sent3.dat" , std::ifstream::out );
    ofs3.write((char * ) buffer3, 2*total_num_samps*sizeof(int16_t));
    ofs3.flush();
    ofs3.close();
    // Save data to file to check what was sent
    std::ofstream ofs4( "sent4.dat" , std::ifstream::out );
    ofs4.write((char * ) buffer4, 2*total_num_samps*sizeof(int16_t));
    ofs4.flush();
    ofs4.close();

    //Conjugate!!!
    for(int i=0; i<(int)(total_num_samps);i++){
      buffer0[i]=std::conj(buffer0[i]);
      buffer1[i]=std::conj(buffer1[i]);
      buffer2[i]=std::conj(buffer2[i]);
      buffer3[i]=std::conj(buffer3[i]);
      buffer4[i]=std::conj(buffer4[i]);
    } 
    
    

    std::cout << " ----------- " << std::endl;
    std::cout<<" Conjugated! \n";
    std::cout << " ----------- " << std::endl;
    
    ///////////////////////////////////////////////////////////////// END  PROCESSING /////////////////////////////////////////////////////////////////////
    
    //create a usrp device and streamer
    dev_addr["addr0"]="192.168.10.2";
    dev = uhd::usrp::multi_usrp::make(dev_addr);    


    // Internal variables 
    uhd::clock_config_t my_clock_config; 

    if (!demoMode) {
      dev->set_time_source("external");
    };

    if (use_external_10MHz) { 
      dev->set_clock_source("external");
    }
    else {
      dev->set_clock_source("internal");
    };


    uhd::usrp::dboard_iface::sptr db_iface;
    db_iface=dev->get_tx_dboard_iface(0);

    board_60GHz_TX  my_60GHz_TX(db_iface);  //60GHz 
    my_60GHz_TX.set_gain(gain); // 60GHz 

    uhd::tune_result_t tr;
    uhd::tune_request_t trq(freq,LOoffset); //std::min(tx_rate,10e6));
    tr=dev->set_tx_freq(trq,0);
    

    //dev->set_tx_gain(gain);
    std::cout << tr.to_pp_string() << "\n";
 

    stream_args.cpu_format="sc16";
    if (use_8bits)
      stream_args.otw_format="sc8";
    else
      stream_args.otw_format="sc16";

    tx_stream=dev->get_tx_stream(stream_args);


    //set properties on the device
    std::cout << boost::format("Setting TX Rate: %f Msps...") % (tx_rate/1e6) << std::endl;
    dev->set_tx_rate(tx_rate);
    std::cout << boost::format("Actual TX Rate: %f Msps...") % (dev->get_tx_rate()/1e6) << std::endl;
    std::cout << boost::format("Setting device timestamp to 0...") << std::endl;


    

    uhd::tx_metadata_t md;


    if(demoMode){

    dev->set_time_now(uhd::time_spec_t(0.0));
    md.start_of_burst = true;
    md.end_of_burst = false;
    md.has_time_spec = false;
    md.time_spec = uhd::time_spec_t(seconds_in_future);

   
    tx_stream->send(buffer0,total_num_samps,md,60);
    
    tx_stream->send(buffer1,total_num_samps,md,3);
    
    tx_stream->send(buffer2,total_num_samps,md,3);

    tx_stream->send(buffer3,total_num_samps,md,3);

    tx_stream->send(buffer4,total_num_samps,md,3);

    tx_stream->send(buffer4,total_num_samps,md,3);

    md.start_of_burst = false;

    std::cout << " " << std::endl;
    std::cout<< "picture transmitted once!" << std::endl;
    std::cout << " " << std::endl;
    
    int f=system("octave toMatlab.m");
    if(f){
      std::cout << " Programm Paused - Press Any Key To leave! " << std::endl;
    }


    }
    else
    {
    
    dev->set_time_now(uhd::time_spec_t(0.0));
    md.start_of_burst = true;
    md.end_of_burst = false;
    md.has_time_spec = false;
    md.time_spec = uhd::time_spec_t(seconds_in_future);

      
    tx_stream->send(buffer0,total_num_samps,md,60);
    
    tx_stream->send(buffer1,total_num_samps,md,3);
    
    tx_stream->send(buffer2,total_num_samps,md,3);

    tx_stream->send(buffer3,total_num_samps,md,3);

    tx_stream->send(buffer4,total_num_samps,md,3);

    tx_stream->send(buffer4,total_num_samps,md,3);

    md.start_of_burst = false;

    std::cout << " " << std::endl;
    std::cout<< "picture transmitted once!" << std::endl;
    std::cout << " " << std::endl;

    };

    //finished
    std::cout << std::endl << "Done!" << std::endl << std::endl;


    return 0;
}
Ejemplo n.º 14
0
void MainWindow::choose_file_button_clicked()
{   try {
        QString fileName = QFileDialog::getOpenFileName(this,QString::fromUtf8("Choose File"),QDir::currentPath(),"Text(*.txt)");
        if (fileName.length() != 0) {
            // ДАЛЕЕ ОЧИСТКА ЗНАЧЕНИЙ!!!
            clear_data();
            clear_lines();

            ui->fileName->setText(fileName);
            QFile my_file(fileName);
            my_file.open(QIODevice::ReadOnly);
            if (my_file.isOpen())
                while (!my_file.atEnd()) {
                    QString exmpl = changeOnDoTA(my_file.readLine());
                    double obj = exmpl.toDouble();
                    started_data.push_back(obj);
                }

            try {

                set_average_data();

               // qDebug() << max_x << " " << min_x;
                set_square_deviation();
                set_Sx();
    //            for (int i = 0; i < started_data.size(); i++)
    //                qDebug() << started_data[i];
                set_r(); //  КИДАЕТ ВНУТРЕННИЙ ЭКСЕПШЕН!
                set_h();

                fill_intervals();
                set_f();
                set_middle_value();
                set_middle_value2();
                set_average_of_intervals();
                set_si();
                set_n_i();
                set_xi_sq();

                choose_quantile();

//                qDebug() << "BEgin";
//                for (int i = 0;i < started_data.size();i++)
//                    qDebug() << started_data[i];
//                qDebug() << "END";

                set_lines();
                for (int i = 0; i < intervals.size();i++) {
                    for (int j = 0; j < intervals[i].size();j++)
                        qDebug() << intervals[i][j];
                    qDebug() << "end_line";
                }

              //  check_result();

                is_chButton_clicked_flag = true;
                my_file.close();
            } catch(std::exception &e){
                clear_data();
                clear_lines();
                is_chButton_clicked_flag = false;
                QMessageBox::critical(this,"Not Valid!!!",e.what());
            }
        }
        else {
            throw (std::invalid_argument("Choose txt File!"));
        }
    } catch(std::exception& e) {
        clear_data();
        clear_lines();
        is_chButton_clicked_flag = false;
       // QMessageBox::critical(this, "Error!",e.what());
    }

}
Ejemplo n.º 15
0
int main(int argc, char *argv[])
{
  long long int x_number;
  long long int y_number;
  long long int z_number;
  long long int temp_num;

  int t_number;

  cout << " Takawira's Log Value Generator" << endl //Name of program
       << "   v 1.0.0" << endl << endl; //Version of program
  cout << "First, I am going to need three numbers to start with." << endl
       << "It's best to use numbers that get bigger, such as " << endl
       << "3, 8, 18." << endl
       << "Then, I am going to need a number of times to do the program's operation." << endl
       << endl << "So, please enter the first number that you would like to start with: ";
  cin >> x_number;
  cout << endl << "Now, enter the next number that you would like to start with: ";
  cin >> y_number;
  cout << endl << "Now enter the last number that you would like to start with: ";
  cin >> z_number;
  cout << endl << "Now, how many times would you like to do the sums?  Multiply the value that you"
       << endl << " enter by two, and then add two to get how many total values you will have. ";
  cin >> t_number;
  cout << endl << "The program will now begin the sums.  Results will be saved in a file called"
       << endl << " 'sumprog.txt'.  Press enter when ready..." << endl;
  getch();

  int ox_number=x_number;
  int oy_number=y_number;
  int oz_number=z_number;

  if(t_number<1) {
    int t_number=1;
  }

  int num_times=0;
  int front_number=2;

 std::ofstream my_file("takawira.txt");
 if(my_file) {

  my_file << "0, " << ox_number << endl
          << "1, " << oy_number << endl
          << "2, " << oz_number << endl;

begsumloop:
  if(num_times<t_number) {
  temp_num=pow(10,((log10(y_number) + log10(z_number)) - log10(x_number)));
  x_number=y_number;
  y_number=z_number;
  z_number=temp_num;
  front_number=(front_number+1);
  my_file << front_number << ", " << z_number << endl;
  num_times=(num_times+1);

  goto begsumloop;

  }
  else
  cout << "Your first number was: " << ox_number << endl
       << "Your second number was: " << oy_number << endl
       << "Your third number was: " << oz_number << endl
       << "The number of times you specified was: " << t_number << endl << endl
       << "Check the folder this program resides in for your output file, 'takawira.txt'";
  my_file << "Sum Program was run " << num_times << " times, which means that there should be " << (num_times+3) << " numbers." << endl;
  goto exitroo;

}
 else
     goto exitroo;

exitroo:
  std::cerr << "";
  getch();
  return 0;
}
Ejemplo n.º 16
0
bool Path::exists()
{
	std::ifstream my_file(fullPath.c_str());
	return my_file.good();

}