// UI
objref vBoxFrequencySimulations
// IClampSin on soma
objref stimFreq

// Sets IClampSin params on the soma.
// $1 - Delay
// $2 - Duration
// $3 - Frequency
// $4 - Amplitude
// $5 - Phase
proc simulateFrequency()  {
    soma {
        stimFreq = new IClampSin(0.5)
        stimFreq.del = $1       // ms
        stimFreq.dur = $2       // ms
        stimFreq.freq = $3      // Hz
        stimFreq.amp = $4       // nA
        stimFreq.phase = $5     // rad
    }
}

// Sets soma params and starts the simulation.
proc runFrequency() {
    simulateFrequency(stimdel, stimdur, stimfreqency, stimamp, stimphase)
    run()

    // Remove IClampSin after simulation
    objref stimFreq
}

// Inits UI and simulation parameters.
proc initParamsFrequency() {
    stimdel = 100000            // ms
    stimdur = 0                 // ms
    stimfreqency = 0.00000001   // Hz
    stimamp = 0                 // nA
    stimphase = 1               // rad
}

// Shows Frequency Electrical Simulation window.
proc showFrequencyUi() { // Voltage Sin  Clamp of Soma, set of parameters  
    vBoxFrequencySimulations = new VBox()
    vBoxFrequencySimulations.intercept(1)
    {
        xpanel("")
        xlabel("Sinusoidal current parameters ")
        xvalue("Delay of current (ms)","stimdel", 1,"", 0, 1)
        xvalue("Duration of current (ms)","stimdur", 1,"", 0, 1)
        xvalue("Amplitude of current (nA)","stimamp", 1,"", 0, 1)
        xvalue("Frequency of Sinusoid (Hz)","stimfreqency", 1,"", 0, 1)
        xlabel("---------------------------------------------------------------------------------------------------------")
        xvalue("Simulation time","tstop", 1,"", 0, 1  )
        xbutton("Run simulation", "runFrequency()")
        xpanel()
    }
    vBoxFrequencySimulations.intercept(0)
    vBoxFrequencySimulations.map("Frequency Stimulation into soma")
}

// Opens Frequency Electrical Simulation window.
proc FrequencyStimulations() {
    initParamsFrequency()
    showFrequencyUi()
}