File: checkRunId.cpp

package info (click to toggle)
dmrgpp 6.06-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 113,900 kB
  • sloc: cpp: 80,986; perl: 14,772; ansic: 2,923; makefile: 83; sh: 17
file content (74 lines) | stat: -rw-r--r-- 1,444 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "ApplicationInfo.h"
#include "BitManip.h"
#include <cstdlib>
#include <iostream>

void usage(const char* progName)
{
	std::cerr << "Usage: " << progName << " -i number | -g times\n";
}

bool checkRunId(PsimagLite::String id, PsimagLite::String progName)
{
	PsimagLite::String str(id);
	int l = str.length();
	if (l < 3) {
		std::cerr << progName << ": too short runId=" << id << "\n";
		return false;
	}

	PsimagLite::String check("");
	PsimagLite::String number("");
	check += str[l - 2];
	check += str[l - 1];

	for (int i = 0; i < l - 2; ++i)
		number += str[i];

	unsigned long int x = atol(number.c_str());
	int bits = PsimagLite::BitManip::countKernighan(x);
	std::cout << number << " " << check << " " << bits << "\n";
	// std::cout<<bits<<"\n";
	return (bits == atoi(check.c_str()));
}

int main(int argc, char** argv)
{
	int opt = 0;
	int g = 0;
	PsimagLite::String id;
	while ((opt = getopt(argc, argv, "g:i:")) != -1) {
		switch (opt) {
		case 'g':
			g = atoi(optarg);
			break;
		case 'i':
			id = optarg;
			break;
		default:
			usage(argv[0]);
			return 1;
		}
	}

	if (id == "" && g == 0) {
		usage(argv[0]);
		return 1;
	}

	if (id != "") {
		bool b = checkRunId(id, argv[0]);
		return (b) ? 0 : 3;
	}

	for (int i = 0; i < g; ++i) {
		PsimagLite::ApplicationInfo appInfo("test");
		bool b = checkRunId(appInfo.runId(), argv[0]);
		if (!b) {
			std::cerr << "Found invalid number\n";
			return 4;
		}
	}

	return 0;
}