Changeset 424

Show
Ignore:
Timestamp:
07/18/08 14:28:56 (3 months ago)
Author:
apdavison
Message:

Now when you try to write data to a file, any existing file of the same name is first renamed by appending '_old' to the filename (see #104 and #106). (Applies to nest2 and neuron2 modules).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/nest2/__init__.py

    r423 r424  
    160160    def write(self, file=None, gather=False, compatible_output=True): 
    161161        user_file = file or self.file 
    162         if isinstance(user_file, basestring) and num_processes() > 1: 
    163             user_file += '.%d' % rank() 
     162        if isinstance(user_file, basestring): 
     163            if num_processes() > 1: 
     164                user_file += '.%d' % rank() 
     165            recording.rename_existing(user_file) 
    164166        nest_filename = _merge_files(self._device, gather) 
    165167        if compatible_output: 
     
    181183            else: 
    182184                raise Exception('Must provide a filename or an open file') 
    183         if gather == True and num_processes() > 1: 
     185        if gather == True and rank() == 0 and num_processes() > 1: 
    184186            root_file = file or self.filename 
     187            recording.rename_existing(root_file) 
    185188            for node in xrange(num_processes()): 
    186                 if rank()==0: 
    187                     node_file = root_file + '.%d' % node  
    188                     if os.path.exists(node_file): 
    189                         system_line = 'cat %s >> %s' % (node_file, root_file) 
    190                         os.system(system_line) 
    191                         system_line = 'rm %s' % node_file 
    192                         os.system(system_line) 
     189                node_file = root_file + '.%d' % node  
     190                if os.path.exists(node_file): 
     191                    os.system('cat %s >> %s' % (node_file, root_file)) 
     192                    os.system('rm %s' % node_file) 
    193193        # don't want to remove nest_filename at this point in case the user wants to access the data 
    194194        # a second time (e.g. with both getSpikes() and printSpikes()), but we should 
  • trunk/src/neuron2/simulator.py

    r403 r424  
    9191        data = self.get(gather) 
    9292        filename = file or self.filename 
     93        recording.rename_existing(filename) 
    9394        numpy.savetxt(filename, data, Recorder.numpy1_0_formats[self.variable], delimiter='\t') 
    9495        if compatible_output: 
    95             recording.write_compatible_output(filename, filename, Recorder.formats[self.variable], 
     96            recording.write_compatible_output(filename, filename, self.variable, Recorder.formats[self.variable], 
    9697                                              self.population, state.dt) 
    9798         
  • trunk/src/recording.py

    r423 r424  
    4242#        pass 
    4343 
     44def rename_existing(filename): 
     45    if os.path.exists(filename): 
     46        os.system('mv %s %s_old' % (filename, filename)) 
     47        logging.warning("File %s already exists. Renaming the original file to %s_old" % (filename, filename)) 
     48 
    4449def convert_compatible_output(data, population, variable): 
    4550    """