# Last edited on 2021-01-06 10:33:13 by jstolfi

SHELL := /bin/bash

# Simulator:
PROGDIR := ${HOME}/programs/c/NEUROMAT/nmsim_elem_net_simulate
PROG := nmsim_elem_net_simulate

# Creator:
GEN_PROGDIR := ${HOME}/programs/c/NEUROMAT/nmsim_elem_net_create_test
GEN_PROG := nmsim_elem_net_create_test

all: compile delete create simulate plot

NNE := 100
NNE1 := ${shell echo "${NNE}-1" | bc -lq}

# Tags of this run and of a comparison run.
TAG=A
CMP=A

# Range of input currents for full-scale test:
SUBTAG := FU
INP_MIN := -35.0
INP_MAX := +35.0

# Trace/plot time ranges 
TTOT := 10000
TRACE_TMIN := 1800
TRACE_TMAX := 9800
PLOT_TMIN := 7875
PLOT_TMAX := 8075

# Times for the ON and OFF pulses:
TIME_ON_0  := 7900
TIME_OFF_0 := 7950
TIME_ON_1  := 8000
TIME_OFF_1 := 8050

# Range of activity to plot:
RHO_MAX := 1.000

TAGSUB := ${TAG}_${SUBTAG}
CMPSUB := ${CMP}_${SUBTAG}
ifneq "/${TAG}" "/${CMP}"
  TAGSUBS := ${CMPSUB} ${TAGSUB}
else
  TAGSUBS := ${TAGSUB}
endif

include ${TAG}.make

NMSIM_FILE := data_nmsim_${TAG}.txt
GEN_PREFIX := out/sim
OUT_PREFIX := ${GEN_PREFIX}_${TAGSUB}

INPUT_OPTS := ${shell make_input_options.sh \
    ${NNE} ${TTOT} ${INP_MIN} ${INP_MAX} \
    ${TIME_ON_0} ${TIME_OFF_0} ${TIME_ON_1} ${TIME_OFF_1} \
  }

TRACE_OPTS := ${shell make_trace_options.sh ${NNE} ${TRACE_TMIN} ${TRACE_TMAX}}
          
compile:
	cd ${PROGDIR} && make all
	cd ${GEN_PROGDIR} && make all

delete:
	rm -fv ${NMSIM_FILE}

create: ${NMSIM_FILE} 

${NMSIM_FILE}: compile 
	${GEN_PROG} \
            -netType FEEDBACK \
	    -netSize ${NNE} \
	    -phiType ${PHI} \
            -V_tau ${V_tau} \
            -M_R ${M_R} \
            -M_tau ${M_tau} \
            -W ${W} \
          > ${NMSIM_FILE}

simulate: compile ${NMSIM_FILE}
	-mkdir -p out
	-rm -f out/*.{txt,png}
	time ${PROG} \
          -netFile ${NMSIM_FILE} \
          -timeStep 1.0 \
          -nSteps ${TTOT} \
          ${INPUT_OPTS} \
          ${TRACE_OPTS} \
          -outPrefix ${OUT_PREFIX}

plot:
	plot_traces.sh 1 0 ${NNE} \
          ${OUT_PREFIX} \
          ${PLOT_TMIN} ${PLOT_TMAX} \
          ${INP_MIN} ${INP_MAX} \
          ${RHO_MAX}