Skip to content

Commit ae40396

Browse files
committed
Merge branch 'doc-preparations-3.6.0' of https://github.com/mccode-dev/McCode into doc-preparations-3.6.0
2 parents 43ef971 + 429e239 commit ae40396

File tree

14 files changed

+255
-149
lines changed

14 files changed

+255
-149
lines changed

mcstas-comps/contrib/TOFSANSdet.comp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@ SAVE
376376
sectnIef= (double*)malloc(sizeof(double)*Nqc*20);
377377
sectnWtf= (double*)malloc(sizeof(double)*Nqc*20);
378378

379+
if (!calibNf || !calibIf || !calibIef || !calibWtf || !sectnNf || !sectnIf || !sectnIef || !sectnWtf) {
380+
fprintf(stderr, "TOFSANSdet %s: Memory allocation error in SAVE. Fatal exit!\n", NAME_CURRENT_COMP);
381+
exit(-1);
382+
}
383+
379384
storez /= storen;
380385

381386
i = Nxc/2; /* calculate center values on beam stop */

mcstas-comps/examples/ISIS/ISIS_LET/ISIS_LET.instr

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,30 @@
1919
* %Example: Ei=3.7 res=HR Detector: sample_PSDmon_I=8835.3
2020
*
2121
* %P
22-
* Ei: [meV] Centre energy for moderator
23-
* dE: [] Multiplier for energy spread: Emin = Ei/dE, Emax = Ei*dE
24-
* Ch3_speed: [Hz] Chopper 3 frequency
25-
* Ch5_speed: [Hz] Chopper 5 frequency
26-
* Ch2_phase: [mus] Chopper 2 phase setting
27-
* pha_offset: [mus] Offset in time for moderator focus
28-
* res: [string] "HF" - High Flux, "HR" - High Resolution, "I" - Intermediate
29-
* snout: [string] "in" or "out"
22+
* Ei: [meV] Centre energy for moderator
23+
* dE: [] Multiplier for energy spread: Emin = Ei/dE, Emax = Ei*dE
24+
* Ch3_speed: [Hz] Chopper 3 frequency
25+
* Ch5_speed: [Hz] Chopper 5 frequency
26+
* Ch2_phase: [mus] Chopper 2 phase setting
27+
* pha_offset: [mus] Offset in time for moderator focus
28+
* res: [string] "HF" - High Flux, "HR" - High Resolution, "I" - Intermediate
29+
* snout: [string] "in" or "out"
30+
* monitors_on: [1] Flag to enable/disable TOF monitors in primary optics
31+
* movable_monitors: [1] Flag to enable/disable PSDs and Div monitors in primary optics
3032
*
3133
* %L
3234
* %E
3335
*******************************************************************************/
3436

3537
DEFINE INSTRUMENT ISIS_LET(Ei = 3.7, dE=1.1, Ch3_speed=100, Ch5_speed=200, Ch2_phase=95000,
36-
pha_offset=80e-6, string res="HF", string snout = "out")
38+
pha_offset=80e-6, string res="HF", string snout = "out", int monitors_on=0, int movable_monitors=0)
3739

3840
DECLARE
3941
%{
4042
double SE2K, v_foc, emin, emax, lam_min, lam_max, jitter=7e-7;
4143
double Ch1_speed, Ch2_speed=10, Ch2_offset=14500, Ch4_speed, Ch5_slit, snout_length;
4244
double L_Ch1=7.833, L_Ch2=8.200, L_Ch3=11.749, L_Ch4=15.664, L_Ch5=23.499;
4345
double L_sample=25, L2=3.5, Ch1_5_halfgap=0.005, smidge = 0.001;
44-
int monitors_on=0, movable_monitors=0;
4546
%}
4647

4748
INITIALIZE

mcstas-comps/examples/Tests_polarization/Supermirror_thin_substrate/Supermirror_thin_substrate.instr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*******************************************************************************
22
* McStas instrument definition URL=http://www.mcstas.org
33
*
4-
* Instrument: Supermirror_thin_substrate
4+
* Instrument: Supermirror_thin_substrate
55
*
66
* %Identification
77
* Written by: Hal Lee

mcstas-comps/examples/Tests_union/Geometry_test/Geometry_test.instr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ COMPONENT sample_box = Union_box(
9696
AT (-0.01,0,0) RELATIVE sample_pos
9797
ROTATED (34,17,0) RELATIVE sample_pos
9898

99-
/* COMPONENT sample_cone = Union_cone( */
100-
/* radius_top=0.031, radius_bottom=0.005, yheight=0.04, priority=22, material_string="Cu") */
101-
/* AT (0.02,-0.03,0) RELATIVE sample_pos */
102-
/* ROTATED (0,0,20) RELATIVE sample_pos */
99+
COMPONENT sample_cone = Union_cone(
100+
radius_top=0.031, radius_bottom=0.005, yheight=0.04, priority=22, material_string="Cu")
101+
AT (0.02,-0.03,0) RELATIVE sample_pos
102+
ROTATED (0,0,20) RELATIVE sample_pos
103103

104104
COMPONENT sample_torus = Union_mesh(
105105
filename = meshfile,

mcstas-comps/share/plane.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ int line_plane_intersect(Coords line_p, Coords line_v, Coords plane_normal, Coor
6666
(*d_intersect_point).x = 0;
6767
(*d_intersect_point).y = 0;
6868
(*d_intersect_point).z = 0;
69-
*dt = 0;
69+
*dt = 0;
70+
return 0;
7071
}
7172
else {
7273
(*d_intersect_point).x = line_v.x * (-n_dot_dp) / n_dot_v;
7374
(*d_intersect_point).y = line_v.y * (-n_dot_dp) / n_dot_v;
7475
(*d_intersect_point).z = line_v.z * (-n_dot_dp) / n_dot_v;
75-
*dt = -n_dot_dp / n_dot_v;
76+
*dt = -n_dot_dp / n_dot_v;
77+
return 0;
7678
}
7779
}
7880

mcstas-comps/share/polyhedron.c

Lines changed: 59 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ int form_polyhedron(int nf_in, Coords *fn_in, Coords *fp_in, Polyhedron *polyhed
299299
Coords *fn,*fp, nn;
300300
fn = calloc(nf_in, sizeof(Coords));
301301
fp = calloc(nf_in, sizeof(Coords));
302-
303-
//loop through nf_in
304-
for (i = 0; i < nf_in; i++) {
302+
if(fn && fp) {
303+
//loop through nf_in
304+
for (i = 0; i < nf_in; i++) {
305305
//fn_in[i] must have non-zero length
306306
if (coords_len(fn_in[i]) < DBL_EPSILON) {
307307
//error, skip this one
@@ -335,22 +335,23 @@ int form_polyhedron(int nf_in, Coords *fn_in, Coords *fp_in, Polyhedron *polyhed
335335
++nf;
336336
}
337337
}
338-
}
338+
}
339339

340-
if (nf < 4) {
340+
if (nf < 4) {
341341
return 0;
342-
}
342+
}
343343

344-
a->nf = nf;
345-
a->fn = calloc(nf, sizeof(Coords));
346-
a->fp = calloc(nf, sizeof(Coords));
347-
for (i = 0; i < nf; i++) {
344+
a->nf = nf;
345+
a->fn = calloc(nf, sizeof(Coords));
346+
a->fp = calloc(nf, sizeof(Coords));
347+
for (i = 0; i < nf; i++) {
348348
a->fn[i] = fn[i];
349349
a->fp[i] = fp[i];
350-
}
350+
}
351351

352-
free(fn);
353-
free(fp);
352+
free(fn);
353+
free(fp);
354+
}
354355
//note: do not zero nf, useful below.
355356

356357
////////////////////////
@@ -366,6 +367,12 @@ int form_polyhedron(int nf_in, Coords *fn_in, Coords *fp_in, Polyhedron *polyhed
366367
vp = calloc(nv, sizeof(Coords));
367368
nfvi = calloc(nf, sizeof(int));
368369
ifvi = calloc(nf, sizeof(int*));
370+
371+
if(!vp || !nfvi || !ifvi) {
372+
fprintf(stderr, "polyhedron.c / form_polyhedron - calloc error. Exit!\n");
373+
exit(-1);
374+
}
375+
369376
for (i = 0; i < nf; i++) {
370377
ifvi[i] = calloc(nv, sizeof(int));
371378
}
@@ -443,7 +450,8 @@ int form_polyhedron(int nf_in, Coords *fn_in, Coords *fp_in, Polyhedron *polyhed
443450
if (m >= 3 && keep) {
444451
//Now start checking
445452
eliminate_list = (int *)calloc(m, sizeof(int)); //initialise with 0 = not eliminate assocated vertex reference
446-
for (l = 0; l < m-2; l++) { //loop through vertices other than the last two since each check involves 3 different vertices
453+
if(eliminate_list) {
454+
for (l = 0; l < m-2; l++) { //loop through vertices other than the last two since each check involves 3 different vertices
447455
if (eliminate_list[m-1]) {
448456
//association with new vertext eliminated. Skip to check next plane.
449457
keep = 0;
@@ -478,9 +486,9 @@ int form_polyhedron(int nf_in, Coords *fn_in, Coords *fp_in, Polyhedron *polyhed
478486
eliminate_list[n] = 1;
479487
}
480488
}
481-
}
482-
//update list of vertex numbers associated with planes
483-
if (keep) {
489+
}
490+
//update list of vertex numbers associated with planes
491+
if (keep) {
484492
for (l = 0, n = 0; l < m; l++) {
485493
if (eliminate_list[l]) {
486494
continue;
@@ -489,8 +497,9 @@ int form_polyhedron(int nf_in, Coords *fn_in, Coords *fp_in, Polyhedron *polyhed
489497
++n;
490498
}
491499
nfvi[ii] = n;
500+
}
501+
free(eliminate_list);
492502
}
493-
free(eliminate_list);
494503
}
495504
}
496505
}
@@ -536,39 +545,40 @@ int form_polyhedron(int nf_in, Coords *fn_in, Coords *fp_in, Polyhedron *polyhed
536545
//The order of the vertices will go along the edge of the polyhedron face
537546
PolyhedronIndexValuePair *iA;
538547
iA = calloc(nfvi[i], sizeof(PolyhedronIndexValuePair));
539-
540-
k = ifvi[i][0];
541-
iA[0].index = k;
542-
iA[0].value = -2; //ensure the starting point stays the first point.
543-
p0 = a->vp[k];
544-
k = ifvi[i][1];
545-
dp01 = coords_sub(a->vp[k], p0); //reference line is between the first & second point
546-
l1 = coords_len(dp01);
547-
iA[1].index = k;
548-
iA[1].value = 1; //angle between the line from first to second point and the reference line is 0, i.e. cosA = 1
549-
550-
for (j = 2; j < nfvi[i]; j++) {
551-
k = ifvi[i][j];
552-
iA[j].index = k;
553-
554-
dp0n = coords_sub(a->vp[k], p0);
555-
l2 = coords_len(dp0n);
548+
if (iA) {
549+
k = ifvi[i][0];
550+
iA[0].index = k;
551+
iA[0].value = -2; //ensure the starting point stays the first point.
552+
p0 = a->vp[k];
553+
k = ifvi[i][1];
554+
dp01 = coords_sub(a->vp[k], p0); //reference line is between the first & second point
555+
l1 = coords_len(dp01);
556+
iA[1].index = k;
557+
iA[1].value = 1; //angle between the line from first to second point and the reference line is 0, i.e. cosA = 1
558+
559+
for (j = 2; j < nfvi[i]; j++) {
560+
k = ifvi[i][j];
561+
iA[j].index = k;
562+
563+
dp0n = coords_sub(a->vp[k], p0);
564+
l2 = coords_len(dp0n);
556565
iA[j].value = coords_sp(dp01, dp0n)/l1/l2;
566+
}
567+
568+
//sort the sequence according to iA[j].value,
569+
//the order of iA[j] is rearranged as a result
570+
//the resulting ordered index are in iA[j].index
571+
qsort(iA, nfvi[i], sizeof(iA[0]), polyhedron_qsort_compare_func);
572+
573+
//store the face vertext indices in the correct order in the array of face vertex indices
574+
a->afvi[i].ifvi = calloc(nfvi[i],sizeof(int));
575+
576+
for (j = 0; j < nfvi[i]; j++) {
577+
a->afvi[i].ifvi[j] = iA[j].index;
578+
}
579+
580+
free(iA);
557581
}
558-
559-
//sort the sequence according to iA[j].value,
560-
//the order of iA[j] is rearranged as a result
561-
//the resulting ordered index are in iA[j].index
562-
qsort(iA, nfvi[i], sizeof(iA[0]), polyhedron_qsort_compare_func);
563-
564-
//store the face vertext indices in the correct order in the array of face vertex indices
565-
a->afvi[i].ifvi = calloc(nfvi[i],sizeof(int));
566-
567-
for (j = 0; j < nfvi[i]; j++) {
568-
a->afvi[i].ifvi[j] = iA[j].index;
569-
}
570-
571-
free(iA);
572582
}
573583
}
574584

mcstas-comps/share/supermirror-lib.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,10 @@ int to_lower_case(char *in, char **out)
268268
int i;
269269
if (out) {
270270
*out=(char*)calloc(n+1,sizeof(char));
271-
for(i=0; i<n; i++) (*out)[i]= in[i]>='A'&&in[i]<='Z' ? in[i]|0x60 : in[i]; //convert to lower case
272-
if (i < CHAR_BUF_LENGTH) (*out)[i] = 0; //zero terminate the out string.
271+
if (*out) {
272+
for(i=0; i<n; i++) (*out)[i]= in[i]>='A'&&in[i]<='Z' ? in[i]|0x60 : in[i]; //convert to lower case
273+
if (i < CHAR_BUF_LENGTH) (*out)[i] = 0; //zero terminate the out string.
274+
}
273275
}
274276
else {
275277
for(i=0; i<n; i++) in[i]= in[i]>='A'&&in[i]<='Z' ? in[i]|0x60 : in[i]; //convert to lower case
@@ -451,7 +453,8 @@ void sm_print_state(char*subheader, SimState*state, Supermirror*sm, double ws_ta
451453

452454
int supermirror_flat_i_prefix = 0;
453455
char supermirror_flat_s_prefix[CHAR_BUF_LENGTH];
454-
456+
sprintf(supermirror_flat_s_prefix,"Sub_%s",subheader);
457+
455458
int i;
456459

457460
printf("%s sm_print_state: %s\n", supermirror_flat_s_prefix, subheader);
@@ -617,9 +620,9 @@ void sm_print_state(char*subheader, SimState*state, Supermirror*sm, double ws_ta
617620
printf("%s T_ir_at_ir_order_0[+/-] = indetermined\n", supermirror_flat_s_prefix);
618621
}
619622
else {
620-
printf("%s T_ir_all[+/-] = (% 5f,% 5f %)\n", supermirror_flat_s_prefix,
623+
printf("%s T_ir_all[+/-] = (% 5f,% 5f)\n", supermirror_flat_s_prefix,
621624
state->T_ir_all[0], state->T_ir_all[1]);
622-
printf("%s T_ir_at_ir_order_0[+/-] = (% 5f,% 5f %)\n", supermirror_flat_s_prefix,
625+
printf("%s T_ir_at_ir_order_0[+/-] = (% 5f,% 5f)\n", supermirror_flat_s_prefix,
623626
state->T_ir_at_ir_order_0[1], state->T_ir_at_ir_order_0[1]);
624627
}
625628
supermirror_flat_dec_prefix(&supermirror_flat_i_prefix, supermirror_flat_s_prefix);
@@ -808,8 +811,8 @@ int set_supermirror_flat_geometry (
808811
MPI_MASTER(printf( "set_supermirror_flat_geometry: ERROR tilt_y_axis_location=\"%s\" must be one of the following\n"
809812
" \"TopFrontEdge\",\"TopMirrorCentre\",\"TopBackEdge\"\n"
810813
" \"FrontSubstrateCentre\",\"SubstrateCentre\",\"BackSubstrateCentre\"\n"
811-
" \"BottomFrontEdge\",\"BottomMirrorCentre\",\"BottomBackEdge\" (case-insensitive)\n"
812-
);)
814+
" \"BottomFrontEdge\",\"BottomMirrorCentre\",\"BottomBackEdge\" (case-insensitive)\n",
815+
lc);)
813816
if (lc != 0) {
814817
free(lc);
815818
lc = 0;
@@ -3374,7 +3377,9 @@ int InitialiseStdSupermirrorFlat(
33743377
}
33753378
if (lc == 0) {
33763379
lc = (char*)calloc(14, sizeof(char));
3377-
strcpy(lc,"bothnotcoated");
3380+
if (lc) {
3381+
strcpy(lc,"bothnotcoated");
3382+
}
33783383
}
33793384
if (strcmp(lc,"bothcoated") == 0) {
33803385
strcpy(top_mirror_spin_plus_material, mirror_spin_plus_material_name); top_mirror_spin_plus_m = mirror_spin_plus_m;

0 commit comments

Comments
 (0)