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
2 changes: 1 addition & 1 deletion mcstas-comps/misc/Annulus.comp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ TRACE %{

MCDISPLAY
%{
mcdis_annulus(0,0,0,outer_radius, inner_radius, 0,1,0);
mcdis_annulus (0, 0, 0, outer_radius, inner_radius, 0, 1, 0);
%}

END
2 changes: 1 addition & 1 deletion mcstas-comps/misc/Circle.comp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ TRACE %{

MCDISPLAY
%{
mcdis_new_circle(0,0,0,radius, 0,1,0);
mcdis_new_circle (0, 0, 0, radius, 0, 1, 0);
%}

END
2 changes: 1 addition & 1 deletion mcstas-comps/misc/Cone.comp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ TRACE %{

MCDISPLAY
%{
mcdis_cone(0,0,0,radius,yheight, 0,1,0);
mcdis_cone (0, 0, 0, radius, yheight, 0, 1, 0);
%}

END
2 changes: 1 addition & 1 deletion mcstas-comps/misc/Disc.comp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ TRACE %{

MCDISPLAY
%{
mcdis_disc(0,0,0,radius, nx,ny,nz);
mcdis_disc (0, 0, 0, radius, nx, ny, nz);
%}

END
140 changes: 71 additions & 69 deletions mcstas-comps/misc/File.comp
Original file line number Diff line number Diff line change
Expand Up @@ -36,88 +36,90 @@ SHARE
%}
DECLARE
%{
char * key;
char * name;
char* key;
char* name;
%}
INITIALIZE
%{
// Sort-out the key that we are searching for
if (metadatakey == NULL || metadatakey[0] == '\0'){
key = malloc((strlen(NAME_CURRENT_COMP) + 1) * sizeof(char));
strcpy(key, NAME_CURRENT_COMP);
} else {
key = malloc((strlen(metadatakey) + 1) * sizeof(char));
strcpy(key, metadatakey);
}
int matches = metadata_table_defined(num_metadata, metadata_table, key);
if (matches != 1) {
// 0 would mean _no_ matches; maybe they metadata name without the component was given?
if (matches == 0 && strcmp(key, NAME_CURRENT_COMP)) {
free(key);
key = malloc((strlen(NAME_CURRENT_COMP) + strlen(metadatakey) + 2) * sizeof(char));
sprintf(key, "%s:%s", NAME_CURRENT_COMP, metadatakey);
matches = metadata_table_defined(num_metadata, metadata_table, key);
// Sort-out the key that we are searching for
if (metadatakey == NULL || metadatakey[0] == '\0') {
key = malloc ((strlen (NAME_CURRENT_COMP) + 1) * sizeof (char));
strcpy (key, NAME_CURRENT_COMP);
} else {
key = malloc ((strlen (metadatakey) + 1) * sizeof (char));
strcpy (key, metadatakey);
}
// there's a bug in metadata_table_defined that returns num_metadata if key == NULL
// But since key _isn't_ null, any other result _should_ mean key == A_COMPONENT_NAME
// _and_ that component defines _multiple_ METADATA entries.
else {
printf("%s: There are %d METADATA entries that match %s; please select only one of:\n", NAME_CURRENT_COMP, matches, key);
metadata_table_print_component_keys(num_metadata, metadata_table, key);
exit(1);
int matches = metadata_table_defined (num_metadata, metadata_table, key);
if (matches != 1) {
// 0 would mean _no_ matches; maybe they metadata name without the component was given?
if (matches == 0 && strcmp (key, NAME_CURRENT_COMP)) {
free (key);
key = malloc ((strlen (NAME_CURRENT_COMP) + strlen (metadatakey) + 2) * sizeof (char));
sprintf (key, "%s:%s", NAME_CURRENT_COMP, metadatakey);
matches = metadata_table_defined (num_metadata, metadata_table, key);
}
// there's a bug in metadata_table_defined that returns num_metadata if key == NULL
// But since key _isn't_ null, any other result _should_ mean key == A_COMPONENT_NAME
// _and_ that component defines _multiple_ METADATA entries.
else {
printf ("%s: There are %d METADATA entries that match %s; please select only one of:\n", NAME_CURRENT_COMP, matches, key);
metadata_table_print_component_keys (num_metadata, metadata_table, key);
exit (1);
}
}
if (metadata_table_defined (num_metadata, metadata_table, key) != 1) {
fprintf (stderr, "%s: No unique metadata defined with key %s\n", NAME_CURRENT_COMP, key);
exit (1);
}

char* name_part = metadata_table_key_literal (key);
if (name_part == NULL) {
#if defined(__MCCODE_VERSION__) && __MCCODE_VERSION__ >= 305000L
// We already restrict that only one key matches.
name_part = metadata_table_name (num_metadata, metadata_table, key);
// is key NAME_CURRENT_COMP or something provided by the user? We don't know
// so we _must_ cycle the key allocation to make this work.
char* new_key = malloc ((strlen (key) + strlen (name_part) + 2) * sizeof (char));
sprintf (new_key, "%s:%s", key, name_part);
free (key);
key = new_key;
#else
printf ("Can not update the key automatically prior to McCode v3.5.0, please fix %s usage or upgrade\n", NAME_CURRENT_COMP);
exit (1);
#endif
}
}
if (metadata_table_defined(num_metadata, metadata_table, key) != 1) {
fprintf(stderr, "%s: No unique metadata defined with key %s\n", NAME_CURRENT_COMP, key);
exit(1);
}

char * name_part = metadata_table_key_literal(key);
if (name_part == NULL) {
#if defined(__MCCODE_VERSION__) && __MCCODE_VERSION__ >= 305000L
// We already restrict that only one key matches.
name_part = metadata_table_name(num_metadata, metadata_table, key);
// is key NAME_CURRENT_COMP or something provided by the user? We don't know
// so we _must_ cycle the key allocation to make this work.
char * new_key = malloc((strlen(key) + strlen(name_part) + 2) * sizeof(char));
sprintf(new_key, "%s:%s", key, name_part);
free(key);
key = new_key;
#else
printf("Can not update the key automatically prior to McCode v3.5.0, please fix %s usage or upgrade\n", NAME_CURRENT_COMP);
exit(1);
#endif
}

if (filename == NULL || filename[0] == '\0'){
char * comp_part = metadata_table_key_component(key);
name = malloc((strlen(comp_part) + strlen(name_part) + 2) * sizeof(char));
sprintf(name, "%s_%s", comp_part, name_part);
free(comp_part);
} else{
name = malloc((strlen(filename) + 1) * sizeof(char));
strcpy(name, filename);
}
free(name_part);
if (filename == NULL || filename[0] == '\0') {
char* comp_part = metadata_table_key_component (key);
name = malloc ((strlen (comp_part) + strlen (name_part) + 2) * sizeof (char));
sprintf (name, "%s_%s", comp_part, name_part);
free (comp_part);
} else {
name = malloc ((strlen (filename) + 1) * sizeof (char));
strcpy (name, filename);
}

free (name_part);

// Read the file contents and write them to file now.
FILE * file_ptr = fopen(name, "w");
fprintf(file_ptr, "%s", metadata_table_literal(num_metadata, metadata_table, key));
fclose(file_ptr);
// Read the file contents and write them to file now.
FILE* file_ptr = fopen (name, "w");
fprintf (file_ptr, "%s", metadata_table_literal (num_metadata, metadata_table, key));
fclose (file_ptr);
%}
TRACE
%{
// Do nothing
// Do nothing
%}
FINALLY
%{
// (Optionally) Remove the file now that the runtime is done
if (!keep && !remove(name)) {
fprintf(stderr, "%s: Could not remove file %s\n", NAME_CURRENT_COMP, name);
}
if (key) free(key);
if (name) free(name);
// (Optionally) Remove the file now that the runtime is done
if (!keep && !remove (name)) {
fprintf (stderr, "%s: Could not remove file %s\n", NAME_CURRENT_COMP, name);
}
if (key)
free (key);
if (name)
free (name);
%}
MCDISPLAY
%{
Expand Down
2 changes: 1 addition & 1 deletion mcstas-comps/misc/Legacy_circle.comp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ TRACE

MCDISPLAY
%{
circle("xy",0,0,0,radius);
circle ("xy", 0, 0, 0, radius);
%}

END
Loading