source: Sophya/trunk/SophyaLib/Manual/piapp.tex@ 3929

Last change on this file since 3929 was 3871, checked in by ansari, 15 years ago

MAJ user's guide piapp pour V=2.2, Reza 12/08/2010

File size: 79.7 KB
RevLine 
[3041]1\documentclass[twoside,10pt]{article}
[2384]2% \usepackage[latin1]{inputenc}
3% \usepackage[T1]{fontenc}
[2171]4\usepackage[francais]{babel}
5\usepackage{graphicx}
6
[2384]7\usepackage{amsmath}
8\usepackage{amssymb}
9\usepackage{latexsym}
10
[2171]11\usepackage{palatino}
12
13% Definition pour Docs Sophya
14\usepackage{defsophya}
15
16\usepackage{makeidx}
17
18\usepackage[ps2pdf,bookmarks,bookmarksnumbered,%
19 urlcolor=blue,citecolor=blue,linkcolor=blue,%
20 pagecolor=blue,%hyperindex,%
21 colorlinks=true,hyperfigures=true,hyperindex=true
22 ]{hyperref}
23
[3429]24\setlength{\textwidth}{15cm}
25\setlength{\textheight}{20.5cm}
26\setlength{\topmargin}{0.cm}
[2171]27\setlength{\oddsidemargin}{0.cm}
28\setlength{\evensidemargin}{0.cm}
29\setlength{\unitlength}{1mm}
30
[2384]31% \newcommand{\piacommand}[1]{
32% \framebox{\bf \Large #1 } \index{#1} % (Command)
33%}
34% \newcommand{\piahelpitem}[1]{
35% \framebox{\bf \Large #1 } \index{#1} (Help item)
36%}
37
[3041]38\newcommand{\rond}{$\bullet \ $}
39\newcommand{\etoile}{$\star \ $}
40\newcommand{\cercle}{$\circ \ $}
41\newcommand{\carre}{$\Box \ $}
42
43%%%% Definition des commandes pour l'aide en ligne
[2171]44\newcommand{\piacommand}[1]{
[2384]45$\blacksquare$ \hspace{3mm} {\bf \Large #1 } \index{#1} % (Command)
[2171]46}
47\newcommand{\piahelpitem}[1]{
[2384]48$\square$ \hspace{3mm} {\bf \Large #1 } \index{#1} (Help item)
[2171]49}
50
[3041]51\newcommand{\menubar}[1]{\hspace{1mm} \framebox{\it MenuBar::#1} \hspace{1mm}}
52
[2171]53\newcommand{\myppageref}[1]{ (p. \pageref{#1} ) }
54
55\makeindex % Constitution d'index
56
57\begin{document}
58\begin{titlepage}
59% The title page - top of the page with the title of the paper
60\titrehp{piapp \\ An interactive data analysis tool}
61% Authors list
62\auteurs{
63R. Ansari & ansari@lal.in2p3.fr \\
64E. Aubourg & aubourg@hep.saclay.cea.fr \\
65C. Magneville & cmv@hep.saclay.cea.fr \\
66O. Perdereau & perderos@lal.in2p3.fr \\
67}
68% \author{R. Ansari {\tt ansari@lal.in2p3.fr} \\
69% E. Aubourg {\tt aubourg@hep.saclay.cea.fr} \\
70% C. Magneville {\tt cmv@hep.saclay.cea.fr}
71% }
72\vspace{1cm}
73\begin{center}
[3858]74{\bf \Large piapp Version: 4.3 (V\_Sep2007) } \\
75{\bf SOPHYA version=4.2 , PI version= 4.2 }
[2171]76\end{center}
77\titrebp{5}
78
79\end{titlepage}
80
81\newpage
82\tableofcontents
83\newpage
84
85\section{Introduction}
86\index{piapp}
87{\bf piapp} (or {\bf spiapp}) is an interactive data analysis
88and visualization program. It is based on the {\bf PI} GUI library
[3041]89and the {\bf SOPHYA} \footnote{see http://www.sophya.org}
90(or {\bf PEIDA++} \footnote{PEIDA++ has been used in EROS software.
91(http://eros.in2p3.fr). It is not maintained anymore.})
92C++ data analysis class library.
93\par
94{\bf piapp} is a powerful command oriented tool for visualising and analysing data.
95Its main features are summarised below:
96\begin{itemize}
97\item[\rond] Image, multiple 2D and few 3D representations
98\item[\rond] Highly interactive graphics, with postscript as export format
99\item[\rond] Capability to handle large data sets. Data can be imported and
100exported in different formats: ASCII, PPF and FITS.
101\item[\rond] Interactive analysis: 2D/3D distributions, histograms, FFT \ldots
102\item[\rond] Flexible c-shell inspired command interpreter.
103\item[\rond] Possibility to perform more complex operations in C++, on objects
104managed by the application through the on-the-fly compilation and execution
105of c++ code fragments in piapp.
106\item[\rond] piapp is a multi-threaded program with separate threads for graphics
107and command execution, ensuring interactive response, even while heavy
108computation is being performed. In addition, thread safe commands can be executed
109in separate threads, for taking advantage of multi CPU (or CPU-cores) workstations.
110\item[\rond] The application can be easily extended through modules which can be
111loaded at run time.
112\end{itemize}
[3438]113
114\subsection{Acknowlegments}
115Many people have contributed to the development SOPHYA and/or the PI library
116and (s)piapp interactive analysis tool.
117we are grateful to the following people:
118
119\begin{tabular}{lcl}
120Reza Ansari & \hspace{5mm} & (LAL-Univ.Paris Sud, Orsay) \\
121Eric Aubourg & & (DAPNIA-CEA/APC, Saclay) \\
122Sophie Henrot-Versille & & (LAL-IN2P3/CNRS, Orsay) \\
123Alex Kim & & (LBL, Berkeley) \\
124Guy Le Meur & & (LAL-IN2P3/CNRS, Orsay) \\
125Eric Lesquoy & & (DAPNIA-CEA, Saclay) \\
126Christophe Magneville & & (DAPNIA-CEA, Saclay) \\
127Bruno Mansoux & & (LAL-IN2P3/CNRS, Orsay) \\
128Olivier Perdereau & & (LAL-IN2P3/CNRS, Orsay) \\
129Nicolas Regnault & & (LPNHE-IN2P3/CNRS, Paris) \\
130Benoit Revenu & & (APC/Univ.Paris 7, Paris) \\
131Francois Touze & & (LAL-IN2P3/CNRS, Orsay) \\
132\end{tabular}
133
134We thank also the persons who have helped us by useful suggestions, among others : \\
[3441]135S. Bargot, S. Plasczczynski, C. Renault and D. Yvon.
[3438]136
[3041]137%%%
[3429]138\begin{figure}[ht!]
139\begin{center}
140\includegraphics[width=15cm]{piapp_mainwin.eps}
141\caption{piapp main window}
142\label{figmainwin}
143\end{center}
144\end{figure}
145\subsection{starting piapp}
[3041]146 {\bf piapp} can simply be started on the command line in a terminal window
147once the SOPHYA/piapp environment has been initialised.
148The environment variables {\tt SOPHYABASE} should contain the directory
149where SOPHYA/piapp has been installed. the shared library path
150{\tt LD\_LIBRARY\_PATH} must contain {\tt \$SOPHYABASE /slb} and the
151current directory {\tt .} and the executable search path {\tt PATH} must
152contain {\tt \$SOPHYABASE /exe}. Refer to the SOPHYA overview manual
153for more information on SOPHYA directory structure. \\
154\par
155{\tt (s)piapp -h} provides a brief help of the command line
[2171]156arguments. Xtoolkit options can also be specified as command line
[3041]157arguments. {\bf spiapp} is the name of SOPHYA/piapp executable,
158in order to distinguish it from PEIDA/piapp.
[2171]159\begin{verbatim}
160csh> spiapp -h
[3041]161 SophyaInitiator::SophyaInitiator() BaseTools Init
162 PIOPersist::Initialize() Starting Sophya Persistence management service
[3429]163SOPHYA Version 2.1 Revision 0 (V_Nov2007) -- Nov 24 2007 13:08:58 gcc 3.3
16420030304 (Apple Computer, Inc. build 1495)
[3041]165 piapp: Interactive data analysis and visualisation program
[3429]166 Usage: piapp [-nored] [-doublered] [-termread] [-term]
167 [-hidezswin] [-small] [-nosig] [-nosigfpe] [-nosigsegv]
[3041]168 [-tmpdir TmpDirectory] [-help2tex] [-exec file [args]]
169 -nored : Don't redirect stdout/stderr to piapp console
[3429]170 -doublered : Redirect stdout/stderr to piapp console AND the terminal
[3041]171 -termread : Read commands on terminal (stdin)
172 -term : equivalent to -nored -termread -small
173 -hidezswin : Hide Zoom/Stat/ColMap window
174 -small : Create small size main piapp window
175 -nosig : Don't catch SigFPE, SigSEGV
176 -nosigfpe -nosigsegv: Don t catch SigFPE / SigSEGV
177 -tmpdir TmpDirectory: defines TMDIR for temporary files
[2171]178 -help2tex: Create a LaTeX help file (piahelp.tex)
[3041]179 -exec file [args] : Execute command file (last option)
[2171]180\end{verbatim}
[3041]181Once {\bf piapp} is started, the main piapp window appears.
182It contains the menu bar, an upper part with the zoom and colormap
183widgets for image displays, memory and CPU usage and a terminal like
184widget (piapp console, see {\bf PIConsole} \myppageref{PIConsole})
185in the lower part. The figure \ref{figmainwin}
[2171]186shows an image of the piapp main window.
[3041]187{\tt stdout/cout, stderr/cerr} are redirected to the piapp console and
188commands can be entered in this widget. It is also possible to keep
189the terminal where piapp was started for {\tt stdout/stderr} (flag {\tt -nored}).
[3439]190The flag {\tt -term} activate a command reader on the terminal
191It is also possible to have a command reader on the terminal ({\tt stdin}). \\[1mm]
[3871]192The environment variable {\tt PIDEFAFSZFRAC} controls the automatic selection
193of font size for drawing axes, as a function of the window size (typical value 0.03 \ldots 0.1).
194Check the command {\tt setdefafsz } \myppageref{setdefafsz} and {\tt setaxesatt}
195\myppageref{setaxesatt} for more information. \\[1mm]
[2171]196
[3041]197\par
198In section 2, we present a quick tour of {\bf piapp}.
199a brief overview of piapp graphics, supported data formats, interactive
200analysis possibilities, the command interpreter and c++ execution
201are presented in the following sections.
202Section \ref{piappcmdref} contains a brief description of all piapp commands
203and help items. Various interactive control windows are described in appendix.
[2171]204
[3439]205\subsection{DemoPIApp and DemoData}
206The directory {\bf DemoPIApp} contains a number of example scripts, such as the
207{\tt demo.pic} and the associated data file {\tt demo.ppf}. It contains
208also examples of loadable modules for piapp. The DemoPIApp/CONTENT
209file contains a brief description of the different files. \\
210The {\bf DemoData} contains a number of data files, in PPF and FITS format, which are
211used for the examples in this document.
[2171]212
[3439]213\subsection{Warnings/Known problems}
214\begin{enumerate}
215\item It might be necessary to define the environment variable
[3817]216{\bf PIXKBMODMASK}, used by the libPI.a to map correctly
[3439]217the {\tt <Alt>} key with some X servers (in particular with
218X11 on MacOS X). \\
219{\tt csh> setenv PIXKBMODMASK 2 }
220However, the default value has been changed in PI/piapp V=4.1 and it should not be
221necessary anymore to define PIXKBMODMASK.
222%%
223\item The output redirection uses unix pipes. On Linux, with commands
224producing long outputs, the application may block because of incorrect management
225of pipes. If this happens, use piapp with {\tt -nored} flag. This problem has been
226in principle solved with SOPHYA V=2.1 / piapp V=4.1
227\end{enumerate}
228
[2171]229\newpage
230\section{A Tour of piapp}
[3041]231\subsection{Interacting with piapp, getting help}
232Users interact with piapp through commands entered in the piapp-console
233(or the unix terminal), and through the different menus.
234Some of the possibilities of the piapp-console are described
235in {\bf PIConsole} help item, in the command reference section \myppageref{PIConsole}.
236The description
237of the commands in available online using the help command.
238An online help window can be displayed by \menubar{File / Help}.
239Commands and help items are grouped in categories which can be
240selected using the OptionMenu in the Help window.
241\begin{verbatim}
242Cmd> help func
243Displays a function y=f(x) (Fills a vector with function values)
244 Usage: func f(x) xmin xmax [npt graphic_attributes]
245 Related commands: funcff func2d func2dff
246Cmd> func sin(x)/x 0.1 10 100 'red line=solid,2'
247---> Graphic display of the function
248\end{verbatim}
249The directory {\tt DemoPIApp} contains a number of example
250command script and sample data files.
251
[3439]252\subsection{The Object Manager (NamedObjMgr)}
[2171]253The {\bf piapp} application is built around an object manager
254(class {\tt NamedObjMgr}) and a graphic application
255(class {\tt PIStdImgApp}). Objects inheriting from
256the class {\tt AnyDataObj} can be managed through adapter
257classes (classes inheriting from {\tt NObjMgrAdapter}) by
258the object manager.
259\par
260User sees the objects (such as Sophya objects Histo, NTuple,
261Arrays, Images, SkyMaps, \ldots) kept in memory, organized
262in a single level tree structure. Four memory directories
263are automatically created and can not be removed: \\
264\centerline{\bf /home \hspace{10mm} /old \hspace{10mm} /tmp \hspace{10mm} /autoc}
265The default working directory (in memory) is {\bf /home}.
266Other directories can be created by the user.
267\begin{center}
268{\bf Warning:} These are only the directory
269structure managed by the piapp application and do not
270correspond to the file system directories
271\end{center}
272The window {\bf ObjMgr} shown in figure \ref{figobjmgrw}
273can be used to navigate in the memory directories and
[3041]274execute simple operations on objects. \\
275This window can be displayed using the menu command
276\menubar{Objects / ObjectManager}.
[2171]277The button \framebox{\small \bf SetCurObj} can be used to set the value
278of the interpreter's variable {\tt cobj} to the selected
279object name.
280Refer to the commands in group {\bf Object Management}
281for more information.
282
283\vspace*{5mm}
284\begin{figure}[ht!]
285\begin{center}
286\includegraphics[width=10cm]{piapp_objmgr.eps}
287\caption{The interactive object management window}
288\label{figobjmgrw}
289\end{center}
290\end{figure}
291
292\subsection{command language}
[3041]293A basic command interpreter ({\bf PIACmd/Commander}) is included in {\bf piapp} and
[2171]294other command interpreters can be inserted in the application
295framework.
[3041]296This interpreter ({\bf Commander} \myppageref{Commander})
[2171]297synthax is close to the c-shell
298(csh) shell script. It is possible to define and use variables
299({\tt set} command, {\tt \$varname}), and execute loops
300({\tt foreach,for}), as well as simple tests
301({\tt if test then ... else ... endif}).
302Commands from a file (default extension .pic) can be executed
303using the {\tt exec} command.
304Long commands can be put on several lines, by ending a line
305by the backslash \\ caracter, to signal that the command
306continues on the next line.
307
308The command macro below shows a sample piapp session, where
309data from the file {\tt demo.ppf} are displayed.
310\begin{verbatim}
311# Trace mode -> On
312traceon
313# Deleting all objects in the current directory
314delobjs *
315# Opening the PPF file demo.ppf
316openppf demo.ppf
317# Various displays in a graphic window, divided into 2x2 zones
318zone 2 2
319# 1D histogram display
320disp h1d blue
321# 2D histogram display
322disp h2d
323# Function display
324func sin(x)/x 0.1 10. 200 gold
325# Surface representation of a matrix
326surf mtx1 colbr32
[2253]327# Contour representation of a matrix
328contour mtx1 'colrj32 normalline ncont=7'
[2171]329# 3D representation of points using a PAW like command
330n/plot nt31.z%y%x ! ! win
331# 3D points superimposed on the previous display
332nt3d nt32 x y z ex ey ez - - 'same fcirclemarker7 red'
333\end{verbatim}
334
335\subsection{NTuple vue / PAW like commands}
336It is possible to plot various expressions of objects, seen as
337a 2D table, with named columns. This possibility exist not only
[3439]338for NTuples/DataTables, but also for most objects (from SOPHYA) handled
339by piapp. The related commands are grouped under {\bf Expr.Plotting} and
340{\bf pawCmd} and are described in section \ref{tableplot}.
[2171]341
342\subsection{C++ execution inside piapp}
343For more complex processings, where the full power of C++
344and the class libraries are necessary, {\bf piapp} provide
345the possibility of executing C++ code, without the burden
346of having to write a complete program. The objects
347present in the current directory are automatically
348declared. The communication with the piapp application
349is done by the {\bf NamedObjMgr} class.
[3492]350Two macros {\tt KeepObj()} and {\tt DispObj()}
[2171]351simplify the task of keeping newly created objects.
352In the example below, we first create a noisy signal
353in a vector, and we keep it in the application
354(Notice the use of multiline command) :
355
356\begin{verbatim}
357Cmd> c++exec c++exec Vector in(1024); \
[3041]358...? in = RandomSequence(RandomSequence::Gaussian, 0., 1.); \
359...? for(int kk=0; kk<in.Size(); kk++) \
360...? in(kk) += 2*sin(kk*0.05); \
361...? KeepObj(in);
[2171]362\end{verbatim}
363We can of course display the resulting vector:
364\begin{verbatim}
365Cmd> disp in
366\end{verbatim}
367
368And, at a subsequent stage, make a low pass filter
369on the vector in:
370\begin{verbatim}
371Cmd> c++exec Vector out(1024); \
[3041]372...? int w = 2; \
373...? for(int k=w; k<in.Size()-w; k++) \
374...? out(k) = in(Range(k-w, k+w)).Sum()/(2.*w+1.); \
375...? KeepObj(out);
[2171]376\end{verbatim}
377
378We can display the new vector {\tt out} overlayed
379on the previously displayed vector:
380\begin{verbatim}
381Cmd> disp out 'red same'
382\end{verbatim}
383
[3439]384See section \ref{flycplusplus} and command group {\bf CxxExecutorCmd}
385for more information.
[2171]386
387\subsection{Extending the application}
388The {\bf piapp} application can easily be extended by the user.
389This is done through shared libraries which can be opened
390and used by the application.
391Two main methods can be used (see command group
392{\bf ExternalModules}) :
393\begin{itemize}
394\item Creation of user functions. A shared library containing
395at least one user function with the following prototype
396should be created:
397\begin{verbatim}
398extern "C" {
399 void myfonction(vector<string>& args);
400}
401\end{verbatim}
402The class {\bf NameObjMgr} should be used to communicate with the
403application. The {\tt link} \myppageref{link} and {\tt call} \myppageref{call}
404should be used to load and execute user functions. An example of
405user function can be found in DemoPIApp/user.cc exlink.pic.
406
407\item Creation of loadable modules: Loadable modules can be
408used to extend the application possibilities in a way totally
409transparent to the user. It is possible to define new commands,
410handling of new object types, additional graphic functionalities
411in a loadable module.
412
413The class {\bf CmdExecutor} is the base class for extending piapp.
414A shared library should be built, containing two functions,for
415the activation and deactivation of the module, with the following
416prototype (where {\tt mymodule} is the module's name.
417\begin{verbatim}
418extern "C" {
419 void mymodule_init();
420 void mymodule_end();
421}
422\end{verbatim}
423
424\end{itemize}
425
[3041]426%%%%%%%%%% Section 3: Graphiques
[2171]427\newpage
[3043]428\section{Interactive graphics}
[3442]429\label{intgraphics}
[3043]430%%%
431\subsection{Display commands}
432Many objects managed by piapp have a default graphic representation. The
433{\bf disp} command \myppageref{disp} can be used to display the object, while
434other commands like {\bf surf} \myppageref{surf} , {\bf imag}
[3429]435or {\bf contour} \myppageref{contour} will try to force a given graphic representation.
436
[3043]437Data from table like objects can be plotted using commands like {\bf nt2d}
438\myppageref{nt2d} or {\bf nt3d} \myppageref{nt3d}. Most objects in piapp
439can also be manipulated like table for plotting purposes, using commands
440like {\bf plot2d} \myppageref{plot2d} , {\bf plot3d} \myppageref{plot3d}
441or {\bf n/plot} \myppageref{nZplot}. These commands are described in section
[3429]442\ref{tableplot}.
443
444Commands producing a graphic output have usually an optional argument called \\
445{\tt graphic\_attributes} or {\tt gr\_att}. \\
446This argument provide a flexible and easy
447way to change and customise the output graphic, as discussed in the paragraphs below.
448
[3043]449The piapp graphics can be exported in postscript (.ps) or encapsulated postscript
450(.eps) format. The commands {\bf w2ps} \myppageref{w2ps} and
451 {\bf w2eps} \myppageref{w2eps} as well the menu \menubar{PostScript} can
[3429]452 be used to export graphics. \\[2mm]
[3439]453The examples in the following pages illustrates the usage of some piapp graphic commands.
454% \newpage
[3043]455\begin{enumerate}
[3442]456\label{francetopo}
457\item Image display. The following example uses the data file francetopo.ppf
458which can be found in the {\bf DemoData} directory. This PPF file contains
459a TMatrix$<$int\_2$>$ (short integers) representing 30 arcmin gridded
460($\sim$ 1 km N-S $\times$ 0.7 km E-W) elevation (or altitude)
461for the area centered on France. It has been made using topographic
462data (DEM: Digital Elevation Model) available from the {\bf N}ational
[3439]463{\bf G}eophysical {\bf D}ata {\bf C}enter
[3442]464\href{http://www.ngdc.noaa.gov/mgg/topo/}{({\bf NGDC/GLOBE})}
[3439]465\footnote{NGDC web site: \hspace{5mm}
[3442]466http://www.ngdc.noaa.gov/ }.
467In section \ref{tableplot}, an example shows how to use this data set to
468create altitude distribution histogram for selected regions.
[3043]469\begin{verbatim}
470# Open a PPF file containing topographic data for france
471# as a TMatrix<short> 1332x1548
[3439]472# The file is in the directory DemoData/
[3043]473openppf francetopo.ppf
474# Display the matrix, whit a zoom factor, lut and color map
475disp francetopo 'zoom/3 lut=lin,-700,800 colbr128 win'
476w2eps francetopo.eps
477\end{verbatim}
478\begin{center}
479\includegraphics[width=13cm]{francetopo.eps}
480\end{center}
[2171]481
[3043]482\item Simple 2D graphics with vector displays
483\begin{verbatim}
484# Create and initialize two vectors - prevent display : nodisp
485Cmd> newvec vva 100 sin(x/10.+0.7)+cos(x/7.+1.4)*1.26 nodisp
486Cmd> newvec vvb 100 sin(x/10.)+cos(x/7.)*1.34 nodisp
487# Set axe drawing options
488Cmd> setaxesatt 'font=times,bold,16 minorticks tickslen=0.02,0.012'
489# Display the two vectors, with different graphic attributes
490Cmd> disp vva 'red line=solid,2 notitle'
491# Define a title for the graphic
492Cmd> settitle 'Example-1: 2 vectors' ' ' 'font=times,bolditalic,18'
493Cmd> disp vvb 'blue marker=box,7 same'
494# Save the graphic into an eps file
495Cmd> w2eps gr2vec.eps
496\end{verbatim}
497% \begin{figure}[ht!]
498\begin{center}
499\includegraphics[width=12cm]{gr2vec.eps}
500% \label{g22vec}
501\end{center}
502%%%
503\item Creating a comparison chart using {\bf bargraph}
504\begin{verbatim}
505# Representation du PNB (en $, 2003) pour quelques pays
506set pays ( Allemagne Espagne France Italie Pays-Bas Suisse UK USA )
507set pnbh ( 22670 14430 22010 18960 23960 37930 25250 35060 )
508setaxesatt 'font=times,bold,16'
509bargraph pnbh pays - 'blue horizontalbars nofill packfrac=0.65 font=helvetica,bold,14'
510setaxelabels 'PNB / Hab , $ 2003' ' ' 'font=times,bold,16'
511w2eps pnbargraph.eps
512\end{verbatim}
513\begin{center}
514\includegraphics[width=12cm]{pnbbargraph.eps}
515\end{center}
516%%%
517\item Displaying a matrix as a surface
518\begin{verbatim}
519openppf demo.ppf mtx1
520setaxesatt 'font=time,bold,16'
521surf mtx1 'colbr128 line=solid,1 grey'
522w2eps surfcol.eps
523\end{verbatim}
524\begin{center}
525\includegraphics[width=13cm]{surfcol.eps}
526\end{center}
527
528\end{enumerate}
529
530%%%%%%%%%%
531\subsection{Graphic objects in piapp}
532The piapp graphics is handled by the {\bf PI} \footnote {http://www.sophya.org/PI} library,
533which provide a large variety of 2D representations,
534few 3D graphics and powerful image display. \\
535Currently, all graphic representations, except for image displays, are handled
536through {\bf PIDrawers} which are managed by a viewer. A viewer can
537manage several {\bf PIDrawers} objects which correspond then to a multilayer
538graphic display. The viewers are also responsible for managing user
539interactions. \\
540Image displays are handled through a specific viewer
541{\bf PIImage} which is also capable of managing PIDrawer objects
542for multi-layer 2D overlay vector graphics. \\[2mm]
543%%
[3429]544Main piapp/PI graphic viewers, windows and drawer objects are described if
545the following sections.
546
547\subsubsection{PIScDrawWdg (2D display)}
548The {\bf PIScDrawWdg} handles a set of of 2-D drawers, managing
[3043]549the 2D coordinate system and interactive zoom. The axes drawing is
550handled by a specialised drawer, number 0, which also manages various added
551graphic elements (text \ldots). The list of various mouse and
552keyboard actions is described in the reference section, under {\bf PIScDrawWdg} \myppageref{PIScDrawWdg} title. In particular, mouse-button-2 can be used
553to zoom on a particular part, {\tt $<$Alt$>$A} activates the coordinates
554and axes manipulation window ({\bf PIAxesTools}) and {\tt $<$Alt$>$G}
555activates the PIDrawer graphic attributes control window ({\bf PIDrawerTools}).
556%%%
[3429]557\subsubsection{PIDraw3DWdg (3D display)}
558The {\bf PIDraw3DWdg} handles a set of of 3-D drawers, managing
[3043]559interactive camera/object rotation (mouse-button-2) and zoom (mouse-button-2).
560{\tt $<$Alt$>$G} to display/activate the PIDrawer graphic attributes
561control window ({\bf PIDrawerTools}).
562See {\bf PIDraw3DWdg} \myppageref{PIDraw3DWdg} for a complete list of mouse
563and keyboard actions.
564Drawer 0 handles axes drawing and graphic elements.
565%%%
[3429]566\subsubsection{PIImage (Image Display)}
567The display of 2-D arrays $A(i,j)$ as an image is managed by
[3043]568the {\bf PIImage} viewer/widget. The PI library interface {\bf P2DArrayAdapter} is used
569to represent a generic 2-D array. The array values are converted into an index, converted
570itself into a color by the use of a color-map or color-table {\bf PIColorMap}.
571$$ \mathrm{LUT:} A(i,j) \longrightarrow idx(i,j) \hspace{5mm} \mathrm{ColorMap:}
572 idx(i,j) \longrightarrow col(i,j) $$
573Currently index range is 0...255 with color-map having 32 or 128 distinct colors.
574PIImage viewers controls a zoom widget, as well as a global image view widget, and
575a color map view widget. A specific image control window can be activated using
576 {\tt $<$Alt$>$O}. See {\bf PIImage} \myppageref{PIImage} for
[3871]577a complete list of mouse and keyboard actions. A base drawer (number 0) handles
578axes drawing and added graphic elements. The colormap with the LUT information
579can also be displayed through a second drawer (PICMapDrawer). The colormap
580display in the main image window is controlled by the {\tt showcmap} graphic option.
[3043]581%%%
[3429]582\subsubsection{Windows}
[3043]583The viewers described above are displayed in differnt kind of windows.
[3492]584The graphic option {\tt next,win,same,stack,inset} can be used to control the way the
585type of windows used, or the way the object is displayed in the window.
586Graphic windows can be divided into several zones
[3429]587(Command {\bf zone} \myppageref{zone}).
588
589When an object is diplayed in piapp, a widget (PIWdg) is created which manages
590the drawer or the 2d-array. The default name for this widget is the displayed
591object name. However, it is possible to specify a name using the graphic attribute: \\
592\hspace*{5mm} {\tt wname=WidgetName} \\
593It is possible to display multiple objects on a single widget, corresponding
594to the superposition of the different drawers. Displaying an object superimposed
595on the previously displayed object can be done using the graphic option
596{\tt same}. It is also possible to specify a target widget by its name, through
597the graphic option \\
598\hspace*{5mm} {\tt samew=WidgetName} \\
[3492]599It is also possible to specify the display of the drawer in a specific region
600of the last displayed widget using the {\tt inset} option, or
601\hspace*{3mm} {\tt inset=fx1,fx2,fy1,fy2} \\
602where {\tt fx1,fx2,fy1,fy2} express X and Y limits, as fractions of the widget size.
[3429]603
[2172]604Refer to the command reference section on windows ({\bf Windows}
605\myppageref{Windows})
[2171]606for information on the different type of windows used by piapp
[3429]607and their properties. \\
608
[3043]609%%%
[3429]610\subsubsection{Drawers}
611Graphical representation of most objects in piapp is
612handled through objects inheriting from the {\bf PIDrawer class}. A base drawer
[3443]613({\bf PIElDrawer}, number 0) is associated to the three viewers presented above,
614and manages the axes drawing as well as the added graphic elements
615(text, arrow, \ldots). A drawer management menu
[3043]616can be activated using {\tt $<$Alt$>$D}. This menu can be used to move and resize
617drawers, or to display a window for changing drawers graphic attributes.
[3429]618%%%
[2172]619\par
[2171]620In addition, a number of control windows can be used to examine and
621change view properties of differents viewers and drawers.
622\begin{itemize}
[3043]623\item[] {\bf PIDrawerTools} activated using {\tt $<$Alt$>$G} or
624\menubar{Tools/Show DrawerTools} on any viewer (see page \myppageref{secdrwtools})
625\item[] {\bf PIAxesTools} activated using {\tt $<$Alt$>$A} or
626\menubar{Tools/Show AxeTools} on PIScDrawWdg (see page \myppageref{secaxestools})
627\item[] {\bf PIImageTools} activated using {\tt $<$Alt$>$O} or
628\menubar{Tools/Show ImageTools} on PIImage
629(see page \myppageref{secimagetools})
630\item[] {\bf PIHisto2DTools} activated using {\tt $<$Alt$>$O} or through the PIDrawerTools
631for an active PIHisto2D drawer. (see page \myppageref{sech2dtools})
632\item[] {\bf PIContourTools} activated using {\tt $<$Alt$>$O} or through the PIDrawerTools
633for an active PIContourDrawer drawer. (see page \myppageref{secconttools})
[2171]634\end{itemize}
[3043]635These control tools are briefly described in appendix.
[2171]636
[3043]637%%%%%%%%%%
638\subsection{Graphic attributes}
639Graphic attributes are specified as a set of space separated strings. Use
640quotes to group them into a single argument parsed by the command
641interpreter. The options are decoded by the different objects handling the
642graphic (viewer widget, drawer, axe drawer). \\
[3871]643The complex decoding scheme is usually transparent for piapp users.
644However, there is an ambiguity when
[3043]645specifying some of the axes attributes, such as color or the font used for
646drawing the axes. The command {\bf setaxesatt} (\myppageref{setaxesatt})
[3871]647should thus be used to specify generic graphic attributes (color, font, line type) for axes.
648
649\subsection{Complex 2D array display}
650A specific graphic attribute can be specified when displaying 2D arrays
651with complex numbers as their content. By default, the complex arrays are rendered
652using the modulus of the complex
653numbers ($\sqrt{\mathrm{real}(z)^2+\mathrm{imag}(z)^2}$), in particular for
654image and surface display {\tt (disp, imag, surf)}. It is however possible to change
655this behaviour by specifying the following graphic attributes:
656\begin{verbatim}
657cdreal : graphic rendering using the real(z)
658cdimag : graphic rendering using the imaginary part, imag(z)
659cdphase : graphic rendering using the phase, atan2(real,imag)
660cdmod : graphic rendering using the module. this is the defaut.
661cdmod2 : graphic rendering using the module squared (re^2+im^2)
662
663## Consider a complex matrix cmx
664piapp> disp cmx
665# will represent the module(cmx) in grey/color scale
666piapp> disp cmx 'cdphase'
667# will represent the phase(cmx) in grey/color scale
668\end{verbatim}
669
670
[3443]671\subsubsection{PIScDrawWdg}
672The {\bf PIScDrawWdg} which handles 2d graphics recognizes the following options:
[3043]673\begin{verbatim}
674>> To define the 2D axes limits (in user coordinates)
675 xylimits=xmin,xmax,ymin,ymax
676>> To define the default drawing rectangle, in fraction of widget size
677 defdrrect=x1,x2,y1,y2 (default: x1=y1=0.1 x2=y2=0.9)
678>> Axes flags :
[3481]679 linx logx : Linear or logarithmic scale for X Axis
680 liny logy : Linear or logarithmic scale for Y Axis
[3871]681 axerl : Set X axis direction Right to Left (or revax)
682 axeud : Set Y axis direction Up to Down (or revay)
[3481]683 axelr : AxeDirLtoR axedu : AxeDirDownUp
[3043]684>> To change the background color (default=white)
685 wbgcol=colname
686
687\end{verbatim}
688%%%
[3443]689\subsubsection{PIDraw3DWdg}
690The {\bf PIDraw3DWdg} which handles 3d graphics recognizes the following options:
[3043]691\begin{verbatim}
692>> To define the 3D box limits :
693 xyzlimits=xmin,xmax,ymin,ymax,zmin,zmax
694 limit3dbox=xmin,xmax,ymin,ymax,zmin,zmax
695>> Autoscaling flags (rescaling of X/Y or X/Y/Z axes)
696 autoscale3dbox / noautoscale3dbox
697 autoscalexy3dbox / noautoscalexy3dbox
698 autoscalez3dbox / noautoscalez3dbox
699>> To change the background color (default=white)
700 wbgcol=colname
701
702\end{verbatim}
703%%%
[3443]704\subsubsection{PIImage}
705The {\bf PIImage} which handles image display recognizes the following options:
[3043]706\begin{verbatim}
707>> Define display zoomfactor
708 zoomxFact (zoomx2 zoomx3 ... zoomx9 ...)
709 zoom/Fact (zoom/2 zoom/3 ... )
710>> LUT (look-up table) definition (pixel value to index conversion)
[3871]711 lut=type,min,max (type=lin/log/exp/sqrt/square)
712 lut_type=rgb is reserved for true color image display
[3294]713>> AutoLut selector : define the method for automatic determination
714 of LUT limits (min/max)
715 autolut=alt[,ns[,minp,maxp]] (minp<=pixels<=maxp)
716 - autolut=minmax[,Frac] 0<=Frac<=1
717 - autolut=meansig[,ns] --> mean +/- ns*sigma
718 - autolut=hispeak[,ns] --> around the peak of pixel values histogram
719 - autolut=histail[,ns] --> the tail of pixel values histogram
[3457]720 - autolut=hisrng[,Frac[,minp,maxp]] 0<=Frac<=1 --> the central pixel values
[3871]721>> To display the color map with the LUT scale in the main image widget
722 showcmap , showcmap=showcmap=no , showcmap=top
723 showcmap=no/top/right/bottom/left/horiz/vert
[3043]724>> Define color table and reversing color indexing flag
725 ColTableName revcmap
726 ==> Standard tables with 32 distinct colors:
727 grey32 invgrey32 colrj32 colbr32 colrv32
728 ==> Standard tables with 128 distinct colors:
729 grey128 invgrey128 colrj128 colbr128
730 ==> Shades of red/green/blue ...
731 red32cm green32cm blue32cm yellow32cm
732 orange32cm cyan32cm violet32cm
733 ==> Some of MIDAS color tables :
734 midas_pastel midas_heat midas_rainbow3
735 midas_bluered midas_bluewhite midas_stairs8
736 midas_stairs9 midas_staircase midas_color
737 midas_manycol midas_idl14 midas_idl15
[3871]738 ==> Other tables
739 multicol16 multicol64
740 ==> Other tables RGB component color map (lut_type=RGB)
741 rgb216cm rgb512cm rgb4096cm rgb32768cm
[3043]742>> Viewed center position (image/array coordinates)
743 imagecenter=xc,yc
744>> Array axes to window axes mapping flags
745 invx invy exchxy
746>> To change the background color (default=black)
747 wbgcol=colname
748
749\end{verbatim}
750%%%
[3443]751\subsubsection{PIGraphicAtt}
752The {\bf PIGraphicAtt} Generic graphic attributes (color/font/line \ldots)
753decoded by all drawers:
[3043]754\begin{verbatim}
755>>> color=ColorName - fgcolor=ColorName - bgcolor=ColorName
756 ColorName: black white grey red blue green yellow
757 magenta cyan turquoise navyblue orange
758 siennared purple limegreen gold violet
759 violetred blueviolet darkviolet skyblue
760 royalblue forestgreen orangered brown
761>>> line=DashType,LineWidth
762 DashType: solid, dash, dotted, dashdotted Width: 1,2,...
763>>> font=FontName,FontAtt,FontSize
764 FontName: courier, helvetica, times, symbol
765 FontAtt: roman, bold, italic, bolditalic
766 FontSize: 6,8,10,12... (pts) - integer
767>>> marker=MarkerType,MarkerSize (MarkerSize: integer 3,5,7...
768 MarkerType: dot, plus, cross, circle, fcircle, box, fbox
769 triangle, ftriangle, star, fstar
770>>> arrow=ArrowType,ArrowSize (ArrowSize: integer 3,5,7...
771 ArrowType: basic, triangle, ftriangle,
772 arrowshaped, farrowshaped
773>>> ColorTables: defcmap grey32 invgrey32 colrj32 colbr32
774 grey128 invgrey128 colrj128 colbr128
775 red32cm green32cm blue32cm yellow32cm
776 orange32cm cyan32cm violet32cm
777 midas_pastel midas_heat midas_rainbow3 midas_bluered
778 midas_bluewhite midas_redwhite
779 multicol16 multicol64
[3871]780 rgb216cm rgb512cm rgb4096cm rgb32768cm
[3043]781> revcmap : This flag reverses ColorMap indexing
782------- Old style graphic att ----------
783>> Lines: defline normalline thinline thickline dashedline thindashedline
784 thickdashedline dottedline thindottedline thickdottedline
785>> Font Att: deffontatt normalfont boldfont italicfont bolditalicfont
786 smallfont smallboldfont smallitalicfont smallbolditalicfont
787 bigfont bigboldfont bigitalicfont bigbolditalicfont
788 hugefont hugeboldfont hugeitalicfont hugebolditalicfont
789>> Font Names: deffont courierfont helveticafont timesfont symbolfont
790>> Marker: dotmarker<S> plusmarker<S> crossmarker<S> circlemarker <S>
791 fcirclemarker<S> boxmarker<S> fboxmarker<S> trianglemarker<S>
792 ftrianglemarker<S> starmarker<S> fstarmarker<S>
793 with <S> = 1 3 5 7 9 , Example fboxmarker5 , plusmarker9 ...
794
795\end{verbatim}
796%%%%
[3443]797\subsubsection{PIElDrawer}
798The {\bf PIElDrawer} decodes axe drawing attributes:
[3043]799\begin{verbatim}
800 >> Axe and grid configuration flags:
801 axesnone stdaxes defaxes
802 boxaxes boxaxesgrid fineaxes fineaxesgrid
803 centeredaxes finecenteredaxes centeredaxesgrid
804 finecenteredaxesgrid grid/nogrid
805 >> Centered axes position: axescenter=xc,yc
806 >> Axe ticks/labels (h=horizontal/x, v=vertical/y):
807 labels/nolabels hlabels/nohlabels vlabels/novlabels
808 ticks/noticks minorticks/nominorticks
809 extticks/intticks/extintticks nbticks=X_NbTicks,Y_NbTicks
810 tickslen=MajorTickLenFrac,MinorTickLenFraC
[3871]811>> Axe label font size:
[3043]812 autofontsize=FontSizeFrac fixedfontsize
813 >> Up/Down title: title tit notitle notit
814 ... Color/Font/line attributes :
815
816\end{verbatim}
[3443]817The {\bf PINTuple} handles most 2D plotting : \\
[3043]818\begin{verbatim}
819 sta,stat,stats: activate statistic display
820 nsta,nstat,nostat,nostats: deactivate statistic display
821 statposoff=OffsetX,OffsetY : Position offset for Stats drawing
822 as a fraction of total size
823 connectpoints: The points are connected by a line
824 noconnectpoints (this is the default)
825 colorscale/nocolorscale (Use color scale for weight)
826 sizescale/sizescale=nbins/nosizescale (Use marker size for weight)
827 (and usual color/line/marker/... attribute decoding)
828
829\end{verbatim}
830%%%
[3443]831\subsubsection{PIHisto, PIHisto2D}
832{\bf PIHisto} and {\bf PIHisto2D} handle1D and 2D histograms display. \\
833The following options are recognised by {\bf PIHisto}: \\
[3043]834\begin{verbatim}
[3138]835 ---- PIHisto options help info :
[3043]836 sta,stat,stats: activate statistic display
837 nsta,nstat,nostat,nostats: deactivate statistic display
838 err / noerr,nerr : draw, do not draw error bars
839 autoerr : draw error bars if Marker drawing requested OR Profile histo
840 fill / nofill,nfill : fill, do not fill bars with selected color
841 statposoff=OffsetX,OffsetY : Position offset for Stats drawing
842 as a fraction of total size
[3151]843 ---- HistoWrapper options :
844 hbincont: select bin content as Y value for display (default)
845 hbinerr: select bin error as Y value for display
846 hbinent: select bin entries as Y value for display
847 hscale=value : multiplicative factor for Y value
848 hoffset=value : additive coefficient for Y value
849 hs1: set hscale=1 hoffset=0 (default)
850 hscale=value : multiplicative factor (in Y)
[3138]851
[3043]852\end{verbatim}
[3443]853The following options are recognised by {\bf PIHisto2D}: \\
[3043]854\begin{verbatim}
855- sta,stat,stats: activate statistic display
856 nsta,nstat,nostat,nostats: deactivate statistic display
857- h2disp=typ[,fracpts]: choose display type
858 typ=var: variable size boxes
859 typ=hbk: "a la hbook2"
860 typ=img: image like (use "h2col" for color map)
861 typ=pts: point clouds (fracpts=max possible fraction
862 of used pixels per bin [0,1])
863- h2scale=lin/log[,logscale]: choose linear or logarithmic scale
864- h2dyn=[hmin][,hmax]: choose histogramme range for display
865- use general key to define color table (ex: grey32,midas_heat,...)
866 (see general graphicatt description)
867- use key "revcmap" to reverse color table
868- h2frac=[fmin][,fmax]: choose sub-range display [0,1]
[3151]869 ---- HistoWrapper options : (see HistoWrapper above)
[3043]870
871\end{verbatim}
872%%%%
[3443]873\subsubsection{PINTuple3D , PISurfaceDrawer}
874The {\bf PINTuple3D} and {\bf PISurfaceDrawer}
875handles basic 3D plotting and can decode the common 3D box options:
[3043]876\begin{verbatim}
877 X/Y,Z axis rescaling option (-> cubic 3D box)
878 rescale=autoscale/ norescale=noautoscale : X/Y and Z axis
879 rescalexy=autoscalexy / norescalexy=noautoscalexy : X/Y axis
880 rescalexy=autoscalexy / norescalexy=noautoscalexy : Z axis
881\end{verbatim}
[3443]882The {\bf PINTuple3D} decodes in addition the following options:
[3043]883\begin{verbatim}
884 connectpoints: The points are connected by a line
885 noconnectpoints (this is the default)
886 colorscale/nocolorscale (Use color scale for weight)
887 sizescale/sizescale=nbins/nosizescale (Use marker size for weight)
888
889\end{verbatim}
[3443]890
891\subsubsection{PIContourDrawer}
892The {\bf PIContourDrawer} decodes the following options : \\
[3429]893\begin{verbatim}
894 autolevels : automatic selection of levels and number of contours
895 ncont=nLevel (or nc=NLevel) : sets the number of contour
896 lev=v1,v2,v3... (or niv=v1,v2,v3...) set the number and levels of contours
897 lstep=nLev,start,step : define incremental levels
898 labon/laboff : display of contour level values on/off
899 linear/bspline/cubicspl=3spl : select contour kind
900
901\end{verbatim}
902
[3443]903\subsubsection{PIBarGraph , PITextDrawer}
904{\bf PIBarGraph} is used by the {\tt bargraph} \myppageref{bargraph}
905command and has the following graphic options:
[3043]906\begin{verbatim}
907 ---- PIBarGraph options help info :
908 fill/nofill: set bar fill option
909 horizontalbars/verticalbars: set bar orientation
910 packfrac=value : set bar packing fraction (0..1)
911 barvaluelabel/nobarvaluelabel: Use/Don't use bar value as labels
912 --- + Usual colr/line/font attribute decoding ...
913 \end{verbatim}
[3443]914The command {\tt textdrawer} \myppageref{textdrawer} uses the
915{\bf PITextDrawer} which has the following options : \\
916\hspace*{10mm} {\tt frame,noframe: enable/disable frame drawing}
[3043]917
918
[3041]919%%%%%%%%%%%%%%% Section 4 : I/O
920\newpage
[3302]921\section{Data formats and input-output (I/O)}
922The data file formats recognized by piapp are the ones supported by the
923SOPHYA library or its extension.
[3041]924\begin{itemize}
[3302]925\item[\bul] ASCII files - Data can be imported from ascii (text) files as
926datatables or arrays. These objects can also be exported as text files.
927\item[\bul] FITS files - FITS is a popular format used in particular in astronomy.
928\href{http://heasarc.gsfc.nasa.gov/docs/software/fitsio/fitsio.html}
929Data is usually read from FITS files as vectors, images, cubes or tables.
[3442]930A subset of SOPHYA objects can be imported or exported in FITS format.
[3302]931\item[\bul] PPF (Portable Persistence file Format) is the native SOPHYA
932data format.
933\item[\bul] PostScript - All graphic output produced by piapp can be exported
934as postscript (.ps) or encapsulated postscript (.eps) files.
935\end{itemize}
936
[3429]937\subsection{Text files}
938Text (or ascii) files can be read into array or datatable objects by spiapp.
939
940{\bf Arrays :} \\
941Arrays can be written to to files in text/ascii format using the {\tt arrtoascii}
942 \myppageref{arrtoascii} command. Double precision matrices and vectors
943 can be read from text files using the commands
944 {\tt mtxfrascii} \myppageref{mtxfrascii} and
945 {\tt vecfrascii} \myppageref{vecfrascii} . \\
946The menu-bar command \menubar{File/Open-ASCII} reads in a text
947file as a matrix.
948\begin{verbatim}
949# Create and initialize a matrix
950newmtx arr 250 150 x+3*y
951# Save the file in the text file arr.txt
952arrtoascii arr arr.txt
953# Read the previously created file and fill a matrix
954mtxfrascii mxa arr.txt
955# Print and display the matrix
956print mxa
957disp mxa zoomx2
958\end{verbatim}
959It is possible to specify the field separator in the input file, as well as the marker for the comment
960lines.
961
962{\bf DataTable :} \\
963Text files can also be read as a 2-D table (NTuple or DataTable). The table should be
964created using the {\tt newnt} \myppageref{newnt} or
965{\tt newdt} \myppageref{newdt} command.
966The command {\tt ntfrascii} \myppageref{ntfrascii} can then be used to append
967data from the file to the datatable.
968
969\subsection{PPF}
970%%%
971PPF (Portable Persistence file Format) is the the native persistence
972format of SOPHYA and thus is fully handled by spiapp. PPF files can
973be opened through the menu-bar \menubar{File/Open-PPF}, or through
974the {\tt openppf} \myppageref{openppf}.
975
976If the PPF file contains NameTags, only the objects marked with nametags are read and given
977the corresponding names. Otherwise, all objects are red sequentially, with their names
978formed by the filename followed by a sequence number. It is also possible to force the sequential
979reading specifying the {\tt -s} flag for openppf.
980
981The objects managed in spiapp by the {\bf NamedObjMgr} can be saved to PPF files, with their
982names as NameTags. The commands {\tt saveppf} \myppageref{saveppf} or
983 {\tt saveall} \myppageref{saveall} can be used to this end.
984
985\begin{verbatim}
986# Create two vectors and two matrices
987newvec va1 150 sin(sqrt(x))
988newvec vb2 150 sin(sqrt(x))*sqrt(x*0.1)
989newmtx mxa 250 150 x+2.*y
990newmtx mxb 250 150 sin(sqrt(x))*cos(sqrt(y))
991# List of the objects in memory
992listobjs
993# Save the two vectors in the file vecab.ppf
994saveppf v* vecab.ppf
995# Save the two matrices in the file mxab.ppf
996saveppf m* mxab.ppf
997\end{verbatim}
998
999\subsection{FITS}
1000FITS files may contain three types of data structures
1001\begin{enumerate}
1002\item Image or array data structure : {\tt IMAGE\_HDU}
1003\item Binary table : {\tt BINARY\_TBL}
1004\item ascii table : {\tt ASCII\_TBL}
1005\end{enumerate}
1006The {\bf FitsIOServer} module contain FitsHandler classes which
1007can map many SOPHYA classes on FITS data structures.
1008Generic {\tt IMAGE\_HDU} correspond to the SOPHYA \tcls{TArray}
1009class, while {\tt BINARY\_TBL} or {\tt ASCII\_TBL} is mapped
1010to NTuple or DataTable.
1011
1012FITS format files can be read through the menu command \menubar{File/Open-Fits},
[3871]1013or using {\tt readfits/openfits} \myppageref{readfits} command. The command
1014{\tt rdfitsarr} \myppageref{rdfitsarr} offer additional possibilities for reading
1015arrays from FITS IMAGE\_HDU, for example array type conversion.
[3429]1016Objects can be exported to FITS using the {\tt writefits/savefits}
1017\myppageref{writefits} command.
1018
1019\begin{verbatim}
1020# Open the PPF file created by the commands above
1021openppf vecab.ppf
1022# Export the two vector objects to file vecab.fits
1023# Note that the '!' forces c-fitsio to overwrite the file, if it exists
1024writefits v?? !vecab.fits
1025\end{verbatim}
1026
[3437]1027There are two commands useful
1028when analyzing large catalogs (BINARY\_TBL) in FITS format, which avoid reading the whole
1029table in memory. {\tt swfitstable}\myppageref{swfitstable} reads a specified HDU
1030as a {\bf SwFitsDataTable} object which uses the FITS file as swap space.
1031The {\tt fitsadapt}\myppageref{fitsadapt} can also be used for similar purposes.
1032
1033The following commands shows how to open a FITS file containing a synchrotron map
[3442]1034of our galaxy. This file contains sky emission at 408 MHz,
1035as brightness temperature, represented as a SOPHYA spherical map
1036(SphereHEALPix$<$r\_4$>$) in \href{http://healpix.jpl.nasa.gov/}{\bf HEALPix}
1037format \footnote{HEALPix home page: \hspace{5mm} http://healpix.jpl.nasa.gov/}.
1038It has been made, by rebinning, from the Haslam 408 MHz
[3439]1039all sky survey map, available from the NASA CMB data repository
[3442]1040\href{http://lambda.gsfc.nasa.gov/}{\bf LAMBDA}
1041\footnote{LAMBDA web site: \hspace{5mm} http://lambda.gsfc.nasa.gov/}.
1042\label{syncmap}
[3437]1043\begin{verbatim}
1044# Open the fits file : the map is in HEALPix format
1045readfits syncmap.fits
1046# Create a window with the appropriate size
1047newwin 1 1 800 400
1048# Display the map, specifying the colormap
1049disp syncmap 'lut=lin,2,50 midas_bluered'
1050\end{verbatim}
1051\begin{figure}[h]
1052\begin{center}
1053\includegraphics[width=15cm]{syncmap.eps}
[3442]1054\caption{Synchron map of our Galaxy, displayed in Molleweide projection.
1055The underlying SOPHYA object is a \tcls{SphereHEALPix} }
[3437]1056\end{center}
1057\end{figure}
1058
[3302]1059\subsection{Graphic export in postscript}
[3429]1060%%
1061Postscript a page description language widely used for printing and
1062graphic output, developed by Adobe systems. Refer to
1063\href{http://www.adobe.com/products/postscript/}{Adobe/PostScript3}
1064for more detail.
[2171]1065
[3429]1066Piapp graphic output can be exported in postscript (level 2) or
[3442]1067encapsulated postscript format, preserving the full precision
1068of vector graphics.
[3429]1069Postscript (.ps) files my contain several pages, each vue or window
1070corresponding to one page and are suitable for direct printing.
1071An Encapsulated Postscript (.eps) file contains a single page,
1072corresponding to a window and is suitable for inclusion in
1073other document.
1074
1075Postscript file can easily be converted to other formats,
1076PDF or image formats (jpeg \ldots) using converters like
[3442]1077{\bf ps2pdf} or {\bf imagemagick}.
[3429]1078
1079The menu items under \menubar{PostScript} can be used to export
1080graphics in postscript. The default file name is {\tt pia.ps}
1081or {\tt pia1.eps} {\tt pia2.eps} \ldots
1082The following commands can also be used to create postscriot file
1083from the display in the current graphic window:
1084\begin{itemize}
1085\item {\tt w2ps} \myppageref{w2ps} to add the current graphic
1086output as a new page to the output postscript file.
1087The current output postscript file (default = w2ps.ps)
1088should be closed before being used. Exiting piapp closes automatically
1089all postscript files.
1090\item {\tt psclosefile} \myppageref{psclosefile} to close the current
1091output postscript file.
1092\item {\tt pssetfilename} \myppageref{pssetfilename} To define
1093the output postscript file name for the subsequent {\tt w2ps} commands.
1094\item {\tt w2eps} \myppageref{w2eps} to export the current
1095graphic display, in Encapsulated Postscript format to the specified file.
1096\begin{verbatim}
1097# Open the PPF file created by the commands above
1098openppf vecab.ppf
1099# Display one of the vectors
1100setaxesatt 'font=helvetica,bold,18 fixedfontsize'
1101disp va1 'blue marker=box,5'
1102# Export the graphic to file va1.eps
1103w2eps va1.eps
1104# The created file can be viewed using gv
1105\end{verbatim}
1106\end{itemize}
1107
[3871]1108\subsection{RGB pixel files}
1109Graphics displayed in piapp windows and widgets (in PIImage, PIScDrawWdg, PIDraw3DWdg)
1110can be exported in a PI-specific image format coding the RGB (Red/Green/Blue) intensities
1111of each pixel. The commands {\tt wdg2rgb} \myppageref{ wdg2rgb } and
1112 {\tt wdg2rgb} \myppageref{ win2rgb } can be used to export graphics to PI-RGB
1113files. The content of PI-RGB files can be read back and displayed using the
1114command {\tt pirgbdisp} \myppageref{pirgbdisp}.
1115It is also possible to compute RGB images and save in this format, for example
1116for creating a false color composite image, from a set of intensity coded images
1117in three wavebands. Check the class {\bf PIPixRGBArray} in the file (PI/pipixutils.h) for
1118more information on PI-RGB format.
1119
1120The {\bf PIPhoto} add-on package can be used to convert PI-RGB images to/from
1121standard image formats (gif, jpeg \ldots). The {\bf PIPhoto} module uses the
1122ImageMagick libraries. It contains also a piapp loadable module which extends
1123the piapp possibilities through a set of commands for reading, writing and
1124manipulating standard image formats in piapp.
1125
1126
1127
1128
[3041]1129%%%%%%%%%%%%%%% Section 5 : analyse a la paw
[2171]1130\newpage
[3438]1131\section{Tables and Expression Plotting}
[3043]1132\label{tableplot}
[3438]1133A powerful data analysis technic available in piapp is
11342D, 3D plot, and histogramming applied to arbitrary analytical
1135expression of table columns.
1136This analysis technic has been introduced by the popular
1137CERN \href{http://paw.web.cern.ch/paw/}{\bf PAW}
1138({\bf P}hysics {\bf A}nalysis {\bf Workstation})
1139\footnote{PAW home page : http://paw.web.cern.ch/paw/ } program
1140and the underlying HBOOK fortran library.
1141Compared to PAW, piapp extends in many respects this capability,
1142piapp offers in particular the possibility to manipulate many
1143objects as if they where a DataTable, or NTuple.
1144There are also additional 2D and 3D representations e.g.
1145{\tt plot2de} \myppageref{plot2de},
1146{\tt plot2dw} \myppageref{plot2dw},
1147{\tt plot2dc} \myppageref{plot2dc} and
1148{\tt plot3dw} \myppageref{plot3dw}.
[3041]1149
[3438]1150\subsection{How does it work ?}
1151
1152The Expression.Plotting commands in piapp operate on objects through the
1153{\bf NTupleInterface} class methods. Some classes like NTuple or BaseDataTable
1154inherit from NTupleInterface, while for the other classes, the corresponding
1155NObjMgrAdapter class exposes an object conforming to NTupleInterface through the
1156method : \\
1157\hspace*{5mm} {\tt NTupleInterface* NObjMgrAdapter::GetNTupleInterface()} \\
1158A C file (PIATmp\_xxx/expf\_pia\_dl.c) is created by piapp containing the
1159specified expressions, which should conform to the C-language syntax.
1160In addition to the functions in {\tt math.h} (sin, cos, log \ldots),
1161the following functions are defined by piapp and can be used:
1162\begin{itemize}
1163\item Flat random number generators: {\tt drand01() , drandpm1() }
1164\item Gaussian random number generator: {\tt GauRand() }
1165\item Angle conversion: {\tt deg2rad(double d), rad2deg(double r) }
1166\item $(\theta,\varphi)$ to Molleweide X,Y projection: \\
1167\hspace*{5mm}{\tt double tetphi2mollX(double theta, double phi)} \\
1168\hspace*{5mm}{\tt double tetphi2mollY(double theta)}
1169\item Longitude(0..360) deg., Latitude(-90..90) deg. conversion to Molleweide X,Y: \\
1170\hspace*{5mm}{\tt double longlat2mollX(double longit, double lat) } \\
1171\hspace*{5mm}{\tt double longlat2mollY(double lat) }
1172\end{itemize}
1173
1174The processing steps for an Expression.Plotting in piapp :
1175\begin{enumerate}
1176\item Creation of the C-file.
1177\item On the fly compilation of the generated file.
1178\item The resulting shared-object is loaded and linked with the application
1179\item Loop over the NTupleInterface object rows. The created function is called
1180with the data from each row
1181\item The return values are used to fill an histogram, or a matrix/vector or
1182another NTuple or to produce a 2D or 3D graphic display.
1183\end{enumerate}
1184
1185Although rather complex, the efficiency gain during processing data easily compensates
1186for the overhead of the compilation step.
1187
1188\subsection{Column/variable names}
1189
1190When working with real 2-D tables (NTuple, DataTable \ldots), the column names
1191are the name of the variables which can be used in the C-expressions.
1192There is an additional variable, called {\tt \_nl}, automatically
1193provided by piapp, corresponding the table row number, starting from 0.
1194
1195For the other objects in piapp, the variable names are listed below:
1196\begin{itemize}
1197\item[\rond] For 2D table objects {\bf (NTuple,DataTable,\ldots)}: ColumnNames,\_nl
1198\item[\rond] For FITS files opened through {\tt fitsadapt} command: FITSColumnNames,\_nl
1199\item[\rond] For {\bf Histo1D/HProf} objects : i,x,val,err,nb,\_nl
1200\item[\rond] For {\bf Histo2D} objects : i,j,x,y,val,err,\_nl
1201\item[\rond] For {\bf HistoErr} objects : i,x,val,err2,nb,\_nl
1202\item[\rond] For {\bf Histo2DErr} objects : i,j,x,y,val,err2,nb,\_nl
1203\item[\rond] For {\bf \tcls{TVector}, \tcls{TMatrix} , \tcls{Image} } objects : \\
1204 \hspace*{10mm} n,r,c,val,real,imag,mod,phas,\_nl
1205\item[\rond] For {\bf \tcls{TArray}} objects : n,x,y,z,t,u,val,real,imag,mod,phas,\_nl
1206\item[\rond] For {\bf GeneralFitData} objects : x0,ex0 x1,ex1 ... xn,exn y,ey ,ok,\_nl
1207\item[\rond] For {\bf \tcls{SphereHEALPix} , \tcls{SphereThetaPhi} , \tcls{SphereECP}
1208\tcls{LocalMap} } objects : \hspace{10mm} i,k,val,real,imag,mod,phas,teta,phi,\_nl
1209\end{itemize}
1210
[3439]1211%%%%%
1212\subsection{Examples}
1213The following examples illustrates the use of some Expression Plotting commands
1214(see the command groups {\bf Expr. Plotting} \myppageref{ExprZZPlotting} and
1215 {\bf pawCmd} \myppageref{pawCmd}).
1216The {\bf pawCmd} defines a number of operations with command name and syntax
1217similar to the CERN PAW program.
1218The graphic output from the examples below are shown in the figures
1219\ref{exhis2dpl} and \ref{uzcpos}.
1220\begin{enumerate}
1221\item 2D plot with error bars \\[1mm]
1222\begin{verbatim}
1223# Set the axes attibute (the font used for axes ...)
1224setaxesatt 'font=helvetica,bold,16 minorticks fixedfontsize'
1225# Open the file demo.ppf (in DemoPIApp)
1226openppf demo.ppf
1227print nt21
1228print nt22
1229# 2D plot directly from the NTuple columns (nt2d)
1230# nt2d DO NOT use a compiled c file
1231nt2d nt21 x y - - - - 'font=helvetica,bold,16'
1232# Overlay a plot with scaled error bars from nt22
1233plot2de nt22 x y ex*0.3 ey*0.5 1 \
1234 'same marker=box,7 red font=helvetica,bold,16 '
1235\end{verbatim}
1236\vspace*{4mm}
[3442]1237\item Compute the histogram of pixel values for a \tcls{SphreHEALPix}.
1238The data come from the synchrotron map (syncmap.fits), described page \pageref{syncmap}.
[3439]1239\begin{verbatim}
[3442]1240# Open the synchrotron map file (HEALPix format spherical map)
[3439]1241# The file can be found in directory DemoData/
1242readfits syncmap.fits
[3442]1243newwin 1 1 800 400
1244disp syncmap 'lut=lin,2,50 midas_bluered'
1245newwin 1 2
[3439]1246# Compute and display the pixel value histogram (brightness temperature)
[3442]1247n/plot syncmap.val val<200 ! ! 'font=helvetica,bold,16 notit'
[3439]1248settitle 'Sky brightness @ 408 MHz' ' ' 'font=helvetica,bold,16'
[3442]1249# display the pixel value histogram in the galactic plane
1250n/plot syncmap.val val<200&&(fabs(teta-M_PI/2)<0.025) ! ! 'red notit'
1251settitle '408 MHz - Galactic plane' ' ' 'font=helvetica,bold,16 red'
[3439]1252\end{verbatim}
1253\vspace*{4mm}
1254\item Sources (galaxies) distribution over the sky. The data used below (uzc.ppf)
1255has been extracted from the {\bf U}pdated {\bf Z}wicky {\bf C}atalog of Galaxies,
1256available from the Harvard-Smithsonian Center For Astrophysics
1257\href{http://tdc-www.harvard.edu/uzc/}{CfA/UZC web site}.
1258\footnote{CfA web site: \hspace{5mm} http://tdc-www.harvard.edu/uzc/} \\[1mm]
1259%%%
1260\begin{verbatim}
1261# Keep the synchrotron map
1262# Open the Updated Zwicky Catalog of galaxies (in DemoData)
1263openppf uzc.ppf
1264zone 1 2
1265# Draw a longitude-latitude grid in Molleweide projection
[3442]1266mollgrid 5 7 'axesnone black font=helvetica,roman,12 notit'
[3439]1267# Overlay the sources distribution from UZC, for bright objects (mag<14)
1268plot2d uzc longlat2mollX(ra*15,dec) longlat2mollY(dec) mag<14 \
1269 'same red marker=circle,5'
1270# Change the plot title
1271settitle 'RA-Dec in degrees UZC (Updated Zwicky Catalog)' ' ' \
1272 'font=helvetica,bold,16 red'
1273# Display the synchrotron map
1274disp syncmap 'lut=lin,2,40 grey128'
1275# Add the source distribution in Galactic coordinates
1276plot2d uzc longlat2mollX(glong,glat) longlat2mollY(glat) mag<14 \
1277 'same nsta red marker=circle,5'
1278\end{verbatim}
[3442]1279%%%%%%%%%%%%%%%%
1280%%%%%%%%%%%%%%%%
1281\item Analysis of elevation (altitude) data for france. We use the francetopo.ppf
1282data set described page \pageref{francetopo}.
1283\begin{verbatim}
1284# open and display the topographic data for france
1285openppf francetopo.ppf (in DemoData/ directory)
1286print francetoto
1287#--- TMatrix<s>(NRows=1332, NCols=1548) ND=2 SizeX*Y*...= 1548x1332 ---
1288disp francetopo 'zoom/2 imagecenter=750,700 lut=lin,-700,800 colbr128'
1289# Compute the altitude distribution
1290newh1d altf 0. 4000 100
1291projh1d altf francetopo val val>0.1
1292# Display the histogram overlayed on the topographic map
1293disp altf 'white line=solid,2 font=helvetica,bold,14 inset=0.1,0.6,0.45,0.9'
1294# Compute altitude distribution for the massif central (Auvergne)
1295newh1d altmc 0. 2000 100
1296# We select the region as a circle of radius 200, centered on x=c=970,y=r=920
1297set regcut (sqrt((c-970)*(c-970)+(r-920)*(r-920))<200)
1298projh1d altmc francetopo val (val>0.1)&&$regcut
1299# Create a new window and display the two histograms
1300newwin 1 2
1301setaxesatt 'font=helvetica,bold,16 fixedfontsize'
1302disp altf 'notit'
1303settitle 'Elevation (altitude) distribution over France' ' ' \
1304 'font=helvetica,bold,16'
1305disp altmc 'notit'
1306settitle 'Elevation (altitude) distribution over MassifCentral' ' ' \
1307 'font=helvetica,bold,16'
1308\end{verbatim}
[3439]1309\end{enumerate}
1310
[3442]1311\begin{figure}[hp]
[3439]1312\includegraphics[width=15cm]{exhis2dpl.eps}
1313\caption{
1314top: 2d plot example with error bars \hspace{5mm}
1315bottom: Histogram of pixel values from the synchrotron map
1316of our galaxy}
1317\label{exhis2dpl}
1318\end{figure}
1319
1320\begin{figure}[p]
1321\includegraphics[width=15cm]{uzcpos.eps}
1322\caption{UZC: Updated Zwicky Catalog. \hspace{5mm}
1323top: The galaxy position distribution in equatorial
1324$(\alpha, \delta)$ coordinates. \hspace{5mm}
1325bottom: Position distribution in Galactic coordinates, superimposed on
1326the synchrotron map.}
1327\label{uzcpos}
1328\end{figure}
1329
[3041]1330%%%%%%%%%%%%%%% Section 6 : command interpreter
1331\newpage
1332\section{Command interpreter}
1333piapp uses the class {\bf PIACmd} which extends slightly the
1334SOPHYA class {\bf Commander} as the command interpreter.
1335{\bf Commander} is a c-shell inspired, string oriented command
1336interpreter. Although it has many limitations compared to
1337c-shell, or Tcl , it provides some interesting possibilities:
1338\begin{itemize}
1339\item Extended arithmetic operations (c-like and RPN)
1340\item Simple and vector variables
1341\item Script definition
1342\item Command execution in separate threads
1343\item Dynamic Load
1344\end{itemize}
1345
1346We describe below the {\bf Commander} possibilities,
1347as well as the few {\bf PIACmd} extensions.
1348
1349\subsection{Variables}
1350The SOPHYA::Commander interpreter manages non typed set of variables.
1351Environment variables are also accessible through
1352the usual {\tt \$varenvname}, unless shadowed by a Commander
1353variable. All Commander variables are vector of strings, and are
1354extended as necessary. {\tt \$varname} is the string formed by all
1355the vector elements. Except when performing arithmetic operations,
1356variables are treated as strings.
1357\par
1358An application level set of variables is also managed
1359by Commander, through redefinition of \\
[3043]1360{\tt Commander::GetVarApp() / GetVarApp() \ldots } methods. \\
[3041]1361The {\bf PIACmd} in piapp redefines the {\tt GetVarApp() }
1362in order to provide an easy access to some of objects attributes or methods,
[3043]1363managed by {\bf NamedObjMgr} (See below).
[3041]1364
[3438]1365\subsubsection{Interpreter/Commander variables}
[3041]1366\begin{itemize}
1367\item[\rond] {\bf Definition and initialisation of variables }
1368\begin{verbatim}
1369# Notice that the set command has no = sign
1370Cmd> set sv StringValue
1371# Clearing/removing of a variable : unset or clearvar
1372Cmd> unset sv
1373
1374# Definition of a multi element variable (vector type)
1375# Notice that spaces before / after '(' and ')' are mandatory
1376Cmd> set vecv ( mot1 mot2 mot3 mot4 mot5 )
[3429]1377# Arithmetic expression : C language syntax - spaces
1378# before/after '=' are mandatory
[3046]1379Cmd> a = 2+3*sqrt(4)
[3041]1380# The '=' operator can also be used to initialize a variable with a string
1381Cmd> a = 'Bonjour Madame'
1382# A vector element can be specified in the left hand side
1383Cmd> vecv[2] = 'coucou'
1384# Or using an interpreter variable as index :
1385Cmd> i = 3
1386Cmd> vecv[i] = 'Ooohhh'
1387\end{verbatim}
1388
1389On the right hand side, the value of a variable should be accessed using
1390the \$ character. \\
1391A string can be parsed into words using {\tt var2words}
1392\begin{verbatim}
1393Cmd> var2words varname wordvarname [separateur]
1394\end{verbatim}
1395
1396\item[\rond] {\bf Accessing variable contents } \\
1397The \$ character is used to access the content of a variable {\tt \$varname} .
1398Substitution rules :
1399The {\tt \$xxx} is replaced by the value of variable xxx.
1400No substitution is performed for strings enclosed in simple quotes {\tt ' ... \$xxx '},
1401but substitution is done in strings enclosed in double quotes.
1402Parenthesis or brackets can be used to specify the variable name, inside a string
1403without white space: {\tt \${vname} } ou {\tt \$(vname)}.
1404\begin{verbatim}
1405Cmd> x = 'Hello'
1406Cmd> echo $x
1407# Size of a vector variable : $#vname
1408Cmd> set vx ( 111 2222 3333 444444 )
1409Cmd> echo $#vx
1410# Accessing vector elements
1411Cmd> echo $vx[0] $vx[1]
1412# or using an interpreter variable as index :
1413Cmd> i = 2
1414Cmd> echo $vx[i]
1415# Special syntax: $[vname] is replaced by the content
1416# of a variable whose name is $vname
1417Cmd> zzz = 'Commander'
1418Cmd> xxx = 'zzz'
1419Cmd> echo '---> $[xxx]= ' $[xxx]
1420---> $[xxx]= Commander
1421\end{verbatim}
1422
1423\par
[3438]1424\end{itemize}
[3041]1425
[3438]1426\subsubsection{Special variables}
[3041]1427\begin{itemize}
1428\item {\tt \$retval} ou {\tt \$retstr} : the string specified in the last {\bf return} statement
1429\item {\tt \$status} : Return code from the last executed command.
1430Arguments of scripts (see below) or file executed through {\bf exec} command.
1431\item {\tt \$\# } : number of arguments, except \$0
1432\item {\tt \$0} : Script or file name
1433\item {\tt \$1 \$2 \$3} .... : Arguments (for scripts and .pic files (exec))
1434\end{itemize}
[3043]1435
[3438]1436\subsubsection{Environment variables}
1437Environment variables can simply be accessed by {\tt \$varenvname}.
1438However, the environment variables have the lowest priority during substitution.
1439Interpreter's variables have the highest priority, followed
1440by the application level variables.
1441
1442\subsubsection{Objects/Application level variables}
[3043]1443For some classes managed by NamedObjMgr,
1444PIACmd provide acces to some of the attributes of the object by
1445{\tt \${objname.attname} }. This mechanism has been implemented in particular for
1446TArrays, TMatrix/TVector, Histograms, NTuples and DataTables.
1447In addition, when brackets are used ($\${vname}$), the priority level between interpreter variables
1448and application level variable is changed. If {\tt vname} exist at the application level,
1449{\tt \${vname} } is replaced by its value, even if an interpreter variable with the
1450same name has been defined.
[3438]1451\begin{itemize}
1452\item[\rond] Accessing object attributes
[3043]1453\begin{verbatim}
1454# -------- Example with a Vector
1455piapp[1] newvec va 12
1456piapp[2] echo $va
1457TVector<d>(12) (nr=12, nc=1)
1458# ------- An undefined attribute, such as ? might be
1459# used to get list of valid attributes
1460piapp[3] echo ${va.?}
[3438]1461TMatrix.Att: rank size/nelts nrow/nrows ncol/ncols sum sumsq norm min ...
[3429]1462# Compound names, in the form name.att must be inclosed in
1463# braces {name.att}
[3043]1464piapp[4] echo ${va.size}
146512
1466# -------- Example with an histogram
1467piapp[8] newh1d his 0. 20. 40
1468piapp[10] echo ${his.?}
1469Histo1D: nbin binw mean sigma over under nentries ndata
1470 xmin xmax vmin vmax imin imax
1471piapp[11] echo ${his.nbin}
147240
1473\end{verbatim}
1474
[3438]1475\item[\rond] Accessing object.Info() \\
1476For objects having an DVList Info() object (TArray/TVector/TMatrix , NTuple, DataTable, SwPPFDataTable, it is possible to access DVList members by the corresponding names : \\
1477\hspace*{10mm} {\tt \$\{objName.info.varName\} }
1478\item[\rond] Getting DataTable rows \\
1479For NTuple and BaseDataTable objects (DataTable, SwPPFDataTable, SwFitsDataTable), it is
1480possible to get a string representation of a given row, by specifying
1481\$\{tableName.row\} followed by the row number (starting from 0) : \\
1482\hspace*{10mm} {\tt \$\{tableName.row.num\} }
1483\end{itemize}
[3043]1484
[3041]1485
[3043]1486
[3041]1487\subsection{Control structures}
1488
1489\begin{itemize}
1490\item[\rond] Enumerated loop:
1491\begin{verbatim}
1492foreach f ( w1 w2 w3 ... )
1493 ...
1494 echo $f
1495end
1496\end{verbatim}
1497
1498Note that spaces before/after '(' et and ')' are mandatory.
1499An alternative form uses a vector variable name :
1500\begin{verbatim}
1501foreach v vecname
1502 ...
1503 echo $v
1504end
1505\end{verbatim}
1506
1507\item[\rond] Integer type loop:
1508\begin{verbatim}
1509for i startInt:endInt[:stepInt]
1510 ....
1511 echo $i
1512end
1513\end{verbatim}
1514
1515\item[\rond] Integer type loop:
1516\begin{verbatim}
1517for f startFloat:endFloat[:stepFloat]
1518 ....
1519 echo $f
1520end
1521\end{verbatim}
1522
1523\item[\rond] Loop over lines of a file
1524\begin{verbatim}
1525forinfile line FileName
1526 ...
1527 echo $line
1528end
1529\end{verbatim}
1530
1531\item[\rond] The {\tt break} instruction can be used to exit from a loop
1532
1533\item[\rond] {\bf if then else} Conditional execution:
1534\begin{verbatim}
1535if ( test ) then
1536endif
1537
1538if ( test ) then
1539 ....
1540else
1541 ....
1542endif
1543\end{verbatim}
1544Note that spaces before/after '(' et and ')' are mandatory.
1545
1546test is in the form {\tt a == b} OR {\tt a != b} OR {\tt a < b} OR {\tt a > b}
1547OR {\tt a <= b} OR {\tt a >= b}. Comparison operators should be delimited
1548by spaces.
1549{\tt ==} et {\tt !=} make a string comparison, while
1550{\tt < , > , <= , >=} compare the values obtained after string to double conversion.
1551\end{itemize}
1552
1553\subsection{Script definition}
1554A script is a sequence of commands. It is very similar to the execution of commands
1555from a file ({\bf exec filename}). Once a script has been defined, it can be called specifying
1556specifying the script name followed by its arguments.
1557\begin{verbatim}
1558# Script definition :
1559defscript scriptname [description ]
1560 ....
1561endscript
1562
1563# Executing the script
1564Cmd> scriptname arg1 arg2 arg3 ....
1565\end{verbatim}
1566
1567The {\tt return} instruction stops the execution and returns from a script, or from a command
1568file called through {\bf exec}. \\
1569The commands {\bf listscript } and {\bf clearscript scriptname} can be used
1570to obtain the list of already defined script, or to clear a script definition.
1571
1572\subsection{Other built-in commands}
1573\begin{itemize}
1574\item[\rond] Instruction {\bf echo } to write the line to cout/stdout
1575\item[\rond] Instruction {\bf echo2file} to write (append) the line to file ({\tt echo2file filename ....})
1576\item[\rond] Instruction {\bf sleep nsec} wait for {\tt nsec} seconds
1577\item[\rond] Instructions {\bf timingon , timingoff , traceon , traceoff } \\
1578%
1579\item[\rond] {\bf exec filename [arg1 arg2 ... ] } to execute command from
1580the file named {\tt filename}. {\tt .pic} is the default extension for the interpreter
1581command files.
1582\item[\rond] {\bf help} and {help keyword/commandname }
1583\item[\rond] {\bf listvars , listcommands } to print the list of defined variables and known
1584commands
1585\item[\rond] An alias for a command by {\bf alias aliasname 'string ' }. Alias substitution
1586occurs for the first word in a command line. {\bf listalias} prints the list of all
1587defined aliases.
1588\item[\rond] Execution control (piapp/PIACmd extension):
1589It is possible to stop the interpreter execution in a loop, a script or
1590a command file by the {\bf stop} command, or using
1591 {\tt <Cntrl C>} in the piapp console (PIConsole) \\
1592\end{itemize}
1593
1594\subsection {Command execution in separate threads}
1595It is possible to create new threads to execute commands
1596( for non built-in interpreter commands). The syntax is similar
1597to unix shell background tasks: an {\&} should be added at the end
1598of the command line. A new thread is then created for the
1599execution of the command, if declared as thread safe \\
1600(see {\tt CmdExecutor::IsThreadable() }.
1601\par
1602Thread management commands:
1603\begin{itemize}
1604\item[\rond] {\bf thrlist }Print current list of threads, with the associated command
1605the thread identifier (integer ThrId) and its status.
1606\item[\rond] {\bf cleanthrlist } Removes all finished threads from the list.
1607An automatic cleanup is performed periodically.
1608\item[\rond] {\bf cancelthr ThId } / {\bf killthr ThId } Stops/kills the thread with
1609the identifier ThId. Avoid using theses commands as the cleanup does
1610not release some resources associated with
1611the thread (memory, mutex \ldots).
1612\end{itemize}
1613
[3438]1614Executing commands in a separate thread is useful for CPU or data intensive
1615commands. Most {\bf Expr.Plotting}
1616(plot2d, plot2dw, plot2de, plot3d, ntloop, fillvec, fillmtx \ldots)
1617and some of the {\bf pawCmd} (n/plot n/proj) are thread safe. However, due to the
1618current mutex lock management for these Expr.Plotting/pawCmd commands, only one
1619such command can run concurrently with other piapp threads.
1620Some of the commands in the {\bf CxxExecutorCmd} (
1621c++exec, c++execfrf, c++create, c++createfrf, c++compile, c++link) are also thread safe.
1622The same remark concerning lock management applies to these commands, while
1623CxxExecutorCmd commands can run in parallel with Expr.Plotting commands.
1624
1625
[3041]1626%%%%%%%%%%%%%%% Section 7 : c++ execution
1627\newpage
1628\section{On the fly C++ execution}
[3439]1629\label{flycplusplus}
[3441]1630Piapp operates on the underlying SOPHYA class library objects.
1631Obviously, only a small fraction of functionalities in the libraries
1632are directly available through the commands. On the fly C++ compilation
1633and execution in piapp provides an easy access to the whole class library.
[3041]1634
[3441]1635The {\bf NamedObjMgr} class handles most of the communication between different
1636component of the application, including user c++ code.
1637The NamedObjMgr class implements a singleton scheme, where all instances of the
1638class operate on the same data.
1639Most operations, in particular directory and object management are thread-safe.
1640The most usefull NamedObjMgr methods in user code are:
1641\begin{itemize}
1642\item Adding an object using its pointer. The object should be created using new. \\
1643{\tt \small bool NamedObjMgr::AddObj(AnyDataObj* obj, string \& nom, bool crd=false) }
1644\item Adding an object using its reference. The Object Adapter is used to Clone
1645the object. For classes like TArray or Spherical maps, implementing reference sharing,
1646the cloned object shares its data with the original object.
1647The Cloned object is then added to the list. \\
1648{\tt \small bool NamedObjMgr::AddObj(AnyDataObj\& obj, string \& nom, bool crd=false)}
1649\item Object display methods : \\
1650{\tt \small NamedObjMgr::DisplayObj(string \& nom, string dopt="") \\
1651NamedObjMgr::DisplayImage(string \& nom, \ldots ) \\
1652NamedObjMgr::DisplayNT(string \& nom, \ldots )} \\
1653\ldots
1654\item Access to other parts of the piapp application : \\
1655{\tt \small PIStdImgApp* NamedObjMgr::GetImgApp() \\
1656PIACmd* PIStdImgApp::CmdInterpreter() }
1657\end{itemize}
1658
1659\subsection{How does it work ?}
1660When one the {\bf CxxExecutorCmd} \myppageref{CxxExecutorCmd} commands
1661({\tt c++exec} or {\tt c++execfrf}) is invoked, piapp performs the
1662following operations:
1663\begin{itemize}
1664\item Create a c++ file, and includes the usual libstc++ and SOPHYA header files
1665(file named PIATmp\_xxx/cxx\_spiapp.cc)
1666\item The user code is put in a c++ function: \\
1667{\small \tt int usercxx( vector<string> \& args ) }
1668\item References to all objects present in the current working NamedObjMgr directory
1669(default=/home) are declared and initialized. Objects in the current directory can
1670thus be easily accessed through variables bearing the corresponding object name
1671in piapp.
1672\item The c++ source file is compiled and linked with SOPHYA libraries,
1673and any additional library, specified through {\tt c++mylibs} \myppageref{cZZmylibs}).
1674The compilation and link steps are carried by the SOPHYA class {\b CxxCompilerLinker}.
1675\item The resulting shared object is loaded by piapp and the function
1676{\tt usercxx()} is called.
1677\end{itemize}
1678
1679To facilitate communication with piapp/NamedObjMgr, two CPP macros are defined:
1680\begin{itemize}
1681\item[\rond] {\bf KeepObj(VarName) } where VarName is a user declared
1682c++ variable, corresponding to an object inheriting from AnyDataObj.
1683When this macro is called, the corresponding object is cloned by the object
1684Adapter and added to the list managed by NamedObjMgr,
1685with VarName as the object name.
[3492]1686\item[\rond] {\bf DispObj(VarName, graphic\_att) } adds the object and
[3441]1687request its display.
1688\end{itemize}
1689
1690\subsection{Examples}
1691
1692\begin{enumerate}
1693\item Computation using TimeStamp object. \\[1mm]
1694%%
1695$\longrightarrow$ File compdate.cc :
1696\begin{verbatim}
1697 TimeStamp now; // Current date
1698 TimeStamp y2000(2000,1,1,12,0,0.); // 1 jan 2000, 12:00
1699 cout << " Y2000=" << y2000 << " --> Now: " << now << endl;
1700 cout << " From Y2000 to Now= " << now.ToDays() - y2000.ToDays() << " days" << endl;
1701\end{verbatim}
1702$\longrightarrow$ piapp commands : \\
1703{\tt piapp> c++execfrf compdate.cc} \\
1704$\longrightarrow$ The result : \\
1705\begin{verbatim}
1706PIABaseExecutor: Call usercxx( ... )
1707 Y2000= 01/01/2000 12:00:0.0 UT --> Now: 13/12/2007 14:20:50.0 UT
1708 From Y2000 to Now= 2903.1 days
1709\end{verbatim}
1710%%%%
1711\item Working with objects in piapp: \\[1mm]
1712\begin{verbatim}
1713# We create three vectors
1714newvec va 256 sin(x/5.)
1715newvec vb 256 cos(x/18.)*exp(-x/150.)
1716newvec vc 256
1717# We call c++exec to make an operation on these vectors
1718c++exec vc=va+3.*vb;
1719# Display the resulting vector
1720disp vc
1721\end{verbatim}
1722%%%
1723\item Creating and adding new objects \\[1mm]
1724$\longrightarrow$ File myf\_fft.h :
1725\begin{verbatim}
1726inline double myf(double x)
1727{
1728return(3*sin(0.2*x)+4*cos(x)+5*sin(4*x+0.25)
1729 +3.5*cos(9*x+0.45) + 0.05*x);
1730}
1731\end{verbatim}
1732$\longrightarrow$ File myf\_fft.h :
1733\begin{verbatim}
1734TVector<r_8> in(4048);
1735TVector<r_8> noise(4048);
1736TVector< complex<r_8> > out;
1737in = RegularSequence(0., 0.05);
1738noise = RandomSequence(RandomSequence::Gaussian, 0., 4.);
1739MathArray<r_8> ma;
1740ma.ApplyFunctionInPlace(in, myf);
1741in += noise;
1742FFTPackServer FFTServ;
1743cout << " Calling FFT " << endl;
1744FFTServ.FFTForward(in, out);
[3492]1745DispObj(in, "");
1746DispObj(out, "red");
[3441]1747\end{verbatim}
1748$\longrightarrow$ piapp commands :
1749\begin{verbatim}
1750# Remove existing in/out objects
1751rm in out
1752# Divide then graphic window in two regions
1753zone 1 2
1754# Compile and execute the c++ code
1755c++execfrf fft.icc myf_fft.h
1756listobjs
1757\end{verbatim}
1758\end{enumerate}
1759
1760\subsection{Include files, libraries \ldots}
1761\begin{itemize}
1762\item[\rond] The different steps of c++exec or c++execfrf
1763can be performed by the following commands: {\tt c++create , c++createfrf,
1764c++compile, c++link, call}. This is useful when the same code
1765has to be executed multiple times.
1766\item[\rond] An interactive editing / c++ execution window can be
1767displayed through the menu-bar, \menubar{Tools/CxxExecutorWindow}
1768\item[\rond] The {\tt c++import} \myppageref{cZZimport}
1769activate inclusion of header files for additional SOPHYA modules,
1770such as Samba SkyMap SkyT FitsIOServe \ldots.
1771\item[\rond] The inclusion of additional header files and libraries
1772can be specified using the {\tt c++include} \myppageref{cZZinclude}
1773and {\tt c++mylibs} \myppageref{cZZmylibs}.
1774\item[\rond] A dialog window for changing various c++ compile and link
1775options can be displayed by through the menu-bar
1776\menubar{Special/CxxExecOption}
1777\end{itemize}
1778
1779
[3041]1780%%%%%%%%%%%%%%% Section 8 : command reference
1781\newpage
[2171]1782\section{piapp command reference}
[2253]1783\label{piappcmdref}
[2171]1784This section contains the description of piapp commands. This information
1785is available on-line, through the help command, or through a graphic
[3041]1786window, accessible by \menubar{File / Help}.
[2171]1787The help items and command are divided into different sections,
1788where related commands are grouped. \\[10mm]
1789
1790% \include{piahelp}
1791\input{piahelp.tex}
1792
1793% La partie des appendix
1794\appendix
1795\newpage
[3041]1796\section{Interactive control windows}
1797\subsection{DrawerTools} \index{DrawerTools}
[2171]1798\label{secdrwtools}
1799The {\bf PIDrawerTools}, shown in the figure \ref{figdrwtools} can be
1800used to change the graphic attributes (color, font, marker, \ldots)
1801of the Drawers displayed in 2D displays
1802({\bf PIScDrawWdg} \myppageref{PIScDrawWdg}) or 3D displays
1803({\bf PIDraw3DWdg} \myppageref{PIDraw3DWdg}), as well in image displays
1804{\bf PIImage} (\myppageref{PIImage}). The PIDrawerTools can be activated
1805either using {\tt Alt<G>} on a PIScDrawWdg,PIDraw3DWdg,PIImage,
[3043]1806or through the \menubar{Tools/Show DrawerTools}.
1807A given drawer can be selected through the DrawerId selector (+ / - buttons)
[2171]1808
[3041]1809\vspace*{5mm}
[2171]1810\begin{figure}[ht!]
1811\begin{center}
[3043]1812\includegraphics[width=8cm]{piapp_drwtools.eps}
[2171]1813\caption{PIDrawerTools}
1814\label{figdrwtools}
1815\end{center}
1816\end{figure}
[3041]1817%%%%
1818\subsection{AxesTools} \index{AxesTools}
[2171]1819\label{secaxestools}
1820The {\bf PIAxesTools}, shown in the figure \ref{figaxestools} can be used to
1821control and change the setting of axes on 2D displays
1822({\bf PIScDrawWdg} \myppageref{PIScDrawWdg}).
1823The PIAxesTools can be activated
1824either using {\tt Alt<A>} on a PIScDrawWdg or through
[3043]1825the \menubar{Tools/Show AxesTools}.
[2171]1826
[3041]1827\vspace*{5mm}
[2171]1828\begin{figure}[ht!]
1829\begin{center}
1830\includegraphics[width=8cm]{piapp_axestools.eps}
1831\caption{PIAxesTools}
1832\label{figaxestools}
1833\end{center}
1834\end{figure}
[3041]1835%%%%%
[3043]1836\subsection{ImageTools} \index{ImageTools}
[2171]1837\label{secimagetools}
1838The {\bf PIImageTools}, shown in the figure \ref{figimgtools} can be used to
1839manipulate a display of type image. Image display are handled by the
1840{\bf PIImage} (\myppageref{PIImage}). The PIImageTools can be activated
[3043]1841either using {\tt Alt<O>} on a PIImage, or through the
1842\menubar{Tools/Show ImageTools}.
[2171]1843
[3041]1844\vspace*{5mm}
[2171]1845\begin{figure}[ht!]
1846\begin{center}
1847\includegraphics[width=8cm]{piapp_imgtools.eps}
1848\caption{PIImageTools}
1849\label{figimgtools}
1850\end{center}
1851\end{figure}
1852
[3041]1853\subsection{Histo2DTools} \index{Histo2DTools}
[2171]1854\label{sech2dtools}
1855The {\bf PIHisto2DTools}, shown in the figure \ref{figh2dtools} can be
1856used to control and change the display caracteristics of 2D histograms.
[2253]1857PIHisto2DTools can be activated
[2171]1858either using {\tt Alt<O>} on a PIScDrawWdg, when the active
1859drawer is a PIHisto2DDrawer, or through the generic drawer tool
1860PIDrawerTools.
1861
[3041]1862\vspace*{5mm}
[2171]1863\begin{figure}[ht!]
1864\begin{center}
1865\includegraphics[width=8cm]{piapp_h2dtools.eps}
1866\caption{PIHisto2DTools}
1867\label{figh2dtools}
1868\end{center}
1869\end{figure}
1870
[3041]1871\subsection{ContourTools} \index{ContourTools}
[2171]1872\label{secconttools}
1873The {\bf PIContourTools}, shown in the figure \ref{figconttools} can be
1874used to control and change the caracteristics of contour displays.
[2253]1875PIContourTools can be activated
[2171]1876either using {\tt Alt<O>} on a PIScDrawWdg, when the active
1877drawer is a PIContDrawer, or through the generic drawer tool
1878PIDrawerTools.
1879
1880\vspace*{10mm}
1881\begin{figure}[ht!]
1882\begin{center}
1883\includegraphics[width=11cm]{piapp_conttools.eps}
1884\caption{PIContourTools}
1885\label{figconttools}
1886\end{center}
1887\end{figure}
1888
1889
[2253]1890
1891Both drawing options (e.g. color, line type, fonts...) and contour
1892determination parameters (e.g. contour number and levels) are controlled
1893by {\bf PIContourTools}.
1894
[3041]1895\subsubsection{Drawing options}
[2253]1896The top choices in {\bf PIContourTools}
1897concern the color map (left choice) or color (right choice) of the contours.
1898If a color map has been chosen, it is used to give each contour a color
1899(according to its level). If no color map has been chosen, contours may be
1900given a color using the left choice box.
1901
1902Contour are by default traced by lines.
1903Alternatively (or in addition) the user may ask to trace them by markers
1904or to put numeric labels (with the contour's level) aside the contour.
1905These options are enabled/disabled by the {\tt LineON}, {\tt MarkerON} and {\tt LabelON}
1906buttons from {\bf PIContourTools}.
1907
1908Options may be recovered ({\tt GetAtt}) or set ({\tt SetAtt})
1909from/to a drawer. Setting an option which adds to the screen will be immediately visible
1910whereas unsetting it requires a {\tt Refresh} to be visible.
1911
1912
[3041]1913\subsubsection{Contour options}
[2253]1914The contouring routines in {\tt spiapp} are based on a hack of the {\tt GNUPlot}
1915routines. Contours are determined from a grid of values
1916using an interpolation scheme. Three schemes may be used
1917(selected by the left menu) :
1918\begin{enumerate}
1919\item Linear interpolation (default), selected by the {\tt Int. Lin.} option
1920\item A cubic spline algorithm, selected by the {\tt CubicSpl} option
1921\item A 2d BSpline algorihm, selected by the {\tt B-Spline} option
1922\end{enumerate}
1923
1924Contour levels and number are automatically
1925determined by the program. They may be specified differently,
1926 through command-line options
1927(see section \ref{piappcmdref} for the help of the contour/ntcont commands)
1928or the lower part of the {\bf PIContourTools} window.
1929
1930The user may specify one of the following alternatives :
1931\begin{enumerate}
1932\item the number of contour (their level beeing automatically set).
1933To do this, select {\tt LevelNum} in the right menu and enter the contour number
1934in the left box below.
1935\item the levels of the contours, through an array of numerical values
1936(e.g. 1,4,6,9,27,4.5 will result in 6 contour lines being drawn, if possible and necessary).
1937To do this, select {\tt LevelDisc} and enter the contour number (left box)
1938and the values (right box) separated by ``{\tt ,}''.
1939\item the levels of the contours through an initial (lower) value and an increment.
1940For this, select {\tt LevelInc} and enter the contour number (left box)
1941and the initial value and increment in the right box, as above.
1942\item come back to the default situation, by choosing {\tt LevelAuto}
1943\end{enumerate}
1944
1945Once these options are set, it is necessary the the program recomputes
1946the contour lines. This is commanded by the {\tt SetParm} button.
1947
1948
[2171]1949\newpage
1950\addcontentsline{toc}{section}{Index}
1951\printindex
1952
1953\end{document}
Note: See TracBrowser for help on using the repository browser.