"subscript out of range" error

Anything that doesn't fit elsewhere.
Post Reply
srene
Posts: 14
Joined: Thu Jun 27, 2013 3:46 pm

"subscript out of range" error

Post by srene » Wed Oct 02, 2013 8:08 am

In my hoc file I managed to write a .dat file to save the Information. Everything worked when I runned the hoc-file. After three runs with different frequencies, I runned it again with higher frequency.

Code: Select all

schreibe_dat()          // is the proc to write the dat and worked
The terminal said:

Code: Select all

/Applications/NEURON-7.3/nrn/x86_64/bin/nrniv: subscript out of range x
 in Frequenz_mit_dat_2.hoc near line 512
 hoc_ac_ = 0.05
               ^
        schreibe_dat("50Hz/50Herz_4Peaks_1.dat")
oc>


Can you imagine what has happened. My hoc file has no line 512. The last line is 505.

ted
Site Admin
Posts: 5591
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: "subscript out of range" error

Post by ted » Wed Oct 02, 2013 9:12 pm

srene wrote:Can you imagine what has happened.
No. Provide relevant information and I will tell you what went wrong. The most relevant item is this: reduced to its minimum, exactly what code controls how many times something is written to the output file?

srene
Posts: 14
Joined: Thu Jun 27, 2013 3:46 pm

Re: "subscript out of range" error

Post by srene » Sun Oct 06, 2013 8:15 am

To explain my problem, I think it`s better to post this here.

[Moderator's comment: This thread started as a post to a different thread that addressed a very different topic. It was split off into a new thread for the sake of clarity, which is ill served if each thread is free to wander all over conceptual space. Most moderated forums follow this policy. ]

To write my .dat file I use this code:

Code: Select all

load_file("/Users/renesoylu/Dropbox/... .../find_maximum.hoc")   ///see the next Code-window for this file

//////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// procedure writing mean of spiketimes, number of non stimulated cells and spiketimes in .dat file
///////////////////////////////////////////////////////////
objectvar recv[nZellen], rect, savdata 
strdef file_name
objectvar spiketime[nStimuli], indices[nStimuli]
objectvar summe_fertig, mittelwert_fertig, ssumme_fertig, sigma_fertig






proc schreibe_dat() { local index, summe, mittelwert, sigma, ssumme, si, si_div

file_name = $s1
for i = 0, nZellen-1 {
	recv[i] = new Vector()
}
rect = new Vector()
for j = 0,nStimuli-1 {
	indices[j] = new Vector()
	spiketime[j] = new Vector()
}
summe_fertig = new Vector()
mittelwert_fertig = new Vector()
ssumme_fertig = new Vector()
sigma_fertig = new Vector()
	
// saving values of voltage in vector

for i = 0,nZellen-1{
	recv[i].record(&Zellen[i].soma.v(0.5))
}

rect.record(&t)
run()


//giving the vector "indices" for every spiketime of every spiking neuron
for j = 0, nStimuli-1 {
	start = rect.indwhere(">=", delay + j*T)
	end = rect.indwhere(">=", delay + (j+1)*T)
	
	for i = nStim, nZellen-1 {
		if (recv[i].max(start,end) > Spikeschwelle) {
			index = recv[i].max_ind(start,end)
			indices[j].append(index)
		}
	}
}
for j = 0, nStimuli-1 {
	print indices[j].size()
}
// Vector "spiketime" gets through vector "rect" the real spiketime
for j = 0,nStimuli-1 {
	spiketime[j].index(rect, indices[j])
}

for j = 0, nStimuli-1 {
	summe = 0
	for i = 0, spiketime[j].size()-1 {
		summe = summe + spiketime[j].x[i]
		print spiketime[j].x[i]
	}
	print summe
	summe_fertig.append(summe)
}
for j = 0, nStimuli-1 {
	mittelwert = 0
	if (spiketime[j].size() >0) {
		mittelwert = summe_fertig.x[j]/spiketime[j].size()
	} else {
		mittelwert = 0}
	mittelwert_fertig.append(mittelwert)
	print "mittelwert: ", mittelwert
}


for j = 0, nStimuli-1 {	
	ssumme = 0
	for i = 0,spiketime[j].size()-1 {
		ssumme = ssumme + (spiketime[j].x[i]-mittelwert_fertig.x[j])^2
	}
	ssumme_fertig.append(ssumme)
	print "ssumme: ", ssumme
}

for j = 0, nStimuli-1 {
	if (spiketime[j].size()>1){
		sigma = sqrt(ssumme_fertig.x[j]/(spiketime[j].size()-1))
		print "sigma ", sigma
	} else{
		sigma = 0
		print sigma}
	sigma_fertig.append(sigma)
}

si_div = 0
for i = 0, sigma_fertig.size()-1 {
	if (sigma_fertig.x[i] > 0) {
		si = si + sigma_fertig.x[i]
		si_div = si_div + 1
	}
}



// need a file to write in data

savdata = new File()
savdata.wopen(file_name)

// saving some parameters and different sigmas of every nStimuli

savdata.printf("nZellen: %d  \n", nZellen)
savdata.printf("nStim: %d  \n", nStim)
savdata.printf("Amplitude in nA: %d  \n", amplitude)
savdata.printf("Delay in ms: %d  \n", delay)
savdata.printf("nGaps: %d  \n", nGaps)
savdata.printf("nSynapsen: %d  \n", nSynapsen)
savdata.printf("Duration in ms: %d  \n", duration)
savdata.printf("Threshold in mV: %d  \n", threshold)
savdata.printf("Frequenz in Hz: %d  \n", Frequenz)
savdata.printf("sigma_mittel: %f \n", si/si_div)
savdata.printf("\n")
for j = 0, nStimuli-1 {
	savdata.printf("sigma%d: %f \n", j+1, sigma_fertig.x[j])
	//savdata.printf("\n")
	savdata.printf("%d Spikes \n", spiketime[j].size())
	savdata.printf("\n")
	savdata.printf("mittelwert%d: %f \n",j+1, mittelwert_fertig.x[j])
	savdata.printf("\n")
	
}
for j = 0, nStimuli-1 {
	for i = 0,spiketime.size()-1 {
		savdata.printf("%f \n",spiketime[j].x[i])
		}
}
savdata.close()

}


Synapsen()
Synapsen()
access Zellen[0].soma


tstop =110


cvode_active(1)  // beschleunigt Simulationen
setnGaps(2000)
set_gaps()
set_gaps()
print "simuliert..."


schreibe_dat("30Hz/50Herz_4Peaks_3.dat")


print "fertig"
and this is find_maximum.hoc which is loaded:

Code: Select all

load_file("nrngui.hoc")



objectvar VEKTOR, t_v_max

/////////////////////////////////////////////////////////////////
// Spiketime
//////////////////////////////////////////////////////////////////
func spike_time() { local dt, index, Spike_time

// function which needs input: VEKTOR *.record(&section,timeintervall) 
// and timeintervall dt
// return: Spike time (maximum of voltage, must be greater than zero
// if maximum <= 0, then return: 0


	VEKTOR = new Vector()
	VEKTOR = $o1
	dt = $2
	index = VEKTOR.max_ind()
	Spike_time = index*dt
	if (VEKTOR.x[index]>0) {
		return Spike_time
	} else {
		return 0
	}
}
///////////////////////////////////////////////////////////////////////


objectvar versuch

////////////////////////////////////////////////////////////////
// Mittelwert
//////////////////////////////////////////////////////////////////////7
func mittelwert() { local i, summe, mittelwert, zellzahl

// pram: number of cells, spiketimes of spikes t_v_max
// return: mean of spiketimes regardless cells which didn´t spike

	versuch = new Vector()
	t_v_max = new Vector()
	versuch = $o1
	zellzahl = versuch.size()
	summe = 0
	for i= 0, versuch.size()-1 {
		t_v_max.append(versuch.x[i])
	}
	for i = 0, versuch.size()-1 {
		if (t_v_max.x[i]>0) {
			summe = summe+t_v_max.x[i]
		} else {
			zellzahl = zellzahl -1
		}
	}
	if (zellzahl ==0) {
		return 0
	} else {
  		mittelwert = summe/zellzahl
		return mittelwert
	}
}
//////////////////////////////////////////////////////////////////

objectvar t_max, t_diff

/////////////////////////////////////////////////////////////////
// delta T
///////////////////////////////////////////////////////////////////
proc deltaT() { local i, summe, mittelwert, zellzahl
	t_max = new Vector()
	t_diff = new Vector()
	
	zellzahl = $1
	summe = 0
	for i = 2, $1+1 {
		t_max.append($i)
	}
	for i = 0, $1-1 {
		if(t_max.x[i]>0) {
			summe = summe+t_max.x[i]
			t_diff.append(t_max.x[i])
		} else {
			zellzahl = zellzahl-1
		}
	}
	mittelwert = summe/zellzahl
	
	for i = 0, zellzahl-1 {
		t_diff.x[i]=t_diff.x[i]-mittelwert
	}
}

and what I get in the terminal (Mac OS X Lion) is this:

Code: Select all

Last login: Sun Oct  6 12:39:44 on console
Rene-Soylus-MacBook:~ renesoylu$ cd ; clear; cp .nrn_as2sh /tmp/nrn_as2sh$$; sh /tmp/nrn_as2sh$$;rm -f /tmp/nrn_as2sh$$ ; exit
-e 
NEURON -- Release 7.3 (849:5be3d097b917) 5be3d097b917
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2013
See http://www.neuron.yale.edu/neuron/credits

loading membrane mechanisms from /Users/renesoylu/Dropbox/Synchronie_der_Muskelste#178BBB/Refractory network/Projekt Boris/Ihw_Ted/ihalfwave_test/Test/x86_64/.libs/libnrnmech.so
Additional mechanisms from files
 ihw.mod kalium.mod
	1 
	1 
	0 
	1 
	1 
	1 
	1 
simuliert...
80 
1 
80 
0 
22.977275 
23.033143 
23.176806 
23.122933 
23.14089 
23.087017 
23.158848 
23.033143 
23.122933 
23.015186 
23.069059 
22.937368 
23.14089 
23.087017 
23.069059 
23.087017 
23.087017 
23.015186 
23.051101 
22.997228 
23.122933 
22.957322 
23.015186 
23.051101 
23.087017 
23.069059 
23.122933 
23.104975 
22.997228 
23.033143 
23.069059 
23.087017 
23.051101 
23.176806 
22.977275 
23.212722 
23.069059 
23.033143 
23.051101 
23.051101 
23.122933 
23.087017 
23.015186 
23.087017 
23.104975 
23.104975 
23.104975 
22.977275 
23.158848 
23.051101 
22.997228 
23.122933 
23.015186 
23.104975 
22.977275 
23.122933 
23.069059 
23.015186 
23.104975 
23.033143 
23.14089 
23.015186 
23.069059 
23.087017 
22.897462 
23.122933 
23.158848 
23.158848 
23.051101 
23.033143 
23.194764 
23.104975 
23.033143 
23.033143 
23.033143 
23.015186 
23.069059 
23.14089 
23.015186 
22.977275 
1845.4768 
46.029531 
46.029531 
64.714752 
64.786449 
64.947768 
64.876071 
64.911919 
64.840222 
64.911919 
64.768525 
64.893995 
64.750601 
64.804374 
64.660979 
64.893995 
64.840222 
64.822298 
64.822298 
64.822298 
64.750601 
64.786449 
64.714752 
64.911919 
64.911919 
64.750601 
64.804374 
64.840222 
64.840222 
64.893995 
64.858147 
64.732677 
64.786449 
64.822298 
64.840222 
64.786449 
64.929844 
64.714752 
64.983616 
64.804374 
64.768525 
64.786449 
64.804374 
64.876071 
64.858147 
64.750601 
64.840222 
64.858147 
64.876071 
64.858147 
64.696828 
64.911919 
64.804374 
64.750601 
64.858147 
64.750601 
64.876071 
64.696828 
64.876071 
64.822298 
64.750601 
64.858147 
64.768525 
64.893995 
64.750601 
64.822298 
64.840222 
64.601232 
64.876071 
64.929844 
64.929844 
64.804374 
64.768525 
64.983616 
64.858147 
64.786449 
64.786449 
64.768525 
64.750601 
64.822298 
64.911919 
64.750601 
64.714752 
5185.5807 
0 
mittelwert: 23.06846 
mittelwert: 46.029531 
mittelwert: 64.819759 
mittelwert: 0 
ssumme: 0.30453095 
ssumme: 0 
ssumme: 0.43678142 
ssumme: 0 
sigma 0.062087214 
0 
sigma 0.07435643 
0 
/Applications/NEURON-7.3/nrn/x86_64/bin/nrniv: subscript out of range x
 in Frequenz_mit_dat_2.hoc near line 511
 hoc_ac_ = 0.05
               ^
        schreibe_dat("30Hz/50Herz_4Peaks_3.dat")
oc>
If everything goes good terminal prints "fertig" at the end and I don´t get an empty .dat file

ted
Site Admin
Posts: 5591
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: "subscript out of range" error

Post by ted » Sun Oct 06, 2013 9:25 pm

The task is to discover where the problem arises. Presumably this is in proc schreibe_dat(). Suggest embedding some "milestone print statements." For example, this loop

Code: Select all

for j = 0, nStimuli-1 {
   if (spiketime[j].size()>1){
      sigma = sqrt(ssumme_fertig.x[j]/(spiketime[j].size()-1))
      print "sigma ", sigma
   } else{
      sigma = 0
      print sigma}
   sigma_fertig.append(sigma)
}
would become

Code: Select all

print "***** entering sigma loop *****"
for j = 0, nStimuli-1 {
   if (spiketime[j].size()>1){
      sigma = sqrt(ssumme_fertig.x[j]/(spiketime[j].size()-1))
   } else{
      sigma = 0
   }
   sigma_fertig.append(sigma)
print "j ", j, " sigma ", sigma
}
print "***** done with sigma loop *****"
It's suprising that you're not using NetCons to detect and automatically capture spike times to Vectors.

Post Reply