File: error_usage.rst

package info (click to toggle)
calceph 4.0.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,944 kB
  • sloc: ansic: 21,414; fortran: 4,054; python: 1,569; sh: 197; makefile: 5
file content (256 lines) | stat: -rw-r--r-- 8,228 bytes parent folder | download | duplicates (2)
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
.. ifconfig:: calcephapi in ('C')

    The following example shows how to stop the execution on the error.

    ::

        t_calcephbin * eph;
        
        /* set the  error handler to stop on error */
        calceph_seterrorhandler(2, 0);
        
        /* open the ephemeris file */
        eph = calceph_open("example1.dat");
        
        /*... computation ... */
    
    The following example shows how to define a custom error handler function.

    ::
    
        /*-----------------------------------------------------------------*/
        /* custom error handler */
        /*-----------------------------------------------------------------*/
        static void myhandler(const char *msg)
        {
                puts("The calceph calls the function myhandler");
                printf("The message contains %d characters\n", (int)strlen(msg));
                puts("The error message is :");
                puts("----------------------");
                puts(msg);
                puts("----------------------");
                puts("The error handler returns");
        }

        int main(void)
        {
            t_calcephbin * eph;
        
            /* set the  error handler to stop on error */
            calceph_seterrorhandler(3, myhandler);
        
            /* open the ephemeris file */
            eph = calceph_open("example1.dat");
        
            /*... computation ... */
            
            return 0;
        }    


.. ifconfig:: calcephapi in ('F2003')

    The following example shows how to stop the execution on the error.

    ::
    
       program f2003error
           USE, INTRINSIC :: ISO_C_BINDING
           use calceph
           implicit none
           integer res
           real(8) jd0
           real(8) dt
           real(8) PV(6)
                      
        ! set the  error handler to stop on error
            call calceph_seterrorhandler(2, C_NULL_FUNPTR)

        ! open the ephemeris file 
           res = calceph_sopen("example1.dat"//C_NULL_CHAR)
           ...
           
       stop
       end      

    The following example shows how to define a custom error handler function.

    ::
    
        !/*-----------------------------------------------------------------*/
        !/* custom error handler */
        !/*-----------------------------------------------------------------*/
             subroutine myhandler(msg, msglen) BIND(C)
                USE, INTRINSIC :: ISO_C_BINDING
                implicit none
                character(kind=C_CHAR), dimension(msglen), intent(in) :: msg
                integer(C_INT), VALUE, intent(in) :: msglen
                write (*,*) "The calceph calls the function myhandler"
                write (*,*) "The message contains ",msglen," characters"
                write(*,*) "The error message is :"
                write(*,*) "----------------------"
                write(*,*) msg
                write(*,*) "----------------------"
                write(*,*) "The error handler returns"
             end

        !/*-----------------------------------------------------------------*/
        !/* main program */
        !/*-----------------------------------------------------------------*/
             program f2003error
                 USE, INTRINSIC :: ISO_C_BINDING
                 use calceph
                 implicit none
                 integer res
                 real(8) jd0
                 real(8) dt
                 real(8) PV(6)
         
                 interface
                  subroutine myhandler(msg, msglen) BIND(C)
                      USE, INTRINSIC :: ISO_C_BINDING
                      implicit none
                      character(kind=C_CHAR), dimension(msglen), intent(in) &
            &          :: msg
                      integer(C_INT), VALUE, intent(in) :: msglen
                  end subroutine
                 end interface 

         
        ! set the  error handler to use my own callback 
                 call calceph_seterrorhandler(3, c_funloc(myhandler))

        ! open the ephemeris file 
                res = calceph_sopen("example1.dat"//C_NULL_CHAR)
           
           ! ...
           
             stop
             end

.. ifconfig:: calcephapi in ('F90')

    The following example shows how to stop the execution on the error.

    ::
    
       program f77error
           implicit none
           include 'f90calceph.h'
           integer*8 peph
           integer res
                      
           ! set the  error handler to stop on error
            call f90calceph_seterrorhandler(2, 0)

           ! open the ephemeris file 
           res = f90calceph_open(peph, "example1.dat")
           ! ...
       stop
       end      

    The following example shows how to define a custom error handler function.

    ::
    
        !-----------------------------------------------------------------
        ! custom error handler
        !-----------------------------------------------------------------
                subroutine myhandler(msg) 
                   implicit none
                   character(len=*) :: msg
                   write (*,*) "The calceph calls the function myhandler"
                   write (*,*) "The message contains ",len(msg)," characters"
                   write(*,*) "The error message is :"
                   write(*,*) "----------------------"
                   write(*,*) msg
                   write(*,*) "----------------------"
                   write(*,*) "The error handler returns"
                end

        !-----------------------------------------------------------------
        ! main program 
        !-----------------------------------------------------------------
        program f77error
           implicit none
           include 'f90calceph.h'
           integer res
           integer*8 peph
           external myhandler
           

            ! set the  error handler to use my own callback 
            call f90calceph_seterrorhandler(3, myhandler)
            
           ! open the ephemeris file 
           res = f90calceph_open(peph, "example1.dat")
           ! ...
       stop
       end      
           

.. ifconfig:: calcephapi in ('Python')

    The following example shows how to stop the execution on the error.

    ::
    
        from calcephpy import *

        #set the  error handler to stop on error 
        seterrorhandler(2, 0);

        # open the ephemeris file 
        peph = CalcephBin.open("example1.dat")
    
     
    The following example shows how to define a custom error handler function.

    ::

        from calcephpy import *

        #-----------------------------------------------------------------
        # custom error handler
        #-----------------------------------------------------------------
        def myhandler(msg):
            print("The calceph calls the function myhandler");
            print("The message contains {0} characters\n".format(len(msg)))
            print("The error message is :")
            print("----------------------")
            print(msg)
            print("----------------------")
            print("The error handler returns")

        # set the  error handler to use my own callback 
        seterrorhandler(3, myhandler)
    
        # open the ephemeris file 
        peph = CalcephBin.open("example1.dat")



.. ifconfig:: calcephapi in ('Mex')

    The following example shows how to define a custom error handler function.

    ::

        %-----------------------------------------------------------------
        % custom error handler
        %-----------------------------------------------------------------
        function myhandler(msg)
            disp('The calceph calls the function myhandler');
            disp('The error message is :')
            disp('----------------------')
            disp(msg)
            disp('----------------------')
            disp('The error handler returns')
        end
         
        % set the  error handler to use my own callback 
        calceph_seterrorhandler(3, 'myhandler')
    
        % open the ephemeris file 
        peph = CalcephBin.open('example1.dat')