Index: trunk/SophyaProg/Examples/README
===================================================================
--- trunk/SophyaProg/Examples/README	(revision 1433)
+++ trunk/SophyaProg/Examples/README	(revision 1634)
@@ -24,4 +24,10 @@
 
 
+5) apc.icc apcxx.icc apcxx_cstyle.icc
+   Matrix and vector manipulation and Fourier filtering 
+   apc.icc : written as a C program
+   apcxx.icc : C++ code with SOPHYA arrays
+   apcxx_cstyle.icc : similar to apcxx.icc but with 
+        C_style programming (explicit loops) 
 
    csh> spiapp   
Index: trunk/SophyaProg/Examples/apc.icc
===================================================================
--- trunk/SophyaProg/Examples/apc.icc	(revision 1634)
+++ trunk/SophyaProg/Examples/apc.icc	(revision 1634)
@@ -0,0 +1,91 @@
+/*  ------------------ apc.icc -------------------
+
+   Example illustrating C programming for performing 
+   operations comparable to those performed in apcxx.icc
+
+                                   R. Ansari  08/2001
+ 
+   ---- Computation steps :
+    > Allocate an array representing a matrix (NL x NC )  (mtx)
+    > fill it with a gaussian distributed random values
+    > make a copy of the matrix   (mtxs)
+    > allocate and fill 1D filter in Fourier space 
+    > Loop over matrix rows k
+     >> Extract row k (fline)
+     >> compute 1D Fourier transform FFTForward (fline) 
+     >> apply filter in Fourier space
+     >> compute backward 1D FFT 
+     >> Replace matrix row with the filtered values
+   
+    > free the allocated memory
+   
+   this example code can be 
+     - included in a main program
+     - executed using runcxx 
+       csh> runcxx -tmpdir /tmp -f apc.icc
+     - executed within spiapp 
+       Cmd> c++execfrf apc.icc
+*/
+
+// Select computation on float or double (r_4 r_8)
+#define FTYP r_4
+
+// Number of matrix lines and colums
+int NL = 1024;
+int NC = 4096;
+int i,k;
+cout << " apc : NL= " << NL << " NC= " << NC << endl;
+PrtTim("apc_Start");
+
+// Creation of the initial matrix
+FTYP * mtx = new FTYP [NL*NC];
+// Filling matrix with gaussian random values
+for(i=0; i<NL*NC; i++) 
+  mtx[i] = 15.+NorRand()*3.;
+
+// Allocation of the copy matrix (mtxs)
+FTYP * mtxs = new FTYP [NL*NC];
+// copying mtxs to mtx 
+for(i=0; i<NL*NC; i++) 
+  mtxs[i] = mtx[i];
+
+// Creation and initialization of the Fourier filter filt(nu)
+FTYP * filt = new FTYP [NC];
+for(i=0; i<NC; i++) { 
+  filt[i] =  1.-i/(double)NC;
+  filt[i] *= filt[i]; 
+}
+
+
+// Creation of the FFTPackServer
+// We use this class to avoid to do the initialization steps needed to use fftpack.
+FFTPackServer ffts;
+ffts.setNormalize(true);
+
+PrtTim("apc_AfterInit");
+
+// Allocation of the matrix row memory  
+FTYP * fline = new FTYP [NC];
+
+//  Loop over matrix rows
+for(k=0; k<NL; k++) {
+  // Matrix row extraction 
+  for(i=0; i<NC; i++) fline[i] = mtx[k*NC+i];
+  // Compute 1D forward FFT
+  ffts.fftf(NC, fline);
+  // Applying filter in Fourier space f(nu) =  f(nu)*filter(nu)
+  for(i=0; i<NC; i++) fline[i] *= filt[i];
+  // backward FFT
+  ffts.fftb(NC, fline);
+  // replace matrix row with filtered values
+  for(i=0; i<NC; i++) mtx[k*NC+i] = fline[i];
+}
+
+PrtTim("apc_AfterFFTLoop");
+
+
+delete[] mtx;
+delete[] mtxs;
+delete[] fline;
+delete[] filt;
+
Index: trunk/SophyaProg/Examples/apcxx.icc
===================================================================
--- trunk/SophyaProg/Examples/apcxx.icc	(revision 1634)
+++ trunk/SophyaProg/Examples/apcxx.icc	(revision 1634)
@@ -0,0 +1,80 @@
+/*  ----------------- apcxx.icc -------------------
+
+   Example illustrating C++ scientific programming 
+   using SOPHYA library arrays and FFT computation 
+   through FFTServerInterface.                         
+                                   R. Ansari  08/2001 
+   ---- Computation steps :
+    > Create a matrix (NL x NC )  (mtx)
+    > fill it with a gaussian distributed random values
+    > make a copy of the matrix   (mtxs)
+    > create a 1D filter in Fourier space 
+    > Loop over matrix rows k
+     >> Extract row k (fline)
+     >> compute 1D Fourier transform FFTForward (fline) 
+     >> apply filter in Fourier space
+     >> compute backward 1D FFT 
+     >> Replace matrix row with the filtered values
+   
+
+   this example code can be 
+     - included in a main program
+     - executed using runcxx 
+       csh> runcxx -tmpdir /tmp -f apcxx.icc
+     - executed within spiapp 
+       Cmd> c++execfrf apcxx.icc
+*/
+
+// Select computation on float or double (r_4 r_8)
+#define FTYP r_4
+
+// Number of matrix lines and colums
+int NL = 1024;
+int NC = 4096;
+cout << " apc_xx : NL= " << NL << " NC= " << NC << endl;
+PrtTim("apcxx_Start");
+
+// BaseArray::SetDefaultMemoryMapping(BaseArray::CMemoryMapping);
+// BaseArray::SetMaxPrint(10, 3);
+
+// Creation of the initial matrix
+TMatrix< FTYP > mtx(NL, NC), mtxs;
+// Filling matrix with gaussian random values
+mtx = RandomSequence(RandomSequence::Gaussian, 15., 3.);
+// Making a copy of the original matrix
+mtxs = mtx;
+
+// Creation and initialization of the Fourier filter filt(nu) = 1/(1+0.3*nu)
+int LFFT = NC/2+1;
+TVector< complex< FTYP > > filt(LFFT, BaseArray::RowVector);
+filt(0) = 1.;
+for(int i=1; i<filt.Size(); i++) 
+  filt(i) = 1./(1+0.3*(double)i);
+
+
+// Creation of the FFTServer
+FFTPackServer ffts;
+ffts.setNormalize(true);
+
+PrtTim("apcxx_AfterInit");
+
+// Vectors for FFT operations 
+TVector< FTYP > fline(NC, BaseArray::RowVector);
+TVector< complex< FTYP > > vfft;
+
+//  Loop over matrix rows
+for(int k=0; k<NL; k++) {
+  fline = mtx.Row(k);      // Matrix row extraction 
+  ffts.FFTForward(fline, vfft);    // Compute 1D forward FFT
+  // Applying filter in Fourier space f(nu) =  f(nu)*filter(nu)
+  vfft.MulElt(filt);             
+  ffts.FFTBackward(vfft, fline);   // backward FFT
+  mtx.Row(k) = fline;      // replace matrix row with filtered values
+ }
+
+PrtTim("apcxx_AfterFFTLoop");
+
+// Macro KeepObj can be used with runcxx or within (s)piapp 
+// KeepObj(mtx);
+// KeepObj(mtxs);
+
Index: trunk/SophyaProg/Examples/apcxx_cstyle.icc
===================================================================
--- trunk/SophyaProg/Examples/apcxx_cstyle.icc	(revision 1634)
+++ trunk/SophyaProg/Examples/apcxx_cstyle.icc	(revision 1634)
@@ -0,0 +1,96 @@
+/*  --------------- apcxx_cstyle.icc -----------------
+
+   Example illustrating C++ scientific programming 
+   using SOPHYA library arrays and FFT computation 
+   through FFTServerInterface.   
+   This example, performs the same operations as in
+   apcxx.icc, through C-style programming with 
+   explicit loops. This C_style should be avoided when 
+   programming in C++.
+                      
+                                   R. Ansari  08/2001
+ 
+   ---- Computation steps :
+    > Create a matrix (NL x NC )  (mtx)
+    > fill it with a gaussian distributed random values
+    > make a copy of the matrix   (mtxs)
+    > create a 1D filter in Fourier space 
+    > Loop over matrix rows k
+     >> Extract row k (fline)
+     >> compute 1D Fourier transform FFTForward (fline) 
+     >> apply filter in Fourier space
+     >> compute backward 1D FFT 
+     >> Replace matrix row with the filtered values
+   
+
+   this example code can be 
+     - included in a main program
+     - executed using runcxx 
+       csh> runcxx -tmpdir /tmp -f apcxx_cstyle.icc
+     - executed within spiapp 
+       Cmd> c++execfrf apcxx_cstyle.icc
+*/
+
+// Select computation on float or double (r_4 r_8)
+#define FTYP r_4
+
+// Number of matrix lines and colums
+int NL = 1024;
+int NC = 4096;
+int i, j;
+cout << " apc_cstyle : NL= " << NL << " NC= " << NC << endl;
+PrtTim("apc_cstyle_Start");
+
+//BaseArray::SetDefaultMemoryMapping(BaseArray::CMemoryMapping);
+//BaseArray::SetMaxPrint(10, 3);
+
+
+// Creation of the initial matrix
+TMatrix< FTYP > mtx(NL, NC);
+// Filling matrix with gaussian random values
+// mtx = RandomSequence(RandomSequence::Gaussian, 15., 3.);
+for(i=0; i<NL; i++) 
+  for(j=0; j<NC; j++) mtx(i, j) = 15.+NorRand()*3.;
+
+// Making a copy of the original matrix
+//mtxs = mtx;
+TMatrix< FTYP > mtxs(NL, NC);
+for(i=0; i<NL; i++) 
+  for(j=0; j<NC; j++) mtxs(i, j) = mtx(i, j);
+
+
+// Creation and initialization of the Fourier filter filt(nu) = 1/(1+0.3*nu)
+int LFFT = NC/2+1;
+TVector< complex< FTYP > > filt(LFFT, BaseArray::RowVector);
+filt(0) = 1.;
+for(int i=1; i<filt.Size(); i++) 
+  filt(i) = 1./(1+0.3*(double)i);
+
+// Creation of the FFTServer
+FFTPackServer ffts;
+ffts.setNormalize(true);
+
+PrtTim("apc_cstyle_AfterInit");
+
+// Vectors for FFT operations 
+TVector< FTYP > fline(NC, BaseArray::RowVector);
+TVector< complex< FTYP > > vfft;
+
+for(int k=0; k<NL; k++) {
+  //  fline = mtx.Row(k);   Matrix row extraction 
+  for(j=0; j<NC; j++) fline(j) = mtx(k, j);
+  ffts.FFTForward(fline, vfft);   // Compute 1D forward FFT
+  // Applying filter in Fourier space f(nu) =  f(nu)*filter(nu)
+  //  vfft.MulElt(filt); 
+  for(j=0; j<LFFT; j++) vfft(j) *= filt(j);
+  ffts.FFTBackward(vfft, fline);  // backward FFT
+  //  mtx.Row(k) = fline;  // replace matrix row with filtered values
+  for(j=0; j<NC; j++) mtx(k, j) = fline(j);
+}
+
+PrtTim("apc_cstyle_AfterFFTLoop");
+
+// Macro KeepObj can be used with runcxx or within (s)piapp 
+// KeepObj(mtx);
+// KeepObj(mtxs);
+
