Index: /trunk/SophyaExt/CodeMinuit/cfortran/Examples/Imakefile
===================================================================
--- /trunk/SophyaExt/CodeMinuit/cfortran/Examples/Imakefile	(revision 2414)
+++ /trunk/SophyaExt/CodeMinuit/cfortran/Examples/Imakefile	(revision 2414)
@@ -0,0 +1,11 @@
+FILES=	chbook-example.c chigz-example.c \ @@\
+        chplot-example.c hbook-cwn.c hbook-cwnc.c \ @@\
+        hbook-ntuple.c minuit-fcn.c minuit-fcn.f minuit-main.c \ @@\
+        pamain.c read_rwntuple.c \ @@\
+	
+
+#ifndef CERNLIB_VAXVMS
+InstallIncludes($(FILES),$(CERN_INCLUDEDIR),cfortran/Examples)
+#else
+InstallIncludes($(FILES),$(CERN_INCLUDEDIR),cfortran.examples)
+#endif
Index: /trunk/SophyaExt/CodeMinuit/cfortran/Examples/chbook-example.c
===================================================================
--- /trunk/SophyaExt/CodeMinuit/cfortran/Examples/chbook-example.c	(revision 2414)
+++ /trunk/SophyaExt/CodeMinuit/cfortran/Examples/chbook-example.c	(revision 2414)
@@ -0,0 +1,48 @@
+/*
+ * This example demonstrate how to call HBOOK from C (histogram part).
+ *
+ * For question/problems contact: Heplib.Support@cern.ch
+ *
+ */
+
+#include <stdlib.h>
+#include <cfortran.h>
+#include <hbook.h>
+
+#if defined(__hpux) || defined(_IBMR2)
+# define extname
+#endif
+
+#define PAWC_SIZE 50000
+
+typedef struct { float PAW[PAWC_SIZE]; } PAWC_DEF;
+#define PAWC COMMON_BLOCK(PAWC,pawc)
+COMMON_BLOCK_DEF(PAWC_DEF,PAWC);
+
+#if defined(__vms) || defined(vms)
+/*        On VMS rand has a range of 2**31 */
+# define RAND_RANGE 2146483648.
+#else
+# define RAND_RANGE 32768.
+#endif
+
+main()
+{
+   int hid=1;
+   int i,j;
+   float r;
+/*
+ * Some C++ compiler generates a memset error when a character string
+ * is passed directly as argument to a F77 function. Using an intermediate 
+ * variable make it work.
+ */
+
+   HLIMIT(PAWC_SIZE);
+   HBOOK1(hid,"Some random distribution",20000,-4.,4.,0.);
+
+   for (i=0;i<100000;i++){
+      for (j=0,r=0.;j<10;r += rand()/RAND_RANGE -0.5 ,j++);
+         HFILL(hid,r,0.,1.);
+   }
+   HPRINT(hid);
+}
Index: /trunk/SophyaExt/CodeMinuit/cfortran/Examples/chigz-example.c
===================================================================
--- /trunk/SophyaExt/CodeMinuit/cfortran/Examples/chigz-example.c	(revision 2414)
+++ /trunk/SophyaExt/CodeMinuit/cfortran/Examples/chigz-example.c	(revision 2414)
@@ -0,0 +1,52 @@
+/*
+ * This example demonstrate how to call HIGZ from C.
+ *
+ * For question/problems contact: Heplib.Support@cern.ch
+ *
+ */
+
+#include <cfortran.h>
+#include <packlib.h>
+#include <higz.h>
+
+#if defined(__hpux) || defined(_IBMR2)
+# define extname
+#endif
+
+#define PAWC_SIZE 50000
+
+typedef struct { float PAW[PAWC_SIZE]; } PAWC_DEF;
+#define PAWC COMMON_BLOCK(PAWC,pawc)
+COMMON_BLOCK_DEF(PAWC_DEF,PAWC);
+
+main()
+{
+   int itype,istat;
+   char c;
+/*
+ * Initialisation 
+ */
+   MZEBRA(-3);
+   MZPAW(PAWC_SIZE," ");
+   IGINIT(0);
+   IGWKTY(itype);
+   IGSSE(6, itype);
+/*
+ * Some simple drawing
+ */
+   KUOPEN(77,"chigz-example.ps","NEW",istat);
+   IGMETA(77,-111);
+   IGRNG(21., 21.);
+   IGBOX(1.0, 20.0, 1.0, 20.0);
+   IGBOX(2.0, 19.0, 2.0, 19.0);
+   IGBOX(3.0, 18.0, 3.0, 18.0);
+   IGBOX(4.0, 17.0, 4.0, 17.0);
+   IGSET("TXAL",23.);
+   IGSET("CHHE",0.5);
+   ITX (10.5,10.5,"HIGZ called from a C program");
+   IGTERM();
+   IGMETA(999,0);
+   KUCLOS(77," ",1);
+   c = getchar();  
+   IGEND();
+}
Index: /trunk/SophyaExt/CodeMinuit/cfortran/Examples/chplot-example.c
===================================================================
--- /trunk/SophyaExt/CodeMinuit/cfortran/Examples/chplot-example.c	(revision 2414)
+++ /trunk/SophyaExt/CodeMinuit/cfortran/Examples/chplot-example.c	(revision 2414)
@@ -0,0 +1,65 @@
+/*
+ * This example demonstrate how to call HPLOT from C.
+ *
+ * For question/problems contact: Heplib.Support@cern.ch
+ *
+ */
+
+#include <stdlib.h>
+#include <cfortran.h>
+#include <graflib.h>
+#include <packlib.h>
+#include <kernlib.h>
+
+#if defined(__hpux) || defined(_IBMR2)
+# define extname
+#endif
+
+#define PAWC_SIZE 50000
+
+typedef struct { float PAW[PAWC_SIZE]; } PAWC_DEF;
+#define PAWC COMMON_BLOCK(PAWC,pawc)
+COMMON_BLOCK_DEF(PAWC_DEF,PAWC);
+
+main()
+{
+   int istat;
+   char c;
+
+   HLIMIT(PAWC_SIZE);
+   HPLINT(4);
+/*
+ * Histograms booking and filling
+ */
+   HBOOK1(1,"x",100,-4.,4.,0.);
+   HBOOK1(2,"y",100,-4.,4.,0.);
+   HBOOK1(3,"(x-y)/(x+y)",100,-6.,6.,0.);
+   fill();
+/*
+ * Histograms plotting
+ */
+   KUOPEN(77,"chplot-example.ps","NEW",istat);
+   IGMETA(77,-111);
+   HPLZON(2,2,1," ");
+   HPLOT(1," "," ",0);
+   HPLOT(2," "," ",0);
+   HPLZON(1,2,2,"S");
+   HPLOT(3," "," ",0);
+   IGMETA(999,0);
+   KUCLOS(77," ",1);
+   c = getchar();  
+   HPLEND();
+}
+
+fill()
+{
+   float x,y;
+   int i;
+
+   for ( i=1; i<1001; i++) {
+      RANNOR(x,y);
+      HF1(1,x,1.);
+      HF1(2,y,1.);
+      HF1(3,(x-y)/(x+y),1.);
+   }
+}
Index: /trunk/SophyaExt/CodeMinuit/cfortran/Examples/hbook-cwn.c
===================================================================
--- /trunk/SophyaExt/CodeMinuit/cfortran/Examples/hbook-cwn.c	(revision 2414)
+++ /trunk/SophyaExt/CodeMinuit/cfortran/Examples/hbook-cwn.c	(revision 2414)
@@ -0,0 +1,39 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <cfortran.h>
+#include <packlib.h>
+ 
+#define PAWC_SIZE 50000
+ 
+typedef float PAWC_DEF[PAWC_SIZE];
+#define PAWC COMMON_BLOCK(PAWC,pawc)
+COMMON_BLOCK_DEF(PAWC_DEF,PAWC);
+ 
+main()
+{
+  const int nmax = 300;
+  int record_size=1024;
+  int istat, n, icycle;
+ 
+  struct { float r; } mycwn; 
+
+  HLIMIT(PAWC_SIZE);
+ 
+  HROPEN(1,"MYCWN","mycwn.hbook","NX",record_size,istat);
+  if (istat) {
+    printf("Error in opening file ...");
+    return EXIT_FAILURE;
+  }
+ 
+  HBNT(1,"MYCWN"," ");
+  HBNAME(1,"BLOCK",mycwn.r,"R:R*4");
+ 
+  for (n=0; n<=nmax; n++) {
+    mycwn.r = n*n;
+    HFNT(1);
+  }
+ 
+  HROUT(0,icycle," ");
+  HREND("MYCWN");
+  KUCLOS(1," ",1);
+}
Index: /trunk/SophyaExt/CodeMinuit/cfortran/Examples/hbook-cwnc.c
===================================================================
--- /trunk/SophyaExt/CodeMinuit/cfortran/Examples/hbook-cwnc.c	(revision 2414)
+++ /trunk/SophyaExt/CodeMinuit/cfortran/Examples/hbook-cwnc.c	(revision 2414)
@@ -0,0 +1,68 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <cfortran.h>
+#include <packlib.h>
+
+#define PAWC_SIZE 50000
+
+typedef float PAWC_DEF[PAWC_SIZE];
+#define PAWC COMMON_BLOCK(PAWC,pawc)
+COMMON_BLOCK_DEF(PAWC_DEF,PAWC);
+
+main()
+{
+  int record_size=1024;
+  int istat, icycle;
+
+  HLIMIT(PAWC_SIZE);
+
+  HROPEN(1,"MYCWN","mycwn.hbook","NX",record_size,istat);
+  if (istat) {
+    printf("Error in opening file ...");
+    return EXIT_FAILURE;
+  }
+
+  HBNT(1,"MYCWN"," ");
+
+  {
+  /* Struct is required if defining more than one variable
+     within a single call to HBNAMC or HBNAME.
+     Struct may also be required in order to introduce
+     an aligned variable, see 'int align' below,
+     which ensures that the subsequent character arrays are aligned.
+     HBNAMC requires the characters to be aligned.
+   */
+  struct { int align; char a[8]; char b[3][4];} m;
+  struct { int align; char c[4]; } n;
+  HBNAMC(1,"BLOCK",m.a,"A:C*8,B(3):C");
+  HBNAMC(1,"BLOCK",n.c,"C:C");
+
+
+  /* Since HFNT() gets the character info. via
+     an adress stored in the HBNAMC call,
+     there is no way that cfortran.h can convert
+     from C strings to Fortran strings.
+     The character arrays have the same number of bytes in C as they do in
+     Fortran. i.e. there is no room for C's trailing '\0' character.
+     So use strncpy() and blank pad until the ed of the array.
+   */
+
+  strncpy(m.a,    "hiho1   ",8);
+  strncpy(m.b[0], "ba  ",4);
+  strncpy(m.b[1], "bb  ",4); /* bb and bc don't show in PAW.                  */
+  strncpy(m.b[2], "bc  ",4); /* Either PAW is broken, or how I use cfortran.h.*/
+  strncpy(n.c,    "coco",4);
+  HFNT(1);
+
+  strncpy(m.a,    "hiho2   ",8);
+  strncpy(m.b[0], "ba2 ",4);
+  strncpy(m.b[1], "bb2 ",4); /* Again bb2 and bc2 don't show in PAW. */
+  strncpy(m.b[2], "bc2 ",4);
+  strncpy(n.c,    "coc2",4);
+  HFNT(1);
+  }
+
+  HROUT(0,icycle," ");
+  HREND("MYCWN");
+  KUCLOS(1," ",1);
+}
Index: /trunk/SophyaExt/CodeMinuit/cfortran/Examples/hbook-ntuple.c
===================================================================
--- /trunk/SophyaExt/CodeMinuit/cfortran/Examples/hbook-ntuple.c	(revision 2414)
+++ /trunk/SophyaExt/CodeMinuit/cfortran/Examples/hbook-ntuple.c	(revision 2414)
@@ -0,0 +1,48 @@
+/*
+ * This example demonstrate how to call HBOOK from C (ntuple part).
+ *
+ * For question/problems contact: Heplib.Support@cern.ch
+ *
+ */
+
+#include <stdlib.h>
+#include <cfortran.h>
+#include <packlib.h>
+
+#define PAWC_SIZE 50000
+
+typedef struct { float PAW[PAWC_SIZE]; } PAWC_DEF;
+#define PAWC COMMON_BLOCK(PAWC,pawc)
+COMMON_BLOCK_DEF(PAWC_DEF,PAWC);
+
+main()
+{
+   int hid=1,istat=0,icycle=0;
+   int i,i1,j;
+   int nvar;
+   float r[3];
+   char chtag_in[3][6]={"X","Y","Z"};
+   char chtag_out[5][8],chtitl[80];
+   float rmin[5],rmax[5];
+   int record_size=1024;
+
+   HLIMIT(PAWC_SIZE);
+   HROPEN(1,"example","ntuple-example.hbook","N",record_size,istat);
+   HBOOKN(hid," An Ntuple",3," ",5000,chtag_in);
+
+   for (i=0;i<10000;i++){
+      for(i1=0;i1<3;i1++)
+         for (j=0,r[i1]=0.;j<10;r[i1] += rand()/32768. -0.5 ,j++);
+            HFN(hid,r);
+   }
+   nvar=5;
+   HGIVEN(hid,chtitl,nvar,chtag_out,rmin,rmax);
+   printf(" title obtained:%s\n variables %d\ntags:>%s< >%s< >%s<\n",
+            chtitl,nvar,chtag_out[0],chtag_out[1],chtag_out[2]);
+   printf(" rmin: %e  %e  %e\n",rmin[0],rmin[1],rmin[2]);
+   printf(" rmax: %e  %e  %e\n",rmax[0],rmax[1],rmax[2]);
+
+   HROUT(0,icycle," ");
+   HREND("example");
+   KUCLOS(1," ",1);
+}
Index: /trunk/SophyaExt/CodeMinuit/cfortran/Examples/minuit-fcn.c
===================================================================
--- /trunk/SophyaExt/CodeMinuit/cfortran/Examples/minuit-fcn.c	(revision 2414)
+++ /trunk/SophyaExt/CodeMinuit/cfortran/Examples/minuit-fcn.c	(revision 2414)
@@ -0,0 +1,30 @@
+#include <math.h>
+#include <string.h>
+
+void fcn(int npar, double grad[3], double * fcnval,
+           double xval[2],int iflag, void (*Dummy)())
+{
+      double Xc=1.11,Yc=3.14;
+/* 
+ *  demo FCN 
+ *  Gunter Folger, May 95
+ */
+
+	switch(iflag) {
+	  case 1:
+/*
+ *      Initialaise.
+ */
+		printf(" fcn_c called to initialise\n");
+		break;
+	  case 2:		
+/*
+ *        derivatives...
+ */
+		break;
+
+	  default:
+		*fcnval = pow(xval[0]-Xc,2.) + pow((xval[1]-Yc),3.)*xval[1];
+		break;
+	}      
+}
Index: /trunk/SophyaExt/CodeMinuit/cfortran/Examples/minuit-fcn.f
===================================================================
--- /trunk/SophyaExt/CodeMinuit/cfortran/Examples/minuit-fcn.f	(revision 2414)
+++ /trunk/SophyaExt/CodeMinuit/cfortran/Examples/minuit-fcn.f	(revision 2414)
@@ -0,0 +1,27 @@
+      Subroutine FCN(Npar,Grad,Fval,Xval,Iflag,Futil)
+      Implicit Double Precision (a-h,o-z)
+
+      Dimension Xval(*), Grad(*)
+
+      Data  Xc,Yc/1.11D0,3.14d0/
+* 
+*  demo FCN 
+*  Gunter Folger, December 94
+*
+
+       if ( Iflag.eq.1 ) Then
+*
+*      Initialaise.
+*
+       Elseif ( Iflag.eq.2) Then
+*
+*        derivatives...
+*
+       Endif
+
+       Fval = (Xval(1)-Xc)**2 + (Xval(2)-Yc)**3*Xval(2)
+
+       Return
+
+*      
+       End
Index: /trunk/SophyaExt/CodeMinuit/cfortran/Examples/minuit-main.c
===================================================================
--- /trunk/SophyaExt/CodeMinuit/cfortran/Examples/minuit-main.c	(revision 2414)
+++ /trunk/SophyaExt/CodeMinuit/cfortran/Examples/minuit-main.c	(revision 2414)
@@ -0,0 +1,48 @@
+/*
+ * This example demonstrate how to call MINUIT from C.
+ *
+ * For question/problems contact: Heplib.Support@cern.ch
+ *
+ */
+
+#if defined(__hpux) || defined(_IBMR2) || defined(__alpha) || defined(__apollo) || defined(__ultrix) || defined(__sgi) || defined(__sun) 
+#define extname
+#endif 
+
+#ifdef extname
+#define FCN fcn_
+#else
+#define FCN fcn
+#endif
+
+#include "cfortran.h"
+#include "minuit.h"
+#define Ncont 20
+int main()
+{
+	int error_flag=0;
+	void *fcn();
+	struct {
+		double x[Ncont];
+		double y[Ncont];
+		int n;
+		} pts;
+	double f_null=0.;
+	
+
+	MNINIT(5,6,7);   /*  initialise  */
+
+	MNSETI(" Minuit Example ");   /* set title */
+
+	MNPARM(1,"X",0.,.1,f_null,f_null,error_flag);
+
+	MNPARM(2,"-Y-",0.,.01,f_null,f_null,error_flag);
+
+	MNEXCM(fcn,"MIGRAD",0,0,error_flag,0);
+
+	MNEXCM(fcn,"MINOS",0,0,error_flag,0);
+
+	MNCONT(fcn,1,2,Ncont,pts.x[0],pts.y[0],pts.n, 0);
+
+}
+
Index: /trunk/SophyaExt/CodeMinuit/cfortran/Examples/pamain.c
===================================================================
--- /trunk/SophyaExt/CodeMinuit/cfortran/Examples/pamain.c	(revision 2414)
+++ /trunk/SophyaExt/CodeMinuit/cfortran/Examples/pamain.c	(revision 2414)
@@ -0,0 +1,23 @@
+#include <stdlib.h>
+#include <cfortran.h>
+#include <paw.h>
+#include <kuip.h>
+
+#define PAWC_SIZE 9000000
+
+typedef struct { float PAW[PAWC_SIZE]; } PAWC_DEF;
+#define PAWC COMMON_BLOCK(PAWC,pawc)
+COMMON_BLOCK_DEF(PAWC_DEF,PAWC);
+
+int main()
+{
+      int iwtyp;
+
+      PAW(PAWC_SIZE,iwtyp);
+
+      KUWHAG();
+
+      PAEXIT();
+
+      return 0;
+}
Index: /trunk/SophyaExt/CodeMinuit/cfortran/Examples/read_rwntuple.c
===================================================================
--- /trunk/SophyaExt/CodeMinuit/cfortran/Examples/read_rwntuple.c	(revision 2414)
+++ /trunk/SophyaExt/CodeMinuit/cfortran/Examples/read_rwntuple.c	(revision 2414)
@@ -0,0 +1,60 @@
+#include <stdlib.h>
+#include <cfortran.h>
+#include <packlib.h>
+
+#define Memory_Size 50000
+#define Number_of_Variables 27
+#define Number_of_Events 10
+
+typedef struct { float PAW[Memory_Size]; } PAWC_DEF;
+#define PAWC COMMON_BLOCK(PAWC,pawc)
+COMMON_BLOCK_DEF(PAWC_DEF,PAWC);
+
+main()
+{
+   int istat  = 0;
+   int icycle = 0;
+   int i,j,Ierr;
+   int IDN = 0;
+   int record_size = 1024;
+
+   float Event[Number_of_Variables];
+   char Chtags[Number_of_Variables][3] = 
+                  {"A1","A2","A3","A4","A5","A6","A7","A8","A9",
+                   "B1","B2","B3","B4","B5","B6","B7","B8","B9",
+                   "C1","C2","C3","C4","C5","C6","C7","C8","C9"};
+
+   HLIMIT(Memory_Size);
+
+   HROPEN(1,"EXAMPLE","example.hbook","N",record_size,istat);
+   if (istat != 0) {
+      printf("Error in opening file ...\n");
+      exit;
+   }
+
+   HBOOKN(10,"Ntuple example",Number_of_Variables,"//EXAMPLE",9000,Chtags);
+
+   for (i=1; i<=Number_of_Events; i++) {
+      for (j=0; j<Number_of_Variables; j++) {
+         Event[j] = (float)i*(float)(j+1);
+      }
+      HFN(10,Event);
+   }
+
+   HROUT(0,icycle," ");
+   HREND("EXAMPLE");
+   KUCLOS(1," ",1);
+/*
+ *       Read back the ntuple 10
+ */
+   HROPEN(1,"EXAMPLE","example.hbook","U",record_size,istat);
+   HRIN(10,9999,0);
+
+   for (i=1; i<=10; i++) {
+      HGN(10,IDN,i,Event,Ierr);
+      printf("%f %f %f \n", Event[0],Event[1],Event[2]);
+   }
+
+   HREND("EXAMPLE");
+   KUCLOS(1," ",1);
+}
