def download(url, toDirectory="/tmp"):
    
    # setup HTTP handler
    certFile = expanduser(ESGF_CREDENTIALS)
    opener = urllib2.build_opener(HTTPSClientAuthHandler(certFile,certFile))
    opener.add_handler(urllib2.HTTPCookieProcessor())
    
    # download file
    localFilePath = join(toDirectory,url.split('/')[-1])
    print "\nDownloading url: %s to local path: %s ..." % (url, localFilePath)
    localFile=open( localFilePath, 'w')
    webFile=opener.open(url)
    localFile.write(webFile.read())
    
    # cleanup
    localFile.close()
    webFile.close()
    opener.close()
    print "... done"
Returns an index offset from datetimes d1 and d2. d1 is expected to be the
dataset/ETHPy150Open apache/climate/ocw/esgf/download.py/download--crossover with--dataset/ETHPy150Open statsmodels/statsmodels/statsmodels/tsa/base/datetools.py/_idx_from_dates