コード例 #1
0
ファイル: __init__.py プロジェクト: matthu7777/pythonmodules
def lmolly(command, data, cdata):
    """
    Loads data from a molly file

    Interactive usage:

    lmolly mol slots fslot

    Arguments:

    mol     -- name of molly file
    slots   -- range of slots as in '1-10', or just a single slot '9' to load data into.
    fslot   -- first slot to read in file, starting from 1
    """

    import trm.dnl.molly as molly

    # generate arguments
    inpt = inp.Input(DINT_ENV, DINT_DEF, inp.clist(command))

    # register parameters
    inpt.register('mol',    inp.Input.LOCAL, inp.Input.PROMPT)
    inpt.register('slots',  inp.Input.LOCAL, inp.Input.PROMPT)
    inpt.register('fslot',  inp.Input.LOCAL, inp.Input.PROMPT)

    # get inputs
    mol  = inpt.get_value('mol',  'molly file name', subs.Fname('example', '.mol'))

    slots  = inpt.get_value('slots', 'slots to load data into', '1-1000')
    slist  = interp_slots(slots, False, data)
    fslot  = inpt.get_value('fslot', 'first slot to read from file', 1, 1, 1000000)

    # load molly data
    try:
        mf = open(mol, 'rb')
        nload = 0

        # junk the first fslot-1
        for i in range(fslot-1):
            print('skipping a molly spectrum')
            molly.skip_molly(mf)

        # save the rest
        for slot in slist:
            mspec = molly.rmspec(mf)
            if mspec:
                data[slot] = mspec
                nload += 1
                if not cdata.mute:
                    print('Loaded ponto data into slot',slot)
            else:
                raise EOFError
        mf.close()
    except EOFError:
        print('End-of-file reached.')
        mf.close()

    # loading no slots is flagged as an error
    if nload == 0:
        raise DintError('load: no slots were loaded')
    elif not cdata.mute:
        print(nload,'slots were loaded.')
コード例 #2
0
ファイル: gmolly.py プロジェクト: trmrsh/trm-dnl
    mout = open(mfile, 'wb')

nwrote = 0
for mfin in unique:
    slts = slots[mfiles == mfin]
    smax = slts.max()
    try:
        minp  = open(mfin,'rb')
        nspec = 1
        while nspec <= smax:
            if nspec in slts:
                mspec = molly.rmspec(minp)
                mspec['Filename'] = mfin[-36:-4]
                mspec.wmolly(mout, hasarc=True)
            else:
                if not molly.skip_molly(minp):
                    print 'Unexpected error while trying to skip spectrum',nspec,'of file,',mfin
                    break
            nspec += 1
        minp.close()
        print 'Read',len(slts),'spectra from',mfin
        nwrote += len(slts)
    except:
        print 'Error reading file',mfin
mout.close()

print 'Read/wrote',nwrote,'spectra to',mfile
print 'Failed to read',len(slots)-nwrote,'spectra.'