def main_worker(haloi,ffo, stardata,snapshot,min_snap):
    hpath = "/bigbang/data/AnnaGroup/caterpillar/halos/middle_mass_halos/H1387186/H1387186_EB_Z127_P7_LN7_LX14_O4_NV4/"
    z_current = htils.get_z_snap(hpath,snapshot)[0]
    #print "Current redshift",z_current
#---# case empty
    if ffo['key'] == 0 :

        if snapshot != min_snap:
        # LW to be computed here
        # Way it is done now is to lookback one snapshot, then find galaxies with stars in them, track them to rhe start
        # and make arrays of star mass and ages for that 'one' position at the last snapshot. Thus you create an SED
        # accordingly and then compute ht ekde/kdi/Jlw

            gal_mass, gal_age, pos_gal  = makelw.lwgal(snapshot, stardata)
            kde , kdi , jlw = lwlib.sedcompute(gal_mass,gal_age,pos_gal)

            jlw_global = lwlib.lwglobal(z_current)
            # Global J is computed as a fit

            total_lw = jlw + jlw_global

            #step2: Pop III or no Pop III
            make_PopIII = popiii.checkpopiii_lw(mvir, total_lw)

            #step3: pass final output
            if make_PopIII == 'yes':
                smass_iii = popiii.makepopiii(niii)
                mstar = smass_iii
                # NEED TO PRINT THIS TO A FILE: GLOBALSTARCAT

                print "MADE IT"
                key_update = 3

#---# case DCBH
    elif ffo['key'] == 1 :

        #do nothing here
        ffo['bh_switch'] = 1

#---# case Pop II stars already exist
    # here is where the prog_info comes in handy

    elif ffo['key'] == 2 :
        popii.makepopii(haloi['snapshot'],haloi['mvir'],haloi['vmax'],haloi['rvir'],ffo['mvir_prog'],ffo['coldgas'],ffo['hotgas'],ffo['blowout'],ffo['mstar'])
        # NEED TO PRINT THIS TO A FILE: GLOBALSTARCAT
        ffo['key'] = 2
#---# case Pop III formed here at some point , make Pop II now
    elif ffo['key'] == 3 :
        popiii.makepopiii(haloi['snapshot'],haloi['mvir'],haloi['vmax'],haloi['rvir'],ffo['mvir_prog'],ffo['coldgas'],ffo['hotgas'],ffo['blowout'],ffo['mstar'])
        # NEED TO PRINT THIS TO A FILE: GLOBALSTARCAT
        ffo['key'] = 2

    if ffo['key'] != 1:
        ffo['bh_switch'] = 0

    #return the output fields
    return ffo['key'], ffo['bh_switch'], ffo['coldgas'], ffo['hotgas'], ffo['blowout'], ffo['mstar']
def main_worker_ini(haloi,ffo, stardata,min_snap):

    total_lw = 0.
    make_PopIII = popiii.checkpopiii_lw(haloi['mvir'], total_lw)

    #step3: pass final output
    if make_PopIII == 'yes':
        smass_iii = popiii.makepopiii(niii)
        stardata['mstar'].append(smass_iii)

    # NEED TO PRINT THIS TO A FILE: GLOBALSTARCAT
        print "MADE IT"
        haloi['key'] = 3