source: Sophya/trunk/DocHFI_L2/sdg.tex@ 794

Last change on this file since 794 was 794, checked in by ansari, 26 years ago

This commit was generated by cvs2svn to compensate for changes in r793,
which included commits to RCS files with non-trunk default branches.

File size: 8.6 KB
Line 
1\documentclass[twoside,12pt]{article}
2% Package standard : Utilisation de caracteres accentues, mode francais et graphique
3\usepackage[latin1]{inputenc}
4\usepackage[T1]{fontenc}
5\usepackage{babel}
6\usepackage{graphicx}
7
8% Extension de symboles mathematiques
9\usepackage{amssymb}
10
11% Definition de taille de page
12\setlength{\textwidth}{16cm}
13\setlength{\textheight}{21.5cm}
14\setlength{\topmargin}{0.5cm}
15\setlength{\oddsidemargin}{0.cm}
16\setlength{\evensidemargin}{0.cm}
17\setlength{\unitlength}{1mm}
18
19\newcommand{\bul}{$\bullet \ $}
20
21\begin{document}
22
23\begin{titlepage}
24\vspace{1cm}
25\rule{110 mm}{0.5 mm}\makebox[50 mm]{\bf Planck HFI L2}
26\vspace{2cm}
27\begin{center}
28\par \renewcommand{\baselinestretch}{2.0} \small
29{\LARGE \bf
30Planck HFI L2 \\
31Software Development Guidelines
32}
33\par \renewcommand{\baselinestretch}{1.0} \normalsize
34\vspace{5 cm}
35\begin{tabular}{ll}
36{R. Ansari} & {\tt ansari@lal.in2p3.fr} \\
37{É. Aubourg} & {\tt aubourg@hep.saclay.cea.fr} \\
38% {É. Lesquoy} & {\tt lesquoy@hep.saclay.cea.fr} \\
39% {C. Magneville} & {\tt cmv@hep.saclay.cea.fr} \\
40\end{tabular}
41
42\end{center}
43\vfill
44\hfill
45% \includegraphics[width=4cm]{Fig/hfi_icon_vsmall.eps}
46\framebox[\textwidth]{\hspace{0.5cm} \bf Planck HFI Level 2
47\hspace{1cm} \today }
48\end{titlepage}
49
50\tableofcontents
51
52\newpage
53% \tableofcontents
54
55\section{Introduction}
56We intend to gather gradually in this document the guidelines
57for the development of Planck HFI Level 2 data processing softwares.
58We assume throughout this document that C++ is the baseline option
59as the programming language for the development of Planck HFI
60Level 2 processing software.
61
62\section{Integration of software modules in different languages}
63We review here some of the problems which may arise when integrating software
64modules written in other languages into C++ programs.
65
66\subsection{C and C++}
67C++ extends the possibilities offered by the C language.
68All of the C language data types and function call syntax are thus
69supported by C++. Among other features, C++ offers the function
70overloading possibility. This means that functions with different
71argument list can have the same name.
72\begin{verbatim}
73int fo(int a);
74int fo(int a, int b);
75int fo(double a, double b);
76\end{verbatim}
77Using {\bf C}, one would have written:
78\begin{verbatim}
79int foi(int a);
80int foii(int a, int b);
81int fodd(double a, double b);
82\end{verbatim}
83C++ compilers use internally a name containing the encoding of the
84argument list. In order to instruct the compiler to use simple
85names, {\bf C} functions should be declared as \\
86{\tt extern "C" }. This is usually included in the header
87file (.h). In the example above, the header file (.h) file
88would be in the form:
89\begin{verbatim}
90#ifdef __cplusplus
91extern "C" {
92#endif
93int foi(int a);
94int foii(int a, int b);
95int fodd(double a, double b);
96#ifdef __cplusplus
97}
98#endif
99\end{verbatim}
100
101\subsection{Fortran and C++}
102Fortran is a simple language and uses only basic data types.
103Although the exact mapping between Fortran and C/C++ basic data types
104may vary depending on the OS and hardware architecture, it is close
105to the one shown in the table below:
106\begin{center}
107\begin{tabular}{lll}
108INTEGER & int & usually 4 bytes \\
109REAL*4 & float & usually 4 bytes \\
110REAL*8 & double & usually 8 bytes \\
111COMPLEX & complex<float> & \\
112COMPLEX*16 & complex<double> & \\
113\end{tabular}
114\end{center}
115In fortran, all arguments are passed by address and
116fortran compilers (on Unix systems) add an underscore "\_"
117to all symbol names. It is thus rather easy to call
118Fortran subroutines or functions from C or C++.
119This is illustrated in the following example:
120\begin{verbatim}
121C Fortran-Code
122 SUBROUTINE FSUB(A,N,B,M)
123 REAL A(*),B(*)
124 INTEGER N,M
125 RETURN
126 END
127\end{verbatim}
128The corresponding C (or C++) declaration is: \\[3mm]
129{\tt void fsub\_(float *a, int *n, float *b, int *m); } \\[3mm]
130{\tt FSUB} can be called from C code, as is shown below :
131\begin{verbatim}
132float aa[10];
133int na=10;
134float bb[10];
135int mb=10;
136fsub_(aa, &na, bb, &mb);
137\end{verbatim}
138
139The case of character string arguments in fortran subroutines
140needs a bit more attention, and the string length needs to be passed
141as an additional integer type argument.
142As with {\bf C} functions, fortran functions or subroutines
143have to be delared {\tt extern "C"} to be used within {\bf C++}
144programs. {\bf C/C++} driver routines can easily be written for
145extensively used fortran modules, simplifying calling sequences.
146
147It should also be noted that the fortran support libraries have to be
148included for the link with the C++ driver.
149It is also possible to translate the whole fortran source code
150into {\bf C} code using {\bf f2c} program. The call syntax
151will be exactly the same as with a Fortran compiler, and
152{\tt libf2c.a} should be used when linking the program.
153
154It is very difficult to use C++ classes directly from fortran.
155However, high level functionalities based on a C++ libray can
156be wrapped in a fortran style function which can be
157called from fortran. One looses of course many of the
158possibilities offered by underlying C++ library.
159
160We illustrate below the wrapping of a simple C++ class:
161\begin{verbatim}
162// An example class performing some computation
163class Example {
164 Example();
165 ~Example();
166 void compute(int sz, float *x);
167 int getSize();
168 float getResult(int k);
169};
170\end{verbatim}
171
172The wrapper would then look like:
173\begin{verbatim}
174extern "C" {
175 void foradapt_(float *a, int *n, float *b, int *m);
176}
177
178foradapt_(float *a, int *m, float *b, int *n)
179{
180// a is the input array, m it's size
181// b is the output array, n the returned size
182// b has to dimensioned big enough in the calling program
183
184Example ex;
185ex.compute(*n, a);
186*m = ex.getSize();
187for(int i=0; i<ex.getSize(); i++)
188 b[i] = ex.getResult(i);
189}
190\end{verbatim}
191
192One can then call {\tt FORADPAT} from fortran :
193\begin{verbatim}
194REAL A(1000)
195REAL B(1000)
196INTEGER N,M
197M = 1000
198N = 1000
199CALL FORADPAT(A, M, B, N)
200\end{verbatim}
201
202
203\subsection{Fortran-90 and C++}
204Fortran-90 (F90) is a much more complex language than Fortran 77
205(F77). Compared to F77, it introduces many new constructions, including:
206\begin{itemize}
207\item[-] pointers
208\item[-] local and global variables
209\item[-] in, out, in-out argument type for function and subroutines
210\item[-] compound data types, similar to structures in C
211\item[-] multidimensional arrays
212\item[-] function and operator overloading.
213\end{itemize}
214It is thus more difficult to use full featured F90 modules from
215{\bf C} or {\bf C++}. One would have to map all these different
216data structures with their attributes between the two languages,
217in a OS/compiler independent way.
218It should however be possible to encapsulate F90 modules into simple F77
219like subroutines that could be called from C/C++.
220
221
222\newpage
223\appendix
224
225\section{The C++ language}
226\vspace{5 mm}
227{\bf C++} is a very powerful Object Oriented language.
228It has been developped by extending the {\bf C} language,
229keeping in mind the efficiency and performance,
230as well as easy integration with existing softwares.
231It incorporates new possibilities such as:
232
233\begin{itemize}
234\item Introduction of object and classes
235\item function overloading
236\item Operator overloading
237\item function and operator inlining (optimisation)
238\item virtual functions (polymorphism)
239\item public, protected and private members
240\item dynamic memory management operators
241\item Exception handling
242\item generic (template) function and classes
243\end{itemize}
244
245{\bf C++} can be considered now as a mature language.
246C++ class library covering various areas, including
247numerical data processing are available as freeware
248or commercial products. Many software tools feature
249a standard C++ API.
250\par \vspace{3mm}
251The current standard for C++ and C are defined by
252\footnote{Available from {\bf http://www.ansi.org/ } }:
253\begin{itemize}
254\item[] {\bf ISO/IEC 14882-1998(E)} Programming languages -- C++
255\item[] {\bf ANSI/ISO 9899-1990} for Programming Languages C
256\end{itemize}
257
258
259\newpage
260\section{C++ compilers}
261
262
263Powerful compilers are available on most platforms,
264including:
265
266\begin{itemize}
267\item[-] the GNU multiplatform g++ \footnote{http://gcc.gnu.org/},
268\item[-] KAI KCC \footnote{http://www.kai.com/C\_plus\_plus/} which is a
269nice multiplatform optimising C++ compiler.
270\item[-] Digital (Compaq) cxx \footnote{http://www.unix.digital.com/cplus/}
271\item[-] IBM VisualAge C++ \footnote{http://www-4.ibm.com/software/ad/vacpp/}
272\item[-] HP aCC \footnote{http://www.hp.com/esy/lang/cpp/}
273\item[-] Silicon Graphics SGI-CC on IRIX \footnote{http://www.sgi.com/developers/devtools/languages/c++.html}
274\item[-] Cray C++ compiler on Unicos \footnote{http://www.sgi.com/software/unicos/cplusoverview.html}
275\end{itemize}
276
277
278\end{document}
Note: See TracBrowser for help on using the repository browser.