Page 1 of 1
Initializing seed with the system time
Posted: Thu Nov 03, 2005 12:05 pm
by miller
Hi!
I would like to initialize the seed of the Random class with the system time. Because I don't know how to do this from hoc code, I wrote a NMODL POINT_PROCESS
Code: Select all
NEURON {
POINT_PROCESS c_functions
}
VERBATIM
#include <time.h>
ENDVERBATIM
FUNCTION GetSystemTime(){
VERBATIM
return time(NULL);
ENDVERBATIM
}
I successully compile it in WinXP with mknrndll.hoc. But when I then call GetSystemTime() from the hoc code I get the error message
Undefined symbol _time referenced from nrnmech.dll.
Anyone knows what should I do?
Posted: Thu Nov 03, 2005 12:35 pm
by Raj
Although only half answer it might hint at another solution direction, under XP with cygwin installed alongside it is possible to do the following:
Code: Select all
strdef datetime
objref szFunctionsObject
szFunctionsObject = new StringFunctions()
system("date +%Y%m%d%H%M%S",datetime)
szFunctionsObject.left(datetime,14) //The date function might produce a newline (it does with cygwin)
This gives you back the system datetime as a string. With sscanf you should be able to convert that to number. The date man page give several other forms including seconds from a time somewhere in 1970 so you can pick what is most convenient.
You can actually inspect the relevant man pages from within neuron, just type system("man date") from the command line and see what happens.
Posted: Thu Nov 10, 2005 7:29 am
by miller
Thanks! It works perfectly! That's exactly what I needed!
Konstantin
Posted: Tue Jul 03, 2007 2:32 pm
by tsa
I have been trying to use sscanf for this same task to convert the system date/time string to a number for seeding but I've been unsuccessful due to my ignorance of the formats used for sscanf.
Every format I've tried listed in the programmers references returns an error of incorrect argument type. Could anyone give a quick sscanf lesson?
Posted: Tue Jul 03, 2007 2:58 pm
by abogaard
Code: Select all
szFunctionsObject.left(strSeed,14)
is an important step before using sscanf, because I think there's a line break in the string generated by default. Then you can use
Technically its a floating point number, but nowhere in your string assignment do you have a decimal point, so you'll get an integer.
Posted: Thu Jul 05, 2007 12:21 pm
by tsa
What is the file type of "intSeed". I'm getting errors that it is not a double pointer but if i declare intSeed as a double NEURON gets stuck in a segmentation violation error loop. Thanks,
Posted: Fri Jul 06, 2007 3:30 am
by Raj
Tsa,
Can you provide us with the shortest possible bit of code that shows your problem. What your wrote sofar gives me the impression that your are overlooking something simple quite unrelated to the details of sscanf.
Regards,
Raj
Posted: Fri Jul 06, 2007 9:06 am
by tsa
You were right Raj, I was putting my variable for strSeed in quotes within sscanf cause the errors. Thanks for your input