NEURON
mos2nrn.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #include <stdio.h>
3 #include <assert.h>
4 #include "../oc/nrnassrt.h"
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include "mos2nrn.h"
8 
9 static void getdname(char* dname);
10 
11 #include <string.h>
12 
13 const char* back2forward(const char*);
14 const char* basefile(const char*);
15 
16 int main(int argc, char** argv) {
17  char buf[256];
18  char dname[256];
19 
20  if (argc != 2) {
21  fprintf(stderr, "Usage: mos2nrn [hocfile | nrnzipfile]\n");
22  return 1;
23  }
24  FILE* f = fopen(argv[1], "r");
25  if (!f) {
26  return 1;
27  }
28  if (fread(buf, 1, 5, f) < 2) {
29  return 1;
30  }
31  fclose(f);
32  if (strncmp(buf, "PK", 2) == 0) { // its a nrnzip file
33  getdname(dname);
34  nrn_assert(snprintf(buf,
35  256,
36  "xterm -sb -e %s/mos2nrn2.sh %s %s %d",
37  NEURON_BIN_DIR,
38  argv[1],
39  dname,
40  0) < 256);
41  int i = system(buf);
42  if (i) {
43  return i;
44  }
45  } else { // its a hoc file
46  sprintf(buf, "xterm -sb -e %s/nrniv %s -", NEURON_BIN_DIR, argv[1]);
47  int i = system(buf);
48  if (i) {
49  return i;
50  }
51  }
52  return 0;
53 }
54 
55 const char* back2forward(const char* back) {
56  static char forward[256];
57  char* cp;
58  strcpy(forward, back);
59  for (cp = forward; *cp; ++cp) {
60  if (*cp == '\\') {
61  *cp = '/';
62  }
63  }
64  return forward;
65 }
66 
67 const char* basefile(const char* path) {
68  const char* cp;
69  for (cp = path + strlen(path) - 1; cp >= path; --cp) {
70  if (*cp == '\\' || *cp == ':' || *cp == '/') {
71  return cp + 1;
72  }
73  }
74  return path;
75 }
76 
77 static void getdname(char* dname) {
78  int fd;
79  const char* tdir;
80  if ((tdir = getenv("TEMP")) == NULL) {
81  tdir = "/tmp";
82  }
83  sprintf(dname, "%s/nrnXXXXXX", tdir);
84 #if HAVE_MKSTEMP
85  fd = mkstemp(dname);
86  close(fd);
87 #else
88  mktemp(dname);
89 #endif
90 }
sprintf(buf, " if (secondorder) {\n" " int _i;\n" " for (_i = 0; _i < %d; ++_i) {\n" " _p[_slist%d[_i]] += dt*_p[_dlist%d[_i]];\n" " }}\n", numeqn, listnum, listnum)
char buf[512]
Definition: init.cpp:13
static int argc
Definition: inithoc.cpp:53
static char ** argv
Definition: inithoc.cpp:54
char * mktemp(char *)
Definition: ivocmac.cpp:27
char * getenv(const char *s)
Definition: macprt.cpp:67
#define i
Definition: md1redef.h:12
int main(int argc, char **argv)
Definition: mos2nrn.cpp:57
#define fprintf
Definition: mwprefix.h:30
#define nrn_assert(ex)
Definition: nrnassrt.h:53
FILE * fopen()
#define NULL
Definition: sptree.h:16
const char * back2forward(const char *)
Definition: mos2nrn.cpp:55
static void getdname(char *dname)
Definition: mos2nrn.cpp:77
const char * basefile(const char *)
Definition: mos2nrn.cpp:67