omuse icon indicating copy to clipboard operation
omuse copied to clipboard

DALES interface workdir and output redirection

Open fjansson opened this issue 5 years ago • 1 comments

It is currently not possible to redirect stdout, stderr to files in the model working directory. If workdir doesn't exist when creating the Dales object and a file in workdir is used for redirection the code fails, because the directory doesn't exist when the output files are created.

The DALES interface behaves differently depending on whether workdir exists. If not, it assumes a fresh start and copies files from inputdir. If it exists, it assumes a restart and doesn't copy files. This means the user code cannot create the working directory in advance.

Proposed fix: in the DALES interface.py, move the directory logic before call to model creation, add mkdirs in between:

class Dales(CommonCode, CodeWithNamelistParameters):
...
def __init__(self, **options):                                                                                                                                                            
        inputdir = None                                                                                                                                                                       
                                                                                                                                                                                              
        # Set working directory                                                                                                                                                               
        self.workdir = "."                                                                                                                                                                    
        if "workdir" in options:                                                                                                                                                              
            self.workdir = options["workdir"]                                                                                                                                                 
            if os.path.exists(self.workdir):  # This is a restart                                                                                                                             
                inputdir = self.workdir                                                                                                                                                       
            else:                                                                                                                                                                             
                os.makedirs(self.workdir)                                                                                                                                                     
                # create work directory so that output files can be placed there                                                                                                              
                                                                                                                                                                                              
        CodeWithNamelistParameters.__init__(self, namelist_parameters)                                                                                                                        
        CommonCode.__init__(self, DalesInterface(**options), **options)                                                                                                                       
        self.stopping_conditions = StoppingConditions(self)                                     

fjansson avatar Dec 10 '20 12:12 fjansson

sorry for getting to this late - I think this solution is ok (is there anything against it?)

ipelupessy avatar May 04 '21 08:05 ipelupessy