瀏覽代碼

remove warnings

richarddobson 2 年之前
父節點
當前提交
818e1c2507
共有 11 個文件被更改,包括 9379 次插入9383 次删除
  1. 152 152
      dev/tabedit/columns.c
  2. 596 595
      dev/tabedit/columns0.c
  3. 933 933
      dev/tabedit/columns1.c
  4. 249 251
      dev/tabedit/columns2.c
  5. 148 148
      dev/tabedit/columns3.c
  6. 981 982
      dev/tabedit/columns4.c
  7. 4510 4510
      dev/tabedit/columns5.c
  8. 479 479
      dev/tabedit/columns6.c
  9. 190 191
      dev/tabedit/getcol.c
  10. 301 302
      dev/tabedit/putcol.c
  11. 840 840
      dev/tabedit/vectors.c

+ 152 - 152
dev/tabedit/columns.c

@@ -1,152 +1,152 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
-
-    The CDP System is free software; you can redistribute it
-    and/or modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    The CDP System is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with the CDP System; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-    02111-1307 USA
- *
- */
-
-
-
-#include <columns.h>
-
-void do_shuffle(int, int);
-
-/**************************** M_REPOS ********************************/
-
-int m_repos(int j)
-{
-	int n, m, k=cnt, OK, is_set = 0;
-	int zib = -ifactor, zab = ifactor;
-	for(n=0;n<k;n++) {
-		OK = 1;
-		if(n>j && !is_set) {
-			zib++;
-			zab++;
-			is_set = 1;
-		}
-		for(m=zib;m<zab;m++) {
-			if(n+m<0)	  continue;
-			if(n+m>=cnt)  break;
-			if(flteq(fmod(number[j],12.0),fmod(number[n+m],12.0))) {
-				OK = 0;
-				break;
-			}
-		}
-		if(OK) {
-		   do_shuffle(n,j);
-		   if(j>n)
-			   return(1);	/* list shuffled forward */
-		   return(0);		/* list not shuffled forward */
-		}
-	}
-	return(-1);
-}	   
-
-/**************************** F_REPOS ********************************/
-
-int f_repos(int j)
-{
-	int n, m, k=cnt-ifactor, OK, is_set = 0;
-	double interval;
-	int zib = -ifactor, zab = ifactor;
-	for(n=0;n<k;n++) {
-		OK = 1;
-		if(n>j && !is_set) {
-			zib++;
-			zab++;
-			is_set = 1;
-		}
-		for(m=zib;m<zab;m++) {
-			if(n+m<0)	  continue;
-			if(n+m>=cnt)  break;
-			interval = log(number[j]/number[n+m])/LOG_2_TO_BASE_E;
-			interval = fmod(fabs(interval),1.0);
-			if(interval<ONEMAX || interval>ONEMIN) {
-				OK = 0;
-				break;
-			}
-		}
-		if(OK) {
-		   do_shuffle(n,j);
-		   if(j>n)
-			   return(1);	/* list shuffled forward */
-		   return(0);		/* list not shuffled forward */
-		}
-	}
-	return(-1);
-}	   
-
-/**************************** DO_SHUFFLE ******************************/
-
-void do_shuffle(int n,int j)
-{
-	int m;
-	double keep = number[j];
-	if(j > n) {
-		for(m=j;m>n;m--)
-		   number[m] = number[m-1];
-	} else {
-		for(m=j;m<n;m++)
-			number[m] = number[m+1];
-	}
-	number[n] = keep;
-}
-
-/************************* CHECK_FOR_CONDITIONAL ************************/
-
-void check_for_conditional(int *argc,char *argv[])
-{
-	int n;
-	char less_than, greater_than;
-	int condit_set = 0;
-
-	if(sloom) {
-		less_than = '@';
-		greater_than = '+';
-	} else {
-		less_than = '{';
-		greater_than = '}';
-	}
-	for(n=1;n<*argc;n++) {
-		if((condit = *argv[n])==less_than || condit==greater_than) {
-			if(condit==less_than)
-				condit = '<';
-			else
-				condit = '>';
-			argv[n]++;
-			if(sscanf(argv[n],"%lf",&thresh)!=1) {
-				sprintf(errstr,"Cannot read conditional value.\n");
-				do_error();
-			}
-			while(n<(*argc)-1) {
-				*(argv+n) = *(argv+n+1);
-				n++;
-			}
-			(*argc)--;
-			condit_set = 1;
-		}
-	}
-	if(!condit_set)
-		condit = 0;
-	if(*argc < 4) {
-		sprintf(errstr,"Too few arguments on commandline.\n");
-		do_error();
-	}
-}
+/*
+ * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
+ * http://www.trevorwishart.co.uk
+ * http://www.composersdesktop.com
+ *
+ This file is part of the CDP System.
+
+ The CDP System is free software; you can redistribute it
+ and/or modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The CDP System is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the CDP System; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA
+ *
+ */
+
+
+
+#include <columns.h>
+
+void do_shuffle(int, int);
+
+/**************************** M_REPOS ********************************/
+
+int m_repos(int j)
+{
+    int n, m, k=cnt, OK, is_set = 0;
+    int zib = -ifactor, zab = ifactor;
+    for(n=0;n<k;n++) {
+        OK = 1;
+        if(n>j && !is_set) {
+            zib++;
+            zab++;
+            is_set = 1;
+        }
+        for(m=zib;m<zab;m++) {
+            if(n+m<0)         continue;
+            if(n+m>=cnt)  break;
+            if(flteq(fmod(number[j],12.0),fmod(number[n+m],12.0))) {
+                OK = 0;
+                break;
+            }
+        }
+        if(OK) {
+            do_shuffle(n,j);
+            if(j>n)
+                return(1);   /* list shuffled forward */
+            return(0);           /* list not shuffled forward */
+        }
+    }
+    return(-1);
+}
+
+/**************************** F_REPOS ********************************/
+
+int f_repos(int j)
+{
+    int n, m, k=cnt-ifactor, OK, is_set = 0;
+    double interval;
+    int zib = -ifactor, zab = ifactor;
+    for(n=0;n<k;n++) {
+        OK = 1;
+        if(n>j && !is_set) {
+            zib++;
+            zab++;
+            is_set = 1;
+        }
+        for(m=zib;m<zab;m++) {
+            if(n+m<0)         continue;
+            if(n+m>=cnt)  break;
+            interval = log(number[j]/number[n+m])/LOG_2_TO_BASE_E;
+            interval = fmod(fabs(interval),1.0);
+            if(interval<ONEMAX || interval>ONEMIN) {
+                OK = 0;
+                break;
+            }
+        }
+        if(OK) {
+            do_shuffle(n,j);
+            if(j>n)
+                return(1);   /* list shuffled forward */
+            return(0);           /* list not shuffled forward */
+        }
+    }
+    return(-1);
+}
+
+/**************************** DO_SHUFFLE ******************************/
+
+void do_shuffle(int n,int j)
+{
+    int m;
+    double keep = number[j];
+    if(j > n) {
+        for(m=j;m>n;m--)
+            number[m] = number[m-1];
+    } else {
+        for(m=j;m<n;m++)
+            number[m] = number[m+1];
+    }
+    number[n] = keep;
+}
+
+/************************* CHECK_FOR_CONDITIONAL ************************/
+
+void check_for_conditional(int *argc,char *argv[])
+{
+    int n;
+    char less_than, greater_than;
+    int condit_set = 0;
+
+    if(sloom) {
+        less_than = '@';
+        greater_than = '+';
+    } else {
+        less_than = '{';
+        greater_than = '}';
+    }
+    for(n=1;n<*argc;n++) {
+        if((condit = *argv[n])==less_than || condit==greater_than) {
+            if(condit==less_than)
+                condit = '<';
+            else
+                condit = '>';
+            argv[n]++;
+            if(sscanf(argv[n],"%lf",&thresh)!=1) {
+                sprintf(errstr,"Cannot read conditional value.\n");
+                do_error();
+            }
+            while(n<(*argc)-1) {
+                *(argv+n) = *(argv+n+1);
+                n++;
+            }
+            (*argc)--;
+            condit_set = 1;
+        }
+    }
+    if(!condit_set)
+        condit = 0;
+    if(*argc < 4) {
+        sprintf(errstr,"Too few arguments on commandline.\n");
+        do_error();
+    }
+}

File diff suppressed because it is too large
+ 596 - 595
dev/tabedit/columns0.c


+ 933 - 933
dev/tabedit/columns1.c

@@ -5,20 +5,20 @@
  *
  *
  This file is part of the CDP System.
  This file is part of the CDP System.
 
 
-    The CDP System is free software; you can redistribute it
-    and/or modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    The CDP System is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with the CDP System; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-    02111-1307 USA
+ The CDP System is free software; you can redistribute it
+ and/or modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The CDP System is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the CDP System; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA
  *
  *
  */
  */
 
 
@@ -28,122 +28,122 @@
 
 
 #include <columns.h>
 #include <columns.h>
 
 
-#define CALCLIM   		0.001
-#define M 			7
-#define NSTACK 			50
-#define	MIDDLE_C_MIDI_OCTAVE	5
-#define CONVERT_LOG10_TO_LOG2	(double)3.321928
-#define LOW_A   		6.875	   /* Frequency of A below MIDI 0  */
+#define CALCLIM                 0.001
+#define M                       7
+#define NSTACK                  50
+#define MIDDLE_C_MIDI_OCTAVE    5
+#define CONVERT_LOG10_TO_LOG2   (double)3.321928
+#define LOW_A                   6.875      /* Frequency of A below MIDI 0  */
 
 
 
 
 
 
-double 	cntevents(double,double,double);
-int 	samesize(double,double,double,double,double);
-void 	approxtimes(double,double,int);
-void 	getetime(double,double,double,double,int);
-double 	gethibnd(double,double,double,double,double);
-double 	getlobnd(double,double,double,double,double);
-double 	refinesize(double,double,double,double,double,double);
-void	prnt_pitchclass(int,int);
-int		strgetfloat_db(char **,double *);
+double  cntevents(double,double,double);
+int     samesize(double,double,double,double,double);
+void    approxtimes(double,double,int);
+void    getetime(double,double,double,double,int);
+double  gethibnd(double,double,double,double,double);
+double  getlobnd(double,double,double,double,double);
+double  refinesize(double,double,double,double,double,double);
+void    prnt_pitchclass(int,int);
+int             strgetfloat_db(char **,double *);
 static void bublsort(void);
 static void bublsort(void);
 static void test_warp_data(void);
 static void test_warp_data(void);
 
 
-int		*cntr;
-char 	**strings = 0;
-char	*stringstore;
-int		stringscnt = 0;
-int	stringstoresize = 0, stringstart = 0;
+int             *cntr;
+char    **strings = 0;
+char    *stringstore;
+int             stringscnt = 0;
+int     stringstoresize = 0, stringstart = 0;
 
 
 /************************ TIMEVENTS ******************************
 /************************ TIMEVENTS ******************************
  *
  *
- * 	Generates event positions from startsize and end size
+ *      Generates event positions from startsize and end size
  *
  *
- *	Let start-time be T0 and end time be T1
- *	Let start size be S0 and end S1
+ *      Let start-time be T0 and end time be T1
+ *      Let start size be S0 and end S1
  *
  *
- *	number of event is given by :-
+ *      number of event is given by :-
  *
  *
- *		N = (T1-T0) log S1
- *		    -------    e__
- *		    (S1-S0)     S0
+ *              N = (T1-T0) log S1
+ *                  -------    e__
+ *                  (S1-S0)     S0
  *
  *
- *	In general this will be non-integral, and we should
- *	round N to an integer, and recalculate S1 by successive 
- *	approximation.
+ *      In general this will be non-integral, and we should
+ *      round N to an integer, and recalculate S1 by successive
+ *      approximation.
  *
  *
- *	Then positions of events are given by
- *	
- *	    for X = 0 to N		 (S1-S0)
- *					  ----- X
- *	T = (S1T0 - S0T1)   S0(T1 - T0)  (T1-T0)
- *	 s   -----------  + ----------  e 
- *	      (S1 - S0)      (S1 - S0)
+ *      Then positions of events are given by
  *
  *
- * 	If difference in eventsizes input to the main program is very small
- * 	then infinite values result. To avoid this we divert the calculation
- * 	to another routine (which assumes the input values are equal.
- * 	The value of CALCLIM  = 0.001. (LArger than usual i.e. 0.05)
+ *          for X = 0 to N               (S1-S0)
+ *                                        ----- X
+ *      T = (S1T0 - S0T1)   S0(T1 - T0)  (T1-T0)
+ *       s   -----------  + ----------  e
+ *            (S1 - S0)      (S1 - S0)
  *
  *
- *	If size values are so BIG that they exceed segment duration, 
- *	eventsize becomes segment duration and a Warning is printed.  
- *(1)	events approx same size.
- *(2)	events of different sizes, find the number of events which approx
- *	fit in the duration.
- *(3)	If there's only one event .. that's it.
- *(4)	Note the error (difference between approximated whole number of events
- *	and the actual,non-integer, number of events).
- *(5)	Calculate acceptable bounds on a new endeventsize, which will give 
- *	a better fit of the integer number of events within the given duration.
- *(6)	Find an acceptable final value for endeventsize by successive approx
- *	NB we don't know whether the function increases as d increases 
- *	so lobound may be > hibound. However, the maths of the method will 
- *	still work, just inverting the sense of the search!!
- *(7)	Calculate the inital times of the events.
+ *      If difference in eventsizes input to the main program is very small
+ *      then infinite values result. To avoid this we divert the calculation
+ *      to another routine (which assumes the input values are equal.
+ *      The value of CALCLIM  = 0.001. (LArger than usual i.e. 0.05)
+ *
+ *      If size values are so BIG that they exceed segment duration,
+ *      eventsize becomes segment duration and a Warning is printed.
+ *(1)   events approx same size.
+ *(2)   events of different sizes, find the number of events which approx
+ *      fit in the duration.
+ *(3)   If there's only one event .. that's it.
+ *(4)   Note the error (difference between approximated whole number of events
+ *      and the actual,non-integer, number of events).
+ *(5)   Calculate acceptable bounds on a new endeventsize, which will give
+ *      a better fit of the integer number of events within the given duration.
+ *(6)   Find an acceptable final value for endeventsize by successive approx
+ *      NB we don't know whether the function increases as d increases
+ *      so lobound may be > hibound. However, the maths of the method will
+ *      still work, just inverting the sense of the search!!
+ *(7)   Calculate the inital times of the events.
  *
  *
  * This function returns the number of events within the time-interval,
  * This function returns the number of events within the time-interval,
  * and returns the times of these events in the array-of-doubles pos.
  * and returns the times of these events in the array-of-doubles pos.
  */
  */
 
 
 int timevents(double intime0,double intime1,double insize0,double insize1)
 int timevents(double intime0,double intime1,double insize0,double insize1)
-{   
-	int    number;
-	double fnum, fnumber, error;
-	double lobound, hibound, duration;
-	if(flteq(insize0,0.0) || flteq(insize1,0.0)) {
-		sprintf(errstr,"Event size of zero encountered.\n");
-		do_error();
-	}
-	duration = (intime1-intime0);
-	if(duration<=0.0)   {
-		sprintf(errstr,"Inconsistent input times (2nd before 1st).\n");
-		do_error();
-	}
-	if(fabs(insize1-insize0)<CALCLIM)			/* 1 */
-		return(number = samesize(intime0,intime1,insize0,insize1,duration));
-	fnum     = cntevents(duration,insize0,insize1);	/* 2 */
-	number   = round(fnum);
-	if(number<=1)					/* 3 */
-		return(1);
-	pos = (double *)exmalloc((number+1) * sizeof(double));
-	fnumber = (double)(number);				/* 4 */
-	error   = fabs(fnum - fnumber);
-	lobound = insize1;					/* 5 */
-	hibound = insize1;
-	if(fnum<fnumber)
-		hibound = gethibnd(fnum,fnumber,insize1,insize0,duration);
-	if(fnum>fnumber)
-		lobound = getlobnd(fnum,fnumber,insize1,insize0,duration);
-	if(error > FLTERR) {				/* 6 */
-		if(lobound < hibound) /* LOBOUND is a HIGH SIZE for a LOW COUNT!! */
-		swap(&hibound,&lobound);
-		insize1 = refinesize(hibound,lobound,fnumber,error,duration,insize0);
-	} else {
-	  	insize1 = (hibound+lobound)/2;
-	}						/* 7 */
-	getetime(intime0,intime1,insize0,insize1,number);
-	pos[number] = intime1;
-	return(number+1);
+{
+    int    number;
+    double fnum, fnumber, error;
+    double lobound, hibound, duration;
+    if(flteq(insize0,0.0) || flteq(insize1,0.0)) {
+        sprintf(errstr,"Event size of zero encountered.\n");
+        do_error();
+    }
+    duration = (intime1-intime0);
+    if(duration<=0.0)   {
+        sprintf(errstr,"Inconsistent input times (2nd before 1st).\n");
+        do_error();
+    }
+    if(fabs(insize1-insize0)<CALCLIM)                       /* 1 */
+        return(number = samesize(intime0,intime1,insize0,insize1,duration));
+    fnum     = cntevents(duration,insize0,insize1); /* 2 */
+    number   = round(fnum);
+    if(number<=1)                                   /* 3 */
+        return(1);
+    pos = (double *)exmalloc((number+1) * sizeof(double));
+    fnumber = (double)(number);                             /* 4 */
+    error   = fabs(fnum - fnumber);
+    lobound = insize1;                                      /* 5 */
+    hibound = insize1;
+    if(fnum<fnumber)
+        hibound = gethibnd(fnum,fnumber,insize1,insize0,duration);
+    if(fnum>fnumber)
+        lobound = getlobnd(fnum,fnumber,insize1,insize0,duration);
+    if(error > FLTERR) {                            /* 6 */
+        if(lobound < hibound) /* LOBOUND is a HIGH SIZE for a LOW COUNT!! */
+            swap(&hibound,&lobound);
+        insize1 = refinesize(hibound,lobound,fnumber,error,duration,insize0);
+    } else {
+        insize1 = (hibound+lobound)/2;
+    }                                               /* 7 */
+    getetime(intime0,intime1,insize0,insize1,number);
+    pos[number] = intime1;
+    return(number+1);
 }
 }
 
 
 /*************************** CNTEVENTS *****************************/
 /*************************** CNTEVENTS *****************************/
@@ -151,36 +151,36 @@ int timevents(double intime0,double intime1,double insize0,double insize1)
 double cntevents(double dur,double s0,double s1)
 double cntevents(double dur,double s0,double s1)
 {   double f1,f2;
 {   double f1,f2;
 
 
-	f1  = dur;
-	f2  = s1-s0;
-	f1 /= f2;
-	f2  = s1/s0;
-	f2  = log(f2);
-	f1 *= f2;
-	return(fabs(f1));
+    f1  = dur;
+    f2  = s1-s0;
+    f1 /= f2;
+    f2  = s1/s0;
+    f2  = log(f2);
+    f1 *= f2;
+    return(fabs(f1));
 }
 }
 
 
 /******************************* SAMESIZE *******************************
 /******************************* SAMESIZE *******************************
  *
  *
  * get event positions, if eventsize approx same throughout segment.
  * get event positions, if eventsize approx same throughout segment.
  *
  *
- *(1)	Get average size, find number of events and round to nearest int.
- *(3)	Recalculate size, and thence event times.
+ *(1)   Get average size, find number of events and round to nearest int.
+ *(3)   Recalculate size, and thence event times.
  */
  */
 
 
 int samesize
 int samesize
 (double intime0,double intime1,double insize0,double insize1,double duration)
 (double intime0,double intime1,double insize0,double insize1,double duration)
 {
 {
-	int	number;
-	double fnum, size;					/* 1 */
-	size   = (insize0+insize1)/2;
-	fnum   = duration/size;
-	number = round(fnum);
-	size   = duration/(double)(number);
-	pos	= (double *)exmalloc((number+1) * sizeof(double));
-	approxtimes(intime0,size,number);
-	pos[number] = intime1;
-	return(number+1);
+    int     number;
+    double fnum, size;                                      /* 1 */
+    size   = (insize0+insize1)/2;
+    fnum   = duration/size;
+    number = round(fnum);
+    size   = duration/(double)(number);
+    pos     = (double *)exmalloc((number+1) * sizeof(double));
+    approxtimes(intime0,size,number);
+    pos[number] = intime1;
+    return(number+1);
 }
 }
 
 
 /************************ APPROXTIME ***************************
 /************************ APPROXTIME ***************************
@@ -189,13 +189,13 @@ int samesize
  */
  */
 
 
 void approxtimes(double intime0,double size,int number)
 void approxtimes(double intime0,double size,int number)
-{   int k; 
-	double *q = pos;
-	*q++ = intime0;
-	for(k=1;k<number;k++) {
-		*q = *(q-1) + size;
-		q++;
-	}
+{   int k;
+    double *q = pos;
+    *q++ = intime0;
+    for(k=1;k<number;k++) {
+        *q = *(q-1) + size;
+        q++;
+    }
 }
 }
 
 
 /******************************* GETETIME ********************************
 /******************************* GETETIME ********************************
@@ -205,22 +205,22 @@ void approxtimes(double intime0,double size,int number)
 
 
 void getetime(double t0,double t1,double s0,double s1,int number)
 void getetime(double t0,double t1,double s0,double s1,int number)
 {   int n;
 {   int n;
-	double sdiff = s1-s0, tdiff = t1-t0, d1, d2, d3, *q = pos;
-	*q++ = t0;
-	for(n=1;n<number;n++)   {
-		d1	= sdiff/tdiff;
-		d1   *= (double)n;
-		d1    = exp(d1);
-		d2    = s0*tdiff;
-		d2   /= sdiff;
-		d1   *= d2;
-		d2    = s1*t0;
-		d3    = s0*t1;
-		d2   -= d3;
-		d2   /= sdiff;
-		d1   += d2;
-		*q++  = d1;
-	}
+    double sdiff = s1-s0, tdiff = t1-t0, d1, d2, d3, *q = pos;
+    *q++ = t0;
+    for(n=1;n<number;n++)   {
+        d1      = sdiff/tdiff;
+        d1   *= (double)n;
+        d1    = exp(d1);
+        d2    = s0*tdiff;
+        d2   /= sdiff;
+        d1   *= d2;
+        d2    = s1*t0;
+        d3    = s0*t1;
+        d2   -= d3;
+        d2   /= sdiff;
+        d1   += d2;
+        *q++  = d1;
+    }
 }
 }
 
 
 /****************************** GETHIBND *****************************
 /****************************** GETHIBND *****************************
@@ -229,34 +229,34 @@ void getetime(double t0,double t1,double s0,double s1,int number)
  * which will act as an UPPER BOUND to be used for searching
  * which will act as an UPPER BOUND to be used for searching
  * for an endsize that will give the integer number of events in the duration,
  * for an endsize that will give the integer number of events in the duration,
  *
  *
- * (0)	Start by REDUCING size, to give BIGGER fnum.
- *(1)  	If we're going downwards, (try -ve) and we go below zero,restore value
- * 	and subtract less.
- *(2)	If the fnums are moving in the opposite direction to what we expect, 
- *	restore values and increment in the opposite direction,but only half 
- *	as much!
+ * (0)  Start by REDUCING size, to give BIGGER fnum.
+ *(1)   If we're going downwards, (try -ve) and we go below zero,restore value
+ *      and subtract less.
+ *(2)   If the fnums are moving in the opposite direction to what we expect,
+ *      restore values and increment in the opposite direction,but only half
+ *      as much!
  */
  */
 
 
 double gethibnd(double fnum,double fnumber,double insize1,
 double gethibnd(double fnum,double fnumber,double insize1,
-		double insize0,double duration)
-{   double lastfnum, try = -1.0;	/* 0 */
-	double bound = insize1;
-	while(fnum<fnumber)  {
-		lastfnum = fnum;
-		bound += try;
-		while(bound<=0)  {				/* 1 */
-			bound -= try;
-			try /= 2.0;
-			bound += try;
-		}
-		fnum  = cntevents(duration,insize0,bound);
-		if(fnum<lastfnum)  {				/* 2 */
-			fnum=lastfnum;
-			bound -= try;		
-			try	 = -(try/2.0);
-   		}
-	}
-	return(bound);
+                double insize0,double duration)
+{   double lastfnum, try = -1.0;        /* 0 */
+    double bound = insize1;
+    while(fnum<fnumber)  {
+        lastfnum = fnum;
+        bound += try;
+        while(bound<=0)  {                              /* 1 */
+            bound -= try;
+            try /= 2.0;
+            bound += try;
+        }
+        fnum  = cntevents(duration,insize0,bound);
+        if(fnum<lastfnum)  {                            /* 2 */
+            fnum=lastfnum;
+            bound -= try;
+            try      = -(try/2.0);
+        }
+    }
+    return(bound);
 }
 }
 
 
 /****************************** GETLOBND *****************************
 /****************************** GETLOBND *****************************
@@ -268,36 +268,36 @@ double gethibnd(double fnum,double fnumber,double insize1,
  *
  *
  * LOBOUND is a LARGER value of SIZE to give SMALLER value of NUM-OF-SEGS.
  * LOBOUND is a LARGER value of SIZE to give SMALLER value of NUM-OF-SEGS.
  *
  *
- * (0)	Start by INCREASING size, to give SMALLER fnum.
- * (1)	If we're going downwards, (try -ve) and we go below zero, restore 
- *	propr value of bound, value and subtract less.
- * (2)	If the fnums are moving in the opposite direction to what we expect, 
- *	(fnum > lastfnum, while we're trying to DECREASE fnum)
- *	restore values and increment in the opposite direction,but only half 
- *	as much!
+ * (0)  Start by INCREASING size, to give SMALLER fnum.
+ * (1)  If we're going downwards, (try -ve) and we go below zero, restore
+ *      propr value of bound, value and subtract less.
+ * (2)  If the fnums are moving in the opposite direction to what we expect,
+ *      (fnum > lastfnum, while we're trying to DECREASE fnum)
+ *      restore values and increment in the opposite direction,but only half
+ *      as much!
  */
  */
 
 
 double getlobnd(double fnum,double fnumber,double insize1,
 double getlobnd(double fnum,double fnumber,double insize1,
-		double insize0,double duration)
+                double insize0,double duration)
 {   double try = 1.0;
 {   double try = 1.0;
-	double lastfnum;
-	double bound = insize1;
-	while(fnum>fnumber)  {
-		lastfnum = fnum;
-		bound += try;
-		while(bound<=0)  {
-			bound -= try;
-			try /= 2;
-			bound += try;
-		}
-		fnum  = cntevents(duration,insize0,bound);
-		if(fnum>lastfnum)  {
-			fnum =lastfnum;
-			bound -= try;		
-			try = -(try/2);
-		}
-	}
-	return(bound);
+    double lastfnum;
+    double bound = insize1;
+    while(fnum>fnumber)  {
+        lastfnum = fnum;
+        bound += try;
+        while(bound<=0)  {
+            bound -= try;
+            try /= 2;
+            bound += try;
+        }
+        fnum  = cntevents(duration,insize0,bound);
+        if(fnum>lastfnum)  {
+            fnum =lastfnum;
+            bound -= try;
+            try = -(try/2);
+        }
+    }
+    return(bound);
 }
 }
 
 
 /***************************** REFINESIZE ******************************
 /***************************** REFINESIZE ******************************
@@ -306,220 +306,220 @@ double getlobnd(double fnum,double fnumber,double insize1,
  */
  */
 
 
 double refinesize(double hibound,double lobound,double fnumber,
 double refinesize(double hibound,double lobound,double fnumber,
-		  double error,double duration,double insize0)
+                  double error,double duration,double insize0)
 {   double size = (hibound+lobound)/2, fnum;
 {   double size = (hibound+lobound)/2, fnum;
-	while(error>(FLTERR))   {
-		size = (hibound+lobound)/2;
-		fnum  = cntevents(duration,insize0,size);
-		error = fabs(fnumber-fnum);
-		if(error>FLTERR)  {
-			if(fnum<fnumber)
-			lobound = size;
-		else
-			hibound = size;
-		}
-	}
-	return(size);
+    while(error>(FLTERR))   {
+        size = (hibound+lobound)/2;
+        fnum  = cntevents(duration,insize0,size);
+        error = fabs(fnumber-fnum);
+        if(error>FLTERR)  {
+            if(fnum<fnumber)
+                lobound = size;
+            else
+                hibound = size;
+        }
+    }
+    return(size);
 }
 }
 
 
 /**************************STRGETFLOAT **************************
 /**************************STRGETFLOAT **************************
- * takes a pointer TO A POINTER to a string. If it succeeds in finding 
+ * takes a pointer TO A POINTER to a string. If it succeeds in finding
  * a float it returns the float value (*val), and it's new position in the
  * a float it returns the float value (*val), and it's new position in the
  * string (*str).
  * string (*str).
  */
  */
 
 
 int  strgetfloat(char **str,double *val)
 int  strgetfloat(char **str,double *val)
 {   char *p, *q, *end;
 {   char *p, *q, *end;
-	double numero;
-	int	point, valid;
-	for(;;) {
-		point = 0;
-		p = *str;
-		while(isspace(*p))
-			p++;
-		q = p;	
-		if(!isdigit(*p) && *p != '.' && *p!='-')
-			return(0);
-		if(*p == '.'|| *p == '-') {
-			if(*p == '-') {
-				p++;
-			} else {
-				point++;
-					p++;
-			}
-		}
-		for(;;) {
-			if(*p == '.') {
-				if(point)
-					return(0);
-				else {
-					point++;
-					p++;
-					continue;
-				}
-			}
-			if(isdigit(*p)) {
-				p++;
-				continue;
-			} else {
-				if(!isspace(*p) && *p!=ENDOFSTR)
-					return(0);
-				else {
-					end = p;
-				    p = q;
-					valid = 0;
-		    		while(p!=end) {
-					   	if(isdigit(*p))
-					  		valid++;
-						p++;
-					}
-					if(valid) {
-			 			if(sscanf(q,"%lf",&numero)!=1)
-							return(0);
-						*val = numero;
-					   *str = end;
-						return(1);
-					}
-					return(0);
-				}
-			}
- 		}
-	}
-	return(0);				/* NOTREACHED */
+    double numero;
+    int     point, valid;
+    for(;;) {
+        point = 0;
+        p = *str;
+        while(isspace(*p))
+            p++;
+        q = p;
+        if(!isdigit(*p) && *p != '.' && *p!='-')
+            return(0);
+        if(*p == '.'|| *p == '-') {
+            if(*p == '-') {
+                p++;
+            } else {
+                point++;
+                p++;
+            }
+        }
+        for(;;) {
+            if(*p == '.') {
+                if(point)
+                    return(0);
+                else {
+                    point++;
+                    p++;
+                    continue;
+                }
+            }
+            if(isdigit(*p)) {
+                p++;
+                continue;
+            } else {
+                if(!isspace(*p) && *p!=ENDOFSTR)
+                    return(0);
+                else {
+                    end = p;
+                    p = q;
+                    valid = 0;
+                    while(p!=end) {
+                        if(isdigit(*p))
+                            valid++;
+                        p++;
+                    }
+                    if(valid) {
+                        if(sscanf(q,"%lf",&numero)!=1)
+                            return(0);
+                        *val = numero;
+                        *str = end;
+                        return(1);
+                    }
+                    return(0);
+                }
+            }
+        }
+    }
+    return(0);                              /* NOTREACHED */
 }
 }
 
 
 /**************************STRGETFLOAT_DB **************************
 /**************************STRGETFLOAT_DB **************************
- * takes a pointer TO A POINTER to a string. If it succeeds in finding 
+ * takes a pointer TO A POINTER to a string. If it succeeds in finding
  * a float it returns the float value (*val), and it's new position in the
  * a float it returns the float value (*val), and it's new position in the
- * string (*str).	  IT JUMPS OVER 'db'
+ * string (*str).         IT JUMPS OVER 'db'
  */
  */
 
 
 int  strgetfloat_db(char **str,double *val)
 int  strgetfloat_db(char **str,double *val)
 {
 {
-	char *p, *q, *end;
-	double numero;
-	int    point, valid;
-	for(;;) {
-		point = 0;
-		p = *str;
-		while(isspace(*p))
-			p++;
-		q = p;	
-		if(!isdigit(*p) && *p != '.' && *p!='-')
-			return(0);
-		if(*p == '.'|| *p == '-') {
-			if(*p == '-') {
-				p++;
-			} else {
-				point++;
-				p++;
-			}
-		}
-		for(;;) {
-			if(*p == '.') {
-				if(point)
-					return(0);
-				else {
-					point++;
-					p++;
-					continue;
-				}
-			}
-			if(isdigit(*p)) {
-				p++;
-				continue;
-			} else {
-				if(!isspace(*p) && *p!=ENDOFSTR && !(*p=='d' || *p=='D') && !(*(p+1)!='b' || *(p+1)!='B'))
-					return(0);
-				else {
-					end = p;
-					p = q;
-					valid = 0;
-					while(p!=end) {
-						if(isdigit(*p))
-							valid++;
-						p++;
-					}
-					if(*end=='d' || *end=='D')
-						end += 2;
-					if(valid) {
-						if(sscanf(q,"%lf",&numero)!=1)
-							return(0);
-						*val = numero;
-						*str = end;
-						return(1);
-					}
-					return(0);
-				}
-			}
-		}
-	}
-	return(0);	   		 /* NOTREACHED */
+    char *p, *q, *end;
+    double numero;
+    int    point, valid;
+    for(;;) {
+        point = 0;
+        p = *str;
+        while(isspace(*p))
+            p++;
+        q = p;
+        if(!isdigit(*p) && *p != '.' && *p!='-')
+            return(0);
+        if(*p == '.'|| *p == '-') {
+            if(*p == '-') {
+                p++;
+            } else {
+                point++;
+                p++;
+            }
+        }
+        for(;;) {
+            if(*p == '.') {
+                if(point)
+                    return(0);
+                else {
+                    point++;
+                    p++;
+                    continue;
+                }
+            }
+            if(isdigit(*p)) {
+                p++;
+                continue;
+            } else {
+                if(!isspace(*p) && *p!=ENDOFSTR && !(*p=='d' || *p=='D') && !(*(p+1)!='b' || *(p+1)!='B'))
+                    return(0);
+                else {
+                    end = p;
+                    p = q;
+                    valid = 0;
+                    while(p!=end) {
+                        if(isdigit(*p))
+                            valid++;
+                        p++;
+                    }
+                    if(*end=='d' || *end=='D')
+                        end += 2;
+                    if(valid) {
+                        if(sscanf(q,"%lf",&numero)!=1)
+                            return(0);
+                        *val = numero;
+                        *str = end;
+                        return(1);
+                    }
+                    return(0);
+                }
+            }
+        }
+    }
+    return(0);                       /* NOTREACHED */
 }
 }
 
 
 /**************************STRGETSTR ***************************/
 /**************************STRGETSTR ***************************/
 
 
 int  strgetstr(char **str,char *str2)
 int  strgetstr(char **str,char *str2)
-{   
-	char *p, *q, c;
-	p = *str;
-	while(isspace(*p))
-		p++;
-	if(*p == ENDOFSTR)
-		return(0);
-	q = p;
-	while(!isspace(*p))
-		p++;
-	c = *p;
-	*p = ENDOFSTR;
-	strcpy(str2,q);
-	*p = c;
-	*str = p;
-	return(1);
-}	
+{
+    char *p, *q, c;
+    p = *str;
+    while(isspace(*p))
+        p++;
+    if(*p == ENDOFSTR)
+        return(0);
+    q = p;
+    while(!isspace(*p))
+        p++;
+    c = *p;
+    *p = ENDOFSTR;
+    strcpy(str2,q);
+    *p = c;
+    *str = p;
+    return(1);
+}
 
 
 /************************** HZTOMIDI ************************/
 /************************** HZTOMIDI ************************/
 
 
 double miditohz(double midi)
 double miditohz(double midi)
 {   double frq;
 {   double frq;
-	frq  = midi;
-	frq += 3.0;
-	frq /= 12.0;
-	frq  = pow((double)2,frq);
-	frq *= LOW_A;
-	return(frq);
+    frq  = midi;
+    frq += 3.0;
+    frq /= 12.0;
+    frq  = pow((double)2,frq);
+    frq *= LOW_A;
+    return(frq);
 }
 }
 
 
 /****************************** MIDITOHZ *************************/
 /****************************** MIDITOHZ *************************/
 
 
 double hztomidi(double hz)
 double hztomidi(double hz)
 {   double midi;
 {   double midi;
-	midi  = hz;
-	midi /= LOW_A;
-	midi  = log10(midi) * CONVERT_LOG10_TO_LOG2;
-	midi *= 12.0;
-	midi -= 3.0;
-	return(midi);
+    midi  = hz;
+    midi /= LOW_A;
+    midi  = log10(midi) * CONVERT_LOG10_TO_LOG2;
+    midi *= 12.0;
+    midi -= 3.0;
+    return(midi);
 }
 }
 
 
 /*********************** RNDPERM ************************/
 /*********************** RNDPERM ************************/
 
 
 void rndperm(double *z)
 void rndperm(double *z)
 {
 {
-	int n,t;
-	int k = cnt * sizeof(double);
-	permm = (double *)exmalloc(k*2);
-	memset((char *)permm,0,k*2);
-	permmm = permm + cnt;
-	for(n=0;n<cnt;n++) {
-		t = (int)(drand48() * (double)(n+1)); /* TRUNCATE */
-		if(t==n)
-			prefix(z,n);
-		else
-			insert(z,n,t);
-	}
-	memcpy((char *)z,(char *)permmm,k);
-	free(permm);
+    int n,t;
+    int k = cnt * sizeof(double);
+    permm = (double *)exmalloc(k*2);
+    memset((char *)permm,0,k*2);
+    permmm = permm + cnt;
+    for(n=0;n<cnt;n++) {
+        t = (int)(drand48() * (double)(n+1)); /* TRUNCATE */
+        if(t==n)
+            prefix(z,n);
+        else
+            insert(z,n,t);
+    }
+    memcpy((char *)z,(char *)permmm,k);
+    free(permm);
 }
 }
 
 
 /*********************** RNDPERM2 ************************
 /*********************** RNDPERM2 ************************
@@ -529,742 +529,742 @@ void rndperm(double *z)
 
 
 void rndperm2(double *z)
 void rndperm2(double *z)
 {   int n,t;
 {   int n,t;
-	int k = cnt * sizeof(double);
-	memset((char *)permm,0,k*2);
-	permmm = permm + cnt;
-	for(n=0;n<cnt;n++) {
-		t = (int)(drand48() * (double)(n+1)); /* TRUNCATE */
-		if(t==n)
-			prefix(z,n);
-		else
-			insert(z,n,t);
-	}
-	memcpy((char *)z,(char *)permmm,k);
+    int k = cnt * sizeof(double);
+    memset((char *)permm,0,k*2);
+    permmm = permm + cnt;
+    for(n=0;n<cnt;n++) {
+        t = (int)(drand48() * (double)(n+1)); /* TRUNCATE */
+        if(t==n)
+            prefix(z,n);
+        else
+            insert(z,n,t);
+    }
+    memcpy((char *)z,(char *)permmm,k);
 }
 }
 
 
 /*********************** MULTRNDPERM ************************
 /*********************** MULTRNDPERM ************************
- *	START
- *	  orig      orig     orig
- *	|--------|--------|--------|
- *	1ST PERM
+ *      START
+ *        orig      orig     orig
+ *      |--------|--------|--------|
+ *      1ST PERM
  *        perm1     orig     orig
  *        perm1     orig     orig
- *	|--------|--------|--------|
- *	NEXT PERM
+ *      |--------|--------|--------|
+ *      NEXT PERM
  *        perm1     perm2    orig
  *        perm1     perm2    orig
- *	|--------|--------|--------|
- *	MEMCPY
+ *      |--------|--------|--------|
+ *      MEMCPY
  *     perm1=perm2  orig     orig
  *     perm1=perm2  orig     orig
- *	|--------|--------|--------|
- *	go to NEXT PERM
+ *      |--------|--------|--------|
+ *      go to NEXT PERM
  */
  */
 
 
 void multrndperm(double *blok1)
 void multrndperm(double *blok1)
 {   int n, m;
 {   int n, m;
-	double lastenditem, *blok2, *blok3;
-	int oneblok	= cnt * sizeof(double);
-	int twobloks   = oneblok*2;
+    double lastenditem, *blok2, *blok3;
+    int oneblok     = cnt * sizeof(double);
+    int twobloks   = oneblok*2;
     int threebloks = oneblok*3;
     int threebloks = oneblok*3;
-	blok1 = (double *)exrealloc((char *)blok1,threebloks);
-	blok2 = blok1 + cnt;
-	blok3 = blok2 + cnt;
+    blok1 = (double *)exrealloc((char *)blok1,threebloks);
+    blok2 = blok1 + cnt;
+    blok3 = blok2 + cnt;
     memcpy((char *)blok2,(char *)blok1,oneblok);
     memcpy((char *)blok2,(char *)blok1,oneblok);
-	memcpy((char *)blok3,(char *)blok1,oneblok);
-	permm = (double *)exmalloc(cnt * 2 * sizeof(double));
-	rndperm2(blok1);			/* perm 1st copy */
-	for(n=0;n<cnt;n++)
-		do_valout(blok1[n]);
-	for(m=1;m<ifactor;m++) {	/* now do perms on 2nd copy */
- 	   lastenditem = *(blok2-1);
-		do {
- 			rndperm2(blok2);
-		} while(blok2[0]==lastenditem);
-			 /* Avoid element repeat at block boundaries */
-		for(n=0;n<cnt;n++)
-			do_valout(blok2[n]);
-		memcpy((char *)blok1,(char *)blok2,twobloks); 
-			/* Move perm along & restore orig set */
-	}
- 	fflush(stdout);
-	free(permm);
+    memcpy((char *)blok3,(char *)blok1,oneblok);
+    permm = (double *)exmalloc(cnt * 2 * sizeof(double));
+    rndperm2(blok1);                        /* perm 1st copy */
+    for(n=0;n<cnt;n++)
+        do_valout(blok1[n]);
+    for(m=1;m<ifactor;m++) {        /* now do perms on 2nd copy */
+        lastenditem = *(blok2-1);
+        do {
+            rndperm2(blok2);
+        } while(blok2[0]==lastenditem);
+        /* Avoid element repeat at block boundaries */
+        for(n=0;n<cnt;n++)
+            do_valout(blok2[n]);
+        memcpy((char *)blok1,(char *)blok2,twobloks);
+        /* Move perm along & restore orig set */
+    }
+    fflush(stdout);
+    free(permm);
 }
 }
 
 
 /************************** INSERT *************************/
 /************************** INSERT *************************/
 
 
 void insert(double *z,int m,int t)
 void insert(double *z,int m,int t)
 {
 {
-	shuffle(t+1,m);
-	permmm[t+1] = z[m];
+    shuffle(t+1,m);
+    permmm[t+1] = z[m];
 }
 }
 
 
 /************************** PREFIX ***************************/
 /************************** PREFIX ***************************/
 
 
 void prefix(double *z,int m)
 void prefix(double *z,int m)
 {   permmm--;
 {   permmm--;
-	permmm[0] = z[m];
+    permmm[0] = z[m];
 }
 }
 
 
 /*************************** SHUFFLE ***********************/
 /*************************** SHUFFLE ***********************/
 
 
 void shuffle(int k,int m)
 void shuffle(int k,int m)
 {
 {
-	int n;
-	double *i;
-	if(k/2 > m) {	/* shuffle up */
-		i = &permmm[m];
-		for(n=m;n>k;n--) {
-			*i = *(i-1);
-			i--;
-		}
-	} else {		/* shuffle down */
-		i = &permmm[0];
-		for(n=0;n<k;n++) {
-			*(i-1) = *i;
-			i++;
-		}
-		permmm--;	/* Move base of perm down by 1 */
-	}
+    int n;
+    double *i;
+    if(k/2 > m) {   /* shuffle up */
+        i = &permmm[m];
+        for(n=m;n>k;n--) {
+            *i = *(i-1);
+            i--;
+        }
+    } else {                /* shuffle down */
+        i = &permmm[0];
+        for(n=0;n<k;n++) {
+            *(i-1) = *i;
+            i++;
+        }
+        permmm--;       /* Move base of perm down by 1 */
+    }
 }
 }
 
 
 /******************************** EXMALLOC ****************************/
 /******************************** EXMALLOC ****************************/
 
 
 char *exmalloc(int n)
 char *exmalloc(int n)
 {
 {
-	char *p;
-	if((p = (char *)malloc(n))==NULL) {
-		sprintf(errstr,"ERROR: Memory allocation failed\n");
-		do_error();
-	}
-	return(p);
+    char *p;
+    if((p = (char *)malloc(n))==NULL) {
+        sprintf(errstr,"ERROR: Memory allocation failed\n");
+        do_error();
+    }
+    return(p);
 }
 }
 
 
 /************************ READ_INPUT_FILE ****************************/
 /************************ READ_INPUT_FILE ****************************/
 
 
 void read_input_file(FILE *fpp)
 void read_input_file(FILE *fpp)
 {   char *p;
 {   char *p;
-	double *number2;
-	while(fgets(temp,20000,fpp)!=NULL) {
-		p = temp;
-		while(strgetfloat(&p,&number[cnt])) {
-			if(++cnt >= arraysize) {
-				arraysize += BIGARRAY;
-/* NOVEMBER 2001 NEW */
-				number2 = (double *)malloc(arraysize*sizeof(double));
-				memcpy((void *)number2,(void *)number,cnt * sizeof(double));
-				number = number2;
-/* NOVEMBER 2001 OLD			
-				number = (double *)exrealloc((char *)number,arraysize*sizeof(double));
-*/					
-			}
-		}
-	}
+    double *number2;
+    while(fgets(temp,20000,fpp)!=NULL) {
+        p = temp;
+        while(strgetfloat(&p,&number[cnt])) {
+            if(++cnt >= arraysize) {
+                arraysize += BIGARRAY;
+                /* NOVEMBER 2001 NEW */
+                number2 = (double *)malloc(arraysize*sizeof(double));
+                memcpy((void *)number2,(void *)number,cnt * sizeof(double));
+                number = number2;
+                /* NOVEMBER 2001 OLD
+                   number = (double *)exrealloc((char *)number,arraysize*sizeof(double));
+                */
+            }
+        }
+    }
 }
 }
 
 
 /************************* DO_INFILE ***************************/
 /************************* DO_INFILE ***************************/
 
 
 void do_infile(char *argv)
 void do_infile(char *argv)
 {
 {
-	char *p;
-	double *number2;
-	if((fp[0] = fopen(argv,"r"))==NULL) {
-		sprintf(errstr,"Cannot open infile %s\n",argv);
-		do_error();
-	}
-	while(fgets(temp,20000,fp[0])!=NULL) {
-		p = temp;
-		while(strgetfloat(&p,&number[cnt])) {
-			if(++cnt >= arraysize) {
-				arraysize += BIGARRAY;
-/* NOVEMBER 2001 NEW */
-				if((number2=(double *)malloc(arraysize*sizeof(double)))==NULL) {
-					sprintf(errstr,"Out of memory for more numbers at %d numbers\n",cnt);
-					do_error();
-				}
-				memcpy((void *)number2,(void *)number,cnt * sizeof(double));
-				number = number2;
-
-/* NOVEMBER 2001 OLD
-				if((number=(double *)exrealloc((char *)number,arraysize*sizeof(double)))==NULL) {
-					sprintf(errstr,"Out of memory for more numbers at %d numbers\n",cnt);
-					do_error();
-				}
-*/
-			}
-		}
-	}
-	if(cnt <=0) {
-		sprintf(errstr,"Invalid or missing data.\n");
-		do_error();
-	}
-	fclose(fp[0]);
+    char *p;
+    double *number2;
+    if((fp[0] = fopen(argv,"r"))==NULL) {
+        sprintf(errstr,"Cannot open infile %s\n",argv);
+        do_error();
+    }
+    while(fgets(temp,20000,fp[0])!=NULL) {
+        p = temp;
+        while(strgetfloat(&p,&number[cnt])) {
+            if(++cnt >= arraysize) {
+                arraysize += BIGARRAY;
+                /* NOVEMBER 2001 NEW */
+                if((number2=(double *)malloc(arraysize*sizeof(double)))==NULL) {
+                    sprintf(errstr,"Out of memory for more numbers at %d numbers\n",cnt);
+                    do_error();
+                }
+                memcpy((void *)number2,(void *)number,cnt * sizeof(double));
+                number = number2;
+
+                /* NOVEMBER 2001 OLD
+                   if((number=(double *)exrealloc((char *)number,arraysize*sizeof(double)))==NULL) {
+                   sprintf(errstr,"Out of memory for more numbers at %d numbers\n",cnt);
+                   do_error();
+                   }
+                */
+            }
+        }
+    }
+    if(cnt <=0) {
+        sprintf(errstr,"Invalid or missing data.\n");
+        do_error();
+    }
+    fclose(fp[0]);
 }
 }
 
 
 /************************* DO_DB_INFILE ***************************/
 /************************* DO_DB_INFILE ***************************/
 
 
 void do_DB_infile(char *argv)
 void do_DB_infile(char *argv)
 {
 {
-	char *p;
-	if((fp[0] = fopen(argv,"r"))==NULL) {
-		sprintf(errstr,"Cannot open infile %s\n",argv);
-		do_error();
-	}
-	while(fgets(temp,20000,fp[0])!=NULL) {
-		p = temp;
-		while(strgetfloat_db(&p,&number[cnt])) {
-			if(++cnt >= arraysize) {
-				arraysize += BIGARRAY;
-				number=(double *)exrealloc((char *)number,arraysize*sizeof(double));
-			}
-		}
-	}
-	if(cnt <=0) {
-		sprintf(errstr,"Invalid or missing data.\n");
-		do_error();
-	}
-	fclose(fp[0]);
+    char *p;
+    if((fp[0] = fopen(argv,"r"))==NULL) {
+        sprintf(errstr,"Cannot open infile %s\n",argv);
+        do_error();
+    }
+    while(fgets(temp,20000,fp[0])!=NULL) {
+        p = temp;
+        while(strgetfloat_db(&p,&number[cnt])) {
+            if(++cnt >= arraysize) {
+                arraysize += BIGARRAY;
+                number=(double *)exrealloc((char *)number,arraysize*sizeof(double));
+            }
+        }
+    }
+    if(cnt <=0) {
+        sprintf(errstr,"Invalid or missing data.\n");
+        do_error();
+    }
+    fclose(fp[0]);
 }
 }
 
 
 /************************* DO_PITCHTEXT_INFILE ***************************/
 /************************* DO_PITCHTEXT_INFILE ***************************/
 
 
 void do_pitchtext_infile(char *argv)
 void do_pitchtext_infile(char *argv)
 {
 {
-	char *p;
-	char temp2[200];
-	if((fp[0] = fopen(argv,"r"))==NULL) {
-		sprintf(errstr,"Cannot open infile %s\n",argv);
-		do_error();
-	}
-	while(fgets(temp,200,fp[0])!=NULL) {
-		p = temp;
-		while(strgetstr(&p,temp2)) {
-			number[cnt] = texttomidi(temp2);
-			if(++cnt >= arraysize) {
-				arraysize += BIGARRAY;
-				number=(double *)exrealloc((char *)number,arraysize*sizeof(double));
-			}
-		}
-	}
-	if(cnt <=0) {
-		sprintf(errstr,"ERROR: Invalid or missing data.\n");
-		do_error();
-	}
-	fclose(fp[0]);
+    char *p;
+    char temp2[200];
+    if((fp[0] = fopen(argv,"r"))==NULL) {
+        sprintf(errstr,"Cannot open infile %s\n",argv);
+        do_error();
+    }
+    while(fgets(temp,200,fp[0])!=NULL) {
+        p = temp;
+        while(strgetstr(&p,temp2)) {
+            number[cnt] = texttomidi(temp2);
+            if(++cnt >= arraysize) {
+                arraysize += BIGARRAY;
+                number=(double *)exrealloc((char *)number,arraysize*sizeof(double));
+            }
+        }
+    }
+    if(cnt <=0) {
+        sprintf(errstr,"ERROR: Invalid or missing data.\n");
+        do_error();
+    }
+    fclose(fp[0]);
 }
 }
 
 
 /************************* DO_OTHER_INFILE **********************/
 /************************* DO_OTHER_INFILE **********************/
 
 
 void do_other_infiles(char *argv[])
 void do_other_infiles(char *argv[])
-{   
-	int n;
-	if(infilecnt>2)
-		fp = (FILE **)exrealloc((char *)fp,infilecnt*sizeof(FILE *));
-	firstcnt = cnt;
-	for(n=1;n<infilecnt;n++) {
-		if((fp[n] = fopen(argv[n+1],"r"))==NULL) {
-			sprintf(errstr,"\nCannot open file %s to read.\n",argv[n+1]);
-			do_error();
-		}
-		read_input_file(fp[n]);
-		if (flag == 'A' && ro =='e') {
-			file_cnt[n] = cnt - firstcnt;
-			firstcnt = cnt;
-		} else if((flag=='J' || (flag=='C' && ro == 'c')) && cnt != firstcnt * (n+1)) {
-			sprintf(errstr,"Input file %d has wrong number of values to match previous column lengths.\n",n+1);
-			do_error();
-		}
-	}
-	if (flag == 'w' && (ro == 't' || ro == 'o')) {
-		test_warp_data();
-	}
+{
+    int n;
+    if(infilecnt>2)
+        fp = (FILE **)exrealloc((char *)fp,infilecnt*sizeof(FILE *));
+    firstcnt = cnt;
+    for(n=1;n<infilecnt;n++) {
+        if((fp[n] = fopen(argv[n+1],"r"))==NULL) {
+            sprintf(errstr,"\nCannot open file %s to read.\n",argv[n+1]);
+            do_error();
+        }
+        read_input_file(fp[n]);
+        if (flag == 'A' && ro =='e') {
+            file_cnt[n] = cnt - firstcnt;
+            firstcnt = cnt;
+        } else if((flag=='J' || (flag=='C' && ro == 'c')) && cnt != firstcnt * (n+1)) {
+            sprintf(errstr,"Input file %d has wrong number of values to match previous column lengths.\n",n+1);
+            do_error();
+        }
+    }
+    if (flag == 'w' && (ro == 't' || ro == 'o')) {
+        test_warp_data();
+    }
 }
 }
 
 
 /********************** DO_OUTFILE *****************************/
 /********************** DO_OUTFILE *****************************/
 
 
 void do_outfile(char *argv) {
 void do_outfile(char *argv) {
 
 
-	if((fp[1] = fopen(argv,"w"))==NULL) {
-		sprintf(errstr,"Cannot open file %s to write.\n",argv);
-		do_error();
-		exit(1);
-	}
+    if((fp[1] = fopen(argv,"w"))==NULL) {
+        sprintf(errstr,"Cannot open file %s to write.\n",argv);
+        do_error();
+        exit(1);
+    }
 }
 }
 
 
 /**************************** QIKSORT ******************************/
 /**************************** QIKSORT ******************************/
 
 
 void qiksort(void) {
 void qiksort(void) {
-	bublsort();
+    bublsort();
 }
 }
 
 
 /************************ BELLPERM1 ***************************/
 /************************ BELLPERM1 ***************************/
 
 
 void bellperm1(void)
 void bellperm1(void)
 {   int n;
 {   int n;
-	for(n=0;n<cnt;n+=2)
-		swap(&number[n], &number[n+1]);
+    for(n=0;n<cnt;n+=2)
+        swap(&number[n], &number[n+1]);
 }
 }
 
 
 /************************** BELLPERM2 ******************************/
 /************************** BELLPERM2 ******************************/
 
 
 void bellperm2(void)
 void bellperm2(void)
 {   int n;
 {   int n;
-	for(n=2;n<cnt;n+=2)
-		swap(&number[n], &number[n-1]);
+    for(n=2;n<cnt;n+=2)
+        swap(&number[n], &number[n-1]);
 }
 }
 
 
 /************************* BELLPERM3 ******************************/
 /************************* BELLPERM3 ******************************/
 
 
 void bellperm3(void)
 void bellperm3(void)
 {   int n;
 {   int n;
-	for(n=2;n<cnt;n+=2)
-		swap(&number[n], &number[n+1]);
+    for(n=2;n<cnt;n+=2)
+        swap(&number[n], &number[n+1]);
 }
 }
 
 
 /***************************** SWAP *******************************/
 /***************************** SWAP *******************************/
 
 
 void swap(double *d0,double *d1)
 void swap(double *d0,double *d1)
 {
 {
-	double temp = *d0;
-	*d0 = *d1;
-	*d1 = temp;
+    double temp = *d0;
+    *d0 = *d1;
+    *d1 = temp;
 }
 }
 
 
 /**************************** FLTEQ *******************************/
 /**************************** FLTEQ *******************************/
 
 
 int flteq(double f1,double f2)
 int flteq(double f1,double f2)
 {
 {
-	double upperbnd, lowerbnd;
-	upperbnd = f2 + FLTERR;		
-	lowerbnd = f2 - FLTERR;		
-	if((f1>upperbnd) || (f1<lowerbnd))
-		return(0);
-	return(1);
+    double upperbnd, lowerbnd;
+    upperbnd = f2 + FLTERR;
+    lowerbnd = f2 - FLTERR;
+    if((f1>upperbnd) || (f1<lowerbnd))
+        return(0);
+    return(1);
 }
 }
 
 
 /***************************** ELIMINATE ********************************/
 /***************************** ELIMINATE ********************************/
 
 
 void eliminate(int m)
 void eliminate(int m)
 {
 {
-	int n;
-	for(n=m+1;n<cnt;n++)
-		number[n-1] = number[n];
-	cnt--;
+    int n;
+    for(n=m+1;n<cnt;n++)
+        number[n-1] = number[n];
+    cnt--;
 }
 }
 
 
 /***************************** EXREALLOC *****************************/
 /***************************** EXREALLOC *****************************/
 
 
 char *exrealloc(char *p,int k)
 char *exrealloc(char *p,int k)
 {
 {
-	char *q;
-	q = exmalloc(k);
-	memcpy(q,p,k);
-	free(p);
-	return(q);
+    char *q;
+    q = exmalloc(k);
+    memcpy(q,p,k);
+    free(p);
+    return(q);
 }
 }
 
 
 /****************************** TEXTTOMIDI ******************************/
 /****************************** TEXTTOMIDI ******************************/
 
 
 double texttomidi(char *str)
 double texttomidi(char *str)
-{   
-	int pitch, octave, octshift = 0;
-	char *p = str;
-	if(!strncmp(str,"B#",2) || !strncmp(str,"b#",2))
-		octshift--;
-	if((str = get_pitchclass(str,&pitch,1))==(char *)0) {
-		sprintf(errstr,"Unknown pitch %s\n",p);
-		do_error();
-	}
-	if(sscanf(str,"%d",&octave)!=1) {
-		sprintf(errstr,"unknown pitch-string %s or no octave value\n",p);
-		do_error();
-	}
-	octave += (MIDDLE_C_MIDI_OCTAVE + octshift);
-	pitch  += (octave * 12);
-	return((double)pitch);
+{
+    int pitch, octave, octshift = 0;
+    char *p = str;
+    if(!strncmp(str,"B#",2) || !strncmp(str,"b#",2))
+        octshift--;
+    if((str = get_pitchclass(str,&pitch,1))==(char *)0) {
+        sprintf(errstr,"Unknown pitch %s\n",p);
+        do_error();
+    }
+    if(sscanf(str,"%d",&octave)!=1) {
+        sprintf(errstr,"unknown pitch-string %s or no octave value\n",p);
+        do_error();
+    }
+    octave += (MIDDLE_C_MIDI_OCTAVE + octshift);
+    pitch  += (octave * 12);
+    return((double)pitch);
 }
 }
 
 
 /****************************** GET_PITCHCLASS ******************************/
 /****************************** GET_PITCHCLASS ******************************/
 
 
 char *get_pitchclass(char *str,int *pitch,int with_octave)
 char *get_pitchclass(char *str,int *pitch,int with_octave)
 {
 {
-	switch(*str++) {
-	case('c'): case('C'): *pitch = 0; break;
-	case('d'): case('D'): *pitch = 2; break;
-	case('e'): case('E'): *pitch = 4; break;
-	case('f'): case('F'): *pitch = 5; break;
-	case('g'): case('G'): *pitch = 7; break;
-	case('a'): case('A'): *pitch = 9; break;
-	case('b'): case('B'): *pitch = 11; break;
-	default: return((char *)0);
-	}
-	switch(*str++) {
-	case('#'): 		(*pitch)++; break;
-	case('b'): 		(*pitch)--; break;
-	default: 		str--; 		break;
-	}
- 	if(with_octave) {
-		if(*str==ENDOFSTR)
-			return((char *)0);		
-	}
-	return(str);
+    switch(*str++) {
+    case('c'): case('C'): *pitch = 0; break;
+    case('d'): case('D'): *pitch = 2; break;
+    case('e'): case('E'): *pitch = 4; break;
+    case('f'): case('F'): *pitch = 5; break;
+    case('g'): case('G'): *pitch = 7; break;
+    case('a'): case('A'): *pitch = 9; break;
+    case('b'): case('B'): *pitch = 11; break;
+    default: return((char *)0);
+    }
+    switch(*str++) {
+    case('#'):              (*pitch)++; break;
+    case('b'):              (*pitch)--; break;
+    default:                str--;          break;
+    }
+    if(with_octave) {
+        if(*str==ENDOFSTR)
+            return((char *)0);
+    }
+    return(str);
 }
 }
 
 
 /******************************** LOGO() **********************************/
 /******************************** LOGO() **********************************/
 
 
 void logo(void)
 void logo(void)
 {   printf("\t    ***************************************************\n");
 {   printf("\t    ***************************************************\n");
-	printf("\t    *           COMPOSERS DESKTOP PROJECT             *\n");
-	printf("\t                   %s $Revision: 1.8 $\n",PROG);
-	printf("\t    *    Manipulate or Generate columns of numbers    *\n");
-	printf("\t    *                by TREVOR WISHART                *\n");
-	printf("\t    ***************************************************\n\n");
+    printf("\t    *           COMPOSERS DESKTOP PROJECT             *\n");
+    printf("\t                   %s $Revision: 1.8 $\n",PROG);
+    printf("\t    *    Manipulate or Generate columns of numbers    *\n");
+    printf("\t    *                by TREVOR WISHART                *\n");
+    printf("\t    ***************************************************\n\n");
 }
 }
 
 
 /****************************** PITCHTOTEXT ******************************/
 /****************************** PITCHTOTEXT ******************************/
 
 
 void pitchtotext(int midi)
 void pitchtotext(int midi)
 {   int oct, n;
 {   int oct, n;
-	int basetone;
-	double diff;
-	for(n=0;n<cnt;n++) {
-		if(midi) {
-			if(number[n] < MIDIMIN || number[n] > MIDIMAX) {
-				fprintf(stdout,"ERROR: MIDI value %d (%lf) is out of range for conversion to pitch.\n", n+1,number[n]);
-				fflush(stdout);
-				exit(1);
-			}
-		} else {
-			if(number[n] < MIDIMINFRQ || number[n] > MIDIMAXFRQ) {
-				fprintf(stdout,"ERROR: frq value %d (%lf) is out of range for conversion to pitch.\n", n+1,number[n]);
-				fflush(stdout);
-				exit(1);
-			}
-		}
-	}
-	for(n=0;n<cnt;n++) {
-		if(!midi)
-			number[n] = hztomidi(number[n]);
-		oct = (int)(number[n]/12.0);	/* TRUNCATE */
-		oct -= 5;
-		basetone = (int)floor(number[n]);
-		diff = number[n] - (double)basetone;
-		if(diff > .5)
-			basetone++;
-		prnt_pitchclass(basetone%12,oct);
-		if(flteq(diff,0.0))
-			strcat(errstr,"\n");
-		else if(flteq(diff,0.5))	/* handle quarter tones */
-			strcat(errstr,"+\n");
-		else if(diff > .5)
-			strcat(errstr,"(--)\n");
-		else
-			strcat(errstr,"(++)\n");
-		fprintf(stdout,"INFO: %s",errstr);
-	}
-	fflush(stdout);
+    int basetone;
+    double diff;
+    for(n=0;n<cnt;n++) {
+        if(midi) {
+            if(number[n] < MIDIMIN || number[n] > MIDIMAX) {
+                fprintf(stdout,"ERROR: MIDI value %d (%lf) is out of range for conversion to pitch.\n", n+1,number[n]);
+                fflush(stdout);
+                exit(1);
+            }
+        } else {
+            if(number[n] < MIDIMINFRQ || number[n] > MIDIMAXFRQ) {
+                fprintf(stdout,"ERROR: frq value %d (%lf) is out of range for conversion to pitch.\n", n+1,number[n]);
+                fflush(stdout);
+                exit(1);
+            }
+        }
+    }
+    for(n=0;n<cnt;n++) {
+        if(!midi)
+            number[n] = hztomidi(number[n]);
+        oct = (int)(number[n]/12.0);    /* TRUNCATE */
+        oct -= 5;
+        basetone = (int)floor(number[n]);
+        diff = number[n] - (double)basetone;
+        if(diff > .5)
+            basetone++;
+        prnt_pitchclass(basetone%12,oct);
+        if(flteq(diff,0.0))
+            strcat(errstr,"\n");
+        else if(flteq(diff,0.5))        /* handle quarter tones */
+            strcat(errstr,"+\n");
+        else if(diff > .5)
+            strcat(errstr,"(--)\n");
+        else
+            strcat(errstr,"(++)\n");
+        fprintf(stdout,"INFO: %s",errstr);
+    }
+    fflush(stdout);
 }
 }
 
 
 /****************************** PRNT_PITCHCLASS ******************************/
 /****************************** PRNT_PITCHCLASS ******************************/
 
 
 void prnt_pitchclass(int z,int oct)
 void prnt_pitchclass(int z,int oct)
 {
 {
-   	switch(z) {
-	case(0):	sprintf(errstr,"C%d",oct);	break;
-	case(1):	sprintf(errstr,"C#%d",oct);	break;
-	case(2):	sprintf(errstr,"D%d",oct);	break;
-	case(3):	sprintf(errstr,"Eb%d",oct);	break;
-	case(4):	sprintf(errstr,"E%d",oct);	break;
-	case(5):	sprintf(errstr,"F%d",oct);	break;
-	case(6):	sprintf(errstr,"F#%d",oct);	break;
-	case(7):	sprintf(errstr,"G%d",oct);	break;
-	case(8):	sprintf(errstr,"Ab%d",oct);	break;
-	case(9):	sprintf(errstr,"A%d",oct);	break;
-	case(10):	sprintf(errstr,"Bb%d",oct);	break;
-	case(11):	sprintf(errstr,"B%d",oct);	break;
-	}					  
+    switch(z) {
+    case(0):        sprintf(errstr,"C%d",oct);      break;
+    case(1):        sprintf(errstr,"C#%d",oct);     break;
+    case(2):        sprintf(errstr,"D%d",oct);      break;
+    case(3):        sprintf(errstr,"Eb%d",oct);     break;
+    case(4):        sprintf(errstr,"E%d",oct);      break;
+    case(5):        sprintf(errstr,"F%d",oct);      break;
+    case(6):        sprintf(errstr,"F#%d",oct);     break;
+    case(7):        sprintf(errstr,"G%d",oct);      break;
+    case(8):        sprintf(errstr,"Ab%d",oct);     break;
+    case(9):        sprintf(errstr,"A%d",oct);      break;
+    case(10):       sprintf(errstr,"Bb%d",oct);     break;
+    case(11):       sprintf(errstr,"B%d",oct);      break;
+    }
 }
 }
 
 
 
 
 void bublsort(void) {
 void bublsort(void) {
-	int n, m;
-	double temp;
-	for(n=0;n<cnt-1;n++) {
-		for(m = n; m<cnt; m++) {
-			if(number[m] < number[n]) {
-				temp = number[n];
-				number[n] = number[m];
-				number[m] = temp;
-			}
-		}
-	}
+    int n, m;
+    double temp;
+    for(n=0;n<cnt-1;n++) {
+        for(m = n; m<cnt; m++) {
+            if(number[m] < number[n]) {
+                temp = number[n];
+                number[n] = number[m];
+                number[m] = temp;
+            }
+        }
+    }
 }
 }
 
 
 /************************* DO_OTHER_STRINGLINE_INFILE ***************************/
 /************************* DO_OTHER_STRINGLINE_INFILE ***************************/
 
 
 int do_other_stringline_infile(char *argv)
 int do_other_stringline_infile(char *argv)
 {
 {
-	int cols;
-/*
-	cnt = stringscnt; DONE PREVIOUSLY
-*/
-	cols = do_stringline_infile(argv,cnt);
-	stringscnt -= cnt;
-	return cols;
+    int cols;
+    /*
+      cnt = stringscnt; DONE PREVIOUSLY
+    */
+    cols = do_stringline_infile(argv,cnt);
+    stringscnt -= cnt;
+    return cols;
 }
 }
 
 
 /************************* DO_STRINGLINE_INFILE ***************************/
 /************************* DO_STRINGLINE_INFILE ***************************/
 
 
 int do_stringline_infile(char *argv,int n)
 int do_stringline_infile(char *argv,int n)
 {
 {
-	int  strspace, cccnt, ccnt = 0, lcnt = 0;
-
-	int space_step = 200, nn;
-	int old_stringstoresize;
-	char *p, *zong;
-	char temp2[200];
-	int total_space = space_step;
-	if((fp[0] = fopen(argv,"r"))==NULL) {
-		fprintf(stdout,"ERROR: Cannot open infile %s\n",argv);
-		fflush(stdout);
-		exit(1);
-	}
-	if(stringstoresize == 0) {
-		if((stringstore = (char *)exmalloc(total_space))==NULL) {
-			sprintf(errstr,"Out of Memory\n");
-			do_error();
-		}
-	}
-	while(fgets(temp,200,fp[0])!=NULL) {
-		p = temp;
-		cccnt = 0;
-		while(strgetstr(&p,temp2)) {
-			strspace = strlen(temp2)+1;
-			old_stringstoresize = stringstoresize;
-			if((stringstoresize += strspace) >= total_space) {
-				while(stringstoresize  >= total_space)
-					total_space += space_step;
-				if((zong = (char *)malloc(total_space))==NULL) {
-					sprintf(errstr,"Out of Memory\n");
-					do_error();
-				} 
-				memcpy(zong,stringstore,old_stringstoresize);
-				free(stringstore);
-				stringstore = zong;
-			}
-			strcpy(stringstore + stringstart,temp2);
-			stringstart += strspace;
-			stringscnt++;
-			cccnt++;
-		}
-		if(lcnt == 0) {
-			ccnt = cccnt;
-			lcnt++;
-		} else if(ccnt != cccnt) {
-			if(cccnt != 0) {
-				fprintf(stdout,"ERROR: File %s is not a true table file (line %d has %d cols instead of %d).\n",
-				argv,lcnt+1,cccnt,ccnt);
-				fflush(stdout);
-				exit(1);
-			} else {
-				continue;
-			}
-		} else {			
-			lcnt++;
-		}
-	}
-	if(stringscnt <= n) {
-		fprintf(stdout,"ERROR: Invalid or missing data.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	if(strings == 0) {
-		if((strings = (char **)malloc(stringscnt * sizeof(char *)))==NULL) {
-			sprintf(errstr,"Out of Memory\n");
-			do_error();
-		}
-	} else {
-		if((strings = (char **)realloc((char *)strings,stringscnt * sizeof(char *)))==NULL) {
-			sprintf(errstr,"Out of Memory\n");
-			do_error();
-		}
-	}
-	p = stringstore;
-	nn = 0;
-	while(nn < stringscnt) {
-		strings[nn] = p;
-		while(*p != ENDOFSTR)
-			p++;
-		p++;
-		nn++;
-	}
-	fclose(fp[0]);
-	return ccnt;
+    int  strspace, cccnt, ccnt = 0, lcnt = 0;
+
+    int space_step = 200, nn;
+    int old_stringstoresize;
+    char *p, *zong;
+    char temp2[200];
+    int total_space = space_step;
+    if((fp[0] = fopen(argv,"r"))==NULL) {
+        fprintf(stdout,"ERROR: Cannot open infile %s\n",argv);
+        fflush(stdout);
+        exit(1);
+    }
+    if(stringstoresize == 0) {
+        if((stringstore = (char *)exmalloc(total_space))==NULL) {
+            sprintf(errstr,"Out of Memory\n");
+            do_error();
+        }
+    }
+    while(fgets(temp,200,fp[0])!=NULL) {
+        p = temp;
+        cccnt = 0;
+        while(strgetstr(&p,temp2)) {
+            strspace = strlen(temp2)+1;
+            old_stringstoresize = stringstoresize;
+            if((stringstoresize += strspace) >= total_space) {
+                while(stringstoresize  >= total_space)
+                    total_space += space_step;
+                if((zong = (char *)malloc(total_space))==NULL) {
+                    sprintf(errstr,"Out of Memory\n");
+                    do_error();
+                }
+                memcpy(zong,stringstore,old_stringstoresize);
+                free(stringstore);
+                stringstore = zong;
+            }
+            strcpy(stringstore + stringstart,temp2);
+            stringstart += strspace;
+            stringscnt++;
+            cccnt++;
+        }
+        if(lcnt == 0) {
+            ccnt = cccnt;
+            lcnt++;
+        } else if(ccnt != cccnt) {
+            if(cccnt != 0) {
+                fprintf(stdout,"ERROR: File %s is not a true table file (line %d has %d cols instead of %d).\n",
+                        argv,lcnt+1,cccnt,ccnt);
+                fflush(stdout);
+                exit(1);
+            } else {
+                continue;
+            }
+        } else {
+            lcnt++;
+        }
+    }
+    if(stringscnt <= n) {
+        fprintf(stdout,"ERROR: Invalid or missing data.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    if(strings == 0) {
+        if((strings = (char **)malloc(stringscnt * sizeof(char *)))==NULL) {
+            sprintf(errstr,"Out of Memory\n");
+            do_error();
+        }
+    } else {
+        if((strings = (char **)realloc((char *)strings,stringscnt * sizeof(char *)))==NULL) {
+            sprintf(errstr,"Out of Memory\n");
+            do_error();
+        }
+    }
+    p = stringstore;
+    nn = 0;
+    while(nn < stringscnt) {
+        strings[nn] = p;
+        while(*p != ENDOFSTR)
+            p++;
+        p++;
+        nn++;
+    }
+    fclose(fp[0]);
+    return ccnt;
 }
 }
 
 
 /************************* DO_OTHER_STRINGLINE_INFILE ***************************/
 /************************* DO_OTHER_STRINGLINE_INFILE ***************************/
 
 
 void do_other_stringline_infiles(char *argv[],char c)
 void do_other_stringline_infiles(char *argv[],char c)
 {
 {
-	int n;
-	int sum, thiscolcnt, last_stringscnt, this_stringscnt, rowcnt=0, thisrowcnt;
-
-	if((cntr = (int *)malloc(infilecnt*sizeof(int)))==NULL) {
-		fprintf(stdout,"ERROR: Out of memory.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	cntr[0] = stringscnt;
-	sum = cntr[0];
-
-	if(c == 'J') {
-		if((rowcnt = stringscnt/colcnt) * colcnt != stringscnt) {
-			fprintf(stdout,
-			"ERROR: Incomplete table 1 : all rows must have same number of columns for this option.\n");
-			fflush(stdout);
-			exit(1);
-		}
-	}
-	for(n=1;n<infilecnt;n++) {
-		last_stringscnt = stringscnt;
-		thiscolcnt = do_stringline_infile(argv[n+1],stringscnt);
-		switch(c) {
-		case('j'):
-			if(thiscolcnt != colcnt) {
-				fprintf(stdout,"ERROR: Count of columns incompatible in the input files.\n");
-				fflush(stdout);
-				exit(1);
-			}
- 			break;
-		case('W'):
-			if(thiscolcnt != colcnt) {
-				fprintf(stdout,"ERROR: Count of columns incompatible in the input files.\n");
-				fflush(stdout);
-				exit(1);
-			}
- 			break;
-		case('J'):
-			this_stringscnt = stringscnt - last_stringscnt;
-			if((thisrowcnt = this_stringscnt/thiscolcnt) * thiscolcnt != this_stringscnt) {
-				fprintf(stdout,
-				"ERROR: Table %d incomplete: all rows must have same number of columns for this option.\n",n+1);
-				fflush(stdout);
-				exit(1);
-			}
-			if(thisrowcnt != rowcnt) {
-				fprintf(stdout,"ERROR: File %d does not have same number of rows as 1st file.\n",n+1);
-				fflush(stdout);
-				exit(1);
-			}
-			break;
-		}
-		cntr[n] = stringscnt - sum;
-		sum += cntr[n];
-	}
-	if(c == 'J')
-		colcnt = rowcnt;	/* held temporarily in global */
+    int n;
+    int sum, thiscolcnt, last_stringscnt, this_stringscnt, rowcnt=0, thisrowcnt;
+
+    if((cntr = (int *)malloc(infilecnt*sizeof(int)))==NULL) {
+        fprintf(stdout,"ERROR: Out of memory.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    cntr[0] = stringscnt;
+    sum = cntr[0];
+
+    if(c == 'J') {
+        if((rowcnt = stringscnt/colcnt) * colcnt != stringscnt) {
+            fprintf(stdout,
+                    "ERROR: Incomplete table 1 : all rows must have same number of columns for this option.\n");
+            fflush(stdout);
+            exit(1);
+        }
+    }
+    for(n=1;n<infilecnt;n++) {
+        last_stringscnt = stringscnt;
+        thiscolcnt = do_stringline_infile(argv[n+1],stringscnt);
+        switch(c) {
+        case('j'):
+            if(thiscolcnt != colcnt) {
+                fprintf(stdout,"ERROR: Count of columns incompatible in the input files.\n");
+                fflush(stdout);
+                exit(1);
+            }
+            break;
+        case('W'):
+            if(thiscolcnt != colcnt) {
+                fprintf(stdout,"ERROR: Count of columns incompatible in the input files.\n");
+                fflush(stdout);
+                exit(1);
+            }
+            break;
+        case('J'):
+            this_stringscnt = stringscnt - last_stringscnt;
+            if((thisrowcnt = this_stringscnt/thiscolcnt) * thiscolcnt != this_stringscnt) {
+                fprintf(stdout,
+                        "ERROR: Table %d incomplete: all rows must have same number of columns for this option.\n",n+1);
+                fflush(stdout);
+                exit(1);
+            }
+            if(thisrowcnt != rowcnt) {
+                fprintf(stdout,"ERROR: File %d does not have same number of rows as 1st file.\n",n+1);
+                fflush(stdout);
+                exit(1);
+            }
+            break;
+        }
+        cntr[n] = stringscnt - sum;
+        sum += cntr[n];
+    }
+    if(c == 'J')
+        colcnt = rowcnt;        /* held temporarily in global */
 }
 }
 
 
 /************************* DO_STRING_INFILE ***************************/
 /************************* DO_STRING_INFILE ***************************/
 
 
 void do_string_infile(char *argv)
 void do_string_infile(char *argv)
 {
 {
-	int  strspace;
-	int space_step = 200, startstringscnt = stringscnt, n;
-	int old_stringstoresize;
-	char *p;
-	char temp2[200];
-	int total_space = space_step;
-	if((fp[0] = fopen(argv,"r"))==NULL) {
-		sprintf(errstr,"Cannot open infile %s\n",argv);
-		do_error();
-	}
-	if(stringstoresize == 0) {
-		if((stringstore = (char *)malloc(total_space))==NULL) {
-			sprintf(errstr,"Out of Memory\n");
-			do_error();
-		}
-	}
-	while(fgets(temp,200,fp[0])!=NULL) {
-		p = temp;
-		while(strgetstr(&p,temp2)) {
-			strspace = strlen(temp2)+1;
-			old_stringstoresize = stringstoresize;
-			if((stringstoresize += strspace) >= total_space) {
-				while(stringstoresize  >= total_space)
-					total_space += space_step;
-				if((stringstore = (char *)realloc((char *)stringstore,total_space))==NULL) {
-					sprintf(errstr,"Out of Memory\n");
-					do_error();
-				}
-			}
-			strcpy(stringstore + stringstart,temp2);
-			stringstart += strspace;
-			stringscnt++;
-		}
-	}
-	if(stringscnt <=0) {
-		sprintf(errstr,"Invalid or missing data.\n");
-		do_error();
-	}
-	if(strings == 0) {
-		if((strings = (char **)malloc(stringscnt * sizeof(char *)))==NULL) {
-			sprintf(errstr,"Out of Memory\n");
-			do_error();
-		}
-	} else {
-		if((strings = (char **)realloc((char *)strings,stringscnt * sizeof(char *)))==NULL) {
-			sprintf(errstr,"Out of Memory\n");
-			do_error();
-		}
-	}
-	p = stringstore;
-	n = 0;
-	while(n < startstringscnt) {
-		while(*p != ENDOFSTR)
-			p++;
-		p++;
-		n++;
-	}
-	while(n < stringscnt) {
-		strings[n] = p;
-		while(*p != ENDOFSTR)
-			p++;
-		p++;
-		n++;
-	}
-	fclose(fp[0]);
+    int  strspace;
+    int space_step = 200, startstringscnt = stringscnt, n;
+    //int old_stringstoresize;
+    char *p;
+    char temp2[200];
+    int total_space = space_step;
+    if((fp[0] = fopen(argv,"r"))==NULL) {
+        sprintf(errstr,"Cannot open infile %s\n",argv);
+        do_error();
+    }
+    if(stringstoresize == 0) {
+        if((stringstore = (char *)malloc(total_space))==NULL) {
+            sprintf(errstr,"Out of Memory\n");
+            do_error();
+        }
+    }
+    while(fgets(temp,200,fp[0])!=NULL) {
+        p = temp;
+        while(strgetstr(&p,temp2)) {
+            strspace = strlen(temp2)+1;
+            //old_stringstoresize = stringstoresize;
+            if((stringstoresize += strspace) >= total_space) {
+                while(stringstoresize  >= total_space)
+                    total_space += space_step;
+                if((stringstore = (char *)realloc((char *)stringstore,total_space))==NULL) {
+                    sprintf(errstr,"Out of Memory\n");
+                    do_error();
+                }
+            }
+            strcpy(stringstore + stringstart,temp2);
+            stringstart += strspace;
+            stringscnt++;
+        }
+    }
+    if(stringscnt <=0) {
+        sprintf(errstr,"Invalid or missing data.\n");
+        do_error();
+    }
+    if(strings == 0) {
+        if((strings = (char **)malloc(stringscnt * sizeof(char *)))==NULL) {
+            sprintf(errstr,"Out of Memory\n");
+            do_error();
+        }
+    } else {
+        if((strings = (char **)realloc((char *)strings,stringscnt * sizeof(char *)))==NULL) {
+            sprintf(errstr,"Out of Memory\n");
+            do_error();
+        }
+    }
+    p = stringstore;
+    n = 0;
+    while(n < startstringscnt) {
+        while(*p != ENDOFSTR)
+            p++;
+        p++;
+        n++;
+    }
+    while(n < stringscnt) {
+        strings[n] = p;
+        while(*p != ENDOFSTR)
+            p++;
+        p++;
+        n++;
+    }
+    fclose(fp[0]);
 }
 }
 
 
 /************************* TEST_WARP_DATA ***************************/
 /************************* TEST_WARP_DATA ***************************/
 
 
-void test_warp_data(void) 
+void test_warp_data(void)
 {
 {
-	int n = 0;
-	if(number[n] < 0) {
-		sprintf(errstr,"Negative time in breakpoint file: Cannot proceed.\n");
-		do_error();
-		exit(1);
-	}
-	if(number[1] < 1.0/1024.0 || number[1] > 1024.0) {
-		sprintf(errstr,"Dubious Timestretch value (%lf) in brkpnt file.\n",number[1]);
-		do_error();
-		exit(1);
-	}
-	for(n = 2; n <firstcnt; n+=2) {
-		if(number[n] <= number[n-2]) {
-			sprintf(errstr,"Times (%lf & %lf) not in increasing order in brkpnt file.\n",number[n-2],number[n]);
-			do_error();
-			exit(1);
-		}
-		if(number[n+1] < 1.0/1024.0 || number[n+1] > 1024.0) {
-			sprintf(errstr,"Dubious Timestretch value (%lf) in brkpnt file.\n",number[n+1]);
-			do_error();
-			exit(1);
-		}
-	}
-	for(n = firstcnt; n <cnt; n++) {
-		if(number[n] < 0.0) {
-			sprintf(errstr,"Negative time (%lf) given in 2nd file: Cannot proceed.\n",number[n]);
-			do_error();
-			exit(1);
-		}
-	}
+    int n = 0;
+    if(number[n] < 0) {
+        sprintf(errstr,"Negative time in breakpoint file: Cannot proceed.\n");
+        do_error();
+        exit(1);
+    }
+    if(number[1] < 1.0/1024.0 || number[1] > 1024.0) {
+        sprintf(errstr,"Dubious Timestretch value (%lf) in brkpnt file.\n",number[1]);
+        do_error();
+        exit(1);
+    }
+    for(n = 2; n <firstcnt; n+=2) {
+        if(number[n] <= number[n-2]) {
+            sprintf(errstr,"Times (%lf & %lf) not in increasing order in brkpnt file.\n",number[n-2],number[n]);
+            do_error();
+            exit(1);
+        }
+        if(number[n+1] < 1.0/1024.0 || number[n+1] > 1024.0) {
+            sprintf(errstr,"Dubious Timestretch value (%lf) in brkpnt file.\n",number[n+1]);
+            do_error();
+            exit(1);
+        }
+    }
+    for(n = firstcnt; n <cnt; n++) {
+        if(number[n] < 0.0) {
+            sprintf(errstr,"Negative time (%lf) given in 2nd file: Cannot proceed.\n",number[n]);
+            do_error();
+            exit(1);
+        }
+    }
 }
 }

+ 249 - 251
dev/tabedit/columns2.c

@@ -1,251 +1,249 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
-
-    The CDP System is free software; you can redistribute it
-    and/or modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    The CDP System is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with the CDP System; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-    02111-1307 USA
- *
- */
-
-
-
-#include <columns.h>
-
-void 	helpm(void),helpM(void),helpg(void),helpr(void),helpl(void),help(void);
-
-/********************************** HELPM **********************************/
-
-void helpm(void)
-{
-fprintf(stderr,
-" ------------------------ MATHEMATICAL OPERATIONS ---------------------------\n"
-"| g     find Greatest                | i    find Intervals (MIDI)            |\n"
-"| l     find Least                   | im@  Multiply Intervals by @          |\n"
-"| t     find Total                   | ia@  Add @ to Intervals               |\n"
-"| p     find Product                 | ra   RAtios btwn succesive values     |\n"
-"| M     find Mean                    | iv   generate Intermediate Values     |\n"
-"| R[@]  find Reciprocals (1/N) (<|>) | iL@  Limit Intervals to < max @       |\n"
-"|       with @, find @/N             | il@  Limit Intervals to > min @       |\n"
-"| a@    Add @                  (<|>) |                                       |\n"
-"| m@    Multiply by @          (<|>) | Ra@  Add Random value between +-@     |\n"
-"| d@    Divide by @            (<|>) | RA@  Add Random value between 0 & @   |\n"
-"| P@    +ve values to Power @  (<|>) | Rm@  Multiply by Randval between 0-@  |\n"
-"|                                    | Rs@  Random Scatter[@=0-1] ascending  |\n"
-"|(<|>) means these can apply to vals |      vals over intervals between vals |\n"
-"|  < or > threshold on command-line. |                                       |\n"
-"|                                    | s[@] Stack values from 0 (overlap @)  |\n"
-"| A@  Approximate to multiplies of @ | sl@  Change Slope by factor @         |\n"
-"| fl@ ensure all vals >= floor-val @ | sd[@] Sum abs Differences (zigzag)    |\n"
-"| li@ ensure all vals <= limit-val @ |       (@=overlap e.g.splicelen)       |\n"
-"|                                    | so@   Sum, minus Overlaps             |\n"
-"| THRESHOLD VALUE IS INDICATED BY an |       @=overlap (e.g.splicelen)       |\n"
-"| extra parameter on command line..  | sn@   Sum N-wise. N = @               |\n"
-"|  e.g. {3 means <3 ;  }7 means >7   |                                       |\n"
-" -------------------- FOR FURTHER HELP TRY -l -M -g -R ----------------------\n");
-exit(1);
-}
-
-/************************************ HELPL ***********************************/
-
-void helpl(void)
-{
-fprintf(stderr,
-" ------------------------ LIST REORDER OR EDIT --------------------------\n"
-"| c     Count vals (<||>threshold) | e@   Eliminate value @ (+-error)    |\n"
-"| mg@   Mark values > @            | eg@  Eliminate vals Greater than @  |\n"
-"| ml@   Mark values < @            | el@  Eliminate vals Less than @     |\n"
-"| cl    Count lines                | ed@  Eliminate Duplicates           |\n"
-"| o     Order list                 |      within range @                 |\n"
-"| rr    Reverse list               | ee   Eliminate Even items           |\n"
-"| Ro[@] Randomise Order (X@)       | Re@  Eliminate @ items at Random    |\n"
-"| dl@   Duplicate List @ times     | bg@  Vals > @ reduced to Bound @    |\n"
-"| dv@   Duplicate each Val @ times | bl@  Vals < @ raised to Bound @     |\n"
-"|                                  | N@   partitioN to @ files,in blocks |\n"
-"| sk@   get 1 value & SKip @       | Nr@  partitioN to @ fils,in rotation|\n"
-"| sK@   get @ values, SKip 1       | C    Concatenate files              |\n"
-"| cc    columnate                  |                                     |\n");
-fprintf(stderr,
-"| As    Alphabetic Sort            | S@   Separate @ columns to @ files  |\n"
-"| F@    Format vals in @ cols      | J    Join as columns in 1 file      |\n"
-"| s[@]  Stack values from 0        | I    Interleave: columns->list      |\n"
-"|       (overlap @)                | E[@] vals End to End in 2 columns   |\n"
-"| Mr[@] Avoid midi-pitch-class     |      (@ = column2 overshoot of      |\n"
-"|       repetition (within @ notes)|      next value in column 1)        |\n"
-"| fr[@] Avoid  frq-pitch-class     | v[@] rank by VOTE: ie. by no. of    |\n"
-"|       repetition (within @ notes)|      times each number(+-@) occurs  |\n"
-"| ir@   Repeat Intervals @ times   | V@   rank frqs by VOTE              |\n"
-"|       starting from last entry   |      @ = semitone range for equalfrq|\n"
-"| F@    format in @ columns        | G@   reGROUP: take every @th item   |\n"
-"|                                  |      from 0, then ditto from 1 etc. |\n"
-"| THRESHOLD IS EXTRA PARAM ON CMDLINE... E.G. {3 MEANS <3 ;  }7 MEANS >7 |\n"
-" ------------------ FOR FURTHER HELP TRY -m -M -g -R --------------------\n");
-exit(1);
-}
-
-/*********************************** HELPM ***********************************/
-
-void helpM(void)
-{
-fprintf(stderr,
-" ----------------------------  MUSICAL OPERATIONS ----------------------------\n"
-"| Mh    MIDI to Hz                    | sd[@] Sum abs Differences (zigzag)    |\n"
-"| Mt    MIDI to Text                  |       (@=overlap e.g. splicelen)      |\n"
-"| hM    hz to MIDI                    | sl@   Change slope by factor @        |\n"
-"| tM    Text to MIDI                  | so@   Sum, minus Overlaps: @=overlap  |\n"
-"| th    Text to Hz                    |       (e.g.splicelen)                 |\n"
-"|                                     | Mm@   Major->Minor,(MIDI) @ = key     |\n"
-"| q@    Quantise over @               | mM@   Minor->Major,(MIDI) @ = key     |\n"
-"| i     get Intervals (e.g. MIDI)     | TM[@] Temper MIDI data. (With @, to a |\n"
-"| Ir    Interval(semitones)-> frqratio|       @-note equal-tempered scale     |\n"
-"| ra    RAtios between succesive vals |       based on concert-C)             |\n"
-"| iM    motivically-Invert MIDI       | Th[@] Temper Hz data. (With @, to a   |\n"
-"| ih    motivically-Invert Hz         |       @-note equal-tempered scale     |\n"
-"| rm@   motivically-ROtate by @       |       based on concert-C)             |\n");
-fprintf(stderr,
-"| B     plain Bob : 8 bells           | do@   Duplicate vals at @ Octaves     |\n"    
-"| At@   Accel Time-seq from event-    |       (MIDI)                          |\n"
-"|       -separation val1 in file      | dO@   Duplicate vals at @ Octaves     |\n"
-"|       to val2 in file, total dur @  |       (FREQUENCIES)                   |\n"
-"|       (optional: starttime val3)    | Mr[@] Avoid midi-pitchclass repeats   |\n"
-"| Tc@   times from crotchet count     |       (within @ notes)                |\n"
-"|       in file, and tempo @          | fr[@] Avoid frq-pitchclass repeats    |\n"
-"| Tl@   Times from crotchet lengths   |       (within @ notes)                |\n"
-"| H@    Generate @ Harmonics          | V@    rank frqs by VOTE               |\n"
-"| Hr@   Generate @ Subharmonics       |       (no. of occcurences)            |\n"
-"| Hg[@] Group frqs as Harmonics:      |       @ = semitone range within which |\n"
-"|       @=tuning tolerance (semitones)|       frqs judged to be equivalent    |\n"
-"|       (default .01)                 | td@   Take set of snd-durations and   |\n"    
-"| Ad@   Accel Durations from val1 to  |       produce list of start-times, to |\n"    
-"|       val2 in file, with total dur @|       give density of @ snds always.  |\n"    
-"| DB    convert dB levels to gain vals| st@   sample to time (@ = srate)      |\n"    
-"| db    convert gain levels to dB     |                                       |\n"    
-" -------------------- FOR FURTHER HELP TRY -m -l -g -R ----------------------\n");
-exit(1);
-}
-
-/**************************************** HELPG *****************************/
-
-void helpg(void)
-{
-fprintf(stderr,"%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
-" -------------------------- GENERATIVE OPERATIONS --------------------------\n",
-"| Rg    Generate Random 0s & 1s      |                                      |\n",
-"|       (number of items, in infile) | ic@   Create @ Intervals, size of    |\n",
-"| Rv@   generate @ Random Values     |       (1) value in file              |\n",
-"|       (maxmin values in infile)    | i=@   Equal Intervals of @ between   |\n",
-"| Rc@   Chop @ to Randomsize chunks  |       2 values in file               |\n",
-"|       (maxmin chunklens in infile) | D@    @ equal Divisions between      |\n",
-"|                                    |       2 values in file               |\n",
-"| iv    gen Intermediate Values      | L@    @ Log-equal divisions between  |\n",
-"|                                    |       2 +ve values in file           |\n",
-"| dv@   Duplicate each Val @ times   | Q@    @ Quadratic-curve steps btwn   |\n",
-"| dl@   Duplicate List @ times       |       2 vals in file, where val3 is  |\n",
-"| ir@   Repeat Intervals @ times,    |       curvature(>0): <1 down: >1 up  |\n",
-"|       starting from last entry     |                                      |\n",
-"|                                    |                                      |\n",
-"| At@   Accel Time-seq from event-   | B     plain Bob : 8 bells            |\n",
-"|       -separation val1 in file, to |                                      |\n",
-"|       val2 in file, total dur @    |                                      |\n",
-"|       (optional: starttime val3)   |                                      |\n",
-"|                                    |                                      |\n",
-"| Ad@   Accel Durations from val1 to |                                      |\n",
-"|       val2 in file, in total dur @ |                                      |\n",
-" ------------------- FOR FURTHER HELP TRY -m -M -l -R ---------------------\n");
-exit(1);
-}
-
-/********************************** HELPR ***********************************/
-
-void helpr(void)
-{
-fprintf(stderr,"%s%s%s%s%s%s%s%s%s%s%s%s",
-" ---------------------------- RANDOM OPERATIONS ---------------------------\n",
-"|                                     |                                    |\n",
-"| Ro[@] Randomise Order               | Rc@   Chop @ to Randchunks         |\n",
-"|       (& again, @ times)            |       (maxmin chunklens in infile) |\n",
-"|                                     | Rg    Generate random 0s & 1s      |\n",
-"| Ra@   Add Randval between +-@       |       (number of items, in infile) |\n",
-"| RA@   Add Randval between 0 & @     | Rv@   Gen @ random Values          |\n",
-"| Rm@   Multiply by Randval btwn 0-@  |       (maxmin vals in infile)      |\n",
-"| Rs@   Scatter[@=0-1] ascending vals |                                    |\n",
-"|       over intervals between vals   | Re@   Eliminate @ items at Random  |\n",
-"|                                     |                                    |\n",
-" -------------------- FOR FURTHER HELP TRY -m -M -l -g --------------------\n");
-exit(1);
-}
-
-/******************************* HELP *******************************/
-
-void help(void)
-{
-fprintf(stderr,
-"a@ .... Add @                          l ..... find LEAST\n"
-"A@ .... Approx to multiples of @       li@ ....LIMIT values to <=@\n"
-"At@ ... ACCELERATING TIME-seq          M ..... find MEAN\n"
-"Ad@ ... ACCELERATING DURATIONS         m@ .... MULTIPLY by @\n"
-"As .... ALPHABETIC SORT                mg@ ... MARK values > @\n"
-"B ..... plain BOB (bell-ringing)       Mr[@].. MIDI-pitchclass-REPETS avoided.\n"
-"bg@ ... Vals >@ reduced to BOUND @     Mh .... MIDI to HZ\n"
-"bl@ ... Vals <@ increased to BOUND @   ml@ ... MARK values < @\n"
-"C ..... CONCATENATE                    Mm@ ... MAJOR->MINOR (MIDI) in key @\n"
-"c ..... COUNT vals    cc...COLUMNATE   Mt .... MIDI to TEXT\n"
-"cl .... COUNT LINES                    mM@ ... MINOR->MAJOR (MIDI) in key @\n"
-"D@ .... @ equal DIVISIONS btwn 2 vals  N@ .... partitioN -> @ files, in blocks\n"
-"DB .... DB values to gain vals         Nr@ ....partN-> @ files, in rotation\n"
-"d@ .... DIVIDE  by @                   o ..... ORDER list\n"
-"db .... gain vals to DB values         P@ .... +ve vals raised to POWER\n"
-"dl@ ... DUPLICATE LIST @ times         p ..... find PRODUCT\n"
-"do@ ... DUPL LIST at @ OCTAVES (MIDI)  Q@ ..@ QUADRATIC-curve steps btwn vals.\n"
-"dO@ ... DUPL LIST at @ OCTAVES (FRQS)  q@ .... QUANTISE over @\n"
-"dv@ ... DUPLICATE each VALUE @ times   R[@]... find RECIPROCALS\n"
-"E[@] .. vals END to END in 2 cols      RA@ ... RANDVAL ADDED\n"
-"e@ .... ELIMINATE value                Ra@ ... RANDVAL +- ADDED\n"
-"ed@ ... ELIMINATE DUPLICATES           ra .... RATIOS betwn vals\n"
-"ee .... ELIMINATE EVEN items           Rc@ ... cut @ into RANDOM CHUNKS\n"
-"eg@ ... ELIMINATE vals > @             Re@ ... RANDOMLY ELIMINATE items\n"
-"el@ ... ELIMINATE vals < @             Rg  ... RANDOM GEN of 0s & 1s\n"
-"fr[@].. FRQ pitchclass REPETS avoided  Rm@ ... MULTIPLY by RAND\n"
-"F@ .... FORMAT in @ columns            rm@ ... motivic-ROTATE\n"
-"fl@ ... FLOOR vals to >=@              Ro[@].. RANDOMISE ORDER\n"
-"g ..... find GREATEST                  rr..... REVERSE list\n"
-"G@ .... GROUP @th items, cyclically    Rs@ ... RANDOM SCATTER vals\n");
-fprintf(stderr,
-"hM .... HZ to MIDI                     Rv@ ... generate RAND VALS\n"
-"H@ .... Generate HARMONICS             S@ .....SEPARATE cols->files\n"
-"Hr@ ... Gen HARMONIC ROOTS (subharms)  s[@] .. STACK vals from 0\n"
-"Hg[@].. GROUP freqs as HARMONICS.      sd[@]...SUM abs DIFFERENCES\n"
-"I ..... INTERLEAVE                     sK@ ... get @ vals,SKIP 1\n"
-"Ir .... INTERVAL(semitones)->frqRATIO  sk@ ... get 1 val, SKIP @\n"
-"i ..... get INTERVALS                  sl@ ... change slope by factor @\n"
-"i=@ ... create EQUAL INTVLS of @       sn@ ... SUM N-WISE. N = @\n"
-"ia@ ... ADD @ to INTERVALS             so@ ... SUM,minus OVERLAPS\n"
-"ic@ ... CREATE @ INTERVALS             st@ ... SAMPLE-CNT to TIME\n"
-"ih .... motiv-INVERT HZ                t ..... find TOTAL\n"
-"iL@ ....LIMIT INTERVALS to < max @     Tc@ ... TEMPO with beatCOUNT ->time\n"
-"il@ ....LIMIT INTERVALS to > min @     td@ ... Time density in @ layers.\n"
-"iM .... motiv-INVERT:MIDI              Th[@].. TEMPER HZ data\n"
-"im@ ... INTERVALS, MULTIPLIED          th .... TEXT to HZ\n"
-"ir@ ... INTERVS, REPEATED              Tl@ ... TEMPO & beatLENGTHS ->time\n"
-"iv .... INTERMEDIATE VALS              TM[@].. TEMPER MIDI data\n"
-"J ..... JOIN as columns                tM .... TEXT to MIDI\n"
-"L@ .... LOG-equal divisions            v[@] .. rank by VOTE(no of times occurs)\n"
-"                                       V@ ..rank frqs by VOTE(@-semitone steps)\n");
-exit(1);
-}
-																	  
-
+/*
+ * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
+ * http://www.trevorwishart.co.uk
+ * http://www.composersdesktop.com
+ *
+ This file is part of the CDP System.
+
+ The CDP System is free software; you can redistribute it
+ and/or modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The CDP System is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the CDP System; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA
+ *
+ */
+
+
+
+#include <columns.h>
+
+void    helpm(void),helpM(void),helpg(void),helpr(void),helpl(void),help(void);
+
+/********************************** HELPM **********************************/
+
+void helpm(void)
+{
+    fprintf(stderr,
+            " ------------------------ MATHEMATICAL OPERATIONS ---------------------------\n"
+            "| g     find Greatest                | i    find Intervals (MIDI)            |\n"
+            "| l     find Least                   | im@  Multiply Intervals by @          |\n"
+            "| t     find Total                   | ia@  Add @ to Intervals               |\n"
+            "| p     find Product                 | ra   RAtios btwn succesive values     |\n"
+            "| M     find Mean                    | iv   generate Intermediate Values     |\n"
+            "| R[@]  find Reciprocals (1/N) (<|>) | iL@  Limit Intervals to < max @       |\n"
+            "|       with @, find @/N             | il@  Limit Intervals to > min @       |\n"
+            "| a@    Add @                  (<|>) |                                       |\n"
+            "| m@    Multiply by @          (<|>) | Ra@  Add Random value between +-@     |\n"
+            "| d@    Divide by @            (<|>) | RA@  Add Random value between 0 & @   |\n"
+            "| P@    +ve values to Power @  (<|>) | Rm@  Multiply by Randval between 0-@  |\n"
+            "|                                    | Rs@  Random Scatter[@=0-1] ascending  |\n"
+            "|(<|>) means these can apply to vals |      vals over intervals between vals |\n"
+            "|  < or > threshold on command-line. |                                       |\n"
+            "|                                    | s[@] Stack values from 0 (overlap @)  |\n"
+            "| A@  Approximate to multiplies of @ | sl@  Change Slope by factor @         |\n"
+            "| fl@ ensure all vals >= floor-val @ | sd[@] Sum abs Differences (zigzag)    |\n"
+            "| li@ ensure all vals <= limit-val @ |       (@=overlap e.g.splicelen)       |\n"
+            "|                                    | so@   Sum, minus Overlaps             |\n"
+            "| THRESHOLD VALUE IS INDICATED BY an |       @=overlap (e.g.splicelen)       |\n"
+            "| extra parameter on command line..  | sn@   Sum N-wise. N = @               |\n"
+            "|  e.g. {3 means <3 ;  }7 means >7   |                                       |\n"
+            " -------------------- FOR FURTHER HELP TRY -l -M -g -R ----------------------\n");
+    exit(1);
+}
+
+/************************************ HELPL ***********************************/
+
+void helpl(void)
+{
+    fprintf(stderr,
+            " ------------------------ LIST REORDER OR EDIT --------------------------\n"
+            "| c     Count vals (<||>threshold) | e@   Eliminate value @ (+-error)    |\n"
+            "| mg@   Mark values > @            | eg@  Eliminate vals Greater than @  |\n"
+            "| ml@   Mark values < @            | el@  Eliminate vals Less than @     |\n"
+            "| cl    Count lines                | ed@  Eliminate Duplicates           |\n"
+            "| o     Order list                 |      within range @                 |\n"
+            "| rr    Reverse list               | ee   Eliminate Even items           |\n"
+            "| Ro[@] Randomise Order (X@)       | Re@  Eliminate @ items at Random    |\n"
+            "| dl@   Duplicate List @ times     | bg@  Vals > @ reduced to Bound @    |\n"
+            "| dv@   Duplicate each Val @ times | bl@  Vals < @ raised to Bound @     |\n"
+            "|                                  | N@   partitioN to @ files,in blocks |\n"
+            "| sk@   get 1 value & SKip @       | Nr@  partitioN to @ fils,in rotation|\n"
+            "| sK@   get @ values, SKip 1       | C    Concatenate files              |\n"
+            "| cc    columnate                  |                                     |\n");
+    fprintf(stderr,
+            "| As    Alphabetic Sort            | S@   Separate @ columns to @ files  |\n"
+            "| F@    Format vals in @ cols      | J    Join as columns in 1 file      |\n"
+            "| s[@]  Stack values from 0        | I    Interleave: columns->list      |\n"
+            "|       (overlap @)                | E[@] vals End to End in 2 columns   |\n"
+            "| Mr[@] Avoid midi-pitch-class     |      (@ = column2 overshoot of      |\n"
+            "|       repetition (within @ notes)|      next value in column 1)        |\n"
+            "| fr[@] Avoid  frq-pitch-class     | v[@] rank by VOTE: ie. by no. of    |\n"
+            "|       repetition (within @ notes)|      times each number(+-@) occurs  |\n"
+            "| ir@   Repeat Intervals @ times   | V@   rank frqs by VOTE              |\n"
+            "|       starting from last entry   |      @ = semitone range for equalfrq|\n"
+            "| F@    format in @ columns        | G@   reGROUP: take every @th item   |\n"
+            "|                                  |      from 0, then ditto from 1 etc. |\n"
+            "| THRESHOLD IS EXTRA PARAM ON CMDLINE... E.G. {3 MEANS <3 ;  }7 MEANS >7 |\n"
+            " ------------------ FOR FURTHER HELP TRY -m -M -g -R --------------------\n");
+    exit(1);
+}
+
+/*********************************** HELPM ***********************************/
+
+void helpM(void)
+{
+    fprintf(stderr,
+            " ----------------------------  MUSICAL OPERATIONS ----------------------------\n"
+            "| Mh    MIDI to Hz                    | sd[@] Sum abs Differences (zigzag)    |\n"
+            "| Mt    MIDI to Text                  |       (@=overlap e.g. splicelen)      |\n"
+            "| hM    hz to MIDI                    | sl@   Change slope by factor @        |\n"
+            "| tM    Text to MIDI                  | so@   Sum, minus Overlaps: @=overlap  |\n"
+            "| th    Text to Hz                    |       (e.g.splicelen)                 |\n"
+            "|                                     | Mm@   Major->Minor,(MIDI) @ = key     |\n"
+            "| q@    Quantise over @               | mM@   Minor->Major,(MIDI) @ = key     |\n"
+            "| i     get Intervals (e.g. MIDI)     | TM[@] Temper MIDI data. (With @, to a |\n"
+            "| Ir    Interval(semitones)-> frqratio|       @-note equal-tempered scale     |\n"
+            "| ra    RAtios between succesive vals |       based on concert-C)             |\n"
+            "| iM    motivically-Invert MIDI       | Th[@] Temper Hz data. (With @, to a   |\n"
+            "| ih    motivically-Invert Hz         |       @-note equal-tempered scale     |\n"
+            "| rm@   motivically-ROtate by @       |       based on concert-C)             |\n");
+    fprintf(stderr,
+            "| B     plain Bob : 8 bells           | do@   Duplicate vals at @ Octaves     |\n"
+            "| At@   Accel Time-seq from event-    |       (MIDI)                          |\n"
+            "|       -separation val1 in file      | dO@   Duplicate vals at @ Octaves     |\n"
+            "|       to val2 in file, total dur @  |       (FREQUENCIES)                   |\n"
+            "|       (optional: starttime val3)    | Mr[@] Avoid midi-pitchclass repeats   |\n"
+            "| Tc@   times from crotchet count     |       (within @ notes)                |\n"
+            "|       in file, and tempo @          | fr[@] Avoid frq-pitchclass repeats    |\n"
+            "| Tl@   Times from crotchet lengths   |       (within @ notes)                |\n"
+            "| H@    Generate @ Harmonics          | V@    rank frqs by VOTE               |\n"
+            "| Hr@   Generate @ Subharmonics       |       (no. of occcurences)            |\n"
+            "| Hg[@] Group frqs as Harmonics:      |       @ = semitone range within which |\n"
+            "|       @=tuning tolerance (semitones)|       frqs judged to be equivalent    |\n"
+            "|       (default .01)                 | td@   Take set of snd-durations and   |\n"
+            "| Ad@   Accel Durations from val1 to  |       produce list of start-times, to |\n"
+            "|       val2 in file, with total dur @|       give density of @ snds always.  |\n"
+            "| DB    convert dB levels to gain vals| st@   sample to time (@ = srate)      |\n"
+            "| db    convert gain levels to dB     |                                       |\n"
+            " -------------------- FOR FURTHER HELP TRY -m -l -g -R ----------------------\n");
+    exit(1);
+}
+
+/**************************************** HELPG *****************************/
+
+void helpg(void)
+{
+    fprintf(stderr,"%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
+            " -------------------------- GENERATIVE OPERATIONS --------------------------\n",
+            "| Rg    Generate Random 0s & 1s      |                                      |\n",
+            "|       (number of items, in infile) | ic@   Create @ Intervals, size of    |\n",
+            "| Rv@   generate @ Random Values     |       (1) value in file              |\n",
+            "|       (maxmin values in infile)    | i=@   Equal Intervals of @ between   |\n",
+            "| Rc@   Chop @ to Randomsize chunks  |       2 values in file               |\n",
+            "|       (maxmin chunklens in infile) | D@    @ equal Divisions between      |\n",
+            "|                                    |       2 values in file               |\n",
+            "| iv    gen Intermediate Values      | L@    @ Log-equal divisions between  |\n",
+            "|                                    |       2 +ve values in file           |\n",
+            "| dv@   Duplicate each Val @ times   | Q@    @ Quadratic-curve steps btwn   |\n",
+            "| dl@   Duplicate List @ times       |       2 vals in file, where val3 is  |\n",
+            "| ir@   Repeat Intervals @ times,    |       curvature(>0): <1 down: >1 up  |\n",
+            "|       starting from last entry     |                                      |\n",
+            "|                                    |                                      |\n",
+            "| At@   Accel Time-seq from event-   | B     plain Bob : 8 bells            |\n",
+            "|       -separation val1 in file, to |                                      |\n",
+            "|       val2 in file, total dur @    |                                      |\n",
+            "|       (optional: starttime val3)   |                                      |\n",
+            "|                                    |                                      |\n",
+            "| Ad@   Accel Durations from val1 to |                                      |\n",
+            "|       val2 in file, in total dur @ |                                      |\n",
+            " ------------------- FOR FURTHER HELP TRY -m -M -l -R ---------------------\n");
+    exit(1);
+}
+
+/********************************** HELPR ***********************************/
+
+void helpr(void)
+{
+    fprintf(stderr,"%s%s%s%s%s%s%s%s%s%s%s%s",
+            " ---------------------------- RANDOM OPERATIONS ---------------------------\n",
+            "|                                     |                                    |\n",
+            "| Ro[@] Randomise Order               | Rc@   Chop @ to Randchunks         |\n",
+            "|       (& again, @ times)            |       (maxmin chunklens in infile) |\n",
+            "|                                     | Rg    Generate random 0s & 1s      |\n",
+            "| Ra@   Add Randval between +-@       |       (number of items, in infile) |\n",
+            "| RA@   Add Randval between 0 & @     | Rv@   Gen @ random Values          |\n",
+            "| Rm@   Multiply by Randval btwn 0-@  |       (maxmin vals in infile)      |\n",
+            "| Rs@   Scatter[@=0-1] ascending vals |                                    |\n",
+            "|       over intervals between vals   | Re@   Eliminate @ items at Random  |\n",
+            "|                                     |                                    |\n",
+            " -------------------- FOR FURTHER HELP TRY -m -M -l -g --------------------\n");
+    exit(1);
+}
+
+/******************************* HELP *******************************/
+
+void help(void)
+{
+    fprintf(stderr,
+            "a@ .... Add @                          l ..... find LEAST\n"
+            "A@ .... Approx to multiples of @       li@ ....LIMIT values to <=@\n"
+            "At@ ... ACCELERATING TIME-seq          M ..... find MEAN\n"
+            "Ad@ ... ACCELERATING DURATIONS         m@ .... MULTIPLY by @\n"
+            "As .... ALPHABETIC SORT                mg@ ... MARK values > @\n"
+            "B ..... plain BOB (bell-ringing)       Mr[@].. MIDI-pitchclass-REPETS avoided.\n"
+            "bg@ ... Vals >@ reduced to BOUND @     Mh .... MIDI to HZ\n"
+            "bl@ ... Vals <@ increased to BOUND @   ml@ ... MARK values < @\n"
+            "C ..... CONCATENATE                    Mm@ ... MAJOR->MINOR (MIDI) in key @\n"
+            "c ..... COUNT vals    cc...COLUMNATE   Mt .... MIDI to TEXT\n"
+            "cl .... COUNT LINES                    mM@ ... MINOR->MAJOR (MIDI) in key @\n"
+            "D@ .... @ equal DIVISIONS btwn 2 vals  N@ .... partitioN -> @ files, in blocks\n"
+            "DB .... DB values to gain vals         Nr@ ....partN-> @ files, in rotation\n"
+            "d@ .... DIVIDE  by @                   o ..... ORDER list\n"
+            "db .... gain vals to DB values         P@ .... +ve vals raised to POWER\n"
+            "dl@ ... DUPLICATE LIST @ times         p ..... find PRODUCT\n"
+            "do@ ... DUPL LIST at @ OCTAVES (MIDI)  Q@ ..@ QUADRATIC-curve steps btwn vals.\n"
+            "dO@ ... DUPL LIST at @ OCTAVES (FRQS)  q@ .... QUANTISE over @\n"
+            "dv@ ... DUPLICATE each VALUE @ times   R[@]... find RECIPROCALS\n"
+            "E[@] .. vals END to END in 2 cols      RA@ ... RANDVAL ADDED\n"
+            "e@ .... ELIMINATE value                Ra@ ... RANDVAL +- ADDED\n"
+            "ed@ ... ELIMINATE DUPLICATES           ra .... RATIOS betwn vals\n"
+            "ee .... ELIMINATE EVEN items           Rc@ ... cut @ into RANDOM CHUNKS\n"
+            "eg@ ... ELIMINATE vals > @             Re@ ... RANDOMLY ELIMINATE items\n"
+            "el@ ... ELIMINATE vals < @             Rg  ... RANDOM GEN of 0s & 1s\n"
+            "fr[@].. FRQ pitchclass REPETS avoided  Rm@ ... MULTIPLY by RAND\n"
+            "F@ .... FORMAT in @ columns            rm@ ... motivic-ROTATE\n"
+            "fl@ ... FLOOR vals to >=@              Ro[@].. RANDOMISE ORDER\n"
+            "g ..... find GREATEST                  rr..... REVERSE list\n"
+            "G@ .... GROUP @th items, cyclically    Rs@ ... RANDOM SCATTER vals\n");
+    fprintf(stderr,
+            "hM .... HZ to MIDI                     Rv@ ... generate RAND VALS\n"
+            "H@ .... Generate HARMONICS             S@ .....SEPARATE cols->files\n"
+            "Hr@ ... Gen HARMONIC ROOTS (subharms)  s[@] .. STACK vals from 0\n"
+            "Hg[@].. GROUP freqs as HARMONICS.      sd[@]...SUM abs DIFFERENCES\n"
+            "I ..... INTERLEAVE                     sK@ ... get @ vals,SKIP 1\n"
+            "Ir .... INTERVAL(semitones)->frqRATIO  sk@ ... get 1 val, SKIP @\n"
+            "i ..... get INTERVALS                  sl@ ... change slope by factor @\n"
+            "i=@ ... create EQUAL INTVLS of @       sn@ ... SUM N-WISE. N = @\n"
+            "ia@ ... ADD @ to INTERVALS             so@ ... SUM,minus OVERLAPS\n"
+            "ic@ ... CREATE @ INTERVALS             st@ ... SAMPLE-CNT to TIME\n"
+            "ih .... motiv-INVERT HZ                t ..... find TOTAL\n"
+            "iL@ ....LIMIT INTERVALS to < max @     Tc@ ... TEMPO with beatCOUNT ->time\n"
+            "il@ ....LIMIT INTERVALS to > min @     td@ ... Time density in @ layers.\n"
+            "iM .... motiv-INVERT:MIDI              Th[@].. TEMPER HZ data\n"
+            "im@ ... INTERVALS, MULTIPLIED          th .... TEXT to HZ\n"
+            "ir@ ... INTERVS, REPEATED              Tl@ ... TEMPO & beatLENGTHS ->time\n"
+            "iv .... INTERMEDIATE VALS              TM[@].. TEMPER MIDI data\n"
+            "J ..... JOIN as columns                tM .... TEXT to MIDI\n"
+            "L@ .... LOG-equal divisions            v[@] .. rank by VOTE(no of times occurs)\n"
+            "                                       V@ ..rank frqs by VOTE(@-semitone steps)\n");
+    exit(1);
+}

+ 148 - 148
dev/tabedit/columns3.c

@@ -1,148 +1,148 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
-
-    The CDP System is free software; you can redistribute it
-    and/or modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    The CDP System is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with the CDP System; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-    02111-1307 USA
- *
- */
-
-
-
-#include <columns.h>
-
-void do_shuffle(int, int);
-
-/**************************** M_REPOS ********************************/
-
-int m_repos(int j)
-{
-	int n, m, k=cnt, OK, is_set = 0;
-	int zib = -ifactor, zab = ifactor;
-	for(n=0;n<k;n++) {
-		OK = 1;
-		if(n>j && !is_set) {
-			zib++;
-			zab++;
-			is_set = 1;
-		}
-		for(m=zib;m<zab;m++) {
-			if(n+m<0)	  continue;
-			if(n+m>=cnt)  break;
-			if(flteq(fmod(number[j],12.0),fmod(number[n+m],12.0))) {
-				OK = 0;
-				break;
-			}
-		}
-		if(OK) {
-		   do_shuffle(n,j);
-		   if(j>n)
-			   return(1);	/* list shuffled forward */
-		   return(0);		/* list not shuffled forward */
-		}
-	}
-	return(-1);
-}	   
-
-/**************************** F_REPOS ********************************/
-
-int f_repos(int j)
-{
-	int n, m, k=cnt-ifactor, OK, is_set = 0;
-	double interval;
-	int zib = -ifactor, zab = ifactor;
-	for(n=0;n<k;n++) {
-		OK = 1;
-		if(n>j && !is_set) {
-			zib++;
-			zab++;
-			is_set = 1;
-		}
-		for(m=zib;m<zab;m++) {
-			if(n+m<0)	  continue;
-			if(n+m>=cnt)  break;
-			interval = log(number[j]/number[n+m])/LOG_2_TO_BASE_E;
-			interval = fmod(fabs(interval),1.0);
-			if(interval<ONEMAX || interval>ONEMIN) {
-				OK = 0;
-				break;
-			}
-		}
-		if(OK) {
-		   do_shuffle(n,j);
-		   if(j>n)
-			   return(1);	/* list shuffled forward */
-		   return(0);		/* list not shuffled forward */
-		}
-	}
-	return(-1);
-}	   
-
-/**************************** DO_SHUFFLE ******************************/
-
-void do_shuffle(int n,int j)
-{
-	int m;
-	double keep = number[j];
-	if(j > n) {
-		for(m=j;m>n;m--)
-		   number[m] = number[m-1];
-	} else {
-		for(m=j;m<n;m++)
-			number[m] = number[m+1];
-	}
-	number[n] = keep;
-}
-
-/************************* CHECK_FOR_CONDITIONAL ************************/
-
-void check_for_conditional(int *argc,char *argv[])
-{
-	int n;
-	char less_than, greater_than;
-	int condit_set = 0;
-
-	if(sloom) {
-		less_than = '@';
-		greater_than = '+';
-	} else {
-		less_than = '{';
-		greater_than = '}';
-	}
-	for(n=1;n<*argc;n++) {
-		if((condit = *argv[n])==less_than || condit==greater_than) {
-			if(condit==less_than)
-				condit = '<';
-			else
-				condit = '>';
-			argv[n]++;
-			if(sscanf(argv[n],"%lf",&thresh)!=1) {
-				sprintf(errstr,"Cannot read conditional value.\n");
-				do_error();
-			}
-			while(n<(*argc)-1) {
-				*(argv+n) = *(argv+n+1);
-				n++;
-			}
-			(*argc)--;
-			condit_set = 1;
-		}
-	}
-	if(!condit_set)
-		condit = 0;
-}
+/*
+ * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
+ * http://www.trevorwishart.co.uk
+ * http://www.composersdesktop.com
+ *
+ This file is part of the CDP System.
+
+ The CDP System is free software; you can redistribute it
+ and/or modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The CDP System is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the CDP System; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA
+ *
+ */
+
+
+
+#include <columns.h>
+
+void do_shuffle(int, int);
+
+/**************************** M_REPOS ********************************/
+
+int m_repos(int j)
+{
+    int n, m, k=cnt, OK, is_set = 0;
+    int zib = -ifactor, zab = ifactor;
+    for(n=0;n<k;n++) {
+        OK = 1;
+        if(n>j && !is_set) {
+            zib++;
+            zab++;
+            is_set = 1;
+        }
+        for(m=zib;m<zab;m++) {
+            if(n+m<0)         continue;
+            if(n+m>=cnt)  break;
+            if(flteq(fmod(number[j],12.0),fmod(number[n+m],12.0))) {
+                OK = 0;
+                break;
+            }
+        }
+        if(OK) {
+            do_shuffle(n,j);
+            if(j>n)
+                return(1);   /* list shuffled forward */
+            return(0);           /* list not shuffled forward */
+        }
+    }
+    return(-1);
+}
+
+/**************************** F_REPOS ********************************/
+
+int f_repos(int j)
+{
+    int n, m, k=cnt-ifactor, OK, is_set = 0;
+    double interval;
+    int zib = -ifactor, zab = ifactor;
+    for(n=0;n<k;n++) {
+        OK = 1;
+        if(n>j && !is_set) {
+            zib++;
+            zab++;
+            is_set = 1;
+        }
+        for(m=zib;m<zab;m++) {
+            if(n+m<0)         continue;
+            if(n+m>=cnt)  break;
+            interval = log(number[j]/number[n+m])/LOG_2_TO_BASE_E;
+            interval = fmod(fabs(interval),1.0);
+            if(interval<ONEMAX || interval>ONEMIN) {
+                OK = 0;
+                break;
+            }
+        }
+        if(OK) {
+            do_shuffle(n,j);
+            if(j>n)
+                return(1);   /* list shuffled forward */
+            return(0);           /* list not shuffled forward */
+        }
+    }
+    return(-1);
+}
+
+/**************************** DO_SHUFFLE ******************************/
+
+void do_shuffle(int n,int j)
+{
+    int m;
+    double keep = number[j];
+    if(j > n) {
+        for(m=j;m>n;m--)
+            number[m] = number[m-1];
+    } else {
+        for(m=j;m<n;m++)
+            number[m] = number[m+1];
+    }
+    number[n] = keep;
+}
+
+/************************* CHECK_FOR_CONDITIONAL ************************/
+
+void check_for_conditional(int *argc,char *argv[])
+{
+    int n;
+    char less_than, greater_than;
+    int condit_set = 0;
+
+    if(sloom) {
+        less_than = '@';
+        greater_than = '+';
+    } else {
+        less_than = '{';
+        greater_than = '}';
+    }
+    for(n=1;n<*argc;n++) {
+        if((condit = *argv[n])==less_than || condit==greater_than) {
+            if(condit==less_than)
+                condit = '<';
+            else
+                condit = '>';
+            argv[n]++;
+            if(sscanf(argv[n],"%lf",&thresh)!=1) {
+                sprintf(errstr,"Cannot read conditional value.\n");
+                do_error();
+            }
+            while(n<(*argc)-1) {
+                *(argv+n) = *(argv+n+1);
+                n++;
+            }
+            (*argc)--;
+            condit_set = 1;
+        }
+    }
+    if(!condit_set)
+        condit = 0;
+}

File diff suppressed because it is too large
+ 981 - 982
dev/tabedit/columns4.c


+ 4510 - 4510
dev/tabedit/columns5.c

@@ -1,4510 +1,4510 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
-
-    The CDP System is free software; you can redistribute it
-    and/or modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    The CDP System is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with the CDP System; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-    02111-1307 USA
- *
- */
-
-
-
-#include <columns.h>
-#include <cdplib.h>
-
-#define MIN_TEMPO (.01666667)		/* 1 beat per hour ! */
-#define MAX_TEMPO (60000)			/* 1 beat per millisecond ! */
-
-int alphabetical_order(char *,char *);
-double leveltodb(double,int);
-double dbtolevel(double);
-void hinsert(int m,int t,int *perm,int permlen);
-void ascending_sort_cells(int *perm,int ccnt);
-void hshuflup(int k,int *perm,int permlen);
-void hprefix(int m,int *perm,int permlen);
-void randperm(int *perm, int permlen);
-static void invertenv(double piv);
-static void docross
-		(double lastnval,double lastmval,double thisnval, double thismval,double time,int *j,double *out,int typ);
-static void hhinsert(int m,int t,int setlen,int *perm);
-static void hhprefix(int m,int setlen,int *perm);
-static void hhshuflup(int k,int setlen,int *perm);
-static void do_repet_restricted_perm(int *arr, int *perm, int arrsiz, int allowed, int endval);
-static void get_metre(char [],int *barlen,int *beatsize);
-static double get_tempo(char *str);
-static double get_beat(int n,int barlen);
-static void get_offset(char *str,double *offset);
-static double randoffset(double scatter);
-static double readbrk(float *warpvals,double time,int wcnt);
-
-/***************************** PRODUCT ***************************/
-
-void product(void)
-{
-	int n;
-	double sum = number[0];
-	for(n=1;n<cnt;n++)
-	sum *= number[n];
-	do_valout_as_message(sum);
-	fflush(stdout);
-}
-
-/*************************** HZ_TO_MIDI ************************/
-
-void hz_to_midi(void)
-{
-	int n;
-	for(n=0;n<cnt;n++) {
-		number[n] = hztomidi(number[n]);
-		do_valout(number[n]);
-	}
-	fflush(stdout);
-}
-
-/******************************** FIND_MEAN *************************/
-
-void find_mean(void)
-{
-	double sum = 0.0;
-	int n;
-	for(n=0;n<cnt;n++)
-		sum += number[n];
-	sum /= (double)cnt;
-	do_valout_as_message(sum);
-	fflush(stdout);
-}
-
-/******************************** MIDI_TO_HZ **************************/
-
-void midi_to_hz(void)
-{
-	int n;
-	for(n=0;n<cnt;n++) {
-		number[n] = miditohz(number[n]);
-		do_valout(number[n]);
-	}
-	fflush(stdout);
-}
-
-/*************************** MAJOR_TO_MINOR *************************/
-
-void major_to_minor(void)
-{
-	int n;
-	int m3 = (4 + ifactor)%12;	/* MIDI location of major 3rd */
-	int m6 = (9 + ifactor)%12;	/* MIDI location of major 6th */
-	for(n=0;n<cnt;n++) {
-		factor = fmod(number[n],TWELVE);
-		if(flteq(factor,(double)m3) || flteq(factor,(double)m6))
-			number[n] -= 1.0;
-		do_valout(number[n]);
-	}
-	fflush(stdout);
-}
-
-/****************** REMOVE_MIDI_PITCHCLASS_DUPLICATES *******************/
-
-void remove_midi_pitchclass_duplicates(void)
-{
-	int n, m, move;
-	int k = cnt-ifactor;
-	int failed = 0;
-	for(n=0;n<k;n++) {
-		for(m=1;m<=ifactor;m++) {
-			if(n+m >= cnt)
-				break;
-			if(flteq(fmod(number[n],12.0),fmod(number[n+m],12.0))) {
-				if((move = m_repos(n+m))<0) {
-					failed++;
-				} else {
-					n += move;	/* list shufld forwd, or not */
-					m--;		/* m+1th item now at m */
-				}
-			}
-		}
-	}
-	if(failed)
-		fprintf(stdout,"WARNING: %d items failed to be separated.\n",failed);
-	for(n=0;n<cnt;n++)
-		do_valout(number[n]);
-	fflush(stdout);
-}
-
-/************************** REVERSE_LIST *************************/
-
-void reverse_list(void)
-{
-	int n;
-	for(n=stringscnt-1;n>=0;n--)
-		do_stringout(strings[n]);
-	fflush(stdout);
-}
-
-/************************* ROTATE_MOTIF *************************/
-
-void rotate_motif(void)
-{
-	int n;
-	for(n=cnt-ifactor;n<cnt;n++)
-		do_valout(number[n]);
-	for(n=0;n<cnt-ifactor;n++)
-		do_valout(number[n]);
-	fflush(stdout);
-}
-
-/************************** RATIOS ****************************/
-
-void ratios(void)
-{
-	int n;
-	for(n=1;n<cnt;n++) {
-		if(flteq(number[n-1],0.0))
-			do_stringout("INF\n");
-		else
-			do_valout(number[n]/number[n-1]);
-	}
-	fflush(stdout);
-}
-
-/******************************** RECIPROCALS ***********************/
-
-void reciprocals(int positive_vals_only)
-{
-	int n;
-	if(positive_vals_only) {
-		for(n=0;n<cnt;n++) {
-			if(number[n] < FLTERR) {
-				fprintf(stdout,"ERROR: Invalid value %d (%lf) for this process\n",n+1,number[n]);
-				fflush(stdout);
-				exit(1);
-			}
-		}
-	}
-	for(n=0;n<cnt;n++) {
-		switch(condit) {
-		case(0):
-			if(flteq(number[n],0.0)) {
-				if(!sloom && !sloombatch)
-					fprintf(fp[1],"INFINITE\n");
-				else if(sloombatch) {
-					fprintf(stdout,"INFINITE\n");
-					fflush(stdout);
-				} else {
-					fprintf(stdout,"ERROR: Division by zero encountered (item %d) : Impossible\n",n+1);
-					fflush(stdout);
-					exit(1);
-				}
-			} else
-				do_valout(factor/number[n]);
-			break;
-		case('>'):
-			if(number[n]>thresh) {
-				if(flteq(number[n],0.0)) {
-					if(!sloom && !sloombatch)
-						fprintf(fp[1],"INFINITE\n");
-					else if(sloombatch) {
-						fprintf(stdout,"INFINITE\n");
-						fflush(stdout);
-					} else {
-						fprintf(stdout,"ERROR: Division by zero encountered (item %d) : Impossible\n",n+1);
-						fflush(stdout);
-						exit(1);
-					}
-				} else
-					do_valout(factor/number[n]);
-			} else
-				do_valout(number[n]);
-			break;
-		case('<'):
-			if(number[n]<thresh) {
-				if(flteq(number[n],0.0)) {
-					if(!sloom && !sloombatch)
-						fprintf(fp[1],"INFINITE\n");
-					else if(sloombatch) {
-						fprintf(stdout,"INFINITE\n");
-						fflush(stdout);
-					} else {
-						fprintf(stdout,"ERROR: Division by zero encountered (item %d) : Impossible\n",n+1);
-						fflush(stdout);
-						exit(1);
-					}
-				} else
-					do_valout(factor/number[n]);
-			} else
-				do_valout(number[n]);
-			break;
-		}
-	}
-	fflush(stdout);
-}
-
-/****************************** RANDOMISE_ORDER *********************/
-
-void randomise_order(int *perm)
-{
-	int n;
-	randperm(perm,stringscnt);
-	for(n=0;n<stringscnt;n++)
-		do_stringout(strings[perm[n]]);
-	fflush(stdout);
-}
-
-/****************************** RANDOMISE_ORDER *********************/
-
-void randomise_Ntimes(int *perm)
-{
-	int n = 0, m, lastperm;
-	for(m = 0;m< ifactor;m++) {
-		if(n == 0)
-			randperm(perm,stringscnt);
-		else {
-			lastperm = perm[stringscnt - 1];
-			randperm(perm,stringscnt);
-			while(perm[0] == lastperm)
-				randperm(perm,stringscnt);
-		}
-		for(n=0;n<stringscnt;n++)
-			do_stringout(strings[perm[n]]);
-	}
-	fflush(stdout);
-}
-
-/************************** ADD_RANDVAL_PLUS_OR_MINUS ********************/
-
-void add_randval_plus_or_minus(void)
-{
-	int n;
-	for(n=0;n<cnt;n++) {
-		number[n] += ((drand48() * 2.0) - 1.0) * factor;
-		do_valout(number[n]);
-	}
-	fflush(stdout);
-}
-
-/****************************** ADD_RANDVAL ***************************/
-
-void add_randval(void)
-{
-	int n;
-	for(n=0;n<cnt;n++) {
- 		number[n] += drand48() * factor;
-		do_valout(number[n]);
-	}
-	fflush(stdout);
-}
-
-/************************ MULTIPLY_BY_RANDVAL ************************/
-
-void multiply_by_randval(void)
-{
-	int n;
-	for(n=0;n<cnt;n++) {
-		number[n] *= drand48() * factor;
-		do_valout(number[n]);
-	}
-	fflush(stdout);
-}
-
-/***************************** RANDCHUNKS ************************/
-
-void randchunks(void)
-{
-	double sum = 0.0;
-	double randrange = fabs(number[1] - number[0]);
-	double minn = min(number[1],number[0]);
-	while(sum<factor) {
-		do_valout(sum);
-		sum += (drand48() * randrange) + minn;
-	}
-	fflush(stdout);
-}
-
-/************************** GENERATE_RANDOM_VALUES ***********************/
-
-void generate_random_values(void)
-{
-	double randrange = number[1] - number[0];
-	int n;
-	for(n=0;n<factor;n++)
-		do_valout((drand48() * randrange) + number[0]);
-	fflush(stdout);
-}
-
-/****************************** RANDOM_0S_AND_1S ********************/
-
-void random_0s_and_1s(void)
-{
-	int n;
-	double sum;
-	int totcnt = (int)round(number[0]);
-	for(n=0;n<totcnt;n++) {
-		sum = drand48() * 2.0;
-  		if(sum>=1.0)
-			do_stringout("1\n");
-		else
-			do_stringout("0\n");
-	}
-	fflush(stdout);
-}
-
-/****************************** RANDOM_PAIRS ********************/
-
-void random_pairs(void)
-{
-	int n;
-	double sum;
-	int totcnt = (int)round(number[2]);
-	char tempa[200];
-	char tempb[200];
-	sprintf(tempa,"%d",(int)round(number[0]));
-	sprintf(tempb,"%d",(int)round(number[1]));
-	for(n=0;n<totcnt;n++) {
-		sum = drand48() * 2.0;
-  		if(sum>=1.0)
-			do_stringout(tempb);
-		else
-			do_stringout(tempa);
-	}
-	fflush(stdout);
-}
-
-/****************************** RANDOM_0S_AND_1S_RESTRAINED ********************/
-
-void random_0s_and_1s_restrained(void)
-{
-	int n, cnt0 = 0, cnt1 = 0;
-	double sum;
-	int totcnt = (int)round(number[0]);
-	int limit  = (int)round(number[1]);
-	for(n=0;n<totcnt;n++) {
-		sum = drand48() * 2.0;
-		if(sum>=1.0) {
-			cnt1++;
-			if(cnt1 <= limit) {
-				do_stringout("1\n");
-				cnt0 = 0;
-			} else {
-				do_stringout("0\n");
-				cnt1 = 0;
-				cnt0 = 1;
-			}
-		} else {
-			cnt0++;
-			if(cnt0 <= limit) {
-				do_stringout("0\n");
-				cnt1 = 0;
-			} else {
-				do_stringout("1\n");
-				cnt0 = 0;
-				cnt1 = 1;
-			}
-		}
-	}
-	fflush(stdout);
-}
-
-/****************************** RANDOM_PAIRS_RESTRAINED ********************/
-
-void random_pairs_restrained(void)
-{
-	int n, cnt0 = 0, cnt1 = 0;
-	double sum;
-	int totcnt = (int)round(number[2]);
-	int limit  = (int)round(number[3]);
-	char tempa[200];
-	char tempb[200];
-	sprintf(tempa,"%d",(int)round(number[0]));
-	sprintf(tempb,"%d",(int)round(number[1]));
-	for(n=0;n<totcnt;n++) {
-		sum = drand48() * 2.0;
-		if(sum>=1.0) {
-			cnt1++;
-			if(cnt1 <= limit) {
-				do_stringout(tempb);
-				cnt0 = 0;
-			} else {
-				do_stringout(tempa);
-				cnt1 = 0;
-				cnt0 = 1;
-			}
-		} else {
-			cnt0++;
-			if(cnt0 <= limit) {
-				do_stringout(tempa);
-				cnt1 = 0;
-			} else {
-				do_stringout(tempb);
-				cnt0 = 0;
-				cnt1 = 1;
-			}
-		}
-	}
-	fflush(stdout);
-}
-
-/****************************** RANDOM_SCATTER **********************/
-
-void random_scatter(void)
-{
-	int n;
-	double scatter; 
-	double *diffs = (double *)exmalloc((cnt-1)*sizeof(double));
-	for(n=0;n<cnt-1;n++) {
-	 	diffs[n] = number[n+1] - number[n];
-		diffs[n] /= 2.0;
-	}
-	for(n=1;n<cnt-1;n++) {
-		scatter = ((drand48() * 2.0) - 1.0) * factor;
-		if(scatter > 0.0)
-			number[n] += diffs[n] * scatter;
-		else
-			number[n] += diffs[n-1] * scatter;
-	}
-	print_numbers();
-}
-
-/************************** RANDOM_ELIMINATION ***********************/
-
-void random_elimination(void)
-{
-	int n, m;
-	for(n=0;n<ifactor;n++) {
-		m = (int)(drand48() * cnt);	/* TRUNCATE */
-		eliminate(m);
-	}
-	print_numbers();
-}
-
-/*************************** EQUAL_DIVISIONS ************************/
-
-void equal_divisions(void)
-{
-	double interval = (number[1] - number[0])/factor;
-	double sum = number[0];
-	if(interval > 0.0) {
-		while(sum<=number[1]) {
-			do_valout(sum);
-			 sum += interval;
-		}
-	} else {
-		while(sum>=number[1]) {
-			do_valout(sum);
-			sum += interval;
-		}
-	}
-	fflush(stdout);
-}
-
-/************************* LOG_EQUAL_DIVISIONS ***********************/
-
-void log_equal_divisions(void)
-{
-	double sum		  = log(number[0]);
-	double top	  = log(number[1]);
-	double interval = (top - sum)/factor;
-	if(sum < top) {
-		while(sum <= top - FLTERR) {
-			do_valout(exp(sum));
-			sum += interval;
-		}
- 		
-	} else {
-		while(sum >= top + FLTERR) {
-			do_valout(exp(sum));
-			sum += interval;
-		}
-	}
-	do_valout(number[1]);
-	fflush(stdout);
-}
-
-/****************************** QUADRATIC_CURVE_STEPS ******************/
-
-void quadratic_curve_steps(void)
-{
-	double sum, diff = number[1] - number[0];
-	double step = fabs(1.0/(factor - 1.0));
-	double thisstep = 0.0;
-	int cnt = 0, ifactor = round(factor);
-	if(diff>0.0)
-		number[2] = 1.0/number[2];
-	for(;;) {
-		sum = pow(thisstep,number[2]);
-		sum = (sum * diff) + number[0];
-		do_valout(sum);
-		if(++cnt >= ifactor)
-			break;
-		thisstep += step;
-	}
-	fflush(stdout);
-}
-
-/*************************** PLAIN_BOB ***************************/
-
-void plain_bob(void)
-{
-	int n, m, k;
-	for(n=0;n<cnt;n++) 
-		do_valout(number[n]);
-	for(m=0;m<cnt-1;m++) {
-		for(k=0;k<cnt-1;k++) {
-			bellperm1();
-			for(n=0;n<cnt;n++)
-				do_valout(number[n]);
-			bellperm2();
-			for(n=0;n<cnt;n++)
-				do_valout(number[n]);
-		}
-		bellperm1();
-		for(n=0;n<cnt;n++)
-			do_valout(number[n]);
-		bellperm3();
-		for(n=0;n<cnt;n++)
-			do_valout(number[n]);
-	}	
-	fflush(stdout);
-}
-
-/*********************** REPEAT_INTERVALS *************************/
-
-void repeat_intervals(void)
-{
-	int n, m;
-	double z, k;
-	for(n=0;n<cnt-1;n++)
-		do_valout(number[n]);
-	z = k = number[n] - number[0];
-	for(m=1;m<=ifactor;m++) {
-		for(n=0;n<cnt-1;n++)	/*TW Feb 2005*/
-			do_valout(number[n] + z);
-		z += k;
-	}
-	fflush(stdout);
-}
-
-/************** MAKE_EQUAL_INTEVALS_BTWN_GIVEN_VALS ************/
-
-void make_equal_intevals_btwn_given_vals(void)
-{
-	double top = number[1];
-	double sum = number[0];
-
-	if(factor > 0.0) {
-		if(number[0] > number[1]) {
-			top = number[0];
-			sum = number[1];
-		}
-	} else {
-			if(number[0] < number[1]) {
-			top = number[0];
-			sum = number[1];
-		}
-	}
-	if(top >= sum ) {
-		while(sum<=top) {
-			do_valout(sum);
-			sum += factor;
-		}
-	} else {
-		while(sum>=top) {
-			do_valout(sum);
-			sum += factor;
-		}
-	}
-	fflush(stdout);
-}
-
-/********************** CREATE_INTERVALS ***********************/
-
-void create_intervals(void)
-{
-	int n;
-	for(n=0;n<ifactor;n++) {
-		do_valout(number[0] * n);
-	}
-	fflush(stdout);
-}
-
-/********************** CREATE_INTERVALS_FROM_BASE ***********************/
-
-void create_intervals_from_base(void)
-{
-	int n;
-	double sum = number[1];
-	for(n=0;n<ifactor;n++) {
-		do_valout(sum);
-		sum += number[0];
-	}
-	fflush(stdout);
-}
-
-/********************** CREATE_RATIOS_FROM_BASE ***********************/
-
-void create_ratios_from_base(void)
-{
-	int n;
-	double sum = number[1];
-	for(n=0;n<ifactor;n++) {
-		do_valout(sum);
-		if(sum > HUGE/2.0 || sum < -HUGE/2.0) {
-			sprintf(errstr,"Calculation overflows.\n");
-			do_error();
-		}
-		sum *= number[0];
-	}
-	fflush(stdout);
-}
-
-/********************** CREATE_EQUAL_STEPS ***********************/
-
-void create_equal_steps(void)
-{
-	int n;
-	double sum = number[0];
-	double step = (number[1] - number[0])/((double)ifactor - 1.0);
-	for(n=0;n<ifactor;n++) {
-		do_valout(sum);
-		sum += step;
-	}
-	fflush(stdout);
-}
-
-/********************** CREATE_EQUAL_VALS ***********************/
-
-void create_equal_vals(void)
-{
-	int n;
-	for(n=0;n<ifactor;n++) {
-		do_valout(number[0]);
-	}
-	fflush(stdout);
-}
-
-/************************ CHANGE_VALUE_OF_INTERVALS ********************/
-
-void change_value_of_intervals(void)
-{
-	double interval, sum = number[0];
-	int n;
-	for(n=1;n<cnt;n++) {
-		do_valout(sum);
-		switch(ro) {
-			case('a'): interval=(number[n]-number[n-1])+factor; break;
-			case('m'): interval=(number[n]-number[n-1])*factor; break;
-			default:
-				fprintf(stdout,"ERROR: Unkonwn case in change_value_of_intervals()\n");
-				fflush(stdout);
-				exit(1);
-				break;
-		}
-		sum += interval;
-	}
-	do_valout(sum);
-	fflush(stdout);
-}
-
-/******************** MOTIVICALLY_INVERT_MIDI **********************/
-
-void motivically_invert_midi(void)
-{
-	double factor = 2.0 * number[0];
-	int n;
-	for(n=1;n<cnt;n++)
-		number[n] = factor - number[n];
-	print_numbers();
-}
-
-/********************** MOTIVICALLY_INVERT_HZ **********************/
-
-void motivically_invert_hz(void)
-{
-	double factor;
-	int n;
-	if(flteq((factor = number[0] * number[0]),0.0)) {
-		sprintf(errstr,"First frq is zero : can't proceed.\n");
-		do_error();
-	}
-	for(n=1;n<cnt;n++)
-		number[n] = factor/number[n];
-	print_numbers();
-}
-
-/******************** GET_INTERMEDIATE_VALUES ************************/
-
-void get_intermediate_values(void)
-{
-	int n;
-	double d;
-	for(n=1;n<cnt;n++) {
-		d = (number[n] + number[n-1])/2.0;
-		do_valout(d);
-	}
-	fflush(stdout);
-}
-
-/******************** INSERT_INTERMEDIATE_VALUES ************************/
-
-void insert_intermediate_values(void)
-{
-	int n;
-	double d;
-	fprintf(stdout,"INFO: %lf\n",number[0]);
-	for(n=1;n<cnt;n++) {
-		d = (number[n] + number[n-1])/2.0;
-		fprintf(stdout,"INFO: %lf\n",d);
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-	}
-	fflush(stdout);
-}
-
-/******************** INSERT_INTERMEDIATE_VALP ************************/
-
-void insert_intermediate_valp(void)
-{
-	int n;
-	double d;
-	for(n=1;n<cnt;n+=2) {
-		fprintf(stdout,"INFO: %lf\n",number[n-1]);
-		d = (number[n] + number[n-1])/2.0;
-		fprintf(stdout,"INFO: %lf\n",d);
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-	}
-	fflush(stdout);
-}
-
-/************************** GET_INTERVALS ***********************/
-
-void get_intervals(void)
-{
-	int n;
-	for(n=1;n<cnt;n++)
-		do_valout(number[n]-number[n-1]);
-	fflush(stdout);
-}
-
-/************************ GET_ONE_SKIP_N ************************/
-
-void get_one_skip_n(void)
-{
-	int n = 0;
-	ifactor = round(factor);
- 	if(ifactor < 1) {
-		sprintf(errstr,"Invalid parameter (%d)\n",ifactor);
-		do_error();
-	}
-	while(n<stringscnt) {
-		do_stringout(strings[n++]);
-		n += ifactor;
-	}
-	fflush(stdout);
-}
-
-/************************ GET_N_SKIP_ONE *************************/
-
-void get_n_skip_one(void)
-{
-	int m, n = 0;	
-	int k, ifactor = round(factor);
-
-	if(ifactor < 1) {
-		sprintf(errstr,"Invalid parameter (%d)\n",ifactor);
-		do_error();
-	}
-	while(n<stringscnt) {
-		if((k = n + ifactor) >= stringscnt) {
-			for(m=n;m<stringscnt;m++)
-				do_stringout(strings[m]);
-			break;
-		}
-		for(m=n;m<k;m++)
-			do_stringout(strings[m]);
-		n+= ifactor+1;
-	}
-	fflush(stdout);
-}
-
-/************************* SUM_NWISE **************************/
-
-void sum_nwise(void)
-{
-	int n, m;
-	ifactor = round(factor);
-/* RWD */
-	if(ifactor > cnt) {
-		sprintf(errstr,"group size (N) too large for infile\n");
-		do_error();
-	}
-	for(n=0;n<=cnt-ifactor;n++) {	/*RWD: test was just < */
-		for(m=1;m<ifactor;m++)
-			number[n] += number[n+m];
-		do_valout(number[n]);
-	}
-	fflush(stdout);
-}
-
-/************************* SUM_MINUS_OVERLAPS *********************/
-
-void sum_minus_overlaps(void)
-{
-	int n;
-	double sum = 0.0;
-	for(n=0;n<cnt;n++)
-		sum += number[n];
-	sum -= (double)(cnt-1) * factor;
-	do_valout_as_message(sum);
-	fflush(stdout);
-}
-
-/******************** SUM_ABSOLUTE_DIFFERENCES ********************/
-
-void sum_absolute_differences(void)
-{
-	int n;
-	double sum = 0.0;
-	for(n=1;n<cnt;n++)
-		sum += fabs(number[n] - number[n-1]);
-	sum -= (double)(cnt-1) * factor;
-	do_valout_as_message(sum);
-	fflush(stdout);
-}
-
-/**************************** STACK ***************************/
-
-void stack(int with_last)
-{
-	int n;
-		double sum = 0.0;
-	for(n=0;n<cnt;n++) {
-		do_valout(sum);
-		sum += number[n] - factor;
-	}
-	if(with_last) {
-		sum += factor;
-		do_valout(sum);
-	}
-	fflush(stdout);
-}
-
-/*********************** DUPLICATE_VALUES **************************/
-
-void duplicate_values(void)
-{
-	int n, m;
-	for(n=0;n<stringscnt;n++) {
-		for(m=0;m<ifactor;m++)
-			do_stringout(strings[n]);
-	}
-	fflush(stdout);
-}
-
-/*********************** DUPLICATE_VALUES_STEPPED **************************/
-
-void duplicate_values_stepped(void)
-{
-	int n, m;
-	double step = number[cnt+1];
-	double offset = 0.0;
-	ifactor = round(number[cnt]);
-	for(m=0;m<ifactor;m++) {
-		for(n=0;n<cnt;n++)
-			fprintf(stdout,"INFO: %lf\n",number[n] + offset);
-		offset += step;
-	}
-	fflush(stdout);
-}
-/**************************** DUPLICATE_LIST **********************/
-
-void duplicate_list(void)
-{
-	int n, m;
-	for(m=0;m<ifactor;m++) {
-		for(n=0;n<stringscnt;n++)
-			do_stringout(strings[n]);
-	}
-	fflush(stdout);
-}
-
-/****************************** FORMAT_VALS ****************************/
-
-void format_vals(void)
-{ /*RWD new Format option : recast by TW */
-	int n, m, OK = 1;
-	double d = (double)cnt/(double)ifactor;
-	int rowcnt = cnt/ifactor;
-	char temp[64];
-
-	errstr[0] = ENDOFSTR;
-	if(d > (double)rowcnt)
-		rowcnt++;
-	if((rowcnt > 82) && sloom) {
-		sprintf(errstr,"Too many (%d) rows to handle",rowcnt);
-		do_error();
-	}
-	for(n=0;n<cnt;n+=rowcnt) {
-		for(m=0;m<rowcnt;m++) {
-			if(!sloom && !sloombatch) {
-				if(n!=0 && m==0)
-					fprintf(fp[1],"\n");
-				if(n+m < cnt)
-					fprintf(fp[1],"%.5lf ",number[n+m]);
-				else
-					OK = 0;
-			} else {
-				if(n!=0 && m==0) {
-					fprintf(stdout,"INFO: %s\n",errstr);
-					errstr[0] = ENDOFSTR;
-				}
-				if(n+m < cnt) {
-					sprintf(temp,"%.5lf ",number[n+m]);
-					strcat(errstr,temp);
-				} else
-					OK = 0;
-			}
-		}
-		if(!OK)
-			break;
-	}
-	if(!sloom && !sloombatch)
-		fprintf(fp[1],"\n");
-	else
-		fprintf(stdout,"INFO: %s\n",errstr);
-	fflush(stdout);
-}
-
-
-/****************************** COLUMN_FORMAT_VALS ****************************/
-
-void column_format_vals(void)
-{	int n, m;
-
-	double d = (double)cnt/(double)ifactor;
-	int rowcnt = cnt/ifactor;
-	char temp[64];
-	errstr[0] = ENDOFSTR;
-	if(d > (double)rowcnt)
-		rowcnt++;
-	for(n=0;n<rowcnt;n++) {
-		for(m=n;m<cnt;m+=rowcnt) {
-			if(!sloom && !sloombatch)
-				fprintf(fp[1],"%.5lf ",number[m]);
-			else {
-				sprintf(temp,"%.5lf ",number[m]);
-				strcat(errstr,temp);
-			}
-		}
-		if(!sloom && !sloombatch)
-			fprintf(fp[1],"\n");
-		else {
-			fprintf(stdout,"INFO: %s\n",errstr);
-			errstr[0] = ENDOFSTR;
-		}
-	}
-	fflush(stdout);
-}
-
-
-/************************ INTERVAL_LIMIT() ********************/
-
-void interval_limit(void)
-{
-	double interval, sum = number[0];
-	int n;
-	do_valout(sum);
-	for(n=1;n<cnt;n++) {
-		interval=number[n]-number[n-1];
-		switch(ro) {
-		case('l'): interval = max(interval,factor);	break;
-		case('L'): interval = min(interval,factor);	break;
-		}
-		sum += interval;
-		do_valout(sum);
-	}
-	fflush(stdout);	
-}
-
-/********************************** TIME_DENSITY ******************************/
-
-void time_density(void)
-{
-	int n, m = 0, k, ended = 0;
-	double min_endtime, *endtime = (double *)exmalloc(ifactor * sizeof(double));
-	for(n=0;n<ifactor;n++)
-		endtime[n] = 0.0;
-	min_endtime = 0.0;
-	for(;;) {
-		for(n=0;n<ifactor;n++) {
-			if(flteq(endtime[n],min_endtime)) {
-				do_valout(endtime[n]);
-				endtime[n] += number[m];
-				if(++m >= cnt) {
-					ended = 1;
-					break;
-				}
-				min_endtime = endtime[n];
-				for(k=0;k<ifactor;k++) {
-					if(endtime[k] < min_endtime)
-						min_endtime = endtime[k];
-				}
-			}
-		}
-		if(ended)
-			break;
-	}
-	fflush(stdout);
-}
-
-/********************************** DIVIDE_LIST ******************************/
-
-void divide_list(void)
-{
-	int n;
-	for(n=0;n<cnt;n++) {
-		switch(condit) {
-		case(0):
-			number[n] /= factor;
-			break;
-		case('>'):
-			if(number[n]>thresh)
-				number[n] /= factor;
-			break;
-		case('<'):
-			if(number[n]<thresh)
-				number[n] /= factor;
-			break;
-		}
-		do_valout(number[n]);
-	}
-	fflush(stdout);
-}
-
-/********************************** GROUP ******************************/
-
-void group(void)
-{
-	int n, m = 0;
-	while(m < ifactor) {
-		for(n=m;n<stringscnt;n+=ifactor) {
-			do_stringout(strings[n]);
-		}
-		if(!sloom && !sloombatch)
-			fprintf(fp[1],"\n");
-		m++;
-	}
-	fflush(stdout);
-}
-
-/********************************** DUPLICATE_OCTAVES ******************************/
-
-void duplicate_octaves(void)
-{
-	int n, m;
-	double d;
-	for(n=0;n<cnt;n++)
-		do_valout(number[n]);
-	for(m=1;m<=ifactor;m++) {
-		d = 12.0 * m;
-		for(n=0;n<cnt;n++)
-			do_valout(number[n] + d);
-	}
-	fflush(stdout);
-}
-
-/********************************** DUPLICATE_OCTFRQ ******************************/
-
-void duplicate_octfrq(void)
-{
-	int n, m;
-	double d;
-	for(n=0;n<cnt;n++)
-		do_valout(number[n]);
-	for(m=1;m<=ifactor;m++) {
-		d = pow(2.0,(double)m);
-		for(n=0;n<cnt;n++)
-			do_valout(number[n] * d);
-	}
-	fflush(stdout);
-}
-
-/********************************** INTERVAL_TO_RATIO ******************************/
-
-void interval_to_ratio(int semitones,int tstretch) 
-{
-	int n;
-	double bum = 0.0;
-	for(n=0;n<cnt;n++) {
-		if(semitones) {
-			bum = number[n];
-			number[n] /= 12.0;
-		}
-	 	if(fabs(number[n]) > MAXOCTTRANS) {
-			if(!semitones)
-				bum = number[n];
-			sprintf(errstr,"Item %d (%lf) is too large or small to convert.\n",n+1,bum);
-			do_error();
-		}
-	}
-	for(n=0;n<cnt;n++) {
-		number[n] = pow(2.0,number[n]);
-		if(tstretch)
-			number[n] = 1.0/number[n];
-		do_valout(number[n]);
-	}
-	fflush(stdout);
-}
-
-/********************************** RATIO_TO_INTERVAL ******************************/
-
-void ratio_to_interval(int semitones,int tstretch) 
-{
-	int n;
-	for(n=0;n<cnt;n++) {
-		if(number[n] < FLTERR) {
-			fprintf(stdout,"ERROR: ratio %d (%lf) is too small or an impossible (negative) value.\n",n+1,number[n]);
-			fflush(stdout);
-			exit(1);
-		}
-		if(tstretch)
-			number[n] = 1.0/number[n];
-	}
-	for(n=0;n<cnt;n++) {
-		number[n] = log(number[n]) * ONE_OVER_LN2;
-		if(semitones)
-			number[n] *= 12.0;
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-	}
-	fflush(stdout);
-}
-
-/********************************** DO_SLOPE ******************************/
-
-void do_slope(void) 
-{
-	int n;
-	double ddiff;
-	do_valout(number[0]);
-	for(n=1;n<cnt;n++) {
-		ddiff = number[n] - number[0];
-		ddiff *= factor;
-		number[n] = number[0] + ddiff;
-		do_valout(number[n]);
-	}
-	fflush(stdout);
-}
-
-
-/********************************** ALPHABETIC_SORT ******************************/
-
-void alphabetic_sort(void)
-{
-	int n,m;
-	char tempp[200],*p;
-	for(n=1;n<stringscnt;n++)  {
-		p =  strings[n];
-		strcpy(tempp,strings[n]);
-		m = n-1;
-		while(m >= 0 && alphabetical_order(tempp,strings[m])) {
-			strings[m+1] = strings[m];
-			m--; 
-		}
-		strings[m+1] = p;
-	}
-	for(n=0;n<stringscnt;n++)
-		do_stringout(strings[n]);	 
-	fflush(stdout);
-}
-
-/******************************* ALPHABETICAL_ORDER **************************/
-
-#define UPPERCASE(x)  ((x) >= 'A' && (x) < 'Z')
-
-
-int alphabetical_order(char *str1,char *str2)
-{
-	char p, q;
-	int n,m;
-	int j = strlen(str1);
-	int k = strlen(str2);
-	m = min(j,k);
-	for(n=0;n<m;n++) {
-		p = str1[n];
-		q = str2[n];
-		if(UPPERCASE(p))	  p += 32;
-		if(UPPERCASE(q))	  q += 32;
-		if(p > q)  	return(0);
-		if(p < q)  	return(1);
-	}
-	if(k<j)
-		return(0);
-	return(1);
-}
-
-/********************************** LEVEL_TO_DB ******************************/
-
-void level_to_db(int sampleval) 
-{
-	int n;	
-	for(n=0;n<cnt;n++) {
-		if(sampleval)
-			number[n] /= (double)MAXSAMP;
-		number[n] = leveltodb(number[n],n);
-		sprintf(errstr,"%lfdB\n",number[n]);
-		do_stringout(errstr);
-	}
-	fflush(stdout);
-}
-
-/********************************** DB_TO_LEVEL ******************************/
-
-void db_to_level(int sampleval) 
-{
-	int n;
-	for(n=0;n<cnt;n++) {
-		number[n] = dbtolevel(number[n]);
-		if(sampleval)
-			number[n] *= (double)MAXSAMP;
-		do_valout(number[n]);
-	}
-	fflush(stdout);
-}
-
-/******************************** LEVELTODB ***********************/
-
-double leveltodb(double val,int n)
-{
-	
-	if(val <= 0.0) {
-		sprintf(errstr,"Gain value %d <= 0.0: Cannot proceed\n",n+1);
-		do_error();
-	}
-	val = log10(val);
-	val *= 20.0;
-	return(val);
-}	
-	
-/******************************** DBTOLEVEL ***********************/
-
-double dbtolevel(double val)
-{
-	int isneg = 0;
-	if(flteq(val,0.0))
-		return(1.0);
-	if(val < 0.0) {
-		val = -val;
-		isneg = 1;
-	}
-	val /= 20.0;
-	val = pow(10.0,val);
-	if(isneg)
-		val = 1.0/val;
-	return(val);
-}	
-
-/******************************** COLUMNATE ***********************/
-
-void columnate(void)
-{
-	int n;
-	for(n=0;n<cnt;n++)
-		do_valout(number[n]);
-	fflush(stdout);
-}
-
-/******************************** SAMP_TO_TIME ***********************/
-
-void samp_to_time(void)
-{
-	int n;
-	double inv_sr = 1.0/(double)ifactor;
-	for(n=0;n<cnt;n++)
-		do_valout(number[n] * inv_sr);
-	fflush(stdout);
-}
-
-/******************************** TIME_TO_SAMP ***********************/
-
-void time_to_samp(void)
-{
-	int n;
-	for(n=0;n<cnt;n++) {
-		do_valout(number[n] * (double)ifactor);
-	}
-	fflush(stdout);
-}
-
-/******************************** DELETE_SMALL_INTERVALS ***********************/
-
-void delete_small_intervals(void)
-{
-	int n, m;
-	int start = 1, end = 1, shrink;
-	double diff;
-	for(n=1;n<cnt;n++) {
-		if((diff = number[n] - number[n-1]) < 0) {
-			fprintf(stdout,"WARNING: Numbers must be in ascending order for this option.\n");
-			fflush(stdout);
-			exit(1);
-		}
-		if(diff <= factor)
-			end++;
-		else {
-			if((shrink = (end - start))) {
-				for(m = n-1;m < cnt; m++)
-					number[m-shrink] = number[m];
-				end = start;
-				cnt -= shrink;
-				n -= shrink;
-			}
-			start++;
-			end++;
-		}
-	}
-	for(n=0;n<cnt;n++)
-		do_valout(number[n]);
-	fflush(stdout);
-}
-
-/******************************** MARK_EVENT_GROUPS ***********************/
-
-void mark_event_groups(void)
-{
-	int n, m;
-	int start = 1, end = 1, shrink;
-	int orig_cnt = cnt;
-	double diff;
-	for(n=1;n<cnt;n++) {
-		if((diff = number[n] - number[n-1]) < 0) {
-			fprintf(stdout,"WARNING: Numbers must be in ascending order for this option.\n");
-			fflush(stdout);
-			exit(1);
-		}
-		if(diff <= factor) {
-			end++;
-		} else {
-			shrink = end - start;
-			switch(shrink) {
-			case(1):		  	/* 2 in group, preserve */
-				start++;
-				break;
-			case(0):			/* 1 isolated point, duplicate */
-				cnt++;
-				if(cnt > orig_cnt) {
-					if((number = (double *)realloc((char *)number,cnt * sizeof(double)))==NULL) {
-						fprintf(stdout,"WARNING: Out of memory for storing numbers.\n");
-						fflush(stdout);
-						exit(1);
-					}
-					orig_cnt = cnt;
-				}
-				for(m = cnt-1; m >= n; m--)
-					number[m] = number[m-1];
-				n++;
-				start++;
-				end++;
-				break;
-			default:			/* >2 in group, bracket */
-				shrink--;
-				for(m = n-1;m < cnt; m++)
-					number[m-shrink] = number[m];
-				end = start;
-				cnt -= shrink;
-				n -= shrink;
-				break;
-			}
-			start++;
-			end++;
-		}
-	}
-	shrink = end - start;
-	switch(shrink) {
-	case(0):
-		cnt++;
-		if(cnt > orig_cnt) {
-			if((number = (double *)realloc((char *)number,cnt * sizeof(double)))==NULL) {
-				fprintf(stdout,"WARNING: Out of memory for storing numbers.\n");
-				fflush(stdout);
-				exit(1);
-			}
-		}
-		for(m = cnt-1; m >= n; m--)
-			number[m] = number[m-1];
-		break;
-	case(1):
-		break;
-	default: 
-		shrink--;
-		for(m = n-1;m < cnt; m++)
-			number[m-shrink] = number[m];
-		cnt -= shrink;
-		break;
-	}
-	for(n=0;n<cnt;n++)
-		do_valout(number[n]);
-	fflush(stdout);
-}
-
-/******************************** SPANPAIR ***********************
- *
- * span pairs of values.
- */
-
-void spanpair(void)
-{
-	int n, m, is_even = 1;
-	int cnt2 = cnt * 2;
-	if(cnt & 1) {
-		fprintf(stdout,"WARNING: This process only works on an even number of values.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	if((number = (double *)realloc((char *)number,cnt2 * sizeof(double)))==NULL) {
-		fprintf(stdout,"WARNING: Out of memory for storing numbers.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	m = cnt2-1; 
-	for(n=cnt-1;n>=0;n--) {
-		if(number[n] < 0.0) {
-			fprintf(stdout,"WARNING: No negative numbers allowed in this option.\n");
-			fflush(stdout);
-			exit(1);
-		}
-		if(is_even) {
-			number[m--] = number[n] + factor + thresh;
-			number[m--] = number[n] + factor;
-		} else {
-			number[m--] = number[n];
-			number[m--] = max(number[n] - thresh, 0.0);
-		}
-		is_even = !is_even;
-	}
-	for(n=0;n<cnt2;n++)
-		do_valout(number[n]);
-	fflush(stdout);
-}
-
-/******************************** SPAN ***********************
- *
- * span single values with a pair.
- */
-
-void span(void)
-{
-	int n, m;
-	int cnt2 = cnt * 4;
-	if((number = (double *)realloc((char *)number,cnt2 * sizeof(double)))==NULL) {
-		fprintf(stdout,"WARNING: Out of memory for storing numbers.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	m = cnt2-1; 
-	for(n=cnt-1;n>=0;n--) {
-		if(number[n] < 0.0) {
-			fprintf(stdout,"WARNING: No negative numbers allowed in this option.\n");
-			fflush(stdout);
-			exit(1);
-		}
-		number[m--] = number[n] + factor + thresh;
-		number[m--] = number[n] + factor;
-		number[m--] = number[n];
-		number[m--] = max(number[n] - thresh, 0.0);
-	}
-	for(n=0;n<cnt2;n++)
-		do_valout(number[n]);
-	fflush(stdout);
-}
-
-/******************************** SPAN_XALL ***********************
- *
- * span single values.
- */
-
-void span_xall(void)
-{
-	int n, m;
-	int cnt2 = cnt * 3;
-	if((number = (double *)realloc((char *)number,cnt2 * sizeof(double)))==NULL) {
-		fprintf(stdout,"WARNING: Out of memory for storing numbers.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	m = cnt2-1; 
-	for(n=cnt-1;n>=0;n--) {
-		if(number[n] < 0.0) {
-			fprintf(stdout,"WARNING: No negative numbers allowed in this option.\n");
-			fflush(stdout);
-			exit(1);
-		}
-		number[m--] = number[n] + thresh;
-		number[m--] = number[n];
-		number[m--] = max(number[n] - thresh, 0.0);
-	}
-	for(n=0;n<cnt2;n++)
-		do_valout(number[n]);
-	fflush(stdout);
-}
-
-/******************************** ALTERNATION PATTERNS ***********************/
-
-void alt0101(void) {
-	int n;
-	for(n=0;n<cnt;n++)
-		fprintf(stdout,"INFO: %lf\n",number[n & 1]);
-	fflush(stdout);
-}
-		
-void alt0011(void) {
-	int n;
-	for(n=0;n<cnt;n++)
-		fprintf(stdout,"INFO: %lf\n",number[n & 2]);
-	fflush(stdout);
-}
-
-void alt01100(void) {
-	int n;
-	fprintf(stdout,"INFO: %lf\n",number[0]);
-	cnt--;
-	for(n=0;n<cnt;n++)
-		fprintf(stdout,"INFO: %lf\n",number[!(n & 2)]);
-	fflush(stdout);
-}
-
-void alt0r0r(void) {
-	int n;
-	double rrange = number[2] - number[1];
-	for(n=0;n<cnt;n++) {
-		if(n & 1) {
-			fprintf(stdout,"INFO: %lf\n",(drand48() * rrange) + number[1]);
-		} else {
-			fprintf(stdout,"INFO: %lf\n",number[0]);
-		}
-	}
-	fflush(stdout);
-}
-
-void altr0r0(void) {
-	int n;
-	double rrange = number[2] - number[1];
-	for(n=0;n<cnt;n++) {
-		if(n & 1) {
-			fprintf(stdout,"INFO: %lf\n",number[0]);
-		} else {
-			fprintf(stdout,"INFO: %lf\n",(drand48() * rrange) + number[1]);
-		}
-	}
-	fflush(stdout);
-}
-
-void altrr00(void) {
-	int n;
-	double rrange = number[2] - number[1];
-	for(n=0;n<cnt;n++) {
-		if(n & 2) {
-			fprintf(stdout,"INFO: %lf\n",number[0]);
-		} else {
-			fprintf(stdout,"INFO: %lf\n",(drand48() * rrange) + number[1]);
-		}
-	}
-	fflush(stdout);
-}
-
-void alt00rr(void) {
-	int n;
-	double rrange = number[2] - number[1];
-	for(n=0;n<cnt;n++) {
-		if(n & 2) {
-			fprintf(stdout,"INFO: %lf\n",(drand48() * rrange) + number[1]);
-		} else {
-			fprintf(stdout,"INFO: %lf\n",number[0]);
-		}
-	}
-	fflush(stdout);
-}
-
-void alt0rr00r(void) {
-	int n;
-	double rrange = number[2] - number[1];
-	fprintf(stdout,"INFO: %lf\n",number[0]);
-	cnt--;
-	for(n=0;n<cnt;n++) {
-		if(n & 2) {
-			fprintf(stdout,"INFO: %lf\n",number[0]);
-		} else {
-			fprintf(stdout,"INFO: %lf\n",(drand48() * rrange) + number[1]);
-		}
-	}
-	fflush(stdout);
-}
-
-void altr00rr0(void) {
-	int n;
-	double rrange = number[2] - number[1];
-	fprintf(stdout,"INFO: %lf\n",(drand48() * rrange) + number[1]);
-	cnt--;
-	for(n=0;n<cnt;n++) {
-		if(n & 2) {
-			fprintf(stdout,"INFO: %lf\n",(drand48() * rrange) + number[1]);
-		} else {
-			fprintf(stdout,"INFO: %lf\n",number[0]);
-		}
-	}
-	fflush(stdout);
-}
-
-void altRR00(void) {
-	int n;
-	double k = 0.0;
-	double rrange = number[2] - number[1];
-	for(n=0;n<cnt;n++) {
-		if(n & 2) {
-			fprintf(stdout,"INFO: %lf\n",number[0]);
-		} else {
-			if (!(n & 1)) {
-				k = (drand48() * rrange) + number[1];
-			}
-			fprintf(stdout,"INFO: %lf\n",k);
-		}
-	}
-	fflush(stdout);
-}
-
-void alt00RR(void) {
-	int n;
-	double k = 0.0;
-	double rrange = number[2] - number[1];
-	for(n=0;n<cnt;n++) {
-		if(n & 2) {
-			if (!(n & 1)) {
-				k = (drand48() * rrange) + number[1];
-			}
-			fprintf(stdout,"INFO: %lf\n",k);
-		} else {
-			fprintf(stdout,"INFO: %lf\n",number[0]);
-		}
-	}
-	fflush(stdout);
-}
-
-void alt0RR00R(void) {
-	int n;
-	double k = 0.0;
-	double rrange = number[2] - number[1];
-	fprintf(stdout,"INFO: %lf\n",number[0]);
-	cnt--;
-	for(n=0;n<cnt;n++) {
-		if(n & 2) {
-			fprintf(stdout,"INFO: %lf\n",number[0]);
-		} else {
-			if (!(n & 1)) {
-				k = (drand48() * rrange) + number[1];
-			}
-			fprintf(stdout,"INFO: %lf\n",k);
-		}
-	}
-	fflush(stdout);
-}
-
-void altR00RR0(void) {
-	int n;
-	double k = 0.0;
-	double rrange = number[2] - number[1];
-	fprintf(stdout,"INFO: %lf\n",(drand48() * rrange) + number[1]);
-	cnt--;
-	for(n=0;n<cnt;n++) {
-		if(n & 2) {
-			if (!(n & 1)) {
-				k = (drand48() * rrange) + number[1];
-			}
-			fprintf(stdout,"INFO: %lf\n",k);
-		} else {
-			fprintf(stdout,"INFO: %lf\n",number[0]);
-		}
-	}
-	fflush(stdout);
-}
-
-/******************************** CHECK FOR ASCENDING_ORDER ***********************/
-
-void ascending_order(void) {
-	int n, OK = 1;
-	for(n=1;n<cnt;n++) {
-		if(number[n] <= number[n-1]) {
-			OK = 0;
-			break;
-		}
-	}
-	if(!sloom && !sloombatch) {
-		if(OK)
-			fprintf(stdout, "sequence is in ascending order.");
-		else
-			fprintf(stdout, "sequence is NOT in ascending order at item %d (%lf)",n+1,number[n]);
-	} else {
-		if(OK)
-			fprintf(stdout, "WARNING: sequence is in ascending order.");
-		else
-			fprintf(stdout, "WARNING: sequence is NOT in ascending order at item %d (%lf)",n+1,number[n]);
-	}
-	fflush(stdout);
-}
-
-/******************************** EDIT INDIVIDUAL VALUES ***********************/
-
-void delete_vals(void) {
-	int n, m, k = (int)factor;
-	if(k < ifactor) {
-		n = ifactor;
-		ifactor = k;
-		k = n;
-	}
-	k = min(k,cnt);
-	if(k < cnt) {
-		for(n=ifactor-1,m=k;m<cnt;m++,n++)
-			number[n] = number[m];
-		cnt -= (k - ifactor + 1);
-	} else {
-		cnt = ifactor-1;
-	}
-	for(n=0;n<cnt;n++)
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-	fflush(stdout);
-}
-
-void replace_val(void) {
-	int n;
-	number[ifactor-1] = factor;
-	for(n=0;n<cnt;n++)
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-	fflush(stdout);
-}
-
-void insert_val(void) {			/* NB we have already malloced the extra space required */
-	int n;
-	ifactor--;
-	if(ifactor < cnt) {
-		for(n = cnt;n >= ifactor; n--)
-			number[n] = number[n-1];
-	}
-	number[ifactor] = factor;
-	cnt++;
-	for(n=0;n<cnt;n++)
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-	fflush(stdout);
-}
-
-/*************************** QUANTISED_SCATTER *******************************
- *
- *	number[0] = quantisation;
- *	number[1] = duration;
- *	number[2] = scatter;
- */
-
-void quantised_scatter(int *perm,int permlen)
-{
-	int n, m, here, k, q_per_step, q_scat, q_hscat, total_q, iscat;
-	double quantisation = number[0], dur = number[1], scat = number[2];
-	total_q = (int)floor(dur/quantisation) + 1;
-	q_per_step = (int)ceil(total_q/(cnt-1));
-	n = 0;
-	number[n++] = 0.0;
-	if(scat <= 1.0)  {
-		q_scat = (int)round(q_per_step * scat);
-		q_hscat = q_scat/2;
-		here = q_per_step;
-		while(n < cnt) {
-			k = (int)floor(drand48() * (double)q_scat) - q_hscat;
-			number[n++] = here + k;
-			here += q_per_step;
-		}
-	} else {
-		iscat = round(scat);
-		q_per_step *= iscat;
-		here = 0;
-		while(n < cnt) {
-			randperm(perm,permlen);				/* permute the next group of quantisation cells */
-			ascending_sort_cells(perm,iscat);	/* sort the first 'iscat' into ascending order */
-
-			for(m=0;m<iscat;m++)
-				perm[m]++;						/*	change range to range 1 to N, rather than 0 to N-1 */
-			for(m=0;m<iscat;m++) {				/* position items above base-cellcnt */
-				number[n] = here + perm[m];
-				if(++n >= cnt)
-					break;	
-			}
-			here += q_per_step;
-		}
-		free(perm);
-	}
-	for(n=0;n<cnt;n++)
-		number[n] *= quantisation;
-	print_numbers();
-}
-
-/*************************** RANDPERM *******************************
- *
- * Produce a random permutation of k integers.
- */
-
-void randperm(int *perm,int permlen)
-{
-	int n, t;
-	for(n=0;n<permlen;n++) {
-		t = (int)floor(drand48() * (n+1));
-		if(t==n) {
-			hprefix(n,perm,permlen);
-		} else {
-			hinsert(n,t,perm,permlen);
-		}
-	}
-}
-
-void hinsert(int m,int t,int *perm,int permlen)
-{
-	hshuflup(t+1,perm,permlen);
-	perm[t+1] = m;
-}
-
-void hprefix(int m,int *perm,int permlen)
-{
-	hshuflup(0,perm,permlen);
-	perm[0] = m;
-}
-
-void hshuflup(int k,int *perm,int permlen)
-{
-	int n, *i;
-	int z = permlen - 1;
-	i = perm+z;
-	for(n = z;n > k;n--) {
-		*i = *(i-1);
-		i--;
-	}
-}
-
-void ascending_sort_cells(int *perm,int ccnt)
-{
-	int n, m, sct;
-	for(n=0;n<(ccnt-1);n++) {
-		for(m=n+1;m<ccnt;m++) {
-			if(*(perm+m) < *(perm+n)) {
-				sct 	  = *(perm+m);
-				*(perm+m) = *(perm+n);
-				*(perm+n) = sct;
-			}
-		}
-	}
-}
-
-/************* REPLACING VALUES EQUAL TO > OR < A GIVEN VAL ****************/
-
-void replace_equal(void) {
-	int n;
-	double maxe = number[cnt] + FLTERR;
-	double mine = number[cnt] - FLTERR;
-	double replace = number[cnt+1];
-	for(n=0;n<cnt;n++) {
-		if((number[n] < maxe) && (number[n] > mine))
-			number[n] = replace;
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-	}
-	fflush(stdout);
-}
-		
-void replace_less(void) {
-	int n;
-	double mine = number[cnt];
-	double replace = number[cnt+1];
-	for(n=0;n<cnt;n++) {
-		if(number[n] < mine)
-			number[n] = replace;
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-	}
-	fflush(stdout);
-}
-		
-void replace_greater(void) {
-	int n;
-	double maxe = number[cnt];
-	double replace = number[cnt+1];
-	for(n=0;n<cnt;n++) {
-		if(number[n] > maxe)
-			number[n] = replace;
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-	}
-	fflush(stdout);
-}
-
-/*************************** GAPPED QUANTISED GRIDS *************************/
-
-void grid(int is_outside)
-{
-	int n, k, tot;
-	double quant = number[cnt], sum, dogrid = 0;
-	if(quant <= .001) {
-		fprintf(stdout,"ERROR: Quantisation step too small.\n");
-		fflush(stdout);
-		return;
-	} else if((tot = (int)ceil(number[cnt-1]/quant)) > 10000) {
-		fprintf(stdout,"ERROR: Quantisation too small, relative to total duration.\n");
-		fflush(stdout);
-		return;
-	} else if(tot < 2) {
-		fprintf(stdout,"ERROR: Quantisation too large, relative to total duration.\n");
-		fflush(stdout);
-		return;
-	}
-	if((permm = (double *)malloc(tot * sizeof(double))) == NULL) {
-		fprintf(stdout,"ERROR: Out of memory.\n");
-		fflush(stdout);
-		return;
-	}
-	if(is_outside)
-		dogrid = 1;	
-	n = 0;
-	k = 0;
-	sum = 0.0;
-	while(n < cnt) {
-		if(dogrid) {
-			while(sum < number[n]) {
-				permm[k++] = sum;
-				sum += quant;
-			}
-		} else {		
-			while(sum < number[n])
-				sum += quant;
-		}
-		dogrid = !dogrid;
-		n++;
-	}
- 	for(n=0;n<k;n++)
-		fprintf(stdout,"INFO: %lf\n",permm[n]);
-	fflush(stdout);
-}
-
-/****** DELETE N VALS AT RANDOM : NOT MORE THAN M ADJACENT VALS DELETED : NOT MORE THAN K ADJACENT VALS UNDELETED ******/
-
-void randdel_not_adjacent(void)
-{
-	int adj, gap, sum, i, j, k, n, z;
-	int delitems, keptitems, keepset_cnt, delset_cnt;
-	int *vacuum, *box, *boxcnt, *box_assocd_with_cntr_no, *cntr_assocd_with_box_no;
-	int remainder, unfilled_boxes, inverted = 0;
-	delitems = round(number[cnt]);	/* number of items to delete */
-	adj	= round(number[cnt+1]);		/* max no of adjacent items to delete */
-	gap	= round(number[cnt+2]);		/* max no of adjacent non-deleted items */
-
-	if(delitems >= cnt) {
-		fprintf(stdout,"ERROR: This will delete the whole column.");
-		fflush(stdout);
-		return;
-	}
-	if(delitems < 1) {
-		fprintf(stdout,"ERROR: Must delete 1 or more items.");
-		fflush(stdout);
-		return;
-	}
-
-
-	if(delitems > cnt/2) {
-		/* Invert the algorithm */
-		inverted = 1;
-		keptitems = delitems;
-		delitems = cnt - keptitems;
-		k = adj;
-		adj = gap;
-		gap = k;
-	} else {
-		keptitems = cnt - delitems;
-	}	
-	if((vacuum = (int *)malloc(delitems * sizeof(int)))==NULL) {
-		fprintf(stdout,"ERROR: Out of memory.\n");
-		fflush(stdout);
-		return;
-	}
-	delset_cnt = 0;
-	sum = 0;
-	while(sum < delitems-1) {				/* generating deletable groups of random sizes */
-		k = (int)floor(drand48()*adj) + 1;	/* within range set by 'adj' */
-		if((sum+k) > delitems-1)			/* once enough items deleted, break */			
-			break;
-		else {
-			vacuum[delset_cnt++] = k;		/* otherwise store the size of deletable group */
-			sum += k;
-		}
-	}
-	if(sum < delitems)						/* fix the size of final deletable group, to make deleted total correct */
-		vacuum[delset_cnt++] = delitems - sum;
-
-	if((vacuum = (int *)realloc((char *)vacuum,delset_cnt * sizeof(int)))==NULL) {
-		fprintf(stdout,"ERROR: Memory reallocation error.\n");
-		fflush(stdout);
-		return;
-	}
-
-	if(delset_cnt > keptitems) {			/* must be as many kept items as deleted groups, to separate those groups */
-		fprintf(stdout,"ERROR: Not enough undeleted items remaining to complete the task.\n");
-		fflush(stdout);
-		return;
-	} else if(delset_cnt == keptitems) { 	/* exactly as many keptitems as deleted groups, they must alternate */
-		j = 0;
-		n = 0;
-		i = (int)floor(drand48() * 2.0);	/* select at random whether to start with deletes or not */
-		if(inverted) {
-			if(i) {								/* and either ... */
-				while(j < delset_cnt) {
-					for(k=0;k<vacuum[j];k++) {	/* print x items */
-						fprintf(stdout,"INFO: %lf\n",number[n]);
-						if(++n > cnt) {
-							fprintf(stdout,"ERROR: Program anomaly in counting data. 6\n");
-							break;
-						}
-					}							/* then skip 1 */
-					if(++n > cnt) {
-						fprintf(stdout,"ERROR: Program anomaly in counting data. 7\n");
-						break;
-					}
-					j++;
-				}
-				fflush(stdout);			
-				return;
-			} else {							/* or .... */
-				while(j < delset_cnt) {			/* skip 1 */
-					if(++n > cnt) {
-						fprintf(stdout,"ERROR: Program anomaly in counting data. 8\n");
-						break;
-					}
-					for(k=0;k<vacuum[j];k++) {	/* then print x items */
-						fprintf(stdout,"INFO: %lf\n",number[n]);	
-						if(++n > cnt) {
-							fprintf(stdout,"ERROR: Program anomaly in counting data. 9\n");
-							break;
-						}
-					}
-					j++;
-				}
-				fflush(stdout);
-				return;
-			}
-		} else {
-			if(i) {								/* and either ... */
-				while(j < delset_cnt) {
-					for(k=0;k<vacuum[j];k++) {	/* skip x items */
-						if(++n > cnt) {
-							fprintf(stdout,"ERROR: Program anomaly in counting data. 10\n");
-							break;
-						}
-					}							/* then print 1 */
-					fprintf(stdout,"INFO: %lf\n",number[n]);
-					if(++n > cnt) {
-						fprintf(stdout,"ERROR: Program anomaly in counting data. 11\n");
-						break;
-					}
-					j++;
-				}
-				fflush(stdout);			
-				return;
-			} else {							/* or .... */
-				while(j < delset_cnt) {			/* print 1 */
-					fprintf(stdout,"INFO: %lf\n",number[n]);	
-					if(++n > cnt) {
-						fprintf(stdout,"ERROR: Program anomaly in counting data. 12\n");
-						break;
-					}
-					for(k=0;k<vacuum[j];k++) {	/* then skip x items */
-						if(++n > cnt) {
-							fprintf(stdout,"ERROR: Program anomaly in counting data. 13\n");
-							break;
-						}
-					}
-					j++;
-				}
-				fflush(stdout);
-				return;
-			}
-		}
-	}
-	keepset_cnt = delset_cnt+1;				/* otherwise, let there be 1 more sets of kept items then of deleted items */
-											/* This is an aesthetic, choice.. there could be an equal number */
-	if(( k = (int)ceil((double)keptitems/(double)keepset_cnt)) > gap) {
-		gap = k + 1;						/* if min-size of largest kept group is > gap, can't use gap value */
-		fprintf(stdout,"ERROR: Intergap distance incompatible with other demands. Adjusting to %d.\n",gap);
-		fflush(stdout);
-	}		
-	if(((box	 = (int *)malloc(keepset_cnt * sizeof(int)))==NULL)
-	|| ((boxcnt	 = (int *)malloc(keepset_cnt * sizeof(int)))==NULL)
-	|| ((box_assocd_with_cntr_no = (int *)malloc(keepset_cnt * sizeof(int)))==NULL)
-	|| ((cntr_assocd_with_box_no = (int *)malloc(keepset_cnt * sizeof(int)))==NULL)) {
-		fprintf(stdout,"ERROR: Out of memory.\n");
-		fflush(stdout);
-		return;
-	}											
-	for(n=0;n<keepset_cnt;n++) {					/* regard each set of kept items as a box */
-		box_assocd_with_cntr_no[n] = n;				/* link each ball-counter to each box */
-		cntr_assocd_with_box_no[n] = n;				/* link each box to each ball-counter */
-			box[n] = 1;								/* Put 1 ball in each box: every kept set must have at least 1 item */
-		boxcnt[n] = 0;								/* preset the boxcnts to zero */
-	}
-	if((remainder = keptitems - keepset_cnt) > 0) {	/* if any leftover balls */
-		unfilled_boxes = keepset_cnt;				/* set number of unfilled boxes */
-		for(n=0;n<remainder;n++) {					/* for all remaining balls */
-			z = (int)floor(drand48() * unfilled_boxes);		
-			box[z]++;								/* distribute each ball to a random box */
-
-			if(box[z] >= gap) {									/* if the box getting the ball is now full */
-				boxcnt[cntr_assocd_with_box_no[z]] = box[z];	/* store the count of balls in the box */
-				unfilled_boxes--;								/* reduce number of boxes to put random balls into */
-				while(z < unfilled_boxes) {					
-					box[z] = box[z+1];					/* eliminate full box, by shuffling boxes above downwards */
-					k = cntr_assocd_with_box_no[z+1];	/* get the boxcnter associated with the next box */
-					box_assocd_with_cntr_no[k]--;		/* force it to point to next lower box (as boxes have moved down 1) */
-					j = box_assocd_with_cntr_no[k];		/* get the box it now points to */
-					cntr_assocd_with_box_no[j] = k;		/* get that to point back to the box counter */ 			
-					z++;
-				}
-			}
-		}
-	}
-	for(n=0;n<keepset_cnt;n++) {						/* save counts of balls in remaining boxes */
-		if(boxcnt[n] <= 0)
-			boxcnt[n] = box[box_assocd_with_cntr_no[n]];
-	}	
-	j = 0;
-	n = 0;
-	if(inverted) {
-		while(j < delset_cnt) {
-			for(k=0;k<boxcnt[j];k++) {						/* skip x items */
-				if(++n > cnt) {
-					fprintf(stdout,"ERROR: Program anomaly in counting data 4.\n");
-					return;
-				}
-			}
-			for(k=0;k<vacuum[j];k++) {						/* print y items */
-				fprintf(stdout,"INFO: %lf\n",number[n]);
-				if(++n > cnt) {
-					fprintf(stdout,"ERROR: Program anomaly in counting data 5.\n");
-					return;
-				}
-			}	   /* Note, all inverted patterns start and end with OFF events - an aesthetic decision */
-			j++;
-		}
-	} else {
-		while(j < delset_cnt) {
-			for(k=0;k<boxcnt[j];k++) {				   		/* print x items */
-				fprintf(stdout,"INFO: %lf\n",number[n]);
-				if(++n > cnt) {
-					fprintf(stdout,"ERROR: Program anomaly in counting data 1.\n");
-					return;
-				}
-			}
-			for(k=0;k<vacuum[j];k++) {						/* skip y items */
-				if(++n > cnt) {
-					fprintf(stdout,"ERROR: Program anomaly in counting data 2.\n");
-					return;
-				}
-			}
-			j++;
-		}
-		for(k=0;k<boxcnt[j];k++) {				   			/* print last x items */
-			fprintf(stdout,"INFO: %lf\n",number[n]);
-			if(++n > cnt) {
-				fprintf(stdout,"ERROR: Program anomaly in counting data 3.\n");
-				break;										
-			}			/* Note, all patterns start and end with ON events - an aesthetic decision */
-		}	 		
-	}
-	fflush(stdout);					
-}
-
-/****************************** REPLACE_WITH_RAND ******************************/
-
-void replace_with_rand(int type) {
-
-	int n;
-	double lim = number[cnt], randlo = number[cnt+1], randhi = number[cnt+2];
-	double k, randrang, limhi, limlo;
-
-	if(randhi < randlo) {
-		k 	   = randhi;
-		randhi = randlo;
-		randlo = k;
-	}
-	randrang = randhi - randlo;
-	switch(type) {
-	case(0):			/* equal */
-		limhi = lim + FLTERR;
-		limlo = lim - FLTERR;
-		for(n=0;n<cnt;n++) {
-			if((number[n] < limhi) && (number[n] > limlo))
-				number[n] = (drand48() * randrang) + randlo;
-			fprintf(stdout,"INFO: %lf\n",number[n]);
-		}
-		break;
-	case(-1):			/* less */
-		for(n=0;n<cnt;n++) {
-			if(number[n] < lim)
-				number[n] = (drand48() * randrang) + randlo;
-			fprintf(stdout,"INFO: %lf\n",number[n]);
-		}
-		break;
-	case(1):			/* greater */
-		for(n=0;n<cnt;n++) {
-			if(number[n] > lim)
-				number[n] = (drand48() * randrang) + randlo;
-			fprintf(stdout,"INFO: %lf\n",number[n]);
-		}
-		break;
-	}
-	fflush(stdout);
-}
-
-/****************************** RANDQUANTA_IN_GAPS ******************************/
-
-void randquanta_in_gaps(void)
-{
-	int totcnt = round(number[cnt]);			  						/* number of vals to make */
-	double q = number[cnt+1];											/* quantisation of grid */
-	int mincnt = round(number[cnt+2]), maxcnt = round(number[cnt+3]);	/* min & max no of events in each time-interval */
-	int k,j,n,m, posibmax = 0, maxqpnts = 0, tot_boxes,minpos,maxpos,remainder,unfilled_boxes;
-	int boxpos, orig_boxpos;
-	int *perm,*box,*boxcnt,*qpnts,*box_assocd_with_cntr_no,*cntr_assocd_with_box_no;
-	double mintim,maxtim;
-	double *qbas;
-		
-	if(maxcnt < mincnt) {	/* orient cnt-range */
-		n = maxcnt;
-		maxcnt = mincnt;
-		mincnt = n;
-	}
-	if(mincnt < 1) {
-		fprintf(stdout,"ERROR: Invalid count of number of items (%d)\n",mincnt);
-		fflush(stdout);
-		exit(1);
-	}
-	if(cnt & 1)				/* Force even number of pairs */
-		cnt--;
-
-	if((tot_boxes = cnt/2) < 1) {
-		fprintf(stdout,"Too few value pairs in input column.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	if(totcnt < tot_boxes * mincnt) {
-		fprintf(stdout,"Insufficient items to distribute amongst the %d pairs.\n",tot_boxes);
-		fflush(stdout);
-		exit(1);
-	}
-	if(((box 	= (int *)malloc(tot_boxes * sizeof(int)))==NULL) 		/* 'boxes' store random placed 'balls' */
-	|| ((boxcnt	= (int *)malloc(tot_boxes * sizeof(int)))==NULL) 		/* counts of balls in 'boxes' */
-	|| ((qpnts 	= (int *)malloc(tot_boxes * sizeof(int)))==NULL)		/* no. of q-points in each time-interval */
-																		/* = maximum number of balls for each box */
-	|| ((qbas 	= (double *)malloc(tot_boxes * sizeof(double)))==NULL)	/* first q-point time in each time-interval */
-	|| ((box_assocd_with_cntr_no = (int *)malloc(tot_boxes * sizeof(int)))==NULL)
-	|| ((cntr_assocd_with_box_no = (int *)malloc(tot_boxes * sizeof(int)))==NULL)) {
-		fprintf(stdout,"Out of memory.\n");								/* because boxes are 'deleted' & shuffled down */
-		fflush(stdout);
-		exit(1);
-	}
-	for(n=0, m =0; n < cnt; n += 2,m++) {
-		mintim = number[n];
-		maxtim = number[n+1];
-
-		minpos = (int)floor(mintim/q);
-		if(((double)minpos * q) < mintim)
-			minpos++;
-		maxpos = (int)floor(maxtim/q);
-
-		qpnts[m] = maxpos - minpos + 1;
-		if(qpnts[m] < mincnt) {
-			fprintf(stdout,"ERROR: timegap between %lf and %lf will not take  %d items\n",number[n],number[n+1],mincnt);
-			fflush(stdout);
-			exit(1);
-		}
-		if(m == 0)	maxqpnts = qpnts[0];
-		else		maxqpnts = max(maxqpnts,qpnts[m]);
-	
-		qbas[m]  = minpos * q;
-		posibmax += min(qpnts[m],maxcnt);
-	}
-	if(posibmax < totcnt) {
-		fprintf(stdout, "ERROR: total count of items exceeds available spaces.\n");
-		fflush(stdout);
-		exit(1);
-	}
-
-	if((perm = (int *)malloc(maxqpnts * sizeof(int)))==NULL) {
-		fprintf(stdout,"Out of memory.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	remainder = totcnt;
-				
-	/* DISTRIBUTE THE REMAINING ITEMS AT RANDOM (with constraints) BETWEEN THE boxcnt BOXES */
-
-	for(n=0;n<tot_boxes;n++) {							/* regard each set of kept items as a box */
-		box_assocd_with_cntr_no[n] = n;					/* link each ball-counter to each box */
-		cntr_assocd_with_box_no[n] = n;					/* link each box to each ball-counter */
-		box[n] = mincnt;								/* Put min no of balls in each box */
-		remainder -= mincnt;
-		boxcnt[n] = 0;									/* preset the boxcnts to zero */
-	}
-	if(remainder > 0) {									/* if any leftover balls */
-
-							/* ELIMINATE ANY BOXES WHICH ARE ALREADY FULL */
-		unfilled_boxes = tot_boxes;						/* set number of unfilled boxes as total no of boxes */
-		boxpos = 0;
-		for(n=0,m=0;n<tot_boxes;n++) {   				/* for all boxes */
-			if(box[boxpos] >= qpnts[n]) {				/* if the box is already full */
-				boxcnt[n] = box[boxpos];				/* store the count of balls that are in the box */
-				unfilled_boxes--;						/* reduce number of boxes to put random balls into */
-				orig_boxpos = boxpos;					/* save the position of the full-box which is being eliminated */
-				while(boxpos < unfilled_boxes) {				
-					box[boxpos] = box[boxpos+1];		/* eliminate full box, by shuffling boxes above downwards */
-					k = cntr_assocd_with_box_no[boxpos+1];	/* get the boxcnter associated with the next box */
-					box_assocd_with_cntr_no[k]--;		/* force it to point to next lower box (as boxes have moved down 1) */
-					j = box_assocd_with_cntr_no[k];		/* get the box it now points to */
-					cntr_assocd_with_box_no[j] = k;		/* get that to point back to the box counter */ 			
-					boxpos++;
-				}
-				boxpos = orig_boxpos;					/* reset box position to where it was: now points to new box */
-			} else { 									
-				boxpos++;								/* if box getting ball is NOT full, go on to next box */
-			}
-		}
-									/* DISTRIBUTE REMAINING BALLS */
-		for(n=0;n<remainder;n++) {   					/* for all remaining balls */
-			boxpos = (int)floor(drand48() * unfilled_boxes);		
-			box[boxpos]++;								/* distribute each ball to a random box */
-			k = cntr_assocd_with_box_no[boxpos];
-			if(box[boxpos] >= qpnts[k]) {				/* if the box getting the ball is now full */
-				boxcnt[k] = box[boxpos];				/* store the count of balls that are in the box */
-				unfilled_boxes--;						/* reduce number of boxes to put random balls into */
-				while(boxpos < unfilled_boxes) {					
-					box[boxpos] = box[boxpos+1];		/* eliminate full box, by shuffling boxes above downwards */
-					k = cntr_assocd_with_box_no[boxpos+1];	/* get the boxcnter associated with the next box */
-					box_assocd_with_cntr_no[k]--;		/* force it to point to next lower box (as boxes have moved down 1) */
-					j = box_assocd_with_cntr_no[k];		/* get the box it now points to */
-					cntr_assocd_with_box_no[j] = k;		/* get that to point back to the box counter */ 			
-					boxpos++;
-				}
-			}
-		}
-	}
-	for(n=0;n<tot_boxes;n++) {							/* save counts of balls in remaining boxes */
-		if(boxcnt[n] <= 0)
-			boxcnt[n] = box[box_assocd_with_cntr_no[n]];
-	}	
-	/* DISTRIBUTE THE VALS AT RANDOM WITHIN THE BOXES */
-
-	for(n=0;n<tot_boxes;n++) {
-		randperm(perm,qpnts[n]);						/* permute the current group of quantisation cells */
-		ascending_sort_cells(perm,boxcnt[n]);			/* sort the first 'boxcnt' of the perm, into ascending order */
-
-		for(m=0;m<boxcnt[n];m++)						/* for each random value, multiply it by quantisation val */
-			fprintf(stdout,"INFO: %lf\n",qbas[n] + (perm[m] * q));
-	}													/* & add to to 1st quantised position in current time-interval */
-	fflush(stdout);
-}
-
-/****************************** INVERT_NORMD_ENV ******************************/
-
-void invert_normd_env(void)
-{	
-	invertenv(1.0);
-}
-
-/****************************** INVERT_AROUND_PIVOT ******************************/
-
-void invert_around_pivot(void)
-{	
-	invertenv(number[cnt] * 2.0);
-}
-
-/****************************** INVERT_OVER_RANGE ******************************/
-
-void invert_over_range(void)
-{	
-	invertenv(number[cnt] + number[cnt+1]);
-}
-
-/****************************** ENV_SUPERIMPOS ******************************/
-
-void env_superimpos(int inverse,int typ)	/* PRODUCT SHOULD INVOLVE LOGS !! */
-{
-	double *out, *no1, *no2, tdiff, tratio, vdiff, vhere;
-	int n, m, j, cnt2, skipped;
-	double thisnval, thismval, lastnval, lastmval, time = 0.0, lastval = 0.0;
-
-	if((out = (double *)malloc((cnt * 2) * sizeof(double)))==NULL) {
-		fprintf(stdout,"ERROR: Out of memory.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	if(factor != 0.0) {		  			/* if inserted after time zero, move it to start time */
-		for(n=firstcnt;n<cnt;n+=2)
-			number[n] += factor;
-	}
-	if(inverse) {					/* If working with inverse of env, invert it */
-		for(n=firstcnt+1;n<cnt;n+=2)
-			number[n] = 1.0 - number[n];
-	}
-	if(number[firstcnt] < number[0]) {
-		no1  = &(number[firstcnt]);	/* If inserted env starts BEFORE orig env, 'invert' process */
-		no2  = number;
-		cnt  = cnt - firstcnt;			/* establish independent counters for each infile */
-		cnt2 = firstcnt;
-	} else {
-		no1  = number;
-		no2  = &(number[firstcnt]);
-		cnt2 = cnt - firstcnt;			/* establish independent counters for each infile */
-		cnt  = firstcnt;
-	}
-	n = 0;
-	m = 0;
-	j = 0;
-	thisnval = 0.0;
-	thismval = 0.0;
-	while(no1[n] < no2[0]) {
-		out[j++] = no1[n++];
-		thisnval = no1[n];
-		thismval = no2[1];
-		switch(typ) {
-		case(MULT):		out[j++] = no1[n++] * no2[1];	break;
-		case(ADD):		out[j++] = no1[n++] + no2[1];	break;
-		case(SUBTRACT):	out[j++] = no1[n++] - no2[1];	break;
-		case(ENVMAX):	
-			out[j++] = max(no1[n],no2[1]); 
-			n++;
-			break;
-		}
-		if(n >= cnt)
-			break;
-	}
-	while(n < cnt) {				
-		if(no1[n] == no2[m]) {		/* brkpnts coincide */
-			out[j++] = no1[n++];
-			m++;					/* new brkpnt val is product of origs */
-			lastnval = thisnval;
-			lastmval = thismval;
-			thisnval = no1[n];
-			thismval = no2[m];
-			switch(typ) {
-			case(MULT):		out[j++] = no1[n++] * no2[m++];	break;
-			case(ADD):		out[j++] = no1[n++] + no2[m++];	break;
-			case(SUBTRACT):	out[j++] = no1[n++] - no2[m++];	break;
-			case(ENVMAX):	
-				out[j++] = max(no1[n],no2[m]);
-				n++;
-				m++;
-				break;
-			}
-			if(m >= cnt2)			/* If at end of inserted env, break from loop */
-				break;
-		} else if(no1[n] > no2[m]) { 	/* inserted brkpnt falls before next orig-brkpnt */
-			while(no1[n] > no2[m]) {
-				time = no2[m];		/* take time from inserted brkpnt */
-				tdiff = no1[n] - no1[n-2];
-				tratio = (no2[m++] - no1[n-2])/tdiff;
-				n++;
-				vdiff = no1[n] - no1[n-2];
-				vhere = (vdiff * tratio) + no1[n-2];	/* value of orig brkpnt, at this time */
-				lastnval = thisnval;
-				lastmval = thismval;
-				thisnval = vhere;
-				thismval = no2[m];
-				docross(lastnval,lastmval,thisnval,thismval,time,&j,out,typ);
-				out[j++] = time;	
-				switch(typ) {
-				case(MULT):		out[j++] = vhere * no2[m++];	break;
-				case(ADD):		out[j++] = vhere + no2[m++];	break;
-				case(SUBTRACT):	out[j++] = vhere - no2[m++];	break;
-				case(ENVMAX):	
-					out[j++] = max(vhere,no2[m]);	
-					m++;
-					break;
-				}
-				n--;				/* remain at same point in orig-brkfile */
-				if(m >= cnt2)
-					break;			/* If at end of inserted env, break from loop */
-			}
-		} else {					/* orig-brkpnt falls before next inserted brkpnt */
-			while(no2[m] > no1[n]) {
-				time = no1[n];		/* take time from orig brkpnt */
-				tdiff = no2[m] - no2[m-2];
-				tratio = (no1[n++] - no2[m-2])/tdiff;
-				m++;
-				vdiff = no2[m] - no2[m-2];
-				vhere = (vdiff * tratio) + no2[m-2];	/* value of inserted brkpnt, at this time */
-				lastnval = thisnval;
-				lastmval = thismval;
-				thismval = vhere;
-				thisnval = no1[n];
-				docross(lastnval,lastmval,thisnval,thismval,time,&j,out,typ);
-				out[j++] = time;	
-				switch(typ) {
-				case(MULT):		out[j++] = vhere * no1[n++];	break;
-				case(ADD):		out[j++] = vhere + no1[n++];	break;
-				case(SUBTRACT):	out[j++] = vhere - no1[n++];	break;
-				case(ENVMAX):	
-					out[j++] = max(vhere,no1[n]);	
-					n++;
-					break;
-				}
-				m--;				/* remain at same point in inserted-brkfile */
-				if(n >= cnt) {		/* if it at end of orig file */
-					while(m < cnt2) {	  /* calc remaining inserted file points */
-						out[j++] = no2[m++];
-						switch(typ) {
-						case(MULT):		out[j++] = no2[m++] * no1[cnt-1];	break;
-						case(ADD):		out[j++] = no2[m++] + no1[cnt-1];	break;
-						case(SUBTRACT):	out[j++] = no2[m++] - no1[cnt-1];	break;
-						case(ENVMAX):	
-							out[j++] = max(no2[m],no1[cnt-1]);
-							m++;
-							break;
-						}
-					}
-					break;			/* and break from loop */
-				}
-			}
-		}
-		if(m >= cnt2)
-			break;					/* If at end of inserted env, break from outer loop */
-	}
-			/* on leaving loop either m > cnt2 or n > cnt */
-
-	while (n < cnt) {				/* if orig brkfile extends beyond inserted file */
-		out[j++] = no1[n++];		/* calculate remaining points */
-		switch(typ) {
-		case(MULT):		out[j++] = no1[n++] * no2[cnt2 - 1];	break;
-		case(ADD):		out[j++] = no1[n++] + no2[cnt2 - 1];	break;
-		case(SUBTRACT):	out[j++] = no1[n++] - no2[cnt2 - 1];	break;
-		case(ENVMAX):	
-			out[j++] = max(no1[n],no2[cnt2 - 1]);	
-			n++;
-			break;
-		}
-	}
-	while (m < cnt2) {				/* if inserted brkfile extends beyond orig file */
-		out[j++] = no2[m++];		/* calculate remaining points */
-		switch(typ) {
-		case(MULT):		out[j++] = no2[m++] * no1[cnt - 1];	break;
-		case(ADD):		out[j++] = no2[m++] + no1[cnt - 1];	break;
-		case(SUBTRACT):	out[j++] = no2[m++] - no1[cnt - 1];	break;
-		case(ENVMAX):	
-			out[j++] = max(no2[m],no1[cnt - 1]);	
-			m++;
-			break;
-		}
-	}
-	fprintf(stdout,"INFO: %lf  %lf\n",out[0],out[1]);
-	skipped = 0;
-	for(n=2;n<j-2;n += 2) {
-		if(!flteq(out[n-1],out[n+1])) {		/* elementary datareduce */
-			if(skipped)
-				fprintf(stdout,"INFO: %lf  %lf\n",time,lastval);
-			fprintf(stdout,"INFO: %lf  %lf\n",out[n],out[n+1]);
-			skipped = 0;
-		} else {
-			skipped = 1;
-			time 	= out[n];
-			lastval = out[n+1];
-		}
-	}
-	fprintf(stdout,"INFO: %lf  %lf\n",out[n],out[n+1]);
-	fflush(stdout);
-}
-
-/****************************** DOCROSS ******************************/
-
-void docross(double lastnval,double lastmval,double thisnval, double thismval,double time,int *j,double *out,int typ)
-{
-	int prehi = 0, posthi = 0;
-	double lasttime, timediff, timecross, valcross, gradn, gradm;
-	if(lastnval > lastmval)
-		prehi = 1;
-	else if(lastnval < lastmval)
-		prehi = -1;
-	if(thisnval > thismval)
-			posthi = 1;
-	else if(thisnval < thismval)
-		posthi = -1;
-	if(prehi && posthi && (prehi != posthi)) {	/* curves intersect */
-		lasttime = out[*(j)-2];
-		timediff = time - lasttime;
-		if(flteq(timediff,0.0)) {
-			fprintf(stdout,"ERROR: Came across time step too small to calculate.\n");
-			fflush(stdout);
-			exit(1);
-		}
-		gradn = (thisnval - lastnval)/timediff;
-		gradm = (thismval - lastmval)/timediff;
-		if(flteq(gradn,gradm)) {
-			fprintf(stdout,"ERROR: possible error in curve crossing algorithm.\n");
-			fflush(stdout);
-			exit(1);
-		}
-		timecross = (lastmval - lastnval)/(gradn - gradm);
-		valcross = (gradn * timecross) + lastnval;
-		out[(*j)++] = timecross + lasttime;
-		switch(typ) {
-		case(MULT):		out[(*j)++] = (valcross * valcross);	break;
-		case(ADD):		out[(*j)++] = (valcross + valcross);	break;
-		case(SUBTRACT):	out[(*j)++] = 0.0;						break;
-		case(ENVMAX):	out[(*j)++] = valcross;					break;
-		}
-	}
-}
-
-/****************************** ENV_DEL_INV ******************************/
-
-void env_del_inv(void)
-{
-	int n, m;
-	cnt += 2;
-	if((number = (double *)realloc((char *)number,cnt * sizeof(double)))==NULL) {
-		fprintf(stdout,"ERROR: Out of memory.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	m = cnt - 1;
-	n = cnt - 3;
-	while(n > 0) {
-		number[m--] = 1.0 - number[n--];		/* inverse */
-		number[m--]	= number[n--] + factor; 	/* delay */
-	}
-	number[1] = number[3];						/* extend initial val.. */
-	number[0] = 0.0; 							/* ...back to zero time */
-	for(n=0;n<cnt;n+=2)
-		fprintf(stdout,"INFO: %lf  %lf\n",number[n],number[n+1]);
-	fflush(stdout);
-}
-
-/****************************** ENV_DEL_INV ******************************/
-
-void env_plateau(void)
-{
-	double plateau;
-	int n;
-	n = ifactor;
-	n--; 					/* get true line number */
-	n *= 2;					/* get brkpnt pair */
-	n++;					/* get val in brkpnt pair */
-	plateau = number[n];	/* get plateau val */
-	n -= 2;
-	number[n] = plateau;	/* put plateau val in previous val*/
-	n--;					
-	number[n] = 0.0;		/* set time here to zero */
-	while(n < cnt) {
-		fprintf(stdout,"INFO: %lf  %lf\n",number[n],number[n+1]);
-		n += 2;
-	}
-	fflush(stdout);
-}
-
-/****************************** TIME_FROM_BEAT_POSITION ******************************/
-
-void time_from_beat_position(int has_offset)
-{
-	int n;
-	double k;
-	if(factor <= FLTERR) {
-		fprintf(stdout,"ERROR: Beat duration is less than or equal to zero.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	if(has_offset && !condit) {
-		fprintf(stdout,"ERROR: No time offset given.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	for(n=0;n< cnt;n++) {
-		if((k = number[n] - 1.0) < 0.0) {
-			fprintf(stdout,"ERROR: Position of beat %d is less than 1. Impossible.\n",n+1);
-			fflush(stdout);
-			exit(1);
-		}
-		number[n] = k * factor;
-		if(has_offset)
-			number[n] += thresh;
-	}
-	for(n=0;n< cnt;n++)
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-	fflush(stdout);
-}
-
-/****************************** INSERT_AFTER_VAL ******************************/
-
-void insert_after_val(void)
-{
-	int n, m, has_started = 0;
-	for(n=0;n<cnt;n++) {
-		if (!has_started) {
-			if(number[n] == number[cnt]) {
-				for(m=0;m <= n; m++)
-					fprintf(stdout,"INFO: %lf\n",number[m]);
-				fprintf(stdout,"INFO: %lf\n",number[cnt+1]);
-				has_started = 1;
-			}
-		} else {
-			fprintf(stdout,"INFO: %lf\n",number[n]);
-		}
-	}
-	if(!has_started) {
-		fprintf(stdout,"ERROR: Value %lf not found in the table.\n",number[cnt]);
-		fflush(stdout);
-		exit(1);
-	}
-	fflush(stdout);
-}
-
-/****************************** MIN_INTERVAL ******************************/
-
-void min_interval(int ismax) {
-	int n, pos;
-	double min_int, max_int, this_int;
-	if(cnt < 2) {
-		fprintf(stdout,"ERROR: Too few values to run this process.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	pos = 1;
-	if (ismax) {
-		max_int = number[1] - number[0];
-		for(n=2;n<cnt;n++) {
-			if((this_int = number[n] - number[n-1]) > max_int) {
-				max_int = this_int;
-				pos = n;
-			}
-		}
-		fprintf(stdout,"WARNING: Maximum interval is %lf between entries %d and %d.\n",max_int,pos,pos+1);
-		fflush(stdout);
-	} else {
-		min_int = number[1] - number[0];
-		for(n=2;n<cnt;n++) {
-			if((this_int = number[n] - number[n-1]) < min_int) {
-				min_int = this_int;
-				pos = n;
-			}
-		}
-		fprintf(stdout,"WARNING: Minimum interval is %lf between entries %d and %d.\n",min_int,pos,pos+1);
-		fflush(stdout);
-	}
-}
-
-/****************************** INSERT_IN_ORDER ******************************/
-
-void insert_in_order(void) {
-	int n, pos = -1;
-	for(n=0;n<cnt-1;n++) {
-		if(number[n+1] <= number[n]) {
-			fprintf(stdout,"ERROR: column not in ascending order.\n");
-			fflush(stdout);
-			exit(1);
-		}
-		if ((pos < 0) && (number[cnt] <= number[n])) {	/* position not found & new number goes here */
-			pos = n;
-		}
-	}
-	if ((pos < 0) && (number[cnt] <= number[n])) {	/* position not found & new number goes here */
-		pos = n;
-	}
-	if(pos < 0) 			/* new number larger than all in column, goes at end */
-		pos = cnt;			
-	if(pos > 0) {			/* if new number not at start of column */
-		for(n=0;n<pos;n++)
-			fprintf(stdout,"INFO: %lf\n",number[n]);
-	}					   	/* insert new number */
-	fprintf(stdout,"INFO: %lf\n",number[cnt]);
-	if(pos < cnt) {			/* if new mumber not at end of column */
-		for(n=pos;n<cnt;n++)
-			fprintf(stdout,"INFO: %lf\n",number[n]);
-	}
-	fflush(stdout);
-}
-
-/****************************** INSERT_AT_START ******************************/
-
-void insert_at_start(void) {
-	int n;
-	fprintf(stdout,"INFO: %lf\n",number[cnt]);
-	for(n=0;n<cnt;n++)
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-	fflush(stdout);
-}
-
-/****************************** INSERT_AT_END ******************************/
-
-void insert_at_end(void) {
-	int n;
-	for(n=0;n<=cnt;n++)
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-	fflush(stdout);
-}
-
-/****************************** FORMAT_STRS ****************************/
-
-void format_strs(void)
-{
-	int n, m, OK = 1;
-	double d = (double)stringscnt/(double)ifactor;
-	int rowcnt = stringscnt/ifactor;
-	char temp[64];
-	errstr[0] = ENDOFSTR;
-	if(d > (double)rowcnt)
-		rowcnt++;
-	for(n=0;n<stringscnt;n+=rowcnt) {
-		for(m=0;m<rowcnt;m++) {
-			if(n!=0 && m==0) {
-				fprintf(stdout,"INFO: %s\n",errstr);
-				errstr[0] = ENDOFSTR;
-			}
-			if(n+m < stringscnt) {
-				sprintf(temp,"%s ",strings[n+m]);
-				strcat(errstr,temp);
-			} else
-				OK = 0;
-		}
-		if(!OK)
-			break;
-	}
-	fprintf(stdout,"INFO: %s\n",errstr);
-	fflush(stdout);
-}
-
-
-/****************************** COLUMN_FORMAT_STRS ****************************/
-
-void column_format_strs(void)
-{	int n, m;
-
-	double d = (double)stringscnt/(double)ifactor;
-	int rowcnt = stringscnt/ifactor;
-	char temp[64];
-	errstr[0] = ENDOFSTR;
-	if(d > (double)rowcnt)
-		rowcnt++;
-	for(n=0;n<rowcnt;n++) {
-		for(m=n;m<stringscnt;m+=rowcnt) {
-			sprintf(temp,"%s ",strings[m]);
-			strcat(errstr,temp);
-		}
-		fprintf(stdout,"INFO: %s\n",errstr);
-		errstr[0] = ENDOFSTR;
-	}
-	fflush(stdout);
-}
-
-/****************************** RANDOM_INTEGERS ****************************/
-
-void random_integers(void)
-{
-	int n, i, j = round(number[1]);
-	int range = abs(j - 1) + 1;
-	int rangbot = (int)min(j,1);
-	ifactor = round(number[0]);
-
-	for(n=0;n<ifactor;n++) {
-		i = (int)floor(drand48() * range) + rangbot;
-		fprintf(stdout,"INFO: %d\n",i);
-	}
-	fflush(stdout);
-}
-
-/****************************** RANDOM_INTEGERS_EVENLY_SPREAD ****************************/
-
-void random_integers_evenly_spread(void)
-{
-	int z, n, m, i, k, j, repets;
-	int range, rangbot, arrsiz, endcnt, endval, allowed, checkpart;
-	int *arr, *arr2, *perm;
-
-	repets = round(number[2]);
-	j = round(number[1]);
-	range = abs(j - 1) + 1;
-	rangbot = (int)min(j,1);
-	arrsiz = range * repets;
-	ifactor = round(number[0]);
-
-	if((arr = (int *)malloc(arrsiz * sizeof(int)))==NULL) {
-		fprintf(stdout,"ERROR: Out of memory.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	if((perm = (int *)malloc(arrsiz * sizeof(int)))==NULL) {
-		fprintf(stdout,"ERROR: Out of memory.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	if((arr2 = (int *)malloc(repets * sizeof(int)))==NULL) {
-		fprintf(stdout,"ERROR: Out of memory.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	n = 0;
-	for(j=0;j<repets;j++) {					/* fill array with REPET copies of values */
-		z = rangbot;
-		for(i=0;i<range;i++)
-			arr[n++] = z++;
-	}
-	endcnt = 0;							  	/* number of items repeated at end of previous perm */
-	endval = 1;								/* value (possibly repeated) at end of previous perm */
-	allowed = -1;							/* number of permissible repetitions of this val at start of NEW perm */
-	checkpart = arrsiz - repets;			/* items at end of array to test for repetitions */
-	n = 0;
-	while(n < ifactor) {
-		do_repet_restricted_perm(arr,perm,arrsiz,allowed,endval);
-		j = 0;
-		for(m = 0;m <arrsiz;m++,n++) {
-			if(n >= ifactor)
-				break;
-			k = arr[perm[m]];
-			fprintf(stdout,"INFO: %d\n",k);
-			if(m >= checkpart)				/* save last checkable stretch of perm */
-				arr2[j++] = k;
-		}
-		fflush(stdout);
-		if(n >= ifactor)
-			break;
-		j--;
-		endval = arr2[j--];					/* note the val at end of perm */
-		endcnt = 1;							/* and count it */
-		for(k = j; k>= 0; k--) {			
-			if(arr2[k] == endval)			/* check adjacent vals, for repetition of value: count */
-				endcnt++;
-			else							/* if no more repetitions, finish counting */
-				break;
-		}
-		allowed = repets - endcnt;			/* get number of permissible repets at start of next perm */
-	}
-}
-
-/****************************** DO_REPET_RESTRICTED_PERM ****************************/
-
-void do_repet_restricted_perm(int *arr, int *perm, int arrsiz, int allowed, int endval)
-{
-	int n, t;
-	int checklen = allowed + 1;
-	int done = 0;
-	while(!done) {
-		for(n=0;n<arrsiz;n++) {
-			t = (int)(drand48() * (double)(n+1)); /* TRUNCATE */
-			if(t==n)
-				hhprefix(n,arrsiz,perm);
-			else
-				hhinsert(n,t,arrsiz,perm);
-		}
-		if(checklen <= 0)
-			break;
-		for(n=0;n<checklen;n++) {
-			if(arr[perm[n]] == endval) {	/* if this is val (repeated) at end of last perm */
-				if(allowed == 0) 			/* if repetition not allowed, force a new perm val */
-					break;
-				else						/* else, repetitions still allowed */
-					allowed--;				/* decrement number of permissible further repets */ 
-			} else {						
-				done = 1;					/* if this is not val at end of last perm */
-				break;						/* perm is OK */
-			}			
-		}
-	}
-}
-
-/***************************** HHINSERT **********************************
- *
- * Insert the value m AFTER the T-th element in perm[].
- */
-
-void hhinsert(int m,int t,int setlen,int *perm)
-{
-	hhshuflup(t+1,setlen,perm);
-	perm[t+1] = m;
-}
-
-/***************************** HHPREFIX ************************************
- *
- * Insert the value m at start of the permutation perm[].
- */
-
-void hhprefix(int m,int setlen,int *perm)
-{			  
-	hhshuflup(0,setlen,perm);
-	perm[0] = m;
-}
-
-/****************************** HHSHUFLUP ***********************************
- *
- * move set members in perm[] upwards, starting from element k.
- */
-
-void hhshuflup(int k,int setlen,int *perm)
-{
-	int n, *i;
-	int z = setlen - 1;
-	i = (perm+z);
-	for(n = z;n > k;n--) {
-		*i = *(i-1);
-		i--;
-	}
-}
-
-/****************************** TIME_FROM_BAR_BEAT_METRE_TEMPO ***********************************/
-
-void time_from_bar_beat_metre_tempo(int has_offset)
-{
-	int barlen, beatsize, n;
-	double tempo,beat,beatdur,time, offset = 0.0;
-
-	if((tempo = get_tempo(strings[cnt+1])) <= 0.0)
-		exit(1);
-	if(has_offset)
-		get_offset(strings[cnt+2],&offset);
-	get_metre(strings[cnt],&barlen,&beatsize);
-	beatdur = (60.0/(double)tempo) * (4.0/(double)beatsize);
-	for(n=0;n<cnt;n++) {
-		beat = get_beat(n,barlen);
-		time = beat * beatdur;
-		time += offset;
-		fprintf(stdout,"INFO: %lf\n",time);
-	}
-	fflush(stdout);
-}
-
-/****************************** GET_METRE ***********************************/
-
-void get_metre(char str[],int *barlen,int *beatsize)
-{
-	int pointcnt = 0, isvalid = 0, mask;
-	char *q, *start, *p = str;
-	start = p;
-	q = start;
-	p += strlen(p);
-	/* strip trailing zeros */
-	if(p == start) {
-		fprintf(stdout, "ERROR: Invalid metre value. (No data).\n");
-		fflush(stdout);
-		exit(1);
-	}
-	p--;
-	while(*p == '0') {
-		*p = ENDOFSTR;		
-		if(p == start)
-			break;
-		p--;
-	}
-	p = start;
-	while(*p != ENDOFSTR) {
-		if(*p == '.') {
-			pointcnt++;
-			q = p;
-		} else if (!isdigit(*p)) {
-			fprintf(stdout, "ERROR: Invalid metre value. non_digit = '%c' in numerator.\n",*p);
-			fflush(stdout);
-			exit(1);
-		}
-		p++;
-	}
-	if(q == start) {
-		fprintf(stdout, "ERROR: Invalid metre value. No numerator.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	if (pointcnt!=1) {
-		if(pointcnt > 1)
-			fprintf(stdout, "ERROR: Invalid metre value. %d decimal points : must be one only.\n",pointcnt);
-		else
-			fprintf(stdout, "ERROR: Invalid metre value. No decimal point\n");
-		fflush(stdout);
-		exit(1);
-	}
-	*q = ENDOFSTR;
-	if(sscanf(start,"%d",barlen)<1) {							/* SAFETY (redundant) */
-		fprintf(stdout, "ERROR: Invalid metre value. Cannot read barlength.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	p = q+1;
-	if(*p==ENDOFSTR) {
-		fprintf(stdout, "ERROR: Invalid metre value. (No denominator).\n");
-		fflush(stdout);
-		exit(1);
-	}
-	start = p;
-	if(*p == '0') {
-		fprintf(stdout, "ERROR: Invalid metre value. (leading zeros in denominator).\n");		/* leading zero(s) */
-		fflush(stdout);
-		exit(1);
-	}
-	while(*p != ENDOFSTR) {
-		if(!isdigit(*p)) {									 	/* non-numeric characters */
-			fprintf(stdout, "ERROR: Invalid metre value. (non-digit character '%c' in denominator )\n",*p);
-			fflush(stdout);
-			exit(1);
-		}
-		p++;
-	}
-	if(sscanf(start,"%d",beatsize)<1) {							/* SAFETY (redundant) */
-		fprintf(stdout, "ERROR: Invalid metre value. Failed to read beatsize from %s\n",start);
-		fflush(stdout);
-		exit(1);
-	}
-	mask = 1;
-	while(mask < 512) {		/* Powers of 2 only !! Need special dispensation for Ferneyhovian metres like 4:10 */
-		if((*beatsize) == mask) {
-			isvalid = 1;
-			break;
-		}
-		mask <<= 1;
-	}	
-	if(!isvalid) {
-		fprintf(stdout, "ERROR: Invalid metre value. beatsize (%d) is invalid in standard usage\n",*beatsize);
-		fflush(stdout);
-		exit(1);
-	}
-}
-
-/****************************** GET_BEAT ***********************************/
-
-double get_beat(int n,int barlen)
-{
-	int pointcnt = 0;
-	char *q = NULL, *p, *start;
-	int bar;
-	double beat;
-	if(strlen(strings[n]) == 0) {
-		fprintf(stdout, "ERROR: Invalid bar:beat value at item %d. (No value found)\n",n+1);
-		fflush(stdout);
-		exit(1);
-	}
-	p = strings[n];
-		/* must have COLON */
-	while(*p != ENDOFSTR) {
-		if(*p == ':') {
-			pointcnt++;
-			q = p;
-		} else if (!isdigit(*p) && (*p != '.')) {
-			pointcnt = -1;
-			break;
-		}
-		p++;
-	}
-	if(pointcnt != 1) {
-		switch(pointcnt) {
-		case(-1):
-			fprintf(stdout, "ERROR: Invalid character (%c) in bar:beat value '%s' in item %d\n",*p,strings[n],n+1);
-			break;
-		case(0):
-			fprintf(stdout, "ERROR: Invalid bar:beat value '%s' at item %d. (No colon found)\n",strings[n],n+1);
-			break;
-		default:
-			fprintf(stdout, "ERROR: Invalid bar:beat value '%s' at item %d : %d colons found (should be only 1)\n",
-			strings[n],n+1,pointcnt);
-			break;
-		}
-		fflush(stdout);
-		exit(1);
-	}
-	*q = ENDOFSTR;
-	if(sscanf(strings[n],"%d",&bar)<1) {	/* SAFETY (redundant) */
-		fprintf(stdout, "ERROR: Invalid bar:beat value at item %d. Failed to read bar count.\n",n+1);
-		fflush(stdout);
-		exit(1);
-	}
-	if(bar < 1) {
-		fprintf(stdout, "ERROR: Invalid bar:beat value at item %d. Bar count less than 1.\n",n+1);
-		fflush(stdout);
-		exit(1);
-	}
-	bar--;
-	start = q+1;
-	if(*start==ENDOFSTR) {
-		fprintf(stdout, "ERROR: Invalid bar:beat value at item %d. No beatcount.\n",n+1);
-		fflush(stdout);
-		exit(1);
-	}
-	if(sscanf(start,"%lf",&beat)<1) {												/* SAFETY (redundant) */
-		fprintf(stdout, "ERROR: Invalid bar:beat value at item %d. Failed to read beatcount.\n",n+1);
-		fflush(stdout);
-		exit(1);
-	}
-	if(beat < 1.0) {
-		fprintf(stdout, "ERROR: Invalid bar:beat value at item %d. Beat count less than 1.\n",n+1);
-		fflush(stdout);
-		exit(1);
-	} else if(beat >= (double)(barlen + 1)) {
-		fprintf(stdout, "ERROR: Invalid bar:beat value at item %d. Beat count beyond bar end.\n",n+1);
-		fflush(stdout);
-		exit(1);
-	} 
-	beat -= 1.0;
-	beat += (bar * (double)barlen);
-	return beat;
-}
-
-/****************************** SCALE_FROM ***********************************/
-
-void scale_from(void) {
-
-	double interval, pivot = number[cnt];
-	double scaler = number[cnt+1];
-	int n;
-	for(n = 0;n<cnt;n++) {
-		interval = number[n] - pivot;
-		interval *= scaler;
-		fprintf(stdout,"INFO: %lf\n",pivot + interval);
-	}
-	fflush(stdout);
-}
-
-/****************************** SCALE_ABOVE ***********************************/
-
-void scale_above(void) {
-
-	double interval, pivot = number[cnt];
-	double scaler = number[cnt+1];
-	int n;
-	for(n = 0;n<cnt;n++) {
-		interval = number[n] - pivot;
-		if(interval > 0.0) {
-			interval *= scaler;
-			fprintf(stdout,"INFO: %lf\n",pivot + interval);
-		} else
-			fprintf(stdout,"INFO: %lf\n",number[n]);
-	}			
-	fflush(stdout);
-}
-
-/****************************** SCALE_BELOW ***********************************/
-
-void scale_below(void) {
-
-	double interval, pivot = number[cnt];
-	double scaler = number[cnt+1];
-	int n;
-	for(n = 0;n<cnt;n++) {
-		interval = number[n] - pivot;
-		if(interval < 0.0) {
-			interval *= scaler;
-			fprintf(stdout,"INFO: %lf\n",pivot + interval);
-		} else
-			fprintf(stdout,"INFO: %lf\n",number[n]);
-	}			
-	fflush(stdout);
-}
-
-/************************** SPAN_RISE ********************************/
-
-void span_rise(void) {
-
-	int n;
-
-	if(number[0] < 0.0) {
-		fprintf(stdout,"ERROR: This option only works with ascending values greater than or equal to zero.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	for(n = 1;n<cnt;n++) {
-		if(number[n] - number[n-1] <= thresh)  {
-			fprintf(stdout,"ERROR: No space for span between number %d (%lf) and number %d (%lf)\n",
-			n,number[n-1],n+1,number[n]);
-			fflush(stdout);
-			exit(1);
-		}
-	}
-	if(number[0] < thresh) {
-		fprintf(stdout,"WARNING: First value too close to zero: NO span inserted.\n");
-		fflush(stdout);
-	} else {
-		fprintf(stdout,"INFO: %lf\n",number[0] - thresh);
-	}
-	fprintf(stdout,"INFO: %lf\n",number[0]);
-
-	for(n = 1;n<cnt;n++) {
-		fprintf(stdout,"INFO: %lf\n",number[n] - thresh);
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-	}
-	fflush(stdout);
-}
-
-/************************** SPAN_FALL ********************************/
-
-void span_fall(void) {
-
-	int n;
-
-	if(number[0] < 0.0) {
-		fprintf(stdout,"ERROR: This option only works with ascending values greater than or equal to zero.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	for(n = 1;n<cnt;n++) {
-		if(number[n] - number[n-1] <= thresh)  {
-			fprintf(stdout,"ERROR: No space for span between number %d (%lf) and number %d (%lf)\n",
-			n,number[n-1],n+1,number[n]);
-			fflush(stdout);
-			exit(1);
-		}
-	}
-	for(n = 0;n<cnt;n++) {
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-		fprintf(stdout,"INFO: %lf\n",number[n] + thresh);
-	}
-	fflush(stdout);
-}
-
-/************************** CYCLIC_SELECT ********************************/
-
-void cyclic_select(char c) {
-
-	int n, m, start, step, k = (int)c, startpos = 0, steppos=0;
-	double item = 0.0;
-	
-	switch(k) {
-	case('s'):
-		steppos  = cnt;
-		startpos = cnt+1;
-		break;
-	case('a'):
-	case('m'):
-		steppos  = cnt+1;
-		startpos = cnt+2;
-		break;
-	}
-	if((start = (int)round(number[startpos])) > cnt) {
-		fprintf(stdout,"ERROR: There are no numbers at or beyond position %d\n",start);
-		fflush(stdout);
-		exit(1);
-	} else if(start < 1) {
-		fprintf(stdout,"ERROR: There are no numbers at or before position %d\n",start);
-		fflush(stdout);
-		exit(1);
-	}
-	start--;
-	if(abs(step = (int)round(number[steppos])) < 1) {
-		fprintf(stdout,"ERROR: Step between values cannot be zero.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	if(c != 's') {
-		if(step < 0) {
-			fprintf(stdout,"ERROR: Step between values cannot be negative.\n");
-			fflush(stdout);
-			exit(1);
-		}
-		item = number[cnt];
-	}
-	switch(k) {
-	case('s'):
-		if(step > 0) {
-			for(n = start;n<cnt;n+=step)
-				fprintf(stdout,"INFO: %lf\n",number[n]);
-		} else {
-			for(n = start;n>=0;n+=step)
-				fprintf(stdout,"INFO: %lf\n",number[n]);
-		}
-		break;
-	case('a'):
-	case('m'):
-		n = 0;
-		while(n < start)
-			fprintf(stdout,"INFO: %lf\n",number[n++]);
-		for(m = 0;n<cnt;m++,n++) {
-			m %= step;
-			if(m == 0) {
-				switch(k) {
-				case('a'):	fprintf(stdout,"INFO: %lf\n",number[n] + item); break;
-				case('m'):	fprintf(stdout,"INFO: %lf\n",number[n] * item); break;
-				}
-			} else {
-				fprintf(stdout,"INFO: %lf\n",number[n]);
-			}
-		}
-		break;
-	}
-	fflush(stdout);
-}
-
-/************************** SPAN_ALL ********************************/
-
-void span_all(void) {
-
-	int n, zero_exists = 0, top_exists = 0;
-
-	if(number[0] < 0.0) {
-		fprintf(stdout,"ERROR: Numbers begin before zero.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	if(number[cnt-1] > factor) {
-		fprintf(stdout,"ERROR: Numbers already run beyond %lf\n",factor);
-		fflush(stdout);
-		exit(1);
-	}
-	if(number[0] <= 0.0)
-		zero_exists = 1;
-	if(number[cnt-1] >= factor)
-		top_exists = 1;
-	if(zero_exists) {
-		if(top_exists) {
-			fprintf(stdout,"ERROR: Numbers already begin at zero and end at %lf\n",factor);
-			fflush(stdout);
-			exit(1);
-		} else {
-			fprintf(stdout,"WARNING: Numbers already start at zero\n");
-			fflush(stdout);
-		}
-	}
-	if(top_exists) {
-		fprintf(stdout,"WARNING: Numbers already end at %lf\n",factor);
-		fflush(stdout);
-	}
-	if(!zero_exists)
-		fprintf(stdout,"INFO: %lf\n",0.0);
-	for(n=0;n<cnt;n++)
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-	if(!top_exists)
-		fprintf(stdout,"INFO: %lf\n",factor);
-	fflush(stdout);
-}
-
-/************************** GET_TEMPO ********************************/
-
-double get_tempo(char *str)
-{
-	char *p = str;
-	double tempo;
-	int pointcnt = 0;
-	while(*p != ENDOFSTR) {
-		if(*p == '.') {
-			pointcnt++;
-		} else if(!isdigit(*p)) {
-			pointcnt = -1;
-			break;
-		}
-		p++;
-	}
-	if(pointcnt < 0 || pointcnt > 1) {
-		fprintf(stdout, "ERROR: Invalid tempo value.\n");
-		fflush(stdout);
-		return(-1.0);
-	}
-	if(sscanf(str,"%lf",&tempo)!=1) {
-		fprintf(stdout, "ERROR: Invalid tempo value.\n");
-		fflush(stdout);
-		return(-1.0);
-	}
-	if(tempo <= 0.0) {
-		fprintf(stdout, "ERROR: Zero or negative tempo: impossible.\n");
-		fflush(stdout);
-		return(-1.0);
-	} else if(tempo > MAX_TEMPO) {
-		fprintf(stdout, "ERROR: Invalid tempo value. Beats shorter than 1 millisecond (!!).\n");
-		fflush(stdout);
-		return(-1.0);
-	} else if(tempo < MIN_TEMPO) {
-		fprintf(stdout, "ERROR: Invalid tempo value. Beats longer than 1 hour (!!).\n");
-		fflush(stdout);
-		return(-1.0);
-	}
-	return tempo;
-}
-
-/************************** GENERATE_RANDOMISED_VALS ********************************/
-
-void generate_randomised_vals(void)
-{
-	double scatter = number[2], span = number[0], sum = 0.0, mean, range, *temp = NULL, d;
-	int cnt = (int)round(number[1]), n, m, j, subcnt;
-	int bigscat = 0;
-	if(scatter > 1.0)
-		bigscat = (int)round(scatter);
-	if(bigscat) {
-		if((temp = (double *)malloc(bigscat * sizeof(double)))==NULL) {
-			fprintf(stdout,"Out of memory.\n");
-			fflush(stdout);
-			exit(1);
-		}
-	}
-	if((number = (double *)realloc((char *)number,(cnt+1) * sizeof(double)))==NULL) {
-		fprintf(stdout,"Out of memory.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	mean = span/(double)cnt;
-	number[0] = 0.0;
-	number[cnt] = span;
-
-	if(bigscat) {
-		for(n=1;n < cnt;n+= bigscat) {
-			if((subcnt = n + bigscat) > cnt)			/* find position of last number in this pass */
-				subcnt = cnt;	  						/* set end position of pass */
-			subcnt--;									/* allow for item already written at 1 */
-			if((subcnt %= bigscat) == 0)				/* set size of pass */
-				subcnt = bigscat;
-			range = mean * subcnt;						/* set range of pass */
-			for(m = 0; m < subcnt; m++)
-				temp[m] = sum + (drand48() * range);	/* generate values within this range */
-			for(m=0;m < subcnt - 1; m++) {				
-				for(j=1;j < subcnt; j++) {
-					if(temp[m] > temp[j]) {				/* sort */
-						d = temp[j];
-						temp[j] = temp[m];
-						temp[m] = d;
-					}
-				}
-			}
-			for(m=0;m<subcnt;m++)						/* concatenate to list of numbers */
-				number[n+m] = temp[m];
-			sum += range;								/* step over range */
-		}
-	} else {
-		for(n=1;n < cnt;n++) {
-			sum += mean;
-			number[n] = sum + (mean * randoffset(scatter));
-		}
-	}
-	for(n=0;n<=cnt;n++)
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-	fflush(stdout);
-}
-
-/************************** RAND_OFFSET ********************************
- *
- * rand number in maximal range -half to +half
- */
-
-double randoffset(double scatter)
-{
-	return (((drand48() * 2.0) - 1.0) * 0.5) * scatter;
-}
-
-/************************** GET_OFFSET ********************************/
-
-void get_offset(char *str,double *offset)
-{
-	if(sscanf(str,"%lf",offset)!=1) {
-		fprintf(stdout,"Cannot read time offset.\n");
-		fflush(stdout);
-		exit(1);
-	}
-}
-
-/************************** PITCH_TO_DELAY ********************************/
-
-void pitch_to_delay(int midi)
-{
-	int n;
-	for(n = 0;n < cnt; n++) {
-		if(midi) {
-			if(number[n] < MIDIMIN || number[n] > MIDIMAX) {
-				fprintf(stdout,"MIDI value %d (%lf) is out of range.\n", n+1,number[n]);
-				fflush(stdout);
-				exit(1);
-			}
-			number[n] = miditohz(number[n]);
-		} else if(number[n] < FLTERR || number[n] > 24000.0) {
-			fprintf(stdout,"Frequency value %d (%lf) is out or range.\n",n+1,number[n]);
-			fflush(stdout);
-			exit(1);
-		}
-		number[n] = 1000.0/number[n];
-	}
-	for(n=0;n<cnt;n++)
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-	fflush(stdout);
-}
-
-/************************** DELAY_TO_PITCH ********************************/
-
-void delay_to_pitch(int midi)
-{
-	int n;
-	for(n = 0;n < cnt; n++) {
-		number[n] /= 1000; 
-		if(number[n] < FLTERR) {
-			fprintf(stdout,"Delay value %d (%lf) is out or range for conversion to pitch value.\n",n+1,number[n]);
-			fflush(stdout);
-			exit(1);
-		}
-		number[n] = 1.0/number[n];
-		if(midi) {
-			if(number[n] < MIDIMINFRQ || number[n] > MIDIMAXFRQ) {
-				fprintf(stdout,"delay value %d (%lf) is out of range for conversion to MIDI.\n", n+1,number[n]);
-				fflush(stdout);
-				exit(1);
-			}
-			number[n] = hztomidi(number[n]);
-		} else if(number[n] < FLTERR || number[n] > 24000) {
-			fprintf(stdout,"Delay value %d (%lf) is out or range for conversion to frq.\n",n+1,number[n]);
-			fflush(stdout);
-			exit(1);
-		}
-	}
-	for(n=0;n<cnt;n++)
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-	fflush(stdout);
-}
-
-
-/* NEW FUNCS HANDLING BRKTABLES DIRECTLY ***** JUNE 2000 ***/
-
-
-/****************************** REVERSE_TIME_INTERVALS ******************************/
-
-void reverse_time_intervals(void)
-{
-	int n, m;
-	double k = number[0];
-	fprintf(stdout,"INFO: %lf  %lf\n",k,number[1]);
-	for(n=3,m = cnt-2;n<cnt;m-=2,n+=2) {
-		k += (number[m] - number[m-2]);
-		fprintf(stdout,"INFO: %lf  %lf\n",k,number[n]);
-	}
-	fflush(stdout);
-}
-
-/****************************** REVERSE_ORDER_OF_BRKVALS ******************************/
-
-void reverse_order_of_brkvals(void)
-{
-	int n, m;
-	for(n=0,m = cnt-1;n<cnt;m-=2,n+=2)
-		fprintf(stdout,"INFO: %lf  %lf\n",number[n],number[m]);
-	fflush(stdout);
-}
-
-/****************************** INVERTENV ******************************/
-
-void invertenv(double piv)
-{	
-	int n;
-	for(n=1;n<cnt;n+=2)
-		fprintf(stdout,"INFO: %lf  %lf\n",number[n-1],piv - number[n]);
-	fflush(stdout);
-}
-
-/******************************** THRESH_CUT ****************************/
-
-void thresh_cut(void)
-{
-	int n,m, k = 0;
-	double ratio, *time;
-	int isgreater = 0;
-	if((cnt <= 0) || ((time = (double *)malloc(cnt * sizeof(double)))==NULL)) {
-		fprintf(stdout,"ERROR: Insufficient memory.\n");
-		return;
-	}
-	if(number[1] > factor)
-		isgreater = 1;
-	for(m=2,n=3;n<cnt;n+=2,m+=2) {
-		switch(isgreater) {
-		case(0):			
-			if(number[n] > factor) {
-				ratio = (factor - number[n-2])/(number[n] - number[n-2]);
-				time[k++] = ((number[m] - number[m-2]) * ratio) + number[m-2];
-				isgreater = 1;
-			}
-			break;
-		case(1):			
-			if(number[n] <= factor) {
-				ratio = (factor - number[n-2])/(number[n] - number[n-2]);
-				time[k++] = ((number[m] - number[m-2]) * ratio) + number[m-2];
-				isgreater = 0;
-			}
-			break;
-		}
-	}
-	if(k == 0) {
-		fprintf(stdout,"ERROR: The values do not cross the threshold.\n");
-		free(time);
-		return;
-	}
-	for(n=0;n<k;n++)
-		do_valout(time[n]);
-	free(time);
-}
-
-/******************************** BAND_CUT ****************************/
-
-void band_cut(void)
-{
-	int n,m, k = 0;
-	double ratio, *time, z, hibnd, lobnd;
-	int bandpos;
-	if((cnt <= 0) || ((time = (double *)malloc(cnt * sizeof(double)))==NULL)) {
-		fprintf(stdout,"ERROR: Insufficient memory.\n");
-		return;
-	}
-	lobnd = number[cnt];
-	hibnd = number[cnt+1];
-
-	if(lobnd > hibnd) {
-		z = lobnd;
-		lobnd = hibnd;
-		hibnd = z;
-	}
-	if(number[1] >= lobnd && number[1] <= hibnd)
-		bandpos = 0;
-	else if(number[1] < lobnd)
-		bandpos = -1;
-	else
-		bandpos = 1;
-	for(m=2,n=3;n<cnt;n+=2,m+=2) {
-		switch(bandpos) {
-		case(0):			
-			if(number[n] < lobnd) {		   /* crosses out downwards */
-				ratio = (lobnd - number[n-2])/(number[n] - number[n-2]);
-				time[k++] = ((number[m] - number[m-2]) * ratio) + number[m-2];
-				bandpos = -1;				   
-			} else if(number[n] > hibnd) {	   /* crosses out upwards */
-				ratio = (hibnd - number[n-2])/(number[n] - number[n-2]);
-				time[k++] = ((number[m] - number[m-2]) * ratio) + number[m-2];
-				bandpos = 1;
-			}
-			break;
-		case(1):			
-			if(number[n] <= hibnd) {	   		/* crosses in from above */
-				ratio = (hibnd - number[n-2])/(number[n] - number[n-2]);
-				time[k++] = ((number[m] - number[m-2]) * ratio) + number[m-2];
-				bandpos = 0;
-			}
-			if(number[n] < lobnd) {			/* then possibly out below */
-				ratio = (lobnd - number[n-2])/(number[n] - number[n-2]);
-				time[k++] = ((number[m] - number[m-2]) * ratio) + number[m-2];
-				bandpos = -1;
-			}
-			break;
-		case(-1):			
-			if(number[n] >= lobnd) {		   /* crosses in from below */
-				ratio = (lobnd - number[n-2])/(number[n] - number[n-2]);
-				time[k++] = ((number[m] - number[m-2]) * ratio) + number[m-2];
-				bandpos = 0;
-			}
-			if(number[n] > hibnd) {			/* then possibly out above */
-				ratio = (hibnd - number[n-2])/(number[n] - number[n-2]);
-				time[k++] = ((number[m] - number[m-2]) * ratio) + number[m-2];
-				bandpos = 1;
-			}
-			break;
-		}
-	}
-	if(k == 0) {
-		fprintf(stdout,"ERROR: The values in the 2nd column do not cross into or out of the specified band.\n");
-		free(time);
-		return;
-	}
-	for(n=0;n<k;n++)
-		do_valout(time[n]);
-	fflush(stdout);
-	free(time);
-}
-
-
-
-/****************************** ENV_APPEND ******************************/
-
-void env_append(void)
-{
-	int n, dojoin = 0;
-	double first_endtime;
-
-	first_endtime = number[firstcnt-2];
-	if (factor < first_endtime) { 
-		fprintf(stdout,"ERROR: Second envelope starts before first one ends.\n");
-		fflush(stdout);
-		exit(1);
-	} else if(flteq(factor,first_endtime)) {
-		if(!flteq(number[firstcnt-1],number[firstcnt+1])) {
-			fprintf(stdout,"ERROR: Abutting envelopes are not at same level (%lf and %lf).\n",number[firstcnt-1],number[firstcnt+1]);
-			fflush(stdout);
-			exit(1);
-		}
-		dojoin = 1;
-	}
-	for(n = firstcnt; n < cnt; n+=2) {
-		number[n] += factor;
-	}
-	if(dojoin) {
-		for(n=0;n<firstcnt;n+=2)
-			do_valpair_out(number[n],number[n+1]);
-		for(n=firstcnt+2;n<cnt;n+=2)
-			do_valpair_out(number[n],number[n+1]);
-	} else {
-		for(n=0;n<cnt;n+=2)
-			do_valpair_out(number[n],number[n+1]);
-	}
-	fflush(stdout);
-}
-
-/****************************** ABUTT ******************************/
-
-void abutt(void)
-{
-	int n,m = 0, i;
-	double displace;
-	int indx = 0;
-	for(i=0;i<infilecnt-1;i++) { 			/* check abutting values match */
-		indx += file_cnt[i];
-		if(!flteq(number[indx-1],number[indx+1])) {
-			fprintf(stdout,"ERROR: Abutting values between files %d and %d do not match\n",i+1,i+2);
-			fflush(stdout);
-			exit(1);
-		}
-	}
-	for(n=0;n < file_cnt[0]; n+=2) { 		/* print all of file 1 */
-		fprintf(stdout, "INFO: %lf  %lf\n",number[m],number[m+1]);
-		m += 2;
-	}
-	displace = number[m-2];		 			/* displace by last time in 1st file */
-	for(i = 1; i <infilecnt; i++) {			/* for all other files */
-		m += 2;								/* skip first (abutting) value */
-		for(n=2;n < file_cnt[i]; n+=2) { 	/* for all other values in file - displace time values */
-			fprintf(stdout, "INFO: %lf  %lf\n",number[m] + displace,number[m+1]);
-			m += 2;
-		}
-		displace += number[m-2];			/* increase displacement by last time in this file */
-	}
-	fflush(stdout);
-}
-
-/****************************** QUANTISE_TIME ******************************/
-
-void quantise_time(void)
-{
-	int n;
-	for(n=0;n<cnt;n+=2)
-		fprintf(stdout,"INFO: %lf  %lf\n",round(number[n]/factor) * factor,number[n+1]);
-	fflush(stdout);
-}
-
-/****************************** QUANTISE_VAL ******************************/
-
-void quantise_val(void)
-{
-	int n;
-	for(n=0;n<cnt;n+=2)
-		fprintf(stdout,"INFO: %lf  %lf\n",number[n],round(number[n+1]/factor) * factor);
-	fflush(stdout);
-}
-
-/****************************** EXPAND_TABLE_DUR_BY_FACTOR ******************************/
-
-void expand_table_dur_by_factor(void)
-{
-	int n;
-	for(n=0;n<cnt;n+=2)
-		fprintf(stdout,"INFO: %lf  %lf\n",number[n] * factor,number[n+1]);
-	fflush(stdout);
-}
-
-/****************************** EXPAND_TABLE_VALS_BY_FACTOR ******************************/
-
-void expand_table_vals_by_factor(void)
-{
-	int n;
-	for(n=0;n<cnt;n+=2)
-		fprintf(stdout,"INFO: %lf  %lf\n",number[n],number[n+1] * factor);
-	fflush(stdout);
-}
-
-/****************************** EXPAND_TABLE_TO_DUR ******************************/
-
-void expand_table_to_dur(void)
-{
-	int n;
-	double ratio;
-
-	if(number[cnt-2] <= 0.0) {
-		fprintf(stdout,"ERROR: Final time in table is zero: cannot proceed.\n");
-		return;
-	}
-	ratio = factor/number[cnt-2];
-
-	for(n=0;n<cnt;n+=2)
-		fprintf(stdout,"INFO: %lf  %lf\n",number[n] * ratio,number[n+1]);
-	fflush(stdout);
-}
-
-/****************************** CUT_TABLE_AT_TIME ******************************/
-
-void cut_table_at_time(void)
-{
-	int n;
-	double timediff,valdiff,timeratio,outval;
-
-	for(n=0;n<cnt;n+=2) {
-		if(flteq(number[n],factor)) {
-			fprintf(stdout,"INFO: %lf  %lf\n",number[n],number[n+1]);
-			break;
-		} else if(number[n] < factor) {
-			fprintf(stdout,"INFO: %lf  %lf\n",number[n],number[n+1]);
-		} else if(n==0) {
-			fprintf(stdout,"WARNING: No values occur before the cut-off time\n");
-			break;
-		} else {
-			timediff  = number[n] - number[n-2];
-			valdiff   = number[n+1] - number[n-1];
-			timeratio = (factor - number[n-2])/timediff;
-			valdiff  *= timeratio;
-			outval	= number[n-1] + valdiff;
-			fprintf(stdout,"INFO: %lf  %lf\n",factor,outval);
-			break;
-		}
-	}
-	fflush(stdout);
-}
-
-/****************************** EXTEND_TABLE_TO_DUR ******************************/
-
-void extend_table_to_dur(void)
-{
-	int n;
- 	for(n=0;n<cnt;n+=2)
-		fprintf(stdout,"INFO: %lf  %lf\n",number[n],number[n+1]);
-	fprintf(stdout,"INFO: %lf  %lf\n",factor,number[n-1]);
-	fflush(stdout);
-}
-
-/****************************** LIMIT_TABLE_VAL_RANGE ******************************/
-
-void limit_table_val_range(void)
-{
-	int n;
- 	if(condit) {
-		for(n=1;n<cnt;n+=2) {
-			number[n] = max((number[n] = min(factor,number[n])),thresh);
-			fprintf(stdout,"INFO: %lf  %lf\n",number[n-1],number[n]);
-		}
-	} else {
-		for(n=1;n<cnt;n+=2) {
-			number[n] = min(factor,number[n]);
-			fprintf(stdout,"INFO: %lf  %lf\n",number[n-1],number[n]);
-		}
-	}
-	fflush(stdout);
-}
-
-/****************************** SUBSTITUTE ******************************/
-
-void substitute(void)
-{
-	int n;
- 	for(n=0;n<cnt;n++) {
-		if(flteq(number[n],thresh))
-			number[n] = factor;
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-	}
-	fflush(stdout);
-}
-
-/****************************** SUBSTITUTE_ALL ******************************/
-
-void substitute_all(void)
-{
-	int n;
- 	for(n=0;n<stringscnt;n++)
-		fprintf(stdout,"INFO: %s\n",string);
-	fflush(stdout);
-}
-
-/****************************** SUBSTITUTE ******************************/
-
-void mean_of_reversed_pairs(void)
-{
-	int n;
-	double z1;
- 	for(n=1;n<cnt;n++) {
-		if(number[n]<number[n-1]) {
-			z1 = (number[n] + number[n-1])/2.0;
-			number[n-1]	= z1 - FLTERR;
-			if((n-2 > 0) && number[n-2] >= number[n-1]) {
-				fprintf(stdout,"WARNING: numbers %d (%lf) and %d (%lf) failed to be separated.\n",
-				n,number[n-1],n+1,number[n]);
-				fflush(stdout);
-				return;
-			}
-			number[n]   = z1 + FLTERR;
-			if((n+1 < cnt) && number[n+1] <= number[n]) {
-				fprintf(stdout,"WARNING: numbers %d (%lf) and %d (%lf) failed to be separated.\n",
-				n+1,number[n],n+2,number[n+1]);
-				fflush(stdout);
-				return;
-			}
-		}
-	}
- 	for(n=0;n<cnt;n++)
-		fprintf(stdout,"INFO: %lf\n",number[n]);
-	fflush(stdout);
-}
-
-/****************************** CONVERT_SPACE_TEX_TO_PAN ******************************/
-
-void convert_space_tex_to_pan(void)
-{
-	int n;
-	for(n=1;n<cnt;n+=2) {
-		number[n] *=2.0;
-		number[n] -=1.0;
-	}
- 	for(n=0;n<cnt;n+=2)
-		fprintf(stdout,"INFO: %lf  %lf\n",number[n],number[n+1]);
-	fflush(stdout);
-}
-
-/****************************** CONVERT_SPACE_PAN_TO_TEX ******************************/
-
-void convert_space_pan_to_tex(void)
-{
-	int n;
-	for(n=1;n<cnt;n+=2) {
-		number[n] *=0.5;
-		number[n] +=0.5;
-	}
- 	for(n=0;n<cnt;n+=2)
-		fprintf(stdout,"INFO: %lf  %lf\n",number[n],number[n+1]);
-	fflush(stdout);
-}
-
-/****************************** CONVERT_TO_EDITS ******************************/
-
-void convert_to_edits(void)
-{
-	int n;
-	double start, end;
-	for(n=0;n<cnt-1;n++) {
-		start = max(0.0,number[n] - factor);
-		end = max(0.0,number[n+1] + factor);
-		fprintf(stdout,"INFO: %lf  %lf\n",start,end);
-	}
-	fflush(stdout);
-}
-
-/****************************** COSIN_SPLINE ******************************/
-
-void cosin_spline(void)
-{
-	int n, cnt_less_one;
-	double val, valchange, skew, startval ,endval;
-	skew = number[3];
-	startval = number[1];
-	endval   = number[2];
-	valchange = endval - startval;
-	cnt_less_one = cnt - 1;
-	if(flteq(skew,1.0)) {
-		for(n=0;n<cnt;n++) {
-			val  = ((double)n/(double)cnt_less_one) * PI;
-			val  = cos(val);
-			val += 1.0;
-			val /= 2.0;
-			val  = 1.0 - val;
-			val  = max(0.0,val);
-			val  = min(val,1.0);
-			val *= valchange;
-			val += startval;
-			fprintf(stdout,"INFO: %lf\n",val);
-		}
-	} else {
-		for(n=0;n<cnt;n++) {
-			val  = ((double)n/(double)cnt_less_one);	/* val in 0 -1 range */
-			val  = pow(val,skew);						/* val skewed, still in 0-1 range */
-			val  = val * PI;							/* (skewed) val in range 0 to PI */
-			val  = cos(val);							/* cosin val running from 1 to -1 */
-			val += 1.0;									/* cosin val running from 2 to 0  */	
-			val /= 2.0;									/* cosin val running from 1 to 0  */	
-			val  = 1.0 - val;							/* cosin val running from 0 to 1  */	
-			val  = max(0.0,val);						/* ensure 0-1 range not exceeeded */
-			val  = min(val,1.0);						
-			val *= valchange;							/* apply cosin shape to val change */
-			val += startval;							/* add cosin change to initial val */
-			fprintf(stdout,"INFO: %lf\n",val);
-		}
-	}
-	fflush(stdout);
-}
-
-/****************************** DISTANCE_FROM_GRID ******************************/
-
-void distance_from_grid()
-{
-	int n, m, besterror;
-	double *diff = (double *)exmalloc((cnt-1)*sizeof(double));
-	double *error = (double *)exmalloc(21 * sizeof(double));
-	double maxdiff = 0.0, mindiff = 0.0, lastmindiff, diffrange, diffstep, thisdiff, thisgrid, minerror;
-	double lowlimit = FLTERR/10000;
-
-	for(n=0;n<cnt-1;n++) {
-		diff[n] = number[n+1] - number[n];
-
-/*
-		if(diff[n]  <= 0.0) {
-			fprintf(stdout, "ERROR: Process only works with increasing sequences of numbers.\n");
-			fflush(stdout);
-			exit(1);
-		}
-*/
-		if(n==0) {
-			mindiff = diff[0];
-			maxdiff = diff[0];
-		} else {
-			mindiff = min(diff[n],mindiff);
-			maxdiff = max(diff[n],maxdiff);
-		}
-	}
-
-	lastmindiff = mindiff;
-	while((diffrange = maxdiff - mindiff) > lowlimit * 20.0) {
-		diffstep = diffrange/20.0;
-		thisdiff = mindiff;
-		for(m=0;m<=20;m++) {
-			error[m] = 0;
-			thisgrid = number[0];
-			for(n=1;n<cnt;n++) {
-				thisgrid += thisdiff;
-				error[m] += fabs(number[n] - thisgrid);
-			}
-			thisdiff += diffstep;
-		}
-		minerror = error[0];
-		besterror = 0;
-		for(m=1;m<=20;m++) {
-			if(minerror > error[m]) {
-				minerror = error[m];
-				besterror = m;
-			}
-		}
-		mindiff = mindiff + (besterror * diffstep);
-		lastmindiff = mindiff;
-		maxdiff = mindiff + diffstep;
-		mindiff -= diffstep;
-	}
-	thisgrid = number[0];
-	for(n=0;n<cnt;n++) {
-		thisdiff = number[n] - thisgrid;
-		if(thisdiff < 0.0 && thisdiff > -FLTERR)
-			thisdiff = 0.0;
-		fprintf(stdout,"INFO: %lf\n",thisdiff);
-		thisgrid += lastmindiff;
-	}
-	fflush(stdout);
-}
-
-/****************************** SINUSOID ******************************/
-
-void sinusoid(void) {
-	double maxval  = number[0], minval  = number[1];
-	double range   = maxval - minval;
-	double phase   = (fmod(number[2],360.0)/360.0) * TWOPI;
-	double periods = number[3];
-	double valdens = number[4];
-	int n, valcnt = (int)floor((periods * valdens) + 1.0);
-	double val, phasestep = TWOPI/valdens;
-
-	for(n = 0; n < valcnt; n++) {
-		val = (sin(phase) + 1.0)/2.0;
-		val *= range;
-		val += minval;
-		fprintf(stdout,"INFO: %lf\n",val);
-		phase = phase + phasestep; /* should be fmod by TWOPI, but seems to work without this */
-	}
-	fflush(stdout);
-}
-
-/****************************** RAND_INTS_WITH_FIXED_ENDS ****************************/
-
-void rand_ints_with_fixed_ends(void)
-{
-	int z, n, m, i, k, j, j1, j2, repets, fullperms, partperm, startval, finval;
-	int range, rangbot, arrsiz, endcnt, endval, allowed, checkpart, done = 0;
-	int *arr, *arr2, *perm;
-
-	repets = round(number[5]);
-	startval = round(number[3]);
-	finval   = round(number[4]);
-	j1 = round(number[1]);
-	j2 = round(number[2]);
-	range = abs(j2 - j1) + 1;
-	rangbot = (int)min(j1,j2);
-	arrsiz = range * repets;
-	ifactor = round(number[0]) - 2;
-	fullperms = ifactor / arrsiz;
-	partperm = ifactor - (fullperms * arrsiz);
-	if(partperm == 0) {
-		fullperms--;		/* The last set of vals has to be calculated separately */
-		partperm = arrsiz;	/* as, unlike others, it will have to be compared with the finval */
-	}
-
-	if((arr = (int *)malloc(arrsiz * sizeof(int)))==NULL) {
-		fprintf(stdout,"ERROR: Out of memory.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	if((perm = (int *)malloc(arrsiz * sizeof(int)))==NULL) {
-		fprintf(stdout,"ERROR: Out of memory.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	if((arr2 = (int *)malloc(repets * sizeof(int)))==NULL) {
-		fprintf(stdout,"ERROR: Out of memory.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	n = 0;
-	for(j=0;j<repets;j++) {					/* fill array with REPET copies of values. */
-		z = rangbot;						/* this set can be permd AS A WHOLE, as repet adjacent copies of any val */
-		for(i=0;i<range;i++)				/* which might arise in perming this set, are allowed */
-			arr[n++] = z++;
-	}
-	endcnt = 0;							  	/* number of items repeated at end of previous perm */
-	endval = startval;						/* value (possibly repeated) at end of previous perm */
-											/* initially this is just the 'startval' fixed by the user */
-	allowed = repets - 1;					/* number of permissible repetitions of this val at start of NEW perm */
-	checkpart = arrsiz - repets;			/* items at end of array to test for repetitions */
-	n = 0;
-	fprintf(stdout,"INFO: %d\n",startval);	/* Output user-specified first value */
-	while(n < fullperms) {
-		do_repet_restricted_perm(arr,perm,arrsiz,allowed,endval);
-		j = 0;
-		for(m = 0;m <arrsiz;m++) {
-			k = arr[perm[m]];
-			fprintf(stdout,"INFO: %d\n",k);
-			if(m >= checkpart)				/* save last checkable stretch of perm */
-				arr2[j++] = k;
-		}
-		fflush(stdout);
-		j--;
-		endval = arr2[j--];					/* note the val at end of perm */
-		endcnt = 1;							/* and count it */
-		for(k = j; k>= 0; k--) {			
-			if(arr2[k] == endval)			/* check adjacent vals, for repetition of value: count */
-				endcnt++;
-			else							/* if no more repetitions, finish counting */
-				break;
-		}
-		allowed = repets - endcnt;			/* get number of permissible repets at start of next perm */
-		n++;
-	}
-	k = partperm - 1;	/* index of last item of next perm which will actually be outputted */
-	j = repets - 1;		/* How many items at end of partperm, other than item k, which need to be checked for value-repetition */
-	while(!done) {
-		do_repet_restricted_perm(arr,perm,arrsiz,allowed,endval);
-		for(n=k;n>=k - j;n--) {
-			if(arr[perm[n]] == finval) {	/* Check end vals of the-set-of-values-in-the-final-perm-which-will-actually-be-outputted */
-				if(allowed == 0) 			/* against 'finval', to avoid too many value-repetitions at end of output */
-					break;
-				else
-					allowed--;
-			} else {						
-				done = 1;
-				break;
-			}			
-		}
-	}
-	for(m = 0;m <partperm;m++) {
-		k = arr[perm[m]];
-		fprintf(stdout,"INFO: %d\n",k);
-	}
-	fprintf(stdout,"INFO: %d\n",finval);
-	fflush(stdout);
-}
-
-/****************************** RAND_ZIGS ****************************/
-
-void rand_zigs(void)
-{
-	int n, k, j, j1, j2, finval, range, rangbot, arrsiz, outvals, lastval, t, done;
-	int *arr, *perm;
-
-	outvals = round(number[0]);
-	j1 = round(number[1]);
-	j2 = round(number[2]);
-	finval = round(number[3]);
-	range = abs(j2 - j1) + 1;
-	rangbot = (int)min(j1,j2);
-	if(finval < rangbot || finval > (int)max(j1,j2)) {
-		fprintf(stdout,"ERROR: Final value specified does not lie within the range of values specified.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	arrsiz = range;
-	if((arr = (int *)malloc(arrsiz * sizeof(int)))==NULL) {
-		fprintf(stdout,"ERROR: Out of memory.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	if((perm = (int *)malloc(arrsiz * sizeof(int)))==NULL) {
-		fprintf(stdout,"ERROR: Out of memory.\n");
-		fflush(stdout);
-		exit(1);
-	}
-	k = rangbot;						/* this set can be permd AS A WHOLE, as repet adjacent copies of any val */
-	for(n=0;n<range;n++)				/* which might arise in perming this set, are allowed */
-		arr[n] = k++;
-	j = 0;
-	lastval = rangbot - 1;
-	done = 0;
-	while(j < outvals) {
-		for(n=0;n<arrsiz;n++) {
-			t = (int)(drand48() * (double)(n+1)); /* Do Perm */
-			if(t==n)
-				hhprefix(n,arrsiz,perm);
-			else
-				hhinsert(n,t,arrsiz,perm);
-		}
-		for(n=0;n<arrsiz;n++) {
-			if (lastval < arr[perm[n]])  {
-				k = lastval + 1;
-				while(k < arr[perm[n]]) {
-					fprintf(stdout,"INFO: %d\n",k);
-					if(++j >= outvals) {
-						lastval = k;
-						done = 1;
-						break;
-					}
-					k++;
-				}
-			} else if(lastval > arr[perm[n]]) {
-				k = lastval - 1;
-				while(k > arr[perm[n]]) {
-					fprintf(stdout,"INFO: %d\n",k);
-					if(++j >= outvals) {
-						lastval = k;
-						done = 1;
-						break;
-					}
-					k--;
-				}
-			} else {		/* next perm val can only be equal to previous at join of two different perms */
-				break;		/* in this case, get a different perm */
-			}
-			if(done) {
-				break;
-			}
-			lastval = arr[perm[n]];
-			fprintf(stdout,"INFO: %d\n",lastval);
-			j++;
-		}
-	}
-	if(lastval < finval) {
-		lastval++;
-		while(lastval <= finval) {
-			fprintf(stdout,"INFO: %d\n",lastval);
-			lastval++;
-		}
-	} else if(lastval > finval) {
-		lastval--;
-		while(lastval >= finval) {
-			fprintf(stdout,"INFO: %d\n",lastval);
-			lastval--;
-		}
-	}
-	fflush(stdout);
-}
-
-/************************** ELIMINATE_DUPLTEXT *************************/
-
-void eliminate_dupltext(void)
-{
-	int m,n,k;
-	for(n=0;n<stringscnt-1;n++) {
-		for(m=n+1;m<stringscnt;m++) {
-			if(!strcmp(strings[n],strings[m])) {
-				for(k = m;k < stringscnt-1; k++)
-					strings[k] = strings[k+1];
-				m--;
-				stringscnt--;
-			}
-		}
-	}
-	for(n=0; n < stringscnt;n++)
-		do_stringout(strings[n]);
-	fflush(stdout);
-}
-
-/************************** RANDOM_WARP *************************/
-
-void random_warp(void)
-{
-	int n, wcnt;
-	float *warpvals, *number2;
-	double lastsum, diff, warp, dummy;
-	FILE *fp;
-	char *p;
-	arraysize = 100;
-	if((warpvals = (float *)malloc(arraysize * sizeof(float)))==NULL) {
-		fprintf(stdout,"ERROR: Out of memory.\n");
-		fflush(stdout);
-		return;
-	}
-	if((fp = fopen(string,"r"))==NULL) {
-		sprintf(errstr,"Cannot open infile %s\n",string);
-		do_error();
-	}
-	wcnt = 0;
-	while(fgets(temp,20000,fp)!=NULL) {
-		p = temp;
-		while(strgetfloat(&p,&dummy)) {
-			warpvals[wcnt] = (float)dummy;
-			if(++wcnt >= arraysize) {
-				arraysize += BIGARRAY;
-				if((number2=(float *)malloc(arraysize*sizeof(float)))==NULL) {
-					sprintf(errstr,"Out of memory for more warp values at %d numbers\n",cnt);
-					do_error();
-				}
-				memcpy((void *)number2,(void *)warpvals,cnt * sizeof(float));
-				warpvals = number2;
-			}
-		}
-	}
-	fclose(fp);
-	if(wcnt ==0 || (wcnt & 1)) {
-		sprintf(errstr,"Invalid or missing warp data.\n");
-		do_error();
-	}
-	lastsum = number[0];
-	do_valout(lastsum);
-	for(n=1;n<cnt;n++) {
-		diff = number[n] - number[n-1];
-		warp = readbrk(warpvals,number[n],wcnt);
-		warp = (((drand48() * 2.0) - 1.0) * warp) + 1.0;
-		diff *= warp;
-		lastsum += diff;
-		do_valout(lastsum);
-	}
-}
-
-double readbrk(float *warpvals,double time,int wcnt)
-{
-	int n, got = 0;
-	double wlasttime = 0.0, wlastval=0.0, wthistime=0.0, wthisval=0.0, val;
-	double timeratio, valdiff;
-	for(n = 0; n< wcnt; n+= 2) {
-		if(warpvals[n] < time) {
-			wlasttime = warpvals[n]; 
-			wlastval  = warpvals[n+1]; 
-		} else {
-			wthistime = warpvals[n];
-			wthisval  = warpvals[n+1]; 
-			got = 1;
-			break;
-		}
-	}
-	if(!got)
-		return (double)warpvals[wcnt - 1];
-	valdiff   = wthisval  - wlastval;
-	timeratio = (time - wlasttime)/(wthistime - wlasttime);
-	val = (valdiff * timeratio) + wlastval;
-	return val;
-}
-
+/*
+ * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
+ * http://www.trevorwishart.co.uk
+ * http://www.composersdesktop.com
+ *
+ This file is part of the CDP System.
+
+ The CDP System is free software; you can redistribute it
+ and/or modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The CDP System is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the CDP System; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA
+ *
+ */
+
+
+
+#include <columns.h>
+#include <cdplib.h>
+
+#define MIN_TEMPO (.01666667)           /* 1 beat per hour ! */
+#define MAX_TEMPO (60000)                       /* 1 beat per millisecond ! */
+
+int alphabetical_order(char *,char *);
+double leveltodb(double,int);
+double dbtolevel(double);
+void hinsert(int m,int t,int *perm,int permlen);
+void ascending_sort_cells(int *perm,int ccnt);
+void hshuflup(int k,int *perm,int permlen);
+void hprefix(int m,int *perm,int permlen);
+void randperm(int *perm, int permlen);
+static void invertenv(double piv);
+static void docross
+(double lastnval,double lastmval,double thisnval, double thismval,double time,int *j,double *out,int typ);
+static void hhinsert(int m,int t,int setlen,int *perm);
+static void hhprefix(int m,int setlen,int *perm);
+static void hhshuflup(int k,int setlen,int *perm);
+static void do_repet_restricted_perm(int *arr, int *perm, int arrsiz, int allowed, int endval);
+static void get_metre(char [],int *barlen,int *beatsize);
+static double get_tempo(char *str);
+static double get_beat(int n,int barlen);
+static void get_offset(char *str,double *offset);
+static double randoffset(double scatter);
+static double readbrk(float *warpvals,double time,int wcnt);
+
+/***************************** PRODUCT ***************************/
+
+void product(void)
+{
+    int n;
+    double sum = number[0];
+    for(n=1;n<cnt;n++)
+        sum *= number[n];
+    do_valout_as_message(sum);
+    fflush(stdout);
+}
+
+/*************************** HZ_TO_MIDI ************************/
+
+void hz_to_midi(void)
+{
+    int n;
+    for(n=0;n<cnt;n++) {
+        number[n] = hztomidi(number[n]);
+        do_valout(number[n]);
+    }
+    fflush(stdout);
+}
+
+/******************************** FIND_MEAN *************************/
+
+void find_mean(void)
+{
+    double sum = 0.0;
+    int n;
+    for(n=0;n<cnt;n++)
+        sum += number[n];
+    sum /= (double)cnt;
+    do_valout_as_message(sum);
+    fflush(stdout);
+}
+
+/******************************** MIDI_TO_HZ **************************/
+
+void midi_to_hz(void)
+{
+    int n;
+    for(n=0;n<cnt;n++) {
+        number[n] = miditohz(number[n]);
+        do_valout(number[n]);
+    }
+    fflush(stdout);
+}
+
+/*************************** MAJOR_TO_MINOR *************************/
+
+void major_to_minor(void)
+{
+    int n;
+    int m3 = (4 + ifactor)%12;      /* MIDI location of major 3rd */
+    int m6 = (9 + ifactor)%12;      /* MIDI location of major 6th */
+    for(n=0;n<cnt;n++) {
+        factor = fmod(number[n],TWELVE);
+        if(flteq(factor,(double)m3) || flteq(factor,(double)m6))
+            number[n] -= 1.0;
+        do_valout(number[n]);
+    }
+    fflush(stdout);
+}
+
+/****************** REMOVE_MIDI_PITCHCLASS_DUPLICATES *******************/
+
+void remove_midi_pitchclass_duplicates(void)
+{
+    int n, m, move;
+    int k = cnt-ifactor;
+    int failed = 0;
+    for(n=0;n<k;n++) {
+        for(m=1;m<=ifactor;m++) {
+            if(n+m >= cnt)
+                break;
+            if(flteq(fmod(number[n],12.0),fmod(number[n+m],12.0))) {
+                if((move = m_repos(n+m))<0) {
+                    failed++;
+                } else {
+                    n += move;      /* list shufld forwd, or not */
+                    m--;            /* m+1th item now at m */
+                }
+            }
+        }
+    }
+    if(failed)
+        fprintf(stdout,"WARNING: %d items failed to be separated.\n",failed);
+    for(n=0;n<cnt;n++)
+        do_valout(number[n]);
+    fflush(stdout);
+}
+
+/************************** REVERSE_LIST *************************/
+
+void reverse_list(void)
+{
+    int n;
+    for(n=stringscnt-1;n>=0;n--)
+        do_stringout(strings[n]);
+    fflush(stdout);
+}
+
+/************************* ROTATE_MOTIF *************************/
+
+void rotate_motif(void)
+{
+    int n;
+    for(n=cnt-ifactor;n<cnt;n++)
+        do_valout(number[n]);
+    for(n=0;n<cnt-ifactor;n++)
+        do_valout(number[n]);
+    fflush(stdout);
+}
+
+/************************** RATIOS ****************************/
+
+void ratios(void)
+{
+    int n;
+    for(n=1;n<cnt;n++) {
+        if(flteq(number[n-1],0.0))
+            do_stringout("INF\n");
+        else
+            do_valout(number[n]/number[n-1]);
+    }
+    fflush(stdout);
+}
+
+/******************************** RECIPROCALS ***********************/
+
+void reciprocals(int positive_vals_only)
+{
+    int n;
+    if(positive_vals_only) {
+        for(n=0;n<cnt;n++) {
+            if(number[n] < FLTERR) {
+                fprintf(stdout,"ERROR: Invalid value %d (%lf) for this process\n",n+1,number[n]);
+                fflush(stdout);
+                exit(1);
+            }
+        }
+    }
+    for(n=0;n<cnt;n++) {
+        switch(condit) {
+        case(0):
+            if(flteq(number[n],0.0)) {
+                if(!sloom && !sloombatch)
+                    fprintf(fp[1],"INFINITE\n");
+                else if(sloombatch) {
+                    fprintf(stdout,"INFINITE\n");
+                    fflush(stdout);
+                } else {
+                    fprintf(stdout,"ERROR: Division by zero encountered (item %d) : Impossible\n",n+1);
+                    fflush(stdout);
+                    exit(1);
+                }
+            } else
+                do_valout(factor/number[n]);
+            break;
+        case('>'):
+            if(number[n]>thresh) {
+                if(flteq(number[n],0.0)) {
+                    if(!sloom && !sloombatch)
+                        fprintf(fp[1],"INFINITE\n");
+                    else if(sloombatch) {
+                        fprintf(stdout,"INFINITE\n");
+                        fflush(stdout);
+                    } else {
+                        fprintf(stdout,"ERROR: Division by zero encountered (item %d) : Impossible\n",n+1);
+                        fflush(stdout);
+                        exit(1);
+                    }
+                } else
+                    do_valout(factor/number[n]);
+            } else
+                do_valout(number[n]);
+            break;
+        case('<'):
+            if(number[n]<thresh) {
+                if(flteq(number[n],0.0)) {
+                    if(!sloom && !sloombatch)
+                        fprintf(fp[1],"INFINITE\n");
+                    else if(sloombatch) {
+                        fprintf(stdout,"INFINITE\n");
+                        fflush(stdout);
+                    } else {
+                        fprintf(stdout,"ERROR: Division by zero encountered (item %d) : Impossible\n",n+1);
+                        fflush(stdout);
+                        exit(1);
+                    }
+                } else
+                    do_valout(factor/number[n]);
+            } else
+                do_valout(number[n]);
+            break;
+        }
+    }
+    fflush(stdout);
+}
+
+/****************************** RANDOMISE_ORDER *********************/
+
+void randomise_order(int *perm)
+{
+    int n;
+    randperm(perm,stringscnt);
+    for(n=0;n<stringscnt;n++)
+        do_stringout(strings[perm[n]]);
+    fflush(stdout);
+}
+
+/****************************** RANDOMISE_ORDER *********************/
+
+void randomise_Ntimes(int *perm)
+{
+    int n = 0, m, lastperm;
+    for(m = 0;m< ifactor;m++) {
+        if(n == 0)
+            randperm(perm,stringscnt);
+        else {
+            lastperm = perm[stringscnt - 1];
+            randperm(perm,stringscnt);
+            while(perm[0] == lastperm)
+                randperm(perm,stringscnt);
+        }
+        for(n=0;n<stringscnt;n++)
+            do_stringout(strings[perm[n]]);
+    }
+    fflush(stdout);
+}
+
+/************************** ADD_RANDVAL_PLUS_OR_MINUS ********************/
+
+void add_randval_plus_or_minus(void)
+{
+    int n;
+    for(n=0;n<cnt;n++) {
+        number[n] += ((drand48() * 2.0) - 1.0) * factor;
+        do_valout(number[n]);
+    }
+    fflush(stdout);
+}
+
+/****************************** ADD_RANDVAL ***************************/
+
+void add_randval(void)
+{
+    int n;
+    for(n=0;n<cnt;n++) {
+        number[n] += drand48() * factor;
+        do_valout(number[n]);
+    }
+    fflush(stdout);
+}
+
+/************************ MULTIPLY_BY_RANDVAL ************************/
+
+void multiply_by_randval(void)
+{
+    int n;
+    for(n=0;n<cnt;n++) {
+        number[n] *= drand48() * factor;
+        do_valout(number[n]);
+    }
+    fflush(stdout);
+}
+
+/***************************** RANDCHUNKS ************************/
+
+void randchunks(void)
+{
+    double sum = 0.0;
+    double randrange = fabs(number[1] - number[0]);
+    double minn = min(number[1],number[0]);
+    while(sum<factor) {
+        do_valout(sum);
+        sum += (drand48() * randrange) + minn;
+    }
+    fflush(stdout);
+}
+
+/************************** GENERATE_RANDOM_VALUES ***********************/
+
+void generate_random_values(void)
+{
+    double randrange = number[1] - number[0];
+    int n;
+    for(n=0;n<factor;n++)
+        do_valout((drand48() * randrange) + number[0]);
+    fflush(stdout);
+}
+
+/****************************** RANDOM_0S_AND_1S ********************/
+
+void random_0s_and_1s(void)
+{
+    int n;
+    double sum;
+    int totcnt = (int)round(number[0]);
+    for(n=0;n<totcnt;n++) {
+        sum = drand48() * 2.0;
+        if(sum>=1.0)
+            do_stringout("1\n");
+        else
+            do_stringout("0\n");
+    }
+    fflush(stdout);
+}
+
+/****************************** RANDOM_PAIRS ********************/
+
+void random_pairs(void)
+{
+    int n;
+    double sum;
+    int totcnt = (int)round(number[2]);
+    char tempa[200];
+    char tempb[200];
+    sprintf(tempa,"%d",(int)round(number[0]));
+    sprintf(tempb,"%d",(int)round(number[1]));
+    for(n=0;n<totcnt;n++) {
+        sum = drand48() * 2.0;
+        if(sum>=1.0)
+            do_stringout(tempb);
+        else
+            do_stringout(tempa);
+    }
+    fflush(stdout);
+}
+
+/****************************** RANDOM_0S_AND_1S_RESTRAINED ********************/
+
+void random_0s_and_1s_restrained(void)
+{
+    int n, cnt0 = 0, cnt1 = 0;
+    double sum;
+    int totcnt = (int)round(number[0]);
+    int limit  = (int)round(number[1]);
+    for(n=0;n<totcnt;n++) {
+        sum = drand48() * 2.0;
+        if(sum>=1.0) {
+            cnt1++;
+            if(cnt1 <= limit) {
+                do_stringout("1\n");
+                cnt0 = 0;
+            } else {
+                do_stringout("0\n");
+                cnt1 = 0;
+                cnt0 = 1;
+            }
+        } else {
+            cnt0++;
+            if(cnt0 <= limit) {
+                do_stringout("0\n");
+                cnt1 = 0;
+            } else {
+                do_stringout("1\n");
+                cnt0 = 0;
+                cnt1 = 1;
+            }
+        }
+    }
+    fflush(stdout);
+}
+
+/****************************** RANDOM_PAIRS_RESTRAINED ********************/
+
+void random_pairs_restrained(void)
+{
+    int n, cnt0 = 0, cnt1 = 0;
+    double sum;
+    int totcnt = (int)round(number[2]);
+    int limit  = (int)round(number[3]);
+    char tempa[200];
+    char tempb[200];
+    sprintf(tempa,"%d",(int)round(number[0]));
+    sprintf(tempb,"%d",(int)round(number[1]));
+    for(n=0;n<totcnt;n++) {
+        sum = drand48() * 2.0;
+        if(sum>=1.0) {
+            cnt1++;
+            if(cnt1 <= limit) {
+                do_stringout(tempb);
+                cnt0 = 0;
+            } else {
+                do_stringout(tempa);
+                cnt1 = 0;
+                cnt0 = 1;
+            }
+        } else {
+            cnt0++;
+            if(cnt0 <= limit) {
+                do_stringout(tempa);
+                cnt1 = 0;
+            } else {
+                do_stringout(tempb);
+                cnt0 = 0;
+                cnt1 = 1;
+            }
+        }
+    }
+    fflush(stdout);
+}
+
+/****************************** RANDOM_SCATTER **********************/
+
+void random_scatter(void)
+{
+    int n;
+    double scatter;
+    double *diffs = (double *)exmalloc((cnt-1)*sizeof(double));
+    for(n=0;n<cnt-1;n++) {
+        diffs[n] = number[n+1] - number[n];
+        diffs[n] /= 2.0;
+    }
+    for(n=1;n<cnt-1;n++) {
+        scatter = ((drand48() * 2.0) - 1.0) * factor;
+        if(scatter > 0.0)
+            number[n] += diffs[n] * scatter;
+        else
+            number[n] += diffs[n-1] * scatter;
+    }
+    print_numbers();
+}
+
+/************************** RANDOM_ELIMINATION ***********************/
+
+void random_elimination(void)
+{
+    int n, m;
+    for(n=0;n<ifactor;n++) {
+        m = (int)(drand48() * cnt);     /* TRUNCATE */
+        eliminate(m);
+    }
+    print_numbers();
+}
+
+/*************************** EQUAL_DIVISIONS ************************/
+
+void equal_divisions(void)
+{
+    double interval = (number[1] - number[0])/factor;
+    double sum = number[0];
+    if(interval > 0.0) {
+        while(sum<=number[1]) {
+            do_valout(sum);
+            sum += interval;
+        }
+    } else {
+        while(sum>=number[1]) {
+            do_valout(sum);
+            sum += interval;
+        }
+    }
+    fflush(stdout);
+}
+
+/************************* LOG_EQUAL_DIVISIONS ***********************/
+
+void log_equal_divisions(void)
+{
+    double sum                = log(number[0]);
+    double top        = log(number[1]);
+    double interval = (top - sum)/factor;
+    if(sum < top) {
+        while(sum <= top - FLTERR) {
+            do_valout(exp(sum));
+            sum += interval;
+        }
+
+    } else {
+        while(sum >= top + FLTERR) {
+            do_valout(exp(sum));
+            sum += interval;
+        }
+    }
+    do_valout(number[1]);
+    fflush(stdout);
+}
+
+/****************************** QUADRATIC_CURVE_STEPS ******************/
+
+void quadratic_curve_steps(void)
+{
+    double sum, diff = number[1] - number[0];
+    double step = fabs(1.0/(factor - 1.0));
+    double thisstep = 0.0;
+    int cnt = 0, ifactor = round(factor);
+    if(diff>0.0)
+        number[2] = 1.0/number[2];
+    for(;;) {
+        sum = pow(thisstep,number[2]);
+        sum = (sum * diff) + number[0];
+        do_valout(sum);
+        if(++cnt >= ifactor)
+            break;
+        thisstep += step;
+    }
+    fflush(stdout);
+}
+
+/*************************** PLAIN_BOB ***************************/
+
+void plain_bob(void)
+{
+    int n, m, k;
+    for(n=0;n<cnt;n++)
+        do_valout(number[n]);
+    for(m=0;m<cnt-1;m++) {
+        for(k=0;k<cnt-1;k++) {
+            bellperm1();
+            for(n=0;n<cnt;n++)
+                do_valout(number[n]);
+            bellperm2();
+            for(n=0;n<cnt;n++)
+                do_valout(number[n]);
+        }
+        bellperm1();
+        for(n=0;n<cnt;n++)
+            do_valout(number[n]);
+        bellperm3();
+        for(n=0;n<cnt;n++)
+            do_valout(number[n]);
+    }
+    fflush(stdout);
+}
+
+/*********************** REPEAT_INTERVALS *************************/
+
+void repeat_intervals(void)
+{
+    int n, m;
+    double z, k;
+    for(n=0;n<cnt-1;n++)
+        do_valout(number[n]);
+    z = k = number[n] - number[0];
+    for(m=1;m<=ifactor;m++) {
+        for(n=0;n<cnt-1;n++)    /*TW Feb 2005*/
+            do_valout(number[n] + z);
+        z += k;
+    }
+    fflush(stdout);
+}
+
+/************** MAKE_EQUAL_INTEVALS_BTWN_GIVEN_VALS ************/
+
+void make_equal_intevals_btwn_given_vals(void)
+{
+    double top = number[1];
+    double sum = number[0];
+
+    if(factor > 0.0) {
+        if(number[0] > number[1]) {
+            top = number[0];
+            sum = number[1];
+        }
+    } else {
+        if(number[0] < number[1]) {
+            top = number[0];
+            sum = number[1];
+        }
+    }
+    if(top >= sum ) {
+        while(sum<=top) {
+            do_valout(sum);
+            sum += factor;
+        }
+    } else {
+        while(sum>=top) {
+            do_valout(sum);
+            sum += factor;
+        }
+    }
+    fflush(stdout);
+}
+
+/********************** CREATE_INTERVALS ***********************/
+
+void create_intervals(void)
+{
+    int n;
+    for(n=0;n<ifactor;n++) {
+        do_valout(number[0] * n);
+    }
+    fflush(stdout);
+}
+
+/********************** CREATE_INTERVALS_FROM_BASE ***********************/
+
+void create_intervals_from_base(void)
+{
+    int n;
+    double sum = number[1];
+    for(n=0;n<ifactor;n++) {
+        do_valout(sum);
+        sum += number[0];
+    }
+    fflush(stdout);
+}
+
+/********************** CREATE_RATIOS_FROM_BASE ***********************/
+
+void create_ratios_from_base(void)
+{
+    int n;
+    double sum = number[1];
+    for(n=0;n<ifactor;n++) {
+        do_valout(sum);
+        if(sum > HUGE/2.0 || sum < -HUGE/2.0) {
+            sprintf(errstr,"Calculation overflows.\n");
+            do_error();
+        }
+        sum *= number[0];
+    }
+    fflush(stdout);
+}
+
+/********************** CREATE_EQUAL_STEPS ***********************/
+
+void create_equal_steps(void)
+{
+    int n;
+    double sum = number[0];
+    double step = (number[1] - number[0])/((double)ifactor - 1.0);
+    for(n=0;n<ifactor;n++) {
+        do_valout(sum);
+        sum += step;
+    }
+    fflush(stdout);
+}
+
+/********************** CREATE_EQUAL_VALS ***********************/
+
+void create_equal_vals(void)
+{
+    int n;
+    for(n=0;n<ifactor;n++) {
+        do_valout(number[0]);
+    }
+    fflush(stdout);
+}
+
+/************************ CHANGE_VALUE_OF_INTERVALS ********************/
+
+void change_value_of_intervals(void)
+{
+    double interval, sum = number[0];
+    int n;
+    for(n=1;n<cnt;n++) {
+        do_valout(sum);
+        switch(ro) {
+        case('a'): interval=(number[n]-number[n-1])+factor; break;
+        case('m'): interval=(number[n]-number[n-1])*factor; break;
+        default:
+            fprintf(stdout,"ERROR: Unkonwn case in change_value_of_intervals()\n");
+            fflush(stdout);
+            exit(1);
+            break;
+        }
+        sum += interval;
+    }
+    do_valout(sum);
+    fflush(stdout);
+}
+
+/******************** MOTIVICALLY_INVERT_MIDI **********************/
+
+void motivically_invert_midi(void)
+{
+    double factor = 2.0 * number[0];
+    int n;
+    for(n=1;n<cnt;n++)
+        number[n] = factor - number[n];
+    print_numbers();
+}
+
+/********************** MOTIVICALLY_INVERT_HZ **********************/
+
+void motivically_invert_hz(void)
+{
+    double factor;
+    int n;
+    if(flteq((factor = number[0] * number[0]),0.0)) {
+        sprintf(errstr,"First frq is zero : can't proceed.\n");
+        do_error();
+    }
+    for(n=1;n<cnt;n++)
+        number[n] = factor/number[n];
+    print_numbers();
+}
+
+/******************** GET_INTERMEDIATE_VALUES ************************/
+
+void get_intermediate_values(void)
+{
+    int n;
+    double d;
+    for(n=1;n<cnt;n++) {
+        d = (number[n] + number[n-1])/2.0;
+        do_valout(d);
+    }
+    fflush(stdout);
+}
+
+/******************** INSERT_INTERMEDIATE_VALUES ************************/
+
+void insert_intermediate_values(void)
+{
+    int n;
+    double d;
+    fprintf(stdout,"INFO: %lf\n",number[0]);
+    for(n=1;n<cnt;n++) {
+        d = (number[n] + number[n-1])/2.0;
+        fprintf(stdout,"INFO: %lf\n",d);
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+    }
+    fflush(stdout);
+}
+
+/******************** INSERT_INTERMEDIATE_VALP ************************/
+
+void insert_intermediate_valp(void)
+{
+    int n;
+    double d;
+    for(n=1;n<cnt;n+=2) {
+        fprintf(stdout,"INFO: %lf\n",number[n-1]);
+        d = (number[n] + number[n-1])/2.0;
+        fprintf(stdout,"INFO: %lf\n",d);
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+    }
+    fflush(stdout);
+}
+
+/************************** GET_INTERVALS ***********************/
+
+void get_intervals(void)
+{
+    int n;
+    for(n=1;n<cnt;n++)
+        do_valout(number[n]-number[n-1]);
+    fflush(stdout);
+}
+
+/************************ GET_ONE_SKIP_N ************************/
+
+void get_one_skip_n(void)
+{
+    int n = 0;
+    ifactor = round(factor);
+    if(ifactor < 1) {
+        sprintf(errstr,"Invalid parameter (%d)\n",ifactor);
+        do_error();
+    }
+    while(n<stringscnt) {
+        do_stringout(strings[n++]);
+        n += ifactor;
+    }
+    fflush(stdout);
+}
+
+/************************ GET_N_SKIP_ONE *************************/
+
+void get_n_skip_one(void)
+{
+    int m, n = 0;
+    int k, ifactor = round(factor);
+
+    if(ifactor < 1) {
+        sprintf(errstr,"Invalid parameter (%d)\n",ifactor);
+        do_error();
+    }
+    while(n<stringscnt) {
+        if((k = n + ifactor) >= stringscnt) {
+            for(m=n;m<stringscnt;m++)
+                do_stringout(strings[m]);
+            break;
+        }
+        for(m=n;m<k;m++)
+            do_stringout(strings[m]);
+        n+= ifactor+1;
+    }
+    fflush(stdout);
+}
+
+/************************* SUM_NWISE **************************/
+
+void sum_nwise(void)
+{
+    int n, m;
+    ifactor = round(factor);
+    /* RWD */
+    if(ifactor > cnt) {
+        sprintf(errstr,"group size (N) too large for infile\n");
+        do_error();
+    }
+    for(n=0;n<=cnt-ifactor;n++) {   /*RWD: test was just < */
+        for(m=1;m<ifactor;m++)
+            number[n] += number[n+m];
+        do_valout(number[n]);
+    }
+    fflush(stdout);
+}
+
+/************************* SUM_MINUS_OVERLAPS *********************/
+
+void sum_minus_overlaps(void)
+{
+    int n;
+    double sum = 0.0;
+    for(n=0;n<cnt;n++)
+        sum += number[n];
+    sum -= (double)(cnt-1) * factor;
+    do_valout_as_message(sum);
+    fflush(stdout);
+}
+
+/******************** SUM_ABSOLUTE_DIFFERENCES ********************/
+
+void sum_absolute_differences(void)
+{
+    int n;
+    double sum = 0.0;
+    for(n=1;n<cnt;n++)
+        sum += fabs(number[n] - number[n-1]);
+    sum -= (double)(cnt-1) * factor;
+    do_valout_as_message(sum);
+    fflush(stdout);
+}
+
+/**************************** STACK ***************************/
+
+void stack(int with_last)
+{
+    int n;
+    double sum = 0.0;
+    for(n=0;n<cnt;n++) {
+        do_valout(sum);
+        sum += number[n] - factor;
+    }
+    if(with_last) {
+        sum += factor;
+        do_valout(sum);
+    }
+    fflush(stdout);
+}
+
+/*********************** DUPLICATE_VALUES **************************/
+
+void duplicate_values(void)
+{
+    int n, m;
+    for(n=0;n<stringscnt;n++) {
+        for(m=0;m<ifactor;m++)
+            do_stringout(strings[n]);
+    }
+    fflush(stdout);
+}
+
+/*********************** DUPLICATE_VALUES_STEPPED **************************/
+
+void duplicate_values_stepped(void)
+{
+    int n, m;
+    double step = number[cnt+1];
+    double offset = 0.0;
+    ifactor = round(number[cnt]);
+    for(m=0;m<ifactor;m++) {
+        for(n=0;n<cnt;n++)
+            fprintf(stdout,"INFO: %lf\n",number[n] + offset);
+        offset += step;
+    }
+    fflush(stdout);
+}
+/**************************** DUPLICATE_LIST **********************/
+
+void duplicate_list(void)
+{
+    int n, m;
+    for(m=0;m<ifactor;m++) {
+        for(n=0;n<stringscnt;n++)
+            do_stringout(strings[n]);
+    }
+    fflush(stdout);
+}
+
+/****************************** FORMAT_VALS ****************************/
+
+void format_vals(void)
+{ /*RWD new Format option : recast by TW */
+    int n, m, OK = 1;
+    double d = (double)cnt/(double)ifactor;
+    int rowcnt = cnt/ifactor;
+    char temp[64];
+
+    errstr[0] = ENDOFSTR;
+    if(d > (double)rowcnt)
+        rowcnt++;
+    if((rowcnt > 82) && sloom) {
+        sprintf(errstr,"Too many (%d) rows to handle",rowcnt);
+        do_error();
+    }
+    for(n=0;n<cnt;n+=rowcnt) {
+        for(m=0;m<rowcnt;m++) {
+            if(!sloom && !sloombatch) {
+                if(n!=0 && m==0)
+                    fprintf(fp[1],"\n");
+                if(n+m < cnt)
+                    fprintf(fp[1],"%.5lf ",number[n+m]);
+                else
+                    OK = 0;
+            } else {
+                if(n!=0 && m==0) {
+                    fprintf(stdout,"INFO: %s\n",errstr);
+                    errstr[0] = ENDOFSTR;
+                }
+                if(n+m < cnt) {
+                    sprintf(temp,"%.5lf ",number[n+m]);
+                    strcat(errstr,temp);
+                } else
+                    OK = 0;
+            }
+        }
+        if(!OK)
+            break;
+    }
+    if(!sloom && !sloombatch)
+        fprintf(fp[1],"\n");
+    else
+        fprintf(stdout,"INFO: %s\n",errstr);
+    fflush(stdout);
+}
+
+
+/****************************** COLUMN_FORMAT_VALS ****************************/
+
+void column_format_vals(void)
+{       int n, m;
+
+    double d = (double)cnt/(double)ifactor;
+    int rowcnt = cnt/ifactor;
+    char temp[64];
+    errstr[0] = ENDOFSTR;
+    if(d > (double)rowcnt)
+        rowcnt++;
+    for(n=0;n<rowcnt;n++) {
+        for(m=n;m<cnt;m+=rowcnt) {
+            if(!sloom && !sloombatch)
+                fprintf(fp[1],"%.5lf ",number[m]);
+            else {
+                sprintf(temp,"%.5lf ",number[m]);
+                strcat(errstr,temp);
+            }
+        }
+        if(!sloom && !sloombatch)
+            fprintf(fp[1],"\n");
+        else {
+            fprintf(stdout,"INFO: %s\n",errstr);
+            errstr[0] = ENDOFSTR;
+        }
+    }
+    fflush(stdout);
+}
+
+
+/************************ INTERVAL_LIMIT() ********************/
+
+void interval_limit(void)
+{
+    double interval, sum = number[0];
+    int n;
+    do_valout(sum);
+    for(n=1;n<cnt;n++) {
+        interval=number[n]-number[n-1];
+        switch(ro) {
+        case('l'): interval = max(interval,factor);     break;
+        case('L'): interval = min(interval,factor);     break;
+        }
+        sum += interval;
+        do_valout(sum);
+    }
+    fflush(stdout);
+}
+
+/********************************** TIME_DENSITY ******************************/
+
+void time_density(void)
+{
+    int n, m = 0, k, ended = 0;
+    double min_endtime, *endtime = (double *)exmalloc(ifactor * sizeof(double));
+    for(n=0;n<ifactor;n++)
+        endtime[n] = 0.0;
+    min_endtime = 0.0;
+    for(;;) {
+        for(n=0;n<ifactor;n++) {
+            if(flteq(endtime[n],min_endtime)) {
+                do_valout(endtime[n]);
+                endtime[n] += number[m];
+                if(++m >= cnt) {
+                    ended = 1;
+                    break;
+                }
+                min_endtime = endtime[n];
+                for(k=0;k<ifactor;k++) {
+                    if(endtime[k] < min_endtime)
+                        min_endtime = endtime[k];
+                }
+            }
+        }
+        if(ended)
+            break;
+    }
+    fflush(stdout);
+}
+
+/********************************** DIVIDE_LIST ******************************/
+
+void divide_list(void)
+{
+    int n;
+    for(n=0;n<cnt;n++) {
+        switch(condit) {
+        case(0):
+            number[n] /= factor;
+            break;
+        case('>'):
+            if(number[n]>thresh)
+                number[n] /= factor;
+            break;
+        case('<'):
+            if(number[n]<thresh)
+                number[n] /= factor;
+            break;
+        }
+        do_valout(number[n]);
+    }
+    fflush(stdout);
+}
+
+/********************************** GROUP ******************************/
+
+void group(void)
+{
+    int n, m = 0;
+    while(m < ifactor) {
+        for(n=m;n<stringscnt;n+=ifactor) {
+            do_stringout(strings[n]);
+        }
+        if(!sloom && !sloombatch)
+            fprintf(fp[1],"\n");
+        m++;
+    }
+    fflush(stdout);
+}
+
+/********************************** DUPLICATE_OCTAVES ******************************/
+
+void duplicate_octaves(void)
+{
+    int n, m;
+    double d;
+    for(n=0;n<cnt;n++)
+        do_valout(number[n]);
+    for(m=1;m<=ifactor;m++) {
+        d = 12.0 * m;
+        for(n=0;n<cnt;n++)
+            do_valout(number[n] + d);
+    }
+    fflush(stdout);
+}
+
+/********************************** DUPLICATE_OCTFRQ ******************************/
+
+void duplicate_octfrq(void)
+{
+    int n, m;
+    double d;
+    for(n=0;n<cnt;n++)
+        do_valout(number[n]);
+    for(m=1;m<=ifactor;m++) {
+        d = pow(2.0,(double)m);
+        for(n=0;n<cnt;n++)
+            do_valout(number[n] * d);
+    }
+    fflush(stdout);
+}
+
+/********************************** INTERVAL_TO_RATIO ******************************/
+
+void interval_to_ratio(int semitones,int tstretch)
+{
+    int n;
+    double bum = 0.0;
+    for(n=0;n<cnt;n++) {
+        if(semitones) {
+            bum = number[n];
+            number[n] /= 12.0;
+        }
+        if(fabs(number[n]) > MAXOCTTRANS) {
+            if(!semitones)
+                bum = number[n];
+            sprintf(errstr,"Item %d (%lf) is too large or small to convert.\n",n+1,bum);
+            do_error();
+        }
+    }
+    for(n=0;n<cnt;n++) {
+        number[n] = pow(2.0,number[n]);
+        if(tstretch)
+            number[n] = 1.0/number[n];
+        do_valout(number[n]);
+    }
+    fflush(stdout);
+}
+
+/********************************** RATIO_TO_INTERVAL ******************************/
+
+void ratio_to_interval(int semitones,int tstretch)
+{
+    int n;
+    for(n=0;n<cnt;n++) {
+        if(number[n] < FLTERR) {
+            fprintf(stdout,"ERROR: ratio %d (%lf) is too small or an impossible (negative) value.\n",n+1,number[n]);
+            fflush(stdout);
+            exit(1);
+        }
+        if(tstretch)
+            number[n] = 1.0/number[n];
+    }
+    for(n=0;n<cnt;n++) {
+        number[n] = log(number[n]) * ONE_OVER_LN2;
+        if(semitones)
+            number[n] *= 12.0;
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+    }
+    fflush(stdout);
+}
+
+/********************************** DO_SLOPE ******************************/
+
+void do_slope(void)
+{
+    int n;
+    double ddiff;
+    do_valout(number[0]);
+    for(n=1;n<cnt;n++) {
+        ddiff = number[n] - number[0];
+        ddiff *= factor;
+        number[n] = number[0] + ddiff;
+        do_valout(number[n]);
+    }
+    fflush(stdout);
+}
+
+
+/********************************** ALPHABETIC_SORT ******************************/
+
+void alphabetic_sort(void)
+{
+    int n,m;
+    char tempp[200],*p;
+    for(n=1;n<stringscnt;n++)  {
+        p =  strings[n];
+        strcpy(tempp,strings[n]);
+        m = n-1;
+        while(m >= 0 && alphabetical_order(tempp,strings[m])) {
+            strings[m+1] = strings[m];
+            m--;
+        }
+        strings[m+1] = p;
+    }
+    for(n=0;n<stringscnt;n++)
+        do_stringout(strings[n]);
+    fflush(stdout);
+}
+
+/******************************* ALPHABETICAL_ORDER **************************/
+
+#define UPPERCASE(x)  ((x) >= 'A' && (x) < 'Z')
+
+
+int alphabetical_order(char *str1,char *str2)
+{
+    char p, q;
+    int n,m;
+    int j = strlen(str1);
+    int k = strlen(str2);
+    m = min(j,k);
+    for(n=0;n<m;n++) {
+        p = str1[n];
+        q = str2[n];
+        if(UPPERCASE(p))          p += 32;
+        if(UPPERCASE(q))          q += 32;
+        if(p > q)       return(0);
+        if(p < q)       return(1);
+    }
+    if(k<j)
+        return(0);
+    return(1);
+}
+
+/********************************** LEVEL_TO_DB ******************************/
+
+void level_to_db(int sampleval)
+{
+    int n;
+    for(n=0;n<cnt;n++) {
+        if(sampleval)
+            number[n] /= (double)MAXSAMP;
+        number[n] = leveltodb(number[n],n);
+        sprintf(errstr,"%lfdB\n",number[n]);
+        do_stringout(errstr);
+    }
+    fflush(stdout);
+}
+
+/********************************** DB_TO_LEVEL ******************************/
+
+void db_to_level(int sampleval)
+{
+    int n;
+    for(n=0;n<cnt;n++) {
+        number[n] = dbtolevel(number[n]);
+        if(sampleval)
+            number[n] *= (double)MAXSAMP;
+        do_valout(number[n]);
+    }
+    fflush(stdout);
+}
+
+/******************************** LEVELTODB ***********************/
+
+double leveltodb(double val,int n)
+{
+
+    if(val <= 0.0) {
+        sprintf(errstr,"Gain value %d <= 0.0: Cannot proceed\n",n+1);
+        do_error();
+    }
+    val = log10(val);
+    val *= 20.0;
+    return(val);
+}
+
+/******************************** DBTOLEVEL ***********************/
+
+double dbtolevel(double val)
+{
+    int isneg = 0;
+    if(flteq(val,0.0))
+        return(1.0);
+    if(val < 0.0) {
+        val = -val;
+        isneg = 1;
+    }
+    val /= 20.0;
+    val = pow(10.0,val);
+    if(isneg)
+        val = 1.0/val;
+    return(val);
+}
+
+/******************************** COLUMNATE ***********************/
+
+void columnate(void)
+{
+    int n;
+    for(n=0;n<cnt;n++)
+        do_valout(number[n]);
+    fflush(stdout);
+}
+
+/******************************** SAMP_TO_TIME ***********************/
+
+void samp_to_time(void)
+{
+    int n;
+    double inv_sr = 1.0/(double)ifactor;
+    for(n=0;n<cnt;n++)
+        do_valout(number[n] * inv_sr);
+    fflush(stdout);
+}
+
+/******************************** TIME_TO_SAMP ***********************/
+
+void time_to_samp(void)
+{
+    int n;
+    for(n=0;n<cnt;n++) {
+        do_valout(number[n] * (double)ifactor);
+    }
+    fflush(stdout);
+}
+
+/******************************** DELETE_SMALL_INTERVALS ***********************/
+
+void delete_small_intervals(void)
+{
+    int n, m;
+    int start = 1, end = 1, shrink;
+    double diff;
+    for(n=1;n<cnt;n++) {
+        if((diff = number[n] - number[n-1]) < 0) {
+            fprintf(stdout,"WARNING: Numbers must be in ascending order for this option.\n");
+            fflush(stdout);
+            exit(1);
+        }
+        if(diff <= factor)
+            end++;
+        else {
+            if((shrink = (end - start))) {
+                for(m = n-1;m < cnt; m++)
+                    number[m-shrink] = number[m];
+                end = start;
+                cnt -= shrink;
+                n -= shrink;
+            }
+            start++;
+            end++;
+        }
+    }
+    for(n=0;n<cnt;n++)
+        do_valout(number[n]);
+    fflush(stdout);
+}
+
+/******************************** MARK_EVENT_GROUPS ***********************/
+
+void mark_event_groups(void)
+{
+    int n, m;
+    int start = 1, end = 1, shrink;
+    int orig_cnt = cnt;
+    double diff;
+    for(n=1;n<cnt;n++) {
+        if((diff = number[n] - number[n-1]) < 0) {
+            fprintf(stdout,"WARNING: Numbers must be in ascending order for this option.\n");
+            fflush(stdout);
+            exit(1);
+        }
+        if(diff <= factor) {
+            end++;
+        } else {
+            shrink = end - start;
+            switch(shrink) {
+            case(1):                        /* 2 in group, preserve */
+                start++;
+                break;
+            case(0):                        /* 1 isolated point, duplicate */
+                cnt++;
+                if(cnt > orig_cnt) {
+                    if((number = (double *)realloc((char *)number,cnt * sizeof(double)))==NULL) {
+                        fprintf(stdout,"WARNING: Out of memory for storing numbers.\n");
+                        fflush(stdout);
+                        exit(1);
+                    }
+                    orig_cnt = cnt;
+                }
+                for(m = cnt-1; m >= n; m--)
+                    number[m] = number[m-1];
+                n++;
+                start++;
+                end++;
+                break;
+            default:                        /* >2 in group, bracket */
+                shrink--;
+                for(m = n-1;m < cnt; m++)
+                    number[m-shrink] = number[m];
+                end = start;
+                cnt -= shrink;
+                n -= shrink;
+                break;
+            }
+            start++;
+            end++;
+        }
+    }
+    shrink = end - start;
+    switch(shrink) {
+    case(0):
+        cnt++;
+        if(cnt > orig_cnt) {
+            if((number = (double *)realloc((char *)number,cnt * sizeof(double)))==NULL) {
+                fprintf(stdout,"WARNING: Out of memory for storing numbers.\n");
+                fflush(stdout);
+                exit(1);
+            }
+        }
+        for(m = cnt-1; m >= n; m--)
+            number[m] = number[m-1];
+        break;
+    case(1):
+        break;
+    default:
+        shrink--;
+        for(m = n-1;m < cnt; m++)
+            number[m-shrink] = number[m];
+        cnt -= shrink;
+        break;
+    }
+    for(n=0;n<cnt;n++)
+        do_valout(number[n]);
+    fflush(stdout);
+}
+
+/******************************** SPANPAIR ***********************
+ *
+ * span pairs of values.
+ */
+
+void spanpair(void)
+{
+    int n, m, is_even = 1;
+    int cnt2 = cnt * 2;
+    if(cnt & 1) {
+        fprintf(stdout,"WARNING: This process only works on an even number of values.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    if((number = (double *)realloc((char *)number,cnt2 * sizeof(double)))==NULL) {
+        fprintf(stdout,"WARNING: Out of memory for storing numbers.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    m = cnt2-1;
+    for(n=cnt-1;n>=0;n--) {
+        if(number[n] < 0.0) {
+            fprintf(stdout,"WARNING: No negative numbers allowed in this option.\n");
+            fflush(stdout);
+            exit(1);
+        }
+        if(is_even) {
+            number[m--] = number[n] + factor + thresh;
+            number[m--] = number[n] + factor;
+        } else {
+            number[m--] = number[n];
+            number[m--] = max(number[n] - thresh, 0.0);
+        }
+        is_even = !is_even;
+    }
+    for(n=0;n<cnt2;n++)
+        do_valout(number[n]);
+    fflush(stdout);
+}
+
+/******************************** SPAN ***********************
+ *
+ * span single values with a pair.
+ */
+
+void span(void)
+{
+    int n, m;
+    int cnt2 = cnt * 4;
+    if((number = (double *)realloc((char *)number,cnt2 * sizeof(double)))==NULL) {
+        fprintf(stdout,"WARNING: Out of memory for storing numbers.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    m = cnt2-1;
+    for(n=cnt-1;n>=0;n--) {
+        if(number[n] < 0.0) {
+            fprintf(stdout,"WARNING: No negative numbers allowed in this option.\n");
+            fflush(stdout);
+            exit(1);
+        }
+        number[m--] = number[n] + factor + thresh;
+        number[m--] = number[n] + factor;
+        number[m--] = number[n];
+        number[m--] = max(number[n] - thresh, 0.0);
+    }
+    for(n=0;n<cnt2;n++)
+        do_valout(number[n]);
+    fflush(stdout);
+}
+
+/******************************** SPAN_XALL ***********************
+ *
+ * span single values.
+ */
+
+void span_xall(void)
+{
+    int n, m;
+    int cnt2 = cnt * 3;
+    if((number = (double *)realloc((char *)number,cnt2 * sizeof(double)))==NULL) {
+        fprintf(stdout,"WARNING: Out of memory for storing numbers.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    m = cnt2-1;
+    for(n=cnt-1;n>=0;n--) {
+        if(number[n] < 0.0) {
+            fprintf(stdout,"WARNING: No negative numbers allowed in this option.\n");
+            fflush(stdout);
+            exit(1);
+        }
+        number[m--] = number[n] + thresh;
+        number[m--] = number[n];
+        number[m--] = max(number[n] - thresh, 0.0);
+    }
+    for(n=0;n<cnt2;n++)
+        do_valout(number[n]);
+    fflush(stdout);
+}
+
+/******************************** ALTERNATION PATTERNS ***********************/
+
+void alt0101(void) {
+    int n;
+    for(n=0;n<cnt;n++)
+        fprintf(stdout,"INFO: %lf\n",number[n & 1]);
+    fflush(stdout);
+}
+
+void alt0011(void) {
+    int n;
+    for(n=0;n<cnt;n++)
+        fprintf(stdout,"INFO: %lf\n",number[n & 2]);
+    fflush(stdout);
+}
+
+void alt01100(void) {
+    int n;
+    fprintf(stdout,"INFO: %lf\n",number[0]);
+    cnt--;
+    for(n=0;n<cnt;n++)
+        fprintf(stdout,"INFO: %lf\n",number[!(n & 2)]);
+    fflush(stdout);
+}
+
+void alt0r0r(void) {
+    int n;
+    double rrange = number[2] - number[1];
+    for(n=0;n<cnt;n++) {
+        if(n & 1) {
+            fprintf(stdout,"INFO: %lf\n",(drand48() * rrange) + number[1]);
+        } else {
+            fprintf(stdout,"INFO: %lf\n",number[0]);
+        }
+    }
+    fflush(stdout);
+}
+
+void altr0r0(void) {
+    int n;
+    double rrange = number[2] - number[1];
+    for(n=0;n<cnt;n++) {
+        if(n & 1) {
+            fprintf(stdout,"INFO: %lf\n",number[0]);
+        } else {
+            fprintf(stdout,"INFO: %lf\n",(drand48() * rrange) + number[1]);
+        }
+    }
+    fflush(stdout);
+}
+
+void altrr00(void) {
+    int n;
+    double rrange = number[2] - number[1];
+    for(n=0;n<cnt;n++) {
+        if(n & 2) {
+            fprintf(stdout,"INFO: %lf\n",number[0]);
+        } else {
+            fprintf(stdout,"INFO: %lf\n",(drand48() * rrange) + number[1]);
+        }
+    }
+    fflush(stdout);
+}
+
+void alt00rr(void) {
+    int n;
+    double rrange = number[2] - number[1];
+    for(n=0;n<cnt;n++) {
+        if(n & 2) {
+            fprintf(stdout,"INFO: %lf\n",(drand48() * rrange) + number[1]);
+        } else {
+            fprintf(stdout,"INFO: %lf\n",number[0]);
+        }
+    }
+    fflush(stdout);
+}
+
+void alt0rr00r(void) {
+    int n;
+    double rrange = number[2] - number[1];
+    fprintf(stdout,"INFO: %lf\n",number[0]);
+    cnt--;
+    for(n=0;n<cnt;n++) {
+        if(n & 2) {
+            fprintf(stdout,"INFO: %lf\n",number[0]);
+        } else {
+            fprintf(stdout,"INFO: %lf\n",(drand48() * rrange) + number[1]);
+        }
+    }
+    fflush(stdout);
+}
+
+void altr00rr0(void) {
+    int n;
+    double rrange = number[2] - number[1];
+    fprintf(stdout,"INFO: %lf\n",(drand48() * rrange) + number[1]);
+    cnt--;
+    for(n=0;n<cnt;n++) {
+        if(n & 2) {
+            fprintf(stdout,"INFO: %lf\n",(drand48() * rrange) + number[1]);
+        } else {
+            fprintf(stdout,"INFO: %lf\n",number[0]);
+        }
+    }
+    fflush(stdout);
+}
+
+void altRR00(void) {
+    int n;
+    double k = 0.0;
+    double rrange = number[2] - number[1];
+    for(n=0;n<cnt;n++) {
+        if(n & 2) {
+            fprintf(stdout,"INFO: %lf\n",number[0]);
+        } else {
+            if (!(n & 1)) {
+                k = (drand48() * rrange) + number[1];
+            }
+            fprintf(stdout,"INFO: %lf\n",k);
+        }
+    }
+    fflush(stdout);
+}
+
+void alt00RR(void) {
+    int n;
+    double k = 0.0;
+    double rrange = number[2] - number[1];
+    for(n=0;n<cnt;n++) {
+        if(n & 2) {
+            if (!(n & 1)) {
+                k = (drand48() * rrange) + number[1];
+            }
+            fprintf(stdout,"INFO: %lf\n",k);
+        } else {
+            fprintf(stdout,"INFO: %lf\n",number[0]);
+        }
+    }
+    fflush(stdout);
+}
+
+void alt0RR00R(void) {
+    int n;
+    double k = 0.0;
+    double rrange = number[2] - number[1];
+    fprintf(stdout,"INFO: %lf\n",number[0]);
+    cnt--;
+    for(n=0;n<cnt;n++) {
+        if(n & 2) {
+            fprintf(stdout,"INFO: %lf\n",number[0]);
+        } else {
+            if (!(n & 1)) {
+                k = (drand48() * rrange) + number[1];
+            }
+            fprintf(stdout,"INFO: %lf\n",k);
+        }
+    }
+    fflush(stdout);
+}
+
+void altR00RR0(void) {
+    int n;
+    double k = 0.0;
+    double rrange = number[2] - number[1];
+    fprintf(stdout,"INFO: %lf\n",(drand48() * rrange) + number[1]);
+    cnt--;
+    for(n=0;n<cnt;n++) {
+        if(n & 2) {
+            if (!(n & 1)) {
+                k = (drand48() * rrange) + number[1];
+            }
+            fprintf(stdout,"INFO: %lf\n",k);
+        } else {
+            fprintf(stdout,"INFO: %lf\n",number[0]);
+        }
+    }
+    fflush(stdout);
+}
+
+/******************************** CHECK FOR ASCENDING_ORDER ***********************/
+
+void ascending_order(void) {
+    int n, OK = 1;
+    for(n=1;n<cnt;n++) {
+        if(number[n] <= number[n-1]) {
+            OK = 0;
+            break;
+        }
+    }
+    if(!sloom && !sloombatch) {
+        if(OK)
+            fprintf(stdout, "sequence is in ascending order.");
+        else
+            fprintf(stdout, "sequence is NOT in ascending order at item %d (%lf)",n+1,number[n]);
+    } else {
+        if(OK)
+            fprintf(stdout, "WARNING: sequence is in ascending order.");
+        else
+            fprintf(stdout, "WARNING: sequence is NOT in ascending order at item %d (%lf)",n+1,number[n]);
+    }
+    fflush(stdout);
+}
+
+/******************************** EDIT INDIVIDUAL VALUES ***********************/
+
+void delete_vals(void) {
+    int n, m, k = (int)factor;
+    if(k < ifactor) {
+        n = ifactor;
+        ifactor = k;
+        k = n;
+    }
+    k = min(k,cnt);
+    if(k < cnt) {
+        for(n=ifactor-1,m=k;m<cnt;m++,n++)
+            number[n] = number[m];
+        cnt -= (k - ifactor + 1);
+    } else {
+        cnt = ifactor-1;
+    }
+    for(n=0;n<cnt;n++)
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+    fflush(stdout);
+}
+
+void replace_val(void) {
+    int n;
+    number[ifactor-1] = factor;
+    for(n=0;n<cnt;n++)
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+    fflush(stdout);
+}
+
+void insert_val(void) {                 /* NB we have already malloced the extra space required */
+    int n;
+    ifactor--;
+    if(ifactor < cnt) {
+        for(n = cnt;n >= ifactor; n--)
+            number[n] = number[n-1];
+    }
+    number[ifactor] = factor;
+    cnt++;
+    for(n=0;n<cnt;n++)
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+    fflush(stdout);
+}
+
+/*************************** QUANTISED_SCATTER *******************************
+ *
+ *      number[0] = quantisation;
+ *      number[1] = duration;
+ *      number[2] = scatter;
+ */
+
+void quantised_scatter(int *perm,int permlen)
+{
+    int n, m, here, k, q_per_step, q_scat, q_hscat, total_q, iscat;
+    double quantisation = number[0], dur = number[1], scat = number[2];
+    total_q = (int)floor(dur/quantisation) + 1;
+    q_per_step = (int)ceil(total_q/(cnt-1));
+    n = 0;
+    number[n++] = 0.0;
+    if(scat <= 1.0)  {
+        q_scat = (int)round(q_per_step * scat);
+        q_hscat = q_scat/2;
+        here = q_per_step;
+        while(n < cnt) {
+            k = (int)floor(drand48() * (double)q_scat) - q_hscat;
+            number[n++] = here + k;
+            here += q_per_step;
+        }
+    } else {
+        iscat = round(scat);
+        q_per_step *= iscat;
+        here = 0;
+        while(n < cnt) {
+            randperm(perm,permlen);                         /* permute the next group of quantisation cells */
+            ascending_sort_cells(perm,iscat);       /* sort the first 'iscat' into ascending order */
+
+            for(m=0;m<iscat;m++)
+                perm[m]++;                                              /*      change range to range 1 to N, rather than 0 to N-1 */
+            for(m=0;m<iscat;m++) {                          /* position items above base-cellcnt */
+                number[n] = here + perm[m];
+                if(++n >= cnt)
+                    break;
+            }
+            here += q_per_step;
+        }
+        free(perm);
+    }
+    for(n=0;n<cnt;n++)
+        number[n] *= quantisation;
+    print_numbers();
+}
+
+/*************************** RANDPERM *******************************
+ *
+ * Produce a random permutation of k integers.
+ */
+
+void randperm(int *perm,int permlen)
+{
+    int n, t;
+    for(n=0;n<permlen;n++) {
+        t = (int)floor(drand48() * (n+1));
+        if(t==n) {
+            hprefix(n,perm,permlen);
+        } else {
+            hinsert(n,t,perm,permlen);
+        }
+    }
+}
+
+void hinsert(int m,int t,int *perm,int permlen)
+{
+    hshuflup(t+1,perm,permlen);
+    perm[t+1] = m;
+}
+
+void hprefix(int m,int *perm,int permlen)
+{
+    hshuflup(0,perm,permlen);
+    perm[0] = m;
+}
+
+void hshuflup(int k,int *perm,int permlen)
+{
+    int n, *i;
+    int z = permlen - 1;
+    i = perm+z;
+    for(n = z;n > k;n--) {
+        *i = *(i-1);
+        i--;
+    }
+}
+
+void ascending_sort_cells(int *perm,int ccnt)
+{
+    int n, m, sct;
+    for(n=0;n<(ccnt-1);n++) {
+        for(m=n+1;m<ccnt;m++) {
+            if(*(perm+m) < *(perm+n)) {
+                sct       = *(perm+m);
+                *(perm+m) = *(perm+n);
+                *(perm+n) = sct;
+            }
+        }
+    }
+}
+
+/************* REPLACING VALUES EQUAL TO > OR < A GIVEN VAL ****************/
+
+void replace_equal(void) {
+    int n;
+    double maxe = number[cnt] + FLTERR;
+    double mine = number[cnt] - FLTERR;
+    double replace = number[cnt+1];
+    for(n=0;n<cnt;n++) {
+        if((number[n] < maxe) && (number[n] > mine))
+            number[n] = replace;
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+    }
+    fflush(stdout);
+}
+
+void replace_less(void) {
+    int n;
+    double mine = number[cnt];
+    double replace = number[cnt+1];
+    for(n=0;n<cnt;n++) {
+        if(number[n] < mine)
+            number[n] = replace;
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+    }
+    fflush(stdout);
+}
+
+void replace_greater(void) {
+    int n;
+    double maxe = number[cnt];
+    double replace = number[cnt+1];
+    for(n=0;n<cnt;n++) {
+        if(number[n] > maxe)
+            number[n] = replace;
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+    }
+    fflush(stdout);
+}
+
+/*************************** GAPPED QUANTISED GRIDS *************************/
+
+void grid(int is_outside)
+{
+    int n, k, tot;
+    double quant = number[cnt], sum, dogrid = 0;
+    if(quant <= .001) {
+        fprintf(stdout,"ERROR: Quantisation step too small.\n");
+        fflush(stdout);
+        return;
+    } else if((tot = (int)ceil(number[cnt-1]/quant)) > 10000) {
+        fprintf(stdout,"ERROR: Quantisation too small, relative to total duration.\n");
+        fflush(stdout);
+        return;
+    } else if(tot < 2) {
+        fprintf(stdout,"ERROR: Quantisation too large, relative to total duration.\n");
+        fflush(stdout);
+        return;
+    }
+    if((permm = (double *)malloc(tot * sizeof(double))) == NULL) {
+        fprintf(stdout,"ERROR: Out of memory.\n");
+        fflush(stdout);
+        return;
+    }
+    if(is_outside)
+        dogrid = 1;
+    n = 0;
+    k = 0;
+    sum = 0.0;
+    while(n < cnt) {
+        if(dogrid) {
+            while(sum < number[n]) {
+                permm[k++] = sum;
+                sum += quant;
+            }
+        } else {
+            while(sum < number[n])
+                sum += quant;
+        }
+        dogrid = !dogrid;
+        n++;
+    }
+    for(n=0;n<k;n++)
+        fprintf(stdout,"INFO: %lf\n",permm[n]);
+    fflush(stdout);
+}
+
+/****** DELETE N VALS AT RANDOM : NOT MORE THAN M ADJACENT VALS DELETED : NOT MORE THAN K ADJACENT VALS UNDELETED ******/
+
+void randdel_not_adjacent(void)
+{
+    int adj, gap, sum, i, j, k, n, z;
+    int delitems, keptitems, keepset_cnt, delset_cnt;
+    int *vacuum, *box, *boxcnt, *box_assocd_with_cntr_no, *cntr_assocd_with_box_no;
+    int remainder, unfilled_boxes, inverted = 0;
+    delitems = round(number[cnt]);  /* number of items to delete */
+    adj     = round(number[cnt+1]);         /* max no of adjacent items to delete */
+    gap     = round(number[cnt+2]);         /* max no of adjacent non-deleted items */
+
+    if(delitems >= cnt) {
+        fprintf(stdout,"ERROR: This will delete the whole column.");
+        fflush(stdout);
+        return;
+    }
+    if(delitems < 1) {
+        fprintf(stdout,"ERROR: Must delete 1 or more items.");
+        fflush(stdout);
+        return;
+    }
+
+
+    if(delitems > cnt/2) {
+        /* Invert the algorithm */
+        inverted = 1;
+        keptitems = delitems;
+        delitems = cnt - keptitems;
+        k = adj;
+        adj = gap;
+        gap = k;
+    } else {
+        keptitems = cnt - delitems;
+    }
+    if((vacuum = (int *)malloc(delitems * sizeof(int)))==NULL) {
+        fprintf(stdout,"ERROR: Out of memory.\n");
+        fflush(stdout);
+        return;
+    }
+    delset_cnt = 0;
+    sum = 0;
+    while(sum < delitems-1) {                               /* generating deletable groups of random sizes */
+        k = (int)floor(drand48()*adj) + 1;      /* within range set by 'adj' */
+        if((sum+k) > delitems-1)                        /* once enough items deleted, break */
+            break;
+        else {
+            vacuum[delset_cnt++] = k;               /* otherwise store the size of deletable group */
+            sum += k;
+        }
+    }
+    if(sum < delitems)                                              /* fix the size of final deletable group, to make deleted total correct */
+        vacuum[delset_cnt++] = delitems - sum;
+
+    if((vacuum = (int *)realloc((char *)vacuum,delset_cnt * sizeof(int)))==NULL) {
+        fprintf(stdout,"ERROR: Memory reallocation error.\n");
+        fflush(stdout);
+        return;
+    }
+
+    if(delset_cnt > keptitems) {                    /* must be as many kept items as deleted groups, to separate those groups */
+        fprintf(stdout,"ERROR: Not enough undeleted items remaining to complete the task.\n");
+        fflush(stdout);
+        return;
+    } else if(delset_cnt == keptitems) {    /* exactly as many keptitems as deleted groups, they must alternate */
+        j = 0;
+        n = 0;
+        i = (int)floor(drand48() * 2.0);        /* select at random whether to start with deletes or not */
+        if(inverted) {
+            if(i) {                                                         /* and either ... */
+                while(j < delset_cnt) {
+                    for(k=0;k<vacuum[j];k++) {      /* print x items */
+                        fprintf(stdout,"INFO: %lf\n",number[n]);
+                        if(++n > cnt) {
+                            fprintf(stdout,"ERROR: Program anomaly in counting data. 6\n");
+                            break;
+                        }
+                    }                                                       /* then skip 1 */
+                    if(++n > cnt) {
+                        fprintf(stdout,"ERROR: Program anomaly in counting data. 7\n");
+                        break;
+                    }
+                    j++;
+                }
+                fflush(stdout);
+                return;
+            } else {                                                        /* or .... */
+                while(j < delset_cnt) {                 /* skip 1 */
+                    if(++n > cnt) {
+                        fprintf(stdout,"ERROR: Program anomaly in counting data. 8\n");
+                        break;
+                    }
+                    for(k=0;k<vacuum[j];k++) {      /* then print x items */
+                        fprintf(stdout,"INFO: %lf\n",number[n]);
+                        if(++n > cnt) {
+                            fprintf(stdout,"ERROR: Program anomaly in counting data. 9\n");
+                            break;
+                        }
+                    }
+                    j++;
+                }
+                fflush(stdout);
+                return;
+            }
+        } else {
+            if(i) {                                                         /* and either ... */
+                while(j < delset_cnt) {
+                    for(k=0;k<vacuum[j];k++) {      /* skip x items */
+                        if(++n > cnt) {
+                            fprintf(stdout,"ERROR: Program anomaly in counting data. 10\n");
+                            break;
+                        }
+                    }                                                       /* then print 1 */
+                    fprintf(stdout,"INFO: %lf\n",number[n]);
+                    if(++n > cnt) {
+                        fprintf(stdout,"ERROR: Program anomaly in counting data. 11\n");
+                        break;
+                    }
+                    j++;
+                }
+                fflush(stdout);
+                return;
+            } else {                                                        /* or .... */
+                while(j < delset_cnt) {                 /* print 1 */
+                    fprintf(stdout,"INFO: %lf\n",number[n]);
+                    if(++n > cnt) {
+                        fprintf(stdout,"ERROR: Program anomaly in counting data. 12\n");
+                        break;
+                    }
+                    for(k=0;k<vacuum[j];k++) {      /* then skip x items */
+                        if(++n > cnt) {
+                            fprintf(stdout,"ERROR: Program anomaly in counting data. 13\n");
+                            break;
+                        }
+                    }
+                    j++;
+                }
+                fflush(stdout);
+                return;
+            }
+        }
+    }
+    keepset_cnt = delset_cnt+1;                             /* otherwise, let there be 1 more sets of kept items then of deleted items */
+    /* This is an aesthetic, choice.. there could be an equal number */
+    if(( k = (int)ceil((double)keptitems/(double)keepset_cnt)) > gap) {
+        gap = k + 1;                                            /* if min-size of largest kept group is > gap, can't use gap value */
+        fprintf(stdout,"ERROR: Intergap distance incompatible with other demands. Adjusting to %d.\n",gap);
+        fflush(stdout);
+    }
+    if(((box         = (int *)malloc(keepset_cnt * sizeof(int)))==NULL)
+       || ((boxcnt      = (int *)malloc(keepset_cnt * sizeof(int)))==NULL)
+       || ((box_assocd_with_cntr_no = (int *)malloc(keepset_cnt * sizeof(int)))==NULL)
+       || ((cntr_assocd_with_box_no = (int *)malloc(keepset_cnt * sizeof(int)))==NULL)) {
+        fprintf(stdout,"ERROR: Out of memory.\n");
+        fflush(stdout);
+        return;
+    }
+    for(n=0;n<keepset_cnt;n++) {                                    /* regard each set of kept items as a box */
+        box_assocd_with_cntr_no[n] = n;                         /* link each ball-counter to each box */
+        cntr_assocd_with_box_no[n] = n;                         /* link each box to each ball-counter */
+        box[n] = 1;                                                             /* Put 1 ball in each box: every kept set must have at least 1 item */
+        boxcnt[n] = 0;                                                          /* preset the boxcnts to zero */
+    }
+    if((remainder = keptitems - keepset_cnt) > 0) { /* if any leftover balls */
+        unfilled_boxes = keepset_cnt;                           /* set number of unfilled boxes */
+        for(n=0;n<remainder;n++) {                                      /* for all remaining balls */
+            z = (int)floor(drand48() * unfilled_boxes);
+            box[z]++;                                                               /* distribute each ball to a random box */
+
+            if(box[z] >= gap) {                                                                     /* if the box getting the ball is now full */
+                boxcnt[cntr_assocd_with_box_no[z]] = box[z];    /* store the count of balls in the box */
+                unfilled_boxes--;                                                               /* reduce number of boxes to put random balls into */
+                while(z < unfilled_boxes) {
+                    box[z] = box[z+1];                                      /* eliminate full box, by shuffling boxes above downwards */
+                    k = cntr_assocd_with_box_no[z+1];       /* get the boxcnter associated with the next box */
+                    box_assocd_with_cntr_no[k]--;           /* force it to point to next lower box (as boxes have moved down 1) */
+                    j = box_assocd_with_cntr_no[k];         /* get the box it now points to */
+                    cntr_assocd_with_box_no[j] = k;         /* get that to point back to the box counter */
+                    z++;
+                }
+            }
+        }
+    }
+    for(n=0;n<keepset_cnt;n++) {                                            /* save counts of balls in remaining boxes */
+        if(boxcnt[n] <= 0)
+            boxcnt[n] = box[box_assocd_with_cntr_no[n]];
+    }
+    j = 0;
+    n = 0;
+    if(inverted) {
+        while(j < delset_cnt) {
+            for(k=0;k<boxcnt[j];k++) {                                              /* skip x items */
+                if(++n > cnt) {
+                    fprintf(stdout,"ERROR: Program anomaly in counting data 4.\n");
+                    return;
+                }
+            }
+            for(k=0;k<vacuum[j];k++) {                                              /* print y items */
+                fprintf(stdout,"INFO: %lf\n",number[n]);
+                if(++n > cnt) {
+                    fprintf(stdout,"ERROR: Program anomaly in counting data 5.\n");
+                    return;
+                }
+            }          /* Note, all inverted patterns start and end with OFF events - an aesthetic decision */
+            j++;
+        }
+    } else {
+        while(j < delset_cnt) {
+            for(k=0;k<boxcnt[j];k++) {                                              /* print x items */
+                fprintf(stdout,"INFO: %lf\n",number[n]);
+                if(++n > cnt) {
+                    fprintf(stdout,"ERROR: Program anomaly in counting data 1.\n");
+                    return;
+                }
+            }
+            for(k=0;k<vacuum[j];k++) {                                              /* skip y items */
+                if(++n > cnt) {
+                    fprintf(stdout,"ERROR: Program anomaly in counting data 2.\n");
+                    return;
+                }
+            }
+            j++;
+        }
+        for(k=0;k<boxcnt[j];k++) {                                                      /* print last x items */
+            fprintf(stdout,"INFO: %lf\n",number[n]);
+            if(++n > cnt) {
+                fprintf(stdout,"ERROR: Program anomaly in counting data 3.\n");
+                break;
+            }                       /* Note, all patterns start and end with ON events - an aesthetic decision */
+        }
+    }
+    fflush(stdout);
+}
+
+/****************************** REPLACE_WITH_RAND ******************************/
+
+void replace_with_rand(int type) {
+
+    int n;
+    double lim = number[cnt], randlo = number[cnt+1], randhi = number[cnt+2];
+    double k, randrang, limhi, limlo;
+
+    if(randhi < randlo) {
+        k          = randhi;
+        randhi = randlo;
+        randlo = k;
+    }
+    randrang = randhi - randlo;
+    switch(type) {
+    case(0):                        /* equal */
+        limhi = lim + FLTERR;
+        limlo = lim - FLTERR;
+        for(n=0;n<cnt;n++) {
+            if((number[n] < limhi) && (number[n] > limlo))
+                number[n] = (drand48() * randrang) + randlo;
+            fprintf(stdout,"INFO: %lf\n",number[n]);
+        }
+        break;
+    case(-1):                       /* less */
+        for(n=0;n<cnt;n++) {
+            if(number[n] < lim)
+                number[n] = (drand48() * randrang) + randlo;
+            fprintf(stdout,"INFO: %lf\n",number[n]);
+        }
+        break;
+    case(1):                        /* greater */
+        for(n=0;n<cnt;n++) {
+            if(number[n] > lim)
+                number[n] = (drand48() * randrang) + randlo;
+            fprintf(stdout,"INFO: %lf\n",number[n]);
+        }
+        break;
+    }
+    fflush(stdout);
+}
+
+/****************************** RANDQUANTA_IN_GAPS ******************************/
+
+void randquanta_in_gaps(void)
+{
+    int totcnt = round(number[cnt]);                                                                        /* number of vals to make */
+    double q = number[cnt+1];                                                                                       /* quantisation of grid */
+    int mincnt = round(number[cnt+2]), maxcnt = round(number[cnt+3]);       /* min & max no of events in each time-interval */
+    int k,j,n,m, posibmax = 0, maxqpnts = 0, tot_boxes,minpos,maxpos,remainder,unfilled_boxes;
+    int boxpos, orig_boxpos;
+    int *perm,*box,*boxcnt,*qpnts,*box_assocd_with_cntr_no,*cntr_assocd_with_box_no;
+    double mintim,maxtim;
+    double *qbas;
+
+    if(maxcnt < mincnt) {   /* orient cnt-range */
+        n = maxcnt;
+        maxcnt = mincnt;
+        mincnt = n;
+    }
+    if(mincnt < 1) {
+        fprintf(stdout,"ERROR: Invalid count of number of items (%d)\n",mincnt);
+        fflush(stdout);
+        exit(1);
+    }
+    if(cnt & 1)                             /* Force even number of pairs */
+        cnt--;
+
+    if((tot_boxes = cnt/2) < 1) {
+        fprintf(stdout,"Too few value pairs in input column.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    if(totcnt < tot_boxes * mincnt) {
+        fprintf(stdout,"Insufficient items to distribute amongst the %d pairs.\n",tot_boxes);
+        fflush(stdout);
+        exit(1);
+    }
+    if(((box        = (int *)malloc(tot_boxes * sizeof(int)))==NULL)                /* 'boxes' store random placed 'balls' */
+       || ((boxcnt     = (int *)malloc(tot_boxes * sizeof(int)))==NULL)                /* counts of balls in 'boxes' */
+       || ((qpnts      = (int *)malloc(tot_boxes * sizeof(int)))==NULL)                /* no. of q-points in each time-interval */
+       /* = maximum number of balls for each box */
+       || ((qbas       = (double *)malloc(tot_boxes * sizeof(double)))==NULL)  /* first q-point time in each time-interval */
+       || ((box_assocd_with_cntr_no = (int *)malloc(tot_boxes * sizeof(int)))==NULL)
+       || ((cntr_assocd_with_box_no = (int *)malloc(tot_boxes * sizeof(int)))==NULL)) {
+        fprintf(stdout,"Out of memory.\n");                                                             /* because boxes are 'deleted' & shuffled down */
+        fflush(stdout);
+        exit(1);
+    }
+    for(n=0, m =0; n < cnt; n += 2,m++) {
+        mintim = number[n];
+        maxtim = number[n+1];
+
+        minpos = (int)floor(mintim/q);
+        if(((double)minpos * q) < mintim)
+            minpos++;
+        maxpos = (int)floor(maxtim/q);
+
+        qpnts[m] = maxpos - minpos + 1;
+        if(qpnts[m] < mincnt) {
+            fprintf(stdout,"ERROR: timegap between %lf and %lf will not take  %d items\n",number[n],number[n+1],mincnt);
+            fflush(stdout);
+            exit(1);
+        }
+        if(m == 0)      maxqpnts = qpnts[0];
+        else            maxqpnts = max(maxqpnts,qpnts[m]);
+
+        qbas[m]  = minpos * q;
+        posibmax += min(qpnts[m],maxcnt);
+    }
+    if(posibmax < totcnt) {
+        fprintf(stdout, "ERROR: total count of items exceeds available spaces.\n");
+        fflush(stdout);
+        exit(1);
+    }
+
+    if((perm = (int *)malloc(maxqpnts * sizeof(int)))==NULL) {
+        fprintf(stdout,"Out of memory.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    remainder = totcnt;
+
+    /* DISTRIBUTE THE REMAINING ITEMS AT RANDOM (with constraints) BETWEEN THE boxcnt BOXES */
+
+    for(n=0;n<tot_boxes;n++) {                                                      /* regard each set of kept items as a box */
+        box_assocd_with_cntr_no[n] = n;                                 /* link each ball-counter to each box */
+        cntr_assocd_with_box_no[n] = n;                                 /* link each box to each ball-counter */
+        box[n] = mincnt;                                                                /* Put min no of balls in each box */
+        remainder -= mincnt;
+        boxcnt[n] = 0;                                                                  /* preset the boxcnts to zero */
+    }
+    if(remainder > 0) {                                                                     /* if any leftover balls */
+
+        /* ELIMINATE ANY BOXES WHICH ARE ALREADY FULL */
+        unfilled_boxes = tot_boxes;                                             /* set number of unfilled boxes as total no of boxes */
+        boxpos = 0;
+        for(n=0,m=0;n<tot_boxes;n++) {                                  /* for all boxes */
+            if(box[boxpos] >= qpnts[n]) {                           /* if the box is already full */
+                boxcnt[n] = box[boxpos];                                /* store the count of balls that are in the box */
+                unfilled_boxes--;                                               /* reduce number of boxes to put random balls into */
+                orig_boxpos = boxpos;                                   /* save the position of the full-box which is being eliminated */
+                while(boxpos < unfilled_boxes) {
+                    box[boxpos] = box[boxpos+1];            /* eliminate full box, by shuffling boxes above downwards */
+                    k = cntr_assocd_with_box_no[boxpos+1];  /* get the boxcnter associated with the next box */
+                    box_assocd_with_cntr_no[k]--;           /* force it to point to next lower box (as boxes have moved down 1) */
+                    j = box_assocd_with_cntr_no[k];         /* get the box it now points to */
+                    cntr_assocd_with_box_no[j] = k;         /* get that to point back to the box counter */
+                    boxpos++;
+                }
+                boxpos = orig_boxpos;                                   /* reset box position to where it was: now points to new box */
+            } else {
+                boxpos++;                                                               /* if box getting ball is NOT full, go on to next box */
+            }
+        }
+        /* DISTRIBUTE REMAINING BALLS */
+        for(n=0;n<remainder;n++) {                                      /* for all remaining balls */
+            boxpos = (int)floor(drand48() * unfilled_boxes);
+            box[boxpos]++;                                                          /* distribute each ball to a random box */
+            k = cntr_assocd_with_box_no[boxpos];
+            if(box[boxpos] >= qpnts[k]) {                           /* if the box getting the ball is now full */
+                boxcnt[k] = box[boxpos];                                /* store the count of balls that are in the box */
+                unfilled_boxes--;                                               /* reduce number of boxes to put random balls into */
+                while(boxpos < unfilled_boxes) {
+                    box[boxpos] = box[boxpos+1];            /* eliminate full box, by shuffling boxes above downwards */
+                    k = cntr_assocd_with_box_no[boxpos+1];  /* get the boxcnter associated with the next box */
+                    box_assocd_with_cntr_no[k]--;           /* force it to point to next lower box (as boxes have moved down 1) */
+                    j = box_assocd_with_cntr_no[k];         /* get the box it now points to */
+                    cntr_assocd_with_box_no[j] = k;         /* get that to point back to the box counter */
+                    boxpos++;
+                }
+            }
+        }
+    }
+    for(n=0;n<tot_boxes;n++) {                                                      /* save counts of balls in remaining boxes */
+        if(boxcnt[n] <= 0)
+            boxcnt[n] = box[box_assocd_with_cntr_no[n]];
+    }
+    /* DISTRIBUTE THE VALS AT RANDOM WITHIN THE BOXES */
+
+    for(n=0;n<tot_boxes;n++) {
+        randperm(perm,qpnts[n]);                                                /* permute the current group of quantisation cells */
+        ascending_sort_cells(perm,boxcnt[n]);                   /* sort the first 'boxcnt' of the perm, into ascending order */
+
+        for(m=0;m<boxcnt[n];m++)                                                /* for each random value, multiply it by quantisation val */
+            fprintf(stdout,"INFO: %lf\n",qbas[n] + (perm[m] * q));
+    }                                                                                                       /* & add to to 1st quantised position in current time-interval */
+    fflush(stdout);
+}
+
+/****************************** INVERT_NORMD_ENV ******************************/
+
+void invert_normd_env(void)
+{
+    invertenv(1.0);
+}
+
+/****************************** INVERT_AROUND_PIVOT ******************************/
+
+void invert_around_pivot(void)
+{
+    invertenv(number[cnt] * 2.0);
+}
+
+/****************************** INVERT_OVER_RANGE ******************************/
+
+void invert_over_range(void)
+{
+    invertenv(number[cnt] + number[cnt+1]);
+}
+
+/****************************** ENV_SUPERIMPOS ******************************/
+
+void env_superimpos(int inverse,int typ)        /* PRODUCT SHOULD INVOLVE LOGS !! */
+{
+    double *out, *no1, *no2, tdiff, tratio, vdiff, vhere;
+    int n, m, j, cnt2, skipped;
+    double thisnval, thismval, lastnval, lastmval, time = 0.0, lastval = 0.0;
+
+    if((out = (double *)malloc((cnt * 2) * sizeof(double)))==NULL) {
+        fprintf(stdout,"ERROR: Out of memory.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    if(factor != 0.0) {                                     /* if inserted after time zero, move it to start time */
+        for(n=firstcnt;n<cnt;n+=2)
+            number[n] += factor;
+    }
+    if(inverse) {                                   /* If working with inverse of env, invert it */
+        for(n=firstcnt+1;n<cnt;n+=2)
+            number[n] = 1.0 - number[n];
+    }
+    if(number[firstcnt] < number[0]) {
+        no1  = &(number[firstcnt]);     /* If inserted env starts BEFORE orig env, 'invert' process */
+        no2  = number;
+        cnt  = cnt - firstcnt;                  /* establish independent counters for each infile */
+        cnt2 = firstcnt;
+    } else {
+        no1  = number;
+        no2  = &(number[firstcnt]);
+        cnt2 = cnt - firstcnt;                  /* establish independent counters for each infile */
+        cnt  = firstcnt;
+    }
+    n = 0;
+    m = 0;
+    j = 0;
+    thisnval = 0.0;
+    thismval = 0.0;
+    while(no1[n] < no2[0]) {
+        out[j++] = no1[n++];
+        thisnval = no1[n];
+        thismval = no2[1];
+        switch(typ) {
+        case(MULT):             out[j++] = no1[n++] * no2[1];   break;
+        case(ADD):              out[j++] = no1[n++] + no2[1];   break;
+        case(SUBTRACT): out[j++] = no1[n++] - no2[1];   break;
+        case(ENVMAX):
+            out[j++] = max(no1[n],no2[1]);
+            n++;
+            break;
+        }
+        if(n >= cnt)
+            break;
+    }
+    while(n < cnt) {
+        if(no1[n] == no2[m]) {          /* brkpnts coincide */
+            out[j++] = no1[n++];
+            m++;                                    /* new brkpnt val is product of origs */
+            lastnval = thisnval;
+            lastmval = thismval;
+            thisnval = no1[n];
+            thismval = no2[m];
+            switch(typ) {
+            case(MULT):             out[j++] = no1[n++] * no2[m++]; break;
+            case(ADD):              out[j++] = no1[n++] + no2[m++]; break;
+            case(SUBTRACT): out[j++] = no1[n++] - no2[m++]; break;
+            case(ENVMAX):
+                out[j++] = max(no1[n],no2[m]);
+                n++;
+                m++;
+                break;
+            }
+            if(m >= cnt2)                   /* If at end of inserted env, break from loop */
+                break;
+        } else if(no1[n] > no2[m]) {    /* inserted brkpnt falls before next orig-brkpnt */
+            while(no1[n] > no2[m]) {
+                time = no2[m];          /* take time from inserted brkpnt */
+                tdiff = no1[n] - no1[n-2];
+                tratio = (no2[m++] - no1[n-2])/tdiff;
+                n++;
+                vdiff = no1[n] - no1[n-2];
+                vhere = (vdiff * tratio) + no1[n-2];    /* value of orig brkpnt, at this time */
+                lastnval = thisnval;
+                lastmval = thismval;
+                thisnval = vhere;
+                thismval = no2[m];
+                docross(lastnval,lastmval,thisnval,thismval,time,&j,out,typ);
+                out[j++] = time;
+                switch(typ) {
+                case(MULT):             out[j++] = vhere * no2[m++];    break;
+                case(ADD):              out[j++] = vhere + no2[m++];    break;
+                case(SUBTRACT): out[j++] = vhere - no2[m++];    break;
+                case(ENVMAX):
+                    out[j++] = max(vhere,no2[m]);
+                    m++;
+                    break;
+                }
+                n--;                            /* remain at same point in orig-brkfile */
+                if(m >= cnt2)
+                    break;                  /* If at end of inserted env, break from loop */
+            }
+        } else {                                        /* orig-brkpnt falls before next inserted brkpnt */
+            while(no2[m] > no1[n]) {
+                time = no1[n];          /* take time from orig brkpnt */
+                tdiff = no2[m] - no2[m-2];
+                tratio = (no1[n++] - no2[m-2])/tdiff;
+                m++;
+                vdiff = no2[m] - no2[m-2];
+                vhere = (vdiff * tratio) + no2[m-2];    /* value of inserted brkpnt, at this time */
+                lastnval = thisnval;
+                lastmval = thismval;
+                thismval = vhere;
+                thisnval = no1[n];
+                docross(lastnval,lastmval,thisnval,thismval,time,&j,out,typ);
+                out[j++] = time;
+                switch(typ) {
+                case(MULT):             out[j++] = vhere * no1[n++];    break;
+                case(ADD):              out[j++] = vhere + no1[n++];    break;
+                case(SUBTRACT): out[j++] = vhere - no1[n++];    break;
+                case(ENVMAX):
+                    out[j++] = max(vhere,no1[n]);
+                    n++;
+                    break;
+                }
+                m--;                            /* remain at same point in inserted-brkfile */
+                if(n >= cnt) {          /* if it at end of orig file */
+                    while(m < cnt2) {         /* calc remaining inserted file points */
+                        out[j++] = no2[m++];
+                        switch(typ) {
+                        case(MULT):             out[j++] = no2[m++] * no1[cnt-1];       break;
+                        case(ADD):              out[j++] = no2[m++] + no1[cnt-1];       break;
+                        case(SUBTRACT): out[j++] = no2[m++] - no1[cnt-1];       break;
+                        case(ENVMAX):
+                            out[j++] = max(no2[m],no1[cnt-1]);
+                            m++;
+                            break;
+                        }
+                    }
+                    break;                  /* and break from loop */
+                }
+            }
+        }
+        if(m >= cnt2)
+            break;                                  /* If at end of inserted env, break from outer loop */
+    }
+    /* on leaving loop either m > cnt2 or n > cnt */
+
+    while (n < cnt) {                               /* if orig brkfile extends beyond inserted file */
+        out[j++] = no1[n++];            /* calculate remaining points */
+        switch(typ) {
+        case(MULT):             out[j++] = no1[n++] * no2[cnt2 - 1];    break;
+        case(ADD):              out[j++] = no1[n++] + no2[cnt2 - 1];    break;
+        case(SUBTRACT): out[j++] = no1[n++] - no2[cnt2 - 1];    break;
+        case(ENVMAX):
+            out[j++] = max(no1[n],no2[cnt2 - 1]);
+            n++;
+            break;
+        }
+    }
+    while (m < cnt2) {                              /* if inserted brkfile extends beyond orig file */
+        out[j++] = no2[m++];            /* calculate remaining points */
+        switch(typ) {
+        case(MULT):             out[j++] = no2[m++] * no1[cnt - 1];     break;
+        case(ADD):              out[j++] = no2[m++] + no1[cnt - 1];     break;
+        case(SUBTRACT): out[j++] = no2[m++] - no1[cnt - 1];     break;
+        case(ENVMAX):
+            out[j++] = max(no2[m],no1[cnt - 1]);
+            m++;
+            break;
+        }
+    }
+    fprintf(stdout,"INFO: %lf  %lf\n",out[0],out[1]);
+    skipped = 0;
+    for(n=2;n<j-2;n += 2) {
+        if(!flteq(out[n-1],out[n+1])) {         /* elementary datareduce */
+            if(skipped)
+                fprintf(stdout,"INFO: %lf  %lf\n",time,lastval);
+            fprintf(stdout,"INFO: %lf  %lf\n",out[n],out[n+1]);
+            skipped = 0;
+        } else {
+            skipped = 1;
+            time    = out[n];
+            lastval = out[n+1];
+        }
+    }
+    fprintf(stdout,"INFO: %lf  %lf\n",out[n],out[n+1]);
+    fflush(stdout);
+}
+
+/****************************** DOCROSS ******************************/
+
+void docross(double lastnval,double lastmval,double thisnval, double thismval,double time,int *j,double *out,int typ)
+{
+    int prehi = 0, posthi = 0;
+    double lasttime, timediff, timecross, valcross, gradn, gradm;
+    if(lastnval > lastmval)
+        prehi = 1;
+    else if(lastnval < lastmval)
+        prehi = -1;
+    if(thisnval > thismval)
+        posthi = 1;
+    else if(thisnval < thismval)
+        posthi = -1;
+    if(prehi && posthi && (prehi != posthi)) {      /* curves intersect */
+        lasttime = out[*(j)-2];
+        timediff = time - lasttime;
+        if(flteq(timediff,0.0)) {
+            fprintf(stdout,"ERROR: Came across time step too small to calculate.\n");
+            fflush(stdout);
+            exit(1);
+        }
+        gradn = (thisnval - lastnval)/timediff;
+        gradm = (thismval - lastmval)/timediff;
+        if(flteq(gradn,gradm)) {
+            fprintf(stdout,"ERROR: possible error in curve crossing algorithm.\n");
+            fflush(stdout);
+            exit(1);
+        }
+        timecross = (lastmval - lastnval)/(gradn - gradm);
+        valcross = (gradn * timecross) + lastnval;
+        out[(*j)++] = timecross + lasttime;
+        switch(typ) {
+        case(MULT):             out[(*j)++] = (valcross * valcross);    break;
+        case(ADD):              out[(*j)++] = (valcross + valcross);    break;
+        case(SUBTRACT): out[(*j)++] = 0.0;                                              break;
+        case(ENVMAX):   out[(*j)++] = valcross;                                 break;
+        }
+    }
+}
+
+/****************************** ENV_DEL_INV ******************************/
+
+void env_del_inv(void)
+{
+    int n, m;
+    cnt += 2;
+    if((number = (double *)realloc((char *)number,cnt * sizeof(double)))==NULL) {
+        fprintf(stdout,"ERROR: Out of memory.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    m = cnt - 1;
+    n = cnt - 3;
+    while(n > 0) {
+        number[m--] = 1.0 - number[n--];                /* inverse */
+        number[m--]     = number[n--] + factor;         /* delay */
+    }
+    number[1] = number[3];                                          /* extend initial val.. */
+    number[0] = 0.0;                                                        /* ...back to zero time */
+    for(n=0;n<cnt;n+=2)
+        fprintf(stdout,"INFO: %lf  %lf\n",number[n],number[n+1]);
+    fflush(stdout);
+}
+
+/****************************** ENV_DEL_INV ******************************/
+
+void env_plateau(void)
+{
+    double plateau;
+    int n;
+    n = ifactor;
+    n--;                                    /* get true line number */
+    n *= 2;                                 /* get brkpnt pair */
+    n++;                                    /* get val in brkpnt pair */
+    plateau = number[n];    /* get plateau val */
+    n -= 2;
+    number[n] = plateau;    /* put plateau val in previous val*/
+    n--;
+    number[n] = 0.0;                /* set time here to zero */
+    while(n < cnt) {
+        fprintf(stdout,"INFO: %lf  %lf\n",number[n],number[n+1]);
+        n += 2;
+    }
+    fflush(stdout);
+}
+
+/****************************** TIME_FROM_BEAT_POSITION ******************************/
+
+void time_from_beat_position(int has_offset)
+{
+    int n;
+    double k;
+    if(factor <= FLTERR) {
+        fprintf(stdout,"ERROR: Beat duration is less than or equal to zero.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    if(has_offset && !condit) {
+        fprintf(stdout,"ERROR: No time offset given.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    for(n=0;n< cnt;n++) {
+        if((k = number[n] - 1.0) < 0.0) {
+            fprintf(stdout,"ERROR: Position of beat %d is less than 1. Impossible.\n",n+1);
+            fflush(stdout);
+            exit(1);
+        }
+        number[n] = k * factor;
+        if(has_offset)
+            number[n] += thresh;
+    }
+    for(n=0;n< cnt;n++)
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+    fflush(stdout);
+}
+
+/****************************** INSERT_AFTER_VAL ******************************/
+
+void insert_after_val(void)
+{
+    int n, m, has_started = 0;
+    for(n=0;n<cnt;n++) {
+        if (!has_started) {
+            if(number[n] == number[cnt]) {
+                for(m=0;m <= n; m++)
+                    fprintf(stdout,"INFO: %lf\n",number[m]);
+                fprintf(stdout,"INFO: %lf\n",number[cnt+1]);
+                has_started = 1;
+            }
+        } else {
+            fprintf(stdout,"INFO: %lf\n",number[n]);
+        }
+    }
+    if(!has_started) {
+        fprintf(stdout,"ERROR: Value %lf not found in the table.\n",number[cnt]);
+        fflush(stdout);
+        exit(1);
+    }
+    fflush(stdout);
+}
+
+/****************************** MIN_INTERVAL ******************************/
+
+void min_interval(int ismax) {
+    int n, pos;
+    double min_int, max_int, this_int;
+    if(cnt < 2) {
+        fprintf(stdout,"ERROR: Too few values to run this process.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    pos = 1;
+    if (ismax) {
+        max_int = number[1] - number[0];
+        for(n=2;n<cnt;n++) {
+            if((this_int = number[n] - number[n-1]) > max_int) {
+                max_int = this_int;
+                pos = n;
+            }
+        }
+        fprintf(stdout,"WARNING: Maximum interval is %lf between entries %d and %d.\n",max_int,pos,pos+1);
+        fflush(stdout);
+    } else {
+        min_int = number[1] - number[0];
+        for(n=2;n<cnt;n++) {
+            if((this_int = number[n] - number[n-1]) < min_int) {
+                min_int = this_int;
+                pos = n;
+            }
+        }
+        fprintf(stdout,"WARNING: Minimum interval is %lf between entries %d and %d.\n",min_int,pos,pos+1);
+        fflush(stdout);
+    }
+}
+
+/****************************** INSERT_IN_ORDER ******************************/
+
+void insert_in_order(void) {
+    int n, pos = -1;
+    for(n=0;n<cnt-1;n++) {
+        if(number[n+1] <= number[n]) {
+            fprintf(stdout,"ERROR: column not in ascending order.\n");
+            fflush(stdout);
+            exit(1);
+        }
+        if ((pos < 0) && (number[cnt] <= number[n])) {  /* position not found & new number goes here */
+            pos = n;
+        }
+    }
+    if ((pos < 0) && (number[cnt] <= number[n])) {  /* position not found & new number goes here */
+        pos = n;
+    }
+    if(pos < 0)                     /* new number larger than all in column, goes at end */
+        pos = cnt;
+    if(pos > 0) {                   /* if new number not at start of column */
+        for(n=0;n<pos;n++)
+            fprintf(stdout,"INFO: %lf\n",number[n]);
+    }                                               /* insert new number */
+    fprintf(stdout,"INFO: %lf\n",number[cnt]);
+    if(pos < cnt) {                 /* if new mumber not at end of column */
+        for(n=pos;n<cnt;n++)
+            fprintf(stdout,"INFO: %lf\n",number[n]);
+    }
+    fflush(stdout);
+}
+
+/****************************** INSERT_AT_START ******************************/
+
+void insert_at_start(void) {
+    int n;
+    fprintf(stdout,"INFO: %lf\n",number[cnt]);
+    for(n=0;n<cnt;n++)
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+    fflush(stdout);
+}
+
+/****************************** INSERT_AT_END ******************************/
+
+void insert_at_end(void) {
+    int n;
+    for(n=0;n<=cnt;n++)
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+    fflush(stdout);
+}
+
+/****************************** FORMAT_STRS ****************************/
+
+void format_strs(void)
+{
+    int n, m, OK = 1;
+    double d = (double)stringscnt/(double)ifactor;
+    int rowcnt = stringscnt/ifactor;
+    char temp[64];
+    errstr[0] = ENDOFSTR;
+    if(d > (double)rowcnt)
+        rowcnt++;
+    for(n=0;n<stringscnt;n+=rowcnt) {
+        for(m=0;m<rowcnt;m++) {
+            if(n!=0 && m==0) {
+                fprintf(stdout,"INFO: %s\n",errstr);
+                errstr[0] = ENDOFSTR;
+            }
+            if(n+m < stringscnt) {
+                sprintf(temp,"%s ",strings[n+m]);
+                strcat(errstr,temp);
+            } else
+                OK = 0;
+        }
+        if(!OK)
+            break;
+    }
+    fprintf(stdout,"INFO: %s\n",errstr);
+    fflush(stdout);
+}
+
+
+/****************************** COLUMN_FORMAT_STRS ****************************/
+
+void column_format_strs(void)
+{       int n, m;
+
+    double d = (double)stringscnt/(double)ifactor;
+    int rowcnt = stringscnt/ifactor;
+    char temp[64];
+    errstr[0] = ENDOFSTR;
+    if(d > (double)rowcnt)
+        rowcnt++;
+    for(n=0;n<rowcnt;n++) {
+        for(m=n;m<stringscnt;m+=rowcnt) {
+            sprintf(temp,"%s ",strings[m]);
+            strcat(errstr,temp);
+        }
+        fprintf(stdout,"INFO: %s\n",errstr);
+        errstr[0] = ENDOFSTR;
+    }
+    fflush(stdout);
+}
+
+/****************************** RANDOM_INTEGERS ****************************/
+
+void random_integers(void)
+{
+    int n, i, j = round(number[1]);
+    int range = abs(j - 1) + 1;
+    int rangbot = (int)min(j,1);
+    ifactor = round(number[0]);
+
+    for(n=0;n<ifactor;n++) {
+        i = (int)floor(drand48() * range) + rangbot;
+        fprintf(stdout,"INFO: %d\n",i);
+    }
+    fflush(stdout);
+}
+
+/****************************** RANDOM_INTEGERS_EVENLY_SPREAD ****************************/
+
+void random_integers_evenly_spread(void)
+{
+    int z, n, m, i, k, j, repets;
+    int range, rangbot, arrsiz, endcnt, endval, allowed, checkpart;
+    int *arr, *arr2, *perm;
+
+    repets = round(number[2]);
+    j = round(number[1]);
+    range = abs(j - 1) + 1;
+    rangbot = (int)min(j,1);
+    arrsiz = range * repets;
+    ifactor = round(number[0]);
+
+    if((arr = (int *)malloc(arrsiz * sizeof(int)))==NULL) {
+        fprintf(stdout,"ERROR: Out of memory.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    if((perm = (int *)malloc(arrsiz * sizeof(int)))==NULL) {
+        fprintf(stdout,"ERROR: Out of memory.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    if((arr2 = (int *)malloc(repets * sizeof(int)))==NULL) {
+        fprintf(stdout,"ERROR: Out of memory.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    n = 0;
+    for(j=0;j<repets;j++) {                                 /* fill array with REPET copies of values */
+        z = rangbot;
+        for(i=0;i<range;i++)
+            arr[n++] = z++;
+    }
+    endcnt = 0;                                                             /* number of items repeated at end of previous perm */
+    endval = 1;                                                             /* value (possibly repeated) at end of previous perm */
+    allowed = -1;                                                   /* number of permissible repetitions of this val at start of NEW perm */
+    checkpart = arrsiz - repets;                    /* items at end of array to test for repetitions */
+    n = 0;
+    while(n < ifactor) {
+        do_repet_restricted_perm(arr,perm,arrsiz,allowed,endval);
+        j = 0;
+        for(m = 0;m <arrsiz;m++,n++) {
+            if(n >= ifactor)
+                break;
+            k = arr[perm[m]];
+            fprintf(stdout,"INFO: %d\n",k);
+            if(m >= checkpart)                              /* save last checkable stretch of perm */
+                arr2[j++] = k;
+        }
+        fflush(stdout);
+        if(n >= ifactor)
+            break;
+        j--;
+        endval = arr2[j--];                                     /* note the val at end of perm */
+        endcnt = 1;                                                     /* and count it */
+        for(k = j; k>= 0; k--) {
+            if(arr2[k] == endval)                   /* check adjacent vals, for repetition of value: count */
+                endcnt++;
+            else                                                    /* if no more repetitions, finish counting */
+                break;
+        }
+        allowed = repets - endcnt;                      /* get number of permissible repets at start of next perm */
+    }
+}
+
+/****************************** DO_REPET_RESTRICTED_PERM ****************************/
+
+void do_repet_restricted_perm(int *arr, int *perm, int arrsiz, int allowed, int endval)
+{
+    int n, t;
+    int checklen = allowed + 1;
+    int done = 0;
+    while(!done) {
+        for(n=0;n<arrsiz;n++) {
+            t = (int)(drand48() * (double)(n+1)); /* TRUNCATE */
+            if(t==n)
+                hhprefix(n,arrsiz,perm);
+            else
+                hhinsert(n,t,arrsiz,perm);
+        }
+        if(checklen <= 0)
+            break;
+        for(n=0;n<checklen;n++) {
+            if(arr[perm[n]] == endval) {    /* if this is val (repeated) at end of last perm */
+                if(allowed == 0)                        /* if repetition not allowed, force a new perm val */
+                    break;
+                else                                            /* else, repetitions still allowed */
+                    allowed--;                              /* decrement number of permissible further repets */
+            } else {
+                done = 1;                                       /* if this is not val at end of last perm */
+                break;                                          /* perm is OK */
+            }
+        }
+    }
+}
+
+/***************************** HHINSERT **********************************
+ *
+ * Insert the value m AFTER the T-th element in perm[].
+ */
+
+void hhinsert(int m,int t,int setlen,int *perm)
+{
+    hhshuflup(t+1,setlen,perm);
+    perm[t+1] = m;
+}
+
+/***************************** HHPREFIX ************************************
+ *
+ * Insert the value m at start of the permutation perm[].
+ */
+
+void hhprefix(int m,int setlen,int *perm)
+{
+    hhshuflup(0,setlen,perm);
+    perm[0] = m;
+}
+
+/****************************** HHSHUFLUP ***********************************
+ *
+ * move set members in perm[] upwards, starting from element k.
+ */
+
+void hhshuflup(int k,int setlen,int *perm)
+{
+    int n, *i;
+    int z = setlen - 1;
+    i = (perm+z);
+    for(n = z;n > k;n--) {
+        *i = *(i-1);
+        i--;
+    }
+}
+
+/****************************** TIME_FROM_BAR_BEAT_METRE_TEMPO ***********************************/
+
+void time_from_bar_beat_metre_tempo(int has_offset)
+{
+    int barlen, beatsize, n;
+    double tempo,beat,beatdur,time, offset = 0.0;
+
+    if((tempo = get_tempo(strings[cnt+1])) <= 0.0)
+        exit(1);
+    if(has_offset)
+        get_offset(strings[cnt+2],&offset);
+    get_metre(strings[cnt],&barlen,&beatsize);
+    beatdur = (60.0/(double)tempo) * (4.0/(double)beatsize);
+    for(n=0;n<cnt;n++) {
+        beat = get_beat(n,barlen);
+        time = beat * beatdur;
+        time += offset;
+        fprintf(stdout,"INFO: %lf\n",time);
+    }
+    fflush(stdout);
+}
+
+/****************************** GET_METRE ***********************************/
+
+void get_metre(char str[],int *barlen,int *beatsize)
+{
+    int pointcnt = 0, isvalid = 0, mask;
+    char *q, *start, *p = str;
+    start = p;
+    q = start;
+    p += strlen(p);
+    /* strip trailing zeros */
+    if(p == start) {
+        fprintf(stdout, "ERROR: Invalid metre value. (No data).\n");
+        fflush(stdout);
+        exit(1);
+    }
+    p--;
+    while(*p == '0') {
+        *p = ENDOFSTR;
+        if(p == start)
+            break;
+        p--;
+    }
+    p = start;
+    while(*p != ENDOFSTR) {
+        if(*p == '.') {
+            pointcnt++;
+            q = p;
+        } else if (!isdigit(*p)) {
+            fprintf(stdout, "ERROR: Invalid metre value. non_digit = '%c' in numerator.\n",*p);
+            fflush(stdout);
+            exit(1);
+        }
+        p++;
+    }
+    if(q == start) {
+        fprintf(stdout, "ERROR: Invalid metre value. No numerator.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    if (pointcnt!=1) {
+        if(pointcnt > 1)
+            fprintf(stdout, "ERROR: Invalid metre value. %d decimal points : must be one only.\n",pointcnt);
+        else
+            fprintf(stdout, "ERROR: Invalid metre value. No decimal point\n");
+        fflush(stdout);
+        exit(1);
+    }
+    *q = ENDOFSTR;
+    if(sscanf(start,"%d",barlen)<1) {                                                       /* SAFETY (redundant) */
+        fprintf(stdout, "ERROR: Invalid metre value. Cannot read barlength.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    p = q+1;
+    if(*p==ENDOFSTR) {
+        fprintf(stdout, "ERROR: Invalid metre value. (No denominator).\n");
+        fflush(stdout);
+        exit(1);
+    }
+    start = p;
+    if(*p == '0') {
+        fprintf(stdout, "ERROR: Invalid metre value. (leading zeros in denominator).\n");               /* leading zero(s) */
+        fflush(stdout);
+        exit(1);
+    }
+    while(*p != ENDOFSTR) {
+        if(!isdigit(*p)) {                                                                              /* non-numeric characters */
+            fprintf(stdout, "ERROR: Invalid metre value. (non-digit character '%c' in denominator )\n",*p);
+            fflush(stdout);
+            exit(1);
+        }
+        p++;
+    }
+    if(sscanf(start,"%d",beatsize)<1) {                                                     /* SAFETY (redundant) */
+        fprintf(stdout, "ERROR: Invalid metre value. Failed to read beatsize from %s\n",start);
+        fflush(stdout);
+        exit(1);
+    }
+    mask = 1;
+    while(mask < 512) {             /* Powers of 2 only !! Need special dispensation for Ferneyhovian metres like 4:10 */
+        if((*beatsize) == mask) {
+            isvalid = 1;
+            break;
+        }
+        mask <<= 1;
+    }
+    if(!isvalid) {
+        fprintf(stdout, "ERROR: Invalid metre value. beatsize (%d) is invalid in standard usage\n",*beatsize);
+        fflush(stdout);
+        exit(1);
+    }
+}
+
+/****************************** GET_BEAT ***********************************/
+
+double get_beat(int n,int barlen)
+{
+    int pointcnt = 0;
+    char *q = NULL, *p, *start;
+    int bar;
+    double beat;
+    if(strlen(strings[n]) == 0) {
+        fprintf(stdout, "ERROR: Invalid bar:beat value at item %d. (No value found)\n",n+1);
+        fflush(stdout);
+        exit(1);
+    }
+    p = strings[n];
+    /* must have COLON */
+    while(*p != ENDOFSTR) {
+        if(*p == ':') {
+            pointcnt++;
+            q = p;
+        } else if (!isdigit(*p) && (*p != '.')) {
+            pointcnt = -1;
+            break;
+        }
+        p++;
+    }
+    if(pointcnt != 1) {
+        switch(pointcnt) {
+        case(-1):
+            fprintf(stdout, "ERROR: Invalid character (%c) in bar:beat value '%s' in item %d\n",*p,strings[n],n+1);
+            break;
+        case(0):
+            fprintf(stdout, "ERROR: Invalid bar:beat value '%s' at item %d. (No colon found)\n",strings[n],n+1);
+            break;
+        default:
+            fprintf(stdout, "ERROR: Invalid bar:beat value '%s' at item %d : %d colons found (should be only 1)\n",
+                    strings[n],n+1,pointcnt);
+            break;
+        }
+        fflush(stdout);
+        exit(1);
+    }
+    *q = ENDOFSTR;
+    if(sscanf(strings[n],"%d",&bar)<1) {    /* SAFETY (redundant) */
+        fprintf(stdout, "ERROR: Invalid bar:beat value at item %d. Failed to read bar count.\n",n+1);
+        fflush(stdout);
+        exit(1);
+    }
+    if(bar < 1) {
+        fprintf(stdout, "ERROR: Invalid bar:beat value at item %d. Bar count less than 1.\n",n+1);
+        fflush(stdout);
+        exit(1);
+    }
+    bar--;
+    start = q+1;
+    if(*start==ENDOFSTR) {
+        fprintf(stdout, "ERROR: Invalid bar:beat value at item %d. No beatcount.\n",n+1);
+        fflush(stdout);
+        exit(1);
+    }
+    if(sscanf(start,"%lf",&beat)<1) {                                                                                               /* SAFETY (redundant) */
+        fprintf(stdout, "ERROR: Invalid bar:beat value at item %d. Failed to read beatcount.\n",n+1);
+        fflush(stdout);
+        exit(1);
+    }
+    if(beat < 1.0) {
+        fprintf(stdout, "ERROR: Invalid bar:beat value at item %d. Beat count less than 1.\n",n+1);
+        fflush(stdout);
+        exit(1);
+    } else if(beat >= (double)(barlen + 1)) {
+        fprintf(stdout, "ERROR: Invalid bar:beat value at item %d. Beat count beyond bar end.\n",n+1);
+        fflush(stdout);
+        exit(1);
+    }
+    beat -= 1.0;
+    beat += (bar * (double)barlen);
+    return beat;
+}
+
+/****************************** SCALE_FROM ***********************************/
+
+void scale_from(void) {
+
+    double interval, pivot = number[cnt];
+    double scaler = number[cnt+1];
+    int n;
+    for(n = 0;n<cnt;n++) {
+        interval = number[n] - pivot;
+        interval *= scaler;
+        fprintf(stdout,"INFO: %lf\n",pivot + interval);
+    }
+    fflush(stdout);
+}
+
+/****************************** SCALE_ABOVE ***********************************/
+
+void scale_above(void) {
+
+    double interval, pivot = number[cnt];
+    double scaler = number[cnt+1];
+    int n;
+    for(n = 0;n<cnt;n++) {
+        interval = number[n] - pivot;
+        if(interval > 0.0) {
+            interval *= scaler;
+            fprintf(stdout,"INFO: %lf\n",pivot + interval);
+        } else
+            fprintf(stdout,"INFO: %lf\n",number[n]);
+    }
+    fflush(stdout);
+}
+
+/****************************** SCALE_BELOW ***********************************/
+
+void scale_below(void) {
+
+    double interval, pivot = number[cnt];
+    double scaler = number[cnt+1];
+    int n;
+    for(n = 0;n<cnt;n++) {
+        interval = number[n] - pivot;
+        if(interval < 0.0) {
+            interval *= scaler;
+            fprintf(stdout,"INFO: %lf\n",pivot + interval);
+        } else
+            fprintf(stdout,"INFO: %lf\n",number[n]);
+    }
+    fflush(stdout);
+}
+
+/************************** SPAN_RISE ********************************/
+
+void span_rise(void) {
+
+    int n;
+
+    if(number[0] < 0.0) {
+        fprintf(stdout,"ERROR: This option only works with ascending values greater than or equal to zero.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    for(n = 1;n<cnt;n++) {
+        if(number[n] - number[n-1] <= thresh)  {
+            fprintf(stdout,"ERROR: No space for span between number %d (%lf) and number %d (%lf)\n",
+                    n,number[n-1],n+1,number[n]);
+            fflush(stdout);
+            exit(1);
+        }
+    }
+    if(number[0] < thresh) {
+        fprintf(stdout,"WARNING: First value too close to zero: NO span inserted.\n");
+        fflush(stdout);
+    } else {
+        fprintf(stdout,"INFO: %lf\n",number[0] - thresh);
+    }
+    fprintf(stdout,"INFO: %lf\n",number[0]);
+
+    for(n = 1;n<cnt;n++) {
+        fprintf(stdout,"INFO: %lf\n",number[n] - thresh);
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+    }
+    fflush(stdout);
+}
+
+/************************** SPAN_FALL ********************************/
+
+void span_fall(void) {
+
+    int n;
+
+    if(number[0] < 0.0) {
+        fprintf(stdout,"ERROR: This option only works with ascending values greater than or equal to zero.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    for(n = 1;n<cnt;n++) {
+        if(number[n] - number[n-1] <= thresh)  {
+            fprintf(stdout,"ERROR: No space for span between number %d (%lf) and number %d (%lf)\n",
+                    n,number[n-1],n+1,number[n]);
+            fflush(stdout);
+            exit(1);
+        }
+    }
+    for(n = 0;n<cnt;n++) {
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+        fprintf(stdout,"INFO: %lf\n",number[n] + thresh);
+    }
+    fflush(stdout);
+}
+
+/************************** CYCLIC_SELECT ********************************/
+
+void cyclic_select(char c) {
+
+    int n, m, start, step, k = (int)c, startpos = 0, steppos=0;
+    double item = 0.0;
+
+    switch(k) {
+    case('s'):
+        steppos  = cnt;
+        startpos = cnt+1;
+        break;
+    case('a'):
+    case('m'):
+        steppos  = cnt+1;
+        startpos = cnt+2;
+        break;
+    }
+    if((start = (int)round(number[startpos])) > cnt) {
+        fprintf(stdout,"ERROR: There are no numbers at or beyond position %d\n",start);
+        fflush(stdout);
+        exit(1);
+    } else if(start < 1) {
+        fprintf(stdout,"ERROR: There are no numbers at or before position %d\n",start);
+        fflush(stdout);
+        exit(1);
+    }
+    start--;
+    if(abs(step = (int)round(number[steppos])) < 1) {
+        fprintf(stdout,"ERROR: Step between values cannot be zero.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    if(c != 's') {
+        if(step < 0) {
+            fprintf(stdout,"ERROR: Step between values cannot be negative.\n");
+            fflush(stdout);
+            exit(1);
+        }
+        item = number[cnt];
+    }
+    switch(k) {
+    case('s'):
+        if(step > 0) {
+            for(n = start;n<cnt;n+=step)
+                fprintf(stdout,"INFO: %lf\n",number[n]);
+        } else {
+            for(n = start;n>=0;n+=step)
+                fprintf(stdout,"INFO: %lf\n",number[n]);
+        }
+        break;
+    case('a'):
+    case('m'):
+        n = 0;
+        while(n < start)
+            fprintf(stdout,"INFO: %lf\n",number[n++]);
+        for(m = 0;n<cnt;m++,n++) {
+            m %= step;
+            if(m == 0) {
+                switch(k) {
+                case('a'):      fprintf(stdout,"INFO: %lf\n",number[n] + item); break;
+                case('m'):      fprintf(stdout,"INFO: %lf\n",number[n] * item); break;
+                }
+            } else {
+                fprintf(stdout,"INFO: %lf\n",number[n]);
+            }
+        }
+        break;
+    }
+    fflush(stdout);
+}
+
+/************************** SPAN_ALL ********************************/
+
+void span_all(void) {
+
+    int n, zero_exists = 0, top_exists = 0;
+
+    if(number[0] < 0.0) {
+        fprintf(stdout,"ERROR: Numbers begin before zero.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    if(number[cnt-1] > factor) {
+        fprintf(stdout,"ERROR: Numbers already run beyond %lf\n",factor);
+        fflush(stdout);
+        exit(1);
+    }
+    if(number[0] <= 0.0)
+        zero_exists = 1;
+    if(number[cnt-1] >= factor)
+        top_exists = 1;
+    if(zero_exists) {
+        if(top_exists) {
+            fprintf(stdout,"ERROR: Numbers already begin at zero and end at %lf\n",factor);
+            fflush(stdout);
+            exit(1);
+        } else {
+            fprintf(stdout,"WARNING: Numbers already start at zero\n");
+            fflush(stdout);
+        }
+    }
+    if(top_exists) {
+        fprintf(stdout,"WARNING: Numbers already end at %lf\n",factor);
+        fflush(stdout);
+    }
+    if(!zero_exists)
+        fprintf(stdout,"INFO: %lf\n",0.0);
+    for(n=0;n<cnt;n++)
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+    if(!top_exists)
+        fprintf(stdout,"INFO: %lf\n",factor);
+    fflush(stdout);
+}
+
+/************************** GET_TEMPO ********************************/
+
+double get_tempo(char *str)
+{
+    char *p = str;
+    double tempo;
+    int pointcnt = 0;
+    while(*p != ENDOFSTR) {
+        if(*p == '.') {
+            pointcnt++;
+        } else if(!isdigit(*p)) {
+            pointcnt = -1;
+            break;
+        }
+        p++;
+    }
+    if(pointcnt < 0 || pointcnt > 1) {
+        fprintf(stdout, "ERROR: Invalid tempo value.\n");
+        fflush(stdout);
+        return(-1.0);
+    }
+    if(sscanf(str,"%lf",&tempo)!=1) {
+        fprintf(stdout, "ERROR: Invalid tempo value.\n");
+        fflush(stdout);
+        return(-1.0);
+    }
+    if(tempo <= 0.0) {
+        fprintf(stdout, "ERROR: Zero or negative tempo: impossible.\n");
+        fflush(stdout);
+        return(-1.0);
+    } else if(tempo > MAX_TEMPO) {
+        fprintf(stdout, "ERROR: Invalid tempo value. Beats shorter than 1 millisecond (!!).\n");
+        fflush(stdout);
+        return(-1.0);
+    } else if(tempo < MIN_TEMPO) {
+        fprintf(stdout, "ERROR: Invalid tempo value. Beats longer than 1 hour (!!).\n");
+        fflush(stdout);
+        return(-1.0);
+    }
+    return tempo;
+}
+
+/************************** GENERATE_RANDOMISED_VALS ********************************/
+
+void generate_randomised_vals(void)
+{
+    double scatter = number[2], span = number[0], sum = 0.0, mean, range, *temp = NULL, d;
+    int cnt = (int)round(number[1]), n, m, j, subcnt;
+    int bigscat = 0;
+    if(scatter > 1.0)
+        bigscat = (int)round(scatter);
+    if(bigscat) {
+        if((temp = (double *)malloc(bigscat * sizeof(double)))==NULL) {
+            fprintf(stdout,"Out of memory.\n");
+            fflush(stdout);
+            exit(1);
+        }
+    }
+    if((number = (double *)realloc((char *)number,(cnt+1) * sizeof(double)))==NULL) {
+        fprintf(stdout,"Out of memory.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    mean = span/(double)cnt;
+    number[0] = 0.0;
+    number[cnt] = span;
+
+    if(bigscat) {
+        for(n=1;n < cnt;n+= bigscat) {
+            if((subcnt = n + bigscat) > cnt)                        /* find position of last number in this pass */
+                subcnt = cnt;                                                   /* set end position of pass */
+            subcnt--;                                                                       /* allow for item already written at 1 */
+            if((subcnt %= bigscat) == 0)                            /* set size of pass */
+                subcnt = bigscat;
+            range = mean * subcnt;                                          /* set range of pass */
+            for(m = 0; m < subcnt; m++)
+                temp[m] = sum + (drand48() * range);    /* generate values within this range */
+            for(m=0;m < subcnt - 1; m++) {
+                for(j=1;j < subcnt; j++) {
+                    if(temp[m] > temp[j]) {                         /* sort */
+                        d = temp[j];
+                        temp[j] = temp[m];
+                        temp[m] = d;
+                    }
+                }
+            }
+            for(m=0;m<subcnt;m++)                                           /* concatenate to list of numbers */
+                number[n+m] = temp[m];
+            sum += range;                                                           /* step over range */
+        }
+    } else {
+        for(n=1;n < cnt;n++) {
+            sum += mean;
+            number[n] = sum + (mean * randoffset(scatter));
+        }
+    }
+    for(n=0;n<=cnt;n++)
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+    fflush(stdout);
+}
+
+/************************** RAND_OFFSET ********************************
+ *
+ * rand number in maximal range -half to +half
+ */
+
+double randoffset(double scatter)
+{
+    return (((drand48() * 2.0) - 1.0) * 0.5) * scatter;
+}
+
+/************************** GET_OFFSET ********************************/
+
+void get_offset(char *str,double *offset)
+{
+    if(sscanf(str,"%lf",offset)!=1) {
+        fprintf(stdout,"Cannot read time offset.\n");
+        fflush(stdout);
+        exit(1);
+    }
+}
+
+/************************** PITCH_TO_DELAY ********************************/
+
+void pitch_to_delay(int midi)
+{
+    int n;
+    for(n = 0;n < cnt; n++) {
+        if(midi) {
+            if(number[n] < MIDIMIN || number[n] > MIDIMAX) {
+                fprintf(stdout,"MIDI value %d (%lf) is out of range.\n", n+1,number[n]);
+                fflush(stdout);
+                exit(1);
+            }
+            number[n] = miditohz(number[n]);
+        } else if(number[n] < FLTERR || number[n] > 24000.0) {
+            fprintf(stdout,"Frequency value %d (%lf) is out or range.\n",n+1,number[n]);
+            fflush(stdout);
+            exit(1);
+        }
+        number[n] = 1000.0/number[n];
+    }
+    for(n=0;n<cnt;n++)
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+    fflush(stdout);
+}
+
+/************************** DELAY_TO_PITCH ********************************/
+
+void delay_to_pitch(int midi)
+{
+    int n;
+    for(n = 0;n < cnt; n++) {
+        number[n] /= 1000;
+        if(number[n] < FLTERR) {
+            fprintf(stdout,"Delay value %d (%lf) is out or range for conversion to pitch value.\n",n+1,number[n]);
+            fflush(stdout);
+            exit(1);
+        }
+        number[n] = 1.0/number[n];
+        if(midi) {
+            if(number[n] < MIDIMINFRQ || number[n] > MIDIMAXFRQ) {
+                fprintf(stdout,"delay value %d (%lf) is out of range for conversion to MIDI.\n", n+1,number[n]);
+                fflush(stdout);
+                exit(1);
+            }
+            number[n] = hztomidi(number[n]);
+        } else if(number[n] < FLTERR || number[n] > 24000) {
+            fprintf(stdout,"Delay value %d (%lf) is out or range for conversion to frq.\n",n+1,number[n]);
+            fflush(stdout);
+            exit(1);
+        }
+    }
+    for(n=0;n<cnt;n++)
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+    fflush(stdout);
+}
+
+
+/* NEW FUNCS HANDLING BRKTABLES DIRECTLY ***** JUNE 2000 ***/
+
+
+/****************************** REVERSE_TIME_INTERVALS ******************************/
+
+void reverse_time_intervals(void)
+{
+    int n, m;
+    double k = number[0];
+    fprintf(stdout,"INFO: %lf  %lf\n",k,number[1]);
+    for(n=3,m = cnt-2;n<cnt;m-=2,n+=2) {
+        k += (number[m] - number[m-2]);
+        fprintf(stdout,"INFO: %lf  %lf\n",k,number[n]);
+    }
+    fflush(stdout);
+}
+
+/****************************** REVERSE_ORDER_OF_BRKVALS ******************************/
+
+void reverse_order_of_brkvals(void)
+{
+    int n, m;
+    for(n=0,m = cnt-1;n<cnt;m-=2,n+=2)
+        fprintf(stdout,"INFO: %lf  %lf\n",number[n],number[m]);
+    fflush(stdout);
+}
+
+/****************************** INVERTENV ******************************/
+
+void invertenv(double piv)
+{
+    int n;
+    for(n=1;n<cnt;n+=2)
+        fprintf(stdout,"INFO: %lf  %lf\n",number[n-1],piv - number[n]);
+    fflush(stdout);
+}
+
+/******************************** THRESH_CUT ****************************/
+
+void thresh_cut(void)
+{
+    int n,m, k = 0;
+    double ratio, *time;
+    int isgreater = 0;
+    if((cnt <= 0) || ((time = (double *)malloc(cnt * sizeof(double)))==NULL)) {
+        fprintf(stdout,"ERROR: Insufficient memory.\n");
+        return;
+    }
+    if(number[1] > factor)
+        isgreater = 1;
+    for(m=2,n=3;n<cnt;n+=2,m+=2) {
+        switch(isgreater) {
+        case(0):
+            if(number[n] > factor) {
+                ratio = (factor - number[n-2])/(number[n] - number[n-2]);
+                time[k++] = ((number[m] - number[m-2]) * ratio) + number[m-2];
+                isgreater = 1;
+            }
+            break;
+        case(1):
+            if(number[n] <= factor) {
+                ratio = (factor - number[n-2])/(number[n] - number[n-2]);
+                time[k++] = ((number[m] - number[m-2]) * ratio) + number[m-2];
+                isgreater = 0;
+            }
+            break;
+        }
+    }
+    if(k == 0) {
+        fprintf(stdout,"ERROR: The values do not cross the threshold.\n");
+        free(time);
+        return;
+    }
+    for(n=0;n<k;n++)
+        do_valout(time[n]);
+    free(time);
+}
+
+/******************************** BAND_CUT ****************************/
+
+void band_cut(void)
+{
+    int n,m, k = 0;
+    double ratio, *time, z, hibnd, lobnd;
+    int bandpos;
+    if((cnt <= 0) || ((time = (double *)malloc(cnt * sizeof(double)))==NULL)) {
+        fprintf(stdout,"ERROR: Insufficient memory.\n");
+        return;
+    }
+    lobnd = number[cnt];
+    hibnd = number[cnt+1];
+
+    if(lobnd > hibnd) {
+        z = lobnd;
+        lobnd = hibnd;
+        hibnd = z;
+    }
+    if(number[1] >= lobnd && number[1] <= hibnd)
+        bandpos = 0;
+    else if(number[1] < lobnd)
+        bandpos = -1;
+    else
+        bandpos = 1;
+    for(m=2,n=3;n<cnt;n+=2,m+=2) {
+        switch(bandpos) {
+        case(0):
+            if(number[n] < lobnd) {            /* crosses out downwards */
+                ratio = (lobnd - number[n-2])/(number[n] - number[n-2]);
+                time[k++] = ((number[m] - number[m-2]) * ratio) + number[m-2];
+                bandpos = -1;
+            } else if(number[n] > hibnd) {     /* crosses out upwards */
+                ratio = (hibnd - number[n-2])/(number[n] - number[n-2]);
+                time[k++] = ((number[m] - number[m-2]) * ratio) + number[m-2];
+                bandpos = 1;
+            }
+            break;
+        case(1):
+            if(number[n] <= hibnd) {                        /* crosses in from above */
+                ratio = (hibnd - number[n-2])/(number[n] - number[n-2]);
+                time[k++] = ((number[m] - number[m-2]) * ratio) + number[m-2];
+                bandpos = 0;
+            }
+            if(number[n] < lobnd) {                 /* then possibly out below */
+                ratio = (lobnd - number[n-2])/(number[n] - number[n-2]);
+                time[k++] = ((number[m] - number[m-2]) * ratio) + number[m-2];
+                bandpos = -1;
+            }
+            break;
+        case(-1):
+            if(number[n] >= lobnd) {                   /* crosses in from below */
+                ratio = (lobnd - number[n-2])/(number[n] - number[n-2]);
+                time[k++] = ((number[m] - number[m-2]) * ratio) + number[m-2];
+                bandpos = 0;
+            }
+            if(number[n] > hibnd) {                 /* then possibly out above */
+                ratio = (hibnd - number[n-2])/(number[n] - number[n-2]);
+                time[k++] = ((number[m] - number[m-2]) * ratio) + number[m-2];
+                bandpos = 1;
+            }
+            break;
+        }
+    }
+    if(k == 0) {
+        fprintf(stdout,"ERROR: The values in the 2nd column do not cross into or out of the specified band.\n");
+        free(time);
+        return;
+    }
+    for(n=0;n<k;n++)
+        do_valout(time[n]);
+    fflush(stdout);
+    free(time);
+}
+
+
+
+/****************************** ENV_APPEND ******************************/
+
+void env_append(void)
+{
+    int n, dojoin = 0;
+    double first_endtime;
+
+    first_endtime = number[firstcnt-2];
+    if (factor < first_endtime) {
+        fprintf(stdout,"ERROR: Second envelope starts before first one ends.\n");
+        fflush(stdout);
+        exit(1);
+    } else if(flteq(factor,first_endtime)) {
+        if(!flteq(number[firstcnt-1],number[firstcnt+1])) {
+            fprintf(stdout,"ERROR: Abutting envelopes are not at same level (%lf and %lf).\n",number[firstcnt-1],number[firstcnt+1]);
+            fflush(stdout);
+            exit(1);
+        }
+        dojoin = 1;
+    }
+    for(n = firstcnt; n < cnt; n+=2) {
+        number[n] += factor;
+    }
+    if(dojoin) {
+        for(n=0;n<firstcnt;n+=2)
+            do_valpair_out(number[n],number[n+1]);
+        for(n=firstcnt+2;n<cnt;n+=2)
+            do_valpair_out(number[n],number[n+1]);
+    } else {
+        for(n=0;n<cnt;n+=2)
+            do_valpair_out(number[n],number[n+1]);
+    }
+    fflush(stdout);
+}
+
+/****************************** ABUTT ******************************/
+
+void abutt(void)
+{
+    int n,m = 0, i;
+    double displace;
+    int indx = 0;
+    for(i=0;i<infilecnt-1;i++) {                    /* check abutting values match */
+        indx += file_cnt[i];
+        if(!flteq(number[indx-1],number[indx+1])) {
+            fprintf(stdout,"ERROR: Abutting values between files %d and %d do not match\n",i+1,i+2);
+            fflush(stdout);
+            exit(1);
+        }
+    }
+    for(n=0;n < file_cnt[0]; n+=2) {                /* print all of file 1 */
+        fprintf(stdout, "INFO: %lf  %lf\n",number[m],number[m+1]);
+        m += 2;
+    }
+    displace = number[m-2];                                 /* displace by last time in 1st file */
+    for(i = 1; i <infilecnt; i++) {                 /* for all other files */
+        m += 2;                                                         /* skip first (abutting) value */
+        for(n=2;n < file_cnt[i]; n+=2) {        /* for all other values in file - displace time values */
+            fprintf(stdout, "INFO: %lf  %lf\n",number[m] + displace,number[m+1]);
+            m += 2;
+        }
+        displace += number[m-2];                        /* increase displacement by last time in this file */
+    }
+    fflush(stdout);
+}
+
+/****************************** QUANTISE_TIME ******************************/
+
+void quantise_time(void)
+{
+    int n;
+    for(n=0;n<cnt;n+=2)
+        fprintf(stdout,"INFO: %lf  %lf\n",round(number[n]/factor) * factor,number[n+1]);
+    fflush(stdout);
+}
+
+/****************************** QUANTISE_VAL ******************************/
+
+void quantise_val(void)
+{
+    int n;
+    for(n=0;n<cnt;n+=2)
+        fprintf(stdout,"INFO: %lf  %lf\n",number[n],round(number[n+1]/factor) * factor);
+    fflush(stdout);
+}
+
+/****************************** EXPAND_TABLE_DUR_BY_FACTOR ******************************/
+
+void expand_table_dur_by_factor(void)
+{
+    int n;
+    for(n=0;n<cnt;n+=2)
+        fprintf(stdout,"INFO: %lf  %lf\n",number[n] * factor,number[n+1]);
+    fflush(stdout);
+}
+
+/****************************** EXPAND_TABLE_VALS_BY_FACTOR ******************************/
+
+void expand_table_vals_by_factor(void)
+{
+    int n;
+    for(n=0;n<cnt;n+=2)
+        fprintf(stdout,"INFO: %lf  %lf\n",number[n],number[n+1] * factor);
+    fflush(stdout);
+}
+
+/****************************** EXPAND_TABLE_TO_DUR ******************************/
+
+void expand_table_to_dur(void)
+{
+    int n;
+    double ratio;
+
+    if(number[cnt-2] <= 0.0) {
+        fprintf(stdout,"ERROR: Final time in table is zero: cannot proceed.\n");
+        return;
+    }
+    ratio = factor/number[cnt-2];
+
+    for(n=0;n<cnt;n+=2)
+        fprintf(stdout,"INFO: %lf  %lf\n",number[n] * ratio,number[n+1]);
+    fflush(stdout);
+}
+
+/****************************** CUT_TABLE_AT_TIME ******************************/
+
+void cut_table_at_time(void)
+{
+    int n;
+    double timediff,valdiff,timeratio,outval;
+
+    for(n=0;n<cnt;n+=2) {
+        if(flteq(number[n],factor)) {
+            fprintf(stdout,"INFO: %lf  %lf\n",number[n],number[n+1]);
+            break;
+        } else if(number[n] < factor) {
+            fprintf(stdout,"INFO: %lf  %lf\n",number[n],number[n+1]);
+        } else if(n==0) {
+            fprintf(stdout,"WARNING: No values occur before the cut-off time\n");
+            break;
+        } else {
+            timediff  = number[n] - number[n-2];
+            valdiff   = number[n+1] - number[n-1];
+            timeratio = (factor - number[n-2])/timediff;
+            valdiff  *= timeratio;
+            outval  = number[n-1] + valdiff;
+            fprintf(stdout,"INFO: %lf  %lf\n",factor,outval);
+            break;
+        }
+    }
+    fflush(stdout);
+}
+
+/****************************** EXTEND_TABLE_TO_DUR ******************************/
+
+void extend_table_to_dur(void)
+{
+    int n;
+    for(n=0;n<cnt;n+=2)
+        fprintf(stdout,"INFO: %lf  %lf\n",number[n],number[n+1]);
+    fprintf(stdout,"INFO: %lf  %lf\n",factor,number[n-1]);
+    fflush(stdout);
+}
+
+/****************************** LIMIT_TABLE_VAL_RANGE ******************************/
+
+void limit_table_val_range(void)
+{
+    int n;
+    if(condit) {
+        for(n=1;n<cnt;n+=2) {
+            number[n] = min(factor, number[n]);
+            number[n] = max(number[n],thresh);
+            fprintf(stdout,"INFO: %lf  %lf\n",number[n-1],number[n]);
+        }
+    } else {
+        for(n=1;n<cnt;n+=2) {
+            number[n] = min(factor,number[n]);
+            fprintf(stdout,"INFO: %lf  %lf\n",number[n-1],number[n]);
+        }
+    }
+    fflush(stdout);
+}
+
+/****************************** SUBSTITUTE ******************************/
+
+void substitute(void)
+{
+    int n;
+    for(n=0;n<cnt;n++) {
+        if(flteq(number[n],thresh))
+            number[n] = factor;
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+    }
+    fflush(stdout);
+}
+
+/****************************** SUBSTITUTE_ALL ******************************/
+
+void substitute_all(void)
+{
+    int n;
+    for(n=0;n<stringscnt;n++)
+        fprintf(stdout,"INFO: %s\n",string);
+    fflush(stdout);
+}
+
+/****************************** SUBSTITUTE ******************************/
+
+void mean_of_reversed_pairs(void)
+{
+    int n;
+    double z1;
+    for(n=1;n<cnt;n++) {
+        if(number[n]<number[n-1]) {
+            z1 = (number[n] + number[n-1])/2.0;
+            number[n-1]     = z1 - FLTERR;
+            if((n-2 > 0) && number[n-2] >= number[n-1]) {
+                fprintf(stdout,"WARNING: numbers %d (%lf) and %d (%lf) failed to be separated.\n",
+                        n,number[n-1],n+1,number[n]);
+                fflush(stdout);
+                return;
+            }
+            number[n]   = z1 + FLTERR;
+            if((n+1 < cnt) && number[n+1] <= number[n]) {
+                fprintf(stdout,"WARNING: numbers %d (%lf) and %d (%lf) failed to be separated.\n",
+                        n+1,number[n],n+2,number[n+1]);
+                fflush(stdout);
+                return;
+            }
+        }
+    }
+    for(n=0;n<cnt;n++)
+        fprintf(stdout,"INFO: %lf\n",number[n]);
+    fflush(stdout);
+}
+
+/****************************** CONVERT_SPACE_TEX_TO_PAN ******************************/
+
+void convert_space_tex_to_pan(void)
+{
+    int n;
+    for(n=1;n<cnt;n+=2) {
+        number[n] *=2.0;
+        number[n] -=1.0;
+    }
+    for(n=0;n<cnt;n+=2)
+        fprintf(stdout,"INFO: %lf  %lf\n",number[n],number[n+1]);
+    fflush(stdout);
+}
+
+/****************************** CONVERT_SPACE_PAN_TO_TEX ******************************/
+
+void convert_space_pan_to_tex(void)
+{
+    int n;
+    for(n=1;n<cnt;n+=2) {
+        number[n] *=0.5;
+        number[n] +=0.5;
+    }
+    for(n=0;n<cnt;n+=2)
+        fprintf(stdout,"INFO: %lf  %lf\n",number[n],number[n+1]);
+    fflush(stdout);
+}
+
+/****************************** CONVERT_TO_EDITS ******************************/
+
+void convert_to_edits(void)
+{
+    int n;
+    double start, end;
+    for(n=0;n<cnt-1;n++) {
+        start = max(0.0,number[n] - factor);
+        end = max(0.0,number[n+1] + factor);
+        fprintf(stdout,"INFO: %lf  %lf\n",start,end);
+    }
+    fflush(stdout);
+}
+
+/****************************** COSIN_SPLINE ******************************/
+
+void cosin_spline(void)
+{
+    int n, cnt_less_one;
+    double val, valchange, skew, startval ,endval;
+    skew = number[3];
+    startval = number[1];
+    endval   = number[2];
+    valchange = endval - startval;
+    cnt_less_one = cnt - 1;
+    if(flteq(skew,1.0)) {
+        for(n=0;n<cnt;n++) {
+            val  = ((double)n/(double)cnt_less_one) * PI;
+            val  = cos(val);
+            val += 1.0;
+            val /= 2.0;
+            val  = 1.0 - val;
+            val  = max(0.0,val);
+            val  = min(val,1.0);
+            val *= valchange;
+            val += startval;
+            fprintf(stdout,"INFO: %lf\n",val);
+        }
+    } else {
+        for(n=0;n<cnt;n++) {
+            val  = ((double)n/(double)cnt_less_one);        /* val in 0 -1 range */
+            val  = pow(val,skew);                                           /* val skewed, still in 0-1 range */
+            val  = val * PI;                                                        /* (skewed) val in range 0 to PI */
+            val  = cos(val);                                                        /* cosin val running from 1 to -1 */
+            val += 1.0;                                                                     /* cosin val running from 2 to 0  */
+            val /= 2.0;                                                                     /* cosin val running from 1 to 0  */
+            val  = 1.0 - val;                                                       /* cosin val running from 0 to 1  */
+            val  = max(0.0,val);                                            /* ensure 0-1 range not exceeeded */
+            val  = min(val,1.0);
+            val *= valchange;                                                       /* apply cosin shape to val change */
+            val += startval;                                                        /* add cosin change to initial val */
+            fprintf(stdout,"INFO: %lf\n",val);
+        }
+    }
+    fflush(stdout);
+}
+
+/****************************** DISTANCE_FROM_GRID ******************************/
+
+void distance_from_grid()
+{
+    int n, m, besterror;
+    double *diff = (double *)exmalloc((cnt-1)*sizeof(double));
+    double *error = (double *)exmalloc(21 * sizeof(double));
+    double maxdiff = 0.0, mindiff = 0.0, lastmindiff, diffrange, diffstep, thisdiff, thisgrid, minerror;
+    double lowlimit = FLTERR/10000;
+
+    for(n=0;n<cnt-1;n++) {
+        diff[n] = number[n+1] - number[n];
+
+        /*
+          if(diff[n]  <= 0.0) {
+          fprintf(stdout, "ERROR: Process only works with increasing sequences of numbers.\n");
+          fflush(stdout);
+          exit(1);
+          }
+        */
+        if(n==0) {
+            mindiff = diff[0];
+            maxdiff = diff[0];
+        } else {
+            mindiff = min(diff[n],mindiff);
+            maxdiff = max(diff[n],maxdiff);
+        }
+    }
+
+    lastmindiff = mindiff;
+    while((diffrange = maxdiff - mindiff) > lowlimit * 20.0) {
+        diffstep = diffrange/20.0;
+        thisdiff = mindiff;
+        for(m=0;m<=20;m++) {
+            error[m] = 0;
+            thisgrid = number[0];
+            for(n=1;n<cnt;n++) {
+                thisgrid += thisdiff;
+                error[m] += fabs(number[n] - thisgrid);
+            }
+            thisdiff += diffstep;
+        }
+        minerror = error[0];
+        besterror = 0;
+        for(m=1;m<=20;m++) {
+            if(minerror > error[m]) {
+                minerror = error[m];
+                besterror = m;
+            }
+        }
+        mindiff = mindiff + (besterror * diffstep);
+        lastmindiff = mindiff;
+        maxdiff = mindiff + diffstep;
+        mindiff -= diffstep;
+    }
+    thisgrid = number[0];
+    for(n=0;n<cnt;n++) {
+        thisdiff = number[n] - thisgrid;
+        if(thisdiff < 0.0 && thisdiff > -FLTERR)
+            thisdiff = 0.0;
+        fprintf(stdout,"INFO: %lf\n",thisdiff);
+        thisgrid += lastmindiff;
+    }
+    fflush(stdout);
+}
+
+/****************************** SINUSOID ******************************/
+
+void sinusoid(void) {
+    double maxval  = number[0], minval  = number[1];
+    double range   = maxval - minval;
+    double phase   = (fmod(number[2],360.0)/360.0) * TWOPI;
+    double periods = number[3];
+    double valdens = number[4];
+    int n, valcnt = (int)floor((periods * valdens) + 1.0);
+    double val, phasestep = TWOPI/valdens;
+
+    for(n = 0; n < valcnt; n++) {
+        val = (sin(phase) + 1.0)/2.0;
+        val *= range;
+        val += minval;
+        fprintf(stdout,"INFO: %lf\n",val);
+        phase = phase + phasestep; /* should be fmod by TWOPI, but seems to work without this */
+    }
+    fflush(stdout);
+}
+
+/****************************** RAND_INTS_WITH_FIXED_ENDS ****************************/
+
+void rand_ints_with_fixed_ends(void)
+{
+    int z, n, m, i, k, j, j1, j2, repets, fullperms, partperm, startval, finval;
+    int range, rangbot, arrsiz, endcnt, endval, allowed, checkpart, done = 0;
+    int *arr, *arr2, *perm;
+
+    repets = round(number[5]);
+    startval = round(number[3]);
+    finval   = round(number[4]);
+    j1 = round(number[1]);
+    j2 = round(number[2]);
+    range = abs(j2 - j1) + 1;
+    rangbot = (int)min(j1,j2);
+    arrsiz = range * repets;
+    ifactor = round(number[0]) - 2;
+    fullperms = ifactor / arrsiz;
+    partperm = ifactor - (fullperms * arrsiz);
+    if(partperm == 0) {
+        fullperms--;            /* The last set of vals has to be calculated separately */
+        partperm = arrsiz;      /* as, unlike others, it will have to be compared with the finval */
+    }
+
+    if((arr = (int *)malloc(arrsiz * sizeof(int)))==NULL) {
+        fprintf(stdout,"ERROR: Out of memory.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    if((perm = (int *)malloc(arrsiz * sizeof(int)))==NULL) {
+        fprintf(stdout,"ERROR: Out of memory.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    if((arr2 = (int *)malloc(repets * sizeof(int)))==NULL) {
+        fprintf(stdout,"ERROR: Out of memory.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    n = 0;
+    for(j=0;j<repets;j++) {                                 /* fill array with REPET copies of values. */
+        z = rangbot;                                            /* this set can be permd AS A WHOLE, as repet adjacent copies of any val */
+        for(i=0;i<range;i++)                            /* which might arise in perming this set, are allowed */
+            arr[n++] = z++;
+    }
+    endcnt = 0;                                                             /* number of items repeated at end of previous perm */
+    endval = startval;                                              /* value (possibly repeated) at end of previous perm */
+    /* initially this is just the 'startval' fixed by the user */
+    allowed = repets - 1;                                   /* number of permissible repetitions of this val at start of NEW perm */
+    checkpart = arrsiz - repets;                    /* items at end of array to test for repetitions */
+    n = 0;
+    fprintf(stdout,"INFO: %d\n",startval);  /* Output user-specified first value */
+    while(n < fullperms) {
+        do_repet_restricted_perm(arr,perm,arrsiz,allowed,endval);
+        j = 0;
+        for(m = 0;m <arrsiz;m++) {
+            k = arr[perm[m]];
+            fprintf(stdout,"INFO: %d\n",k);
+            if(m >= checkpart)                              /* save last checkable stretch of perm */
+                arr2[j++] = k;
+        }
+        fflush(stdout);
+        j--;
+        endval = arr2[j--];                                     /* note the val at end of perm */
+        endcnt = 1;                                                     /* and count it */
+        for(k = j; k>= 0; k--) {
+            if(arr2[k] == endval)                   /* check adjacent vals, for repetition of value: count */
+                endcnt++;
+            else                                                    /* if no more repetitions, finish counting */
+                break;
+        }
+        allowed = repets - endcnt;                      /* get number of permissible repets at start of next perm */
+        n++;
+    }
+    k = partperm - 1;       /* index of last item of next perm which will actually be outputted */
+    j = repets - 1;         /* How many items at end of partperm, other than item k, which need to be checked for value-repetition */
+    while(!done) {
+        do_repet_restricted_perm(arr,perm,arrsiz,allowed,endval);
+        for(n=k;n>=k - j;n--) {
+            if(arr[perm[n]] == finval) {    /* Check end vals of the-set-of-values-in-the-final-perm-which-will-actually-be-outputted */
+                if(allowed == 0)                        /* against 'finval', to avoid too many value-repetitions at end of output */
+                    break;
+                else
+                    allowed--;
+            } else {
+                done = 1;
+                break;
+            }
+        }
+    }
+    for(m = 0;m <partperm;m++) {
+        k = arr[perm[m]];
+        fprintf(stdout,"INFO: %d\n",k);
+    }
+    fprintf(stdout,"INFO: %d\n",finval);
+    fflush(stdout);
+}
+
+/****************************** RAND_ZIGS ****************************/
+
+void rand_zigs(void)
+{
+    int n, k, j, j1, j2, finval, range, rangbot, arrsiz, outvals, lastval, t, done;
+    int *arr, *perm;
+
+    outvals = round(number[0]);
+    j1 = round(number[1]);
+    j2 = round(number[2]);
+    finval = round(number[3]);
+    range = abs(j2 - j1) + 1;
+    rangbot = (int)min(j1,j2);
+    if(finval < rangbot || finval > (int)max(j1,j2)) {
+        fprintf(stdout,"ERROR: Final value specified does not lie within the range of values specified.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    arrsiz = range;
+    if((arr = (int *)malloc(arrsiz * sizeof(int)))==NULL) {
+        fprintf(stdout,"ERROR: Out of memory.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    if((perm = (int *)malloc(arrsiz * sizeof(int)))==NULL) {
+        fprintf(stdout,"ERROR: Out of memory.\n");
+        fflush(stdout);
+        exit(1);
+    }
+    k = rangbot;                                            /* this set can be permd AS A WHOLE, as repet adjacent copies of any val */
+    for(n=0;n<range;n++)                            /* which might arise in perming this set, are allowed */
+        arr[n] = k++;
+    j = 0;
+    lastval = rangbot - 1;
+    done = 0;
+    while(j < outvals) {
+        for(n=0;n<arrsiz;n++) {
+            t = (int)(drand48() * (double)(n+1)); /* Do Perm */
+            if(t==n)
+                hhprefix(n,arrsiz,perm);
+            else
+                hhinsert(n,t,arrsiz,perm);
+        }
+        for(n=0;n<arrsiz;n++) {
+            if (lastval < arr[perm[n]])  {
+                k = lastval + 1;
+                while(k < arr[perm[n]]) {
+                    fprintf(stdout,"INFO: %d\n",k);
+                    if(++j >= outvals) {
+                        lastval = k;
+                        done = 1;
+                        break;
+                    }
+                    k++;
+                }
+            } else if(lastval > arr[perm[n]]) {
+                k = lastval - 1;
+                while(k > arr[perm[n]]) {
+                    fprintf(stdout,"INFO: %d\n",k);
+                    if(++j >= outvals) {
+                        lastval = k;
+                        done = 1;
+                        break;
+                    }
+                    k--;
+                }
+            } else {                /* next perm val can only be equal to previous at join of two different perms */
+                break;          /* in this case, get a different perm */
+            }
+            if(done) {
+                break;
+            }
+            lastval = arr[perm[n]];
+            fprintf(stdout,"INFO: %d\n",lastval);
+            j++;
+        }
+    }
+    if(lastval < finval) {
+        lastval++;
+        while(lastval <= finval) {
+            fprintf(stdout,"INFO: %d\n",lastval);
+            lastval++;
+        }
+    } else if(lastval > finval) {
+        lastval--;
+        while(lastval >= finval) {
+            fprintf(stdout,"INFO: %d\n",lastval);
+            lastval--;
+        }
+    }
+    fflush(stdout);
+}
+
+/************************** ELIMINATE_DUPLTEXT *************************/
+
+void eliminate_dupltext(void)
+{
+    int m,n,k;
+    for(n=0;n<stringscnt-1;n++) {
+        for(m=n+1;m<stringscnt;m++) {
+            if(!strcmp(strings[n],strings[m])) {
+                for(k = m;k < stringscnt-1; k++)
+                    strings[k] = strings[k+1];
+                m--;
+                stringscnt--;
+            }
+        }
+    }
+    for(n=0; n < stringscnt;n++)
+        do_stringout(strings[n]);
+    fflush(stdout);
+}
+
+/************************** RANDOM_WARP *************************/
+
+void random_warp(void)
+{
+    int n, wcnt;
+    float *warpvals, *number2;
+    double lastsum, diff, warp, dummy;
+    FILE *fp;
+    char *p;
+    arraysize = 100;
+    if((warpvals = (float *)malloc(arraysize * sizeof(float)))==NULL) {
+        fprintf(stdout,"ERROR: Out of memory.\n");
+        fflush(stdout);
+        return;
+    }
+    if((fp = fopen(string,"r"))==NULL) {
+        sprintf(errstr,"Cannot open infile %s\n",string);
+        do_error();
+    }
+    wcnt = 0;
+    while(fgets(temp,20000,fp)!=NULL) {
+        p = temp;
+        while(strgetfloat(&p,&dummy)) {
+            warpvals[wcnt] = (float)dummy;
+            if(++wcnt >= arraysize) {
+                arraysize += BIGARRAY;
+                if((number2=(float *)malloc(arraysize*sizeof(float)))==NULL) {
+                    sprintf(errstr,"Out of memory for more warp values at %d numbers\n",cnt);
+                    do_error();
+                }
+                memcpy((void *)number2,(void *)warpvals,cnt * sizeof(float));
+                warpvals = number2;
+            }
+        }
+    }
+    fclose(fp);
+    if(wcnt ==0 || (wcnt & 1)) {
+        sprintf(errstr,"Invalid or missing warp data.\n");
+        do_error();
+    }
+    lastsum = number[0];
+    do_valout(lastsum);
+    for(n=1;n<cnt;n++) {
+        diff = number[n] - number[n-1];
+        warp = readbrk(warpvals,number[n],wcnt);
+        warp = (((drand48() * 2.0) - 1.0) * warp) + 1.0;
+        diff *= warp;
+        lastsum += diff;
+        do_valout(lastsum);
+    }
+}
+
+double readbrk(float *warpvals,double time,int wcnt)
+{
+    int n, got = 0;
+    double wlasttime = 0.0, wlastval=0.0, wthistime=0.0, wthisval=0.0, val;
+    double timeratio, valdiff;
+    for(n = 0; n< wcnt; n+= 2) {
+        if(warpvals[n] < time) {
+            wlasttime = warpvals[n];
+            wlastval  = warpvals[n+1];
+        } else {
+            wthistime = warpvals[n];
+            wthisval  = warpvals[n+1];
+            got = 1;
+            break;
+        }
+    }
+    if(!got)
+        return (double)warpvals[wcnt - 1];
+    valdiff   = wthisval  - wlastval;
+    timeratio = (time - wlasttime)/(wthistime - wlasttime);
+    val = (valdiff * timeratio) + wlastval;
+    return val;
+}

File diff suppressed because it is too large
+ 479 - 479
dev/tabedit/columns6.c


+ 190 - 191
dev/tabedit/getcol.c

@@ -5,20 +5,20 @@
  *
  *
  This file is part of the CDP System.
  This file is part of the CDP System.
 
 
-    The CDP System is free software; you can redistribute it
-    and/or modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    The CDP System is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with the CDP System; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-    02111-1307 USA
+ The CDP System is free software; you can redistribute it
+ and/or modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The CDP System is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the CDP System; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA
  *
  *
  */
  */
 
 
@@ -35,143 +35,143 @@
 #include <math.h>
 #include <math.h>
 #include <string.h>
 #include <string.h>
 
 
-#define PROG 	 "GETCOL"
+#define PROG     "GETCOL"
 #define ENDOFSTR '\0'
 #define ENDOFSTR '\0'
 
 
-FILE 	*fp1, *fpout;
-char	*skip_column(char *,int,char *);
-char	*skip_column_wanted(char *,int,char *);
-void 	usage(void), logo(void);
+FILE    *fp1, *fpout;
+char    *skip_column(char *,int,char *);
+char    *skip_column_wanted(char *,int,char *);
+void    usage(void), logo(void);
 
 
-int		ignore_s_and_e = 0, ignore_c = 0;
-int		sloom = 0;
-int		sloombatch = 0;
+int             ignore_s_and_e = 0, ignore_c = 0;
+int             sloom = 0;
+int             sloombatch = 0;
 const char* cdp_version = "7.1.0";
 const char* cdp_version = "7.1.0";
 
 
 int main(int argc,char *argv[])
 int main(int argc,char *argv[])
-{   
-	char temp[2000], *p, *q;
-	int n, skip=0, column, cnt=0;
-
-	if(argc==2 && (strcmp(argv[1],"--version") == 0)) {
-		fprintf(stdout,"%s\n",cdp_version);
-		fflush(stdout);
-		return 0;
-	}
-/* VERSION 3 */
-	if(argc < 2)
-		usage();
-	if(!strcmp(argv[1],"#")) {
-		sloom = 1;
-		argv++;
-		argc--;
-	} else if (!strcmp(argv[1],"##")) {
-		p = argv[0];
-		argc--;
-		argv++;
-		argv[0] = p;
-		sloombatch = 1;
-	}
-
-
-
-
-	if(!strcmp(argv[argc-1],"-e")) {
-		ignore_s_and_e = 1;
-		argc--;
-	} else 	if(!strcmp(argv[argc-1],"-ec")) {
-		ignore_c = 1;
-		argc--;
-	}
-	if(argc<4 || argc>5)
-		usage();
-	if((fp1 = fopen(argv[1],"r"))==NULL) {
-		fprintf(stdout,"ERROR: Cannot open file '%s'\n",argv[1]);
-		fflush(stdout);
-		usage();
-	}
-	if((fpout = fopen(argv[2],"w"))==NULL) {
-		fprintf(stdout,"ERROR: Cannot open file '%s'\n",argv[2]);
-		fflush(stdout);
-		usage();
-	}
-	if(sscanf(argv[3],"%d",&column)!=1) {
-		fprintf(stdout,"ERROR: Cannot read column value.\n");
-		fflush(stdout);
-		usage();
-	}
-	if(column<1) {
-		fprintf(stdout,"ERROR: Column value cannot be less than 1.\n");
-		fflush(stdout);
-		usage();
-	}
-	column--;
-	if(argc==5 && sscanf(argv[4],"%d",&skip)!=1) {
-		fprintf(stdout,"ERROR: Cannot read skip value.\n");
-		fflush(stdout);
-		usage();
-	}
-	for(n=0;n<skip;n++) {
-		if(fgets(temp,200,fp1)!=temp) {
-			fprintf(stdout,"ERROR: Failed to get skippable line %d in file '%s'\n",
-			n+1,argv[1]);
-			fflush(stdout);
-			exit(1);
-		}
-		q = temp;				/* IGNORE EMPTY LINES */
-		p = temp;
-		while(*p != ENDOFSTR) {
-			if(isspace(*p))
-				q++;
-			p++;
-		}
-		if(p==q)
-			n--;
-	}
-	while(fgets(temp,2000,fp1)!=NULL) {
-		cnt++;
-		p = temp;
-/*RWD*/	while(isspace(*p)) p++;
-/*and*/	if(*p=='\n' || *p==ENDOFSTR){
-			if(!sloom && !sloombatch)
-				fputs("\n",fpout);
-			else
-				fprintf(stdout,"INFO: \n");
-			continue;
-		}
-		if(ignore_s_and_e && (!strcmp(temp,"e\n") || !strcmp(temp,"e") || !strcmp(temp,"s\n") || !strncmp(temp,";",1)))
-			continue;
-		if(ignore_c && !strncmp(temp,";",1))
-			continue;
-		for(n=0;n<column;n++) {
-			if(*p==ENDOFSTR) {
-				fprintf(stdout,"ERROR: Not enough columns in line %d.\n",cnt);
-				fflush(stdout);
-				exit(1);
-			}
-			p = skip_column(p,cnt,argv[1]);
-		}
-		q = p;
-		if(*p==ENDOFSTR) {
-			fprintf(stdout,"ERROR: Not enough columns in line %d.\n",cnt);
-			fflush(stdout);
-			exit(1);
-		}
-		p = skip_column_wanted(p,cnt,argv[1]);
-		if(*p==ENDOFSTR) {
-			p--;	/* DELETE NEWLINE */
-			if(*p!='\n')
-				p++;
-		}
-		*p = ENDOFSTR;
-		if(!sloom && !sloombatch) {
-			fputs(q,fpout);
-			fputs("\n",fpout);
-		} else
-			fprintf(stdout,"INFO: %s\n",q);
-	}
-	fflush(stdout);
-	return 0;
+{
+    char temp[2000], *p, *q;
+    int n, skip=0, column, cnt=0;
+
+    if(argc==2 && (strcmp(argv[1],"--version") == 0)) {
+        fprintf(stdout,"%s\n",cdp_version);
+        fflush(stdout);
+        return 0;
+    }
+    /* VERSION 3 */
+    if(argc < 2)
+        usage();
+    if(!strcmp(argv[1],"#")) {
+        sloom = 1;
+        argv++;
+        argc--;
+    } else if (!strcmp(argv[1],"##")) {
+        p = argv[0];
+        argc--;
+        argv++;
+        argv[0] = p;
+        sloombatch = 1;
+    }
+
+
+
+
+    if(!strcmp(argv[argc-1],"-e")) {
+        ignore_s_and_e = 1;
+        argc--;
+    } else  if(!strcmp(argv[argc-1],"-ec")) {
+        ignore_c = 1;
+        argc--;
+    }
+    if(argc<4 || argc>5)
+        usage();
+    if((fp1 = fopen(argv[1],"r"))==NULL) {
+        fprintf(stdout,"ERROR: Cannot open file '%s'\n",argv[1]);
+        fflush(stdout);
+        usage();
+    }
+    if((fpout = fopen(argv[2],"w"))==NULL) {
+        fprintf(stdout,"ERROR: Cannot open file '%s'\n",argv[2]);
+        fflush(stdout);
+        usage();
+    }
+    if(sscanf(argv[3],"%d",&column)!=1) {
+        fprintf(stdout,"ERROR: Cannot read column value.\n");
+        fflush(stdout);
+        usage();
+    }
+    if(column<1) {
+        fprintf(stdout,"ERROR: Column value cannot be less than 1.\n");
+        fflush(stdout);
+        usage();
+    }
+    column--;
+    if(argc==5 && sscanf(argv[4],"%d",&skip)!=1) {
+        fprintf(stdout,"ERROR: Cannot read skip value.\n");
+        fflush(stdout);
+        usage();
+    }
+    for(n=0;n<skip;n++) {
+        if(fgets(temp,200,fp1)!=temp) {
+            fprintf(stdout,"ERROR: Failed to get skippable line %d in file '%s'\n",
+                    n+1,argv[1]);
+            fflush(stdout);
+            exit(1);
+        }
+        q = temp;                               /* IGNORE EMPTY LINES */
+        p = temp;
+        while(*p != ENDOFSTR) {
+            if(isspace(*p))
+                q++;
+            p++;
+        }
+        if(p==q)
+            n--;
+    }
+    while(fgets(temp,2000,fp1)!=NULL) {
+        cnt++;
+        p = temp;
+        /*RWD*/ while(isspace(*p)) p++;
+        /*and*/ if(*p=='\n' || *p==ENDOFSTR){
+            if(!sloom && !sloombatch)
+                fputs("\n",fpout);
+            else
+                fprintf(stdout,"INFO: \n");
+            continue;
+        }
+        if(ignore_s_and_e && (!strcmp(temp,"e\n") || !strcmp(temp,"e") || !strcmp(temp,"s\n") || !strncmp(temp,";",1)))
+            continue;
+        if(ignore_c && !strncmp(temp,";",1))
+            continue;
+        for(n=0;n<column;n++) {
+            if(*p==ENDOFSTR) {
+                fprintf(stdout,"ERROR: Not enough columns in line %d.\n",cnt);
+                fflush(stdout);
+                exit(1);
+            }
+            p = skip_column(p,cnt,argv[1]);
+        }
+        q = p;
+        if(*p==ENDOFSTR) {
+            fprintf(stdout,"ERROR: Not enough columns in line %d.\n",cnt);
+            fflush(stdout);
+            exit(1);
+        }
+        p = skip_column_wanted(p,cnt,argv[1]);
+        if(*p==ENDOFSTR) {
+            p--;    /* DELETE NEWLINE */
+            if(*p!='\n')
+                p++;
+        }
+        *p = ENDOFSTR;
+        if(!sloom && !sloombatch) {
+            fputs(q,fpout);
+            fputs("\n",fpout);
+        } else
+            fprintf(stdout,"INFO: %s\n",q);
+    }
+    fflush(stdout);
+    return 0;
 }
 }
 
 
 /******************************** USAGE *****************************/
 /******************************** USAGE *****************************/
@@ -179,67 +179,66 @@ int main(int argc,char *argv[])
 
 
 void usage(void)
 void usage(void)
 {
 {
-	if(!sloom && !sloombatch) {
-		logo();
-		fprintf(stderr,"USAGE : getcol infile outfile colno [skiplines] [-e]\n\n");
-		fprintf(stderr,"skiplines  Ignores this number of lines at start of file.\n");
-		fprintf(stderr,"-e         Ignores lines with a single 'e' or 's' (as in CSound scores)\n");
-		fprintf(stderr,"           and comment lines starting with ';'\n");
-		fprintf(stderr,"           (skipped lines should still be counted).\n");
-	}
-	exit(1);
+    if(!sloom && !sloombatch) {
+        logo();
+        fprintf(stderr,"USAGE : getcol infile outfile colno [skiplines] [-e]\n\n");
+        fprintf(stderr,"skiplines  Ignores this number of lines at start of file.\n");
+        fprintf(stderr,"-e         Ignores lines with a single 'e' or 's' (as in CSound scores)\n");
+        fprintf(stderr,"           and comment lines starting with ';'\n");
+        fprintf(stderr,"           (skipped lines should still be counted).\n");
+    }
+    exit(1);
 }
 }
 
 
 /*************************** SKIP_COLUMN **************************/
 /*************************** SKIP_COLUMN **************************/
 
 
 char *skip_column(char *p,int cnt,char *argv)
 char *skip_column(char *p,int cnt,char *argv)
 {
 {
-	if(*p==ENDOFSTR) {
-		fprintf(stdout,"ERROR: Not enough columns in line %d file %s\n",cnt,argv);
-		fflush(stdout);
-		exit(0);
-	}
- 	while(!isspace(*p)) {
-		p++;
-		if(*p==ENDOFSTR)
-			return(p);
-	}
-	while(isspace(*p)) {
-		p++;
-		if(*p==ENDOFSTR)
-			return(p);
-   }
-   return(p);
+    if(*p==ENDOFSTR) {
+        fprintf(stdout,"ERROR: Not enough columns in line %d file %s\n",cnt,argv);
+        fflush(stdout);
+        exit(0);
+    }
+    while(!isspace(*p)) {
+        p++;
+        if(*p==ENDOFSTR)
+            return(p);
+    }
+    while(isspace(*p)) {
+        p++;
+        if(*p==ENDOFSTR)
+            return(p);
+    }
+    return(p);
 }
 }
 
 
 /*************************** SKIP_COLUMN_WANTED **************************/
 /*************************** SKIP_COLUMN_WANTED **************************/
 
 
 char *skip_column_wanted(char *p,int cnt,char *argv)
 char *skip_column_wanted(char *p,int cnt,char *argv)
 {
 {
-	if(*p==ENDOFSTR) {
-		fprintf(stdout,"ERROR: Not enough columns in line %d file %s\n",cnt,argv);
-		fflush(stdout);
-		exit(0);
-	}
- 	while(!isspace(*p++)) {
-		if(*p==ENDOFSTR)
-			return(p);
-	}
-	return(p);
+    if(*p==ENDOFSTR) {
+        fprintf(stdout,"ERROR: Not enough columns in line %d file %s\n",cnt,argv);
+        fflush(stdout);
+        exit(0);
+    }
+    while(!isspace(*p++)) {
+        if(*p==ENDOFSTR)
+            return(p);
+    }
+    return(p);
 }
 }
 
 
 /******************************** LOGO() **********************************/
 /******************************** LOGO() **********************************/
 
 
 void logo(void)
 void logo(void)
-{   
-	printf("\t    ***************************************************\n");
-	printf("\t    *            COMPOSERS DESKTOP PROJECT            *\n");
-	printf("\t                    %s $Revision: 1.2 $\n",PROG);
-	printf("\t    *                                                 *\n");
-	printf("\t    *   get Nth column from a file of columned data   *\n");
-	printf("\t    *      (skipping M lines at start of file).       *\n");
-	printf("\t    *                                                 *\n");
-	printf("\t    *                by TREVOR WISHART                *\n");
-	printf("\t    ***************************************************\n\n");
+{
+    printf("\t    ***************************************************\n");
+    printf("\t    *            COMPOSERS DESKTOP PROJECT            *\n");
+    printf("\t                    %s $Revision: 1.2 $\n",PROG);
+    printf("\t    *                                                 *\n");
+    printf("\t    *   get Nth column from a file of columned data   *\n");
+    printf("\t    *      (skipping M lines at start of file).       *\n");
+    printf("\t    *                                                 *\n");
+    printf("\t    *                by TREVOR WISHART                *\n");
+    printf("\t    ***************************************************\n\n");
 }
 }
-

+ 301 - 302
dev/tabedit/putcol.c

@@ -5,20 +5,20 @@
  *
  *
  This file is part of the CDP System.
  This file is part of the CDP System.
 
 
-    The CDP System is free software; you can redistribute it
-    and/or modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+ The CDP System is free software; you can redistribute it
+ and/or modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
 
 
-    The CDP System is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Lesser General Public License for more details.
+ The CDP System is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU Lesser General Public License for more details.
 
 
-    You should have received a copy of the GNU Lesser General Public
-    License along with the CDP System; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-    02111-1307 USA
+ You should have received a copy of the GNU Lesser General Public
+ License along with the CDP System; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA
  *
  *
  */
  */
 
 
@@ -37,323 +37,322 @@
 
 
 FILE *fp2, *fp1, *fpout;
 FILE *fp2, *fp1, *fpout;
 
 
-#define PROG 	"PUTCOL"
+#define PROG    "PUTCOL"
 #define NEW_COL_SPACE (128)
 #define NEW_COL_SPACE (128)
 
 
 #define ENDOFSTR '\0'
 #define ENDOFSTR '\0'
 #define NEWLINE  '\n'
 #define NEWLINE  '\n'
-#define	TAB	 '\t'
+#define TAB      '\t'
 
 
-void 	usage(void), logo(void);
-char 	*skip_column(char *,int,char *);
-int 	sloom = 0;
-int 	sloombatch = 0;
+void    usage(void), logo(void);
+char    *skip_column(char *,int,char *);
+int     sloom = 0;
+int     sloombatch = 0;
 
 
-int		ignore_s_and_e = 0, ignore_c = 0;
+int             ignore_s_and_e = 0, ignore_c = 0;
 
 
-char	errstr[400];
+char    errstr[400];
 const char* cdp_version = "7.1.0";
 const char* cdp_version = "7.1.0";
 
 
 int main(int argc,char *argv[])
 int main(int argc,char *argv[])
 {
 {
-	char temp[400], temp2[400], *p, *q, c;
-	int n, skip = 0, column, cnt=0, replace = 0, end_col = 0, keep = 1, outlinecnt, newlen;
-	char **line = (char **)0;
-	if(argc==2 && (strcmp(argv[1],"--version") == 0)) {
-		fprintf(stdout,"%s\n",cdp_version);
-		fflush(stdout);
-		return 0;
-	}
-	if(argc < 2)
-		usage();
-	if(!strcmp(argv[1],"#")) {
-		sloom = 1;
-		argv++;
-		argc--;
-	} else if (!strcmp(argv[1],"##")) {
-		p = argv[0];
-		argc--;
-		argv++;
-		argv[0] = p;
-		sloombatch = 1;
-	}
-	if(!strcmp(argv[argc-1],"-e")) {
-		ignore_s_and_e = 1;
-		argc--;
-	}
-	if(!strcmp(argv[argc-1],"-ec")) {
-		ignore_c = 1;
-		argc--;
-	}
-	if(argc<6 || argc>7)
-		usage();
+    char temp[400], temp2[400], *p, c;
+    int n, skip = 0, column, cnt=0, replace = 0, end_col = 0, keep = 1, outlinecnt, newlen;
+    char **line = (char **)0;
+    if(argc==2 && (strcmp(argv[1],"--version") == 0)) {
+        fprintf(stdout,"%s\n",cdp_version);
+        fflush(stdout);
+        return 0;
+    }
+    if(argc < 2)
+        usage();
+    if(!strcmp(argv[1],"#")) {
+        sloom = 1;
+        argv++;
+        argc--;
+    } else if (!strcmp(argv[1],"##")) {
+        p = argv[0];
+        argc--;
+        argv++;
+        argv[0] = p;
+        sloombatch = 1;
+    }
+    if(!strcmp(argv[argc-1],"-e")) {
+        ignore_s_and_e = 1;
+        argc--;
+    }
+    if(!strcmp(argv[argc-1],"-ec")) {
+        ignore_c = 1;
+        argc--;
+    }
+    if(argc<6 || argc>7)
+        usage();
 
 
-	if(!sloom) {
-		if(!strcmp(argv[3],argv[2]) || !strcmp(argv[3],argv[1])) {
-			fprintf(stdout,"ERROR: Cannot use same file for input and ouput.\n");
-			fflush(stdout);
-			usage();
-		}
-		if((fpout = fopen(argv[3],"w"))==NULL) {
-			fprintf(stdout,"ERROR: Cannot open file '%s'\n",argv[3]);
-			fflush(stdout);
-			usage();
-		}
-	}
-	if((fp1 = fopen(argv[1],"r"))==NULL) {
-		fprintf(stdout,"ERROR: Cannot open file '%s'\n",argv[1]);
-		fflush(stdout);
-		usage();
-	}
-	if((fp2 = fopen(argv[2],"r"))==NULL) {
-		fprintf(stdout,"ERROR: Cannot open file '%s'\n",argv[2]);
-		fflush(stdout);
-		usage();
-	}
-	if(sscanf(argv[4],"%d",&column)!=1) {
-		fprintf(stdout,"ERROR: Cannot read column value.\n");
-		fflush(stdout);
-		usage();
-	}
-	if(column<1) {
-		fprintf(stdout,"ERROR: Column value cannot be less than 1.\n");
-		fflush(stdout);
-		usage();
-	}
-	column--;
-	if(argc==7 && sscanf(argv[6],"%d",&skip)!=1) {
-		fprintf(stdout,"ERROR: Cannot read skip value.\n");
-		fflush(stdout);
-		usage();
-	}
-	if(skip<0) {
-		skip = -skip;
-		keep = 0;
-	}
-	if(*argv[5]++!='-') {
-		fprintf(stdout,"ERROR: Unknown parameter %s.\n",--argv[5]);
-		fflush(stdout);
-		usage();
-	}
-	switch(*argv[5]) {
-	case('r'): replace = 1; break;
-	case('i'):	break;
-	default:
-		fprintf(stdout,"ERROR: Unknown flag -%c\n",*argv[5]);
-		fflush(stdout);
-		usage();
-	}
-	outlinecnt = 0;
-	if(skip > 0) {
-		if(keep) {
-			if((line = (char **)malloc(skip * sizeof(char *)))==NULL) {
-				fprintf(stdout,"ERROR: Out of memory\n");
-				fflush(stdout);
-			}			
-		}
-		for(n=0;n<skip;n++) {
-			if(fgets(temp,400,fp2)!=temp) {
-				fprintf(stdout,"ERROR: Failed to get skippable line %d in file '%s'\n",n+1,argv[1]);
-				fflush(stdout);
-				exit(1);
-			}
-			if(keep) {
-				if((line[outlinecnt] = (char *)malloc((strlen(temp)+2) * sizeof(char)))==NULL) {
-					fprintf(stdout,"ERROR: Out of memory\n");
-					fflush(stdout);
-				}			
-				line[outlinecnt][0] = ENDOFSTR;
-				strcat(line[outlinecnt],temp);
-				outlinecnt++;
-			}
-		}
-	}
-	while(fgets(temp,400,fp2)!=NULL) {
-/*RWD*/ p = temp;
-/*RWD*/ while(isspace(*p)) p++;
-/*and*/	if(*p=='\n' || *p == ENDOFSTR){
-			if((line = (char **)realloc((char *)line,(outlinecnt+1) * sizeof(char *)))==NULL) {
-				fprintf(stdout,"ERROR: Out of memory\n");
-				fflush(stdout);
-			}			
-			if((line[outlinecnt] = (char *)malloc(2 * sizeof(char)))==NULL) {
-				fprintf(stdout,"ERROR: Out of memory\n");
-				fflush(stdout);
-			}			
-			line[outlinecnt][0] = ENDOFSTR;
-			outlinecnt++;
-			continue;
-		}
-		if((ignore_s_and_e && (!strcmp(temp,"e\n") || !strcmp(temp,"e") || !strcmp(temp,"s\n") || !strncmp(temp,";",1)))
-		|| (ignore_c && !strncmp(temp,";",1))) {
-			if(line==(char **)0) {
-				if((line = (char **)malloc((outlinecnt+1) * sizeof(char *)))==NULL) {
-					fprintf(stdout,"ERROR: Out of memory\n");
-					fflush(stdout);
-				}			
-			} else {
-				if((line = (char **)realloc((char *)line,(outlinecnt+1) * sizeof(char *)))==NULL) {
-					fprintf(stdout,"ERROR: Out of memory\n");
-					fflush(stdout);
-				}			
-			}
-			if((line[outlinecnt] = (char *)malloc((strlen(temp)+2) * sizeof(char)))==NULL) {
-				fprintf(stdout,"ERROR: Out of memory\n");
-				fflush(stdout);
-			}			
-			line[outlinecnt][0] = ENDOFSTR;
-			strcat(line[outlinecnt],temp);
-			outlinecnt++;
-			continue;
-		}
-		cnt++;
-		end_col = 0;
-		q = p;
-		for(n=0;n<column;n++) {
-			if(*p==ENDOFSTR) {
-				fprintf(stdout,"ERROR: Not enough columns in line %d in origfile.\n",cnt);
-				fflush(stdout);
-				exit(1);
-			}
-			p = skip_column(p,cnt,argv[1]);
-		}
-		if(*p==ENDOFSTR) {
-			if(replace) {
-				fprintf(stdout,"ERROR: Not enough columns in line %d in origfile.\n",cnt);
-				fflush(stdout);
-				exit(1);
-			} else {
-				p--;	/* HANG ONTO NEWLINE */
-				if(*p != NEWLINE)
-					p++;
-				end_col = 1;		
-			}	
-		}
-		c = *p;
-		*p = ENDOFSTR;
-		if(line==(char **)0) {
-			if((line = (char **)malloc((outlinecnt+1) * sizeof(char *)))==NULL) {
-				fprintf(stdout,"ERROR: Out of memory\n");
-				fflush(stdout);
-			}			
-		} else {
-			if((line = (char **)realloc((char *)line,(outlinecnt+1) * sizeof(char *)))==NULL) {
-				fprintf(stdout,"ERROR: Out of memory\n");
-				fflush(stdout);
-			}			
-		}
-		if((line[outlinecnt] = (char *)malloc((strlen(temp)+2+NEW_COL_SPACE) * sizeof(char)))==NULL) {
-			fprintf(stdout,"ERROR: Out of memory\n");
-			fflush(stdout);
-		}			
-		line[outlinecnt][0] = ENDOFSTR;
-		strcat(line[outlinecnt],temp);
-		if(end_col)
-			strcat(line[outlinecnt],"\t");
-		*p = c;
-		if(replace) {
-			p = skip_column(p,cnt,argv[1]);
-			if(*p==ENDOFSTR) {
-				p--;		/* KEEP NEWLINE !!! */
-				if(*p != NEWLINE)
-					p++;
-				end_col = 1;
-			}
-		}
-		strcpy(temp2,p);
-   		if(fgets(temp,400,fp1)==NULL) {
-			fprintf(stdout,"ERROR: No more vals in file %s at line %d\n",argv[1],cnt);
-			fflush(stdout);
-			break;
-		}
-		p = temp + strlen(temp);
-		p--;	/* DELETE NEWLINE */
-		if(*p != NEWLINE)
-			p++;
-		if(!end_col)
-			*p++ = TAB;
-		*p = ENDOFSTR;
-		strcat(temp,temp2);
-		newlen = strlen(line[outlinecnt]) + strlen(temp) + 2;
-		if((line[outlinecnt] = (char *)realloc((char *)line[outlinecnt],newlen * sizeof(char)))==NULL) {
-			fprintf(stdout,"ERROR: Memory problem.\n");
-			fflush(stdout);
-		}			
-		strcat(line[outlinecnt],temp);
-		outlinecnt++;
-	}
-	if(sloom) {
-		if((fpout = fopen(argv[3],"w"))==NULL) {
-			fprintf(stdout,"ERROR: Cannot reopen file '%s'\n",argv[3]);
-			fflush(stdout);
-			usage();
-		}
-	}
-	for(n=0;n<outlinecnt;n++) {
-		if(!sloom && !sloombatch) {
-			strcat(line[n],"\n");
-			fputs(line[n],fpout);
-		} else 
-			fprintf(stdout,"INFO: %s\n",line[n]);
-	}
-	fflush(stdout);
-	fclose(fp2);
-	fclose(fp1);
-	return 0;
+    if(!sloom) {
+        if(!strcmp(argv[3],argv[2]) || !strcmp(argv[3],argv[1])) {
+            fprintf(stdout,"ERROR: Cannot use same file for input and ouput.\n");
+            fflush(stdout);
+            usage();
+        }
+        if((fpout = fopen(argv[3],"w"))==NULL) {
+            fprintf(stdout,"ERROR: Cannot open file '%s'\n",argv[3]);
+            fflush(stdout);
+            usage();
+        }
+    }
+    if((fp1 = fopen(argv[1],"r"))==NULL) {
+        fprintf(stdout,"ERROR: Cannot open file '%s'\n",argv[1]);
+        fflush(stdout);
+        usage();
+    }
+    if((fp2 = fopen(argv[2],"r"))==NULL) {
+        fprintf(stdout,"ERROR: Cannot open file '%s'\n",argv[2]);
+        fflush(stdout);
+        usage();
+    }
+    if(sscanf(argv[4],"%d",&column)!=1) {
+        fprintf(stdout,"ERROR: Cannot read column value.\n");
+        fflush(stdout);
+        usage();
+    }
+    if(column<1) {
+        fprintf(stdout,"ERROR: Column value cannot be less than 1.\n");
+        fflush(stdout);
+        usage();
+    }
+    column--;
+    if(argc==7 && sscanf(argv[6],"%d",&skip)!=1) {
+        fprintf(stdout,"ERROR: Cannot read skip value.\n");
+        fflush(stdout);
+        usage();
+    }
+    if(skip<0) {
+        skip = -skip;
+        keep = 0;
+    }
+    if(*argv[5]++!='-') {
+        fprintf(stdout,"ERROR: Unknown parameter %s.\n",--argv[5]);
+        fflush(stdout);
+        usage();
+    }
+    switch(*argv[5]) {
+    case('r'): replace = 1; break;
+    case('i'):      break;
+    default:
+        fprintf(stdout,"ERROR: Unknown flag -%c\n",*argv[5]);
+        fflush(stdout);
+        usage();
+    }
+    outlinecnt = 0;
+    if(skip > 0) {
+        if(keep) {
+            if((line = (char **)malloc(skip * sizeof(char *)))==NULL) {
+                fprintf(stdout,"ERROR: Out of memory\n");
+                fflush(stdout);
+            }
+        }
+        for(n=0;n<skip;n++) {
+            if(fgets(temp,400,fp2)!=temp) {
+                fprintf(stdout,"ERROR: Failed to get skippable line %d in file '%s'\n",n+1,argv[1]);
+                fflush(stdout);
+                exit(1);
+            }
+            if(keep) {
+                if((line[outlinecnt] = (char *)malloc((strlen(temp)+2) * sizeof(char)))==NULL) {
+                    fprintf(stdout,"ERROR: Out of memory\n");
+                    fflush(stdout);
+                }
+                line[outlinecnt][0] = ENDOFSTR;
+                strcat(line[outlinecnt],temp);
+                outlinecnt++;
+            }
+        }
+    }
+    while(fgets(temp,400,fp2)!=NULL) {
+        /*RWD*/ p = temp;
+        /*RWD*/ while(isspace(*p)) p++;
+        /*and*/ if(*p=='\n' || *p == ENDOFSTR){
+            if((line = (char **)realloc((char *)line,(outlinecnt+1) * sizeof(char *)))==NULL) {
+                fprintf(stdout,"ERROR: Out of memory\n");
+                fflush(stdout);
+            }
+            if((line[outlinecnt] = (char *)malloc(2 * sizeof(char)))==NULL) {
+                fprintf(stdout,"ERROR: Out of memory\n");
+                fflush(stdout);
+            }
+            line[outlinecnt][0] = ENDOFSTR;
+            outlinecnt++;
+            continue;
+        }
+        if((ignore_s_and_e && (!strcmp(temp,"e\n") || !strcmp(temp,"e") || !strcmp(temp,"s\n") || !strncmp(temp,";",1)))
+           || (ignore_c && !strncmp(temp,";",1))) {
+            if(line==(char **)0) {
+                if((line = (char **)malloc((outlinecnt+1) * sizeof(char *)))==NULL) {
+                    fprintf(stdout,"ERROR: Out of memory\n");
+                    fflush(stdout);
+                }
+            } else {
+                if((line = (char **)realloc((char *)line,(outlinecnt+1) * sizeof(char *)))==NULL) {
+                    fprintf(stdout,"ERROR: Out of memory\n");
+                    fflush(stdout);
+                }
+            }
+            if((line[outlinecnt] = (char *)malloc((strlen(temp)+2) * sizeof(char)))==NULL) {
+                fprintf(stdout,"ERROR: Out of memory\n");
+                fflush(stdout);
+            }
+            line[outlinecnt][0] = ENDOFSTR;
+            strcat(line[outlinecnt],temp);
+            outlinecnt++;
+            continue;
+        }
+        cnt++;
+        end_col = 0;
+        for(n=0;n<column;n++) {
+            if(*p==ENDOFSTR) {
+                fprintf(stdout,"ERROR: Not enough columns in line %d in origfile.\n",cnt);
+                fflush(stdout);
+                exit(1);
+            }
+            p = skip_column(p,cnt,argv[1]);
+        }
+        if(*p==ENDOFSTR) {
+            if(replace) {
+                fprintf(stdout,"ERROR: Not enough columns in line %d in origfile.\n",cnt);
+                fflush(stdout);
+                exit(1);
+            } else {
+                p--;    /* HANG ONTO NEWLINE */
+                if(*p != NEWLINE)
+                    p++;
+                end_col = 1;
+            }
+        }
+        c = *p;
+        *p = ENDOFSTR;
+        if(line==(char **)0) {
+            if((line = (char **)malloc((outlinecnt+1) * sizeof(char *)))==NULL) {
+                fprintf(stdout,"ERROR: Out of memory\n");
+                fflush(stdout);
+            }
+        } else {
+            if((line = (char **)realloc((char *)line,(outlinecnt+1) * sizeof(char *)))==NULL) {
+                fprintf(stdout,"ERROR: Out of memory\n");
+                fflush(stdout);
+            }
+        }
+        if((line[outlinecnt] = (char *)malloc((strlen(temp)+2+NEW_COL_SPACE) * sizeof(char)))==NULL) {
+            fprintf(stdout,"ERROR: Out of memory\n");
+            fflush(stdout);
+        }
+        line[outlinecnt][0] = ENDOFSTR;
+        strcat(line[outlinecnt],temp);
+        if(end_col)
+            strcat(line[outlinecnt],"\t");
+        *p = c;
+        if(replace) {
+            p = skip_column(p,cnt,argv[1]);
+            if(*p==ENDOFSTR) {
+                p--;            /* KEEP NEWLINE !!! */
+                if(*p != NEWLINE)
+                    p++;
+                end_col = 1;
+            }
+        }
+        strcpy(temp2,p);
+        if(fgets(temp,400,fp1)==NULL) {
+            fprintf(stdout,"ERROR: No more vals in file %s at line %d\n",argv[1],cnt);
+            fflush(stdout);
+            break;
+        }
+        p = temp + strlen(temp);
+        p--;    /* DELETE NEWLINE */
+        if(*p != NEWLINE)
+            p++;
+        if(!end_col)
+            *p++ = TAB;
+        *p = ENDOFSTR;
+        strcat(temp,temp2);
+        newlen = strlen(line[outlinecnt]) + strlen(temp) + 2;
+        if((line[outlinecnt] = (char *)realloc((char *)line[outlinecnt],newlen * sizeof(char)))==NULL) {
+            fprintf(stdout,"ERROR: Memory problem.\n");
+            fflush(stdout);
+        }
+        strcat(line[outlinecnt],temp);
+        outlinecnt++;
+    }
+    if(sloom) {
+        if((fpout = fopen(argv[3],"w"))==NULL) {
+            fprintf(stdout,"ERROR: Cannot reopen file '%s'\n",argv[3]);
+            fflush(stdout);
+            usage();
+        }
+    }
+    for(n=0;n<outlinecnt;n++) {
+        if(!sloom && !sloombatch) {
+            strcat(line[n],"\n");
+            fputs(line[n],fpout);
+        } else
+            fprintf(stdout,"INFO: %s\n",line[n]);
+    }
+    fflush(stdout);
+    fclose(fp2);
+    fclose(fp1);
+    return 0;
 }
 }
 
 
 /******************************** USAGE *****************************/
 /******************************** USAGE *****************************/
 
 
 void usage(void)
 void usage(void)
 {
 {
-	if(!sloom) {
-		logo();
-		fprintf(stderr,"USAGE : putcol columnfile intofile outfile colno -r|-i [[-]skiplines] [-e]\n\n");
-		fprintf(stderr,"COLUMNFILE  File with NEW column.\n");
-		fprintf(stderr,"INTOFILE    File INTO which the new column goes.\n");
-		fprintf(stderr,"OUTFILE     Resultant file.\n");
-		fprintf(stderr,"COLNO       POSITION of the column to be added.\n");
-		fprintf(stderr,"-r          REPLACE original column.\n");
-		fprintf(stderr,"-i          INSERT new column amongst original columns.\n");
-		fprintf(stderr,"SKIPLINES   SKIP OVER skiplines before inserting column.\n");
-	    fprintf(stderr,"-SKIPLINES  THROW AWAY skiplines: then insert column.\n");
-		fprintf(stderr,"-e          Ignore lines which contain only 'e' or 's'.\n");
-		fprintf(stderr,"            and comment lines starting with ';'\n");
-		fprintf(stderr,"            (skipped lines should still be counted).\n");
-	}
-	exit(1);
+    if(!sloom) {
+        logo();
+        fprintf(stderr,"USAGE : putcol columnfile intofile outfile colno -r|-i [[-]skiplines] [-e]\n\n");
+        fprintf(stderr,"COLUMNFILE  File with NEW column.\n");
+        fprintf(stderr,"INTOFILE    File INTO which the new column goes.\n");
+        fprintf(stderr,"OUTFILE     Resultant file.\n");
+        fprintf(stderr,"COLNO       POSITION of the column to be added.\n");
+        fprintf(stderr,"-r          REPLACE original column.\n");
+        fprintf(stderr,"-i          INSERT new column amongst original columns.\n");
+        fprintf(stderr,"SKIPLINES   SKIP OVER skiplines before inserting column.\n");
+        fprintf(stderr,"-SKIPLINES  THROW AWAY skiplines: then insert column.\n");
+        fprintf(stderr,"-e          Ignore lines which contain only 'e' or 's'.\n");
+        fprintf(stderr,"            and comment lines starting with ';'\n");
+        fprintf(stderr,"            (skipped lines should still be counted).\n");
+    }
+    exit(1);
 }
 }
 
 
 /*************************** SKIP_COLUMN **************************/
 /*************************** SKIP_COLUMN **************************/
 
 
 char *skip_column(char *p,int cnt,char *argv)
 char *skip_column(char *p,int cnt,char *argv)
-{  
-	if(*p==ENDOFSTR) {
-		fprintf(stdout,"ERROR: Not enough columns in line %d file %s\n",cnt,argv);
-		fflush(stdout);
-		exit(0);
-	}
-	while(!isspace(*p)) {
-		p++;
-		if(*p==ENDOFSTR)  return(p);
-	}
-	while(isspace(*p)) {
-		p++;
-		if(*p==ENDOFSTR)  return(p);
-   }
-   return(p);
+{
+    if(*p==ENDOFSTR) {
+        fprintf(stdout,"ERROR: Not enough columns in line %d file %s\n",cnt,argv);
+        fflush(stdout);
+        exit(0);
+    }
+    while(!isspace(*p)) {
+        p++;
+        if(*p==ENDOFSTR)  return(p);
+    }
+    while(isspace(*p)) {
+        p++;
+        if(*p==ENDOFSTR)  return(p);
+    }
+    return(p);
 }
 }
 
 
 /******************************** LOGO() **********************************/
 /******************************** LOGO() **********************************/
 
 
 void logo(void)
 void logo(void)
 {   printf("\t    ***************************************************\n");
 {   printf("\t    ***************************************************\n");
-	printf("\t    *           COMPOSERS DESKTOP PROJECT             *\n");
-	printf("\t                    %s $Revision: 1.3 $	\n",PROG);
-	printf("\t    *                                                 *\n");
-	printf("\t    *    Insert a column of figures, in a textfile,   *\n");
-	printf("\t    *              into an existing file.             *\n");
-	printf("\t    *                                                 *\n");
-	printf("\t    *                by TREVOR WISHART                *\n");
-	printf("\t    ***************************************************\n\n");
+    printf("\t    *           COMPOSERS DESKTOP PROJECT             *\n");
+    printf("\t                    %s $Revision: 1.3 $       \n",PROG);
+    printf("\t    *                                                 *\n");
+    printf("\t    *    Insert a column of figures, in a textfile,   *\n");
+    printf("\t    *              into an existing file.             *\n");
+    printf("\t    *                                                 *\n");
+    printf("\t    *                by TREVOR WISHART                *\n");
+    printf("\t    ***************************************************\n\n");
 }
 }

File diff suppressed because it is too large
+ 840 - 840
dev/tabedit/vectors.c


Some files were not shown because too many files changed in this diff