Skip to content

Commit 18f6ac4

Browse files
authored
Merge pull request #2248 from mccode-dev/linter-fixes
Various McStas linter fixes
2 parents 2ee65e0 + 2fd52ba commit 18f6ac4

22 files changed

+458
-155
lines changed

.github/workflows/mcstas-basictest.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,24 +470,26 @@ jobs:
470470
cd src
471471
export CHANGEDCOMPS=`git diff --name-only HEAD HEAD~1| grep \.comp\$ | grep mcstas-comps | xargs -n1 basename | sed s/\.comp//g | xargs echo`
472472
export NUMCHANGEDCOMPS=`git diff --name-only HEAD HEAD~1|grep \.comp\$ | grep mcstas-comps | wc -l | xargs echo`
473+
cd -
473474
if [ "$NUMCHANGEDCOMPS" != "0" ];
474475
then
475476
for comp in $CHANGEDCOMPS;
476477
do
477478
echo Finding tests including component $comp
478-
NUMMATCH=`find mcstas-comps -name \*.instr -exec grep -H ${comp} \{\} \; | cut -f1 -d: | sort | uniq | wc -l`
479+
NUMMATCH=`find src/mcstas-comps -name \*.instr -exec grep -H ${comp} \{\} \; | cut -f1 -d: | sort | uniq | wc -l`
479480
if [ "$NUMMATCH" -gt "0" ];
480481
then
481482
if [ "$RUNNER_OS" != "Windows" ]; then
482-
mctest --mpi=2 --testdir run_${comp} --comp=${comp} --suffix=${{ matrix.CC }}_CHANGES $PERMISSIVE
483+
mctest --mpi=2 --testdir run_${comp} --comp=${comp} --suffix=${{ matrix.CC }}_CHANGES $PERMISSIVE --verbose
483484
else
484-
echo .\\install\\bin\\mctest --verbose --testdir run_${comp} --comp=${comp} --suffix=${{ matrix.CC }}_CHANGES --permissive >> ..\\changedinstr.bat
485+
echo .\\install\\bin\\mctest --verbose --testdir run_${comp} --comp=${comp} --suffix=${{ matrix.CC }}_CHANGES --permissive --verbose >> changedinstr.bat
485486
fi
486487
else
487488
echo No matching tests found
488489
fi
489490
done
490491
fi
492+
cd src
491493
export RUNALL="NO"
492494
export CHANGEDINSTR=`git diff --name-only HEAD HEAD~1| grep \.instr\$ | grep mcstas-comps | xargs -n1 basename | sed s/\.instr//g | xargs echo`
493495
export CHANGEDINSTR=`echo $CHANGEDINSTR | xargs -n1 echo | sort | uniq | xargs echo | sed s/\ /,/g`

.github/workflows/mcstas-conda-basictest.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,24 +224,26 @@ jobs:
224224
cd src
225225
export CHANGEDCOMPS=`git diff --name-only HEAD HEAD~1| grep \.comp\$ | grep mcstas-comps | xargs -n1 basename | sed s/\.comp//g | xargs echo`
226226
export NUMCHANGEDCOMPS=`git diff --name-only HEAD HEAD~1|grep \.comp\$ | grep mcstas-comps | wc -l | xargs echo`
227+
cd -
227228
if [ "$NUMCHANGEDCOMPS" != "0" ];
228229
then
229230
for comp in $CHANGEDCOMPS;
230231
do
231232
echo Finding tests including component $comp
232-
NUMMATCH=`find mcstas-comps -name \*.instr -exec grep -H ${comp} \{\} \; | cut -f1 -d: | sort | uniq | wc -l`
233+
NUMMATCH=`find src/mcstas-comps -name \*.instr -exec grep -H ${comp} \{\} \; | cut -f1 -d: | sort | uniq | wc -l`
233234
if [ "$NUMMATCH" -gt "0" ];
234235
then
235236
if [ "$RUNNER_OS" != "Windows" ]; then
236-
mctest --mpi=2 --testdir run_${comp} --comp=${comp} --suffix=CHANGES $PERMISSIVE
237+
mctest --mpi=2 --testdir run_${comp} --comp=${comp} --suffix=CHANGES $PERMISSIVE --verbose
237238
else
238-
mctest.bat --mpi=2 --testdir run_${comp} --comp=${comp} --suffix=CHANGES $PERMISSIVE
239+
mctest.bat --mpi=2 --testdir run_${comp} --comp=${comp} --suffix=CHANGES $PERMISSIVE --verbose
239240
fi
240241
else
241242
echo No matching tests found
242243
fi
243244
done
244245
fi
246+
cd src
245247
export RUNALL="NO"
246248
export CHANGEDINSTR=`git diff --name-only HEAD HEAD~1| grep \.instr\$ | grep mcstas-comps | xargs -n1 basename | sed s/\.instr//g | xargs echo`
247249
export CHANGEDINSTR=`echo $CHANGEDINSTR | xargs -n1 echo | sort | uniq | xargs echo | sed s/\ /,/g`

.github/workflows/mcxtrace-basictest.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,24 +403,26 @@ jobs:
403403
cd src
404404
export CHANGEDCOMPS=`git diff --name-only HEAD HEAD~1| grep \.comp\$ | grep mcxtrace-comps | xargs -n1 basename | sed s/\.comp//g | xargs echo`
405405
export NUMCHANGEDCOMPS=`git diff --name-only HEAD HEAD~1|grep \.comp\$ | grep mcxtrace-comps | wc -l | xargs echo`
406+
cd -
406407
if [ "$NUMCHANGEDCOMPS" != "0" ];
407408
then
408409
for comp in $CHANGEDCOMPS;
409410
do
410411
echo Finding tests including component $comp
411-
NUMMATCH=`find mcxtrace-comps -name \*.instr -exec grep -H ${comp} \{\} \; | cut -f1 -d: | sort | uniq | wc -l`
412+
NUMMATCH=`find src/mcxtrace-comps -name \*.instr -exec grep -H ${comp} \{\} \; | cut -f1 -d: | sort | uniq | wc -l`
412413
if [ "$NUMMATCH" -gt "0" ];
413414
then
414415
if [ "$RUNNER_OS" != "Windows" ]; then
415-
mxtest --mpi=2 --testdir run_${comp} --comp=${comp} --suffix=${{ matrix.CC }}_CHANGES $PERMISSIVE
416+
mxtest --mpi=2 --testdir run_${comp} --comp=${comp} --suffix=${{ matrix.CC }}_CHANGES $PERMISSIVE --verbose
416417
else
417-
echo .\\install\\bin\\mxtest --verbose --testdir run_${comp} --comp=${comp} --suffix=${{ matrix.CC }}_CHANGES --permissive >> ..\\changedinstr.bat
418+
echo .\\install\\bin\\mxtest --verbose --testdir run_${comp} --comp=${comp} --suffix=${{ matrix.CC }}_CHANGES --permissive --verbose >> changedinstr.bat
418419
fi
419420
else
420421
echo No matching tests found
421422
fi
422423
done
423424
fi
425+
cd src
424426
export RUNALL="NO"
425427
export CHANGEDINSTR=`git diff --name-only HEAD HEAD~1| grep \.instr\$ | grep mcxtrace-comps | xargs -n1 basename | sed s/\.instr//g | xargs echo`
426428
export CHANGEDINSTR=`echo $CHANGEDINSTR | xargs -n1 echo | sort | uniq | xargs echo | sed s/\ /,/g`

.github/workflows/mcxtrace-conda-basictest.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,24 +205,26 @@ jobs:
205205
cd src
206206
export CHANGEDCOMPS=`git diff --name-only HEAD HEAD~1| grep \.comp\$ | grep mcxtrace-comps | xargs -n1 basename | sed s/\.comp//g | xargs echo`
207207
export NUMCHANGEDCOMPS=`git diff --name-only HEAD HEAD~1|grep \.comp\$ | grep mcxtrace-comps | wc -l | xargs echo`
208+
cd -
208209
if [ "$NUMCHANGEDCOMPS" != "0" ];
209210
then
210211
for comp in $CHANGEDCOMPS;
211212
do
212213
echo Finding tests including component $comp
213-
NUMMATCH=`find mcxtrace-comps -name \*.instr -exec grep -H ${comp} \{\} \; | cut -f1 -d: | sort | uniq | wc -l`
214+
NUMMATCH=`find src/mcxtrace-comps -name \*.instr -exec grep -H ${comp} \{\} \; | cut -f1 -d: | sort | uniq | wc -l`
214215
if [ "$NUMMATCH" -gt "0" ];
215216
then
216217
if [ "$RUNNER_OS" != "Windows" ]; then
217-
mxtest --mpi=2 --testdir run_${comp} --comp=${comp} --suffix=CHANGES $PERMISSIVE
218+
mxtest --mpi=2 --testdir run_${comp} --comp=${comp} --suffix=CHANGES $PERMISSIVE --verbose
218219
else
219-
mxtest.bat --mpi=2 --testdir run_${comp} --comp=${comp} --suffix=CHANGES $PERMISSIVE
220+
mxtest.bat --mpi=2 --testdir run_${comp} --comp=${comp} --suffix=CHANGES $PERMISSIVE --verbose
220221
fi
221222
else
222223
echo No matching tests found
223224
fi
224225
done
225226
fi
227+
cd src
226228
export RUNALL="NO"
227229
export CHANGEDINSTR=`git diff --name-only HEAD HEAD~1| grep \.instr\$ | grep mcxtrace-comps | xargs -n1 basename | sed s/\.instr//g | xargs echo`
228230
export CHANGEDINSTR=`echo $CHANGEDINSTR | xargs -n1 echo | sort | uniq | xargs echo | sed s/\ /,/g`

common/lib/share/r-interoff-lib.c

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ int r_off_clip_3D_mod(r_intersection* t, Coords a, Coords b,
336336
pol.npol = faceArray[i]; //nb vertex of polygon
337337
pol.p = popol;
338338
pol.normal= coords_set(0,0,1);
339+
pol.D = 1;
339340
unsigned long indVertP1=faceArray[++i]; //polygon's first vertex index in vtxTable
340341
int j=1;
341342
/*check whether vertex is left or right of plane*/
@@ -758,7 +759,7 @@ long r_off_init( char *offfile, double xwidth, double yheight, double zdepth,
758759
face_W_Array = malloc(polySize*sizeof(double));
759760

760761

761-
if (!normalArray || !faceArray || !DArray) return(0);
762+
if (!normalArray || !faceArray || !DArray || !face_m_Array || !face_alpha_Array || !face_W_Array) return(0);
762763

763764
// fill faces
764765
faceSize=0;
@@ -812,6 +813,10 @@ long r_off_init( char *offfile, double xwidth, double yheight, double zdepth,
812813
{
813814
int nbVertex=faceArray[i];//nb of vertices of this polygon
814815
double *vertices=malloc(3*nbVertex*sizeof(double));
816+
if (!vertices) {
817+
fprintf(stderr,"Error allocating vertex array sized %i\n",nbVertex);
818+
exit(-1);
819+
}
815820
int j;
816821

817822
for (j=0; j<nbVertex; ++j)
@@ -825,6 +830,7 @@ long r_off_init( char *offfile, double xwidth, double yheight, double zdepth,
825830
r_polygon p;
826831
p.p =vertices;
827832
p.npol=nbVertex;
833+
p.D=1;
828834
r_off_normal(&(p.normal),p);
829835

830836
normalArray[indNormal]=p.normal;
@@ -1238,7 +1244,60 @@ int r_off_x_intersect(double *l0,double *l3,
12381244
*******************************************************************************/
12391245
void r_off_display(r_off_struct data)
12401246
{
1241-
#ifndef OPENACC
1247+
if(mcdotrace==2){
1248+
// Estimate size of the JSON string
1249+
const int VERTEX_OVERHEAD = 30;
1250+
const int FACE_OVERHEAD_BASE = 20;
1251+
const int FACE_INDEX_OVERHEAD = 15;
1252+
int estimated_size = 256; // Base size
1253+
estimated_size += data.vtxSize * VERTEX_OVERHEAD;
1254+
1255+
for (int i = 0; i < data.faceSize;) {
1256+
int num_indices = data.faceArray[i];
1257+
estimated_size += FACE_OVERHEAD_BASE + num_indices * FACE_INDEX_OVERHEAD;
1258+
i += num_indices + 1;
1259+
}
1260+
1261+
char *json_string = malloc(estimated_size);
1262+
if (json_string == NULL) {
1263+
fprintf(stderr, "Memory allocation failed.\n");
1264+
return;
1265+
}
1266+
1267+
char *ptr = json_string;
1268+
ptr += sprintf(ptr, "{ \"vertices\": [");
1269+
1270+
for (int i = 0; i < data.vtxSize; i++) {
1271+
ptr += sprintf(ptr, "[%g, %g, %g]", data.vtxArray[i].x, data.vtxArray[i].y, data.vtxArray[i].z);
1272+
if (i < data.vtxSize - 1) {
1273+
ptr += sprintf(ptr, ", ");
1274+
}
1275+
}
1276+
1277+
ptr += sprintf(ptr, "], \"faces\": [");
1278+
1279+
for (int i = 0; i < data.faceSize;) {
1280+
int num = data.faceArray[i];
1281+
ptr += sprintf(ptr, "{ \"face\": [");
1282+
for (int j = 1; j <= num; j++) {
1283+
ptr += sprintf(ptr, "%lu", data.faceArray[i + j]);
1284+
if (j < num) {
1285+
ptr += sprintf(ptr, ", ");
1286+
}
1287+
}
1288+
ptr += sprintf(ptr, "]}");
1289+
i += num + 1;
1290+
if(i<data.faceSize){
1291+
ptr += sprintf(ptr, ", ");
1292+
}
1293+
}
1294+
1295+
ptr += sprintf(ptr, "]}");
1296+
mcdis_polyhedron(json_string);
1297+
1298+
free(json_string);
1299+
}
1300+
else {
12421301
unsigned int i;
12431302
double ratio=(double)(N_VERTEX_DISPLAYED)/(double)data.faceSize;
12441303
unsigned int pixel=0;
@@ -1251,7 +1310,7 @@ void r_off_display(r_off_struct data)
12511310
z0 = data.vtxArray[data.faceArray[i+1]].z;
12521311
double x1=x0,y1=y0,z1=z0;
12531312
double cmx=0,cmy=0,cmz=0;
1254-
1313+
12551314
int drawthis = rand01() < ratio;
12561315
// First pass, calculate center of mass location...
12571316
for (j=1; j<=nbVertex; j++) {
@@ -1262,15 +1321,17 @@ void r_off_display(r_off_struct data)
12621321
cmx /= nbVertex;
12631322
cmy /= nbVertex;
12641323
cmz /= nbVertex;
1265-
1266-
char pixelinfo[1024];
1267-
sprintf(pixelinfo, "%lu,%lu,%lu,%i,%g,%g,%g,%g,%g,%g", data.mantidoffset+pixel, data.mantidoffset, data.mantidoffset+data.polySize-1, nbVertex, cmx, cmy, cmz, x1-cmx, y1-cmy, z1-cmz);
1324+
1325+
char pixelinfo[1024];
1326+
char pixelinfotmp[1024];
1327+
sprintf(pixelinfo, "%li,%li,%li,%i,%g,%g,%g,%g,%g,%g", data.mantidoffset+pixel, data.mantidoffset, data.mantidoffset+data.polySize-1, nbVertex, cmx, cmy, cmz, x1-cmx, y1-cmy, z1-cmz);
12681328
for (j=2; j<=nbVertex; j++) {
12691329
double x2,y2,z2;
12701330
x2 = data.vtxArray[data.faceArray[i+j]].x;
12711331
y2 = data.vtxArray[data.faceArray[i+j]].y;
12721332
z2 = data.vtxArray[data.faceArray[i+j]].z;
1273-
sprintf(pixelinfo, "%s,%g,%g,%g", pixelinfo, x2-cmx, y2-cmy, z2-cmz);
1333+
sprintf(pixelinfotmp, "%s,%g,%g,%g", pixelinfo, x2-cmx, y2-cmy, z2-cmz);
1334+
sprintf(pixelinfo,"%s",pixelinfotmp);
12741335
if (ratio > 1 || drawthis) {
12751336
mcdis_line(x1,y1,z1,x2,y2,z2);
12761337
}
@@ -1285,7 +1346,7 @@ void r_off_display(r_off_struct data)
12851346
}
12861347
i += nbVertex;
12871348
}
1288-
#endif
1349+
}
12891350
} /* r_off_display */
12901351

12911352
/* end of r-interoff-lib.c */

mcstas-comps/contrib/FlatEllipse_finite_mirror.comp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ see
8686
double * get_r_at_z0(int number, double z_0, double r_0, double z_extract, double LStart, double LEnd, double lStart, double lEnd) {
8787
int n = number;
8888
double *r_zExtracts = malloc(n*sizeof(double_t)); /* n is an array of 10 integers */
89-
r_zExtracts[0] = r_0;
89+
if (!r_zExtracts) {
90+
fprintf(stderr,"NMO comp function get_r_at_z0: malloc() failed. Exit! \n");
91+
exit(-1);
92+
}
93+
r_zExtracts[0] = r_0;
9094
//helper variables as in conic_finite_mirror.h and explained in swissneutronics_überlegungen
9195
double k1;
9296
double k2;
@@ -147,6 +151,10 @@ INITIALIZE
147151
//read the data from the file into an array and point rfron_inner to it
148152
nummirror = rsTable.rows;
149153
rfront_inner = malloc(sizeof(double)*nummirror);
154+
if (!rfront_inner) {
155+
fprintf(stderr,"Component %s: malloc() failed in INIT. Exit! \n", NAME_CURRENT_COMP);
156+
exit(-1);
157+
}
150158
for (int i = 0; i < nummirror; i++){
151159

152160
rfront_inner[i] = Table_Index(rsTable, i, 1);//reads the value of the second col where i sits in the first col

mcstas-comps/contrib/ISIS_moderator.comp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,10 @@ int cmdnumberI(char *mc,int* num,const int len)
701701
(mc[i]=='\t' || mc[i]==' ' || mc[i]==',');i++);
702702
if(i==len || !mc[i]) return 0;
703703
ss=malloc(sizeof(char)*(len+1));
704+
if (!ss) {
705+
fprintf(stderr,"ISIS_moderator: malloc() failure in cmdnumberI\n");
706+
exit(-1);
707+
}
704708
/* char *ss=new char[len+1]; */
705709
for(;i<len && mc[i]!='\n' && mc[i]
706710
&& mc[i]!='\t' && mc[i]!=' ' && mc[i]!=',';i++)

mcstas-comps/contrib/Lens.comp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,7 @@ SHARE
130130
* RETURNS: rotated nx,ny,nz coordinates
131131
*/
132132
#pragma acc routine seq
133-
void Lens_roughness(double *nx, double *ny, double *nz, double tilt
134-
#ifdef OPENACC
135-
, _class_particle* _particle
136-
#endif
137-
)
133+
void Lens_roughness(double *nx, double *ny, double *nz, double tilt, _class_particle* _particle)
138134
{
139135
double nt_x, nt_y, nt_z; /* transverse vector */
140136
double n1_x, n1_y, n1_z; /* normal vector (tmp) */
@@ -288,6 +284,7 @@ do {
288284
if (geometry && strlen(geometry) && strcmp(geometry, "NULL") && strcmp(geometry, "0")) {
289285
double t1=0,t0=0;
290286
Coords n, n0, n1;
287+
n=n0=n1=coords_set(0,0,0);
291288
int intersect=off_intersect (&t0, &t1, &n0, &n1, x,y,z, vx,vy,vz, 0, 0, 0, thread_offdata);
292289
if (!intersect) dt=-1;
293290
else if (t0 < 0 && 0 < t1) { dt = t1; n=n1; }
@@ -356,11 +353,7 @@ do {
356353
}
357354
}
358355
/* tilt normal vector for roughness, in cone theta_RMS */
359-
if (RMS>0) Lens_roughness(&nx, &ny, &nz, theta_RMS
360-
#ifdef OPENACC
361-
, _particle
362-
#endif
363-
);
356+
if (RMS>0) Lens_roughness(&nx, &ny, &nz, theta_RMS, _particle);
364357

365358
/* compute incoming angles w.r.t surface */
366359
NORM(nx,ny,nz);
@@ -386,6 +379,7 @@ do {
386379
if (geometry && strlen(geometry) && strcmp(geometry, "NULL") && strcmp(geometry, "0")) {
387380
double t1=0,t0=0;
388381
Coords n, n0, n1;
382+
n=n0=n1=coords_set(0,0,0);
389383
int intersect=off_intersect (&t0, &t1, &n0, &n1, x,y,z, vx,vy,vz, 0, 0, 0, thread_offdata);
390384
if (!intersect) dt=-1;
391385
else if (t0 < 0 && 0 < t1) { dt = t1; n=n1; }
@@ -499,6 +493,7 @@ do {
499493
if (geometry && strlen(geometry) && strcmp(geometry, "NULL") && strcmp(geometry, "0")) {
500494
double t1=0,t0=0;
501495
Coords n, n0, n1;
496+
n=n0=n1=coords_set(0,0,0);
502497
int intersect=off_intersect (&t0, &t1, &n0, &n1, x,y,z, vx,vy,vz, 0, 0, 0, thread_offdata);
503498
if (!intersect) dt=-1;
504499
else if (t0 < 0 && 0 < t1) { dt = t1; n=n1; }
@@ -553,11 +548,7 @@ do {
553548
}
554549
}
555550
/* tilt normal vector for roughness, in cone theta_RMS */
556-
if (RMS>0) Lens_roughness(&nx, &ny, &nz, theta_RMS
557-
#ifdef OPENACC
558-
, _particle
559-
#endif
560-
);
551+
if (RMS>0) Lens_roughness(&nx, &ny, &nz, theta_RMS, _particle);
561552

562553
/* compute incoming angles w.r.t surface */
563554
NORM(nx,ny,nz);

0 commit comments

Comments
 (0)