Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions common/lib/share/mccode-r.c
Original file line number Diff line number Diff line change
Expand Up @@ -4149,9 +4149,8 @@ mcstatic void norm_func(double *x, double *y, double *z) {
#ifdef FUNNEL
long sort_absorb_last(_class_particle* particles, _class_particle* pbuffer, long len, long buffer_len, long flag_split, long* multiplier) {
#define SAL_THREADS 1024 // num parallel sections
if (len<SAL_THREADS) return sort_absorb_last_serial(particles, len);

if (multiplier != NULL) *multiplier = -1; // set default out value for multiplier
if (len<SAL_THREADS) return sort_absorb_last_serial(particles, len);
long newlen = 0;
long los[SAL_THREADS]; // target array startidxs
long lens[SAL_THREADS]; // target array sublens
Expand Down Expand Up @@ -4219,8 +4218,8 @@ long sort_absorb_last(_class_particle* particles, _class_particle* pbuffer, long
}
//for (int ii=0;ii<accumlen;ii++) printf("%ld ", (psorted[ii]->_absorbed));

// return (no SPLIT)
if (flag_split != 1)
// return (no SPLIT, or nothing left to split)
if (flag_split != 1 || accumlen == 0)
return accumlen;

// SPLIT - repeat the non-absorbed block N-1 times, where len % accumlen = N + R
Expand Down
25 changes: 24 additions & 1 deletion common/lib/share/read_table-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,29 @@ MCDETECTOR Table_Write(t_Table Table, char *file, char *xl, char *yl,
#define MyNL_ARGMAX 50
#endif

static int Table_ParseHeader_wordchar(char c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
}

/* Find symbol in header as a whole word (like regex \b...\b), not case
sensitive. Word boundaries are only required where the symbol itself starts
or ends with a word character, so "sigma_a " or "e_min=" match as given.
E.g. "Vc" must not match inside a file name such as /tmp/tmp.0.aVcX9q,
which cif2hkl writes into the header before the real "Vc" line. */
static char *Table_ParseHeader_find(char *header, char *symbol) {
size_t len = strlen(symbol);
char *pos = header;
while ((pos = (char*)strcasestr(pos, symbol))) {
int start_ok = !Table_ParseHeader_wordchar(symbol[0])
|| pos == header || !Table_ParseHeader_wordchar(pos[-1]);
int end_ok = !Table_ParseHeader_wordchar(symbol[len-1])
|| !Table_ParseHeader_wordchar(pos[len]);
if (start_ok && end_ok) return pos;
pos++;
}
return NULL;
}

char **Table_ParseHeader_backend(char *header, ...){
va_list ap;
char exit_flag=0;
Expand Down Expand Up @@ -1350,7 +1373,7 @@ char **Table_ParseHeader_backend(char *header, ...){
exit_flag = 1; break;
}
/* search for the symbol in the header */
pos = (char*)strcasestr(header, arg_char);
pos = Table_ParseHeader_find(header, arg_char);
if (pos) {
char *eol_pos;
eol_pos = strchr(pos+strlen(arg_char), '\n');
Expand Down
3 changes: 3 additions & 0 deletions mcstas-comps/optics/Pol_guide_vmirror.comp
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,19 @@ INITIALIZE
}

n_index = sizeof (rPar) / sizeof (rPar[0]);
if (n_index > 6) n_index = 6; // r..ParToFunc holds at most 6 values
for (i_index = 0; i_index < n_index; i_index++) {
rParToFunc[i_index] = rPar[i_index];
}

n_index = sizeof (rUpPar) / sizeof (rUpPar[0]);
if (n_index > 6) n_index = 6; // r..ParToFunc holds at most 6 values
for (i_index = 0; i_index < n_index; i_index++) {
rUpParToFunc[i_index] = rUpPar[i_index];
}

n_index = sizeof (rDownPar) / sizeof (rDownPar[0]);
if (n_index > 6) n_index = 6; // r..ParToFunc holds at most 6 values
for (i_index = 0; i_index < n_index; i_index++) {
rDownParToFunc[i_index] = rDownPar[i_index];
}
Expand Down
2 changes: 1 addition & 1 deletion mcstas-comps/samples/Isotropic_Sqw.comp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ SHARE
printf ("Isotropic_sqw: Converting %ld %s from %s into S(q,w) data\n", size, flag_qSq ? "S(q)" : "powder lines", sqwTable.filename);
});
/* allocate line_data array */
list = (struct line_data*)malloc (size * sizeof (struct line_data));
list = (struct line_data*)calloc (size, sizeof (struct line_data)); // zeroed: the multiplicity check may look one entry ahead

for (i = 0; i < size; i++) {
double j = 0, d = 0, w = 0, DWfactor = 0, F2 = 0, Sq = -1, q = 0;
Expand Down
2 changes: 1 addition & 1 deletion mcstas-comps/samples/PowderN.comp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ SHARE
info->compname););
}
/* allocate line_data array */
list = (struct line_data*)malloc (size * sizeof (struct line_data));
list = (struct line_data*)calloc (size, sizeof (struct line_data)); // zeroed: the multiplicity check may look one entry ahead
if (!list) {
exit (fprintf (stderr, "PowderN: %s: Error: Could not allocate line array\n", info->compname));
}
Expand Down
2 changes: 1 addition & 1 deletion mcstas-comps/union/Powder_process.comp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ SHARE
"WARNING: but F2 unit is set to barns=0 (fm^2). Intensity might be 100 times too low.\n",
info->compname););
/* allocate line_data array */
list = (struct line_data_union*)malloc (size * sizeof (struct line_data_union));
list = (struct line_data_union*)calloc (size, sizeof (struct line_data_union)); // zeroed: the multiplicity check may look one entry ahead
if (!list)
exit (fprintf (stderr, "Powder_process: ERROR allocating memory (read_line_data_union)\n"));

Expand Down
2 changes: 1 addition & 1 deletion mcxtrace-comps/samples/Isotropic_Sqw.comp
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ SHARE
printf ("Isotropic_Sqw: Converting %ld %s from %s into S(q,w) data\n", size, flag_qSq ? "S(q)" : "powder lines", sqwTable.filename);
});
/* allocate line_data array */
list = (struct line_data*)malloc (size * sizeof (struct line_data));
list = (struct line_data*)calloc (size, sizeof (struct line_data)); // zeroed: the multiplicity check may look one entry ahead

for (i = 0; i < size; i++) {
double j = 0, d = 0, w = 0, DWfactor = 0, F2 = 0, Sq = -1, q = 0;
Expand Down
2 changes: 1 addition & 1 deletion mcxtrace-comps/samples/PowderN.comp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ SHARE
info->compname););
}
/* allocate line_data array */
list = (struct line_data*)malloc (size * sizeof (struct line_data));
list = (struct line_data*)calloc (size, sizeof (struct line_data)); // zeroed: the multiplicity check may look one entry ahead

for (i = 0; i < size; i++) {
/* printf("Reading in line %i\n",i);*/
Expand Down
12 changes: 6 additions & 6 deletions mcxtrace-comps/share/reflectivity-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ int reflec_Init_File(t_Reflec *R, char *filename){
} else {
stracpy(R->rc.matrl,header_parsed[0],255);
R->rc.T = table;
R->rc.d = strtod(header_parsed[4], NULL);
R->rc.d = header_parsed[4] ? strtod(header_parsed[4], NULL) : 0; /* d is optional */
R->rc.rho=strtod(header_parsed[3],NULL);
R->rc.Z=strtod(header_parsed[1],NULL);
R->rc.At=strtod(header_parsed[2],NULL);
Expand Down Expand Up @@ -221,16 +221,16 @@ int reflec_Init_File(t_Reflec *R, char *filename){
case KINEMATIC:
{
char **header_parsed = Table_ParseHeader(table->header, "#N=", "#gamma=", "#lambda=", "#rho_ab=", NULL);
if (! (header_parsed[0] && header_parsed[1] && header_parsed[2] && header_parsed[3] && header_parsed[4])){
if (! (header_parsed[0] && header_parsed[1] && header_parsed[2] && header_parsed[3])){
fprintf(stderr,"Error: %s: Could not parse file \"%s\".\n",
REFLIBNAME,filename);
exit(-1);
}

R->rk.N = strtol(header_parsed[0], NULL, 10);
R->rk.Gamma = strtod(header_parsed[2], NULL);
R->rk.Lambda = strtod(header_parsed[3], NULL);
R->rk.rho_AB = strtod(header_parsed[4], NULL);
R->rk.Gamma = strtod(header_parsed[1], NULL);
R->rk.Lambda = strtod(header_parsed[2], NULL);
R->rk.rho_AB = strtod(header_parsed[3], NULL);
break;
}

Expand Down Expand Up @@ -291,7 +291,7 @@ enum reflec_Type get_table_reflec_type(t_Table *t){
if(!type){
/*type of reflectivity file is not specified - try to guess instead*/
header_parsed = Table_ParseHeader(t->header,"Z",NULL);
long Z = strtol(header_parsed[0],NULL,0);
long Z = header_parsed[0] ? strtol(header_parsed[0],NULL,0) : 0;
if(Z >0 && Z<116){
/*this appears to be a coating file similar to Pt.txt and Be.txt (in the mcxtrace data library*/
printf("INFO: %s: Datafile type not explicit in reflectivity file %s.\n"
Expand Down
Loading