-
Notifications
You must be signed in to change notification settings - Fork 39
/
mad_ptc.c
1998 lines (1656 loc) · 53 KB
/
mad_ptc.c
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "madx.h"
void makerdtstwisstable(void);
void printpoly(int*, int );
static void
fill_twiss_header_ptc(struct table* t, double ptc_deltap)
/* puts beam parameters etc. at start of twiss table */
{
int i, h_length = 100; /*39+3+1+1+6+4; change when adding header lines ! - last 6 for the closed orbit */
double dtmp;
/* struct table* s; */
static const int tmplen=49;
char tmp[tmplen];
int row;
static const char * const beampars[] = {"mass", "charge", "energy", "pc",
"gamma", "kbunch", "bcurrent",
"sige","sigt",
"npart",
"ex","ey","et"};
int Nbeampars = sizeof(beampars)/sizeof(beampars[0]);
static const char * const ptcpars[] = {"length", "alpha_c", "alpha_c_p", "alpha_c_p2",
"alpha_c_p3", "eta_c", "gamma_tr",
"q1","q2","dq1","dq2","qs",
"beta_x_min","beta_x_max","beta_y_min","beta_y_max",
"beta11min","beta11max", "beta12min","beta12max", "beta13min","beta13max",
"beta21min","beta21max", "beta22min","beta22max", "beta23min","beta23max",
"beta31min","beta31max", "beta32min","beta32max", "beta33min","beta33max",
"disp1min","disp1max",
"disp2min","disp2max",
"disp3min","disp3max",
"disp4min","disp4max",
"orbit_x", "orbit_px","orbit_y","orbit_py","orbit_pt","orbit_t",
"xcorms", "pxcorms","ycorms","pycorms","tcorms","ptcorms",
"xcomin", "xcomax",
"pxcomin", "pxcomax",
"ycomin", "ycomax",
"pycomin", "pycomax",
"tcomin", "tcomax",
"ptcomin", "ptcomax"};
int Nptcpars = sizeof(ptcpars)/sizeof(ptcpars[0]);
/*printf("There is %d beam parameters and %d PTC pars to add\n",Nbeampars,Nptcpars);*/
if (t == NULL) return;
/* ATTENTION: if you add header lines, augment h_length accordingly */
if (t->header == NULL) t->header = new_char_p_array(h_length);
strncpy(tmp, t->org_sequ->name,tmplen);
sprintf(c_dum->c, v_format("@ SEQUENCE %%%02ds \"%s\""),
strlen(tmp),stoupper(tmp));
addto_char_p_array(t->header,c_dum);
i = get_string("beam", "particle", tmp);
sprintf(c_dum->c, v_format("@ PARTICLE %%%02ds \"%s\""),
i, stoupper(tmp));
addto_char_p_array(t->header,c_dum);
for (i=0; i<Nbeampars;i++)
{
strncpy(tmp,beampars[i],tmplen); /*we have to copy for stoupper that can not change a constant string*/
dtmp = get_value("beam", tmp);
sprintf(c_dum->c, v_format("@ %-16.16s %%le %F"),stoupper(tmp) ,dtmp);
addto_char_p_array(t->header,c_dum);
}
sprintf(c_dum->c, v_format("@ DELTAP %%le %F"), ptc_deltap);
addto_char_p_array(t->header,c_dum);
if (get_option("ptc_twiss_summary") != zero){
/* one-turn information gets computed iff ptc_twiss_summary set to 1 in madx_ptc_twiss.f90 */
/* retreive all pieces of information from the ptc_twiss*/
row = 1; /* this particular table has only one row filled-in */
for (i=0; i<Nptcpars;i++)
{
strncpy(tmp,ptcpars[i],tmplen);
double_from_table_row("ptc_twiss_summary",tmp,&row,&dtmp);
sprintf(c_dum->c, v_format("@ %-16.16s %%le %F"),stoupper(tmp) ,dtmp);
addto_char_p_array(t->header,c_dum);
}
}
}
static int
pro_ptc_select_checkpushtable(struct in_cmd* cmd, struct int_array** tabnameIA, struct int_array** colnameIA)
{
struct command_parameter_list* c_parameters= cmd->clone->par;
struct name_list* c_parnames = cmd->clone->par_names;
struct table* aTable = 0x0;
int pos = 0;
char* tablename = 0x0;
char* columnname = 0x0;
/*extracts column specified by the user*/
pos = name_list_pos("column", c_parnames);
if (pos < 0)
{
printf("mad_ptc.c: pro_ptc_select: column parameter does not exist.\n");
return 5;
}
columnname = c_parameters->parameters[pos]->string;
if ( columnname == 0x0 )
{
/* warning("mad_ptc.c: pro_ptc_select: Column name is empty: ", "ignored");*/
return 6;
}
*colnameIA = new_int_array(1+strlen(columnname));
conv_char(columnname,*colnameIA);
/*extracts table specified by the user*/
pos = name_list_pos("table", c_parnames);
if (pos < 0)
{
printf("mad_ptc.c: pro_ptc_select: table parameter does not exist.\n");
return 1;
}
tablename = c_parameters->parameters[pos]->string;
if ( tablename == 0x0 )
{
return -1;/*This means that table name was not specified at all*/
}
if ( tablename[0] == 0 )
{
return -1; /*This means that table name was not specified at all*/
}
aTable = find_table(tablename);
if (!aTable)
{
printf("mad_ptc.c: pro_ptc_select: table <<%s>> does not exist: Create table first\n",tablename);
return 3;
}
/*checks if the specified column exists*/
pos = name_list_pos(columnname,aTable->columns);
if (pos < 0)
{
mad_error("mad_ptc.c: pro_ptc_select","Can not find column named <<%s>> in table <<%s>>.",
columnname,aTable->name);
return 7;
}
pos = name_list_pos("name",aTable->columns);
if (pos < 0)
{
warning("mad_ptc.c: pro_ptc_selectaTable->name: There is no column named <<name>> in table <<%s>>.",aTable->name);
return 8;
}
/*so none of the columns is filled */
aTable->org_cols = aTable->num_cols;
*tabnameIA = new_int_array(1+strlen(tablename));
conv_char(tablename,*tabnameIA);
return 0;
}
// public interface
int
minimum_acceptable_order(void)
{
return min_order;
}
int
select_ptc_idx(void)
{
struct table* t = find_table("normal_results");;
return t ? t->curr : -1;
}
void
ptc_track_end(void)
{
int i;
struct node* c_node;
if (track_is_on == 0)
{
warning("ptc_track_end: no PTC_TRACK command seen yet", "ignored");
return;
}
for (i = 0; i < stored_track_start->curr; i++)
stored_track_start->commands[i] =
delete_command(stored_track_start->commands[i]);
stored_track_start->curr = 0;
if (current_sequ)
{
c_node = current_sequ->ex_start;
}
else
{
c_node = 0x0;
}
while(c_node != NULL) /* clean observation points */
{
c_node->obs_point = 0;
c_node->obs_orbit = delete_double_array(c_node->obs_orbit);
if (c_node == current_sequ->ex_end) break;
c_node = c_node->next;
}
curr_obs_points = 1;
track_is_on = 0;
}
void
ptc_track_observe(struct in_cmd* cmd)
{
struct node* nodes[2];
const char* place = command_par_string("place", cmd->clone);
if (get_ex_range(place, current_sequ, nodes))
{
nodes[0]->obs_point = ++curr_obs_points;
printf("obs_points: %d \n",curr_obs_points);
}
else
{
warning("ptc_track_observe: unknown place,", "ignored");
return;
}
}
/*________________________________________________________________*/
void
ptc_putbeambeam(struct in_cmd* cmd)
{
/*Installs beam beam interaction on a given integration step*/
/*might be defined by global s or element name and local s*/
(void)cmd;
w_ptc_putbeambeam_();
}
/*________________________________________________________________*/
void
ptc_dumpmaps(struct in_cmd* cmd)
/*Dumps PTC map for each element in the current sequence*/
{
(void)cmd;
w_ptc_dumpmaps_();
}
void
ptc_oneturnmap(struct in_cmd* cmd)
{
(void)cmd;
}
void
pro_ptc_normal(void)
/* controls ptc_normal module */
{
// need to set probe_beam to read beam parameters for beam-beam, for example
struct command* keep_beam = current_beam;
double ptc_deltap;
ptc_deltap = get_value(current_command->name,"deltap");
adjust_beam();
probe_beam = clone_command(current_beam);
adjust_probe_fp(ptc_deltap); /* sets correct gamma, beta, etc. */
w_ptc_normal_();
/* cleanup */
current_beam = keep_beam;
probe_beam = delete_command(probe_beam);
}
void
pro_ptc_twiss(void)
/* controls ptc_twiss module */
{
struct command* keep_beam = current_beam;
struct int_array* tarr;
int ptc_twiss_summary = 0 ; /* set to 1 when a summary-table is filled-in */
struct int_array* summary_tarr; /* to pass summary-table name to Fortran */
struct node *nodes[2], *use_range[2];
double ptc_deltap;
const char *table_name = NULL, *summary_table_name = NULL;
char *filename = NULL, *summary_filename = NULL; /* for summary table */
int j, w_file,beta_def;
int w_file_summary; /* toggle to write the summary table into a file */
struct table* nonlin_table = 0;
/*
start command decoding
*/
use_range[0] = current_sequ->range_start;
use_range[1] = current_sequ->range_end;
char* range = command_par_string_user("range", current_twiss);
if (range)
{
if (get_sub_range(range, current_sequ, nodes))
{
current_sequ->range_start = nodes[0];
current_sequ->range_end = nodes[1];
}
else warning("illegal range ignored:", range);
}
for (j = 0; j < current_sequ->n_nodes; j++)
{
if (current_sequ->all_nodes[j] == current_sequ->range_start) break;
}
if (attach_beam(current_sequ) == 0)
fatal_error("PTC_TWISS - sequence without beam:", current_sequ->name);
table_name = command_par_string_user("table", current_twiss);
if(!table_name)
table_name = "ptc_twiss";
/* --- */
/* do the same as above for the table holding summary data after one-turn */
summary_table_name = command_par_string_user("summary_table", current_twiss);
if (!summary_table_name)
summary_table_name = "ptc_twiss_summary";
/* --- */
w_file = command_par_string_user2("file", current_twiss, &filename);
if (w_file && !filename) // TG: should be impossible?
filename = permbuff("dummy");
/* --- */
/* do the same as above for the file to hold the summary-table */
w_file_summary = command_par_string_user2("summary_file", current_twiss, &summary_filename);
if (w_file_summary && !summary_filename) // TG: should be impossible?
summary_filename = permbuff("dummy");
/*
end of command decoding
*/
if ((beta_def = twiss_input(current_twiss)) < 0)
{
if (beta_def == -1) warning("unknown beta0,", "Twiss ignored");
else if (beta_def == -2)
warning("betx or bety missing,", "Twiss ignored");
/* set_variable("twiss_tol", &tol_keep); */
return;
}
set_option("twiss_inval", &beta_def);
ptc_deltap = get_value(current_command->name,"deltap");
// LD 2016.04.19
adjust_beam();
probe_beam = clone_command(current_beam);
adjust_probe_fp(ptc_deltap); /* sets correct gamma, beta, etc. */
nonlin_table = make_table("nonlin", "nonlin", nonlin_table_cols,
nonlin_table_types, current_sequ->n_nodes);
/*nonlin_table->dynamic = 1;*/
add_to_table_list(nonlin_table, table_register);
tarr = new_int_array(strlen(table_name)+1);
conv_char(table_name, tarr);
twiss_table = make_table(table_name, "twiss", twiss_table_cols,
twiss_table_types, current_sequ->n_nodes);
twiss_table->dynamic = 1;
add_to_table_list(twiss_table, table_register);
current_sequ->tw_table = twiss_table;
twiss_table->org_sequ = current_sequ;
twiss_table->curr= 0;
current_node = current_sequ->ex_start;
/* w_ptc_twiss_(tarr->i); */
if (command_par_value("trackrdts",current_twiss) != 0)
{
makerdtstwisstable();
}
/* --- */
/* create additional table to hold summary data after one-turn */
/* such as momentum compaction factor, tune and chromaticities */
summary_tarr = new_int_array(strlen(summary_table_name)+1);
conv_char(summary_table_name, summary_tarr);
ptc_twiss_summary_table = make_table(summary_table_name, "twiss summary",
ptc_twiss_summary_table_cols, ptc_twiss_summary_table_types,
5); /* only one row would be enough */
/* 18 january 2010 static table - ptc_twiss_summary_table->dynamic = 1; */
/* actually static for time-being */
add_to_table_list( ptc_twiss_summary_table, table_register );
/* --- */
w_ptc_twiss_(tarr->i,summary_tarr->i);
/* upon completion of the Fortran ptc_twiss call ... */
fill_twiss_header_ptc(twiss_table,ptc_deltap);
if (w_file) out_table(table_name, twiss_table, filename);
/* --- */
if (w_file_summary) out_table(summary_table_name, ptc_twiss_summary_table,
summary_filename);
/* --- */
/* cleanup */
current_beam = keep_beam;
probe_beam = delete_command(probe_beam);
current_sequ->range_start = use_range[0];
current_sequ->range_end = use_range[1];
delete_int_array(tarr);
/* --- */
delete_int_array(summary_tarr);
/* --- */
ptc_twiss_summary = get_option("ptc_twiss_summary");
if (ptc_twiss_summary) {
print_table(ptc_twiss_summary_table);
}
}
void
pro_ptc_create_layout(void)
/* controls ptc_create_layout module */
{
// int pos; not used
struct command* keep_beam = current_beam;
if (attach_beam(current_sequ) == 0)
fatal_error("ptc_create_layout - sequence without beam:", current_sequ->name);
// LD 2016.04.19
adjust_beam();
probe_beam = clone_command(current_beam);
adjust_probe_fp(0);
if (!table_exists("errors_dipole"))
{
errors_dipole = make_table("errors_dipole", "efield", efield_table_cols,
efield_table_types, 10000);
add_to_table_list(errors_dipole, table_register);
}
else
{
reset_count("errors_dipole");
}
if (!table_exists("errors_field"))
{
errors_field = make_table("errors_field", "efield", efield_table_cols,
efield_table_types, 10000);
add_to_table_list(errors_field, table_register);
}
else
{
reset_count("errors_field");
}
if (!table_exists("errors_total"))
{
errors_total = make_table("errors_total", "efield", efield_table_cols,
efield_table_types, 10000);
add_to_table_list(errors_total, table_register);
}
else
{
reset_count("errors_total");
}
w_ptc_create_layout_();
/* cleanup */
current_beam = keep_beam;
probe_beam = delete_command(probe_beam);
}
void
pro_ptc_read_errors(void)
/* controls ptc_read_errors module */
{
struct command* keep_beam = current_beam;
if (attach_beam(current_sequ) == 0)
fatal_error("ptc_read_errors - sequence without beam:", current_sequ->name);
// LD 2016.04.19
adjust_beam();
probe_beam = clone_command(current_beam);
adjust_probe_fp(0);
w_ptc_read_errors_();
/* cleanup */
current_beam = keep_beam;
probe_beam = delete_command(probe_beam);
}
void
pro_ptc_refresh_k(void)
/* controls ptc_refresh_k module */
{
struct command* keep_beam = current_beam;
if (attach_beam(current_sequ) == 0)
fatal_error("ptc_refresh_k - sequence without beam:", current_sequ->name);
// LD 2016.04.19
adjust_beam();
probe_beam = clone_command(current_beam);
adjust_probe_fp(0);
w_ptc_refresh_k_();
/* cleanup */
current_beam = keep_beam;
probe_beam = delete_command(probe_beam);
}
void
select_ptc_normal(struct in_cmd* cmd)
/* sets up all columns of the table normal_results except the last one (value) */
{
struct table* t;
struct command_parameter* cp;
int i, j, jj, curr;
int skew, mynorder,myn1,myn2,mynres,indexa[4][1000];
char* order_list;
int min_req_order;
double order[4],n1,n2,n3,n4;
if (log_val("clear", cmd->clone))
{
min_order = 1;
min_req_order = 1;
mynres = 0;
skew = 0;
reset_count("normal_results");
/* if (t = find_table("normal_results")) delete_table(t);*/
return;
}
if (!(t = find_table("normal_results")))
{
/* initialise table */
normal_results = make_table("normal_results", "normal_res", normal_res_cols,
normal_res_types, MAX_ROWS);
normal_results->dynamic = 1;
add_to_table_list(normal_results, table_register);
reset_count("normal_results");
t = find_table("normal_results");
min_order = 1;
min_req_order = 1;
}
/* initialise order array */
order[0] = zero;
order[1] = zero;
order[2] = zero;
order[3] = zero;
if (t->curr == t->max) grow_table(t);
for (j = 0; j < PTC_NAMES_L; j++)
{
/* Treat each ptc variable */
if (command_par(names[j], this_cmd->clone, &cp))
{
curr = cp->m_string->curr;
if (curr > 4)
printf("Too many values for the attribute %s. Only the first four are retained.\n",names[j]);
for (i = 0; i < curr; i++)
{
order_list = cp->m_string->p[i];
order[i] = atoi(order_list);
}
if (j == 10 || j == 11)
{
min_req_order = order[0]+order[1]+order[2];
mynres = 0;
skew = 0;
mynorder = (int)order[0];
if (mynorder < 0) skew = 1;
mynorder = abs(mynorder);
myn1 = (int)order[1];
myn2 = (int)order[2];
min_req_order = mynorder;
res_index_(&skew, &mynorder, &myn1, &myn2, &indexa[0][0], &mynres);
if (mynres > 0)
{
if (j == 10)
{
for (jj = 0; jj < mynres; jj++)
{
n1 = (double)indexa[0][jj];
n2 = (double)indexa[1][jj];
n3 = (double)indexa[2][jj];
n4 = (double)indexa[3][jj];
string_to_table_curr("normal_results", "name", "hamc");
double_to_table_curr("normal_results", "order1", &n1);
double_to_table_curr("normal_results", "order2", &n2);
double_to_table_curr("normal_results", "order3", &n3);
double_to_table_curr("normal_results", "order4", &n4);
augment_count("normal_results");
string_to_table_curr("normal_results", "name", "hams");
double_to_table_curr("normal_results", "order1", &n1);
double_to_table_curr("normal_results", "order2", &n2);
double_to_table_curr("normal_results", "order3", &n3);
double_to_table_curr("normal_results", "order4", &n4);
augment_count("normal_results");
string_to_table_curr("normal_results", "name", "hama");
double_to_table_curr("normal_results", "order1", &n1);
double_to_table_curr("normal_results", "order2", &n2);
double_to_table_curr("normal_results", "order3", &n3);
double_to_table_curr("normal_results", "order4", &n4);
augment_count("normal_results");
}
string_to_table_curr("normal_results", "name", "haml");
double_to_table_curr("normal_results", "order1", &order[0]);
double_to_table_curr("normal_results", "order2", &order[1]);
double_to_table_curr("normal_results", "order3", &order[2]);
double_to_table_curr("normal_results", "order4", &order[3]);
n1 = (double)mynres;
double_to_table_curr("normal_results", "value", &n1);
augment_count("normal_results");
}
if (j == 11)
{
for (jj = 0; jj < mynres; jj++)
{
n1 = (double)indexa[0][jj];
n2 = (double)indexa[1][jj];
n3 = (double)indexa[2][jj];
n4 = (double)indexa[3][jj];
string_to_table_curr("normal_results", "name", "gnfc");
double_to_table_curr("normal_results", "order1", &n1);
double_to_table_curr("normal_results", "order2", &n2);
double_to_table_curr("normal_results", "order3", &n3);
double_to_table_curr("normal_results", "order4", &n4);
augment_count("normal_results");
string_to_table_curr("normal_results", "name", "gnfs");
double_to_table_curr("normal_results", "order1", &n1);
double_to_table_curr("normal_results", "order2", &n2);
double_to_table_curr("normal_results", "order3", &n3);
double_to_table_curr("normal_results", "order4", &n4);
augment_count("normal_results");
string_to_table_curr("normal_results", "name", "gnfa");
double_to_table_curr("normal_results", "order1", &n1);
double_to_table_curr("normal_results", "order2", &n2);
double_to_table_curr("normal_results", "order3", &n3);
double_to_table_curr("normal_results", "order4", &n4);
augment_count("normal_results");
}
string_to_table_curr("normal_results", "name", "gnfu");
double_to_table_curr("normal_results", "order1", &order[0]);
double_to_table_curr("normal_results", "order2", &order[1]);
double_to_table_curr("normal_results", "order3", &order[2]);
double_to_table_curr("normal_results", "order4", &order[3]);
n1 = (double)mynres;
double_to_table_curr("normal_results", "value", &n1);
augment_count("normal_results");
}
}
}
else
{
if(((strcmp(names[j], "dq1") == zero)|| (strcmp(names[j], "dq2") == zero)) && order[0] == zero) order[0]=one;
string_to_table_curr("normal_results", "name", names[j]);
double_to_table_curr("normal_results", "order1", &order[0]);
double_to_table_curr("normal_results", "order2", &order[1]);
double_to_table_curr("normal_results", "order3", &order[2]);
double_to_table_curr("normal_results", "order4", &order[3]);
augment_count("normal_results");
if(j == 12)
{
min_req_order = 1;
}
else
{
min_req_order = order[0]+order[1]+order[2];
if (j >= 8) min_req_order += order[0]+order[1];
if (j >= 6) min_req_order += 1;
}
}
if (min_order < min_req_order) min_order = min_req_order;
}
}
if (debuglevel > 2)
{
printf("The minimum required order is %d \n--------------------------------\n",min_order);
}
}
void
pro_ptc_trackline(struct in_cmd* cmd)
{
/*Does PTC tracking taking to the account acceleration */
/*it is basically wrapper to subroutine ptc_trackline() in madx_ptc_trackline.f90*/
int one = 1;
int parexist = -1;
double value = 0;
int ivalue = 0;
struct command* keep_beam = current_beam;
if (attach_beam(current_sequ) == 0)
fatal_error("PTC_TRACKLINE - sequence without beam:", current_sequ->name);
if (command_par_string_or_calldef("file", cmd->clone, &track_filename))
set_option("track_dump", &one);
if (!track_filename)
track_filename = permbuff("dummy");
track_filename = permbuff(track_filename);
command_par_string_or_calldef("extension", cmd->clone, &track_fileext);
if (!track_fileext)
track_fileext = permbuff("\0");
track_fileext = permbuff(track_fileext);
if (command_par_value("everystep",cmd->clone) != 0)
{
printf("Enforcing onetable=true, current is %f\n", command_par_value("onetable",cmd->clone));
set_command_par_value("onetable", cmd->clone, 1.0);
printf("Now is %f\n", command_par_value("onetable",cmd->clone));
}
parexist = command_par_value2("onetable",cmd->clone,&value);
if (parexist)
{
ivalue = (int)value;
set_option("onetable", &ivalue);
}
// LD 2016.04.19
adjust_beam();
probe_beam = clone_command(current_beam);
adjust_probe_fp(0);
track_tables_delete(); /* deleting all track related tables*/
track_tables_create(cmd);
if (command_par_value("everystep",cmd->clone) != 0)
{
/*printf("Calling PTC track line every step\n");*/
w_ptc_track_everystep_(&curr_obs_points);
}
else
{
/*printf("Calling STD PTC track line\n");*/
w_ptc_trackline_(&curr_obs_points);
}
track_tables_dump();
/* cleanup */
current_beam = keep_beam;
probe_beam = delete_command(probe_beam);
}
void
pro_ptc_enforce6d(struct in_cmd* cmd)
{
/*Does PTC tracking taking to the account acceleration */
/*it is basically wrapper to subroutine ptc_trackline() in madx_ptc_trackline.f90*/
double switchvalue;
struct name_list* nl;
int flag;
if (cmd == 0x0)
{
warning("pro_ptc_enforce6d:","Command is null!!!");
return;
}
if (cmd->clone == 0x0)
{
mad_error("pro_ptc_enforce6d","Command Definintion is null!!!");
return;
}
nl = cmd->clone->par_names;
/*DEBUG LEVEL SWITCH*/
if ( name_list_pos("flag", nl) >=0 )
{
command_par_value2("flag", cmd->clone, &switchvalue);
flag = (int)switchvalue;
w_ptc_enforce6d_(&flag);
}
else
{
printf("flag is not present\n");
}
}
void
pro_ptc_setswitch(struct in_cmd* cmd)
{
/*Does PTC tracking taking to the account acceleration */
/*it is basically wrapper to subroutine ptc_trackline() in madx_ptc_trackline.f90*/
int i;
double switchvalue;
struct name_list* nl;
int found;
if (cmd == 0x0)
{
warning("pro_ptc_setswitch:","Command is null!!!");
return;
}
if (cmd->clone == 0x0)
{
printf("pro_ptc_setswitch: Command Definintion is null!!!\n");
return;
}
if (match_is_on == kMatch_PTCknobs)
{
madx_mpk_setsetswitch(cmd);
return;
}
nl = cmd->clone->par_names;
/*DEBUG DEBUG LEVEL*/
if ( name_list_pos("debuglevel", nl) >=0 )
{
found = command_par_value2("debuglevel", cmd->clone, &switchvalue);
debuglevel = (int)switchvalue;
w_ptc_setdebuglevel_(&debuglevel);
}
else
{
printf("debuglevel is not present (keeping current value)\n");
}
/*MAPDUMP LEVEL*/
if ( name_list_pos("mapdump", nl) >=0 ) {
found = command_par_value2("mapdump", cmd->clone, &switchvalue);
// if (debuglevel > 0) printf("mapdump is found and its value is %f\n", switchvalue);
int mapdump = (int)switchvalue;
w_ptc_setmapdumplevel_(&mapdump);
}
/*MADPRINT TPSA FORMAT*/
if ( name_list_pos("madprint", nl) >=0 ) {
found = command_par_value2("madprint", cmd->clone, &switchvalue);
// if (debuglevel > 0) printf("madprint is found and its value is %f\n", switchvalue);
int madprint = (int)switchvalue;
w_ptc_setmadprint_(&madprint);
}
/*ACCELERATION SWITCH*/
found = command_par_value_user2("maxacceleration", cmd->clone, &switchvalue);
if (found)
{
if (debuglevel > 0) printf("maxaccel is found and its value is %f\n", switchvalue);
i = (int)switchvalue;
w_ptc_setaccel_method_(&i);
}
else
{
if (debuglevel > 0) printf("maxaccel is not present (keeping current value)\n");
}
/*EXACT_MIS SWITCH*/
found = command_par_value_user2("exact_mis", cmd->clone, &switchvalue);
if (found)
{
if (debuglevel > 0) printf("exact_mis is found and its value is %f\n", switchvalue);
i = (int)switchvalue;
w_ptc_setexactmis_(&i);
}
else
{
if (debuglevel > 0) printf("exact_mis is not present (keeping current value)\n");
}
/*radiation SWITCH*/
found = command_par_value_user2("radiation", cmd->clone, &switchvalue);
if (found)
{
if (debuglevel > 0) printf("radiation is found and its value is %f\n", switchvalue);
i = (int)switchvalue;
w_ptc_setradiation_(&i);
}
else
{
if (debuglevel > 0) printf("radiation is not present (keeping current value)\n");
}
/*modulation SWITCH*/
found = command_par_value_user2("modulation", cmd->clone, &switchvalue);
if (found)
{
if (debuglevel > 0) printf("modulation is found and its value is %f\n", switchvalue);
i = (int)switchvalue;
w_ptc_setmodulation_(&i);
}
else
{
if (debuglevel > 0) printf("modulation is not present (keeping current value)\n");
}
/*stochastic SWITCH*/
found = command_par_value_user2("stochastic", cmd->clone, &switchvalue);
if (found)
{
if (debuglevel > 0) printf("stochastic is found and its value is %f\n", switchvalue);
i = (int)switchvalue;
w_ptc_setstochastic_(&i);
}
else
{
if (debuglevel > 0) printf("stochastic is not present (keeping current value)\n");
}
/*spin SWITCH*/
found = command_par_value_user2("spin", cmd->clone, &switchvalue);
if (found)
{
if (debuglevel > 0) printf("spin is found and its value is %f\n", switchvalue);
i = (int)switchvalue;
w_ptc_setspin_(&i);
}
else
{
if (debuglevel > 10) printf("spin is not present (keeping current value)\n");
}
/*envelope SWITCH*/
found = command_par_value_user2("envelope", cmd->clone, &switchvalue);
if (found)
{
if (debuglevel > 0) printf("envelope is found and its value is %f\n", switchvalue);
i = (int)switchvalue;
w_ptc_setenvelope_(&i);
}
else
{
if (debuglevel > 0) printf("envelope is not present (keeping current value)\n");
}
/*fringe SWITCH*/
found = command_par_value_user2("fringe", cmd->clone, &switchvalue);
if (found)
{
if (debuglevel > 0) printf("fringe is found and its value is %f\n", switchvalue);
i = (int)switchvalue;
w_ptc_setfringe_(&i);
}
else
{
if (debuglevel > 0) printf("fringe is not present (keeping current value)\n");
}
/*totalpath SWITCH*/
found = command_par_value_user2("totalpath", cmd->clone, &switchvalue);
if (found)
{
if (debuglevel > 0) printf("totalpath is found and its value is %f\n", switchvalue);
i = (int)switchvalue;
w_ptc_settotalpath_(&i);
}
else
{
if (debuglevel > 0) printf("totalpath is not present (keeping current value)\n");
}
/*TIME SWITCH*/
found = command_par_value_user2("time", cmd->clone, &switchvalue);
if (found)
{
if (debuglevel > 0) printf("time is found and its value is %f\n", switchvalue);