if ix >= 0:
                    print (prog)
#                    try:
#                        procpool[prog]
#                    except:
#                        progfiles[prog]={'ifiles'}
                    #print r.params[prog]
                    #params = r.params[prog]
                    #print 'R',params

                    #r.params.update(p.params['main'])
                    for ifile in filelst:
                        progfiles[prog]
                        params['ifile'] = ifile
                        r.params[prog]['ifile'] = ifile
                        r.genOutputFilename(prog)
                        ofile = r.params[prog]['ofile']
                        print (ifile, ofile)
                        stat = processParFile(phash=r,params=params, processor=prog, sensor=sensor,verbose=verbose)
                        filelst.remove(ifile)
                        filelst.append(ofile)
                        print ('O',stat)

            except Exception:
                pass
            if stat > 0:
                sys.exit(1)
    else:
        print (parser.print_help())
        sys.exit(1)
def processParFile(parfile=None, params=None, processor=None, sensor=None,
    getanc=False,phash=None,verbose=False):
    """Execute processing for a given parameter file"""

    if phash is None:
        phash = ParamProcessing(params=params, parfile=parfile)
    if parfile:
        phash.parseParFile()
    pkeys = phash.params.keys()
    phash.genOutputFilename(processor)

    if processor is None:
        try:
            processor = phash.params['main']['ocproc']
        except  Exception:
            try:
                pkeys.remove('main')
                if len(pkeys) == 1:
                    processor = pkeys[0]
                else:
                    print ("Error! More than 1 processor found.... ")
#                    sys.exit(1)
                    status = 1
            except Exception:
                print ("Error! Need to know what process to run.... Exiting")
#                sys.exit(1)
                status = 1


    if sensor is None:
        try:
            sensor = phash.params['main']['ocproc_sensor']
        except Exception:
            pass
#    Check for getanc requirement...
    try:
        getanc = int(phash.params['main']['ocproc_getanc'])
    except Exception:
        pass

    try:
        runproc = proc_cmd[processor][sensor]
    except Exception:
        runproc = processor

    try:
        nonparcode = nonpar.index(runproc)
    except Exception:
        nonparcode = -1

    # Run getanc if necessary...
    if processor in ('l2gen') and getanc:
        if verbose:
            print ("Retrieving ancillary files...")
        fcmd = ''.join(['--file=', phash.params[processor]['ifile']])
        anccmd = ['/Users/Shared/seadas7/trunk/python/getanc.py', fcmd]
        ancstat = subprocess.call(anccmd)
        if ancstat not in (1, 99):
            ancparfile = phash.params[processor]['ifile'] + '.anc'
            phash.parseParFile(ancparfile)
        else:
            print ("Ancillary file retreival failed. Exiting...")
            status = 1
#            sys.exit(1)

    print (phash.params[processor])
    # Set up process command
    if nonparcode >= 0:
        w = ProcWrap(phash.params[processor])
        w.procSelect(runproc)
        cmd = w.procmd
    else:
        parfilename = phash.params[processor]['ifile'] + '.par'
        phash.parfile = parfilename
        phash.buildParameterFile(processor)
        cmd = ['/Users/Shared/OCSSW/run/bin/' + runproc, 'par=' + parfilename]

    print (cmd)
    print ('V',verbose)
    if verbose:
#        print p.parstr
        rstr = ' '.join(cmd)
        print ("Running:\n  ", rstr)
        print (phash.params[processor])
    # Create output and error log files
    try:
        ix = cmd.index('>')
        outFile = cmd[ix+1]
        cmd.remove('>')
        cmd.remove(outFile)
    except Exception:
        outlog = phash.params[processor]['ifile'] + '.log'
        outFile = os.path.join(os.curdir, outlog)

    print (outlog)
    errlog = phash.params[processor]['ifile'] + '.err'
    errFile = os.path.join(os.curdir,errlog)
    outptr = open(outFile, 'w')
    errptr = open(errFile, 'w')

    # Call the subprocess using convenience method
    status = subprocess.call(cmd, 0, None, None, outptr, errptr)
    print ('S', status)
    # Close log handles
    outptr.close()
    errptr.close()


    statptr = open(errFile, 'r')
    statData = statptr.read()
    statptr.close()
    # Check the process exit code
    if not status == 0:
        print ('Error (%s) executing command:\n' % status)
        print ('\t', ' '. join(cmd))
        print ('\n' + statData)
        sys.exit(1)
    else:
        if verbose:
            print (statData)
            print ('Processing successful.')

    return status #phash.params[processor]['ofile']