1 #include <../../nmodlconf.h> 33 #if !defined(NRN_DYNAMIC_UNITS) 34 #define NRN_DYNAMIC_UNITS 0 38 #include "../mswin/extra/d2upath.cpp" 47 extern double fabs(
double);
49 extern void diag(
char*,
char*);
50 #define IFUNITS {if (!UnitsOn) return;} 51 #define OUTTOLERANCE(arg1,arg2) (fabs(arg2/arg1 - 1.) > 1.e-5) 65 #if defined(NEURON_DATA_DIR) 66 static char *
dfile = NEURON_DATA_DIR
"/lib/nrnunits.lib" SUFFIX;
68 static char *
dfile =
"/usr/lib/units";
71 #if defined(__TURBOC__) || defined(__GO32__) 88 int pu(
int,
int,
int);
108 #if NRN_DYNAMIC_UNITS 109 static struct dynam {
151 if (c ==
'\r') { c =
'\n';}
156 }
else if (
pc && *
pc) {
163 #define UNIT_STK_SIZE 20 169 static char buf[256];
170 GetModuleFileName(
NULL, buf, 256);
171 for (i=strlen(buf); i >= 0 && buf[
i] !=
'\\'; --
i) {;}
174 for (i=strlen(buf); i >= 0 && buf[
i] !=
'\\'; --
i) {;}
185 return getenv(
"NEURONHOME");
195 static char buf[256];
199 {
int seee=0;
for (
ucp=buf; *
ucp;
ucp++) {
200 if (*
ucp ==
'e') seee=1;
204 for(i=0; i<
NDIM; i++)
205 f |=
pu(p->
dim[i], i, f);
209 for(i=0; i<
NDIM; i++)
210 f |=
pu(-p->
dim[i], i, f);
239 for (i=0; i<
NDIM; i++) {
265 for (i=0; i<
NDIM; i++) {
277 for (i=0; i<
NDIM; i++) {
333 printf(
"Redefinition of units (%s) to:", s1);
335 printf(
" is ignored.\nThey remain:");
337 diag(
"Units redefinition", (
char *)0);
341 for (i=0; i<
NDIM; i++) {
348 #if NRN_DYNAMIC_UNITS 349 table = dynam[legacy].table;
350 names = dynam[legacy].names;
355 #if NRN_DYNAMIC_UNITS 357 for (i = 0; i < 2; ++
i) {
386 for (i=0; i<
NDIM; i++) {
402 for (i=0; i<
NDIM; i++) {
417 for (i=0; i<
NDIM; i++) {
421 for (i=1; i<
val; i++) {
434 if (up->
dim[0] == 9 ||
usp->
dim[0] == 9) {
437 for (i=0; i<
NDIM; i++) {
469 for (i=0; i <
NDIM; i++) {
476 for (i=0; i<
NDIM; i++) {
485 diag(
"The units of the previous two expressions are not conformable",(
char*)
"\n");
490 fprintf(stderr,
"The previous primary expression with units: %s\n\ 491 is missing a conversion factor and should read:\n (%g)*(",
494 diag(
")\n", (
char *)0);
511 if (up->
dim[0] == 9 ||
usp->
dim[0] == 9) {
520 for (i=0; i <
NDIM; i++) {
526 for (i=0; i<
NDIM; i++) {
541 diag(
"underflow or overflow in units calculation", (
char *)0);
551 if (
usp->
dim[0] == 9) {
return;}
552 for (i=0; i<
NDIM; i++) {
555 diag(
"The previous expression is not dimensionless", (
char *)0);
566 fprintf(stderr,
"The previous expression needs the conversion factor (%g)\n",
582 static int units_alloc_called = 0;
583 if (!units_alloc_called) {
584 units_alloc_called = 1;
585 #if NRN_DYNAMIC_UNITS 586 for (i=0; i < 2; ++
i) {
589 dynam[
i].names = (
char*)calloc(
NTAB*10,
sizeof(
char));
596 names = (
char*)calloc(
NTAB*10,
sizeof(
char));
602 #if MODL||NMODL||HMODL||SIMSYS 611 #if NRN_DYNAMIC_UNITS 612 for (i=0; i < 2; ++
i) {
638 diag(
"Bad MODLUNIT environment variable. Cant open:", buf);
641 #if defined(__MINGW32__) 645 if (strncmp(s,
"/cygdrive/", 10) == 0) {
668 fprintf(stderr,
"Set a MODLUNIT environment variable path to the units table file\n");
669 fprintf(stderr,
"Cant open units table in either of:\n%s\n", buf);
725 printf(
"conformability\n");
731 printf(
"underflow or overflow\n");
741 int pu(
int u,
int i,
int f)
772 for(c=0; c<
NDIM; c++)
802 err |=
lookup(cp, p, den, c);
830 for(i=0; i<
NDIM; i++)
834 for(i=0; i<
NDIM; i++)
837 if(c >=
'2' && c <=
'9') {
845 while(*cp1 == *cp2++)
857 for(cp1 = name; *cp1; cp1++);
858 if(cp1 > name+1 && *--cp1 ==
's') {
862 fprintf(stderr,
"Need declaration in UNITS block of the form:\n\ 863 (%s) (units)\n", name);
864 diag(
"Cannot recognize the units: ", name);
869 static int equal(
char* s1,
char* s2)
884 struct table *tp, *lp;
889 for(i=0; i<
NDIM; i++) {
923 while(c !=
'\n' && c != 0)
928 #if NRN_DYNAMIC_UNITS 939 for (i = 0; i < 6; ++
i) {
943 assert(strcmp(legstr,
"Legacy") == 0);
945 assert(y_or_n ==
'Y' || y_or_n ==
'N');
946 legacy = (y_or_n ==
'Y') ? 1 : 0;
949 while(c !=
'\n' && c != 0) {
962 while(c !=
' ' && c !=
'\t') {
974 for(c=0; c<
NDIM; c++)
990 for(c=0; c<
NDIM; c++) {
992 if(t>1 || (f>0 && t!=0))
1005 printf(
"redefinition %s\n", np);
1009 #if NRN_DYNAMIC_UNITS 1013 double modern_getflt() {
1024 while(c ==
' ' || c ==
'\t');
1027 if(c >=
'0' && c <=
'9') {
1037 if(c ==
'+' || c ==
'-') {
1041 while(c >=
'0' && c <=
'9') {
1047 d_modern = atof(str);
1049 d_modern /= modern_getflt();
1064 #if NRN_DYNAMIC_UNITS 1066 return modern_getflt();
1073 while(c ==
' ' || c ==
'\t');
1076 if(c >=
'0' && c <=
'9') {
1090 if(c ==
'+' || c ==
'-') {
1096 while(c >=
'0' && c <=
'9') {
1124 if((c=
peekc) != 0) {
1149 h = h*57 + *np++ -
'0';
1150 if( ((
int)h)<0) h= -(
int)h;
1183 #if NRN_DYNAMIC_UNITS 1188 "#define %s _nrnunit_%s[_nrnunit_use_legacy_]\n" 1190 "static double _nrnunit_%s[2] = {%a, %g}; /* %.18g */\n",
1191 name, name, name, modern, legacy, modern);
1198 #if (defined(LegacyFR) && LegacyFR == 1)
static double dynam_unit_mag(int legacy, char *u1, char *u2)
static int Getc(FILE *inp)
char * hoc_dos2unixpath(const char *d)
static void print_unit_expr(int i)
void nrnunit_dynamic_str(char *buf, const char *name, char *u1, char *u2)
void unit_push_num(double d)
static void units_alloc()
sprintf(buf," if (secondorder) {\ " int _i;\" " for(_i=0;_i< %d;++_i) {\" " _p[_slist%d[_i]]+=dt *_p[_dlist%d[_i]];\" " }}\", numeqn, listnum, listnum)
static struct unit unit_stack[UNIT_STK_SIZE]
#define OUTTOLERANCE(arg1, arg2)
void install_units(char *s1, char *s2)
void Unit_exponent(int val)
char * getenv(const char *s)
fprintf(stderr, "Don't know the location of params at %p\, pp)
static void install_units_help(char *s1, char *s2)
void diag(char *, char *)
int lookup(char *name, unit *up, int den, int c)
struct table * hash_table(char *)
static int equal(char *s1, char *s2)
static char * neuronhome()
char * Unit_str(unit *up)
static char * unames[NDIM]
void unit_mag_mul(double d)
static struct table * table
static void switch_units(int legacy)