File: ecl.html

package info (click to toggle)
pyraf 2.2.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,384 kB
  • sloc: python: 24,918; ansic: 372; lisp: 76; makefile: 8
file content (426 lines) | stat: -rw-r--r-- 14,379 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
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
	<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">
	<TITLE></TITLE>
	<META NAME="GENERATOR" CONTENT="OpenOffice.org 2.0  (Linux)">
	<META NAME="AUTHOR" CONTENT="Todd Miller">
	<META NAME="CREATED" CONTENT="20061117;8415800">
	<META NAME="CHANGEDBY" CONTENT="Todd Miller">
	<META NAME="CHANGED" CONTENT="20061121;13283200">
	<STYLE>
	<!--
		@page { size: 8.5in 11in }
		TD P.western { font-family: "Arial", sans-serif }
		H1.western { font-family: "Arial", sans-serif }
		P.western { font-family: "Arial", sans-serif }
		TH P.western { font-family: "Arial", sans-serif }
	-->
	</STYLE>
</HEAD>
<BODY LANG="en-US" DIR="LTR">
<H1 CLASS="western" ALIGN=CENTER><FONT SIZE=7>PyRAF ECL Support</FONT></H1>
<H1 CLASS="western">Overview</H1>
<P CLASS="western">PyRAF can now support the error handling
constructs of IRAF's ECL scripting language.  In addition to PyRAF's
classic Python exception handling, PyRAF's  ECL support enables
certain errors to be trapped and to cause exception handling
statements to execute. 
</P>
<P CLASS="western">PyRAF's ECL captures the following errors:</P>
<UL>
	<LI><DD><FONT FACE="Arial, sans-serif">System exceptions (FPE,
	segfault, etc) thrown by compiled tasks (i.e. SPP or C)</FONT></DD><LI><DD>
	<FONT FACE="Arial, sans-serif">error() calls from compiled tasks</FONT></DD><LI><DD>
	<FONT FACE="Arial, sans-serif">error() calls from CL scripts</FONT></DD><LI><DD STYLE="margin-bottom: 0.2in">
	<FONT FACE="Arial, sans-serif">division by zero in CL scripts</FONT></DD></UL>
<H1 CLASS="western">Activating ECL Support</H1>
<P CLASS="western">During it's introduction, PyRAF's ECL support is
optional and is only activated by one of the following means:</P>
<TABLE WIDTH=703 BORDER=1 CELLPADDING=4 CELLSPACING=3 STYLE="page-break-inside: avoid">
	<COL WIDTH=211>
	<COL WIDTH=465>
	<TR VALIGN=TOP>
		<TD WIDTH=211>
			<P CLASS="western" ALIGN=CENTER><B>Activation Method</B></P>
		</TD>
		<TD WIDTH=465>
			<P CLASS="western" ALIGN=CENTER><B>Description</B></P>
		</TD>
	</TR>
	<TR VALIGN=TOP>
		<TD WIDTH=211>
			<PRE>pyraf -e</PRE>
		</TD>
		<TD WIDTH=465>
			<P CLASS="western">Use command line switch -e when invoking pyraf.</P>
		</TD>
	</TR>
	<TR VALIGN=TOP>
		<TD WIDTH=211>
			<PRE>pyaf –ecl</PRE>
		</TD>
		<TD WIDTH=465>
			<P CLASS="western">Use the verbose switch, --ecl, when invoking
			pyraf</P>
		</TD>
	</TR>
	<TR VALIGN=TOP>
		<TD WIDTH=211>
			<PRE>epyraf</PRE>
		</TD>
		<TD WIDTH=465>
			<P CLASS="western">Link pyraf to epyraf and run as epyraf.</P>
		</TD>
	</TR>
	<TR VALIGN=TOP>
		<TD WIDTH=211>
			<PRE>setenv PYRAF_USE_ECL 1</PRE>
		</TD>
		<TD WIDTH=465>
			<P CLASS="western">Set the environment variable PYRAF_USE_ECL to 1</P>
		</TD>
	</TR>
</TABLE>
<P CLASS="western"><BR><BR>
</P>
<P CLASS="western">In the absence of the above methods,  PyRAF runs
without ECL support.</P>
<H1 CLASS="western">New ECL Keywords</H1>
<P CLASS="western">PyRAF's ECL support uses the following words as
keywords, i.e. words which are part of ECL and can no longer be used
as program identifiers (i.e. variable, task, or procedure names):</P>
<UL>
	<LI><PRE>iferr</PRE>
	<LI><PRE>ifnoerr</PRE>
	<LI><PRE STYLE="margin-bottom: 0.2in">then</PRE>
</UL>
<H1 CLASS="western">ECL Grammar Extensions</H1>
<P CLASS="western" STYLE="background: transparent">PyRAF's support
for ECL includes two new symmetric statements, <SPAN STYLE="background: transparent"><FONT COLOR="#0000ff"><B><FONT COLOR="#000000">iferr</FONT></B>
</FONT></SPAN>and <B><FONT COLOR="#000000">ifnoerr</FONT></B><FONT COLOR="#0000ff">.</FONT>
iferr is used to describe what should be done when an error <B>occurs</B>
in a group of guarded statements, and ifnoerr is used to emphasize
what should be done when an error <B>does not occur</B> in a group of
guarded statements. A “guarded statement” is essentially a block
of ordinary CL statements for which errors should be trapped. An
“except action” are the statement(s) which should be executed
when an error occurs (iferr) or does not occur (ifnoerr). An “else
action” are the statement(s) which should be executed when an error
occurs. Below is the section of the PyRAF grammar which describes ECL
iferr statements; IFERR, IFNOERR, THEN, and ELSE denote keyword
literals:</P>
<PRE STYLE="margin-left: 0.79in">iferr_stmt    ::= if_kind guarded_stmt except_action
iferr_stmt    ::= if_kind guarded_stmt opt_newline THEN except_action
iferr_stmt    ::= if_kind guarded_stmt opt_newline THEN except_action opt_newline ELSE else_action
if_kind       ::= IFERR
if_kind       ::= IFNOERR                
guarded_stmt  ::=  { opt_newline statement_list }
except_action ::= compound_stmt
else_action   ::= compound_stmt</PRE><P CLASS="western">
A compound statement can be a single statement or block of
statements.</P>
<H1 CLASS="western">ECL Syntax Examples</H1>
<P CLASS="western">The simplest form of ECL error statement is a
block of guarded statements followed by a single handler statement
which should execute when one or more of the guarded statements fail.
The <B>then</B> keyword is optional in this form. A curious property
of ECL error handling is that <I>all guarded statements execute</I>,
even those following the first failed statement. This contrasts
sharply with Python's exception handling model which performs it's
traceback immediately following the first error.</P>
<PRE STYLE="margin-left: 2.36in">iferr {
&lt;guarded statements&gt;
} &lt;error-handler statement&gt;


iferr {
&lt;guarded statements&gt;
} then
&lt;error-handler statement&gt;</PRE><P CLASS="western">
When a block of error handler statements is desired, the <B>then</B>
keyword should be used to be compatible with ECL. An optional <B>else</B>
clause may be used to specify what to do when the guarded statements
all succeed; either the <B>then</B> clause or the <B>else</B> clause
is executed, but never both.</P>
<PRE STYLE="margin-left: 2.36in">iferr {
&lt;guarded statements&gt;
} then {
&lt;error-handler statements&gt;
} else {
&lt;non-error-handler statements&gt;
}</PRE><P CLASS="western">
There is a symmetric form of <B>iferr</B> which uses the keyword
<B>ifnoerr</B>. It is perhaps most useful when one doesn't want to
specify anything to handle an error, but only specify what to do when
the guarded statements succeed.  <B>ifnoerr</B> is effectively <B>iferr
</B>with the error-handling and success-handling statements reversed.</P>
<PRE STYLE="margin-left: 2.36in">ifnoerr {
&lt;guarded statements&gt;
} then {
&lt;non-error statements&gt;
} 



ifnoerr {
&lt;guarded statements&gt;
} then {
&lt;non-error statements&gt;
} else {
&lt;error handling statements&gt;
}</PRE><H1 CLASS="western">
ECL Pseudo Variables</H1>
<P CLASS="western">PyRAF in ECL mode defines the following pseudo
variables which are associated with each <I>task</I> object:</P>
<TABLE WIDTH=656 BORDER=1 CELLPADDING=4 CELLSPACING=3 STYLE="page-break-inside: avoid">
	<COL WIDTH=139>
	<COL WIDTH=490>
	<THEAD>
		<TR VALIGN=TOP>
			<TD WIDTH=139>
				<P CLASS="western" ALIGN=CENTER><B>Variable</B></P>
			</TD>
			<TD WIDTH=490>
				<P CLASS="western" ALIGN=CENTER><B>Description</B></P>
			</TD>
		</TR>
	</THEAD>
	<TBODY>
		<TR VALIGN=TOP>
			<TD WIDTH=139>
				<PRE>$errno</PRE>
			</TD>
			<TD WIDTH=490>
				<P CLASS="western">The numerical value associated with the last
				error.</P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=139>
				<PRE>$errtask</PRE>
			</TD>
			<TD WIDTH=490>
				<P CLASS="western">The task which caused the error.</P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=139>
				<PRE>$errmsg</PRE>
			</TD>
			<TD WIDTH=490>
				<P CLASS="western">The text message associated with the last
				error.</P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=139>
				<PRE>$err_dzvalue</PRE>
			</TD>
			<TD WIDTH=490>
				<P CLASS="western">The <I>result</I> value of a division by zero.</P>
			</TD>
		</TR>
	</TBODY>
</TABLE>
<P CLASS="western"><BR><BR>
</P>
<P CLASS="western">Since pseudo variables are associated with a task
object, they have several properties:</P>
<OL>
	<LI><P CLASS="western">They are persistent, i.e. not cleared until a
	task is re-run, and only then based on erract's <B>clear</B> field.
	They are however overwritten with each new error.</P>
	<LI><P CLASS="western">They can be accessed in CL code as written in
	the table above.</P>
	<LI><P CLASS="western">They can be accessed from the command line
	using DOLLAR notation after a traceback has occurred:</P>
	<P CLASS="western">--&gt; iraf.failed_task.DOLLARerrno</P>
	<P CLASS="western">57</P>
	<P CLASS="western">--&gt; iraf.failed_task.DOLLARerrmsg</P>
	<P CLASS="western">'becuz something went wrong...'</P>
	<P CLASS="western">--&gt; iraf.failed_task_caller.DOLLARerrtask</P>
	<P CLASS="western">failed_task</P>
	<LI><P CLASS="western">They are not re-entrant – i.e., recursive
	procedures using them are only referring to a single storage
	location and will interfere with one another, only recording the
	last error.</P>
</OL>
<H1 CLASS="western">ECL Functions</H1>
<P CLASS="western">PyRAF in ECL mode defines the following error
handling functions which are analogous to the pseudo variables and
easier to use.</P>
<TABLE WIDTH=703 BORDER=1 CELLPADDING=4 CELLSPACING=3 STYLE="page-break-inside: avoid">
	<COL WIDTH=102>
	<COL WIDTH=574>
	<THEAD>
		<TR VALIGN=TOP>
			<TD WIDTH=102>
				<P CLASS="western" ALIGN=CENTER><B>Function</B></P>
			</TD>
			<TD WIDTH=574>
				<P CLASS="western" ALIGN=CENTER><B>Description</B></P>
			</TD>
		</TR>
	</THEAD>
	<TBODY>
		<TR VALIGN=TOP>
			<TD WIDTH=102>
				<PRE>error()</PRE>
			</TD>
			<TD WIDTH=574>
				<P CLASS="western">Forces a CL error state, generally raising a
				traceback.</P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=102>
				<PRE>errno()</PRE>
			</TD>
			<TD WIDTH=574>
				<P CLASS="western">Returns the numerical value associated with
				the last error.</P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=102>
				<PRE>errmsg()</PRE>
			</TD>
			<TD WIDTH=574>
				<P CLASS="western">Returns the message associated with the last
				error.</P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=102>
				<PRE>errtask()</PRE>
			</TD>
			<TD WIDTH=574>
				<P CLASS="western">Returns the task associated with the last
				error.</P>
			</TD>
		</TR>
	</TBODY>
</TABLE>
<H1 CLASS="western">Division By Zero</H1>
<P CLASS="western">PyRAF's ECL mode now traps division by zero and
either raises and ECL exception or returns the default result value
contained in the variable <B>$err_dzvalue</B>.</P>
<P CLASS="western">So in ECL, the following guarded code:</P>
<PRE STYLE="margin-left: 0.79in">iferr {
$err_dzvalue = 33
print 1/0
}
</PRE><P CLASS="western">
Outputs:</P>
<PRE STYLE="margin-left: 0.79in">Warning on line 6 of 'nested5':  divide by zero - using $err_dzvalue = 33
33</PRE><P CLASS="western">
While un-guarded code such as:</P>
<PRE STYLE="margin-left: 0.79in">$err_dzvalue = 33
print 1/0</PRE><P CLASS="western">
Generates a traceback and outputs:</P>
<PRE STYLE="margin-left: 0.79in">ERROR (1): divide by zero
   'print 1/0'
      line 4: /home/jmiller/nested5.cl
Traceback (innermost last):
  File &quot;&lt;CL script CL1&gt;&quot;, line 8, in &lt;module&gt;
IrafError: ERROR: divide by zero
                                                                                                                                                                                </PRE><H1 CLASS="western">
Controlling ECL Behavior using erract</H1>
<P CLASS="western">PyRAF's ECL mode behavior is controlled by a
multi-field environment variable named <B>erract</B>. erract is set
in PyRAF as a string containing one or more field modifiers. 
</P>
<PRE STYLE="margin-left: 1.58in; text-align: left">--&gt; show erract
abort trace flpr clear full ecl</PRE><P CLASS="western" ALIGN=LEFT>
Multiple fields may be changed with a single “set” command, and
not all fields need be specified. Fields not mentioned in a set
statement retain their old values.</P>
<PRE STYLE="margin-left: 1.58in; text-align: left">--&gt; set erract=&quot;noflpr noclear&quot;

--&gt; show erract
abort trace noflpr noclear full ecl
</PRE>
<TABLE WIDTH=703 BORDER=1 CELLPADDING=4 CELLSPACING=3>
	<COL WIDTH=147>
	<COL WIDTH=529>
	<THEAD>
		<TR VALIGN=TOP>
			<TH WIDTH=147>
				<P CLASS="western">Erract Field</P>
			</TH>
			<TH WIDTH=529>
				<P CLASS="western">Description</P>
			</TH>
		</TR>
	</THEAD>
	<TBODY>
		<TR VALIGN=TOP>
			<TD WIDTH=147>
				<PRE>abort / noabort</PRE>
			</TD>
			<TD WIDTH=529>
				<P CLASS="western">Outside an iferr block, a failed task results
				in an immediate error. Inside an iferr block, a failed task
				causes an error as soon as the iferr guarded block is exited. Set
				to noabort and errors won't stop execution regardless of iferr
				usage.</P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=147>
				<PRE>trace / notrace</PRE>
			</TD>
			<TD WIDTH=529>
				<P CLASS="western">Print traceback information to stderr, or
				don't print.</P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=147>
				<PRE>flpr / noflpr</PRE>
			</TD>
			<TD WIDTH=529>
				<P CLASS="western">Flush the process cache on error, or don't
				flush.</P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=147>
				<PRE>clear / noclear</PRE>
			</TD>
			<TD WIDTH=529>
				<P CLASS="western">Clear the error pseudo variables for a task
				before running it, or retain the old error values which may or
				may not be overwritten.</P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=147>
				<PRE>full / nofull</PRE>
			</TD>
			<TD WIDTH=529>
				<P CLASS="western">Print traceback information on the entire
				procedure call chain, or only on the innermost CL procedure.</P>
			</TD>
		</TR>
		<TR VALIGN=TOP>
			<TD WIDTH=147>
				<PRE>ecl  / noecl</PRE>
			</TD>
			<TD WIDTH=529>
				<P CLASS="western">Use the new ECL error handling, or use classic
				PyRAF/Python exception handling inside iferr and ifnoerr blocks.
				Setting noecl causes an error to raise an immediate exception and
				give a Python traceback.</P>
				<P CLASS="western">This is a runtime control.   It does not
				affect ECL compilation which can only be activated at system
				startup.</P>
			</TD>
		</TR>
	</TBODY>
</TABLE>
<P CLASS="western"><BR><BR>
</P>
</BODY>
</HTML>