48 if (str1 == NULL && str2 != NULL)
50 if (str1 != NULL && str2 == NULL)
52 if (str1 == NULL && str2 == NULL)
56 if (toupper(*str1++) != toupper(*str2++))
101 char str[256], path[256], key_name[256], line[256];
117 if (strchr(key_name,
'[')) {
118 index = atoi(strchr(key_name,
'[') + 1);
119 *strchr(key_name,
'[') = 0;
133 s = fgets(line,
sizeof(line), f);
140 s = fgets(line,
sizeof(line), f);
143 if (strchr(line,
'=') != NULL) {
145 *(strchr(
str,
'=') - 1) = 0;
151 strcpy(
str, strchr(line,
'=') + 2);
152 if (strchr(
str,
':') != NULL) {
153 strcpy(
str, strchr(
str,
':') + 2);
154 if (strchr(
str,
'\n') != NULL)
155 *strchr(
str,
'\n') = 0;
156 if (
str[0] ==
'[' && strchr(
str,
']') != NULL)
157 strcpy(
str, strchr(
str,
']') + 2);
166 s = fgets(line,
sizeof(line), f);
170 if (line[0] ==
'[' && atoi(line + 1) ==
index) {
171 strcpy(
str, strchr(line,
']') + 2);
172 if (strchr(
str,
'\n') != NULL)
173 *strchr(
str,
'\n') = 0;
184 }
while (line[0] !=
'[' || line[1] !=
'/');
195 while (
str[a] !=
'\0')
198 while ((
str[
k] !=
'.') && (
k >= 0))
200 for (
i = 0;
i < (10 - (a -
k));
i++)
238 f1 = fopen(filename,
"r");
241 while (result != 0) {
243 if (fgets(line,
sizeof(line), f1) == NULL)
248 if (line[0] ==
'[') {
251 if (fgets(line,
sizeof(line), f1) != NULL) {
267 if (fgets(line,
sizeof(line), f1) != NULL) {
283 if ((fgets(line,
sizeof(line), f1) != NULL) && (line[0] !=
'['))
291 while (fgets(line,
sizeof(line), f1) != NULL && line[0] !=
'[') {
306 if ((fgets(line,
sizeof(line), f1) != NULL) && (line[0] !=
'['))
312 if ((fgets(line,
sizeof(line), f1) != NULL) && (line[0] !=
'['))
329 printf(
"\n ERROR:\nCan't open file %s\n", filename);
348#define EVENTID_BOR ((short int) 0x8000)
349#define EVENTID_EOR ((short int) 0x8001)
350#define EVENTID_MESSAGE ((short int) 0x8002)
372 char *buffer, *p, odb_name[256];
374 fhm = open(mid_file, O_RDONLY, 0644);
376 printf(
"Cannot open file \"%s\"\n", mid_file);
380 if (strchr(odb_file,
'%')) {
382 while (*p && !isdigit(*p))
385 snprintf(odb_name,
sizeof(odb_name), odb_file,
run_number);
387 strcpy(odb_name, odb_file);
389 fho = open(odb_name, O_WRONLY | O_CREAT | O_APPEND, 0644);
391 printf(
"Cannot open file \"%s\"\n", odb_name);
395 n =
read(fhm, &header,
sizeof(header));
396 if (
n !=
sizeof(header)) {
397 printf(
"Cannot read event header from file \"%s\"\n", mid_file);
402 printf(
"First event in \"%s\" is not a BOR event\n", mid_file);
406 buffer = (
char*)malloc(header.
data_size);
410 printf(
"Cannot read %d bytes from \"%s\"\n", header.
data_size, mid_file);
416 printf(
"Cannot write %d bytes to \"%s\"\n", header.
data_size, odb_name);
424 printf(
"\"%s\" successfully created\n", odb_name);
430int main(
int argc,
char *argv[])
432 int cfg, print, n_files;
434 strcpy(
var_name,
"/Runinfo/Run number");
449 for (
i = 1;
i < argc;
i++) {
450 if (argv[
i][0] ==
'-')
451 if (argv[
i][1] ==
'c') {
452 printf(
"%s", argv[
i + 1]);
464 for (
i = 1;
i < argc;
i++) {
465 if (argv[
i][0] ==
'-') {
466 if (argv[
i][1] ==
'q')
468 else if (argv[
i][1] ==
'a')
471 if (
i + 1 >= argc || argv[
i + 1][0] ==
'-')
473 if (argv[
i][1] ==
'r') {
476 }
else if (argv[
i][1] ==
'v') {
478 while (
i + 1 < argc && argv[
i + 1][0] !=
'-')
479 if (argv[
i + 1][0] !=
'-') {
482 if (argv[
i][0] !=
'-')
485 }
else if (argv[
i][1] ==
'f')
487 else if (argv[
i][1] ==
'e')
495 printf(
"\nusage: odbhist -r <run1> <run2> -v <varname>[index]\n");
496 printf(
" [-f <filename>] [-q] [-a] [-c <file>] [-e <file>]\n");
497 printf(
" <run1> <run2> Range of run numbers (inclusive)\n");
499 (
" <varname> ODB variable name like \"/Runinfo/Run number\"\n");
500 printf(
" [index] Index if <varname> is an array\n");
501 printf(
" <filename> run%%05d.odb by default\n");
502 printf(
" -e <file> Extract ODB file from MID file\n");
503 printf(
" -q Don't display run number\n");
504 printf(
" -a Add numbers for all runs\n");
505 printf(
" -c load configuration from file\n");
506 printf(
" (parameters loaded from cfg file will be\n");
507 printf(
" overwriten by parameters from command line)\n");
519 printf(
"Second run is %d and must be larger or equal than first run %d\n",
529 for (
k = 0;
k <=
j;
k++) {
556 for (
k = 0;
k <=
j;
k++)
557 printf(
"%lf\t",
total[
k]);
562 printf(
"No files found in selected range\n");
#define write(n, a, f, d)
BOOL equal_ustring(char *str1, char *str2)
int load_pars_from_file(char filename[256])
int extract(char *mid_file, char *odb_file)
int odb_hist(char *file_name, int run_number, char *var_name, int quiet, double *value, int eoln, int boln, int print)