Esempio n. 1
0
int main(int argc, char* argv[]) {
    fprintf(stderr, "KwPbar for C test suite\n");
    fprintf(stderr, "\nTesting printing...\n");
    int t1 = pbar(0, 2);  // 0
    int t2 = pbar(1, 2);  // 0
    int t3 = pbar(2, 2);  // 0
    fprintf(stderr, "\ndone.\n");
    fprintf(stderr, "\nTesting erasing...\n");
    int t4 = pbar(2, 3);  // 0
    erase_pbar();
    fprintf(stderr, "done.\n");
    fprintf(stderr, "\nTesting expected failures...\n");
    int t5 = pbar(1, 0);  // 1
    int t6 = pbar(2, 1);  // 2
    int t7 = pbar(-2, 1); // 2
    fprintf(stderr, "done.\n");
    int score = t1 + t2 + t3 + t4 + t5 + t6 + t7;
    int expected = 5;
    if (score == expected) {
        fprintf(stderr, "\nPASS (error score %d/%d)\n", score, expected);
    } else {
        fprintf(stderr, "\nFAIL (error score %d/%d)\n", score, expected);
    }
    return (expected - score);
}
Eigen::MatrixXd TwoDimensionalCut::getMatrix()
{
  Eigen::MatrixXd mat(cut->getEnergies().size(), points.size());
  progressBar pbar(points.size());
  std::thread myThread(&progressBar::run, &pbar);
#ifdef USE_THREADS
  tbb::parallel_for(tbb::blocked_range<std::size_t>(0, points.size()),
                    [this, &pbar, &mat](const tbb::blocked_range<std::size_t> r)
                    {
                      std::unique_ptr<SpinWaveGenie::SpinWavePlot> cutclone = cut->clone();
                      for (std::size_t m = r.begin(); m < r.end(); ++m)
                      {
                        Eigen::MatrixXd::ColXpr values = mat.col(m);
                        auto it = points.begin() + m;
                        std::vector<double> val = cutclone->getCut((*it)[0], (*it)[1], (*it)[2]);
#ifdef _MSC_VER
                        std::copy(val.begin(), val.end(), stdext::make_checked_array_iterator(values.data(), values.size()));
#else
                        std::copy(val.begin(), val.end(), values.data());
#endif
                        pbar.increment();
                      }
                    });
#else
  for (std::size_t m = 0; m < points.size(); ++m)
  {
    Eigen::MatrixXd::ColXpr values = mat.col(m);
    auto it = points.begin() + m;
    std::vector<double> val = cut->getCut((*it)[0], (*it)[1], (*it)[2]);
#ifdef _MSC_VER
    std::copy(val.begin(), val.end(), stdext::make_checked_array_iterator(values.data(), values.size()));
#else
    std::copy(val.begin(), val.end(), values.data());
#endif
    pbar.increment();
  }
#endif
  myThread.join();
  return mat;
}
Esempio n. 3
0
bool ja2xp::convertSLFto7z(vfs::tReadableFile* pInFile, vfs::tWritableFile *pOutFile, bool bConvertSTIs, bool bPngOffsets)
{
	vfs::CSLFLibrary src_lib(pInFile,"");
	if(!src_lib.init())
	{
		std::wcout << L"Could not init SLF Library \"" << pInFile->getPath().c_wcs() << L"\"" << std::endl;
		return false;
	}
	
	vfs::CCreateUncompressed7zLibrary create7zLib;

	vfs::CSLFLibrary::Iterator it = src_lib.begin();
	int count = 0;
	while(!it.end())
	{
		count++;
		it.next();
	}
	ProgressBar pbar(54,count);
	it = src_lib.begin();
	for(; !it.end(); it.next())
	{
		count++;
		vfs::CBufferFile* temp_file = NULL;
		vfs::tReadableFile *file = vfs::tReadableFile::cast(it.value());
		if(bConvertSTIs)
		{
			vfs::Path filename = it.value()->getPath();
			if(vfs::StrCmp::Equal(filename().substr(filename().length()-4,4), L".sti"))
			{
				vfs::Path path = filename().substr(0,filename.length()-4) + L".jpc.7z";
				temp_file = new vfs::CBufferFile(path);
				if(convertSTItoJPC(vfs::tReadableFile::cast(it.value()), vfs::tWritableFile::cast(temp_file), bPngOffsets, false))
				{
					file = vfs::tReadableFile::cast( temp_file );
				}
			}
		}
		if(create7zLib.addFile(file))
		{
			pbar.Next(it.value()->getPath()());
		}
		else
		{
			std::wcout << L"Adding file '" << it.value()->getPath().c_wcs() << L"' failed!"  << std::endl;
		}
		if(temp_file)
		{
			delete temp_file;
		}
	}
	std::wstringstream wss;
	wss << L"Writing file \"" << pOutFile->getPath().c_wcs() << L"\"";
	pbar.Next(wss.str());
	if(!create7zLib.writeLibrary(pOutFile))
	{
		wss.str(L"");
		wss << L"Could not write file \"" << pOutFile->getPath().c_wcs() << L"\"";
		pbar.Next(wss.str());
		return false;
	}
	return true;
}
Esempio n. 4
0
int main(int argc, char* argv[]) {
    int i = 0;
    char time_arg = 1;
    char expected_argc = 2;
    char stay_mode = 0;
    strcpy(PROGNAME, argv[0]);
    if (argc == 1 ||
        strcmp(argv[1], "-h") == 0 ||
        strcmp(argv[1], "--help") == 0) {
        usage(1);
        return 2;
    } else if (strcmp(argv[1], "-v") == 0 ||
               strcmp(argv[1], "--version") == 0) {
        fprintf(stderr, "%s %s\n", argv[0], VERSION);
        return 2;
    }

    if (strcmp(argv[1], "-s") == 0 ||
        strcmp(argv[1], "--stay") == 0) {
        stay_mode = 1;
        time_arg = 2;
        expected_argc = 3;
    }

    if (argc != expected_argc) {
        usage(1);
        return 2;
    }

    // we do use timespec, but we manage them ourselves
    // (we do not pass tmsec to nanosleep or the like)
    struct timespec tmsec = input_to_timespec(argv[time_arg]);
    struct nruns nr = timespec_to_nruns(tmsec);
#if defined(DEBUG) || defined(DRYMODE)
    fprintf(stderr, "abuser wants %s\n", print_timespec(tmsec));
    fprintf(stderr, "nruns: %lld runs, %s, final %s\n", nr.runs,
            print_timespec(nr.runlength), print_timespec(nr.final));
#endif

#ifndef DRYMODE
    int errno;
    errno = pbar(0, 1);
    if (errno != 0) return errno;
    for (i = 0; i < nr.runs; i++) {
        nanosleep(&nr.runlength, &nr.runlength);
        errno = pbar(i, nr.runs + 1);
        if (errno != 0) return errno;
    }
    nanosleep(&nr.final, &nr.final);
    errno = pbar(1, 1);
    if (errno != 0) return errno;
    if (stay_mode) {
        // stay mode, progressbar stays on the screen
        printf("\n");
    } else {
        // progressbar disappears at the end
        erase_pbar();
    }
#endif

    return 0;
}
Esempio n. 5
0
	int
main(int argc, char *argv[])
{
	int i, nv;
	double val;
	char aval[MAXLEN], *endptr;

	/* defaults */
	int maxchars  =   25;
	double minval =    0;
	double maxval =  100.0;
	char psym     =  '=';
	int print_nl  =    1;
	const char *label = NULL;


	for(i=1; i < argc; i++) {
		if(!strncmp(argv[i], "-w", 3)) {
			if(++i < argc)
				maxchars = atoi(argv[i]);
		}
		else if(!strncmp(argv[i], "-s", 3)) {
			if(++i < argc)
				psym = argv[i][0];
		}
		else if(!strncmp(argv[i], "-max", 5)) {
			if(++i < argc) {
				maxval = strtod(argv[i], &endptr);
				if(*endptr) {
					fprintf(stderr, "dbar: '%s' incorrect number format", argv[i]);
					return EXIT_FAILURE;
				}
			}
		}
		else if(!strncmp(argv[i], "-min", 5)) {
			if(++i < argc) {
				minval = strtod(argv[i], &endptr);
				if(*endptr) {
					fprintf(stderr, "dbar: '%s' incorrect number format", argv[i]);
					return EXIT_FAILURE;
				}
			}
		}
		else if(!strncmp(argv[i], "-l", 3)) {
			if(++i < argc)
				label = argv[i];
		}
		else if(!strncmp(argv[i], "-nonl", 6)) {
			print_nl = 0;
		}
		else {
			fprintf(stderr, "usage: dbar [-w <characters>] [-s <symbol>] [-min <minvalue>] [-max <maxvalue>] [-l <string>] [-nonl]\n");
			return EXIT_FAILURE;
		}
	}

	while(fgets(aval, MAXLEN, stdin)) {
		nv = sscanf(aval, "%lf %lf %lf", &val, &minval, &maxval);
		if(nv == 2) {
			maxval = minval;
			minval = 0;
		}

		pbar(label, (100*(val-minval))/(maxval-minval), maxchars, psym, print_nl);
	}

	return EXIT_SUCCESS;
}