66 std::cout << std::endl <<
"usage: msr2msr <msr-file-in> <msr-file-out> | [--help]";
67 std::cout << std::endl <<
" <msr-file-in> : input msr-file";
68 std::cout << std::endl <<
" <msr-file-out>: converted msr-output-file";
69 std::cout << std::endl <<
" if the <msr-file-in> is already in the 2008 format";
70 std::cout << std::endl <<
" the output file will be identical to the input file.";
71 std::cout << std::endl << std::endl;
88 if (!strstr(str,
"RUN"))
98 Ssiz_t idx = line.Index(
"(");
103 std::vector<std::string> tokens = PStringUtils::Split(line.Data(),
" \t");
104 if (tokens.size() < 4) {
105 std::cout << std::endl <<
"**ERROR**: Something is wrong with the RUN block header:";
106 std::cout << std::endl <<
" >> " << str;
107 std::cout << std::endl <<
" >> no <msr-file-out> is created";
108 std::cout << std::endl;
112 if (tokens.size() == 5) {
113 snprintf(str, size,
"%s (name beamline institute data-file-format)", line.Data());
117 if (run.Contains(
"NEMU")) {
118 snprintf(str, size,
"RUN %s MUE4 PSI WKM (name beamline institute data-file-format)", tokens[1].c_str());
119 }
else if (run.Contains(
"PSI")) {
120 snprintf(str, size,
"RUN %s %s PSI PSI-BIN (name beamline institute data-file-format)",
121 tokens[1].c_str(), tokens[2].c_str());
122 }
else if (run.Contains(
"TRIUMF")) {
123 snprintf(str, size,
"RUN %s %s TRIUMF MUD (name beamline institute data-file-format)",
124 tokens[1].c_str(), tokens[2].c_str());
125 }
else if (run.Contains(
"RAL")) {
126 snprintf(str, size,
"RUN %s %s RAL NEXUS (name beamline institute data-file-format)",
127 tokens[1].c_str(), tokens[2].c_str());
148 if (strstr(str,
"Nr.")) {
149 strcpy(str,
"# No Name Value Step Pos_Error Boundaries");
158 std::vector<std::string> tokens = PStringUtils::Split(line.Data(),
" \t");
159 std::size_t noTokens = tokens.size();
162 snprintf(sstr,
sizeof(sstr),
"%10s", tokens[0].c_str());
165 strcat(sstr, tokens[1].c_str());
166 memset(spaces, 0,
sizeof(spaces));
167 memset(spaces,
' ', 12-strlen(tokens[1].c_str()));
168 strcat(sstr, spaces);
170 strcat(sstr, tokens[2].c_str());
171 if (strlen(tokens[2].c_str()) < 10) {
172 memset(spaces, 0,
sizeof(spaces));
173 memset(spaces,
' ', 10-strlen(tokens[2].c_str()));
174 strcat(sstr, spaces);
179 strcat(sstr, tokens[3].c_str());
180 if (strlen(tokens[3].c_str()) < 12) {
181 memset(spaces, 0,
sizeof(spaces));
182 memset(spaces,
' ', 12-strlen(tokens[3].c_str()));
183 strcat(sstr, spaces);
187 strcat(sstr,
"none");
189 }
else if (noTokens == 6) {
191 snprintf(sstr,
sizeof(sstr),
"%10s", tokens[0].c_str());
194 strcat(sstr, tokens[1].c_str());
195 memset(spaces, 0,
sizeof(spaces));
196 memset(spaces,
' ', 12-strlen(tokens[1].c_str()));
197 strcat(sstr, spaces);
199 strcat(sstr, tokens[2].c_str());
200 if (strlen(tokens[2].c_str()) < 10) {
201 memset(spaces, 0,
sizeof(spaces));
202 memset(spaces,
' ', 10-strlen(tokens[2].c_str()));
203 strcat(sstr, spaces);
208 strcat(sstr, tokens[3].c_str());
209 if (strlen(tokens[3].c_str()) < 12) {
210 memset(spaces, 0,
sizeof(spaces));
211 memset(spaces,
' ', 12-strlen(tokens[3].c_str()));
212 strcat(sstr, spaces);
217 strcat(sstr,
"none ");
219 strcat(sstr, tokens[4].c_str());
220 if (strlen(tokens[4].c_str()) < 8) {
221 memset(spaces, 0,
sizeof(spaces));
222 memset(spaces,
' ', 8-strlen(tokens[4].c_str()));
223 strcat(sstr, spaces);
228 strcat(sstr, tokens[5].c_str());
252 std::vector<std::string> tokens;
255 if ((line.Contains(
"sktt") || line.Contains(
"statKTTab")) && line.Contains(
"glf")) {
257 strcpy(sstr,
"statGssKTLF ");
260 tokens = PStringUtils::Split(line.Data(),
" \t");
261 std::size_t noTokens = tokens.size();
263 std::cout << std::endl <<
"**ERROR** in THEORY block";
264 std::cout << std::endl <<
" Line: '" << str <<
"' is not a valid statKTTab statement.";
265 std::cout << std::endl <<
" Cannot handle file." << std::endl;
268 for (Int_t i=1; i<3; i++) {
270 strcat(sstr, tokens[i].c_str());
272 strcat(sstr,
" (frequency damping)");
274 }
else if ((line.Contains(
"sktt") || line.Contains(
"statKTTab")) && line.Contains(
"llf")) {
276 strcpy(sstr,
"statExpKTLF ");
279 tokens = PStringUtils::Split(line.Data(),
" \t");
280 std::size_t noTokens = tokens.size();
282 std::cout << std::endl <<
"**ERROR** in THEORY block";
283 std::cout << std::endl <<
" Line: '" << str <<
"' is not a valid statKTTab statement.";
284 std::cout << std::endl <<
" Cannot handle file." << std::endl;
287 for (Int_t i=1; i<3; i++) {
289 strcat(sstr, tokens[i].c_str());
291 strcat(sstr,
" (frequency damping)");
293 }
else if ((line.Contains(
"dktt") || line.Contains(
"dynmKTTab")) && line.Contains(
"kdglf")) {
295 strcpy(sstr,
"dynGssKTLF ");
298 tokens = PStringUtils::Split(line.Data(),
" \t");
299 std::size_t noTokens = tokens.size();
301 std::cout << std::endl <<
"**ERROR** in THEORY block";
302 std::cout << std::endl <<
" Line: '" << str <<
"' is not a valid dynmKTTab statement.";
303 std::cout << std::endl <<
" Cannot handle file." << std::endl;
306 for (Int_t i=1; i<4; i++) {
308 strcat(sstr, tokens[i].c_str());
310 strcat(sstr,
" (frequency damping hopping-rate)");
312 }
else if ((line.Contains(
"dktt") || line.Contains(
"dynmKTTab")) && line.Contains(
"kdllf")) {
314 strcpy(sstr,
"dynExpKTLF ");
317 tokens = PStringUtils::Split(line.Data(),
" \t");
318 std::size_t noTokens = tokens.size();
320 std::cout << std::endl <<
"**ERROR** in THEORY block";
321 std::cout << std::endl <<
" Line: '" << str <<
"' is not a valid dynmKTTab statement.";
322 std::cout << std::endl <<
" Cannot handle file." << std::endl;
325 for (Int_t i=1; i<4; i++) {
327 strcat(sstr, tokens[i].c_str());
329 strcat(sstr,
" (frequency damping hopping-rate)");
331 }
else if (line.Contains(
"internFld")) {
333 noOfAddionalParams++;
336 strcpy(sstr,
"internFld ");
339 tokens = PStringUtils::Split(line.Data(),
" \t");
340 std::size_t noTokens = tokens.size();
342 std::cout << std::endl <<
"**ERROR** in THEORY block";
343 std::cout << std::endl <<
" Line: '" << str <<
"' is not a valid internFld statement.";
344 std::cout << std::endl <<
" Cannot handle file." << std::endl;
347 strcat(sstr,
" _x_");
348 for (Int_t i=1; i<4; i++) {
350 strcat(sstr, tokens[i].c_str());
352 strcat(sstr,
" (fraction phase frequency Trate Lrate)");
354 }
else if (line.Contains(
"internBsl")) {
356 noOfAddionalParams++;
359 strcpy(sstr,
"internBsl ");
362 tokens = PStringUtils::Split(line.Data(),
" \t");
363 std::size_t noTokens = tokens.size();
365 std::cout << std::endl <<
"**ERROR** in THEORY block";
366 std::cout << std::endl <<
" Line: '" << str <<
"' is not a valid internBsl statement.";
367 std::cout << std::endl <<
" Cannot handle file." << std::endl;
370 strcat(sstr,
" _x_");
371 for (Int_t i=1; i<4; i++) {
373 strcat(sstr, tokens[i].c_str());
375 strcat(sstr,
" (fraction phase frequency Trate Lrate)");
478 fin.open(fln, std::iostream::in);
479 if (!fin.is_open()) {
480 std::cout << std::endl <<
"**ERROR**: Couldn't open input msr-file " << fln;
481 std::cout << std::endl <<
" Will quit." << std::endl;
487 fout.open(
"__temp.msr", std::iostream::out);
488 if (!fout.is_open()) {
489 std::cout << std::endl <<
"**ERROR**: Couldn't open output msr-file __temp.msr";
490 std::cout << std::endl <<
" Will quit." << std::endl;
500 while (std::getline(fin, str) && success) {
501 if (str.find(
"FITPARAMETER") != std::string::npos) {
503 }
else if (str.find(
"THEORY") != std::string::npos) {
513 for (
int i=0; i<noOfAddionalParams; i++) {
514 fout <<
" " << param+i <<
" frac" << i+1 <<
" 0.333333 0.0 none" << std::endl;
523 if (str.find(
"_x_") != std::string::npos) {
530 fout << str << std::endl;
542 std::filesystem::copy_file(std::filesystem::path(
"__temp.msr"), std::filesystem::path(fln),
543 std::filesystem::copy_options::overwrite_existing, ec);
545 std::cerr <<
"**ERROR** couldn't copy __temp.msr -> " << fln <<
": " << ec.message() << std::endl;
548 std::filesystem::remove(std::filesystem::path(
"__temp.msr"), ec);
550 std::cerr <<
"**ERROR** couldn't remove __temp.msr: " << ec.message() << std::endl;
606int main(
int argc,
char *argv[])
617 fin.open(argv[1], std::iostream::in);
618 if (!fin.is_open()) {
619 std::cout << std::endl <<
"**ERROR**: Couldn't open input msr-file " << argv[1];
620 std::cout << std::endl <<
" Will quit." << std::endl;
626 fout.open(argv[2], std::iostream::out);
627 if (!fout.is_open()) {
628 std::cout << std::endl <<
"**ERROR**: Couldn't open output msr-file " << argv[2];
629 std::cout << std::endl <<
" Will quit." << std::endl;
638 int noOfAddionalParams = 0;
640 while (!fin.eof() && success) {
641 fin.getline(str,
sizeof(str));
643 if (strstr(str,
"FITPARAMETER")) {
645 }
else if (strstr(str,
"RUN")) {
647 }
else if (strstr(str,
"THEORY")) {
649 }
else if (strstr(str,
"STATISTIC")) {
670 fout << str << std::endl;
680 std::filesystem::remove_all(std::filesystem::path(argv[2]), ec);
682 std::cerr <<
"**ERROR** couldn't remove " << argv[2] <<
": " << ec.message() << std::endl;
687 if (theoryTag != -1) {
691 std::cout << std::endl <<
"done ..." << std::endl;