File tree Expand file tree Collapse file tree 1 file changed +15
-15
lines changed Expand file tree Collapse file tree 1 file changed +15
-15
lines changed Original file line number Diff line number Diff line change @@ -87,30 +87,30 @@ def remove_timeseries(ff):
87
87
return ff
88
88
89
89
90
- def create_outfile ( args ):
90
+ def create_default_outname ( filename , suffix = "_perturbed" ):
91
91
"""
92
- This provides an outline for editing if a new file should be
93
- created
92
+ Create a default output filename by appending a suffix to the input filename.
93
+ If an output filename already exists, a number will be appended to produce a unique output filename.
94
94
95
95
Parameters
96
96
----------
97
- args: ArgumentParser object
98
- The argument parser object with output file name
97
+ filename: str
98
+ The input filename.
99
+ suffix: str, optional
100
+ The suffix to append to the filename.
99
101
100
102
Returns
101
103
----------
102
- output_file - str - This is a string of an output name
104
+ output_filename: str
105
+ The default output filename.
103
106
"""
104
-
105
- #Seperate the string into the extension and the base
106
- basename , ext = os .path .splitext (args .ifile )
107
- output_filename = basename + '_perturbed' + ext
108
-
109
- #Check if that name alreay exists
107
+ output_filename = f"{ filename } { suffix } "
108
+ num = ""
110
109
if os .path .exists (output_filename ):
111
- raise FileExistsError (f"The file '{ output_filename } ' already exists. Cannot save over the file" )
112
- else :
113
- return output_filename
110
+ num = 1
111
+ while os .path .exists (f"{ output_filename } { num } " ):
112
+ num += 1
113
+ return f"{ output_filename } { num } "
114
114
115
115
116
116
def create_perturbation (args , rs , nlon , nlat ):
You can’t perform that action at this time.
0 commit comments