Skip to content

Display error when no output plot files are generated#42

Merged
lelaus merged 4 commits into
masterfrom
040_no_output
Jun 19, 2025
Merged

Display error when no output plot files are generated#42
lelaus merged 4 commits into
masterfrom
040_no_output

Conversation

@dmanzione

Copy link
Copy Markdown
Collaborator

So far, if any problem in the generation of the output plot files happened, no error message was shown to the user if the output folder already had plot files with the same names.
This could happen either when configuring the plot from the GUI or when loading an invalid .inp file.
The issue has been addressed by checking the last modification time of the output files: now, if no change in the last modification time occurs, an exception is raised and a pop-up message is displayed.

So far, if any problem in the generation of the output plot files happened, no error message was shown to the user if the output folder already had plot files with the same names. This has been addressed by checking the last modification time of the output files: if any change in the last modification time occurs, it means the files have been generated, otherwise an exception is raised and a pop-up message is shown.
So far, if any problems arise when loading an invalid .inp file, the error message was not shown. Now, should any exception occurs, it is caught in the 'display_inp_plots' method and a pop-up message is displayed.
@dmanzione dmanzione linked an issue Mar 21, 2025 that may be closed by this pull request
Comment thread tugui/support.py Outdated

Returns
-------
The file last modification time, if exists; None otherwise.

@lelaus lelaus Jun 10, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity, I'd suggest using this explanatory sentence:
"The last modification time of the file, if it exists; None otherwise."

Comment thread tugui/tu_interface.py Outdated
# Check if the files has been created after running the plot executable:
# if the time has not changed, it means that either the .dat or the .plt
# files have not been generated, hence an exception is raised.
if (modif_time0 == get_file_modification_time(datGen.dat_paths[i]) or

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, check how the function "os.path.getmtime()" works. In case multiple .dat files are generated as specified in the same .inp file, they have slightly different "getmtime()" times. If, in a subsequent .dat file generation, something goes wrong with any .dat files that is not the first one, this if statement cannot identify the issue. I'd suggest trying to check whether changing the logical operator from "==" to ">" would work appropriately.

@dmanzione dmanzione Jun 11, 2025

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the tuplot executable always overwrites any already present output file, I decided to simplify the treatment by applying the following logic:

  1. since the path names of the files that tuplot will generate are known, the files are removed if found in the output folder just before running the executable;
  2. after running the tuplot executable, the existence of these files is checked; an exception is raised if any .dat/.plt file is missing.

A specific function remove_if_file_exists has been added to the support.py module for the purpose of removing the already present files. In particular, given the path name, it tries to remove the file; if not present, the OSError exception is caught, but not re-raised as it does not imply an issue for its purpose. The exception will only be re-raised if the error type is different from the one indicating a missing file.

Comment thread tugui/tu_interface.py Outdated
"for plotting. One or both the requested .dat/.plt files have "
"not been produced.")

# Build the paths of the generated plot files from the user-specified

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The remaining portion of this for loop seems useless in case the output folder coincides with the folder of the .inp file. If so, I'd suggest avoiding to apply the remaining portion of this for loop and continue directly to the next for loop iteration. This should remove the overhead.

@lelaus lelaus merged commit 336df60 into master Jun 19, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong plot shown

2 participants