def generate_links(detected_times, archiveLocation, fileNamePrefix, year, dataFileLocation, has_zdb):
    """
    Generate a archive links for a layer based on the last provided time period
    Arguments:
        detected_times -- the list of available time periods
        archiveLocation -- the location of the archive data
        fileNamePrefix -- the prefix of the MRF files
        year -- whether or not the layer uses a year-based directory structure
        dataFileLocation -- file location for the default data file
        has_zdb -- whether or not the layer contains a zdb file
    """
    
    # Find the latest file in the archive
    if len(detected_times[-1].split("/")) == 3:
        period = "/" + detected_times[-1].split("/")[2]
    else:
        period = ""
    last_time = detect_time(detected_times[-1].split("/")[0]+"/DETECT"+period, archiveLocation, fileNamePrefix, year, has_zdb)[-1].split("/")[1]
    
    if 'T' in last_time: # sub-daily files
        t = datetime.strptime(last_time,"%Y-%m-%dT%H:%M:%SZ")
        if has_zdb:
            filename = fileNamePrefix + datetime.strftime(t,"%Y%j") + "_"
        else:
            filename = fileNamePrefix + datetime.strftime(t,"%Y%j%H%M%S") + "_"
        last_year = datetime.strftime(t,"%Y")
    else:
        t = datetime.strptime(last_time,"%Y-%m-%d")
        filename = fileNamePrefix + datetime.strftime(t,"%Y%j") + "_"
        last_year = datetime.strftime(t,"%Y")
    
    link_pre, data_ext = os.path.splitext(dataFileLocation)
    link_dir = os.path.dirname(link_pre)
    
    mrf = archiveLocation + ("",str(last_year)+"/")[year] + filename + ".mrf"
    idx = archiveLocation + ("",str(last_year)+"/")[year] + filename + ".idx"
    data = archiveLocation + ("",str(last_year)+"/")[year] + filename + data_ext
    zdb = archiveLocation + ("",str(last_year)+"/")[year] + filename + ".zdb"
    
    mrf_link = link_pre + ".mrf"
    idx_link = link_pre + ".idx"
    data_link = link_pre + data_ext
    zdb_link = link_pre + ".zdb"
    
    # make sure link directory exists
    if not os.path.exists(link_dir):
        os.makedirs(link_dir)
        print "Created directory " + link_dir   
    
    if os.path.isfile(mrf):
        if os.path.lexists(mrf_link):
            os.remove(mrf_link)
            print "Removed existing file " + mrf_link
        os.symlink(mrf, mrf_link)
        print "Created soft link " + mrf_link + " -> " + mrf
    if os.path.isfile(idx):
        if os.path.lexists(idx_link):
            os.remove(idx_link)
            print "Removed existing file " + idx_link
        os.symlink(idx, idx_link)
        print "Created soft link " + idx_link + " -> " + idx
    else:
        log_sig_warn("Default MRF index file " + idx + " does not exist", sigevent_url)
    if os.path.isfile(data):
        if os.path.lexists(data_link):
            os.remove(data_link)
            print "Removed existing file " + data_link
        os.symlink(data, data_link)
        print "Created soft link " + data_link + " -> " + data
    else:
        log_sig_warn("Default MRF data file " + data + " does not exist", sigevent_url)
    if os.path.isfile(zdb):
        if os.path.lexists(zdb_link):
            os.remove(zdb_link)
            print "Removed existing file " + zdb_link
        os.symlink(zdb, zdb_link)
        print "Created soft link " + zdb_link + " -> " + zdb
    
    return mrf_link, idx_link, data_link, zdb_link
    
#-------------------------------------------------------------------------------
dataset/ETHPy150Open nasa-gibs/onearth/src/layer_config/bin/oe_configure_layer.py/generate_links/original