def ridiculous_fname_fcn(w, j, enc_name, dec_fit, task=None):
    if task =='co':
        check_none = True
        j_orig = j
    else:
        check_none = False
    done = 0
    
    if task is None:
        pass
    else:
        j = j+'_'+task+'_'

    while not done:
        s_ = main_sim_gen.wts_2_str(w)
        w2 = w.copy()
        w2[1] += 0.01
        w2[3] += 0.01
        s2_ = main_sim_gen.wts_2_str(w2)
        
        search_str = j+s_
        search_str2 = j+s2_

        dir_ = save_path

        hdf_fnames = glob.glob(dir_+'*'+search_str+'*'+'.hdf')
        print 'search string1: ',dir_+'*'+search_str+'*'+'.hdf'

        if len(hdf_fnames) == 0:
            mod_search_str2 = j + s_[:4]
            hdf_fnames = glob.glob(dir_+'*'+search_str2+'*'+'.hdf')
            print 'search string2: ', search_str2

        if len(hdf_fnames)==0:
            mod_search_str = j + s_[:4]
            hdf_fnames = glob.glob(dir_+'*'+mod_search_str+'*'+'.hdf')
            print 'old_search: ', search_str, ' new search: ', mod_search_str
        else:
            print 'success: ', search_str, hdf_fnames

        if len(hdf_fnames) > 1:
            mod_mod_search_str = j + s_[:5]
            hdf_fnames = glob.glob(dir_+'*'+mod_mod_search_str+'*'+'.hdf')

        if len(hdf_fnames) > 1:

            #Take newest file: 
            import datetime
            s0 = hdf_fnames[0]
            ix = s0.find('enc') + 3
            s0_d = s0[ix:]
            d0 = datetime.datetime(2000+int(s0_d[4:6]), int(s0_d[:2]), int(s0_d[2:4]), int(s0_d[7:9]), int(s0_d[9:11]))

            s1 = hdf_fnames[1]
            ix = s1.find('enc') + 3
            s1_d = s1[ix:]
            d1 = datetime.datetime(2000+int(s1_d[4:6]), int(s1_d[:2]), int(s1_d[2:4]), int(s1_d[7:9]), int(s1_d[9:11]))

            ix_ = np.argmax([d0, d1])
            hdf_fnames = [hdf_fnames[ix_]]
            print 'date method: ', hdf_fnames
        
        if len(hdf_fnames) != 1:
            error = 1
            hdf_fnames = [0]
        else:
            error = 0

        if np.logical_and(error, check_none):
            j = j_orig
            check_none = 0
        else:
            done = 1


    return hdf_fnames[0], error
def less_ridiculous_fname_fcn(wts, inp, enc_name, dec_fit, task=None):
    wt_str = main_sim_gen.wts_2_str(wts)
    encoder_index=enc_name[-5]
    search_str = save_path+'*'+inp+task+'_'+wt_str+'_'+'encoder_'+encoder_index+'_'+dec_fit+'*'+'.hdf'
    hdf_fnames = glob.glob(search_str)
    return hdf_fnames[0], 0