@@ -528,6 +528,27 @@ def load_package_info(args):
528528 return args
529529
530530
531+ def _check_saved_file_exists (args ):
532+ """Check if the output files already exist based on the input paths
533+ and output directory."""
534+ existing_files = []
535+ for path in args .input_paths :
536+ outfile = args .output_directory / (f"{ path .stem } -mud-corrected.chi" )
537+ if outfile .exists () and not args .force :
538+ existing_files .append (outfile )
539+ if args .output_correction :
540+ corrfile = args .output_directory / (f"{ path .stem } -cve.chi" )
541+ if corrfile .exists () and not args .force :
542+ existing_files .append (corrfile )
543+ if existing_files :
544+ existing_files_str = "\n " .join (str (f ) for f in existing_files )
545+ raise FileExistsError (
546+ "The following output files already exist:"
547+ f"\n { existing_files_str } \n "
548+ "Use --force to overwrite them."
549+ )
550+
551+
531552def preprocessing_args (args ):
532553 """Perform preprocessing on the provided args. The process includes
533554 loading package and user information, setting input, output,
@@ -542,6 +563,11 @@ def preprocessing_args(args):
542563 -------
543564 args : argparse.Namespace
544565 The updated argparse Namespace with arguments preprocessed.
566+
567+ Raises
568+ ------
569+ FileExistsError
570+ If the output files already exist and --force is not used.
545571 """
546572 args = load_wavelength_from_config_file (args )
547573 args = set_mud (args )
@@ -552,6 +578,7 @@ def preprocessing_args(args):
552578 args = load_user_metadata (args )
553579 args = load_user_info (args )
554580 args = load_package_info (args )
581+ _check_saved_file_exists (args )
555582 return args
556583
557584
0 commit comments