Skip to content

Commit efb5291

Browse files
authored
Merge pull request #491 from hibtc/find_table
Add find_table function
2 parents d4a46ae + bb24b6b commit efb5291

File tree

13 files changed

+114
-209
lines changed

13 files changed

+114
-209
lines changed

src/mad_dynap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ track_dynap(struct in_cmd* cmd)
9090
trrun_(&flag, &turns,orbit0, oneturnmat, ibuf1, ibuf2, buf1, buf2,
9191
buf_dxt, buf_dyt, buf3, buf4, buf5, &e_flag, ibuf3, buf6);
9292

93-
t = table_register->tables[name_list_pos("tracksumm", table_register->names)];
93+
t = find_table("tracksumm");
9494
print_table(t);
9595
if (e_flag) {
9696
warning("track_dynap: particle lost before last turn,", "ignored");
@@ -99,7 +99,7 @@ track_dynap(struct in_cmd* cmd)
9999

100100
trdynrun_(buf4, buf5, &turns, &npart, buf7, buf8, buf10, buf11, buf9);
101101

102-
/* table_register->tables[name_list_pos("dynapsumm", table_register->names)];
102+
/* t = find_table("dynapsumm");
103103
print_table(t);
104104
if (get_option("dynap_dump")) dynap_tables_dump(); */
105105

src/mad_elemerr.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ error_seterr(struct in_cmd* cmd)
116116
char slnname[NAME_L];
117117

118118
char *namtab, namtab_buf[NAME_L];
119-
int t1;
120119

121120
struct table *err;
122121

@@ -127,7 +126,7 @@ error_seterr(struct in_cmd* cmd)
127126

128127
if ((namtab = command_par_string("table",cmd->clone)) != NULL) {
129128
printf("Want to use named table: %s\n",namtab);
130-
if ((t1 = name_list_pos(namtab, table_register->names)) > -1)
129+
if ((err = find_table(namtab)))
131130
printf("The table ==> %s <=== was found \n",namtab);
132131
else {
133132
warning("No such error table in memory:", namtab);
@@ -141,16 +140,14 @@ error_seterr(struct in_cmd* cmd)
141140
}
142141

143142
strcpy(namtab=namtab_buf,"error");
144-
if ((t1 = name_list_pos(namtab, table_register->names)) > -1)
143+
if ((err = find_table(namtab)))
145144
printf("The default table ==> %s <=== was found \n",namtab);
146145
else {
147146
warning("No default error table in memory:", namtab);
148147
exit(-77);
149148
}
150149
}
151150

152-
err = table_register->tables[t1];
153-
154151
/* check that the table has all the columns that we expect*/
155152
from_col = find_index_in_table(efield_table_cols, "k0l");
156153
to_col = find_index_in_table(efield_table_cols, "p20sl");

src/mad_exec.c

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ exec_create_table(struct in_cmd* cmd)
295295
return;
296296
}
297297

298-
if ((pos = name_list_pos(name, table_register->names)) > -1) {
298+
if (table_exists(name)) {
299299
warning("table already exists: ", "ignored");
300300
return;
301301
}
@@ -385,12 +385,12 @@ exec_dump(struct in_cmd* cmd)
385385
strcpy(filename,f);
386386

387387
// get table from registered tables
388-
if ((pos = name_list_pos(name, table_register->names)) < 0) {
388+
struct table* t = find_table(name);
389+
if (!t) {
389390
warning("table not found:", "ignored");
390391
return;
391392
}
392393

393-
struct table* t = table_register->tables[pos];
394394
out_table(name, t, filename);
395395

396396
return;
@@ -417,12 +417,12 @@ exec_shrink_table(struct in_cmd* cmd)
417417
return;
418418
}
419419

420-
if ((pos = name_list_pos(name, table_register->names)) < 0) {
420+
t = find_table(name);
421+
if (!t) {
421422
warning("table name not found:", "ignored");
422423
return;
423424
}
424425

425-
t = table_register->tables[pos];
426426
pos = name_list_pos("row", nl);
427427
row = pos >= 0 ? pl->parameters[pos]->double_value : t->curr - 1;
428428

@@ -450,12 +450,12 @@ exec_fill_table(struct in_cmd* cmd)
450450
return;
451451
}
452452

453-
if ((pos = name_list_pos(name, table_register->names)) < 0) {
453+
struct table* t = find_table(name);
454+
if (!t) {
454455
warning("table not found:", "ignored");
455456
return;
456457
}
457458

458-
struct table* t = table_register->tables[pos];
459459

460460
if ((pos = name_list_pos("row", nl)) < 0)
461461
row = t->curr+1;
@@ -497,13 +497,12 @@ exec_fill_knob_table(struct in_cmd* cmd)
497497
return;
498498
}
499499

500-
if ((pos = name_list_pos(name, table_register->names)) < 0) {
500+
struct table* t = find_table(name);
501+
if (!t) {
501502
warning("table not found:", "ignored");
502503
return;
503504
}
504505

505-
struct table* t = table_register->tables[pos];
506-
507506
if ((pos = name_list_pos("row", nl)) < 0)
508507
row = t->curr+1;
509508
else {
@@ -570,13 +569,12 @@ exec_setvars_table(struct in_cmd* cmd)
570569
return;
571570
}
572571

573-
if ((pos = name_list_pos(name, table_register->names)) < 0) {
572+
struct table* t = find_table(name);
573+
if (!t) {
574574
warning("table not found:", "ignored");
575575
return;
576576
}
577577

578-
struct table* t = table_register->tables[pos];
579-
580578
if ((pos = name_list_pos("row", nl)) < 0)
581579
row = t->curr;
582580
else {
@@ -612,13 +610,12 @@ exec_setvars_lin_table(struct in_cmd* cmd)
612610
return;
613611
}
614612

615-
if ((pos = name_list_pos(name, table_register->names)) < 0) {
613+
struct table* t = find_table(name);
614+
if (!t) {
616615
warning("table not found:", "ignored");
617616
return;
618617
}
619618

620-
struct table* t = table_register->tables[pos];
621-
622619
pos = name_list_pos("row1", nl);
623620
row1 = pos >= 0 ? (int) pl->parameters[pos]->double_value : t->curr;
624621
pos = name_list_pos("row2", nl);
@@ -678,13 +675,12 @@ exec_setvars_knob_table(struct in_cmd* cmd)
678675
return;
679676
}
680677

681-
if ((pos = name_list_pos(name, table_register->names)) < 0) {
678+
struct table* t = find_table(name);
679+
if (!t) {
682680
warning("table not found:", "ignored");
683681
return;
684682
}
685683

686-
struct table* t = table_register->tables[pos];
687-
688684
pos = name_list_pos("row", nl);
689685
row = pos >= 0 ? (int) pl->parameters[pos]->double_value : t->curr;
690686
pos = name_list_pos("knob", nl);
@@ -745,13 +741,12 @@ exec_setvars_const_table(struct in_cmd* cmd)
745741
return;
746742
}
747743

748-
if ((pos = name_list_pos(name, table_register->names)) < 0) {
744+
struct table* t = find_table(name);
745+
if (!t) {
749746
warning("table not found:", "ignored");
750747
return;
751748
}
752749

753-
struct table* t = table_register->tables[pos];
754-
755750
pos = name_list_pos("const", nl);
756751
double constant = pl->parameters[pos]->double_value;
757752

src/mad_node.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,10 +634,9 @@ advance_to_pos(char* table, int* t_pos)
634634
struct table* t;
635635
int pos, cnt = 0, ret = 0;
636636
mycpy(c_dum->c, table);
637-
if ((pos = name_list_pos(c_dum->c, table_register->names)) > -1)
637+
if ((t = find_table(c_dum->c)))
638638
{
639639
ret = 1;
640-
t = table_register->tables[pos];
641640
if (t->origin == 1) return 1; /* table is read, has no node pointers */
642641
while (current_node)
643642
{

src/mad_orbit.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ static void correct_setcorr(struct in_cmd* cmd) {
365365

366366
if ((namtab = command_par_string("table", cmd->clone)) != NULL ) {
367367
printf("Want to use named table: %s\n", namtab);
368-
if (name_list_pos(namtab, table_register->names) > -1) {
368+
if (table_exists(namtab)) {
369369
printf("The table ==> %s <=== was found \n", namtab);
370370
} else {
371371
/* fatal_error("Corrector table requested, but not existing:",namtab); */
@@ -802,7 +802,6 @@ static int pro_correct2_gettables(int iplane, struct in_cmd* cmd) {
802802
char* orbtab1;
803803
char* orbtab2;
804804

805-
int t1, t2;
806805
int ebl1, ebl2;
807806

808807
int j, k;
@@ -823,9 +822,7 @@ static int pro_correct2_gettables(int iplane, struct in_cmd* cmd) {
823822
/* Get access to tables, for orbit and model the default is twiss_table */
824823
if ((orbtab1 = command_par_string("beam1tab", cmd->clone)) != NULL ) {
825824
printf("Want to use orbit from: %s\n", orbtab1);
826-
if ((t1 = name_list_pos(orbtab1, table_register->names)) > -1) {
827-
b1 = table_register->tables[t1];
828-
} else {
825+
if (!(b1 = find_table(orbtab1))) {
829826
fatal_error("Beam 1 ORBIT table requested, but not provided:", orbtab1);
830827
}
831828
} else {
@@ -834,9 +831,7 @@ static int pro_correct2_gettables(int iplane, struct in_cmd* cmd) {
834831

835832
if ((orbtab2 = command_par_string("beam2tab", cmd->clone)) != NULL ) {
836833
printf("Want to use orbit from: %s\n", orbtab2);
837-
if ((t2 = name_list_pos(orbtab2, table_register->names)) > -1) {
838-
b2 = table_register->tables[t2];
839-
} else {
834+
if (!(b2 = find_table(orbtab2))) {
840835
fatal_error("Beam 2 ORBIT table requested, but not provided:", orbtab2);
841836
}
842837
} else {
@@ -1929,7 +1924,6 @@ static int pro_correct_gettables(int iplane, struct in_cmd* cmd) {
19291924
char* modtab;
19301925

19311926
int j;
1932-
int pps, ppt;
19331927

19341928
int cntm = { 0 };
19351929
int cntc = { 0 };
@@ -1948,9 +1942,7 @@ static int pro_correct_gettables(int iplane, struct in_cmd* cmd) {
19481942

19491943
if ((orbtab = command_par_string("orbit", cmd->clone)) != NULL ) {
19501944
printf("Want to use orbit from: %s\n", orbtab);
1951-
if ((pps = name_list_pos(orbtab, table_register->names)) > -1) {
1952-
orbin_table = table_register->tables[pps];
1953-
} else {
1945+
if (!(orbin_table = find_table(orbtab))) {
19541946
fatal_error("ORBIT table for correction requested, but not provided:", orbtab);
19551947
}
19561948
} else { // the orbit table is the twiss table
@@ -1965,9 +1957,7 @@ static int pro_correct_gettables(int iplane, struct in_cmd* cmd) {
19651957

19661958
if ((tartab = command_par_string("target", cmd->clone)) != NULL ) {
19671959
printf("Want to use target orbit from: %s\n", tartab);
1968-
if ((ppt = name_list_pos(tartab, table_register->names)) > -1) {
1969-
target_table = table_register->tables[ppt];
1970-
} else {
1960+
if (!(target_table = find_table(tartab))) {
19711961
fatal_error("TARGET table for correction requested, but not provided:", tartab);
19721962
}
19731963
} else {
@@ -1977,9 +1967,7 @@ static int pro_correct_gettables(int iplane, struct in_cmd* cmd) {
19771967

19781968
if ((modtab = command_par_string("model", cmd->clone)) != NULL ) {
19791969
printf("Want to use model orbit from: %s\n", modtab);
1980-
if ((ppt = name_list_pos(modtab, table_register->names)) > -1) {
1981-
model_table = table_register->tables[ppt];
1982-
} else {
1970+
if (!(model_table = find_table(modtab))) {
19831971
fatal_error("MODEL table for correction requested, but not provided:", modtab);
19841972
}
19851973
} else {

src/mad_plot.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -373,17 +373,11 @@ exec_plot(struct in_cmd* cmd)
373373
// name_list_pos(table_name, table_register->names));
374374

375375
/* HG 21.10.09 allow plot from external table, part1 */
376-
if ((pos = name_list_pos(table_name, table_register->names)) > -1) {
377-
p_table = table_register->tables[pos];
378-
if (!p_table) {
379-
warning("Plot - potentially already destroyed table:", table_name);
380-
return;
381-
}
382-
} else {
376+
p_table = find_table(table_name);
377+
if (!p_table) {
383378
/* fatal_error("Plot - non-existing table:", table_name); return; */
384379
warning("Plot - potentially non-existing table:", table_name);
385380
return;
386-
/*p_table = table_register->tables[pos];*/
387381
}
388382
/* HG 21.10.09 allow plot from external table, end part1 */
389383

0 commit comments

Comments
 (0)