64 std::cout << std::endl <<
"usage: msr2msr <msr-file-in> <msr-file-out> | [--help]";
65 std::cout << std::endl <<
" <msr-file-in> : input msr-file";
66 std::cout << std::endl <<
" <msr-file-out>: converted msr-output-file";
67 std::cout << std::endl <<
" if the <msr-file-in> is already in the 2008 format";
68 std::cout << std::endl <<
" the output file will be identical to the input file.";
69 std::cout << std::endl << std::endl;
86 if (!strstr(str,
"RUN"))
96 Ssiz_t idx = line.Index(
"(");
101 std::vector<std::string> tokens = PStringUtils::Split(line.Data(),
" \t");
102 if (tokens.size() < 4) {
103 std::cout << std::endl <<
"**ERROR**: Something is wrong with the RUN block header:";
104 std::cout << std::endl <<
" >> " << str;
105 std::cout << std::endl <<
" >> no <msr-file-out> is created";
106 std::cout << std::endl;
110 if (tokens.size() == 5) {
111 snprintf(str, size,
"%s (name beamline institute data-file-format)", line.Data());
115 if (run.Contains(
"NEMU")) {
116 snprintf(str, size,
"RUN %s MUE4 PSI WKM (name beamline institute data-file-format)", tokens[1].c_str());
117 }
else if (run.Contains(
"PSI")) {
118 snprintf(str, size,
"RUN %s %s PSI PSI-BIN (name beamline institute data-file-format)",
119 tokens[1].c_str(), tokens[2].c_str());
120 }
else if (run.Contains(
"TRIUMF")) {
121 snprintf(str, size,
"RUN %s %s TRIUMF MUD (name beamline institute data-file-format)",
122 tokens[1].c_str(), tokens[2].c_str());
123 }
else if (run.Contains(
"RAL")) {
124 snprintf(str, size,
"RUN %s %s RAL NEXUS (name beamline institute data-file-format)",
125 tokens[1].c_str(), tokens[2].c_str());
146 if (strstr(str,
"Nr.")) {
147 strcpy(str,
"# No Name Value Step Pos_Error Boundaries");
156 std::vector<std::string> tokens = PStringUtils::Split(line.Data(),
" \t");
157 std::size_t noTokens = tokens.size();
160 snprintf(sstr,
sizeof(sstr),
"%10s", tokens[0].c_str());
163 strcat(sstr, tokens[1].c_str());
164 memset(spaces, 0,
sizeof(spaces));
165 memset(spaces,
' ', 12-strlen(tokens[1].c_str()));
166 strcat(sstr, spaces);
168 strcat(sstr, tokens[2].c_str());
169 if (strlen(tokens[2].c_str()) < 10) {
170 memset(spaces, 0,
sizeof(spaces));
171 memset(spaces,
' ', 10-strlen(tokens[2].c_str()));
172 strcat(sstr, spaces);
177 strcat(sstr, tokens[3].c_str());
178 if (strlen(tokens[3].c_str()) < 12) {
179 memset(spaces, 0,
sizeof(spaces));
180 memset(spaces,
' ', 12-strlen(tokens[3].c_str()));
181 strcat(sstr, spaces);
185 strcat(sstr,
"none");
187 }
else if (noTokens == 6) {
189 snprintf(sstr,
sizeof(sstr),
"%10s", tokens[0].c_str());
192 strcat(sstr, tokens[1].c_str());
193 memset(spaces, 0,
sizeof(spaces));
194 memset(spaces,
' ', 12-strlen(tokens[1].c_str()));
195 strcat(sstr, spaces);
197 strcat(sstr, tokens[2].c_str());
198 if (strlen(tokens[2].c_str()) < 10) {
199 memset(spaces, 0,
sizeof(spaces));
200 memset(spaces,
' ', 10-strlen(tokens[2].c_str()));
201 strcat(sstr, spaces);
206 strcat(sstr, tokens[3].c_str());
207 if (strlen(tokens[3].c_str()) < 12) {
208 memset(spaces, 0,
sizeof(spaces));
209 memset(spaces,
' ', 12-strlen(tokens[3].c_str()));
210 strcat(sstr, spaces);
215 strcat(sstr,
"none ");
217 strcat(sstr, tokens[4].c_str());
218 if (strlen(tokens[4].c_str()) < 8) {
219 memset(spaces, 0,
sizeof(spaces));
220 memset(spaces,
' ', 8-strlen(tokens[4].c_str()));
221 strcat(sstr, spaces);
226 strcat(sstr, tokens[5].c_str());
250 std::vector<std::string> tokens;
253 if ((line.Contains(
"sktt") || line.Contains(
"statKTTab")) && line.Contains(
"glf")) {
255 strcpy(sstr,
"statGssKTLF ");
258 tokens = PStringUtils::Split(line.Data(),
" \t");
259 std::size_t noTokens = tokens.size();
261 std::cout << std::endl <<
"**ERROR** in THEORY block";
262 std::cout << std::endl <<
" Line: '" << str <<
"' is not a valid statKTTab statement.";
263 std::cout << std::endl <<
" Cannot handle file." << std::endl;
266 for (Int_t i=1; i<3; i++) {
268 strcat(sstr, tokens[i].c_str());
270 strcat(sstr,
" (frequency damping)");
272 }
else if ((line.Contains(
"sktt") || line.Contains(
"statKTTab")) && line.Contains(
"llf")) {
274 strcpy(sstr,
"statExpKTLF ");
277 tokens = PStringUtils::Split(line.Data(),
" \t");
278 std::size_t noTokens = tokens.size();
280 std::cout << std::endl <<
"**ERROR** in THEORY block";
281 std::cout << std::endl <<
" Line: '" << str <<
"' is not a valid statKTTab statement.";
282 std::cout << std::endl <<
" Cannot handle file." << std::endl;
285 for (Int_t i=1; i<3; i++) {
287 strcat(sstr, tokens[i].c_str());
289 strcat(sstr,
" (frequency damping)");
291 }
else if ((line.Contains(
"dktt") || line.Contains(
"dynmKTTab")) && line.Contains(
"kdglf")) {
293 strcpy(sstr,
"dynGssKTLF ");
296 tokens = PStringUtils::Split(line.Data(),
" \t");
297 std::size_t noTokens = tokens.size();
299 std::cout << std::endl <<
"**ERROR** in THEORY block";
300 std::cout << std::endl <<
" Line: '" << str <<
"' is not a valid dynmKTTab statement.";
301 std::cout << std::endl <<
" Cannot handle file." << std::endl;
304 for (Int_t i=1; i<4; i++) {
306 strcat(sstr, tokens[i].c_str());
308 strcat(sstr,
" (frequency damping hopping-rate)");
310 }
else if ((line.Contains(
"dktt") || line.Contains(
"dynmKTTab")) && line.Contains(
"kdllf")) {
312 strcpy(sstr,
"dynExpKTLF ");
315 tokens = PStringUtils::Split(line.Data(),
" \t");
316 std::size_t noTokens = tokens.size();
318 std::cout << std::endl <<
"**ERROR** in THEORY block";
319 std::cout << std::endl <<
" Line: '" << str <<
"' is not a valid dynmKTTab statement.";
320 std::cout << std::endl <<
" Cannot handle file." << std::endl;
323 for (Int_t i=1; i<4; i++) {
325 strcat(sstr, tokens[i].c_str());
327 strcat(sstr,
" (frequency damping hopping-rate)");
329 }
else if (line.Contains(
"internFld")) {
331 noOfAddionalParams++;
334 strcpy(sstr,
"internFld ");
337 tokens = PStringUtils::Split(line.Data(),
" \t");
338 std::size_t noTokens = tokens.size();
340 std::cout << std::endl <<
"**ERROR** in THEORY block";
341 std::cout << std::endl <<
" Line: '" << str <<
"' is not a valid internFld statement.";
342 std::cout << std::endl <<
" Cannot handle file." << std::endl;
345 strcat(sstr,
" _x_");
346 for (Int_t i=1; i<4; i++) {
348 strcat(sstr, tokens[i].c_str());
350 strcat(sstr,
" (fraction phase frequency Trate Lrate)");
352 }
else if (line.Contains(
"internBsl")) {
354 noOfAddionalParams++;
357 strcpy(sstr,
"internBsl ");
360 tokens = PStringUtils::Split(line.Data(),
" \t");
361 std::size_t noTokens = tokens.size();
363 std::cout << std::endl <<
"**ERROR** in THEORY block";
364 std::cout << std::endl <<
" Line: '" << str <<
"' is not a valid internBsl statement.";
365 std::cout << std::endl <<
" Cannot handle file." << std::endl;
368 strcat(sstr,
" _x_");
369 for (Int_t i=1; i<4; i++) {
371 strcat(sstr, tokens[i].c_str());
373 strcat(sstr,
" (fraction phase frequency Trate Lrate)");
480 fin.open(fln, std::iostream::in);
481 if (!fin.is_open()) {
482 std::cout << std::endl <<
"**ERROR**: Couldn't open input msr-file " << fln;
483 std::cout << std::endl <<
" Will quit." << std::endl;
489 fout.open(
"__temp.msr", std::iostream::out);
490 if (!fout.is_open()) {
491 std::cout << std::endl <<
"**ERROR**: Couldn't open output msr-file __temp.msr";
492 std::cout << std::endl <<
" Will quit." << std::endl;
502 while (!fin.eof() && success) {
503 fin.getline(str,
sizeof(str));
505 if (strstr(str,
"FITPARAMETER")) {
507 }
else if (strstr(str,
"THEORY")) {
517 for (
int i=0; i<noOfAddionalParams; i++) {
518 fout <<
" " << param+i <<
" frac" << i+1 <<
" 0.333333 0.0 none" << std::endl;
527 if (strstr(str,
"_x_")) {
534 fout << str << std::endl;
543 snprintf(str,
sizeof(str),
"cp __temp.msr %s", fln);
544 if (system(str) == -1) {
545 std::cerr <<
"**ERROR** cmd: " << str <<
" failed." << std::endl;
549 strcpy(str,
"rm __temp.msr");
550 if (system(str) == -1) {
551 std::cerr <<
"**ERROR** cmd: " << str <<
" failed." << std::endl;
607int main(
int argc,
char *argv[])
618 fin.open(argv[1], std::iostream::in);
619 if (!fin.is_open()) {
620 std::cout << std::endl <<
"**ERROR**: Couldn't open input msr-file " << argv[1];
621 std::cout << std::endl <<
" Will quit." << std::endl;
627 fout.open(argv[2], std::iostream::out);
628 if (!fout.is_open()) {
629 std::cout << std::endl <<
"**ERROR**: Couldn't open output msr-file " << argv[2];
630 std::cout << std::endl <<
" Will quit." << std::endl;
639 int noOfAddionalParams = 0;
641 while (!fin.eof() && success) {
642 fin.getline(str,
sizeof(str));
644 if (strstr(str,
"FITPARAMETER")) {
646 }
else if (strstr(str,
"RUN")) {
648 }
else if (strstr(str,
"THEORY")) {
650 }
else if (strstr(str,
"STATISTIC")) {
671 fout << str << std::endl;
680 snprintf(str,
sizeof(str),
"rm -rf %s", argv[2]);
681 if (system(str) == -1) {
682 std::cerr <<
"**ERROR** cmd: " << str <<
" failed." << std::endl;
687 if (theoryTag != -1) {
691 std::cout << std::endl <<
"done ..." << std::endl;