source: sasview/src/sas/sascalc/file_converter/red2d_writer.py @ eb98f24

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since eb98f24 was 0b1a677, checked in by lewis, 8 years ago

Only perform writing on separate thread

Also move reader/writer classes to sascalc

  • Property mode set to 100644
File size: 1.0 KB
Line 
1import os
2import time
3from sas.sascalc.dataloader.readers.red2d_reader import Reader as Red2DReader
4
5class Red2DWriter(Red2DReader):
6
7    def write(self, filename, data, thread):
8        """
9        Write to .dat
10
11        :param filename: file name to write
12        :param data: data2D
13        """
14        # Write the file
15        fd = open(filename, 'w')
16        t = time.localtime()
17        time_str = time.strftime("%H:%M on %b %d %y", t)
18
19        header_str = "Data columns are Qx - Qy - I(Qx,Qy)\n\nASCII data"
20        header_str += " created at %s \n\n" % time_str
21        # simple 2D header
22        fd.write(header_str)
23        # write qx qy I values
24        for i in range(len(data.data)):
25            if thread.isquit():
26                fd.close()
27                os.remove(filename)
28                return False
29
30            fd.write("%g  %g  %g\n" % (data.qx_data[i],
31                                        data.qy_data[i],
32                                       data.data[i]))
33
34        fd.close()
35
36        return True
Note: See TracBrowser for help on using the repository browser.