# Path: swhlab/core.py
# def abfIDfromFname(fname):
# def abfProtocol(fname):
# def headerHTML(header,fname):
#     def __init__(self, fname, createFolder=False):
#     def setsweep(self, sweep=0, channel=0):
#     def sweepList(self):
#     def setsweeps(self):
#     def comments_load(self):
#     def generate_protocol(self):
#     def get_protocol(self,sweep):
#     def get_protocol_sequence(self,sweep):
#     def clamp_values(self,timePoint=0):
#     def epochTimes(self,nEpoch=2):
#     def average(self,t1=0,t2=None,setsweep=False):
#     def averageSweep(self,sweepFirst=0,sweepLast=None):
#     def kernel_gaussian(self, sizeMS, sigmaMS=None, forwardOnly=False):
#     def sweepYfiltered(self):
#     def sweepYsmartbase(self):
#     def phasicNet(self,biggestEvent=50,m1=.5,m2=None):
#     def output_touch(self):
#     def output_clean(self):
#     def inspect(self):
# class ABF:
#             Y = proto[step]['fEpochInitLevel']+proto[step]['fEpochLevelInc']*self.sweep
#         I1,I2=int(t1*self.pointsPerSec),int(t2*self.pointsPerSec)
#         Y=self.sweepYsmartbase()[int(m1):int(m2)]
# 
# Path: swhlab/indexing/indexing.py
# class INDEX:
#     def __init__(self,ABFfolder):
#     def scan(self):
#     def convertImages(self):
#     def analyzeAll(self):
#     def analyzeABF(self,ID):
#     def htmlFor(self,fname):
#     def html_single_basic(self,abfID,launch=False,overwrite=False):
#     def html_single_plot(self,abfID,launch=False,overwrite=False):
#     def html_index(self,launch=True):
# def doStuff(ABFfolder,analyze=False,convert=False,index=True,overwrite=True,
#             launch=True):
# def analyzeSingle(abfFname):
#             ID="UNKNOWN"
#                 ID=fname[:8]
#             ID="UNKNOWN"
#                 ID=fname[:8]
#     IN=INDEX(ABFfolder)
#     IN=INDEX(ABFfolder)


import os
import sys
import glob
import pylab
import numpy as np
import traceback
import swhlab
from swhlab.core import common as cm #shorthand
from swhlab.indexing.indexing import genIndex
        print(traceback.format_exc())
        print("~"*50,"CRASHED","~"*50)
    return abf.ID

def autoFolder(folder,startAt=None,limit=None,matching=None):
    fnames=glob.glob(folder+"/*.abf")
    analyzed=[]
    if startAt:
        if type(startAt) == str:
            for i in range(len(fnames)):
                if startAt in fnames[i]:
                    startAt=i
                    break
        fnames=fnames[int(startAt):]
    if limit:
        fnames=fnames[:int(limit)]
    if matching:
        fnames2=[]
        for fname in fnames:
            if matching in fname:
                fnames2.append(fname)
        fnames=fnames2
    for i in range(len(fnames)):
        print("\n### analyzing %d of %d ###"%(i+1,len(fnames)))
        analyzed.append(autoABF(fnames[i]))
    return analyzed

if __name__=="__main__":
    folder=r'C:\Users\swharden\Desktop\2016-07-11 PIR TR IHC'
    analyzed=autoFolder(folder,matching="16711054")

# Path: swhlab/core.py
# def abfIDfromFname(fname):
# def abfProtocol(fname):
# def headerHTML(header,fname):
#     def __init__(self, fname, createFolder=False):
#     def setsweep(self, sweep=0, channel=0):
#     def sweepList(self):
#     def setsweeps(self):
#     def comments_load(self):
#     def generate_protocol(self):
#     def get_protocol(self,sweep):
#     def get_protocol_sequence(self,sweep):
#     def clamp_values(self,timePoint=0):
#     def epochTimes(self,nEpoch=2):
#     def average(self,t1=0,t2=None,setsweep=False):
#     def averageSweep(self,sweepFirst=0,sweepLast=None):
#     def kernel_gaussian(self, sizeMS, sigmaMS=None, forwardOnly=False):
#     def sweepYfiltered(self):
#     def sweepYsmartbase(self):
#     def phasicNet(self,biggestEvent=50,m1=.5,m2=None):
#     def output_touch(self):
#     def output_clean(self):
#     def inspect(self):
# class ABF:
#             Y = proto[step]['fEpochInitLevel']+proto[step]['fEpochLevelInc']*self.sweep
#         I1,I2=int(t1*self.pointsPerSec),int(t2*self.pointsPerSec)
#         Y=self.sweepYsmartbase()[int(m1):int(m2)]
# 
# Path: swhlab/indexing/indexing.py
# class INDEX:
#     def __init__(self,ABFfolder):
#     def scan(self):
#     def convertImages(self):
#     def analyzeAll(self):
#     def analyzeABF(self,ID):
#     def htmlFor(self,fname):
#     def html_single_basic(self,abfID,launch=False,overwrite=False):
#     def html_single_plot(self,abfID,launch=False,overwrite=False):
#     def html_index(self,launch=True):
# def doStuff(ABFfolder,analyze=False,convert=False,index=True,overwrite=True,
#             launch=True):
# def analyzeSingle(abfFname):
#             ID="UNKNOWN"
#                 ID=fname[:8]
#             ID="UNKNOWN"
#                 ID=fname[:8]
#     IN=INDEX(ABFfolder)
#     IN=INDEX(ABFfolder)


# Path: doc/oldcode/indexing/standard.py
import os
import sys
import glob
import pylab
import numpy as np
import traceback
import swhlab
from swhlab.core import common as cm #shorthand
from swhlab.indexing.indexing import genIndex

        print(traceback.format_exc())
        print("~"*50,"CRASHED","~"*50)
    return abf.ID

def autoFolder(folder,startAt=None,limit=None,matching=None):
    fnames=glob.glob(folder+"/*.abf")
    analyzed=[]
    if startAt:
        if type(startAt) == str:
            for i in range(len(fnames)):
                if startAt in fnames[i]:
                    startAt=i
                    break
        fnames=fnames[int(startAt):]
    if limit:
        fnames=fnames[:int(limit)]
    if matching:
        fnames2=[]
        for fname in fnames:
            if matching in fname:
                fnames2.append(fname)
        fnames=fnames2
    for i in range(len(fnames)):
        print("\n### analyzing %d of %d ###"%(i+1,len(fnames)))
        analyzed.append(autoABF(fnames[i]))
    return analyzed

if __name__=="__main__":
    folder=r'C:\Users\swharden\Desktop\2016-07-11 PIR TR IHC'
    analyzed=autoFolder(folder,matching="16711054")

    genIndex(folder)