File: ropen.rst

package info (click to toggle)
neuron 8.2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,760 kB
  • sloc: cpp: 149,571; python: 58,465; ansic: 50,329; sh: 3,510; xml: 213; pascal: 51; makefile: 35; sed: 5
file content (153 lines) | stat: -rwxr-xr-x 3,494 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
.. _ropen:

Open and Write to Files (Obsolete)
----------------------------------



.. function:: ropen


    Syntax:
        ``h.ropen("infile")``

        ``h.ropen()``


    Description:
        ``h.ropen("infile")`` opens *infile* for reading.  A subsequent ``h.ropen()`` with no arguments 
        closes the previously opened *infile*. A file which is re-opened with 
        ``ropen(infile)`` positions the stream at the beginning of the file. 

    Example:

        .. code-block::
            python

            ###########################################
            ### create a file titled "file.dat" with: #
            ### 42 13.7                               #
            ### 14 64.1                               #
            ### 12 9                                  #
            ###########################################

            from neuron import h, gui

            def r_open(ndat):
                h.ropen("file.dat")
                x = []
                y = []
                for i in range(ndat):
                    x.append(h.fscan())
                    y.append(h.fscan())
                h.ropen()
                return x, y

            # ndat is number of data points
            ndat = 3
            x, y = r_open(ndat)
         
         

    Diagnostics:
        This function returns 0 if the file is not successfully opened. 
         

    .. seealso::
        :ref:`read <keyword_read>`, :func:`fscan`, :func:`getstr`, :class:`File`
        

    .. warning::
        There is no way to open more than one read file at a time.  The same is 
        true for write files. 
         


----



.. function:: wopen


    Syntax:
        ``h.wopen("outfile")``

        ``h.wopen()``


    Description:
        ``h.wopen()`` is similar to ``h.ropen()`` but opens a file for writing. Contents of an 
        already existing *outfile* are destroyed.  Wopened files are written to 
        with :func:`fprint`. With no argument, the previously wopened file is closed. 
        h.wopen() returns 0 on failure to open a file. 

    Example:

        .. code-block::
            python

            from neuron import h, gui

            def w_open(ndat, x, y):
                h.wopen("file.dat") 
                for i in range(ndat):
                    h.fprint("%g %g\n", x[i], y[i])
                h.wopen()

            # ndat is number of data points
            ndat = 3
            x = [42.0, 14.0, 12.0]
            y = [13.7, 64.1, 9.0]
            w_open(ndat, x, y)

            


    .. seealso::
        :func:`fprint`, :func:`File`


----



.. function:: xopen


    Syntax:
        ``h.xopen("hocfile")``

        ``h.xopen("hocfile", "RCSrevision")``


    Description:
        ``h.xopen()`` executes the commands in ``hocfile``.  This is a convenient way 
        to define user functions and procedures. 
        An optional second argument is the RCS revision number in the form of a 
        string. The RCS file with that revision number is checked out into a 
        temporary file and executed. The temporary file is then removed.  A file 
        of the same primary name is unaffected. 


----



.. function:: fprint

    Syntax:
        ``h.fprint()``

    Example:

        .. code-block::
            python

            h.fprint("%g %g\n", x, y)

    Description:

        Same as :func:`printf` but prints to a file opened with :func:`wopen`. If no file 
        is opened it prints to the standard output.