@@ -0,0 +1,2352 @@
+# -*- coding: utf-8 -*-%0A#%0A#   Copyright (C) 2018 European Synchrotron Radiation Facility, Grenoble, France%0A#%0A#   Principal author:   Wout De Nolf (wout.de_nolf@esrf.eu)%0A#%0A# Permission is hereby granted, free of charge, to any person obtaining a copy%0A# of this software and associated documentation files (the %22Software%22), to deal%0A# in the Software without restriction, including without limitation the rights%0A# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell%0A# copies of the Software, and to permit persons to whom the Software is%0A# furnished to do so, subject to the following conditions:%0A#%0A# The above copyright notice and this permission notice shall be included in%0A# all copies or substantial portions of the Software.%0A#%0A# THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0A# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,%0A# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE%0A# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER%0A# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,%0A# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN%0A# THE SOFTWARE.%0A%0Aimport time%0A%0Adef array2SpecMca(data):%0A    %22%22%22 Write a python array into a Spec array.%0A        Return the string containing the Spec array%0A    %22%22%22%0A    tmpstr = %22@A %22%0A    length = len(data)%0A    for idx in range(0, length, 16):%0A        if idx+15 %3C length:%0A            for i in range(0, 16):%0A                tmpstr += %22%25.8g %22 %25 data%5Bidx+i%5D%0A            if idx+16 != length:%0A                tmpstr += %22%5C%5C%22%0A        else:%0A            for i in range(idx, length):%0A                tmpstr += %22%25.8g %22 %25 data%5Bi%5D%0A        tmpstr += %22%5Cn%22%0A    return tmpstr%0A    %0Adef save(mca,filename,mode=%22w%22,zero=0,gain=1):%0A    with open(filename, mode) as ffile:%0A        ffile.write(%22#F %25s%5Cn%22 %25 filename)%0A        ffile.write(%22#D %25s%5Cn%22 %25 (time.ctime(time.time())))%0A        ffile.write(%22%5Cn%22)%0A        ffile.write(%22#S 1 %25s%5Cn%22 %25 %22spectrocrunch%22)%0A        ffile.write(%22#D %25s%5Cn%22 %25 (time.ctime(time.time())))%0A        ffile.write(%22#@MCA %2516C%5Cn%22)%0A        ffile.write(%22#@CHANN %25d %25d %25d 1%5Cn%22 %25 (len(mca), 0, len(mca)-1))%0A        ffile.write(%22#@CALIB %25.7g %25.7g %25.7g%5Cn%22 %25 (zero,gain,0))%0A        ffile.write(array2SpecMca(mca))%0A        ffile.write(%22%5Cn%22)%0A        %0A        %0A

Write MCA spectra.