/* pmxab.f -- translated by f2c (version 19991025).
   You must link the resulting object file with the libraries:
	-lf2c -lm   (in that order)
*/

#include "f2c.h"

/* Common Block Declarations */

struct {
    integer miditime, lasttime;
} comevent_;

#define comevent_1 comevent_

struct {
    integer levson[16], levsoff[16], imidso[16], naccbl[16], laccbl[160]	
	    /* was [16][10] */, jaccbl[160]	/* was [16][10] */, nusebl;
    logical slmon[16], dbltie;
} comslm_;

#define comslm_1 comslm_

struct {
    integer imidi[16];
    real trest[16];
    integer mcpitch[10], mgap, iacclo[96]	/* was [16][6] */, iacchi[96]	
	    /* was [16][6] */, midinst[15], nmidcrd, midchan[30]	/* 
	    was [15][2] */, numchan, naccim[16], laccim[160]	/* was [16][
	    10] */, jaccim[160]	/* was [16][10] */;
    logical crdacc, notmain, restpend[16], relacc, twoline[15], ismidi;
    shortint mmidi[393216]	/* was [16][24576] */;
} commidi_;

#define commidi_1 commidi_

struct {
    integer ipbuf, ilbuf, nlbuf;
    shortint lbuf[2000];
    char bufq[65536];
} inbuff_;

#define inbuff_1 inbuff_

struct {
    integer musize;
    real whead20;
} commus_;

#define commus_1 commus_

union {
    struct {
	integer iv, ivxo[200], ipo[200];
	real to[200], tno[200];
	integer nnl[15], nv, ibar, mtrnuml, nodur[3000]	/* was [15][200] */, 
		lenbar, iccount, idum, itsofar[15], nib[225]	/* was [15][
		15] */, nn[15];
	logical rest[3000]	/* was [15][200] */;
	integer lenbr0, lenbr1;
	logical firstline, newmeter;
    } _1;
    struct {
	integer iv, ivxo[200], ipo[200];
	real to[200], tno[200];
	integer nnl[15], nv, ibar, mtrnuml, nodur[3000]	/* was [15][200] */, 
		lenbar, iccount, nbars, itsofar[15], nib[225]	/* was [15][
		15] */, nn[15];
	logical rest[3000]	/* was [15][200] */;
	integer lenbr0, lenbr1;
	logical firstline, newmeter;
    } _2;
} a1ll_;

#define a1ll_1 (a1ll_._1)
#define a1ll_2 (a1ll_._2)

struct {
    integer n69[16];
} comdiag_;

#define comdiag_1 comdiag_

struct {
    integer mmacstrt[320]	/* was [16][20] */, mmacend[320]	/* 
	    was [16][20] */, immac, mmactime[20], nmidsec, msecstrt[320]	
	    /* was [16][20] */, msecend[320]	/* was [16][20] */;
    logical mmacrec, gottempo;
} commmac_;

#define commmac_1 commmac_

struct {
    integer nnodur;
    real wminnh[600];
    integer nnpd[2000];
    real durb[2000];
    integer iddot, nptr[600], ibarcnt, mbrest, ibarmbr, ibaroff;
    real udsp[600], wheadpt;
    logical gotclef;
    real sqzb[2000];
} c1omnotes_;

#define c1omnotes_1 c1omnotes_

struct compage_1_ {
    real widthpt, ptheight;
    integer nsyst, nflb, ibarflb[41], isysflb[41], npages, nfpb, ipagfpb[19], 
	    isysfpb[19];
    logical usefig;
    real fintstf, gintstf, fracsys[20];
    integer nmovbrk, isysmb[21], nistaff[41];
};

#define compage_1 (*(struct compage_1_ *) &compage_)

struct {
    integer nkeys, ibrkch[18], newkey[18];
    logical iskchb;
    integer idsig, isig1;
    logical kchmid[18], ornrpt, shifton, barend;
    integer noinst;
} comkeys_;

#define comkeys_1 comkeys_

struct {
    logical lastchar, fbon, issegno;
    integer ihead;
    logical isheadr;
    integer nline;
    logical isvolt;
    real fracindent;
    integer nsperi[15];
} c1omget_;

#define c1omget_1 c1omget_

struct {
    real elskb, tnminb[600];
} linecom_;

#define linecom_1 linecom_

struct cblock_1_ {
    real etatop, etabot, etait, etatc, etacs1, hgtin, hgtti, hgtco, xilbn, 
	    xilbtc, xilhdr, xilfig, a, b;
    integer inhnoh;
};

#define cblock_1 (*(struct cblock_1_ *) &cblock_)

struct cominbot_1_ {
    integer inbothd;
};

#define cominbot_1 (*(struct cominbot_1_ *) &cominbot_)

struct {
    integer nvmx[15], ivmx[30]	/* was [15][2] */, ivx;
    real fbar;
} c1ommvl_;

#define c1ommvl_1 c1ommvl_

struct {
    integer macnum;
    logical mrecord, mplay;
    integer macuse, icchold;
    char lnholdq[128];
    logical endmac;
} commac_;

#define commac_1 commac_

struct {
    real eonk, ewmxk;
} comeon_;

#define comeon_1 comeon_

struct comtol_1_ {
    real tol;
};

#define comtol_1 (*(struct comtol_1_ *) &comtol_)

struct comtrans_1_ {
    integer ntrans;
    char cheadq[60];
};

#define comtrans_1 (*(struct comtrans_1_ *) &comtrans_)

struct comstart_1_ {
    real facmtr;
};

#define comstart_1 (*(struct comstart_1_ *) &comstart_)

struct comtitl_1_ {
    char instrq[60], titleq[60], compoq[60];
    logical headlog;
    integer inskip, ncskip, inhead;
};

#define comtitl_1 (*(struct comtitl_1_ *) &comtitl_)

struct spfacs_1_ {
    real grafac, acgfac, accfac, xspfac, xb4fac, clefac, emgfac, flagfac, 
	    dotfac, bacfac, agc1fac, gslfac, arpfac, rptfac;
    integer lrrptfac;
    real dbarfac, ddbarfac, dotsfac, upstmfac, rtshfac;
};

#define spfacs_1 (*(struct spfacs_1_ *) &spfacs_)

struct combmh_1_ {
    real bmhgt, clefend;
};

#define combmh_1 (*(struct combmh_1_ *) &combmh_)

struct {
    integer ip1mac[20], il1mac[20], ip2mac[20], il2mac[20], ic1mac[20], ilmac,
	     iplmac;
} c1ommac_;

#define c1ommac_1 c1ommac_

union {
    struct {
	integer mult[3000]	/* was [15][200] */, iv, nnl[15], nv, ibar, 
		ivxo[200], ipo[200];
	real to[200], tno[200], tnote[200], eskz[3000]	/* was [15][200] */;
	integer ipl[3000]	/* was [15][200] */, ibm1[120]	/* was [15][8]
		 */, ibm2[120]	/* was [15][8] */, nolev[3000]	/* was [15][
		200] */, ibmcnt[15], nodur[3000]	/* was [15][200] */, 
		jn, lenbar, iccount, nbars, itsofar[15], nacc[3000]	/* 
		was [15][200] */, nib[225]	/* was [15][15] */, nn[15], 
		lenb0, lenb1;
	real slfac;
	integer musicsize;
	real stemmax, stemmin, stemlen;
	integer mtrnuml, mtrdenl, mtrnmp, mtrdnp, islur[3000]	/* was [15][
		200] */, ifigdrop[125], iline;
	logical figbass, figcheck, firstgulp;
	integer irest[3000]	/* was [15][200] */, iornq[3015]	/* 
		was [15][201] */, isdat1[202], isdat2[202], nsdat, isdat3[202]
		;
	logical beamon[15], isfig[200];
	char sepsymq[15], sq[1], ulq[120]	/* was [15][8] */;
    } _1;
    struct {
	integer mult[3000]	/* was [15][200] */, jv, nnl[15], nv, ibar, 
		ivxo[200], ipo[200];
	real to[200], tno[200], tnote[200], eskz[3000]	/* was [15][200] */;
	integer ipl[3000]	/* was [15][200] */, ibm1[120]	/* was [15][8]
		 */, ibm2[120]	/* was [15][8] */, nolev[3000]	/* was [15][
		200] */, ibmcnt[15], nodur[3000]	/* was [15][200] */, 
		jn, lenbar, iccount, nbars, itsofar[15], nacc[3000]	/* 
		was [15][200] */, nib[225]	/* was [15][15] */, nn[15], 
		lenb0, lenb1;
	real slfac;
	integer musicsize;
	real stemmax, stemmin, stemlen;
	integer mtrnuml, mtrdenl, mtrnmp, mtrdnp, islur[3000]	/* was [15][
		200] */, ifigdrop[125], iline;
	logical figbass, figcheck, firstgulp;
	integer irest[3000]	/* was [15][200] */, iornq[3015]	/* 
		was [15][201] */, isdat1[202], isdat2[202], nsdat, isdat3[202]
		;
	logical beamon[15], isfig[200];
	char sepsymq[15], sq[1], ulq[120]	/* was [15][8] */;
    } _2;
} all_;

#define all_1 (all_._1)
#define all_2 (all_._2)

struct {
    logical islast;
} comlast_;

#define comlast_1 comlast_

struct {
    integer ivbjmp;
    logical isbjmp;
} combjmp_;

#define combjmp_1 combjmp_

union {
    struct {
	integer itfig[74];
	char figq[444];
	integer nfigs;
    } _1;
    struct {
	integer itfig[74];
	char figqq[444];
	integer nfigs;
    } _2;
} comfig_;

#define comfig_1 (comfig_._1)
#define comfig_2 (comfig_._2)

struct {
    real space[80];
    integer nb;
    real prevtn[15], flgndv[15];
    logical flgndb;
    real eskgnd, ptsgnd;
    integer ivmxsav[30]	/* was [15][2] */, nvmxsav[15];
} comnsp_;

#define comnsp_1 comnsp_

struct {
    integer nfb[15];
    real t1fb[300]	/* was [15][20] */, t2fb[300]	/* was [15][20] */;
    char ulfbq[300]	/* was [15][20] */;
    integer ifb;
} comfb_;

#define comfb_1 comfb_

struct {
    logical lastchar, rptnd1, sluron[30]	/* was [15][2] */, fbon, 
	    ornrpt;
    integer movbrk, movnmp, movdnp, movgap;
    real parmov, fintstf, gintstf;
    logical rptprev;
    char rptfq1[1], rptfq2[1];
} comget_;

#define comget_1 comget_

struct {
    integer ibmtyp;
} combeam_;

#define combeam_1 combeam_

union {
    struct {
	integer nnodur, lastlev, ndlev[30]	/* was [15][2] */;
	logical shifton, setis, notcrd;
	integer npreslur;
	logical was2[15];
	integer noinst;
	logical nobar1;
    } _1;
    struct {
	integer nnodur, lastlev, ndlev[30]	/* was [15][2] */;
	logical shifton, setis, notcrd;
	integer npreslur;
	logical was2[15];
	integer ninow;
	logical nobar1;
    } _2;
} comnotes_;

#define comnotes_1 (comnotes_._1)
#define comnotes_2 (comnotes_._2)

struct {
    integer itopfacteur, ibotfacteur, interfacteur, isig0, isig, lastisig;
    real fracindent, widthpt, height;
    integer idsig, lnam[15];
    char inameq[1185];
} comtop_;

#define comtop_1 comtop_

struct {
    integer naskb;
    real task[20], wask[20], elask[20];
} comas1_;

#define comas1_1 comas1_

struct {
    integer nasksys;
    real wasksys[400], elasksys[400];
} comas2_;

#define comas2_1 comas2_

struct {
    real ask[1400];
    integer iask;
    logical topmods;
} comas3_;

#define comas3_1 comas3_

struct {
    logical bar1syst;
    real fixednew, scaldold, wheadpt, fbar, poenom;
} comask_;

#define comask_1 comask_

struct {
    integer listslur;
    logical upslur[30]	/* was [15][2] */;
    integer ndxslur;
} comslur_;

#define comslur_1 comslur_

struct {
    integer is1n1, is2n1, irzbnd, isnx;
} comsln_;

#define comsln_1 comsln_

struct {
    integer ivg[37], ipg[37], nolevg[74], itoff[74];
    real aftshft;
    integer nng[37], ngstrt[37], ibarmbr, mbrest;
    real xb4mbr;
    integer noffseg, ngrace, nvolt, ivlit[52], iplit[52], nlit, lenlit[52], 
	    multg[37];
    logical upg[37], slurg[37], slashg[37];
    integer naccg[74];
    char voltxtq[60], litq[6656];
} comgrace_;

#define comgrace_1 comgrace_

struct {
    integer ntrill, ivtrill[18], iptrill[18];
    real xnsktr[18];
    integer ncrd, icrdat[93], icrdot[93], icrdorn[93], nudorn, kudorn[63], 
	    minlev, maxlev, icrd1, icrd2;
} comtrill_;

#define comtrill_1 comtrill_

struct {
    integer ncc[15];
    real tcc[150]	/* was [15][10] */;
    integer ncmidcc[150]	/* was [15][10] */, ndotmv[15];
    real updot[300]	/* was [15][20] */, rtdot[300]	/* was [15][20] */;
} comcc_;

#define comcc_1 comcc_

struct {
    logical ispoi;
} compoi_;

#define compoi_1 compoi_

struct {
    logical bcspec;
} combc_;

#define combc_1 combc_

struct {
    real hpttot[176];
} comhsp_;

#define comhsp_1 comhsp_

struct {
    integer nvmx[15], ivmx[30]	/* was [15][2] */, ivx;
} commvl_;

#define commvl_1 commvl_

struct {
    real udsp[50], tudsp[50];
    integer nudsp;
    real udoff[300]	/* was [15][20] */;
    integer nudoff[15];
} comudsp_;

#define comudsp_1 comudsp_

struct {
    integer ihnum3;
    logical flipend[15];
    integer ixrest[15];
} strtmid_;

#define strtmid_1 strtmid_

struct {
    integer narp, itar[8], ivar1[8], levar1[8], ncmar1[8];
    real xinsnow;
    logical lowdot;
} comarp_;

#define comarp_1 comarp_

struct {
    integer nsperi[15], nspern[15];
    logical rename;
    integer iiorig[15];
} comnvi_;

#define comnvi_1 comnvi_

struct {
    integer ndyn, idyndat[99];
} comdyn_;

#define comdyn_1 comdyn_

struct {
    integer ihdht;
    logical lower;
    char headrq[80], lowerq[80];
    integer ihdvrt;
} comhead_;

#define comhead_1 comhead_

struct {
    integer noctup;
} comoct_;

#define comoct_1 comoct_

struct {
    logical cwrferm[15];
} comcwrf_;

#define comcwrf_1 comcwrf_

union {
    struct {
	integer ixtup;
	logical vxtup[15];
	integer ntupv[15], nolev1[15], islope[15];
	real xelsk[24], eloff[15];
    } _1;
    struct {
	integer ixtup;
	logical vxtup[15];
	integer ntupv[15], nolev1[15], islope[15];
	real xels11[24], eloff[15];
    } _2;
} comxtup_;

#define comxtup_1 (comxtup_._1)
#define comxtup_2 (comxtup_._2)

struct {
    shortint ipslon[16], lusebl[10], jusebl[10];
} comips_;

#define comips_1 comips_

/* Initialized data */

struct {
    real e_1[2];
    integer fill_2[127];
    real e_3[20];
    integer fill_4[63];
    } compage_ = { (float)524., (float)740., {0}, (float)0., (float)0., (
	    float)0., (float)0., (float)0., (float)0., (float)0., (float)0., (
	    float)0., (float)0., (float)0., (float)0., (float)0., (float)0., (
	    float)0., (float)0., (float)0., (float)0., (float)0., (float)0. };

struct {
    real e_1[14];
    integer e_2;
    } cblock_ = { (float).5, (float).25, (float).4, (float).4, (float).2, (
	    float)12., (float)21., (float)12., (float)4., (float)1.6, (float)
	    5., (float)5.7, (float)1.071, (float)2.714, 16 };

struct {
    integer e_1;
    } cominbot_ = { 16 };

struct {
    real e_1;
    } comtol_ = { (float).001 };

struct {
    integer fill_1[1];
    char e_2[60];
    } comtrans_ = { {0}, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
	    ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
	    ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
	    ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
	    ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '} };

struct {
    real e_1;
    } comstart_ = { (float).7 };

struct {
    char e_1[180];
    logical e_2;
    integer fill_3[3];
    } comtitl_ = { {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
	    ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
	    ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
	    ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
	    ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
	    ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
	    ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
	    ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
	    ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
	    ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
	    ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
	    ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
	    ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 
	    ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 
	    FALSE_ };

struct {
    real e_1[14];
    integer e_2;
    real e_3[5];
    } spfacs_ = { (float)1.3333, (float).4, (float).7, (float).3, (float).2, (
	    float)2., (float)1., (float).7, (float).7, (float).9, (float).5, (
	    float)9., (float)1.7, (float)1.32, 2, (float).47, (float).83, (
	    float).17, (float).5, (float)1. };

struct {
    real e_1[2];
    } combmh_ = { (float)1.1, (float)2.3 };


/* Table of constant values */

static integer c__9 = 9;
static integer c__1 = 1;
static integer c__24 = 24;
static integer c__2 = 2;
static integer c__128 = 128;
static logical c_true = TRUE_;
static integer c__3 = 3;
static logical c_false = FALSE_;
static integer c__4 = 4;
static integer c__0 = 0;
static integer c__92 = 92;
static integer c__15 = 15;
static integer c__5 = 5;
static real c_b1232 = (float)1.;
static integer c__12 = 12;
static real c_b1398 = (float)0.;
static integer c__13 = 13;
static integer c__7 = 7;
static integer c__19 = 19;
static integer c__8 = 8;
static integer c__14 = 14;
static integer c__6 = 6;
static integer c__10 = 10;
static integer c__80 = 80;
static integer c__34 = 34;
static integer c__23 = 23;
static real c_b2065 = (float)-2.;
static integer c__20 = 20;
static integer c__30 = 30;
static integer c__22 = 22;
static integer c__60 = 60;
static integer c__39 = 39;
static integer c__96 = 96;
static real c_b3023 = (float)2.;
static integer c__28 = 28;
static integer c__11 = 11;
static integer c__17 = 17;
static integer c__129 = 129;
static integer c__16 = 16;
static integer c__26 = 26;
static integer c__29 = 29;
static integer c__256 = 256;

/* Main program */ MAIN__()
{
    /* Initialized data */

    static integer maxit = 200;
    static integer ncalls = 0;
    static logical isfirst = TRUE_;

    /* System generated locals */
    address a__1[2], a__2[3];
    integer i__1, i__2, i__3[2], i__4[3], i__5;
    real r__1;
    char ch__1[44], ch__2[28], ch__3[35], ch__4[36];
    olist o__1;
    cllist cl__1;
    inlist ioin__1;

    /* Builtin functions */
    integer s_wsle(), do_lio(), e_wsle(), s_rsfe(), do_fio(), e_rsfe();
    /* Subroutine */ int s_stop();
    integer s_cmp(), i_indx();
    /* Subroutine */ int s_copy(), s_cat();
    integer f_inqu(), f_open(), f_clos(), s_wsfe(), e_wsfe();

    /* Local variables */
    static integer icm;
    static real poe[125];
    static integer ivx;
    static real poe0[125];
    static integer ljob, ipoe[125];
    extern /* Subroutine */ int pmxa_(), pmxb_();
    static integer isys, ljob4;
    extern integer iargc_();
    static integer nbari[125], nbars[125], isysd, numit, isyst, isysu, nsyst, 
	    nbars0[125];
    static real poebar;
    extern /* Subroutine */ int getarg_();
    static integer idnord;
    static logical fexist;
    static real devpmx;
    static integer iupord;
    extern integer lenstr_();
    extern /* Subroutine */ int printl_();
    static integer ndxpmx;
    static real poebar0;
    static char jobname[24], infileq[27], lnholdq[128];
    static real devnorm;
    static integer numargs;
    extern /* Subroutine */ int sortpoe_();
    static real devnorm0;
    static logical optimize;
    extern /* Subroutine */ int poestats_(), writemidi_();

    /* Fortran I/O blocks */
    static cilist io___8 = { 0, 6, 0, 0, 0 };
    static cilist io___9 = { 0, 6, 0, 0, 0 };
    static cilist io___10 = { 0, 5, 0, "(a)", 0 };
    static cilist io___13 = { 0, 6, 0, 0, 0 };
    static cilist io___14 = { 0, 6, 0, 0, 0 };
    static cilist io___15 = { 0, 6, 0, 0, 0 };
    static cilist io___19 = { 0, 6, 0, 0, 0 };
    static cilist io___21 = { 0, 18, 1, "(a)", 0 };
    static cilist io___35 = { 0, 6, 0, 0, 0 };
    static cilist io___36 = { 0, 15, 0, 0, 0 };
    static cilist io___44 = { 0, 6, 0, 0, 0 };
    static cilist io___45 = { 0, 15, 0, 0, 0 };
    static cilist io___46 = { 0, 6, 0, "(5x,20i3)", 0 };
    static cilist io___47 = { 0, 15, 0, "(5x,20i3)", 0 };
    static cilist io___48 = { 0, 6, 0, 0, 0 };
    static cilist io___49 = { 0, 15, 0, 0, 0 };
    static cilist io___50 = { 0, 6, 0, 0, 0 };
    static cilist io___51 = { 0, 15, 0, 0, 0 };
    static cilist io___52 = { 0, 6, 0, 0, 0 };
    static cilist io___53 = { 0, 15, 0, 0, 0 };
    static cilist io___54 = { 0, 6, 0, "(5x,20i3)", 0 };
    static cilist io___55 = { 0, 15, 0, "(5x,20i3)", 0 };
    static cilist io___56 = { 0, 6, 0, "(5x,20i3)", 0 };
    static cilist io___57 = { 0, 15, 0, "(5x,20i3)", 0 };


/* cccccccccccccccccccccccc */

/*  pmxab, Version 2.2 (p2197) March 18, 2000 */

/* cccccccccccccccccccccccc */

/* To do */

/*   Transpose by instruments */
/*   Beams with single 64ths */
/*   128ths and/or dotted 64ths */
/*   Close out MIDI with integral # of beats? */
/*   Increase ast dimensions or redo logic. */
/*   Does slur direction get set for user-defined single-note stem dir'ns? */
/*   Transpose by sections. */
/*   Loop over sections only */
/*   Command-line option to read nbarss in.  Write out nbarss when optimizing. */
/*     (or just read from .plg?) */
/*   Beams over bar lines. */
/*   2-digit figures */
/*   Repeated ornaments retain offset info. */
/*   Unbeamed xtups. */
/*   A real coule (slanted line between notes in a chord) */
/*   Clean up dynamic marks.  (Add description in ref200!) */
/*   Dotted slurs for grace notes. */
/*   Undotted chord notes with dotted main note. */
/*   Forced line break without line #. */
/* 2.197 */
/*   add /comips/ to save tie-check midi variables */
/*   For spacing of clef changes at start of input block, changed integer time */
/*     lastnodur to prevtn, so it works with xtups. Possible incompatibility! */
/* 2.196 */
/*   Fix Ickbug with time check in ncmid() */
/*   Interchange \fermataup7 and \pausec to get proper alignment */
/*   Enable French violin clef "f",  number 7 in PMX, but 9 in MusiXTeX. */
/*   Add defn's of \hsp, \hspp to pmx.tex */
/*   Fix pre-slurs on xtup chord notes. */
/*   Fixed raised PAuse, define \liftPAuse */
/*   Replace \zbreve\sk with \breve. */
/*   Made "1" work as mtrdenl by doubling it and mtrnuml */
/*     BUT WAIT...what about "o" and 1 as shorthand for 16???? Search for "Kluge" */
/*   Added "vo" (voice) as MIDI instrument 55 */
/*   Allow 3-digit page numbers (search for "toppageno") */
/*   Fix bug caused by prior fix (cancelling accid after bar line was ignored). */
/*   Fix double accids in chords */
/* 2.194 */
/*   Fix bug with accid/tie/barline/chord in addmidi by restructuring accid if */
/*     block. */
/*   Add meter to MIDI file with every pause */
/*   Purify FORTRAN? */
/* 2.193 */
/*   Increased # of in-line TeX strings from 36 to 52. */
/*   Fix entry of # of bytes in header of tempo/meter/key track to allow >255. */
/* 2.191 */
/*   Event track: Tempos, meters, keys all together.  Data in comevent */
/* 2.15 */
/*   Pretty good midi capability.  Still no attention to slurs on chord notes. */
/* 2.11 */
/*   11 Dec 99 c   rm1 */
/*   11 Dec 99 "oes?", "oe?" */
/*   11 Dec 99 Cancel slur horizontal tweaks with non-stemmed notes */
/*   11 Dec 99 Error message for shifted, repeated ornaments. */
/* 2.10 (Version 2.1) */
/*   Fix bug with lowdot and xtuplets */
/* 2.09 */
/*   Fix bug with multiple ornament heights over beams, when one is . or _ */
/*   Error message from pmxa if rest on last note of xtup. */
/*   Enable 12 slurs. */
/*   Reinstate multiple rests at start of xtup. */
/* 2.07 */
/*   Combine consecutive type-1 TeX strings. */
/*   \midslur and \curve as 3rd signed digit in slur termination, + 2 opt. int's. */
/*   Fixed breve chord notes in docrd */
/*   Check irest(28) as well as vxtup when setting nodur for chord notes, since */
/*     vxtup isn't set until 1st *main* note in xtup */
/*   Vectorize nolev1, slope, ixrest.  Klug fix for xtups with variable spacing. */
/* 2.06+ */
/*   Make deterministic the beam slope calculation when there are an even # of */
/*     slopes in list and middle two are equal magnitude but opposite sign. */
/*   pmxa Trap for "o:" before 1st note in block */
/*   Partial bug fix for 64th notes in xtuplets. */
/*   Make ixrest a vector, since with new time scheme may not finish xtup in */
/*     same notes block. */
/*   Increase max # of pages from 20 to 30 (dimensions of nsystp,..., in pmxb) */

/* 2.06 */
/*   Account for changes in nv when computing \interstaff. Add a counter */
/*     nistaff(iflb) = # of interstaff spaces per system = nv-1.  Set whenever */
/*     setting isysflb(iflb). Note nv can only change at a forced line break. */
/*     Note also, iflb starts at 0! */

/* 2.05 */
/*   Automatic start of new notes group with part 2 of staff-jump beam */
/*     In make1bar, set irest bit 29 of lowest-voice note at same time, */
/*     use as flag when making notes groups. */
/*   For now, remove dummy blank line at end...it zaps terminal repeats. */

/* 2.02 */
/*   Fixed slur-counting bug for multiple, slurred, aftergraces. */
/* 2.01 */
/*  Increase to ask(1400) */
/*  Increase max forced page breaks to 18 */
/*  Define pausc for centered pause */

/* 2.0a */
/*  Insert dummy blank line at very end to handle input files w/o terminal CR-LF */

/* pmx03r */
/*   Option m[n] in S symbol to change musicsize (for parts) */
/*   Double dotted rests now work. */
/*   Write file name to log file */
/*   Check existence of input file */
/*   Allow 24-char jobname, may end with ".pmx" */
/*   Comment out time stuff */
/*   Replace 3-argument getarg with 2-argument + iargc */
/*   Fix bug with negative noinst due to nint<=int replacement */
/*   move lovation of iv in isdat1 to allow iv>7. */
/*   Set nm=15 */
/* pmx03q */
/*   replace int(x+.001) with nint(x) */
/*   Write TeX file name to screen and to pml. */
/*   Replace char(...) with chax(...) to sovle msdev bug. */
/*   Bug fix: macro terminations when M is on a line by itself. */
/*   Bug fix: don't accumulate space for XS in pmxa. */
/*   Streamline Macros: use pointers to bufq instead of scratch files */
/* pmx03p */
/*   Store input file in single character array bufq. */
/*     lbuf(i)*2 is length of line i */
/*     ipbuf is position just before next line to be read. */
/* pmx03 */
/*   Optimize read/writes */
/* pmx02 */
/*   Fix line count (for errors) when there are saved macros */
/* pmx01 */
/*   In optimize mode, open/close macros (Watch out for residual zz files!) */
/*   Command line input */
/*   Option Ao to optimize, otherwise normal processing */

/* cccccc */

/*  immac(i) is the index of i-th macro, i=1,nmac.  Also make a list containing */
/*   nmidsec  section starts and stops based on PLAYING macros (not recording). */

/*      itstart = mytime() */

/*  Initialize midi parameters */

    commmac_1.gottempo = FALSE_;
    commidi_1.ismidi = FALSE_;
    commidi_1.relacc = FALSE_;
    commmac_1.mmacrec = FALSE_;
    commmac_1.nmidsec = 1;
    commidi_1.mgap = 10;
    comevent_1.miditime = 0;
    comevent_1.lasttime = 0;
    commidi_1.nmidcrd = 0;
    comslm_1.nusebl = 0;
    commidi_1.notmain = FALSE_;
    for (ivx = 1; ivx <= 15; ++ivx) {
	commidi_1.twoline[ivx - 1] = FALSE_;
	commidi_1.midinst[ivx - 1] = 6;
/* L3: */
    }
    for (icm = 0; icm <= 15; ++icm) {
	commidi_1.imidi[icm] = 0;
	commidi_1.restpend[icm] = FALSE_;
	commidi_1.trest[icm] = (float)0.;
	comslm_1.levson[icm] = 0;
	comslm_1.levsoff[icm] = 0;
	comslm_1.slmon[icm] = FALSE_;
	comslm_1.naccbl[icm] = 0;
	comdiag_1.n69[icm] = 0;
	commmac_1.msecstrt[icm] = 1;
/* L12: */
    }

/*  End of midi parameter initialization */

    commus_1.musize = 0;
    optimize = FALSE_;
    numargs = iargc_();
    if (numargs == 0) {
	s_wsle(&io___8);
	do_lio(&c__9, &c__1, "You could have entered a jobname on the comman\
d line,", (ftnlen)53);
	e_wsle();
	s_wsle(&io___9);
	do_lio(&c__9, &c__1, "      but you may enter one now:", (ftnlen)32);
	e_wsle();
	s_rsfe(&io___10);
	do_fio(&c__1, jobname, (ftnlen)24);
	e_rsfe();
	numargs = 1;
    } else {
	getarg_(&c__1, jobname, &a1ll_1.idum, (ftnlen)24);
/*        call getarg(1,jobname) */
/* May need to replace this w/ next l */
    }
L10:
    ljob = lenstr_(jobname, &c__24, (ftnlen)24);
    if (ljob > 24) {
	s_wsle(&io___13);
	do_lio(&c__9, &c__1, "Jobname is too long. Try again.", (ftnlen)31);
	e_wsle();
	s_stop("1", (ftnlen)1);
    } else if (ljob == 0) {
	s_wsle(&io___14);
	do_lio(&c__9, &c__1, "No was jobname entered. Try again.", (ftnlen)34)
		;
	e_wsle();
	s_stop("1", (ftnlen)1);
    } else if (numargs == 2) {
	if (ljob == 2 && s_cmp(jobname, "-o", (ftnlen)2, (ftnlen)2) == 0) {
	    optimize = TRUE_;
	    getarg_(&c__2, jobname, &a1ll_1.idum, (ftnlen)24);
/*          call getarg(2,jobname) */
/* May need to replace this w/ next */
	    numargs = 1;
	    goto L10;
	} else {
	    s_wsle(&io___15);
	    do_lio(&c__9, &c__1, "Illegal option on command line", (ftnlen)30)
		    ;
	    e_wsle();
	    s_stop("1", (ftnlen)1);
	}
    }

/*  Strip ".pmx" if necessary */

/* Computing MAX */
    i__1 = i_indx(jobname, ".pmx", (ftnlen)24, (ftnlen)4), i__2 = i_indx(
	    jobname, ".PMX", (ftnlen)24, (ftnlen)4);
    ndxpmx = max(i__1,i__2);
    if (ndxpmx > 0) {
	s_copy(jobname, jobname, (ftnlen)24, ndxpmx - 1);
	ljob += -4;
    }

/*  Check for existence of input file */

/* Writing concatenation */
    i__3[0] = ljob, a__1[0] = jobname;
    i__3[1] = 4, a__1[1] = ".pmx";
    s_cat(infileq, a__1, i__3, &c__2, (ftnlen)27);
    ioin__1.inerr = 0;
    ioin__1.infilen = 27;
    ioin__1.infile = infileq;
    ioin__1.inex = &fexist;
    ioin__1.inopen = 0;
    ioin__1.innum = 0;
    ioin__1.innamed = 0;
    ioin__1.inname = 0;
    ioin__1.inacc = 0;
    ioin__1.inseq = 0;
    ioin__1.indir = 0;
    ioin__1.infmt = 0;
    ioin__1.inform = 0;
    ioin__1.inunf = 0;
    ioin__1.inrecl = 0;
    ioin__1.innrec = 0;
    ioin__1.inblank = 0;
    f_inqu(&ioin__1);
    if (! fexist) {
	s_wsle(&io___19);
/* Writing concatenation */
	i__3[0] = 17, a__1[0] = "Cannot find file ";
	i__3[1] = 27, a__1[1] = infileq;
	s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)44);
	do_lio(&c__9, &c__1, ch__1, (ftnlen)44);
	e_wsle();
	s_stop("1", (ftnlen)1);
    }

/*  Open a log file */

    o__1.oerr = 0;
    o__1.ounit = 15;
    o__1.ofnmlen = ljob + 4;
/* Writing concatenation */
    i__3[0] = ljob, a__1[0] = jobname;
    i__3[1] = 4, a__1[1] = ".pml";
    s_cat(ch__2, a__1, i__3, &c__2, (ftnlen)28);
    o__1.ofnm = ch__2;
    o__1.orl = 0;
    o__1.osta = 0;
    o__1.oacc = 0;
    o__1.ofm = 0;
    o__1.oblnk = 0;
    f_open(&o__1);
    printl_("This is pmxab, version 2.2, 18 March 2000", (ftnlen)41);
    ljob4 = ljob;
/* Writing concatenation */
    i__3[0] = 8, a__1[0] = "Opening ";
    i__3[1] = 27, a__1[1] = infileq;
    s_cat(ch__3, a__1, i__3, &c__2, (ftnlen)35);
    printl_(ch__3, (ftnlen)35);
    o__1.oerr = 0;
    o__1.ounit = 18;
    o__1.ofnmlen = 27;
    o__1.ofnm = infileq;
    o__1.orl = 0;
    o__1.osta = 0;
    o__1.oacc = 0;
    o__1.ofm = 0;
    o__1.oblnk = 0;
    f_open(&o__1);

/*  Copy input file into common buffer */

    inbuff_1.ipbuf = 0;
    for (inbuff_1.ilbuf = 1; inbuff_1.ilbuf <= 2000; ++inbuff_1.ilbuf) {
	i__1 = s_rsfe(&io___21);
	if (i__1 != 0) {
	    goto L9;
	}
	i__1 = do_fio(&c__1, lnholdq, (ftnlen)128);
	if (i__1 != 0) {
	    goto L9;
	}
	i__1 = e_rsfe();
	if (i__1 != 0) {
	    goto L9;
	}
	inbuff_1.lbuf[inbuff_1.ilbuf - 1] = (shortint) lenstr_(lnholdq, &
		c__128, (ftnlen)128);
	if (inbuff_1.lbuf[inbuff_1.ilbuf - 1] == 0) {

/*  Blank line.  Make it a single blank with length 1 */

	    inbuff_1.lbuf[inbuff_1.ilbuf - 1] = 1;
	    s_copy(lnholdq, " ", (ftnlen)128, (ftnlen)1);
	}
	i__1 = inbuff_1.ipbuf;
	s_copy(inbuff_1.bufq + i__1, lnholdq, inbuff_1.ipbuf + inbuff_1.lbuf[
		inbuff_1.ilbuf - 1] - i__1, (ftnlen)128);
	inbuff_1.ipbuf += inbuff_1.lbuf[inbuff_1.ilbuf - 1];
/* L8: */
    }
    printl_("Too many lines in input file", (ftnlen)28);
    s_stop("1", (ftnlen)1);
L9:

/*  Insert dummy line to handle input files w/o CR-LF at end. */

    inbuff_1.nlbuf = inbuff_1.ilbuf - 1;
/*      nlbuf = ilbuf */
/*      bufq(ipbuf+1:ipbuf+3) = ' / ' */
/*      lbuf(nlbuf) = 3 */
    cl__1.cerr = 0;
    cl__1.cunit = 18;
    cl__1.csta = 0;
    f_clos(&cl__1);
    i__1 = maxit;
    for (numit = 1; numit <= i__1; ++numit) {
	if (optimize) {
	    printl_("Starting an iteration", (ftnlen)21);
	}

/*  When isfirst=.true., pmxa() generates linebreaks normally, output in nbars0. */
/*    Otherwise, nbars0 is the input */
/*  When islast=.false., pmxb only returns poe's, otherwise does whole job */

	pmxa_(jobname, &ljob4, &isfirst, &nsyst, nbars0, &optimize, (ftnlen)
		24);
	if (! optimize) {
	    if (commidi_1.ismidi) {

/*  Set up channel numbers for midi. */

		commidi_1.numchan = 0;
		for (a1ll_1.iv = a1ll_1.nv; a1ll_1.iv >= 1; --a1ll_1.iv) {
		    if (commidi_1.twoline[a1ll_1.iv - 1]) {
			commidi_1.midchan[a1ll_1.iv + 14] = commidi_1.numchan;
			++commidi_1.numchan;
		    }
		    commidi_1.midchan[a1ll_1.iv - 1] = commidi_1.numchan;
		    ++commidi_1.numchan;
/* L11: */
		}
	    }

/*  numchan will now be the number of channels, but max channel # is numchan-1 */

	    pmxb_(&c_true, poe0, &ncalls, &optimize);
	    if (commidi_1.ismidi) {

/*  Write midi file */

		o__1.oerr = 0;
		o__1.ounit = 51;
		o__1.ofnmlen = ljob + 4;
/* Writing concatenation */
		i__3[0] = ljob, a__1[0] = jobname;
		i__3[1] = 4, a__1[1] = ".mid";
		s_cat(ch__2, a__1, i__3, &c__2, (ftnlen)28);
		o__1.ofnm = ch__2;
		o__1.orl = 0;
		o__1.osta = 0;
		o__1.oacc = 0;
		o__1.ofm = 0;
		o__1.oblnk = 0;
		f_open(&o__1);
		printl_(" ", (ftnlen)1);
/* Writing concatenation */
		i__4[0] = 8, a__2[0] = "Writing ";
		i__4[1] = ljob, a__2[1] = jobname;
		i__4[2] = 4, a__2[2] = ".mid";
		s_cat(ch__4, a__2, i__4, &c__3, (ftnlen)36);
		printl_(ch__4, ljob + 12);
		writemidi_(jobname, &ljob, (ftnlen)24);
	    }
	    cl__1.cerr = 0;
	    cl__1.cunit = 15;
	    cl__1.csta = 0;
	    f_clos(&cl__1);
	    s_stop("", (ftnlen)0);
	}
	pmxb_(&c_false, poe0, &ncalls, &optimize);
	poestats_(&nsyst, poe0, &poebar0, &devnorm0);

/*  Save initial deviation and line breaks for later comparison */

	if (numit == 1) {
	    devpmx = devnorm0;
	    i__2 = nsyst;
	    for (isys = 1; isys <= i__2; ++isys) {
		nbari[isys - 1] = nbars0[isys - 1];
/* L20: */
	    }
	}
	sortpoe_(&nsyst, poe0, ipoe);
	for (iupord = nsyst; iupord >= 1; --iupord) {
	    isysu = ipoe[iupord - 1];
	    s_wsle(&io___35);
	    do_lio(&c__9, &c__1, "isysu=", (ftnlen)6);
	    do_lio(&c__3, &c__1, (char *)&isysu, (ftnlen)sizeof(integer));
	    e_wsle();
	    s_wsle(&io___36);
	    do_lio(&c__9, &c__1, "isysu=", (ftnlen)6);
	    do_lio(&c__3, &c__1, (char *)&isysu, (ftnlen)sizeof(integer));
	    e_wsle();

/*  Skip if system isysu has poe0 < avg or isysd has poe0 > avg */

	    if (poe0[isysu - 1] < poebar0) {
		goto L1;
	    }
	    i__2 = nsyst;
	    for (idnord = 1; idnord <= i__2; ++idnord) {
		isysd = ipoe[idnord - 1];
		if (isysu == isysd || nbars0[isysd - 1] == 1 || poe0[isysd - 
			1] > poebar0) {
		    goto L5;
		}
		i__5 = nsyst;
		for (isyst = 1; isyst <= i__5; ++isyst) {
		    nbars[isyst - 1] = nbars0[isyst - 1];
		    if (isyst == isysu) {
			++nbars[isyst - 1];
		    } else if (isyst == isysd) {
			--nbars[isyst - 1];
		    }
/* L2: */
		}
		pmxa_(jobname, &ljob4, &isfirst, &nsyst, nbars, &optimize, (
			ftnlen)24);
		pmxb_(&c_false, poe, &ncalls, &optimize);
		poestats_(&nsyst, poe, &poebar, &devnorm);
		if (devnorm < devnorm0) {
		    devnorm0 = devnorm;
		    poebar0 = poebar;
		    i__5 = nsyst;
		    for (isys = 1; isys <= i__5; ++isys) {
			nbars0[isys - 1] = nbars[isys - 1];
			poe0[isys - 1] = poe[isys - 1];
/* L4: */
		    }
		    s_wsle(&io___44);
		    do_lio(&c__9, &c__1, "Improved with iup,idown,devnorm:", (
			    ftnlen)32);
		    do_lio(&c__3, &c__1, (char *)&isysu, (ftnlen)sizeof(
			    integer));
		    do_lio(&c__3, &c__1, (char *)&isysd, (ftnlen)sizeof(
			    integer));
		    do_lio(&c__4, &c__1, (char *)&devnorm0, (ftnlen)sizeof(
			    real));
		    e_wsle();
		    s_wsle(&io___45);
		    do_lio(&c__9, &c__1, "Improved with iup,idown,devnorm:", (
			    ftnlen)32);
		    do_lio(&c__3, &c__1, (char *)&isysu, (ftnlen)sizeof(
			    integer));
		    do_lio(&c__3, &c__1, (char *)&isysd, (ftnlen)sizeof(
			    integer));
		    do_lio(&c__4, &c__1, (char *)&devnorm0, (ftnlen)sizeof(
			    real));
		    e_wsle();
		    s_wsfe(&io___46);
		    i__5 = nsyst;
		    for (isys = 1; isys <= i__5; ++isys) {
			do_fio(&c__1, (char *)&nbars0[isys - 1], (ftnlen)
				sizeof(integer));
		    }
		    e_wsfe();
		    s_wsfe(&io___47);
		    i__5 = nsyst;
		    for (isys = 1; isys <= i__5; ++isys) {
			do_fio(&c__1, (char *)&nbars0[isys - 1], (ftnlen)
				sizeof(integer));
		    }
		    e_wsfe();
		    sortpoe_(&nsyst, poe0, ipoe);
		    goto L6;
		}
L5:
		;
	    }
L1:
	    ;
	}

/*  If we get here, must have gone thru all switches and found nothing better, */
/*  so done! */

	goto L7;
L6:
	;
    }
L7:
    s_wsle(&io___48);
    do_lio(&c__9, &c__1, "Optimum located, numit:", (ftnlen)23);
    do_lio(&c__3, &c__1, (char *)&numit, (ftnlen)sizeof(integer));
    do_lio(&c__9, &c__1, ",  ncalls:", (ftnlen)10);
    do_lio(&c__3, &c__1, (char *)&ncalls, (ftnlen)sizeof(integer));
    e_wsle();
    s_wsle(&io___49);
    do_lio(&c__9, &c__1, "Optimum located, numit:", (ftnlen)23);
    do_lio(&c__3, &c__1, (char *)&numit, (ftnlen)sizeof(integer));
    do_lio(&c__9, &c__1, ",  ncalls:", (ftnlen)10);
    do_lio(&c__3, &c__1, (char *)&ncalls, (ftnlen)sizeof(integer));
    e_wsle();
    s_wsle(&io___50);
    do_lio(&c__9, &c__1, "Final error:", (ftnlen)12);
    do_lio(&c__4, &c__1, (char *)&devnorm0, (ftnlen)sizeof(real));
    do_lio(&c__9, &c__1, ", initial error:", (ftnlen)16);
    do_lio(&c__4, &c__1, (char *)&devpmx, (ftnlen)sizeof(real));
    e_wsle();
    s_wsle(&io___51);
    do_lio(&c__9, &c__1, "Final error:", (ftnlen)12);
    do_lio(&c__4, &c__1, (char *)&devnorm0, (ftnlen)sizeof(real));
    do_lio(&c__9, &c__1, ", initial error:", (ftnlen)16);
    do_lio(&c__4, &c__1, (char *)&devpmx, (ftnlen)sizeof(real));
    e_wsle();
    s_wsle(&io___52);
    do_lio(&c__9, &c__1, "Percentage improvement:", (ftnlen)23);
    r__1 = (1 - devnorm0 / devpmx) * (float)100.;
    do_lio(&c__4, &c__1, (char *)&r__1, (ftnlen)sizeof(real));
    e_wsle();
    s_wsle(&io___53);
    do_lio(&c__9, &c__1, "Percentage improvement:", (ftnlen)23);
    r__1 = (1 - devnorm0 / devpmx) * (float)100.;
    do_lio(&c__4, &c__1, (char *)&r__1, (ftnlen)sizeof(real));
    e_wsle();
    printl_("Initial bars/system:", (ftnlen)20);
    s_wsfe(&io___54);
    i__1 = nsyst;
    for (isys = 1; isys <= i__1; ++isys) {
	do_fio(&c__1, (char *)&nbari[isys - 1], (ftnlen)sizeof(integer));
    }
    e_wsfe();
    s_wsfe(&io___55);
    i__1 = nsyst;
    for (isys = 1; isys <= i__1; ++isys) {
	do_fio(&c__1, (char *)&nbari[isys - 1], (ftnlen)sizeof(integer));
    }
    e_wsfe();
    printl_("Final bars/system:", (ftnlen)18);
    s_wsfe(&io___56);
    i__1 = nsyst;
    for (isys = 1; isys <= i__1; ++isys) {
	do_fio(&c__1, (char *)&nbars0[isys - 1], (ftnlen)sizeof(integer));
    }
    e_wsfe();
    s_wsfe(&io___57);
    i__1 = nsyst;
    for (isys = 1; isys <= i__1; ++isys) {
	do_fio(&c__1, (char *)&nbars0[isys - 1], (ftnlen)sizeof(integer));
    }
    e_wsfe();
    pmxa_(jobname, &ljob4, &c_false, &nsyst, nbars0, &optimize, (ftnlen)24);
    pmxb_(&c_true, poe0, &ncalls, &optimize);
/*      itend = mytime() */
/*      print*,'Elapsed time in ms:',itend-itstart */
/*      write(15,*)'Elapsed time in ms:',itend-itstart */
    cl__1.cerr = 0;
    cl__1.cunit = 15;
    cl__1.csta = 0;
    f_clos(&cl__1);
} /* MAIN__ */

/* Subroutine */ int poestats_(nsyst, poe, poebar, devnorm)
integer *nsyst;
real *poe, *poebar, *devnorm;
{
    /* System generated locals */
    integer i__1;
    real r__1;

    /* Builtin functions */
    double sqrt();

    /* Local variables */
    static real sumx;
    static integer isyst;
    static real sumxx;


/*  Compute avg. & norm. std. dev. of poe. */

    /* Parameter adjustments */
    --poe;

    /* Function Body */
    sumx = (float)0.;
    sumxx = (float)0.;
    i__1 = *nsyst;
    for (isyst = 1; isyst <= i__1; ++isyst) {
	sumx += poe[isyst];
/* Computing 2nd power */
	r__1 = poe[isyst];
	sumxx += r__1 * r__1;
/* L1: */
    }
/* L2: */
/* Computing 2nd power */
    r__1 = sumx;
    *devnorm = sqrt(*nsyst * sumxx / (r__1 * r__1) - 1);
    *poebar = sumx / *nsyst;
    return 0;
} /* poestats_ */

/* Subroutine */ int sortpoe_(nsyst, poe, ipoe)
integer *nsyst;
real *poe;
integer *ipoe;
{
    /* System generated locals */
    integer i__1, i__2;

    /* Local variables */
    static integer io1, io2, iord, itemp;


/*  Initialize ipoe: */

    /* Parameter adjustments */
    --ipoe;
    --poe;

    /* Function Body */
    i__1 = *nsyst;
    for (iord = 1; iord <= i__1; ++iord) {
	ipoe[iord] = iord;
/* L3: */
    }

/*  Construct ipoe vector with pairwise interchanges.  When done, ipoe(1) will */
/*  be index of smallest poe, and ipoe(nsyst) will be index of biggest poe. */

    i__1 = *nsyst - 1;
    for (io1 = 1; io1 <= i__1; ++io1) {
	i__2 = *nsyst;
	for (io2 = io1 + 1; io2 <= i__2; ++io2) {
	    if (poe[ipoe[io1]] > poe[ipoe[io2]]) {

/* Interchange the indices */

		itemp = ipoe[io1];
		ipoe[io1] = ipoe[io2];
		ipoe[io2] = itemp;
	    }
/* L5: */
	}
/* L4: */
    }
    return 0;
} /* sortpoe_ */

/* Subroutine */ int pmxa_(basenameq, lbase, isfirst, nsyout, nbarss, 
	optimize, basenameq_len)
char *basenameq;
integer *lbase;
logical *isfirst;
integer *nsyout, *nbarss;
logical *optimize;
ftnlen basenameq_len;
{
    /* Initialized data */

    static real wtimesig = (float).72;
    static real wclef = (float).8;
    static real wkeysig = (float).28;

    /* System generated locals */
    integer i__1, i__2, i__3, i__4, i__5, i__6;
    real r__1, r__2, r__3, r__4;
    doublereal d__1, d__2;
    olist o__1;
    cllist cl__1;
    alist al__1;

    /* Builtin functions */
    integer s_wsle(), e_wsle(), do_lio(), s_wsfe(), do_fio(), e_wsfe(), 
	    f_open(), f_clos();
    /* Subroutine */ int s_stop();
    integer i_nint();
    double pow_dd();
    integer f_rew();

    /* Local variables */
    static real c__, d__;
    static integer j, ip, kv;
    static real xn;
    static integer nns, isy, key1, key2, nacc;
    static real diff;
    static integer iflb, ifig, ifpb, ioff;
    extern doublereal feon_();
    static real elsk[600];
    static integer ikey;
    static real elss[125];
    static logical loop;
    static real wdpt;
    static integer iptr;
    static real diff1;
    static integer ibar1;
    extern doublereal f1eon_();
    static integer ipage;
    static real celsk[601];
    static logical newmb[600];
    static integer ibars;
    static real dtmin, dtmax, xelsk, wmins;
    static integer ibarb4;
    static real fsyst;
    static integer isyst;
    static real elmin0, elmin1;
    static integer isysb4;
    static real omegag, facins, glueil;
    extern /* Subroutine */ int outbar_();
    static integer jprntb, nintpg, mtrdnp;
    static real poenom;
    extern /* Subroutine */ int printl_();
    static integer mtrnmp, nshort;
    static real wminpt, celskb4, xiltxt;
    static integer nsystp;
    static real wsyspt;
    extern /* Subroutine */ int g1etset_();
    static integer lenbeat, lastbar[126];
    static real xilfrac;
    static integer iflbnow;
    static logical bottreb;
    static integer mtrdenl, imovbrk, lenmult;
    static real sumelsk;
    static integer nsystpp;
    extern /* Subroutine */ int g1etnote_();
    extern integer i1fnodur_();
    extern /* Subroutine */ int makeabar_();
    static real xmtrnum0, heightil;
    extern /* Subroutine */ int findeonk_();
    static real elsstarg;
    static integer isysendpg, nomnsystp;

    /* Fortran I/O blocks */
    static cilist io___68 = { 0, 6, 0, 0, 0 };
    static cilist io___69 = { 0, 6, 0, 0, 0 };
    static cilist io___70 = { 0, 15, 0, "(a)", 0 };
    static cilist io___71 = { 0, 19, 0, "(i6)", 0 };
    static cilist io___78 = { 0, 6, 0, 0, 0 };
    static cilist io___85 = { 0, 15, 0, "(/,a19,i4,a1,i4)", 0 };
    static cilist io___86 = { 0, 6, 0, "(/,a19,i4,a1,i4)", 0 };
    static cilist io___91 = { 0, 6, 0, 0, 0 };
    static cilist io___93 = { 0, 6, 0, 0, 0 };
    static cilist io___94 = { 0, 6, 0, 0, 0 };
    static cilist io___95 = { 0, 6, 0, 0, 0 };
    static cilist io___97 = { 0, 12, 0, "(a)", 0 };
    static cilist io___98 = { 0, 12, 0, 0, 0 };
    static cilist io___99 = { 0, 12, 0, "(6f10.5/f10.5,3i5)", 0 };
    static cilist io___100 = { 0, 12, 0, 0, 0 };
    static cilist io___119 = { 0, 12, 0, 0, 0 };
    static cilist io___134 = { 0, 12, 0, "(i5)", 0 };
    static cilist io___151 = { 0, 6, 0, 0, 0 };
    static cilist io___152 = { 0, 6, 0, 0, 0 };
    static cilist io___153 = { 0, 15, 0, "(/a,i5,a)", 0 };
    static cilist io___155 = { 0, 12, 0, "(1pe12.5/i5,5e12.3)", 0 };
    static cilist io___156 = { 0, 13, 0, "(i5)", 0 };
    static cilist io___157 = { 0, 6, 0, "(/,a)", 0 };
    static cilist io___158 = { 0, 6, 0, 0, 0 };
    static cilist io___159 = { 0, 15, 0, "(/,a)", 0 };
    static cilist io___160 = { 0, 15, 0, "()", 0 };


/* ccccccccccccccccccccccccccccccccccccccccccccccc */
/* c                                            cc */
/* c Subroutine, combine with pmxb.for */
/* c */
/* ccccccccccccccccccccccccccccccccccccccccccccccc */
/* c */
/* c  Need to consider X spaces in xtuplets when getting poenom, and */
/* c      maybe fbar? */
/* c  mx06a */
/* c    ID numbers for voices when number of voices is reduced. */
/* c */
/* c  mx03a */
/* c    account for new fracindent for new movements. */
/* c */
/* c  Known changes since pmxa. Version 1.1b (see pmxb for longer list) */
/* c */
/* c  Check ID codes for slurs. */
/* c  Version 1.24 still does not have details for spacing/positioning */
/* c    arpeggios if there are accidentals or shifted notes or crowded scores. */
/* c  Fix problem in 1.22 with arpeggios across multi-line staves */
/* c  Fix problem in 1.22 with flat key signatures */
/* c  Read setup data as strings */
/* c  Warning for octave designation plus +/- */
/* c  Don't pause for volta warning, */
/* c  Macros */
/* c  Correct fsyst to account for transposition and key changes. */
/* c  Check for nbars > nsyst */
/* c */
/* cccccccccccccccccccccccccccccccccc */
    /* Parameter adjustments */
    --nbarss;

    /* Function Body */
    commus_1.whead20 = (float).3;
    if (! (*optimize)) {
	s_wsle(&io___68);
	e_wsle();
	s_wsle(&io___69);
	do_lio(&c__9, &c__1, "Starting first PMX pass", (ftnlen)23);
	e_wsle();
	s_wsfe(&io___70);
	do_fio(&c__1, " Starting first PMX pass", (ftnlen)24);
	e_wsfe();
    }
    if (*isfirst) {
	o__1.oerr = 0;
	o__1.ounit = 19;
	o__1.ofnmlen = 11;
	o__1.ofnm = "pmxaerr.dat";
	o__1.orl = 0;
	o__1.osta = 0;
	o__1.oacc = 0;
	o__1.ofm = 0;
	o__1.oblnk = 0;
	f_open(&o__1);
	s_wsfe(&io___71);
	do_fio(&c__1, (char *)&c__0, (ftnlen)sizeof(integer));
	e_wsfe();
	cl__1.cerr = 0;
	cl__1.cunit = 19;
	cl__1.csta = 0;
	f_clos(&cl__1);
    }
    if (! (*optimize)) {
	jprntb = 81;
    }
    commac_1.macuse = 0;
    comkeys_1.ornrpt = FALSE_;
    commac_1.mrecord = FALSE_;
    commac_1.mplay = FALSE_;
    c1omget_1.lastchar = FALSE_;
    for (c1omnotes_1.ibarcnt = 1; c1omnotes_1.ibarcnt <= 600; 
	    ++c1omnotes_1.ibarcnt) {
	c1omnotes_1.udsp[c1omnotes_1.ibarcnt - 1] = (float)0.;
	c1omnotes_1.wminnh[c1omnotes_1.ibarcnt - 1] = (float)-1.;
/* L42: */
    }

/*  Initialize input buffer */

    inbuff_1.ilbuf = 1;
    inbuff_1.ipbuf = 0;
    g1etset_(&a1ll_2.nv, &comkeys_1.noinst, &a1ll_2.mtrnuml, &mtrdenl, &
	    mtrnmp, &mtrdnp, &xmtrnum0, comkeys_1.newkey, &compage_1.npages, &
	    compage_1.nsyst, &commus_1.musize, &bottreb);

/*  Save initial meter for midi */

    if (! (*isfirst) && compage_1.npages == 0) {
	s_wsle(&io___78);
	do_lio(&c__9, &c__1, "Sorry, must have npages>0 for optimization.", (
		ftnlen)43);
	e_wsle();
	s_stop("1", (ftnlen)1);
    }
    *nsyout = compage_1.nsyst;

/*  isig1 will be changed in getnote if there is a transposition */

    comkeys_1.isig1 = comkeys_1.newkey[0];
    if (compage_1.npages > compage_1.nsyst) {
	printl_("npages > nsyst in input.  Please fix the input.", (ftnlen)47)
		;
	s_stop("1", (ftnlen)1);
    }

/*  fbar = afterruleskip/elemskip */
/*  apt = width of small accidental + space in points (= 6 at 20pt) =wheadpt */

    c1ommvl_1.fbar = (float)1.;
    c1omnotes_1.wheadpt = commus_1.whead20 * commus_1.musize;
    ifig = 0;
    compage_1.usefig = TRUE_;
    lenbeat = i1fnodur_(&mtrdenl, "x", (ftnlen)1);
    lenmult = 1;
    if (mtrdenl == 2) {
	lenbeat = 16;
	lenmult = 2;
    }
    a1ll_2.lenbr1 = lenmult * a1ll_2.mtrnuml * lenbeat;
    r__1 = lenmult * xmtrnum0 * lenbeat;
    a1ll_2.lenbr0 = i_nint(&r__1);
    a1ll_2.mtrnuml = 0;
    if (a1ll_2.lenbr0 != 0) {
	c1omnotes_1.ibaroff = 1;
	a1ll_2.lenbar = a1ll_2.lenbr0;
    } else {
	c1omnotes_1.ibaroff = 0;
	a1ll_2.lenbar = a1ll_2.lenbr1;
    }
    c1omnotes_1.ibarcnt = 0;
    c1omnotes_1.nptr[0] = 1;
    a1ll_2.iccount = 128;
    compage_1.nmovbrk = 0;
    compage_1.nflb = 0;
    compage_1.nfpb = 0;
    compage_1.ipagfpb[0] = 1;
    compage_1.isysfpb[0] = 1;
    compage_1.ibarflb[0] = 1;
    compage_1.isysflb[0] = 1;
    compage_1.nistaff[0] = a1ll_2.nv - 1;

/*  Initialize for loop over lines */

    comkeys_1.nkeys = 1;
    comkeys_1.ibrkch[0] = 1;
    comkeys_1.shifton = FALSE_;
    a1ll_2.firstline = TRUE_;
    a1ll_2.newmeter = FALSE_;
    c1omget_1.ihead = 0;
    c1omget_1.isheadr = FALSE_;
    c1omnotes_1.gotclef = FALSE_;
    comkeys_1.idsig = 0;
    c1omnotes_1.iddot = 0;
    compage_1.fintstf = (float)-1.;
    compage_1.gintstf = (float)1.;
L30:
    loop = TRUE_;
    comkeys_1.iskchb = FALSE_;
    c1omget_1.issegno = FALSE_;
    a1ll_2.nbars = 0;
    c1omnotes_1.ibarmbr = 0;
/* L3: */
    i__1 = a1ll_2.nv;
    for (a1ll_2.iv = 1; a1ll_2.iv <= i__1; ++a1ll_2.iv) {
	c1ommvl_1.nvmx[a1ll_2.iv - 1] = 1;
	c1ommvl_1.ivmx[a1ll_2.iv - 1] = a1ll_2.iv;
	a1ll_2.itsofar[a1ll_2.iv - 1] = 0;
	a1ll_2.nnl[a1ll_2.iv - 1] = 0;
	for (j = 1; j <= 200; ++j) {
	    a1ll_2.rest[a1ll_2.iv + j * 15 - 16] = FALSE_;
/* L5: */
	}
/* L4: */
    }
    a1ll_2.iv = 1;
    c1ommvl_1.ivx = 1;
    c1omget_1.fbon = FALSE_;
    comkeys_1.barend = FALSE_;
    c1omget_1.isvolt = FALSE_;
L2:
    if (loop) {

/*  Within this short loop, nv voices are filled up for the duration of a block. */
/*  On exit (loop=.false.) the following are set: nnl(nv),itsofar(nv) */
/*  nodur(..),rest(..).  nnl will later be */
/*  increased and things slid around as accidental skips are added. */

	g1etnote_(&loop, &ifig, optimize);
	if (c1omget_1.lastchar) {
	    goto L20;
	}
	goto L2;
    }
    i__1 = a1ll_2.nbars;
    for (a1ll_2.ibar = 1; a1ll_2.ibar <= i__1; ++a1ll_2.ibar) {
	++c1omnotes_1.ibarcnt;

/*  The following is just a signal to start a new bar when cataloging spaces */
/*    for catspace(...) */

	c1omnotes_1.nptr[c1omnotes_1.ibarcnt] = c1omnotes_1.nptr[
		c1omnotes_1.ibarcnt - 1];
	newmb[c1omnotes_1.ibarcnt - 1] = FALSE_;
	if (a1ll_2.newmeter && a1ll_2.ibar == 1) {
	    newmb[c1omnotes_1.ibarcnt - 1] = TRUE_;
	}

/*  Above is only for spacing calcs later on.  Remember new meter can only occur */
/*  at START of a new input line (ibar = 1) */

	if (a1ll_2.ibar != c1omnotes_1.ibarmbr) {
	    if (! (*optimize)) {
		i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff;
		outbar_(&i__2, &jprntb);
	    }
	} else {
	    if (! (*optimize)) {
		s_wsfe(&io___85);
		do_fio(&c__1, " Multibar rest, bars", (ftnlen)20);
		i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff;
		do_fio(&c__1, (char *)&i__2, (ftnlen)sizeof(integer));
		do_fio(&c__1, "-", (ftnlen)1);
		i__3 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			c1omnotes_1.mbrest - 1;
		do_fio(&c__1, (char *)&i__3, (ftnlen)sizeof(integer));
		e_wsfe();
		s_wsfe(&io___86);
		do_fio(&c__1, " Multibar rest, bars", (ftnlen)20);
		i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff;
		do_fio(&c__1, (char *)&i__2, (ftnlen)sizeof(integer));
		do_fio(&c__1, "-", (ftnlen)1);
		i__3 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			c1omnotes_1.mbrest - 1;
		do_fio(&c__1, (char *)&i__3, (ftnlen)sizeof(integer));
		e_wsfe();
		jprntb = 0;
	    }
	    c1omnotes_1.ibaroff = c1omnotes_1.ibaroff - c1omnotes_1.mbrest + 
		    1;
	}
	if (a1ll_2.firstline && a1ll_2.lenbr0 != 0) {
	    if (a1ll_2.ibar == 1) {
		a1ll_2.lenbar = a1ll_2.lenbr0;
	    } else {
		a1ll_2.lenbar = a1ll_2.lenbr1;
	    }
	}
	if (a1ll_2.ibar > 1) {

/*  For bars after first, slide all stuff down to beginning of arrays */

	    i__2 = a1ll_2.nv;
	    for (a1ll_2.iv = 1; a1ll_2.iv <= i__2; ++a1ll_2.iv) {
		i__3 = c1ommvl_1.nvmx[a1ll_2.iv - 1];
		for (kv = 1; kv <= i__3; ++kv) {
		    c1ommvl_1.ivx = c1ommvl_1.ivmx[a1ll_2.iv + kv * 15 - 16];
		    ioff = a1ll_2.nib[c1ommvl_1.ivx + (a1ll_2.ibar - 1) * 15 
			    - 16];
		    i__4 = a1ll_2.nib[c1ommvl_1.ivx + a1ll_2.ibar * 15 - 16] 
			    - ioff;
		    for (ip = 1; ip <= i__4; ++ip) {
			a1ll_2.nodur[c1ommvl_1.ivx + ip * 15 - 16] = 
				a1ll_2.nodur[c1ommvl_1.ivx + (ip + ioff) * 15 
				- 16];
			a1ll_2.rest[c1ommvl_1.ivx + ip * 15 - 16] = 
				a1ll_2.rest[c1ommvl_1.ivx + (ip + ioff) * 15 
				- 16];
/* L12: */
		    }
/* L11: */
		}
	    }
	}
	i__3 = a1ll_2.nv;
	for (a1ll_2.iv = 1; a1ll_2.iv <= i__3; ++a1ll_2.iv) {
	    i__2 = c1ommvl_1.nvmx[a1ll_2.iv - 1];
	    for (kv = 1; kv <= i__2; ++kv) {
		ioff = 0;
		if (a1ll_2.ibar > 1) {
		    ioff = a1ll_2.nib[c1ommvl_1.ivmx[a1ll_2.iv + kv * 15 - 16]
			     + (a1ll_2.ibar - 1) * 15 - 16];
		}
/* L67: */
	    }
	}
	makeabar_();
	elsk[c1omnotes_1.ibarcnt - 1] = linecom_1.elskb + c1ommvl_1.fbar;
/* L10: */
    }
    a1ll_2.newmeter = FALSE_;
    a1ll_2.firstline = FALSE_;
    goto L30;
L20:

/* Vertical analysis. */

    if (compage_1.npages == 0) {
	if (compage_1.nsyst == 0) {
	    s_wsle(&io___91);
	    do_lio(&c__9, &c__1, "When npages=0, must set nsyst=bars/syst, n\
ot 0", (ftnlen)46);
	    e_wsle();
	    s_stop("1", (ftnlen)1);
	}
	compage_1.nsyst = (c1omnotes_1.ibarcnt - 1) / compage_1.nsyst + 1;
	if (a1ll_2.nv == 1) {
	    nsystpp = 12;
	} else if (a1ll_2.nv == 2) {
	    nsystpp = 7;
	} else if (a1ll_2.nv == 3) {
	    nsystpp = 5;
	} else if (a1ll_2.nv == 4) {
	    nsystpp = 3;
	} else {
	    nsystpp = 2;
	}
	compage_1.npages = (compage_1.nsyst - 1) / nsystpp + 1;
    }

/*  Check nsyst vs ibarcnt */

    if (compage_1.nsyst > c1omnotes_1.ibarcnt) {
	s_wsle(&io___93);
	e_wsle();
	s_wsle(&io___94);
	do_lio(&c__9, &c__1, "nsyst,ibarcnt:", (ftnlen)14);
	do_lio(&c__3, &c__1, (char *)&compage_1.nsyst, (ftnlen)sizeof(integer)
		);
	do_lio(&c__3, &c__1, (char *)&c1omnotes_1.ibarcnt, (ftnlen)sizeof(
		integer));
	e_wsle();
	s_wsle(&io___95);
	do_lio(&c__9, &c__1, "There are more systems than bars.", (ftnlen)33);
	e_wsle();
	s_stop("1", (ftnlen)1);
    }

/*  Set up dummy forced line & page breaks after last real one */

    ++compage_1.nflb;
    compage_1.ibarflb[compage_1.nflb] = c1omnotes_1.ibarcnt + 1;
    compage_1.isysflb[compage_1.nflb] = compage_1.nsyst + 1;
    ++compage_1.nfpb;
    compage_1.ipagfpb[compage_1.nfpb] = compage_1.npages + 1;
    compage_1.isysfpb[compage_1.nfpb] = compage_1.nsyst + 1;
    heightil = compage_1.ptheight * (float)4. / commus_1.musize;
    o__1.oerr = 0;
    o__1.ounit = 12;
    o__1.ofnm = 0;
    o__1.orl = 0;
    o__1.osta = "SCRATCH";
    o__1.oacc = 0;
    o__1.ofm = 0;
    o__1.oblnk = 0;
    f_open(&o__1);
    s_wsfe(&io___97);
    do_fio(&c__1, basenameq, (*lbase));
    e_wsfe();
    s_wsle(&io___98);
    do_lio(&c__3, &c__1, (char *)&(*lbase), (ftnlen)sizeof(integer));
    e_wsle();

/* Pass to pmxb the initial signature, including effect of transposition. */

    s_wsfe(&io___99);
    do_fio(&c__1, (char *)&c1ommvl_1.fbar, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&c1omnotes_1.wheadpt, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&cblock_1.etait, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&cblock_1.etatc, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&cblock_1.etacs1, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&cblock_1.etatop, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&cblock_1.etabot, (ftnlen)sizeof(real));
    do_fio(&c__1, (char *)&cominbot_1.inbothd, (ftnlen)sizeof(integer));
    do_fio(&c__1, (char *)&cblock_1.inhnoh, (ftnlen)sizeof(integer));
    do_fio(&c__1, (char *)&comkeys_1.isig1, (ftnlen)sizeof(integer));
    e_wsfe();
    s_wsle(&io___100);
    do_lio(&c__3, &c__1, (char *)&compage_1.npages, (ftnlen)sizeof(integer));
    do_lio(&c__4, &c__1, (char *)&compage_1.widthpt, (ftnlen)sizeof(real));
    do_lio(&c__4, &c__1, (char *)&compage_1.ptheight, (ftnlen)sizeof(real));
    do_lio(&c__3, &c__1, (char *)&compage_1.nsyst, (ftnlen)sizeof(integer));
    e_wsle();
    iflbnow = -1;
    isysb4 = 0;
    i__1 = compage_1.nfpb;
    for (ifpb = 1; ifpb <= i__1; ++ifpb) {

/*  Each time thru this loop is like a single score with several pages */

	compage_1.npages = compage_1.ipagfpb[ifpb] - compage_1.ipagfpb[ifpb - 
		1];
	compage_1.nsyst = compage_1.isysfpb[ifpb] - compage_1.isysfpb[ifpb - 
		1];
	nomnsystp = (compage_1.nsyst - 1) / compage_1.npages + 1;
	nshort = nomnsystp * compage_1.npages - compage_1.nsyst;
	i__2 = compage_1.npages;
	for (ipage = 1; ipage <= i__2; ++ipage) {
	    nsystp = nomnsystp;
	    if (ipage <= nshort) {
		--nsystp;
	    }

/*  Last system number on this page: */
	    isysendpg = isysb4 + nsystp;
	    nintpg = 0;
	    i__3 = isysendpg;
	    for (isy = isysb4 + 1; isy <= i__3; ++isy) {
		if (compage_1.isysflb[iflbnow + 1] == isy) {
		    ++iflbnow;
		}
		nintpg += compage_1.nistaff[iflbnow];
/* L15: */
	    }
	    xilfrac = (float)0.;
	    xiltxt = (float)0.;
	    if (ipage == 1 && c1omget_1.ihead > 0) {

/*  Needn't zero out ihead after printing titles if we only allow titles at top? */

		if ((c1omget_1.ihead & 1) == 1) {
		    xiltxt += cblock_1.hgtin * 4 / commus_1.musize;
		    xilfrac += cblock_1.etait;
		}
		if ((c1omget_1.ihead & 2) == 2) {
		    xiltxt += cblock_1.hgtti * 4 / commus_1.musize;
		    xilfrac += cblock_1.etatc;
		}
		if ((c1omget_1.ihead & 4) == 4) {
		    xiltxt += cblock_1.hgtco * 4 / commus_1.musize;
		    xilfrac += cblock_1.etacs1;
		} else {

/* Use double the title-composer space if there is no composer */

		    xilfrac += cblock_1.etatc;
		}
	    }
	    d__ = xilfrac + nsystp - 1 + cblock_1.etatop + cblock_1.etabot;
/*          C = nsystp*(nv-1) */
	    c__ = (real) nintpg;
/*          xN = heightil - xiltxt - 4*nsystp*nv - (nsystp-1)*xilbn */
	    xn = heightil - xiltxt - (nintpg + nsystp << 2) - (nsystp - 1) * 
		    cblock_1.xilbn;
	    if (bottreb) {
		xn -= (nsystp - 1) * cblock_1.xilbtc;
	    }
	    if (c1omget_1.ihead == 0 && c1omget_1.isheadr) {
		xn -= cblock_1.xilhdr;
	    }
	    if (ifig == 1) {
		xn -= nsystp * cblock_1.xilfig;
	    }
	    glueil = (xn - cblock_1.b * c__) / (d__ + cblock_1.a * c__);
	    omegag = (cblock_1.b * d__ + cblock_1.a * xn) / (d__ + cblock_1.a 
		    * c__);

/*  G = \interlines between systems */
/*  omega*G = \interlines between staves of the same system */
/*  \interstaff = 4+omega*G */
/*  C = total number of interstaff spaces in the page */
/*  D = omega-indep factors for scalable height = nsy-1 (intersystem glue) */
/*      + etatop + etabot + etatxt + */
/*  N = scaleable height (\interlignes) = height - htext - staff heights - xil */
/*  xil = extra interliges = (nsy-1)*xilbn + 10 if header and no titles */
/*                          + (nsy-1)*xiltcb    for treble clef bottoms */
/*                          + nsy*xilfig        for figures */
/*  G = N/(D + omega * C) = glueil,   (1) */
/*  But (empirically)  omega*G = a*G + b (2) */
/*      with a=1.071 and b=2.714 */
/*  Solving (1) and (2) gives */
/*      G = (N-b*C)/(D+a*C) , omega*G = (b*D+a*N)/(D+a*C) */
/*  Pass to pmxb    omega*G (=\interstaff-4) */
/*                  (etatop,bot,it,tc,cx)*G as inputs to \titles */

/*       glueil = (heightil-xiltxt-nsystp*(xil+4*nv)) */
/*    *             /(nsystp*(1+gfact*(nv-1))-1+etatop+etabot+xilfrac) */
/*       xnsttop = glueil*etatop */
/*       xintstaff = 4+gfact*glueil */

/*  Only the first page will get local adjustment now if needed, others in pmxb */

	    if (ifpb == 1 && ipage == 1 && compage_1.fintstf > (float)0.) {
		facins = compage_1.fintstf;
		compage_1.fintstf = (float)-1.;
	    } else {

/*  gintstf = 1.0 by default, but may be changed with AI<x> */

		facins = compage_1.gintstf;
	    }
	    s_wsle(&io___119);
	    do_lio(&c__3, &c__1, (char *)&nsystp, (ftnlen)sizeof(integer));
/* Computing MAX */
	    r__2 = (float)0., r__3 = cblock_1.etatop * glueil;
	    r__1 = dmax(r__2,r__3);
	    do_lio(&c__4, &c__1, (char *)&r__1, (ftnlen)sizeof(real));
	    r__4 = facins * (omegag + 4);
	    do_lio(&c__4, &c__1, (char *)&r__4, (ftnlen)sizeof(real));
	    e_wsle();
	    c1omget_1.ihead = 0;
	    c1omget_1.isheadr = FALSE_;
	    isysb4 = isysendpg;
/* L7: */
	}
/* L8: */
    }

/*  Done with vertical, now do horizontals */

    celsk[1] = elsk[0];
    i__1 = c1omnotes_1.ibarcnt;
    for (a1ll_2.ibar = 2; a1ll_2.ibar <= i__1; ++a1ll_2.ibar) {
	celsk[a1ll_2.ibar] = celsk[a1ll_2.ibar - 1] + elsk[a1ll_2.ibar - 1];
/* L21: */
    }
    lastbar[0] = 0;
    ibar1 = 1;
    wmins = (float)-1.;
    iflb = 1;
    imovbrk = 0;
    ikey = 1;

/*  Return nsyst to its *total* value */

    compage_1.nsyst = compage_1.isysfpb[compage_1.nfpb] - 1;
    i__1 = compage_1.nsyst;
    for (isyst = 1; isyst <= i__1; ++isyst) {
	if (isyst == compage_1.isysflb[iflb]) {
	    ++iflb;
	}
	if (compage_1.nmovbrk > 0 && imovbrk < compage_1.nmovbrk) {
	    if (isyst == compage_1.isysmb[imovbrk + 1]) {
		++imovbrk;
	    }
	}
	ibarb4 = lastbar[isyst - 1];
	if (isyst == 1) {
	    if (*isfirst) {
		elsstarg = celsk[compage_1.ibarflb[1] - 1] / (
			compage_1.isysflb[1] - 1 - c1omget_1.fracindent) * (1 
			- c1omget_1.fracindent);
	    }
	    celskb4 = (float)0.;
	} else {
	    celskb4 = celsk[ibarb4];

/*  Must dimension isysmb(0:*) just so I can execute this test! */

	    if (*isfirst) {
		if (compage_1.nmovbrk > 0 && isyst == compage_1.isysmb[
			imovbrk]) {

/*  First syst after forced line break.  There may be indentation. */

		    elsstarg = (celsk[compage_1.ibarflb[iflb] - 1] - celskb4) 
			    / (compage_1.isysflb[iflb] - isyst - 
			    compage_1.fracsys[imovbrk - 1]) * (1 - 
			    compage_1.fracsys[imovbrk - 1]);
		} else {

/*  There is no indentation to deal with */

		    elsstarg = (celsk[compage_1.ibarflb[iflb] - 1] - celskb4) 
			    / (compage_1.isysflb[iflb] - isyst);
		}
	    }
	}
	if (*isfirst) {
	    diff1 = (r__1 = elsstarg - elsk[ibarb4], dabs(r__1));
	    i__2 = c1omnotes_1.ibarcnt;
	    for (a1ll_2.ibar = ibarb4 + 2; a1ll_2.ibar <= i__2; ++a1ll_2.ibar)
		     {
		diff = elsstarg - (celsk[a1ll_2.ibar] - celskb4);
		if (dabs(diff) >= diff1) {
		    goto L24;
		}
		diff1 = dabs(diff);
/* L23: */
	    }
L24:
	    --a1ll_2.ibar;
	    lastbar[isyst] = a1ll_2.ibar;
	    nbarss[isyst] = a1ll_2.ibar - ibarb4;
	} else {

/*  nbarss is given as an input, must compute lastbar and ibar */

	    lastbar[isyst] = nbarss[isyst] + ibarb4;
	    a1ll_2.ibar = lastbar[isyst];
	}

/*  elss is # of elemskip in the syst. from notes & ars's, not ruleskips, ask's. */

	elss[isyst - 1] = celsk[a1ll_2.ibar] - celskb4;
	s_wsfe(&io___134);
	i__2 = lastbar[isyst - 1] + 1;
	do_fio(&c__1, (char *)&i__2, (ftnlen)sizeof(integer));
	e_wsfe();

/*  Transposed sigs are isig1, newkey(2,3,...). */

	if (ikey == 1) {
	    key1 = comkeys_1.isig1;
	} else {
	    key1 = comkeys_1.newkey[ikey - 1];
	}
	fsyst = wclef + abs(key1) * wkeysig + (float)2. / commus_1.musize;
	xelsk = (float)0.;
L1:
	if (ikey < comkeys_1.nkeys) {
	    if (comkeys_1.ibrkch[ikey] <= lastbar[isyst]) {

/*  Add space for all key changes */

		++ikey;
		key2 = comkeys_1.newkey[ikey - 1];
/* Computing MAX */
/* Computing MAX */
		i__5 = abs(key1), i__6 = abs(key2);
		i__3 = (i__2 = key2 - key1, abs(i__2)), i__4 = max(i__5,i__6);
		nacc = max(i__3,i__4);
		fsyst += nacc * wkeysig;

/*  Account for afterruleskips (fbar) */

		xelsk += c1ommvl_1.fbar / 2;
		if (comkeys_1.ibrkch[ikey - 1] < lastbar[isyst] && ! 
			comkeys_1.kchmid[ikey - 1]) {
		    xelsk += (float)-1.;
		}
		key1 = key2;
		goto L1;
	    }
	}

/*  Add extra fixed space for double bar */

	if (isyst == compage_1.nsyst) {
	    fsyst += (float)4.5 / commus_1.musize;
	}

/*  Add extra fixed space for initial time signature */

	if (isyst == 1) {
	    fsyst += wtimesig;
	}

/*  Add extra fixed space for time signature changes & user-defined spaces */

	i__2 = lastbar[isyst];
	for (ibars = ibarb4 + 1; ibars <= i__2; ++ibars) {
	    if (newmb[ibars - 1]) {
		fsyst += wtimesig;
	    }
	    fsyst += c1omnotes_1.udsp[ibars - 1] / commus_1.musize;
/* L26: */
	}
	if (isyst == 1) {
	    wdpt = compage_1.widthpt * (1 - c1omget_1.fracindent);
	} else {
	    if (compage_1.nmovbrk > 0 && imovbrk > 0 && isyst == 
		    compage_1.isysmb[imovbrk]) {
		wdpt = compage_1.widthpt * (1 - compage_1.fracsys[imovbrk - 1]
			);
	    } else {
		wdpt = compage_1.widthpt;
	    }
	}
	wsyspt = wdpt - fsyst * commus_1.musize - nbarss[isyst] * (float).4;

/*  Checks for min spacing */
/*  Get min allowable space */

	dtmin = (float)1e3;
	i__2 = ibar1 + nbarss[isyst] - 1;
	for (a1ll_2.ibar = ibar1; a1ll_2.ibar <= i__2; ++a1ll_2.ibar) {
/* Computing MIN */
	    r__1 = dtmin, r__2 = linecom_1.tnminb[a1ll_2.ibar - 1];
	    dtmin = dmin(r__1,r__2);
	    if (c1omnotes_1.wminnh[a1ll_2.ibar - 1] >= (float)0.) {
		wmins = c1omnotes_1.wminnh[a1ll_2.ibar - 1];
	    }
/* L45: */
	}
	if (wmins < (float)0.) {
	    wmins = (float).3;
	}
	wminpt = (wmins + 1) * (float).3 * commus_1.musize;

/*  Find max duration & # of notes for this system */

	dtmax = (float)0.;
	nns = 0;
	i__2 = c1omnotes_1.nptr[ibar1 + nbarss[isyst] - 1] - 1;
	for (iptr = c1omnotes_1.nptr[ibar1 - 1]; iptr <= i__2; ++iptr) {
/* Computing MAX */
	    r__1 = dtmax, r__2 = c1omnotes_1.durb[iptr - 1];
	    dtmax = dmax(r__1,r__2);
	    nns += c1omnotes_1.nnpd[iptr - 1];
/* L43: */
	}
	elmin0 = wsyspt * f1eon_(&dtmin) / (elss[isyst - 1] + xelsk);
	if (elmin0 >= wminpt) {

/*  Subtract out fbar stuff to keep old way of passing sumelsk to pmxb; */
/*    there is no need to "flatten" */

	    sumelsk = elss[isyst - 1] - c1ommvl_1.fbar * nbarss[isyst];
	    comeon_1.eonk = (float)0.;
	    comeon_1.ewmxk = (float)1.;
	} else {
	    elmin1 = wsyspt / ((c1ommvl_1.fbar * nbarss[isyst] + xelsk) / 
		    f1eon_(&dtmax) + nns);
	    if (elmin1 <= wminpt) {
		s_wsle(&io___151);
		e_wsle();
		s_wsle(&io___152);
		do_lio(&c__9, &c__1, "In system #", (ftnlen)11);
		do_lio(&c__3, &c__1, (char *)&isyst, (ftnlen)sizeof(integer));
		do_lio(&c__9, &c__1, " cannot meet min. space rqmt", (ftnlen)
			28);
		e_wsle();
		s_wsfe(&io___153);
		do_fio(&c__1, "In system #", (ftnlen)11);
		do_fio(&c__1, (char *)&isyst, (ftnlen)sizeof(integer));
		do_fio(&c__1, " cannot meet min. space rqmt", (ftnlen)28);
		e_wsfe();
		comeon_1.eonk = (float).9;
	    } else {

/*  Find eonk by Newton method */

/*            eonk = min(.9,(wminpt-elmin0)/(elmin1-elmin0)) */
		i__2 = c1omnotes_1.nptr[ibar1 + nbarss[isyst] - 1] - 1;
		r__1 = wsyspt / wminpt;
		r__2 = c1ommvl_1.fbar * nbarss[isyst] + xelsk;
		r__3 = (wminpt - elmin0) / (elmin1 - elmin0);
		findeonk_(&c1omnotes_1.nptr[ibar1 - 1], &i__2, &r__1, &r__2, &
			dtmin, &dtmax, &r__3);
		comeon_1.eonk = dmin((float).9,comeon_1.eonk);
	    }
	    d__1 = (doublereal) f1eon_(&dtmax);
	    d__2 = (doublereal) comeon_1.eonk;
	    comeon_1.ewmxk = pow_dd(&d__1, &d__2);

/*  Recompute poenom! */

	    sumelsk = (float)0.;
	    i__2 = c1omnotes_1.nptr[ibar1 + nbarss[isyst] - 1] - 1;
	    for (iptr = c1omnotes_1.nptr[ibar1 - 1]; iptr <= i__2; ++iptr) {
		r__1 = c1omnotes_1.durb[iptr - 1] / c1omnotes_1.sqzb[iptr - 1]
			;
		sumelsk += c1omnotes_1.nnpd[iptr - 1] * c1omnotes_1.sqzb[iptr 
			- 1] * feon_(&r__1);
/* L44: */
	    }
	}
	poenom = wsyspt / (sumelsk + c1ommvl_1.fbar * nbarss[isyst] + xelsk);

/* Set fracindent for output: orig if isyst=1, fracsys(imovbrk) if movbrk, else 0 */

	if (isyst > 0) {
	    if (compage_1.nmovbrk > 0 && imovbrk > 0 && isyst == 
		    compage_1.isysmb[imovbrk]) {
		c1omget_1.fracindent = compage_1.fracsys[imovbrk - 1];
	    } else {
		c1omget_1.fracindent = (float)0.;
	    }
	}
	s_wsfe(&io___155);
	do_fio(&c__1, (char *)&poenom, (ftnlen)sizeof(real));
	do_fio(&c__1, (char *)&nbarss[isyst], (ftnlen)sizeof(integer));
	do_fio(&c__1, (char *)&sumelsk, (ftnlen)sizeof(real));
	do_fio(&c__1, (char *)&fsyst, (ftnlen)sizeof(real));
	do_fio(&c__1, (char *)&c1omget_1.fracindent, (ftnlen)sizeof(real));
	do_fio(&c__1, (char *)&comeon_1.eonk, (ftnlen)sizeof(real));
	do_fio(&c__1, (char *)&comeon_1.ewmxk, (ftnlen)sizeof(real));
	e_wsfe();
	ibar1 += nbarss[isyst];
/* L22: */
    }
    al__1.aerr = 0;
    al__1.aunit = 12;
    f_rew(&al__1);
    o__1.oerr = 0;
    o__1.ounit = 13;
    o__1.ofnm = 0;
    o__1.orl = 0;
    o__1.osta = "SCRATCH";
    o__1.oacc = 0;
    o__1.ofm = 0;
    o__1.oblnk = 0;
    f_open(&o__1);
    s_wsfe(&io___156);
    do_fio(&c__1, (char *)&ifig, (ftnlen)sizeof(integer));
    e_wsfe();
    al__1.aerr = 0;
    al__1.aunit = 13;
    f_rew(&al__1);
    inbuff_1.ilbuf = 1;
    inbuff_1.ipbuf = 0;
    if (! (*optimize)) {
	s_wsfe(&io___157);
	do_fio(&c__1, " Done with first pass", (ftnlen)21);
	e_wsfe();
	s_wsle(&io___158);
	e_wsle();
	s_wsfe(&io___159);
	do_fio(&c__1, " Done with first pass", (ftnlen)21);
	e_wsfe();
	s_wsfe(&io___160);
	e_wsfe();
    }

/*  Following syntax is needed since pmxa is called with literal argument .false. */

    if (*isfirst) {
	*isfirst = FALSE_;
    }
    return 0;
} /* pmxa_ */

/* Subroutine */ int g1etnote_(loop, ifig, optimize)
logical *loop;
integer *ifig;
logical *optimize;
{
    /* Initialized data */

    static char literq[51*2+1] = "Literal TeX string cannot start with 4 bac\
kslashes!TeX string must have <129 char, end with backslash!";

    /* System generated locals */
    integer i__1, i__2, i__3, i__4, i__5;
    real r__1;
    char ch__1[1];

    /* Builtin functions */
    integer i_indx(), s_wsle(), do_lio(), e_wsle();
    /* Subroutine */ int s_stop();
    integer s_cmp(), i_nint();
    double log();
    integer pow_ii(), s_wsfe(), do_fio(), e_wsfe(), s_rsfe(), e_rsfe();

    /* Local variables */
    static integer i__, j, ic, igr;
    static real dum;
    static integer ngr, iiv, num1, num2;
    extern /* Character */ VOID chax_();
    static real fnum;
    static char dumq[1], dotq[1], durq[1];
    static integer itup;
    static real snum;
    static integer ntup;
    extern /* Subroutine */ int g1etx_(), read10_();
    static real dimen;
    static char charq[1];
    static integer indxb;
    static char lineq[128];
    static integer icsav, iorig, iinow, iposn, ninow, icclhw;
    static char charlq[1];
    extern /* Subroutine */ int setmac_(), chklit_();
    static logical fulbrp;
    extern /* Subroutine */ int errmsg_();
    static integer literr, mtrdnp;
    static real sysflb;
    static integer numint, mtrnmp, numnum;
    static real fnsyst;
    static integer lenbeat;
    extern /* Subroutine */ int getmidi_(), readnum_();
    static integer mtrdenl, lenmult, numshft;
    static logical plusmin;
    static real tintstf;
    extern /* Subroutine */ int g1etchar_();
    extern integer i1fnodur_();
    extern /* Subroutine */ int checkdyn_();
    static integer idotform;
    extern /* Subroutine */ int readmeter_();

    /* Fortran I/O blocks */
    static cilist io___165 = { 0, 6, 0, 0, 0 };
    static cilist io___166 = { 0, 6, 0, 0, 0 };
    static cilist io___174 = { 0, 6, 0, 0, 0 };
    static cilist io___175 = { 0, 6, 0, 0, 0 };
    static cilist io___176 = { 0, 6, 0, 0, 0 };
    static cilist io___180 = { 0, 6, 0, 0, 0 };
    static cilist io___181 = { 0, 6, 0, 0, 0 };
    static cilist io___182 = { 0, 6, 0, 0, 0 };
    static cilist io___192 = { 0, 6, 0, 0, 0 };
    static cilist io___196 = { 0, 6, 0, 0, 0 };
    static cilist io___197 = { 0, 6, 0, 0, 0 };
    static cilist io___198 = { 0, 6, 0, 0, 0 };
    static cilist io___201 = { 0, 6, 0, 0, 0 };
    static cilist io___207 = { 0, 6, 0, 0, 0 };
    static cilist io___208 = { 0, 6, 0, 0, 0 };
    static cilist io___209 = { 0, 6, 0, 0, 0 };
    static cilist io___210 = { 0, 6, 0, 0, 0 };
    static cilist io___214 = { 0, 6, 0, 0, 0 };
    static cilist io___215 = { 0, 6, 0, 0, 0 };
    static cilist io___216 = { 0, 6, 0, 0, 0 };
    static cilist io___218 = { 0, 6, 0, "(1x,a21,i3,a23)", 0 };
    static cilist io___222 = { 0, 6, 0, 0, 0 };
    static cilist io___223 = { 0, 6, 0, 0, 0 };
    static cilist io___224 = { 0, 5, 0, "(a)", 0 };
    static cilist io___228 = { 0, 6, 0, 0, 0 };


L1:
    g1etchar_(lineq, &a1ll_2.iccount, charq, (ftnlen)128, (ftnlen)1);
    if (*(unsigned char *)charq != ' ') {
	*(unsigned char *)charlq = *(unsigned char *)charq;
    }
    if (c1omget_1.lastchar) {
	if (i_indx("/%", charlq, (ftnlen)2, (ftnlen)1) == 0) {
	    s_wsle(&io___165);
	    do_lio(&c__9, &c__1, "Last non-blank character is \"", (ftnlen)29)
		    ;
	    do_lio(&c__9, &c__1, charlq, (ftnlen)1);
	    do_lio(&c__9, &c__1, "\", not \"/,%\"", (ftnlen)12);
	    e_wsle();
	    s_wsle(&io___166);
	    do_lio(&c__9, &c__1, "ASCII code:", (ftnlen)11);
	    i__1 = *(unsigned char *)charlq;
	    do_lio(&c__3, &c__1, (char *)&i__1, (ftnlen)sizeof(integer));
	    e_wsle();
	    s_stop("1", (ftnlen)1);
	}
	return 0;
    }
    if (*(unsigned char *)charq == ' ') {
	goto L1;
    } else if (*(unsigned char *)charq == '%' && a1ll_2.iccount == 1) {
	a1ll_2.iccount = 128;
	goto L1;
    } else if (*(unsigned char *)charq >= 97 && *(unsigned char *)charq <= 
	    103 || *(unsigned char *)charq == 'r') {

/*  This is a note/rest. gotclef is only used for checking for clef before "/" */

	if (c1omnotes_1.gotclef) {
	    c1omnotes_1.gotclef = FALSE_;
	}
	idotform = 0;
	numnum = 0;
	plusmin = FALSE_;
L28:
	++a1ll_2.nnl[c1ommvl_1.ivx - 1];
	if (a1ll_2.nnl[c1ommvl_1.ivx - 1] > 200) {
	    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + a1ll_2.nbars + 
		    1;
	    errmsg_(lineq, &a1ll_2.iccount, &i__1, ">200 notes in line of mu\
sic. Use smaller blocks!", (ftnlen)128, (ftnlen)48);
	    s_stop("1", (ftnlen)1);
	}
	*(unsigned char *)dotq = 'x';

/*  Check if this is 'r ' and previous note was full-bar-pause */

	i__1 = a1ll_2.iccount;
/* Computing MAX */
	i__2 = 1, i__3 = a1ll_2.nnl[c1ommvl_1.ivx - 1] - 1;
/* Computing MAX */
	i__4 = 1, i__5 = a1ll_2.nnl[c1ommvl_1.ivx - 1] - 1;
	fulbrp = *(unsigned char *)charq == 'r' && s_cmp(lineq + i__1, " ", 
		a1ll_2.iccount + 1 - i__1, (ftnlen)1) == 0 && a1ll_2.nnl[
		c1ommvl_1.ivx - 1] > 1 && a1ll_2.rest[c1ommvl_1.ivx + max(
		i__2,i__3) * 15 - 16] && a1ll_2.nodur[c1ommvl_1.ivx + max(
		i__4,i__5) * 15 - 16] == a1ll_2.lenbar;
L2:
	g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	ic = *(unsigned char *)durq;
	if (ic <= 57 && ic >= 48) {

/*  Digit */

	    if (numnum == 0) {
		c1omnotes_1.nnodur = ic - 48;
		numnum = 1;
		goto L2;
	    } else if (numnum == 1) {
		if (*(unsigned char *)charq == 'r') {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Only one digit a\
llowed after rest symbol \"r\"!", (ftnlen)128, (ftnlen)45);
		    s_stop("1", (ftnlen)1);
		}
		numnum = 2;
		if (plusmin) {
		    s_wsle(&io___174);
		    e_wsle();
		    s_wsle(&io___175);
		    do_lio(&c__9, &c__1, "*********WARNING*********", (ftnlen)
			    25);
		    e_wsle();
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Before version 1\
.2, +/- was ignored if octave was!", (ftnlen)128, (ftnlen)50);
		    s_wsle(&io___176);
		    do_lio(&c__9, &c__1, "explicitly specified.  May need to\
 edit old editions", (ftnlen)52);
		    e_wsle();
		}
		goto L2;
	    } else {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, ">2 digits in note sy\
mbol!", (ftnlen)128, (ftnlen)25);
		s_stop("1", (ftnlen)1);
	    }
	} else if (*(unsigned char *)durq == 'd') {
	    *(unsigned char *)dotq = *(unsigned char *)durq;
	    i__1 = a1ll_2.iccount;
	    if (s_cmp(lineq + i__1, "d", a1ll_2.iccount + 1 - i__1, (ftnlen)1)
		     == 0) {
		c1omnotes_1.iddot = 1;
		++a1ll_2.iccount;

/*  Since we flow out, double dots won't work with other dot options */

	    }
	    i__1 = a1ll_2.iccount;
	    if (i_indx("+-", lineq + i__1, (ftnlen)2, a1ll_2.iccount + 1 - 
		    i__1) > 0) {

/*  move a dot, provided a number follows. */

		g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)
			1);
		g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)
			1);
		if (i_indx("0123456789-.", durq, (ftnlen)12, (ftnlen)1) == 0) 
			{

/*  Backup, exit the loop normally */

		    a1ll_2.iccount += -2;
		    goto L2;
		}
		readnum_(lineq, &a1ll_2.iccount, dumq, &fnum, (ftnlen)128, (
			ftnlen)1);
		if (i_indx("+-", dumq, (ftnlen)2, (ftnlen)1) > 0) {

/*  Vertical shift also */

		    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (
			    ftnlen)1);
		    if (i_indx("0123456789-.", durq, (ftnlen)12, (ftnlen)1) ==
			     0) {
			i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &a1ll_2.iccount, &i__1, "Expected num\
ber after 2nd +/- (shift dot)!", (ftnlen)128, (ftnlen)42);
			s_stop("1", (ftnlen)1);
		    }
		    readnum_(lineq, &a1ll_2.iccount, durq, &fnum, (ftnlen)128,
			     (ftnlen)1);
		}
		--a1ll_2.iccount;
	    }
	    goto L2;
	} else if (i_indx("<>", durq, (ftnlen)2, (ftnlen)1) > 0) {

/*  Accidental shift */

	    i__1 = a1ll_2.iccount - 2;
	    if (i_indx("fsn", lineq + i__1, (ftnlen)3, a1ll_2.iccount - 1 - 
		    i__1) == 0) {
		i__1 = a1ll_2.iccount - 1;
		i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &i__1, &i__2, "Expected \"f\", \"s\", or \"\
n\" before \"<\" or \">\"!", (ftnlen)128, (ftnlen)44);
		s_stop("1", (ftnlen)1);
	    }
	    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (i_indx("123456789.0", durq, (ftnlen)11, (ftnlen)1) == 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Expected number afte\
r </> (accidental shift)!", (ftnlen)128, (ftnlen)45);
		s_stop("1", (ftnlen)1);
	    }
	    readnum_(lineq, &a1ll_2.iccount, durq, &fnum, (ftnlen)128, (
		    ftnlen)1);
	    if (fnum > (float)3.15) {
		i__1 = a1ll_2.iccount - 1;
		i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &i__1, &i__2, "Horizontal accidental shift mu\
st be less than 3.15!", (ftnlen)128, (ftnlen)51);
		s_stop("1", (ftnlen)1);
	    }
	    --a1ll_2.iccount;
	    goto L2;
	} else if (i_indx("+-", durq, (ftnlen)2, (ftnlen)1) > 0) {
	    if (*(unsigned char *)charq != 'r') {
		i__1 = a1ll_2.iccount - 2;
		i__2 = a1ll_2.iccount;
		if (i_indx("fsn", lineq + i__1, (ftnlen)3, a1ll_2.iccount - 1 
			- i__1) > 0 && i_indx("0123456789", lineq + i__2, (
			ftnlen)10, a1ll_2.iccount + 1 - i__2) > 0) {

/*  This may be start of accidental shift, but may be octave and duration */

		    icsav = a1ll_2.iccount;
		    ++a1ll_2.iccount;
		    readnum_(lineq, &a1ll_2.iccount, durq, &fnum, (ftnlen)128,
			     (ftnlen)1);
		    if (i_indx("+-", durq, (ftnlen)2, (ftnlen)1) > 0) {

/*  This is an accid shift */

			if (fnum > (float)30.5) {
			    i__1 = a1ll_2.iccount - 1;
			    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff 
				    + a1ll_2.nbars + 1;
			    errmsg_(lineq, &i__1, &i__2, "Vertical accidenta\
l shift must be less than 31!", (ftnlen)128, (ftnlen)47);
			    s_stop("1", (ftnlen)1);
			}
			g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (
				ftnlen)1);
			if (i_indx("1234567890.", durq, (ftnlen)11, (ftnlen)1)
				 == 0) {
			    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff 
				    + a1ll_2.nbars + 1;
			    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Expected\
 2nd number of 2-number accidental shift)!", (ftnlen)128, (ftnlen)50);
			    s_stop("1", (ftnlen)1);
			}
			readnum_(lineq, &a1ll_2.iccount, durq, &fnum, (ftnlen)
				128, (ftnlen)1);
			if (fnum > (float)3.15) {
			    i__1 = a1ll_2.iccount - 1;
			    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff 
				    + a1ll_2.nbars + 1;
			    errmsg_(lineq, &i__1, &i__2, "Horizontal acciden\
tal shift must be less than 3.15!", (ftnlen)128, (ftnlen)51);
			    s_stop("1", (ftnlen)1);
			}
			--a1ll_2.iccount;
			goto L2;
		    } else {

/*  Not accid shift, reset, then flow out */

			a1ll_2.iccount = icsav;
		    }
		}
		plusmin = TRUE_;
		if (numnum == 2) {
		    s_wsle(&io___180);
		    e_wsle();
		    s_wsle(&io___181);
		    do_lio(&c__9, &c__1, "*********WARNING*********", (ftnlen)
			    25);
		    e_wsle();
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Before version 1\
.2, +/- was ignored if octave was!", (ftnlen)128, (ftnlen)50);
		    s_wsle(&io___182);
		    do_lio(&c__9, &c__1, "explicitly specified.  May need to\
 edit old editions", (ftnlen)52);
		    e_wsle();
		}
		goto L2;

/*  It's a rest containing +|- .  Must refer to a vertical shift.  Read past. */

	    } else {
		g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)
			1);
		readnum_(lineq, &a1ll_2.iccount, durq, &dum, (ftnlen)128, (
			ftnlen)1);
		--a1ll_2.iccount;
		goto L2;
	    }
	} else if (i_indx("fsnulare", durq, (ftnlen)8, (ftnlen)1) > 0) {
	    goto L2;
	} else if (*(unsigned char *)durq == 'p') {
	    fulbrp = *(unsigned char *)charq == 'r';
	    if (! fulbrp) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "The option \"p\" onl\
y works with \"r\" (rest)!", (ftnlen)128, (ftnlen)42);
		s_stop("1", (ftnlen)1);
	    }
	    goto L2;
	} else if (*(unsigned char *)durq == 'b') {
	    if (*(unsigned char *)charq != 'r') {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "You entered \"b\"; I\
 expected \"rb\"!", (ftnlen)128, (ftnlen)33);
		s_stop("1", (ftnlen)1);
	    } else if (numnum == 2) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "You entered \"r\" &\
 \"b\" with two numbers!", (ftnlen)128, (ftnlen)39);
	    }
	    goto L2;
	} else if (*(unsigned char *)durq == 'x') {

/*  xtuplet: Set all durations to 0 except last one. */

	    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (i_indx("123456789", durq, (ftnlen)9, (ftnlen)1) == 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "First char after \"\
x\" in xtuplet must be \"1\"-\"9\"!", (ftnlen)128, (ftnlen)48);
		s_stop("1", (ftnlen)1);
	    }
	    readnum_(lineq, &a1ll_2.iccount, durq, &fnum, (ftnlen)128, (
		    ftnlen)1);
	    if (fnum > (float)99.) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Xtuplet cannot have \
more than 99 notes!", (ftnlen)128, (ftnlen)39);
		s_stop("1", (ftnlen)1);
	    } else if (i_indx(" n", durq, (ftnlen)2, (ftnlen)1) == 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Only legal character\
s here are \" \" or \"n\"!", (ftnlen)128, (ftnlen)42);
		s_stop("1", (ftnlen)1);
	    }
	    if (*(unsigned char *)durq == 'n') {

/*  Number alteration stuff */

		numshft = 0;
L30:
		g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)
			1);
		if (*(unsigned char *)durq == 'f') {
		    goto L30;
		} else if (i_indx("+-", durq, (ftnlen)2, (ftnlen)1) > 0) {
		    ++numshft;
		    if (numshft == 3) {
			i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &a1ll_2.iccount, &i__1, "Only 2 numbe\
rs are allowed after \"n\" in xtup!", (ftnlen)128, (ftnlen)45);
			s_stop("1", (ftnlen)1);
		    }
		    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (
			    ftnlen)1);
		    if (i_indx("0123456789.", durq, (ftnlen)11, (ftnlen)1) == 
			    0) {
			i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &a1ll_2.iccount, &i__1, "This charact\
er should be a digit or \".\"!", (ftnlen)128, (ftnlen)40);
			s_stop("1", (ftnlen)1);
		    }
		    readnum_(lineq, &a1ll_2.iccount, durq, &snum, (ftnlen)128,
			     (ftnlen)1);
		    --a1ll_2.iccount;
		    if (numshft == 1 && snum > (float)15.1 || numshft == 2 && 
			    snum > (float)1.51) {
			i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &a1ll_2.iccount, &i__1, "Number aft\
er \"n\" in xtup is out of range!", (ftnlen)128, (ftnlen)41);
			s_stop("1", (ftnlen)1);
		    }
		    goto L30;
		} else if (*(unsigned char *)durq != ' ') {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Illegal characte\
r after \"n\" in xtup!", (ftnlen)128, (ftnlen)36);
		    s_stop("1", (ftnlen)1);
		}
	    }
	    ntup = i_nint(&fnum);
	    i__1 = ntup;
	    for (itup = 2; itup <= i__1; ++itup) {
		a1ll_2.nodur[c1ommvl_1.ivx + a1ll_2.nnl[c1ommvl_1.ivx - 1] * 
			15 - 16] = 0;
		++a1ll_2.nnl[c1ommvl_1.ivx - 1];
L110:
		g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)
			1);
		if (*(unsigned char *)durq == ' ') {
		    goto L110;
		} else if (*(unsigned char *)durq == 'o') {

/*  Ornament in xtup.  "o" symbol must come AFTER the affected note */

		    g1etchar_(lineq, &a1ll_2.iccount, dumq, (ftnlen)128, (
			    ftnlen)1);
		    if (i_indx("(stmx+Tup._)e:>^", dumq, (ftnlen)16, (ftnlen)
			    1) == 0) {
			if (i_indx("fg", dumq, (ftnlen)2, (ftnlen)1) > 0) {
			    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff 
				    + a1ll_2.nbars + 1;
			    errmsg_(lineq, &a1ll_2.iccount, &i__2, "Fermata \
or segno not allowed in xtuplet!", (ftnlen)128, (ftnlen)40);
			} else {
			    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff 
				    + a1ll_2.nbars + 1;
			    errmsg_(lineq, &a1ll_2.iccount, &i__2, "Illegal \
ornament!", (ftnlen)128, (ftnlen)17);
			}
			s_stop("1", (ftnlen)1);
		    }
		    if (*(unsigned char *)dumq == 'T') {

/*  Trill.  may be followed by 't' and/or number.  read 'til blank */

L29:
			g1etchar_(lineq, &a1ll_2.iccount, dumq, (ftnlen)128, (
				ftnlen)1);
			if (*(unsigned char *)dumq != ' ') {
			    goto L29;
			}
		    } else if (*(unsigned char *)dumq == 'e') {
			g1etchar_(lineq, &a1ll_2.iccount, dumq, (ftnlen)128, (
				ftnlen)1);
			if (i_indx("sfn?", dumq, (ftnlen)4, (ftnlen)1) == 0) {
			    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff 
				    + a1ll_2.nbars + 1;
			    errmsg_(lineq, &a1ll_2.iccount, &i__2, "Illegal \
character after \"e\" in edit. accid. symbol!", (ftnlen)128, (ftnlen)51);
			    s_stop("1", (ftnlen)1);
			}
			g1etchar_(lineq, &a1ll_2.iccount, dumq, (ftnlen)128, (
				ftnlen)1);
			if (*(unsigned char *)dumq == '?') {
			    g1etchar_(lineq, &a1ll_2.iccount, dumq, (ftnlen)
				    128, (ftnlen)1);
			}
		    } else if (*(unsigned char *)dumq == ':') {
			i__2 = a1ll_2.iccount;
			if (s_cmp(lineq + i__2, " ", a1ll_2.iccount + 1 - 
				i__2, (ftnlen)1) != 0) {
			    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff 
				    + a1ll_2.nbars + 1;
			    errmsg_(lineq, &a1ll_2.iccount, &i__2, "\":\" mu\
st be followed by blank in \"o: \"!", (ftnlen)128, (ftnlen)39);
			    s_stop("1", (ftnlen)1);
			} else if (! comkeys_1.ornrpt) {
			    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff 
				    + a1ll_2.nbars + 1;
			    errmsg_(lineq, &a1ll_2.iccount, &i__2, "Turned o\
ff repeated ornaments before they were on!", (ftnlen)128, (ftnlen)50);
			    s_stop("1", (ftnlen)1);
			}
			comkeys_1.ornrpt = FALSE_;
		    } else {
			g1etchar_(lineq, &a1ll_2.iccount, dumq, (ftnlen)128, (
				ftnlen)1);
		    }
		    if (i_indx("+- :", dumq, (ftnlen)4, (ftnlen)1) == 0) {
			i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &a1ll_2.iccount, &i__2, "Illegal char\
acter in ornament symbol!", (ftnlen)128, (ftnlen)37);
			s_stop("1", (ftnlen)1);
		    }
		    if (*(unsigned char *)dumq == ':') {
			i__2 = a1ll_2.iccount;
			if (s_cmp(lineq + i__2, " ", a1ll_2.iccount + 1 - 
				i__2, (ftnlen)1) != 0) {
			    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff 
				    + a1ll_2.nbars + 1;
			    errmsg_(lineq, &a1ll_2.iccount, &i__2, "\":\" mu\
st be followed by blank in \"o: \"!", (ftnlen)128, (ftnlen)39);
			    s_stop("1", (ftnlen)1);
			} else if (comkeys_1.ornrpt) {
			    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff 
				    + a1ll_2.nbars + 1;
			    errmsg_(lineq, &a1ll_2.iccount, &i__2, "Turned o\
n repeated ornaments but already on!", (ftnlen)128, (ftnlen)44);
			    s_stop("1", (ftnlen)1);
			}
			comkeys_1.ornrpt = TRUE_;
		    }
/*              if (index('+-',dumq) .gt. 0) */
/*     *               call readnum(lineq,iccount,durq,fnum) */
		    if (i_indx("+-", dumq, (ftnlen)2, (ftnlen)1) > 0) {
			readnum_(lineq, &a1ll_2.iccount, durq, &fnum, (ftnlen)
				128, (ftnlen)1);
			if (*(unsigned char *)durq == ':') {
			    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff 
				    + a1ll_2.nbars + 1;
			    errmsg_(lineq, &a1ll_2.iccount, &i__2, "Cannot s\
hift AND repeat an ornament!", (ftnlen)128, (ftnlen)36);
			    s_stop("1", (ftnlen)1);
			}
		    }
		    goto L110;
		} else if (i_indx("st()", durq, (ftnlen)4, (ftnlen)1) > 0) {
		    iposn = 0;
		    numint = 0;
L15:
		    g1etchar_(lineq, &a1ll_2.iccount, dumq, (ftnlen)128, (
			    ftnlen)1);
		    ++iposn;
		    if (i_indx("udltb", dumq, (ftnlen)5, (ftnlen)1) > 0) {
			goto L15;
		    } else if (i_indx("+-", dumq, (ftnlen)2, (ftnlen)1) > 0) {
			++numint;
			++a1ll_2.iccount;
			readnum_(lineq, &a1ll_2.iccount, durq, &fnum, (ftnlen)
				128, (ftnlen)1);
			if (numint == 1) {
			    if (i_nint(&fnum) > 15) {
				i__2 = a1ll_2.iccount - 1;
				i__3 = c1omnotes_1.ibarcnt - 
					c1omnotes_1.ibaroff + a1ll_2.nbars + 
					1;
				errmsg_(lineq, &i__2, &i__3, "Magnitude of s\
lur height adjustment cannot exceed 15!", (ftnlen)128, (ftnlen)53);
				s_stop("1", (ftnlen)1);
			    }
			} else if (numint == 2) {
			    if (dabs(fnum) > (float)6.3) {
				i__2 = a1ll_2.iccount - 1;
				i__3 = c1omnotes_1.ibarcnt - 
					c1omnotes_1.ibaroff + a1ll_2.nbars + 
					1;
				errmsg_(lineq, &i__2, &i__3, "Slur horiz shi\
ft must be in the range (-6.3,6.3)!", (ftnlen)128, (ftnlen)49);
				s_stop("1", (ftnlen)1);
			    }
			} else {

/*  Third signed integer, must be a midslur or curve spec. */

			    if (dabs(fnum) > (float)31.) {
				i__2 = a1ll_2.iccount - 1;
				i__3 = c1omnotes_1.ibarcnt - 
					c1omnotes_1.ibaroff + a1ll_2.nbars + 
					1;
				errmsg_(lineq, &i__2, &i__3, "Slur midheight\
 must be in the range (-31,31)!", (ftnlen)128, (ftnlen)45);
				s_stop("1", (ftnlen)1);
			    }
			    if (*(unsigned char *)durq == ':') {

/*  Expecting curve parameters.  Get two numbers */

				for (i__ = 1; i__ <= 2; ++i__) {
				    ++a1ll_2.iccount;
				    fnum = (real) (*(unsigned char *)&lineq[
					    a1ll_2.iccount - 1] - 48);
				    if ((r__1 = fnum - (float)3.5, dabs(r__1))
					     > (float)3.6) {
					i__2 = c1omnotes_1.ibarcnt - 
						c1omnotes_1.ibaroff + 
						a1ll_2.nbars + 1;
					errmsg_(lineq, &a1ll_2.iccount, &i__2,
						 "Slur curve parameter must \
be in range (0,7)!", (ftnlen)128, (ftnlen)44);
					s_stop("1", (ftnlen)1);
				    }
/* L40: */
				}
				++a1ll_2.iccount;
			    }
			}
			--a1ll_2.iccount;
			goto L15;
		    } else if (*(unsigned char *)dumq != ' ') {
			ic = *(unsigned char *)dumq;
			if (ic >= 48 && ic <= 57 || ic >= 65 && ic <= 90) {
			    if (iposn == 1) {
				goto L15;
			    }
			    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff 
				    + a1ll_2.nbars + 1;
			    errmsg_(lineq, &a1ll_2.iccount, &i__2, "Slur ID \
must be 2nd character in slur symbol!", (ftnlen)128, (ftnlen)45);
			    s_stop("1", (ftnlen)1);
			}
			i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &a1ll_2.iccount, &i__2, "Illegal char\
acter in slur symbol!", (ftnlen)128, (ftnlen)33);
			s_stop("1", (ftnlen)1);
		    }
		    goto L110;
		} else if (i_indx("0123456789#-nx_", durq, (ftnlen)15, (
			ftnlen)1) > 0) {

/*  We have a figure.  Only allow on 1st note of xtup */

		    if (itup != 2) {
			i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &a1ll_2.iccount, &i__2, "Figure in xt\
up only allowed on 1st note!", (ftnlen)128, (ftnlen)40);
			s_stop("1", (ftnlen)1);
		    } else if (*(unsigned char *)durq == 'x') {
			i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &a1ll_2.iccount, &i__2, "No floating \
figures in xtuplets!", (ftnlen)128, (ftnlen)32);
			s_stop("1", (ftnlen)1);
		    }
		    if (compage_1.usefig && c1ommvl_1.ivx == 1) {
			*ifig = 1;
		    }
L26:
		    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (
			    ftnlen)1);
		    if (i_indx("0123456789#-n_", durq, (ftnlen)14, (ftnlen)1) 
			    > 0) {
			goto L26;
		    } else if (*(unsigned char *)durq != ' ') {
			i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &a1ll_2.iccount, &i__2, "Illegal char\
acter in figure in xtuplet!", (ftnlen)128, (ftnlen)39);
			s_stop("1", (ftnlen)1);
		    }
		    goto L110;
		} else /* if(complicated condition) */ {
		    chax_(ch__1, (ftnlen)1, &c__92);
		    if (*(unsigned char *)durq == *(unsigned char *)&ch__1[0])
			     {
			chklit_(lineq, &a1ll_2.iccount, &literr, (ftnlen)128);
			if (literr > 0) {
			    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff 
				    + a1ll_2.nbars + 1;
			    errmsg_(lineq, &a1ll_2.iccount, &i__2, literq + (
				    literr - 1) * 51, (ftnlen)128, (ftnlen)51)
				    ;
			    s_stop("1", (ftnlen)1);
			}
			goto L110;
		    } else if (*(unsigned char *)durq == 'M') {

/*  Temporary trap until I get around putting this in pmxb */

			i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &a1ll_2.iccount, &i__2, "Macros not y\
et allowed in xtuplets!", (ftnlen)128, (ftnlen)35);
			s_stop("1", (ftnlen)1);
		    } else if (*(unsigned char *)durq == 'X') {
			i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			g1etx_(lineq, &a1ll_2.iccount, &c_false, &
				comkeys_1.shifton, &i__2, &c1omnotes_1.udsp[
				c1omnotes_1.ibarcnt + a1ll_2.nbars], &
				c1omnotes_1.wheadpt, (ftnlen)128);
			goto L110;
		    } else if (*(unsigned char *)durq == 'z') {

/*  Chord note in xtup.  Read past for now. */

L33:
			g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (
				ftnlen)1);
			if (*(unsigned char *)durq != ' ') {
			    goto L33;
			}
			goto L110;
		    }
		}
		if (i_indx("abcdefgr", durq, (ftnlen)8, (ftnlen)1) == 0) {
		    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__2, "In xtup, this ch\
aracter is not allowed!", (ftnlen)128, (ftnlen)39);
		    s_stop("1", (ftnlen)1);
		} else if (*(unsigned char *)durq == 'r' && itup == ntup) {
		    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__2, "Sorry, PMX canno\
t end an xtuplet with a rest!", (ftnlen)128, (ftnlen)45);
		    s_stop("1", (ftnlen)1);
		}
L7:
		g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)
			1);
		if (i_indx("sfn2345678ul", durq, (ftnlen)12, (ftnlen)1) > 0) {
		    goto L7;
		} else if (i_indx("+-<>", durq, (ftnlen)4, (ftnlen)1) > 0) {

/*  May have either octave jump or shifted accid. on main xtup note */

		    i__2 = a1ll_2.iccount;
		    if (i_indx("+-", durq, (ftnlen)2, (ftnlen)1) > 0 && 
			    i_indx("01234567890", lineq + i__2, (ftnlen)11, 
			    a1ll_2.iccount + 1 - i__2) == 0) {
			goto L7;
		    }
		    ++a1ll_2.iccount;
		    readnum_(lineq, &a1ll_2.iccount, durq, &fnum, (ftnlen)128,
			     (ftnlen)1);
		    --a1ll_2.iccount;
		    goto L7;
		} else if (*(unsigned char *)durq != ' ') {
		    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__2, "Illegal option o\
n xtuplet note!", (ftnlen)128, (ftnlen)31);
		    s_stop("1", (ftnlen)1);
		}
/* L6: */
	    }

/*  6==End of loop for xtuplet input */

	} else if (*(unsigned char *)durq == 'm') {

/*  Multi-bar rest: next 1 or two digits are # of bars. */

	    if (a1ll_2.iv > 1) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Cannot have multibar\
 rest if nv>1!", (ftnlen)128, (ftnlen)34);
		s_stop("1", (ftnlen)1);
	    } else if (a1ll_2.itsofar[a1ll_2.iv - 1] % a1ll_2.lenbar != 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Multibar rest must s\
tart at beginning of bar!", (ftnlen)128, (ftnlen)45);
		s_stop("1", (ftnlen)1);
	    } else if (c1omnotes_1.ibarmbr > 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Only one multibar re\
st allowed per block!", (ftnlen)128, (ftnlen)41);
		s_stop("1", (ftnlen)1);
	    }

/*  For some purposes, pretend its one bar only */

	    a1ll_2.nodur[a1ll_2.iv + a1ll_2.nnl[a1ll_2.iv - 1] * 15 - 16] = 
		    a1ll_2.lenbar;
	    c1omnotes_1.ibarmbr = a1ll_2.nbars + 1;
	    c1omnotes_1.mbrest = 0;
L20:
	    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (*(unsigned char *)durq >= 48 && *(unsigned char *)durq <= 57) 
		    {
		c1omnotes_1.mbrest = c1omnotes_1.mbrest * 10 + *(unsigned 
			char *)durq - 48;
		goto L20;
	    }
	    if (*(unsigned char *)durq != ' ') {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Illegal character af\
ter \"rm\"!", (ftnlen)128, (ftnlen)29);
		s_stop("1", (ftnlen)1);
	    }
	} else if (*(unsigned char *)durq == '.') {

/*  Dotted pattern.  Close out note.  Mult time by 3/4. */
/*  Set time for next note to 1/4.  Start the note. */

	    idotform = 1;
	} else if (*(unsigned char *)durq == ',') {
	    idotform = 3;

/*  Now flow to duration setting, as if durq=' ' */

	} else if (*(unsigned char *)durq == 'o') {

/*  Suppress full bar rest */

	    if (*(unsigned char *)charq != 'r') {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "\"o\" option only le\
gal for rest, not note!", (ftnlen)128, (ftnlen)41);
		s_stop("1", (ftnlen)1);
	    }
	    goto L2;
	} else if (*(unsigned char *)durq != ' ') {
	    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + a1ll_2.nbars + 
		    1;
	    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Illegal character!", (
		    ftnlen)128, (ftnlen)18);
	    s_wsle(&io___192);
	    do_lio(&c__9, &c__1, "ASCII code:", (ftnlen)11);
	    i__1 = *(unsigned char *)durq;
	    do_lio(&c__3, &c__1, (char *)&i__1, (ftnlen)sizeof(integer));
	    e_wsle();
	    s_stop("1", (ftnlen)1);
	}

/*  Set the duration */

	if (idotform > 0) {
	    if (idotform == 1) {
		a1ll_2.nodur[c1ommvl_1.ivx + a1ll_2.nnl[c1ommvl_1.ivx - 1] * 
			15 - 16] = i1fnodur_(&c1omnotes_1.nnodur, dotq, (
			ftnlen)1) * 3 / 2;
	    } else if (idotform == 2) {
		a1ll_2.nodur[c1ommvl_1.ivx + a1ll_2.nnl[c1ommvl_1.ivx - 1] * 
			15 - 16] = a1ll_2.nodur[c1ommvl_1.ivx + (a1ll_2.nnl[
			c1ommvl_1.ivx - 1] - 1) * 15 - 16] / 3;
	    } else if (idotform == 3) {
		a1ll_2.nodur[c1ommvl_1.ivx + a1ll_2.nnl[c1ommvl_1.ivx - 1] * 
			15 - 16] = i1fnodur_(&c1omnotes_1.nnodur, dotq, (
			ftnlen)1);
	    } else if (idotform == 4) {
		a1ll_2.nodur[c1ommvl_1.ivx + a1ll_2.nnl[c1ommvl_1.ivx - 1] * 
			15 - 16] = a1ll_2.nodur[c1ommvl_1.ivx + (a1ll_2.nnl[
			c1ommvl_1.ivx - 1] - 1) * 15 - 16] / 2;
	    }
	} else if (c1omnotes_1.ibarmbr != a1ll_2.nbars + 1 && ! fulbrp) {
	    a1ll_2.nodur[c1ommvl_1.ivx + a1ll_2.nnl[c1ommvl_1.ivx - 1] * 15 - 
		    16] = i1fnodur_(&c1omnotes_1.nnodur, dotq, (ftnlen)1);

/*  Check for double dot */

	    if (c1omnotes_1.iddot == 1) {
		a1ll_2.nodur[c1ommvl_1.ivx + a1ll_2.nnl[c1ommvl_1.ivx - 1] * 
			15 - 16] = a1ll_2.nodur[c1ommvl_1.ivx + a1ll_2.nnl[
			c1ommvl_1.ivx - 1] * 15 - 16] * 7 / 6;
		c1omnotes_1.iddot = 0;
	    }
	} else if (fulbrp) {
	    a1ll_2.nodur[c1ommvl_1.ivx + a1ll_2.nnl[c1ommvl_1.ivx - 1] * 15 - 
		    16] = a1ll_2.lenbar;

/*  Use a one-line function to set nnodur.  It gives inverse of ifnodur. */

	    i__1 = (integer) (log(a1ll_2.lenbar + (float).1) / (float).69315) 
		    + 48;
	    chax_(ch__1, (ftnlen)1, &i__1);
	    c1omnotes_1.nnodur = i_indx("62514x0x37", ch__1, (ftnlen)10, (
		    ftnlen)1) - 1;
	    fulbrp = FALSE_;
	}
	a1ll_2.rest[c1ommvl_1.ivx + a1ll_2.nnl[c1ommvl_1.ivx - 1] * 15 - 16] =
		 *(unsigned char *)charq == 'r';

/*  If inside forced beam, check if note is beamable */

	if (c1omget_1.fbon) {
	    if (a1ll_2.nodur[c1ommvl_1.ivx + a1ll_2.nnl[c1ommvl_1.ivx - 1] * 
		    15 - 16] < 16) {
		goto L120;
	    }
	    if (a1ll_2.nnl[c1ommvl_1.ivx - 1] > 1) {
		if (a1ll_2.nodur[c1ommvl_1.ivx + (a1ll_2.nnl[c1ommvl_1.ivx - 
			1] - 1) * 15 - 16] == 0) {
		    goto L120;
		}
	    }
	    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + a1ll_2.nbars + 
		    1;
	    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Unbeamable thing in forc\
ed beam!", (ftnlen)128, (ftnlen)32);
	    s_stop("1", (ftnlen)1);
	}
L120:
	a1ll_2.itsofar[c1ommvl_1.ivx - 1] += a1ll_2.nodur[c1ommvl_1.ivx + 
		a1ll_2.nnl[c1ommvl_1.ivx - 1] * 15 - 16];
	if (a1ll_2.itsofar[c1ommvl_1.ivx - 1] % a1ll_2.lenbar == 0) {
	    ++a1ll_2.nbars;
	    if (comkeys_1.shifton) {
		comkeys_1.barend = TRUE_;
	    }

/*  Will check barend when 1st note of next bar is entered. */

	    if (a1ll_2.nbars > 15) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Cannot have more tha\
n 15 bars in an input block!", (ftnlen)128, (ftnlen)48);
		s_stop("1", (ftnlen)1);
	    }
	    a1ll_2.nib[c1ommvl_1.ivx + a1ll_2.nbars * 15 - 16] = a1ll_2.nnl[
		    c1ommvl_1.ivx - 1];
	    if (a1ll_2.firstline && a1ll_2.lenbar != a1ll_2.lenbr1) {

/*  Just finished the pickup bar for this voice. */

		if (a1ll_2.itsofar[c1ommvl_1.ivx - 1] != a1ll_2.lenbr0) {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Pickup bar lengt\
h disagrees with mtrnum0!", (ftnlen)128, (ftnlen)41);
		    s_stop("1", (ftnlen)1);
		}
		a1ll_2.lenbar = a1ll_2.lenbr1;
		a1ll_2.itsofar[c1ommvl_1.ivx - 1] = 0;
	    }
	} else if (comkeys_1.barend) {
	    if (comkeys_1.shifton) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Bar ended with user-\
defined shift still on!", (ftnlen)128, (ftnlen)43);
		s_stop("1", (ftnlen)1);
	    }
	    comkeys_1.barend = FALSE_;
	}
	if (idotform == 1 || idotform == 3) {
	    g1etchar_(lineq, &a1ll_2.iccount, charq, (ftnlen)128, (ftnlen)1);
	    if (i_indx("abcedfgr", charq, (ftnlen)8, (ftnlen)1) == 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Expected note name o\
r \"r\" here!", (ftnlen)128, (ftnlen)31);
		s_stop("1", (ftnlen)1);
	    }
	    ++idotform;
	    numnum = 1;
	    goto L28;
	}

/*  End of sub block for note-rest */

    } else if (*(unsigned char *)charq == 'z') {
	g1etchar_(lineq, &a1ll_2.iccount, charq, (ftnlen)128, (ftnlen)1);
L25:
	g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	if (i_indx("nfsdre12345678", durq, (ftnlen)14, (ftnlen)1) > 0) {
	    goto L25;
	} else if (i_indx("<>", durq, (ftnlen)2, (ftnlen)1) > 0) {
	    i__1 = a1ll_2.iccount - 2;
	    if (i_indx("fsn", lineq + i__1, (ftnlen)3, a1ll_2.iccount - 1 - 
		    i__1) == 0) {
		i__1 = a1ll_2.iccount - 1;
		i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &i__1, &i__2, "Must have \"f,s,n\" before \"\
<\" or \">\"!", (ftnlen)128, (ftnlen)36);
		s_stop("1", (ftnlen)1);
	    }
	    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (i_indx("1234567890.", durq, (ftnlen)11, (ftnlen)1) == 0) {
		i__1 = a1ll_2.iccount - 1;
		i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &i__1, &i__2, "Expected a number to start her\
e for accidental shift!", (ftnlen)128, (ftnlen)53);
		s_stop("1", (ftnlen)1);
	    }
	    readnum_(lineq, &a1ll_2.iccount, durq, &fnum, (ftnlen)128, (
		    ftnlen)1);
	    --a1ll_2.iccount;
	    goto L25;
	} else if (i_indx("+-", durq, (ftnlen)2, (ftnlen)1) > 0) {
	    i__1 = a1ll_2.iccount;
	    if (i_indx("1234567890.", lineq + i__1, (ftnlen)11, 
		    a1ll_2.iccount + 1 - i__1) == 0) {
		goto L25;
	    }

/*  Number or '.' (durq) follows +/- .   Get it. */

	    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	    i__1 = a1ll_2.iccount;
	    if (*(unsigned char *)durq == '.' && i_indx("1234567890", lineq + 
		    i__1, (ftnlen)10, a1ll_2.iccount + 1 - i__1) == 0) {
		i__1 = a1ll_2.iccount - 1;
		i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &i__1, &i__2, "\".\" here must be followed by\
 a digit!", (ftnlen)128, (ftnlen)37);
		s_stop("1", (ftnlen)1);
		i__1 = a1ll_2.iccount - 3;
	    } else if (i_indx("sfnd", lineq + i__1, (ftnlen)4, a1ll_2.iccount 
		    - 2 - i__1) == 0) {
		i__1 = a1ll_2.iccount - 1;
		i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &i__1, &i__2, "Number after +/- must follow\
 \"d,s,f,n\"!", (ftnlen)128, (ftnlen)39);
		s_stop("1", (ftnlen)1);
	    }
	    readnum_(lineq, &a1ll_2.iccount, durq, &fnum, (ftnlen)128, (
		    ftnlen)1);
	    if (i_indx("+-", durq, (ftnlen)2, (ftnlen)1) == 0) {
		--a1ll_2.iccount;
		goto L25;
	    }

/*  2nd +/- */

	    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (*(unsigned char *)durq == '.') {
		g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)
			1);
	    }
	    if (i_indx("1234567890", durq, (ftnlen)10, (ftnlen)1) == 0) {
		i__1 = a1ll_2.iccount - 1;
		i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &i__1, &i__2, "Expected a number here!", (
			ftnlen)128, (ftnlen)23);
		s_stop("1", (ftnlen)1);
	    }
	    readnum_(lineq, &a1ll_2.iccount, durq, &fnum, (ftnlen)128, (
		    ftnlen)1);
	    --a1ll_2.iccount;
	    goto L25;
	} else if (*(unsigned char *)durq != ' ' || i_indx("abcdefg", charq, (
		ftnlen)7, (ftnlen)1) == 0) {
	    i__1 = a1ll_2.iccount - 1;
	    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + a1ll_2.nbars + 
		    1;
	    errmsg_(lineq, &i__1, &i__2, "Illegal character in chord note!", (
		    ftnlen)128, (ftnlen)32);
	    s_stop("1", (ftnlen)1);
	}
    } else if (*(unsigned char *)charq == 'G') {
	ngr = 1;
L9:
	g1etchar_(lineq, &a1ll_2.iccount, charq, (ftnlen)128, (ftnlen)1);
	if (i_indx("123456789", charq, (ftnlen)9, (ftnlen)1) > 0) {
	    readnum_(lineq, &a1ll_2.iccount, durq, &fnum, (ftnlen)128, (
		    ftnlen)1);
	    ngr = i_nint(&fnum);
	    --a1ll_2.iccount;
	    goto L9;
	} else if (i_indx("AWulxs", charq, (ftnlen)6, (ftnlen)1) > 0) {
	    goto L9;
	} else if (*(unsigned char *)charq == 'm') {
	    g1etchar_(lineq, &a1ll_2.iccount, charq, (ftnlen)128, (ftnlen)1);
	    if (i_indx("01234", charq, (ftnlen)5, (ftnlen)1) == 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "A digit less than 5 \
must follow \"m\" in a grace note!", (ftnlen)128, (ftnlen)52);
		s_stop("1", (ftnlen)1);
	    }
	    goto L9;
	}

/*  At this point, charq is first note name in rest (grace?) */

	i__1 = ngr;
	for (igr = 1; igr <= i__1; ++igr) {
	    numnum = 0;
	    if (igr > 1) {
L55:
		g1etchar_(lineq, &a1ll_2.iccount, charq, (ftnlen)128, (ftnlen)
			1);
		if (*(unsigned char *)charq == ' ') {
		    goto L55;
		}
	    }
	    if (i_indx("abcdefg", charq, (ftnlen)7, (ftnlen)1) == 0) {
		i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__2, "In grace, expected\
 \"a\"-\"g\"!", (ftnlen)128, (ftnlen)27);
		s_stop("1", (ftnlen)1);
	    }
L18:
	    g1etchar_(lineq, &a1ll_2.iccount, charq, (ftnlen)128, (ftnlen)1);
	    if (*(unsigned char *)charq != ' ') {
		if (i_indx("+-1234567", charq, (ftnlen)9, (ftnlen)1) > 0) {
		    if (numnum == 1) {
			i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &a1ll_2.iccount, &i__2, "Only one of\
 \"+-1234567\" allowed here in grace!", (ftnlen)128, (ftnlen)46);
			s_stop("1", (ftnlen)1);
		    }
		    numnum = 1;
		    goto L18;
		} else if (i_indx("nfs", charq, (ftnlen)3, (ftnlen)1) > 0) {
		    goto L18;
		}

/*  Digits are possible octave numbers */

		i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__2, "Illegal character af\
ter note name in grace!", (ftnlen)128, (ftnlen)43);
		s_stop("1", (ftnlen)1);
	    }
/* L19: */
	}
    } else /* if(complicated condition) */ {
	chax_(ch__1, (ftnlen)1, &c__92);
	if (*(unsigned char *)charq == *(unsigned char *)&ch__1[0]) {
	    chklit_(lineq, &a1ll_2.iccount, &literr, (ftnlen)128);
	    if (literr > 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, literq + (literr - 1) *
			 51, (ftnlen)128, (ftnlen)51);
		s_stop("1", (ftnlen)1);
	    }
	} else if (*(unsigned char *)charq == 'o') {

/*  "o" symbol must come AFTER the affected note */

	    if (a1ll_2.nnl[c1ommvl_1.ivx - 1] == 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "\"o\" must be in sam\
e input block, after affected note!", (ftnlen)128, (ftnlen)53);
		s_stop("1", (ftnlen)1);
	    }
	    g1etchar_(lineq, &a1ll_2.iccount, dumq, (ftnlen)128, (ftnlen)1);
	    if (i_indx("(stmgx+Tupf._)e:>^", dumq, (ftnlen)18, (ftnlen)1) == 
		    0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Illegal ornament!", (
			ftnlen)128, (ftnlen)17);
		s_stop("1", (ftnlen)1);
	    }
	    if (*(unsigned char *)dumq == ':') {
		g1etchar_(lineq, &a1ll_2.iccount, dumq, (ftnlen)128, (ftnlen)
			1);
		if (*(unsigned char *)dumq != ' ') {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Expected blank a\
fter \"o:\"!", (ftnlen)128, (ftnlen)26);
		    s_stop("1", (ftnlen)1);
		} else if (! comkeys_1.ornrpt) {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Turned off repea\
ted ornaments before they were on!", (ftnlen)128, (ftnlen)50);
		    s_stop("1", (ftnlen)1);
		}
		comkeys_1.ornrpt = FALSE_;
	    } else if (*(unsigned char *)dumq == 'g') {
		if (c1omget_1.issegno) {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Sorry, only one\
 \"segno\" per input block!", (ftnlen)128, (ftnlen)40);
		    s_stop("1", (ftnlen)1);
		} else if (c1ommvl_1.ivx != 1) {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "segno can only b\
e in voice 1!", (ftnlen)128, (ftnlen)29);
		    s_stop("1", (ftnlen)1);
		}
		c1omget_1.issegno = TRUE_;
L12:
		g1etchar_(lineq, &a1ll_2.iccount, dumq, (ftnlen)128, (ftnlen)
			1);
		if (*(unsigned char *)dumq == '-' || *(unsigned char *)dumq >=
			 48 && *(unsigned char *)dumq <= 58) {
		    goto L12;
		}
		if (*(unsigned char *)dumq != ' ') {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Illegal characte\
r in segno ornament symbol!", (ftnlen)128, (ftnlen)43);
		    s_stop("1", (ftnlen)1);
		}
	    } else if (*(unsigned char *)dumq == 'T') {

/*  Trill.  may be followed by 't' and/or number.  read 'til blank */

L22:
		g1etchar_(lineq, &a1ll_2.iccount, dumq, (ftnlen)128, (ftnlen)
			1);
		if (*(unsigned char *)dumq == ':') {
		    i__1 = a1ll_2.iccount;
		    if (s_cmp(lineq + i__1, " ", a1ll_2.iccount + 1 - i__1, (
			    ftnlen)1) != 0) {
			i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &a1ll_2.iccount, &i__1, "Expected bla\
nk after \":\"!", (ftnlen)128, (ftnlen)25);
			s_stop("1", (ftnlen)1);
		    }
		    goto L32;
		} else if (*(unsigned char *)dumq != ' ') {
		    goto L22;
		}
	    } else if (*(unsigned char *)dumq == 'f') {
		g1etchar_(lineq, &a1ll_2.iccount, dumq, (ftnlen)128, (ftnlen)
			1);
		if (i_indx(" d+-:", dumq, (ftnlen)5, (ftnlen)1) == 0) {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Illegal characte\
r after \"f\" in fermata ornament symbol!", (ftnlen)128, (ftnlen)55);
		    s_stop("1", (ftnlen)1);
		}
		if (*(unsigned char *)dumq == 'd') {
		    g1etchar_(lineq, &a1ll_2.iccount, dumq, (ftnlen)128, (
			    ftnlen)1);
		}
		if (*(unsigned char *)dumq == ':') {
		    goto L32;
		}
	    } else if (*(unsigned char *)dumq == 'e') {
		g1etchar_(lineq, &a1ll_2.iccount, dumq, (ftnlen)128, (ftnlen)
			1);
		if (i_indx("sfn?", dumq, (ftnlen)4, (ftnlen)1) == 0) {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Illegal characte\
r after \"e\" in edit. accid. symbol!", (ftnlen)128, (ftnlen)51);
		    s_stop("1", (ftnlen)1);
		}
		g1etchar_(lineq, &a1ll_2.iccount, dumq, (ftnlen)128, (ftnlen)
			1);
		if (*(unsigned char *)dumq == '?') {
		    g1etchar_(lineq, &a1ll_2.iccount, dumq, (ftnlen)128, (
			    ftnlen)1);
		}
	    } else {
		g1etchar_(lineq, &a1ll_2.iccount, dumq, (ftnlen)128, (ftnlen)
			1);
	    }
	    if (i_indx("+- :", dumq, (ftnlen)4, (ftnlen)1) == 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Illegal character in\
 ornament symbol!", (ftnlen)128, (ftnlen)37);
		s_stop("1", (ftnlen)1);
	    }
	    if (i_indx("+-", dumq, (ftnlen)2, (ftnlen)1) > 0) {
		readnum_(lineq, &a1ll_2.iccount, durq, &fnum, (ftnlen)128, (
			ftnlen)1);
		if (*(unsigned char *)durq == ':') {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Cannot shift AND\
 repeat an ornament!", (ftnlen)128, (ftnlen)36);
		    s_stop("1", (ftnlen)1);
		}
	    }
L32:
	    if (*(unsigned char *)dumq == ':') {
		i__1 = a1ll_2.iccount;
		if (s_cmp(lineq + i__1, " ", a1ll_2.iccount + 1 - i__1, (
			ftnlen)1) != 0) {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "\":\" must be fo\
llowed by blank in \"o: \"!", (ftnlen)128, (ftnlen)39);
		    s_stop("1", (ftnlen)1);
		} else if (comkeys_1.ornrpt) {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Turned on repeat\
ed ornaments but already on!", (ftnlen)128, (ftnlen)44);
		    s_stop("1", (ftnlen)1);
		}
		comkeys_1.ornrpt = TRUE_;
	    }
	} else if (i_indx("st()", charq, (ftnlen)4, (ftnlen)1) > 0) {
	    numint = 0;
	    iposn = 0;
L8:
	    g1etchar_(lineq, &a1ll_2.iccount, dumq, (ftnlen)128, (ftnlen)1);
	    ++iposn;
	    if (i_indx("udltb+- ", dumq, (ftnlen)8, (ftnlen)1) == 0) {

/*  Check for explicit ID code. */

		ic = *(unsigned char *)dumq;
		if (ic < 48 || ic > 57 && ic < 65 || ic > 90) {

/*  Not 0-9 or A-Z, so exit */

		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Illegal characte\
r in slur symbol!", (ftnlen)128, (ftnlen)33);
		    s_stop("1", (ftnlen)1);
		} else {

/*  It is a possible ID code.  Right place? */

		    if (iposn != 1) {

/*  Slur ID is not 2nd! */

			i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &a1ll_2.iccount, &i__1, "Slur ID must\
 be second character in slur symbol!", (ftnlen)128, (ftnlen)48);
			s_stop("1", (ftnlen)1);
		    }
		}

/*  Slur ID is OK. */

		goto L8;
	    }
	    if (i_indx("udltb", dumq, (ftnlen)5, (ftnlen)1) > 0) {
		goto L8;
	    } else if (i_indx("+-", dumq, (ftnlen)2, (ftnlen)1) > 0) {
		++numint;
		if (*(unsigned char *)charq == 't') {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "\"+|-\" for slur\
 height only allowed in \"s\"-slurs!", (ftnlen)128, (ftnlen)48);
		    s_stop("1", (ftnlen)1);
		}
		++a1ll_2.iccount;
		readnum_(lineq, &a1ll_2.iccount, durq, &fnum, (ftnlen)128, (
			ftnlen)1);
		if (numint == 1) {
		    if (i_nint(&fnum) > 15) {
			i__1 = a1ll_2.iccount - 1;
			i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &i__1, &i__2, "Magnitude of slur heig\
ht adjustment cannot exceed 15!", (ftnlen)128, (ftnlen)53);
			s_stop("1", (ftnlen)1);
		    }
		} else if (numint == 2) {
		    if (dabs(fnum) > (float)6.3) {
			i__1 = a1ll_2.iccount - 1;
			i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &i__1, &i__2, "Slur horiz shift must \
be in range (-6.3,6.3)!", (ftnlen)128, (ftnlen)45);
			s_stop("1", (ftnlen)1);
		    }
		} else {

/*  Third signed integer, must be a midslur or curve spec. */

		    if (dabs(fnum) > (float)31.) {
			i__1 = a1ll_2.iccount - 1;
			i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &i__1, &i__2, "Slur midheight must be\
 in the range (-31,31)!", (ftnlen)128, (ftnlen)45);
			s_stop("1", (ftnlen)1);
		    }
		    if (*(unsigned char *)durq == ':') {

/*  Expecting curve parameters.  Get two numbers */

			for (i__ = 1; i__ <= 2; ++i__) {
			    ++a1ll_2.iccount;
			    fnum = (real) (*(unsigned char *)&lineq[
				    a1ll_2.iccount - 1] - 48);
			    if ((r__1 = fnum - (float)3.5, dabs(r__1)) > (
				    float)3.6) {
				i__1 = c1omnotes_1.ibarcnt - 
					c1omnotes_1.ibaroff + a1ll_2.nbars + 
					1;
				errmsg_(lineq, &a1ll_2.iccount, &i__1, "Slur\
 curve parameter must be in range (0,7)!", (ftnlen)128, (ftnlen)44);
				s_stop("1", (ftnlen)1);
			    }
/* L41: */
			}
			++a1ll_2.iccount;
		    }
		}
		--a1ll_2.iccount;
		goto L8;
	    }
	} else if (*(unsigned char *)charq == '?') {
	} else if (*(unsigned char *)charq >= 48 && *(unsigned char *)charq <=
		 57 || i_indx("#-nx_", charq, (ftnlen)5, (ftnlen)1) > 0) {

/*  We have a figure.  Must come AFTER the note it goes under */

	    if (a1ll_2.itsofar[c1ommvl_1.ivx - 1] == 0 && (! a1ll_2.firstline 
		    || a1ll_2.lenbr0 == 0 || a1ll_2.lenbar == a1ll_2.lenbr0)) 
		    {

/*  Figure before first note in block */

		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Cannot put figure be\
fore first note in block!", (ftnlen)128, (ftnlen)45);
		s_stop("1", (ftnlen)1);
	    }
	    if (*(unsigned char *)charq == 'x') {
		indxb = i_indx(lineq + (a1ll_2.iccount - 1), " ", 128 - (
			a1ll_2.iccount - 1), (ftnlen)1);
		if (indxb < 5) {
		    i__1 = a1ll_2.iccount + indxb - 1;
		    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &i__1, &i__2, "Cannot have a blank here i\
n floating figure!", (ftnlen)128, (ftnlen)44);
		    s_stop("1", (ftnlen)1);
		}
	    }
	    if (compage_1.usefig) {
		*ifig = 1;
	    }
L5:
	    g1etchar_(lineq, &a1ll_2.iccount, charq, (ftnlen)128, (ftnlen)1);
	    if (*(unsigned char *)charq != ' ') {
		goto L5;
	    }
	} else if (*(unsigned char *)charq == '[') {
	    if (c1omget_1.fbon) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Started forced beam \
while another was open!", (ftnlen)128, (ftnlen)43);
		s_stop("1", (ftnlen)1);
	    }
	    c1omget_1.fbon = TRUE_;
L17:
	    g1etchar_(lineq, &a1ll_2.iccount, charq, (ftnlen)128, (ftnlen)1);
	    if (i_indx("uljh", charq, (ftnlen)4, (ftnlen)1) > 0) {
		goto L17;
	    } else if (i_indx("+-", charq, (ftnlen)2, (ftnlen)1) > 0) {
		++a1ll_2.iccount;
		readnum_(lineq, &a1ll_2.iccount, durq, &fnum, (ftnlen)128, (
			ftnlen)1);
		--a1ll_2.iccount;
		goto L17;
	    } else if (*(unsigned char *)charq == 'm') {

/*  Forced multiplicity, next char should be 1-4 */

		g1etchar_(lineq, &a1ll_2.iccount, charq, (ftnlen)128, (ftnlen)
			1);
		if (i_indx("1234", charq, (ftnlen)4, (ftnlen)1) == 0) {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Forced multiplic\
ity for a beam must be 1, 2, 3, or 4!", (ftnlen)128, (ftnlen)53);
		    s_stop("1", (ftnlen)1);
		}
		goto L17;
	    } else if (*(unsigned char *)charq != ' ') {
		if (i_indx("0123456789", charq, (ftnlen)10, (ftnlen)1) > 0) {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "After \"[\", dig\
its must now be preceeded by \"+\" or \"-\"!", (ftnlen)128, (ftnlen)54);
		    s_wsle(&io___196);
		    do_lio(&c__9, &c__1, "You will have to edit older source\
s to meet this rqmt,", (ftnlen)54);
		    e_wsle();
		    s_wsle(&io___197);
		    do_lio(&c__9, &c__1, "but it was needed to allow 2-digit\
 height adjustments.", (ftnlen)54);
		    e_wsle();
		    s_wsle(&io___198);
		    do_lio(&c__9, &c__1, "Sorry for the inconvenience.  --Th\
e Management", (ftnlen)46);
		    e_wsle();
		} else {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Illegal characte\
r after [!", (ftnlen)128, (ftnlen)26);
		}
		s_stop("1", (ftnlen)1);
	    }
	} else if (*(unsigned char *)charq == ']') {
	    g1etchar_(lineq, &a1ll_2.iccount, charq, (ftnlen)128, (ftnlen)1);
	    if (i_indx("j ", charq, (ftnlen)2, (ftnlen)1) > 0) {
		if (c1omget_1.fbon) {
		    c1omget_1.fbon = FALSE_;
		} else {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Forced beam stop\
 with no corresponding start!", (ftnlen)128, (ftnlen)45);
		    s_stop("1", (ftnlen)1);
		}
	    } else if (*(unsigned char *)charq == '[') {
		if (! c1omget_1.fbon) {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "\"][\" can only \
go in forced beam!", (ftnlen)128, (ftnlen)32);
		    s_stop("1", (ftnlen)1);
		}
	    } else if (*(unsigned char *)charq != 'j') {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "\"]\" must be follow\
ed by blank, \"j\", or \"[\"!", (ftnlen)128, (ftnlen)43);
		s_stop("1", (ftnlen)1);
	    }
	} else if (*(unsigned char *)charq == 'D') {

/*  Dynamic mark */

	    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + a1ll_2.nbars + 
		    1;
	    checkdyn_(lineq, &a1ll_2.iccount, &i__1, (ftnlen)128);
	} else if (i_indx("lhw", charq, (ftnlen)3, (ftnlen)1) > 0) {

/*  Save position for later check */

	    icclhw = a1ll_2.iccount;
	    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (i_indx("0123456789.+- ", durq, (ftnlen)14, (ftnlen)1) == 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Illegal character af\
ter \"l\", \"w\", or \"h\"!", (ftnlen)128, (ftnlen)41);
		s_stop("1", (ftnlen)1);
	    }
	    c1omget_1.isheadr = c1omget_1.isheadr || *(unsigned char *)charq 
		    == 'h';
	    if (i_indx(" +-", durq, (ftnlen)3, (ftnlen)1) > 0) {

/*  There is a header (or lower string?) */

		if (i_indx("+-", durq, (ftnlen)2, (ftnlen)1) > 0) {

/*  User-defined vert offset (\internote). */

		    if (*(unsigned char *)charq != 'h') {
			i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &a1ll_2.iccount, &i__1, "\"+\" or \"\
-\" not permitted here!", (ftnlen)128, (ftnlen)30);
			s_stop("1", (ftnlen)1);
		    }

/*  Have "h" followed by +/- .  Check for digit. */
/*     Can blow durq since not using fnum for now, but... */

		    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (
			    ftnlen)1);
		    if (i_indx("123456789", durq, (ftnlen)9, (ftnlen)1) == 0) 
			    {
			i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &a1ll_2.iccount, &i__1, "There must b\
e a digit here!", (ftnlen)128, (ftnlen)27);
			s_stop("1", (ftnlen)1);
		    }

/*  Have "h" followed by +/- followed by a digit.  No need to get the number. */

/*           call readnum(lineq,iccount,durq,fnum) */
		}
		if (*(unsigned char *)charq != 'w') {

/*  Header or lower string. */

		    if (icclhw != 1) {
			i__1 = a1ll_2.iccount - 1;
			i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &i__1, &i__2, "\"h\" or \"l\" must be\
 first character in line!", (ftnlen)128, (ftnlen)43);
			s_stop("1", (ftnlen)1);
		    }

/*  Read past the next line, which has the string. */

		    read10_(charq, &c1omget_1.lastchar, (ftnlen)1);
		    ++c1omget_1.nline;
		    a1ll_2.iccount = 128;
		} else {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Symbol \"w\" (wi\
dth) must be followed by a digit!", (ftnlen)128, (ftnlen)47);
		    s_stop("1", (ftnlen)1);
		}
	    } else {

/*  Height or width change spec.  Check if at start of piece. */

		if (c1omnotes_1.ibarcnt > 0) {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Symbol must go a\
t top of first input block!", (ftnlen)128, (ftnlen)43);
		    s_stop("1", (ftnlen)1);
		}
		readnum_(lineq, &a1ll_2.iccount, durq, &dimen, (ftnlen)128, (
			ftnlen)1);

/*  Check units.  Convert to points */

		if (*(unsigned char *)durq == ' ' || *(unsigned char *)durq ==
			 'p') {
		    dimen += (float).5;
		} else if (*(unsigned char *)durq == 'i') {
		    dimen = dimen * 72 + (float).5;
		} else if (*(unsigned char *)durq == 'm') {
		    dimen = dimen / (float)25.4 * 72 + (float).5;
		} else {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Illegal unit; mu\
st be \"p\",\"i\",or\"m\"!", (ftnlen)128, (ftnlen)36);
		    s_stop("1", (ftnlen)1);
		}
		if (*(unsigned char *)charq == 'h') {
		    compage_1.ptheight = (real) ((integer) dimen);
		} else {
		    compage_1.widthpt = (real) ((integer) dimen);
		}
	    }
	} else if (*(unsigned char *)charq == 'm') {

/*  Time signature change.  Only allow at beginning of block. */
/*    mtrnuml, mtrdenl (logical) and p (printable) will be input. */
/*    mtrnuml=0 initially. (In common) */

/*  Check whether at beginning of a block */

	    if (c1ommvl_1.ivx != 1 || a1ll_2.nnl[0] != 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Meter change only OK\
 in voice 1, at start of block!", (ftnlen)128, (ftnlen)51);
		s_wsle(&io___201);
		do_lio(&c__9, &c__1, "voice number is", (ftnlen)15);
		do_lio(&c__3, &c__1, (char *)&c1ommvl_1.ivx, (ftnlen)sizeof(
			integer));
		e_wsle();
		s_stop("1", (ftnlen)1);
	    }
	    a1ll_2.newmeter = TRUE_;
	    readmeter_(lineq, &a1ll_2.iccount, &a1ll_2.mtrnuml, &mtrdenl, (
		    ftnlen)128);
	    if (a1ll_2.mtrnuml == 0) {
		i__1 = a1ll_2.iccount - 1;
		i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &i__1, &i__2, "Digit 0 not allowed here!", (
			ftnlen)128, (ftnlen)25);
		s_stop("1", (ftnlen)1);
/*        else if (mtrdenl .eq. 1) then */
/* c */
/* c  Kluge!!! */
/* c */
/*          mtrdenl = 2 */
/*          mtrnuml = 2*mtrnuml */
	    }
	    readmeter_(lineq, &a1ll_2.iccount, &mtrnmp, &mtrdnp, (ftnlen)128);

/*  Read past printed time signature; not used in pmxa. */

	    lenbeat = i1fnodur_(&mtrdenl, "x", (ftnlen)1);
	    lenmult = 1;
	    if (mtrdenl == 2) {
		lenbeat = 16;
		lenmult = 2;
	    }
	    a1ll_2.lenbar = lenmult * a1ll_2.mtrnuml * lenbeat;
	    a1ll_2.mtrnuml = 0;
	} else if (*(unsigned char *)charq == 'C') {
	    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (! (i_indx("tsmanrbf", durq, (ftnlen)8, (ftnlen)1) > 0 || *(
		    unsigned char *)durq >= 48 && *(unsigned char *)durq <= 
		    55)) {
/*     *      (ichar(durq).ge.48 .and. ichar(durq).le.54))) then */
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Must have t,s,m,a,n,\
r,b,f or 1-7 after C!", (ftnlen)128, (ftnlen)41);
/*     *           'Must have t,s,m,a,n,r,b,f or 1-6 after C!') */
		s_stop("1", (ftnlen)1);
	    }
	    c1omnotes_1.gotclef = TRUE_;
	} else if (*(unsigned char *)charq == 'R') {
	    if (c1ommvl_1.ivx != 1) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Repeats can only go \
in voice 1!", (ftnlen)128, (ftnlen)31);
		s_stop("1", (ftnlen)1);
	    }
L10:
	    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (i_indx("lrdDb", durq, (ftnlen)5, (ftnlen)1) > 0) {
		goto L10;
	    }
	    if (*(unsigned char *)durq != ' ') {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Illegal character af\
ter \"R\" (repeat/double bar)!", (ftnlen)128, (ftnlen)48);
		s_stop("1", (ftnlen)1);
	    }
	} else if (*(unsigned char *)charq == 'V') {

/*  Ending */

	    if (a1ll_2.iv != 1) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Voltas are only allo\
wed in voice #1!", (ftnlen)128, (ftnlen)36);
		s_stop("1", (ftnlen)1);
	    } else if (c1omget_1.isvolt) {
		s_wsle(&io___207);
		e_wsle();
		s_wsle(&io___208);
		do_lio(&c__9, &c__1, "*******WARNING********", (ftnlen)22);
		e_wsle();
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "There is more than o\
ne volta in this input block.!", (ftnlen)128, (ftnlen)50);
		s_wsle(&io___209);
		do_lio(&c__9, &c__1, "This may work in a score, but WILL NOT\
 work in parts.", (ftnlen)53);
		e_wsle();
		s_wsle(&io___210);
		do_lio(&c__9, &c__1, "Safest to have only 1 volta per block,\
 at the start of the block", (ftnlen)64);
		e_wsle();
	    }
	    c1omget_1.isvolt = TRUE_;
L11:
	    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (*(unsigned char *)durq != ' ') {
		goto L11;
	    }
	} else if (*(unsigned char *)charq == 'B') {
	} else if (*(unsigned char *)charq == 'P') {
	    if (c1ommvl_1.ivx != 1 || a1ll_2.nnl[0] != 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Only allowed at begi\
nning of block!", (ftnlen)128, (ftnlen)35);
		s_stop("1", (ftnlen)1);
	    }
L16:
	    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (*(unsigned char *)durq == 'l' || *(unsigned char *)durq == 
		    'r' || *(unsigned char *)durq >= 48 && *(unsigned char *)
		    durq <= 57) {
		goto L16;
	    }
	    if (*(unsigned char *)durq == 'c') {

/*  Expect a centered name, and it has to be last option */

		g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)
			1);
		if (*(unsigned char *)durq == '"') {

/*  Quoted name, go to next quote mark */

		    for (++a1ll_2.iccount; a1ll_2.iccount <= 127; 
			    ++a1ll_2.iccount) {
			if (*(unsigned char *)&lineq[a1ll_2.iccount - 1] == 
				'"') {
			    goto L36;
			}
/* L35: */
		    }
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Missing close qu\
ote after page number command (P)!", (ftnlen)128, (ftnlen)50);
		    s_stop("1", (ftnlen)1);
L36:
		    ;
		} else if (*(unsigned char *)durq != ' ') {

/*  Space-delimited name, look for next blank */

		    for (++a1ll_2.iccount; a1ll_2.iccount <= 127; 
			    ++a1ll_2.iccount) {
			if (*(unsigned char *)&lineq[a1ll_2.iccount - 1] == 
				' ') {
			    goto L38;
			}
/* L37: */
		    }
L38:
		    ;
		}
	    } else if (*(unsigned char *)durq != ' ') {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Only \"l\",\"r\",\"\
c\" or digit allowed after \"P\"!", (ftnlen)128, (ftnlen)44);
		s_stop("1", (ftnlen)1);
	    }
	} else if (*(unsigned char *)charq == 'W') {
	    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (*(unsigned char *)durq != '.') {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Next char after \" \
W\" must be \".\"!", (ftnlen)128, (ftnlen)33);
		s_stop("1", (ftnlen)1);
	    }
	    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (*(unsigned char *)durq >= 48 || *(unsigned char *)durq <= 57) 
		    {
		c1omnotes_1.wminnh[c1omnotes_1.ibarcnt + a1ll_2.nbars] = (*(
			unsigned char *)durq - 48) * (float).1;
	    } else {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Next char after \"\
 W.\" must be 0-9!", (ftnlen)128, (ftnlen)34);
		s_stop("1", (ftnlen)1);
	    }
	} else if (*(unsigned char *)charq == 'T') {

/*  Titles */

	    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (i_indx("itc", durq, (ftnlen)3, (ftnlen)1) == 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Must put \"i\", \"\
t\", or \"c\" after \"T\"!", (ftnlen)128, (ftnlen)36);
		s_stop("1", (ftnlen)1);
	    }
	    i__1 = i_indx("itc", durq, (ftnlen)3, (ftnlen)1) - 1;
	    c1omget_1.ihead += pow_ii(&c__2, &i__1);

/*  Maybe a number after 'Tt', but ignore here.  Read past string on next line. */

	    read10_(charq, &c1omget_1.lastchar, (ftnlen)1);
	    ++c1omget_1.nline;
	    a1ll_2.iccount = 128;
	} else if (*(unsigned char *)charq == 'A') {
L27:
	    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (i_indx("rbsd", durq, (ftnlen)4, (ftnlen)1) > 0) {
		goto L27;
	    } else if (*(unsigned char *)durq == 'a') {
		g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)
			1);
		readnum_(lineq, &a1ll_2.iccount, durq, &c1ommvl_1.fbar, (
			ftnlen)128, (ftnlen)1);
		--a1ll_2.iccount;
		goto L27;
	    } else if (*(unsigned char *)durq == 'i') {
		g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)
			1);

/*  Local interstaff correction.  Set to -1. if not specifiec, or after use, */
/*  or anytime except at top, since pmxb handles all times except at top. */

		readnum_(lineq, &a1ll_2.iccount, durq, &tintstf, (ftnlen)128, 
			(ftnlen)1);
		if (c1omnotes_1.ibarcnt == 0) {
		    compage_1.fintstf = tintstf;
		}
		--a1ll_2.iccount;
		goto L27;
	    } else if (*(unsigned char *)durq == 'I') {

/*  Global interstaff correction.  Use in place of fintstf if fintstf<0 */

		g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)
			1);
		readnum_(lineq, &a1ll_2.iccount, durq, &compage_1.gintstf, (
			ftnlen)128, (ftnlen)1);
		--a1ll_2.iccount;
		goto L27;
	    } else if (*(unsigned char *)durq == 'o') {
		*optimize = TRUE_;
		goto L27;
	    } else if (*(unsigned char *)durq != ' ') {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "The only legal entri\
es after \"A\" are \"r,s,b,a,i,I,d,o\"!", (ftnlen)128, (ftnlen)55);
		s_stop("1", (ftnlen)1);
	    }
	} else if (*(unsigned char *)charq == 'K') {

/*  Rules and function of K command */

/*  Only 1 K +/-n +/-m  allowed per block if n.ne.0 (transposition).  isig1 is */
/*  initial sig, and must be passed to pmxb because it is needed when topfile */
/*  is called, which is before the K+n+m command is read in pmxb.  Also, we */
/*  compute and save ibrkch and newkey for each syst, accounting for key changes, */
/*  then adjust fbar to make poenom much more accurate. */

	    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (i_indx("+-", durq, (ftnlen)2, (ftnlen)1) == 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "\"K\" (transpose or \
key change) must be followed by \"+,-\"!", (ftnlen)128, (ftnlen)56);
		s_stop("1", (ftnlen)1);
	    }
	    ++a1ll_2.iccount;
	    num1 = 44 - *(unsigned char *)durq;

/*  num1= +1 or -1 */

	    readnum_(lineq, &a1ll_2.iccount, durq, &fnum, (ftnlen)128, (
		    ftnlen)1);
	    num1 = i_nint(&fnum) * num1;
	    if (i_indx("+-", durq, (ftnlen)2, (ftnlen)1) == 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "1st number after \"\
K\" must be followed by \"+,-\"!", (ftnlen)128, (ftnlen)47);
		s_stop("1", (ftnlen)1);
	    }
	    ++a1ll_2.iccount;
	    num2 = 44 - *(unsigned char *)durq;
	    readnum_(lineq, &a1ll_2.iccount, durq, &fnum, (ftnlen)128, (
		    ftnlen)1);
	    num2 *= (integer) (fnum + (float).1);
	    if (num1 == 0) {

/*  Key change, only one per block allowed */

		if (comkeys_1.iskchb) {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Only one key cha\
nge allowed per input block!", (ftnlen)128, (ftnlen)44);
		    s_stop("1", (ftnlen)1);
		}
		comkeys_1.iskchb = TRUE_;
		++comkeys_1.nkeys;
		comkeys_1.kchmid[comkeys_1.nkeys - 1] = a1ll_2.itsofar[
			c1ommvl_1.ivx - 1] % a1ll_2.lenbar != 0;

/*  Make ibrkch = barnum-1 if at start of bar, so fsyst advances ok at linebreak. */

		comkeys_1.ibrkch[comkeys_1.nkeys - 1] = c1omnotes_1.ibarcnt + 
			a1ll_2.nbars;
		if (comkeys_1.kchmid[comkeys_1.nkeys - 1]) {
		    ++comkeys_1.ibrkch[comkeys_1.nkeys - 1];
		}
		comkeys_1.newkey[comkeys_1.nkeys - 1] = num2 + 
			comkeys_1.idsig;
	    } else {

/*  Transposition */

		if (c1omnotes_1.ibarcnt > 0) {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Transposition mu\
st be at top of first input block!", (ftnlen)128, (ftnlen)50);
		    s_stop("1", (ftnlen)1);
		}
		comkeys_1.isig1 = num2;
		comkeys_1.idsig = comkeys_1.isig1 - comkeys_1.newkey[0];

/*  idsig is the difference between sig after transposition, and sig in setup. */
/*  It may alter # of accid's in key changes if there is transposition. */

	    }
	} else if (*(unsigned char *)charq == '|') {

/*  Optional bar symbol */

	    if (a1ll_2.itsofar[c1ommvl_1.ivx - 1] % a1ll_2.lenbar != 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Bar line marker out \
of place!", (ftnlen)128, (ftnlen)29);
		s_stop("1", (ftnlen)1);
	    } else if (comkeys_1.shifton) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Bar ended with user-\
defined shift still on!", (ftnlen)128, (ftnlen)43);
		s_stop("1", (ftnlen)1);
	    }
	} else if (*(unsigned char *)charq == '/') {
	    if (c1omget_1.fbon) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Block ended with for\
ced beam open!", (ftnlen)128, (ftnlen)34);
		s_stop("1", (ftnlen)1);
	    } else if (comkeys_1.shifton) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Bar ended with user-\
defined shift still on!", (ftnlen)128, (ftnlen)43);
		s_stop("1", (ftnlen)1);
	    } else if (c1omnotes_1.gotclef) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "May not enter clef a\
t end of input block!", (ftnlen)128, (ftnlen)41);
		s_stop("1", (ftnlen)1);
	    }
	    comkeys_1.barend = FALSE_;

/*  Perform time checks */

	    if (a1ll_2.itsofar[c1ommvl_1.ivx - 1] % a1ll_2.lenbar != 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Block duration not d\
ivisible by lenbar!", (ftnlen)128, (ftnlen)39);
		s_wsle(&io___214);
		do_lio(&c__9, &c__1, "lenbar is ", (ftnlen)10);
		do_lio(&c__3, &c__1, (char *)&a1ll_2.lenbar, (ftnlen)sizeof(
			integer));
		e_wsle();
		s_stop("1", (ftnlen)1);
	    } else if (c1ommvl_1.ivx > 1 && a1ll_2.itsofar[c1ommvl_1.ivx - 1] 
		    != a1ll_2.itsofar[0]) {
		s_wsle(&io___215);
		e_wsle();
		s_wsle(&io___216);
		do_lio(&c__9, &c__1, "# of bars in voice 1, current voice:", (
			ftnlen)36);
		i__1 = a1ll_2.itsofar[0] / a1ll_2.lenbar;
		do_lio(&c__3, &c__1, (char *)&i__1, (ftnlen)sizeof(integer));
		i__2 = a1ll_2.itsofar[c1ommvl_1.ivx - 1] / a1ll_2.lenbar;
		do_lio(&c__3, &c__1, (char *)&i__2, (ftnlen)sizeof(integer));
		e_wsle();
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Block duration not e\
qual to voice 1!", (ftnlen)128, (ftnlen)36);
		s_stop("1", (ftnlen)1);
	    }
	    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (*(unsigned char *)durq == ' ' && a1ll_2.iv == a1ll_2.nv) {

/*  End of input block */

		*loop = FALSE_;
	    } else {

/*  Start a new voice */

		if (a1ll_2.lenbr0 != 0 && a1ll_2.firstline) {
		    a1ll_2.lenbar = a1ll_2.lenbr0;
		}
		a1ll_2.nbars = 0;
		if (*(unsigned char *)durq == ' ') {

/*  New voice is on next staff */

		    ++a1ll_2.iv;
		    c1ommvl_1.ivx = a1ll_2.iv;
		} else {

/*  New voice is on same staff.  Set up for it */

		    c1ommvl_1.ivx = a1ll_2.nv + 1;
		    i__1 = a1ll_2.nv;
		    for (iiv = 1; iiv <= i__1; ++iiv) {
			if (c1ommvl_1.nvmx[iiv - 1] == 2) {
			    ++c1ommvl_1.ivx;
			}
/* L23: */
		    }
		    if (c1ommvl_1.ivx > 15) {
			s_wsfe(&io___218);
			do_fio(&c__1, "Cannot have more than", (ftnlen)21);
			do_fio(&c__1, (char *)&c__15, (ftnlen)sizeof(integer))
				;
			do_fio(&c__1, " lines of music at once", (ftnlen)23);
			e_wsfe();
			s_stop("1", (ftnlen)1);
		    }
		    c1ommvl_1.nvmx[a1ll_2.iv - 1] = 2;
		    c1ommvl_1.ivmx[a1ll_2.iv + 14] = c1ommvl_1.ivx;
		    a1ll_2.itsofar[c1ommvl_1.ivx - 1] = 0;
		    a1ll_2.nnl[c1ommvl_1.ivx - 1] = 0;
		    for (j = 1; j <= 200; ++j) {
			a1ll_2.rest[c1ommvl_1.ivx + j * 15 - 16] = FALSE_;
/* L24: */
		    }

/*  For midi stuff, record that there is a 2nd line of music in this voice */

		    if (commidi_1.ismidi) {
			commidi_1.twoline[a1ll_2.iv - 1] = TRUE_;
		    }
		}
	    }
	    a1ll_2.iccount = 128;
	} else if (*(unsigned char *)charq == 'S') {

/*  New nsyst: for use with partmaker scor2prt, for parts w/ diff # of systs. */

	    if (c1omnotes_1.ibarcnt > 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "\"S\" can only be in\
 first input block!", (ftnlen)128, (ftnlen)37);
		s_stop("1", (ftnlen)1);
	    }
	    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (i_indx("123456789 ", durq, (ftnlen)10, (ftnlen)1) == 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "A digit must follow\
 \"S\"!", (ftnlen)128, (ftnlen)24);
		s_stop("1", (ftnlen)1);
	    }
	    readnum_(lineq, &a1ll_2.iccount, durq, &fnsyst, (ftnlen)128, (
		    ftnlen)1);
	    compage_1.nsyst = i_nint(&fnsyst);
L14:
	    if (*(unsigned char *)durq == 'P') {

/*  New npages for parts. */

		g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)
			1);
		if (i_indx("123456789 ", durq, (ftnlen)10, (ftnlen)1) == 0) {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Must have a numb\
er here!", (ftnlen)128, (ftnlen)24);
		    s_stop("1", (ftnlen)1);
		}
		readnum_(lineq, &a1ll_2.iccount, durq, &fnsyst, (ftnlen)128, (
			ftnlen)1);
		compage_1.npages = i_nint(&fnsyst);
		goto L14;
	    } else if (*(unsigned char *)durq == 'm') {

/*  Reset musize (musicsize). */

		g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)
			1);
		if (i_indx("123456789 ", durq, (ftnlen)10, (ftnlen)1) == 0) {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Must have a numb\
er here!", (ftnlen)128, (ftnlen)24);
		    s_stop("1", (ftnlen)1);
		}
		readnum_(lineq, &a1ll_2.iccount, durq, &fnsyst, (ftnlen)128, (
			ftnlen)1);
		commus_1.musize = i_nint(&fnsyst);
		c1omnotes_1.wheadpt = commus_1.whead20 * commus_1.musize;
		goto L14;
	    } else if (*(unsigned char *)durq != ' ') {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Illegal character \
in \"S\" symbol!", (ftnlen)128, (ftnlen)32);
		s_stop("1", (ftnlen)1);
	    }
	} else if (*(unsigned char *)charq == 'L') {
	    ++compage_1.nflb;
	    compage_1.ibarflb[compage_1.nflb] = c1omnotes_1.ibarcnt + 
		    a1ll_2.nbars + 1;
	    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (i_indx("123456789", durq, (ftnlen)9, (ftnlen)1) == 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Need integer to defi\
ne forced line break!", (ftnlen)128, (ftnlen)41);
		s_stop("1", (ftnlen)1);
	    }
	    readnum_(lineq, &a1ll_2.iccount, durq, &sysflb, (ftnlen)128, (
		    ftnlen)1);
	    compage_1.isysflb[compage_1.nflb] = i_nint(&sysflb);
	    if (compage_1.nflb > 1) {

/*  Check if new number is > prior one */

		if (compage_1.isysflb[compage_1.nflb] <= compage_1.isysflb[
			compage_1.nflb - 1]) {
		    i__1 = a1ll_2.iccount - 1;
		    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &i__1, &i__2, "You already forced a line \
break at a later line!", (ftnlen)128, (ftnlen)48);
		    s_stop("1", (ftnlen)1);
		}
	    }
	    if (compage_1.npages == 0) {
		s_wsle(&io___222);
		e_wsle();
		s_wsle(&io___223);
		do_lio(&c__9, &c__1, "WARNING! You forced a line break at li\
ne ", (ftnlen)41);
		do_lio(&c__3, &c__1, (char *)&compage_1.isysflb[
			compage_1.nflb], (ftnlen)sizeof(integer));
		do_lio(&c__9, &c__1, " but npage = 0.  Continue?", (ftnlen)26)
			;
		e_wsle();
		s_rsfe(&io___224);
		do_fio(&c__1, charq, (ftnlen)1);
		e_rsfe();
		if (i_indx("yY", charq, (ftnlen)2, (ftnlen)1) == 0) {
		    s_stop("1", (ftnlen)1);
		}
	    } else if (compage_1.isysflb[compage_1.nflb] > compage_1.nsyst) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Forced line break at\
 line num > nsyst!", (ftnlen)128, (ftnlen)38);
		s_stop("1", (ftnlen)1);
	    } else if (i_indx(" PM", durq, (ftnlen)3, (ftnlen)1) == 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Must have \" \", \"\
P\", or \"M\" here!", (ftnlen)128, (ftnlen)32);
		s_stop("1", (ftnlen)1);
	    }
	    if (*(unsigned char *)durq == 'P') {

/*  Forced page break here, get page number. */

		g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)
			1);
		if (i_indx("123456789", durq, (ftnlen)9, (ftnlen)1) == 0) {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Need integer to \
define forced page break!", (ftnlen)128, (ftnlen)41);
		    s_stop("1", (ftnlen)1);
		}
		readnum_(lineq, &a1ll_2.iccount, durq, &fnum, (ftnlen)128, (
			ftnlen)1);
		++compage_1.nfpb;
		compage_1.ipagfpb[compage_1.nfpb] = i_nint(&fnum);
		compage_1.isysfpb[compage_1.nfpb] = compage_1.isysflb[
			compage_1.nflb];
	    }
	    if (i_indx(" M", durq, (ftnlen)2, (ftnlen)1) == 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "Illegal character in\
 linebreak symbol!", (ftnlen)128, (ftnlen)38);
		s_stop("1", (ftnlen)1);
	    } else if (*(unsigned char *)durq == 'M') {
		++compage_1.nmovbrk;
		compage_1.isysmb[compage_1.nmovbrk] = compage_1.isysflb[
			compage_1.nflb];
		g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (ftnlen)
			1);
L31:
		if (*(unsigned char *)durq == '+') {

/*  Vertical spacing, read past number. */

		    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (
			    ftnlen)1);
		    if (i_indx("123456789", durq, (ftnlen)9, (ftnlen)1) == 0) 
			    {
			i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &a1ll_2.iccount, &i__1, "Integer requ\
ired here!", (ftnlen)128, (ftnlen)22);
			s_stop("1", (ftnlen)1);
		    }
		    readnum_(lineq, &a1ll_2.iccount, durq, &fnum, (ftnlen)128,
			     (ftnlen)1);
		    goto L31;
		} else if (*(unsigned char *)durq == 'i') {

/*  Change indentation, */

		    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (
			    ftnlen)1);
		    if (i_indx(".123456789", durq, (ftnlen)10, (ftnlen)1) == 
			    0) {
			i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &a1ll_2.iccount, &i__1, "Decimal numb\
er required here!", (ftnlen)128, (ftnlen)29);
			s_stop("1", (ftnlen)1);
		    }

/*  fracsys was initialized in block data to all 0.'s */

		    readnum_(lineq, &a1ll_2.iccount, durq, &compage_1.fracsys[
			    compage_1.nmovbrk - 1], (ftnlen)128, (ftnlen)1);
		    goto L31;
		} else if (*(unsigned char *)durq == 'c') {
		    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (
			    ftnlen)1);
		    goto L31;
		} else if (*(unsigned char *)durq == 'r') {
		    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (
			    ftnlen)1);
		    if (i_indx("+-", durq, (ftnlen)2, (ftnlen)1) == 0) {
			i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &a1ll_2.iccount, &i__1, "Must have\
 \"+\" or \"-\" after \"r\" as movement break option!", (ftnlen)128, (ftnlen)
				56);
			s_stop("1", (ftnlen)1);
		    }
		    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (
			    ftnlen)1);
		    goto L31;
		} else if (*(unsigned char *)durq == 'n') {

/*  Change # of voices.  Input ninow, iorig(1...ninow).  Will use names, */
/*  staves per inst. and clefs  corr. to iorig in original list of instruments. */

		    a1ll_2.nv = 0;
		    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (
			    ftnlen)1);
		    ninow = *(unsigned char *)durq - 48;
		    if (ninow < 1 || ninow > 15) {
			i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
				a1ll_2.nbars + 1;
			errmsg_(lineq, &a1ll_2.iccount, &i__1, "New noinst m\
ust come here!", (ftnlen)128, (ftnlen)26);
			s_stop("1", (ftnlen)1);
		    }
		    i__1 = ninow;
		    for (iinow = 1; iinow <= i__1; ++iinow) {
			g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (
				ftnlen)1);
			iorig = *(unsigned char *)durq - 48;
			if (iorig < 1 || iorig > comkeys_1.noinst) {
			    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff 
				    + a1ll_2.nbars + 1;
			    errmsg_(lineq, &a1ll_2.iccount, &i__2, "Must ent\
er inst. # from orig. list here!", (ftnlen)128, (ftnlen)40);
			    s_stop("1", (ftnlen)1);
			}
			a1ll_2.nv += c1omget_1.nsperi[iorig - 1];
/* L63: */
		    }
		    i__1 = a1ll_2.nv;
		    for (iiv = 1; iiv <= i__1; ++iiv) {

/*  Get clef names */

			g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (
				ftnlen)1);
			if (! (i_indx("tsmanrbf", durq, (ftnlen)8, (ftnlen)1) 
				> 0 || *(unsigned char *)durq >= 48 && *(
				unsigned char *)durq <= 55)) {
/*     *             (ichar(durq).ge.48 .and. ichar(durq).le.54))) then */
			    i__2 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff 
				    + a1ll_2.nbars + 1;
			    errmsg_(lineq, &a1ll_2.iccount, &i__2, "Must hav\
e t,s,m,a,n,r,b,f or 1-7 as clef symbol here!", (ftnlen)128, (ftnlen)53);
/*     *          'Must have t,s,m,a,n,r,b,f or 1-6 as clef symbol here!') */
			    s_stop("1", (ftnlen)1);
			}

/*  Initialize new voices */

			c1ommvl_1.nvmx[iiv - 1] = 1;
			c1ommvl_1.ivmx[iiv - 1] = iiv;
			a1ll_2.itsofar[iiv - 1] = 0;
			a1ll_2.nnl[iiv - 1] = 0;
			for (j = 1; j <= 200; ++j) {
			    a1ll_2.rest[iiv + j * 15 - 16] = FALSE_;
/* L62: */
			}
/* L61: */
		    }

/*  Loop back up, this might not be last option in M */

		    g1etchar_(lineq, &a1ll_2.iccount, durq, (ftnlen)128, (
			    ftnlen)1);
		    goto L31;
		} else if (*(unsigned char *)durq != ' ') {
		    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			    a1ll_2.nbars + 1;
		    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Illegal characte\
r after Movement break symbol!", (ftnlen)128, (ftnlen)46);
		    s_stop("1", (ftnlen)1);
		}
		if (compage_1.fracsys[compage_1.nmovbrk - 1] < (float).001) {

/*  Since fracsys was not explicitly set, set it to prior value. */

		    if (compage_1.nmovbrk == 1) {
			compage_1.fracsys[compage_1.nmovbrk - 1] = 
				c1omget_1.fracindent;
		    } else {
			compage_1.fracsys[compage_1.nmovbrk - 1] = 
				compage_1.fracsys[compage_1.nmovbrk - 2];
		    }
		}
	    }

/*  Just before exiting if-block for forced line breaks, set counter to use when */
/*  dealing with vertical space calcs */

	    compage_1.nistaff[compage_1.nflb] = a1ll_2.nv - 1;
	} else if (*(unsigned char *)charq == 'F') {
	    compage_1.usefig = FALSE_;
	} else if (*(unsigned char *)charq == 'X') {
	    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + a1ll_2.nbars + 
		    1;
	    g1etx_(lineq, &a1ll_2.iccount, &c_true, &comkeys_1.shifton, &i__1,
		     &c1omnotes_1.udsp[c1omnotes_1.ibarcnt + a1ll_2.nbars], &
		    c1omnotes_1.wheadpt, (ftnlen)128);
	} else if (*(unsigned char *)charq == 'I') {

/*  MIDI settings. */

	    if (c1ommvl_1.ivx != 1 || a1ll_2.nnl[0] != 0) {
		i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + 
			a1ll_2.nbars + 1;
		errmsg_(lineq, &a1ll_2.iccount, &i__1, "MIDI stuff only allo\
wed at start of block!", (ftnlen)128, (ftnlen)42);
		s_stop("1", (ftnlen)1);
	    }
	    commidi_1.ismidi = TRUE_;
	    getmidi_(&a1ll_2.nv, lineq, &a1ll_2.iccount, &c1omnotes_1.ibarcnt,
		     &c1omnotes_1.ibaroff, &a1ll_2.nbars, &a1ll_2.lenbar, &
		    mtrdenl, &c_true, (ftnlen)128);
	} else if (*(unsigned char *)charq == 'M') {
	    setmac_(lineq, &a1ll_2.iccount, &c1omnotes_1.ibarcnt, &
		    c1omnotes_1.ibaroff, &a1ll_2.nbars, charq, durq, &
		    c1ommvl_1.ivx, &c1omget_1.nline, (ftnlen)128, (ftnlen)1, (
		    ftnlen)1);
	} else {
	    i__1 = c1omnotes_1.ibarcnt - c1omnotes_1.ibaroff + a1ll_2.nbars + 
		    1;
	    errmsg_(lineq, &a1ll_2.iccount, &i__1, "Illegal character!", (
		    ftnlen)128, (ftnlen)18);
	    s_wsle(&io___228);
	    do_lio(&c__9, &c__1, "ASCII code:", (ftnlen)11);
	    i__1 = *(unsigned char *)charq;
	    do_lio(&c__3, &c__1, (char *)&i__1, (ftnlen)sizeof(integer));
	    e_wsle();
	    s_stop("1", (ftnlen)1);
	}
    }
    return 0;
} /* g1etnote_ */

/* Subroutine */ int g1etchar_(lineq, iccount, charq, lineq_len, charq_len)
char *lineq;
integer *iccount;
char *charq;
ftnlen lineq_len;
ftnlen charq_len;
{
    /* Builtin functions */
    /* Subroutine */ int s_copy();

    /* Local variables */
    static integer ndxm;
    extern /* Subroutine */ int read10_(), m1rec1_();
    static integer nbars, ibaroff, ibarcnt;


/*  Gets the next character out of lineq*128.  If pointer iccount=128 on entry, */
/*  then reads in a new line.  Resets iccount.  Ends program if no more input. */

    if (*iccount == 128) {
	read10_(lineq, &c1omget_1.lastchar, (ftnlen)128);
	if (c1omget_1.lastchar) {
	    return 0;
	}
	if (! commac_1.endmac) {
	    *iccount = 0;
	    if (! commac_1.mplay) {
		++c1omget_1.nline;
	    }
	} else {
	    commac_1.endmac = FALSE_;
	    *iccount = commac_1.icchold;
	    s_copy(lineq, commac_1.lnholdq, (ftnlen)128, (ftnlen)128);
	}
	if (commac_1.mrecord) {
	    m1rec1_(lineq, iccount, &ibarcnt, &ibaroff, &nbars, &ndxm, (
		    ftnlen)128);
	}
    }
    ++(*iccount);
    *(unsigned char *)charq = *(unsigned char *)&lineq[*iccount - 1];
    return 0;
} /* g1etchar_ */

integer i1fnodur_(idur, dotq, dotq_len)
integer *idur;
char *dotq;
ftnlen dotq_len;
{
    /* System generated locals */
    integer ret_val;

    /* Builtin functions */
    integer s_wsle(), e_wsle(), do_lio();
    /* Subroutine */ int s_stop();

    /* Fortran I/O blocks */
    static cilist io___233 = { 0, 6, 0, 0, 0 };
    static cilist io___234 = { 0, 6, 0, 0, 0 };


    if (*idur == 6) {
	ret_val = 1;
    } else if (*idur == 3) {
	ret_val = 2;
    } else if (*idur == 1) {
	ret_val = 4;
    } else if (*idur == 8) {
	ret_val = 8;
    } else if (*idur == 4) {
	ret_val = 16;
    } else if (*idur == 2) {
	ret_val = 32;
    } else if (*idur == 0) {
	ret_val = 64;
    } else if (*idur == 16) {

/*  Only used for denominator of time signatures, not for notes */

	ret_val = 4;
    } else if (*idur == 9) {
	ret_val = 128;
    } else {
	s_wsle(&io___233);
	e_wsle();
	s_wsle(&io___234);
	do_lio(&c__9, &c__1, "You entered an invalid note-length value:", (
		ftnlen)41);
	do_lio(&c__3, &c__1, (char *)&(*idur), (ftnlen)sizeof(integer));
	e_wsle();
	s_stop("1", (ftnlen)1);
    }
    if (*(unsigned char *)dotq == 'd') {
	ret_val = ret_val * 3 / 2;
    }
    return ret_val;
} /* i1fnodur_ */

/* Subroutine */ int makeabar_()
{
    /* System generated locals */
    integer i__1, i__2;
    real r__1, r__2, r__3;

    /* Builtin functions */
    integer i_nint();

    /* Local variables */
    static integer ib, in, kv, cnn[15];
    static real xit[15];
    static integer ilnc;
    static real tmin;
    static integer nnsk, ntot;
    extern doublereal f1eon_();
    static real space[80];
    extern doublereal fnote_();
    static real tminn, tnote[200];
    static integer istop[80];
    static real squez[80];
    static integer istart[80], ivnext;
    static real tstart[80], xsquez;
    extern /* Subroutine */ int catspace_();
    static real elsperns;
    extern doublereal getsquez_();


/*  On input, have pseudo-durations in nodur(ivx,ip).  Not real durations for */
/*    xtups, since only last note of xtup gets non-zero nodur, which */
/*    corresponds to single note of full length of xtup. */
/*  In this subroutine we make an ordered list of all notes in all voices. */
/*    ilnc      = list note counter */
/*    ivxo(ilnc), ipo(ilnc) = voice# and position in voice of ilnc-th note. */
/*    to(ilnc)  = real duration of the note in PMX-units (64=whole note) */
/*    tno(ilnc) = time to next event in the bar. */
/*    tnote(ilnc) = actual duration of note */
/*  Then run thru list, grouping consecutive notes into \notes groups ib. */
/*    space(ib) = real time unit for the \notes group */
/*    squez(ib) = factor on space to get effective space.  This will be 1 if */
/*                there is a note exactly spanning each interval of space, and */
/*                <1 if not. */
/*  Details:  let eon = elemskips per noteskip (like length).  Basic formula is */
/*    eon = sqrt(space/2.) */
/*  If tgovern >= space, then */
/*    eon = sqrt(tgovern/2)*(space/tgovern) = space/sqrt(2*tgovern). */
/*  Time needed to give this eon using basic formula is */
/*    teq = space**2/tgovern */
/*  Factor on space to get teq is */
/*    squez(ib) = space/tgovern */
/*  The eon for each ib can then be computed based on time of space*squez. */
/*  Iff squez = 1, there is a note spanning every increment in the \notes group. */

/*    tnminb = minimum time span in the bar for increments spanned by notes, */
/*             i.e., with squez=1.  Use after parsing into line to decide if */
/*             spacing needs to be "flattened" among notes groups. */

    linecom_1.elskb = (float)0.;
    linecom_1.tnminb[c1omnotes_1.ibarcnt - 1] = (float)1e3;
    i__1 = a1ll_2.nv;
    for (a1ll_2.iv = 1; a1ll_2.iv <= i__1; ++a1ll_2.iv) {
	i__2 = c1ommvl_1.nvmx[a1ll_2.iv - 1];
	for (kv = 1; kv <= i__2; ++kv) {
	    c1ommvl_1.ivx = c1ommvl_1.ivmx[a1ll_2.iv + kv * 15 - 16];
	    if (a1ll_2.ibar > 1) {
		a1ll_2.nn[c1ommvl_1.ivx - 1] = a1ll_2.nib[c1ommvl_1.ivx + 
			a1ll_2.ibar * 15 - 16] - a1ll_2.nib[c1ommvl_1.ivx + (
			a1ll_2.ibar - 1) * 15 - 16];
	    } else {
		a1ll_2.nn[c1ommvl_1.ivx - 1] = a1ll_2.nib[c1ommvl_1.ivx + 
			a1ll_2.ibar * 15 - 16];
	    }
/* L1: */
	}
    }

/* initialize list note counter, time(iv), curr. note(iv) */

    ilnc = 1;
    i__2 = a1ll_2.nv;
    for (a1ll_2.iv = 1; a1ll_2.iv <= i__2; ++a1ll_2.iv) {
	i__1 = c1ommvl_1.nvmx[a1ll_2.iv - 1];
	for (kv = 1; kv <= i__1; ++kv) {
	    c1ommvl_1.ivx = c1ommvl_1.ivmx[a1ll_2.iv + kv * 15 - 16];
	    cnn[c1ommvl_1.ivx - 1] = 1;
	    a1ll_2.ivxo[ilnc - 1] = c1ommvl_1.ivx;
	    a1ll_2.ipo[ilnc - 1] = 1;
	    a1ll_2.to[ilnc - 1] = (float)0.;
	    tnote[ilnc - 1] = fnote_(a1ll_2.nodur, &c1ommvl_1.ivx, &c__1);
	    xit[c1ommvl_1.ivx - 1] = tnote[ilnc - 1];
	    if ((r__1 = xit[c1ommvl_1.ivx - 1] - a1ll_2.lenbar, dabs(r__1)) < 
		    comtol_1.tol) {
		xit[c1ommvl_1.ivx - 1] = (float)1e3;
	    }
	    ++ilnc;
/* L4: */
	}
    }

/*  Build the list */

L5:

/*  Determine which voice comes next from end of notes done so far. */
/*  tmin is the earliest ending time of notes done so far */

    tmin = (float)1e3;
    i__1 = a1ll_2.nv;
    for (a1ll_2.iv = 1; a1ll_2.iv <= i__1; ++a1ll_2.iv) {
	i__2 = c1ommvl_1.nvmx[a1ll_2.iv - 1];
	for (kv = 1; kv <= i__2; ++kv) {
	    c1ommvl_1.ivx = c1ommvl_1.ivmx[a1ll_2.iv + kv * 15 - 16];
/* Computing MIN */
	    r__1 = tmin, r__2 = xit[c1ommvl_1.ivx - 1];
	    tminn = dmin(r__1,r__2);
	    if (tminn < tmin) {
		tmin = tminn;
		ivnext = c1ommvl_1.ivx;
	    }
/* L6: */
	}
    }
    if (tmin > (float)999.) {
	goto L7;
    }
    a1ll_2.ivxo[ilnc - 1] = ivnext;
    ++cnn[ivnext - 1];
    a1ll_2.ipo[ilnc - 1] = cnn[ivnext - 1];
    a1ll_2.to[ilnc - 1] = tmin;

/*  Check if this voice is done */

    tnote[ilnc - 1] = fnote_(a1ll_2.nodur, &ivnext, &cnn[ivnext - 1]);
    if (cnn[ivnext - 1] == a1ll_2.nn[ivnext - 1]) {
	xit[ivnext - 1] = (float)1e3;
    } else {
	xit[ivnext - 1] += tnote[ilnc - 1];
    }
    ++ilnc;
    goto L5;
L7:
    ntot = ilnc - 1;
    i__2 = ntot - 1;
    for (in = 1; in <= i__2; ++in) {
	a1ll_2.tno[in - 1] = a1ll_2.to[in] - a1ll_2.to[in - 1];
/* L8: */
    }
    a1ll_2.tno[ntot - 1] = fnote_(a1ll_2.nodur, &a1ll_2.ivxo[ntot - 1], &
	    a1ll_2.ipo[ntot - 1]);
    tnote[ntot - 1] = a1ll_2.tno[ntot - 1];

/*  Debug writes */

/*      write(*,'()') */
/*      write(*,'(16i5)')(ivxo(in),in=1,ntot) */
/*      write(*,'(16i5)')(ipo(in),in=1,ntot) */
/*      write(*,'(16f5.1)')(to(in),in=1,ntot) */
/*      write(*,'(16f5.1)')(tno(in),in=1,ntot) */
/*      write(*,'(16i5)')(nodur(ivxo(in),ipo(in)),in=1,ntot) */
/*      write(*,'(16f5.1)')(tnote(in),in=1,ntot) */

/*  Done w/ list.  Initialize loop for building note blocks: */

    ib = 1;
    istart[0] = 1;
    space[0] = (float)0.;
    in = 1;

/*  Start the loop */

L9:
    if (in == ntot) {
	if (space[ib - 1] < comtol_1.tol) {
	    space[ib - 1] = a1ll_2.tno[in - 1];

/*  Last gap in bar is spanned by a note, so cannot need a squeeze. */

	    squez[ib - 1] = (float)1.;
	}
	istop[ib - 1] = ntot;

/* From here flow out of this if block and into block-setup */

    } else if (space[ib - 1] < comtol_1.tol) {

/* space hasn't been set yet, so tentatively set: */

	space[ib - 1] = a1ll_2.tno[in - 1];
	if (space[ib - 1] < comtol_1.tol) {
	    ++in;
	} else {

/*  Tentative space tno(in) is non-zero. Set squez, which will be kept (since */
/*    it is a unique property of the particular increment starting here) : */

	    squez[ib - 1] = getsquez_(&in, &ntot, &space[ib - 1], tnote, 
		    a1ll_2.to);
	    istop[ib - 1] = in;
	}
	goto L9;
    } else if (a1ll_2.tno[in] < comtol_1.tol) {

/* This is not the last note in the space, so */

	++in;
	goto L9;
    } else if ((r__1 = a1ll_2.tno[in] - space[ib - 1], dabs(r__1)) < 
	    comtol_1.tol) {

/*  Next increment has same space.  Does it have same squez? */

	i__2 = in + 1;
	xsquez = getsquez_(&i__2, &ntot, &space[ib - 1], tnote, a1ll_2.to);

/*  If it does have the same squez, loop, otherwise flow out */

	if ((r__1 = xsquez - squez[ib - 1], dabs(r__1)) < comtol_1.tol) {

/* Keep spacing the same, update tentative stop point */

	    ++in;
	    istop[ib - 1] = in;
	    goto L9;
	}
    }

/* At this point istart, istop, space, and squez are good, so close out block */

    tstart[ib - 1] = a1ll_2.to[istart[ib - 1] - 1];

/*  Compute elemskips assuming no flattening to increase min space.  The formula */
/*  is only correct if f1eon(t) = sqrt(t/2); more generally (after possible */
/*  flattening in pmxb), elsperns = squez*feon(space/squez) */

    r__1 = space[ib - 1] * squez[ib - 1];
    elsperns = f1eon_(&r__1);
    if (istop[ib - 1] == ntot) {
	r__1 = (a1ll_2.lenbar - tstart[ib - 1]) / space[ib - 1];
	nnsk = i_nint(&r__1);
    } else {
	r__1 = (a1ll_2.to[istop[ib - 1]] - tstart[ib - 1]) / space[ib - 1];
	nnsk = i_nint(&r__1);
    }
    linecom_1.elskb += elsperns * nnsk;
    if (c1omnotes_1.nptr[c1omnotes_1.ibarcnt] > c1omnotes_1.nptr[
	    c1omnotes_1.ibarcnt - 1]) {
	catspace_(&space[ib - 1], &squez[ib - 1], &nnsk);
    } else {

/*  This is the first entry for this bar */

	c1omnotes_1.nnpd[c1omnotes_1.nptr[c1omnotes_1.ibarcnt - 1] - 1] = 
		nnsk;
	c1omnotes_1.durb[c1omnotes_1.nptr[c1omnotes_1.ibarcnt - 1] - 1] = 
		space[ib - 1];
	c1omnotes_1.sqzb[c1omnotes_1.nptr[c1omnotes_1.ibarcnt - 1] - 1] = 
		squez[ib - 1];
	++c1omnotes_1.nptr[c1omnotes_1.ibarcnt];
    }

/*  Update minimum space spanned by a note */

    if ((r__1 = squez[ib - 1] - 1, dabs(r__1)) < comtol_1.tol) {
/* Computing MIN */
	r__2 = linecom_1.tnminb[c1omnotes_1.ibarcnt - 1], r__3 = space[ib - 1]
		;
	linecom_1.tnminb[c1omnotes_1.ibarcnt - 1] = dmin(r__2,r__3);
    }
    if (istop[ib - 1] == ntot) {
	goto L15;
    }

/*  End of spatial accounting for now */

    ++ib;
    istart[ib - 1] = istop[ib - 2] + 1;
    in = istart[ib - 1];

/* Set tentative block space for new block */

    space[ib - 1] = a1ll_2.tno[in - 1];
    if (space[ib - 1] > comtol_1.tol) {
	squez[ib - 1] = getsquez_(&in, &ntot, &space[ib - 1], tnote, 
		a1ll_2.to);
    }
    istop[ib - 1] = in;
    goto L9;
L15:
/*     nb = ib */

/*  Debug writes */

/*      write(*,'(16i5)')(istart(ib),ib=1,nb) */
/*      write(*,'(16i5)')(istop(ib),ib=1,nb) */
/*      write(*,'(16f5.1)')(space(ib),ib=1,nb) */
/*      write(*,'(16f5.1)')(squez(ib),ib=1,nb) */

    return 0;
} /* makeabar_ */

doublereal f1eon_(time)
real *time;
{
    /* System generated locals */
    real ret_val;

    /* Builtin functions */
    double sqrt();

    ret_val = sqrt(*time / 2);
    return ret_val;
} /* f1eon_ */

/* Subroutine */ int catspace_(space, squez, nnsk)
real *space, *squez;
integer *nnsk;
{
    /* System generated locals */
    integer i__1;
    real r__1;

    /* Local variables */
    static integer iptr;

    i__1 = c1omnotes_1.nptr[c1omnotes_1.ibarcnt] - 1;
    for (iptr = c1omnotes_1.nptr[c1omnotes_1.ibarcnt - 1]; iptr <= i__1; 
	    ++iptr) {
	if ((r__1 = *space - c1omnotes_1.durb[iptr - 1], dabs(r__1)) < 
		comtol_1.tol) {
	    if ((r__1 = *squez - c1omnotes_1.sqzb[iptr - 1], dabs(r__1)) < 
		    comtol_1.tol) {

/*  Increment pre-existing entry */

		c1omnotes_1.nnpd[iptr - 1] += *nnsk;
		return 0;
	    }
	}
/* L16: */
    }

/*  Didn't find current duration & squez, so add a new entry. */
/*  No particular reason to keep in order, so add at the end. */

    c1omnotes_1.nnpd[c1omnotes_1.nptr[c1omnotes_1.ibarcnt] - 1] = *nnsk;
    c1omnotes_1.durb[c1omnotes_1.nptr[c1omnotes_1.ibarcnt] - 1] = *space;
    c1omnotes_1.sqzb[c1omnotes_1.nptr[c1omnotes_1.ibarcnt] - 1] = *squez;
    ++c1omnotes_1.nptr[c1omnotes_1.ibarcnt];
    return 0;
} /* catspace_ */

/* Subroutine */ int chklit_(lineq, iccount, literr, lineq_len)
char *lineq;
integer *iccount, *literr;
ftnlen lineq_len;
{
    /* System generated locals */
    char ch__1[1];

    /* Local variables */
    extern /* Character */ VOID chax_();
    static char charq[1];
    static integer itype, lenlit;
    extern /* Subroutine */ int g1etchar_();

    *literr = 0;
    itype = 1;
L17:
    g1etchar_(lineq, iccount, charq, (ftnlen)128, (ftnlen)1);
    chax_(ch__1, (ftnlen)1, &c__92);
    if (*(unsigned char *)charq == *(unsigned char *)&ch__1[0]) {
	++itype;
	if (itype > 3) {
	    *literr = 1;
	    return 0;
	}
	goto L17;
    }
    lenlit = itype;
L18:
    g1etchar_(lineq, iccount, charq, (ftnlen)128, (ftnlen)1);
    chax_(ch__1, (ftnlen)1, &c__92);
    if (*(unsigned char *)charq == *(unsigned char *)&ch__1[0]) {
	g1etchar_(lineq, iccount, charq, (ftnlen)128, (ftnlen)1);
	if (*(unsigned char *)charq != ' ') {

/*  Starting a new tex command withing the string */

	    lenlit += 2;
	    if (lenlit > 128) {
		*literr = 2;
		return 0;
	    }
	    goto L18;
	}
    } else {
	++lenlit;
	if (lenlit > 128) {
	    *literr = 2;
	    return 0;
	}
	goto L18;
    }
    return 0;
} /* chklit_ */

/* Subroutine */ int errmsg_(lineq, iccount, ibarno, msgq, lineq_len, 
	msgq_len)
char *lineq;
integer *iccount, *ibarno;
char *msgq;
ftnlen lineq_len;
ftnlen msgq_len;
{
    /* System generated locals */
    address a__1[2], a__2[5], a__3[4];
    integer i__1[2], i__2, i__3, i__4[5], i__5[4];
    real r__1;
    char ch__1[18], ch__2[1], ch__3[1], ch__4[7], ch__5[79];
    cilist ci__1;
    olist o__1;
    cllist cl__1;

    /* Builtin functions */
    /* Subroutine */ int s_copy(), s_cat();
    integer s_wsle(), e_wsle();
    double r_lg10();
    integer i_indx(), s_wsfe(), do_fio(), e_wsfe(), do_lio(), f_open(), 
	    f_clos();

    /* Local variables */
    static integer i1, i10;
    extern /* Character */ VOID chax_();
    static char outq[78];
    static integer iposn, ndigbn, ndignl, lenmsg;

    /* Fortran I/O blocks */
    static cilist io___260 = { 0, 6, 0, 0, 0 };
    static cilist io___264 = { 0, 6, 0, "(1x,a)", 0 };
    static cilist io___265 = { 0, 15, 0, "(a)", 0 };
    static cilist io___268 = { 0, 6, 0, 0, 0 };
    static cilist io___269 = { 0, 15, 0, "(a)", 0 };
    static cilist io___270 = { 0, 19, 0, "(i6)", 0 };


    if (*iccount <= 78) {
	s_copy(outq, lineq, (ftnlen)78, (ftnlen)78);
	iposn = *iccount;
    } else {
/* Writing concatenation */
	i__1[0] = 4, a__1[0] = "... ";
	i__1[1] = 74, a__1[1] = lineq + 54;
	s_cat(outq, a__1, i__1, &c__2, (ftnlen)78);
	iposn = *iccount - 50;
    }
    s_wsle(&io___260);
    e_wsle();
/* Computing MAX */
    r__1 = *ibarno + (float).1;
    i__2 = 1, i__3 = (integer) (r_lg10(&r__1) + 1);
    ndigbn = max(i__2,i__3);
    r__1 = c1omget_1.nline + (float).1;
    ndignl = (integer) (r_lg10(&r__1) + 1);
    lenmsg = i_indx(msgq, "!", msgq_len, (ftnlen)1) - 1;

/*  Split off msgq(..) sinve UNIX compilers don't allow concat substring!!! */

    ci__1.cierr = 0;
    ci__1.ciunit = 6;
/* Writing concatenation */
    i__4[0] = 8, a__2[0] = "(/,a15,i";
    i__2 = ndignl + 48;
    chax_(ch__2, (ftnlen)1, &i__2);
    i__4[1] = 1, a__2[1] = ch__2;
    i__4[2] = 5, a__2[2] = ",a6,i";
    i__3 = ndigbn + 48;
    chax_(ch__3, (ftnlen)1, &i__3);
    i__4[3] = 1, a__2[3] = ch__3;
    i__4[4] = 3, a__2[4] = ",$)";
    ci__1.cifmt = (s_cat(ch__1, a__2, i__4, &c__5, (ftnlen)18), ch__1);
    s_wsfe(&ci__1);
    do_fio(&c__1, " ERROR in line ", (ftnlen)15);
    do_fio(&c__1, (char *)&c1omget_1.nline, (ftnlen)sizeof(integer));
    do_fio(&c__1, ", bar ", (ftnlen)6);
    do_fio(&c__1, (char *)&(*ibarno), (ftnlen)sizeof(integer));
    e_wsfe();
    s_wsfe(&io___264);
    do_fio(&c__1, msgq, lenmsg);
    e_wsfe();
    ci__1.cierr = 0;
    ci__1.ciunit = 15;
/* Writing concatenation */
    i__4[0] = 8, a__2[0] = "(/,a15,i";
    i__2 = ndignl + 48;
    chax_(ch__2, (ftnlen)1, &i__2);
    i__4[1] = 1, a__2[1] = ch__2;
    i__4[2] = 5, a__2[2] = ",a6,i";
    i__3 = ndigbn + 48;
    chax_(ch__3, (ftnlen)1, &i__3);
    i__4[3] = 1, a__2[3] = ch__3;
    i__4[4] = 3, a__2[4] = ",$)";
    ci__1.cifmt = (s_cat(ch__1, a__2, i__4, &c__5, (ftnlen)18), ch__1);
    s_wsfe(&ci__1);
    do_fio(&c__1, " ERROR in line ", (ftnlen)15);
    do_fio(&c__1, (char *)&c1omget_1.nline, (ftnlen)sizeof(integer));
    do_fio(&c__1, ", bar ", (ftnlen)6);
    do_fio(&c__1, (char *)&(*ibarno), (ftnlen)sizeof(integer));
    e_wsfe();
    s_wsfe(&io___265);
    do_fio(&c__1, msgq, lenmsg);
    e_wsfe();
    i10 = iposn / 10;
    i1 = iposn - i10 * 10;
    ci__1.cierr = 0;
    ci__1.ciunit = 6;
/* Writing concatenation */
    i__5[0] = 1, a__3[0] = "(";
    i__2 = i10 + 48;
    chax_(ch__2, (ftnlen)1, &i__2);
    i__5[1] = 1, a__3[1] = ch__2;
    i__3 = i1 + 48;
    chax_(ch__3, (ftnlen)1, &i__3);
    i__5[2] = 1, a__3[2] = ch__3;
    i__5[3] = 4, a__3[3] = "x,a)";
    ci__1.cifmt = (s_cat(ch__4, a__3, i__5, &c__4, (ftnlen)7), ch__4);
    s_wsfe(&ci__1);
    do_fio(&c__1, "v", (ftnlen)1);
    e_wsfe();
    ci__1.cierr = 0;
    ci__1.ciunit = 15;
/* Writing concatenation */
    i__5[0] = 1, a__3[0] = "(";
    i__2 = i10 + 48;
    chax_(ch__2, (ftnlen)1, &i__2);
    i__5[1] = 1, a__3[1] = ch__2;
    i__3 = i1 + 48;
    chax_(ch__3, (ftnlen)1, &i__3);
    i__5[2] = 1, a__3[2] = ch__3;
    i__5[3] = 4, a__3[3] = "x,a)";
    ci__1.cifmt = (s_cat(ch__4, a__3, i__5, &c__4, (ftnlen)7), ch__4);
    s_wsfe(&ci__1);
    do_fio(&c__1, "v", (ftnlen)1);
    e_wsfe();
    s_wsle(&io___268);
    do_lio(&c__9, &c__1, outq, (ftnlen)78);
    e_wsle();
    s_wsfe(&io___269);
/* Writing concatenation */
    i__1[0] = 1, a__1[0] = " ";
    i__1[1] = 78, a__1[1] = outq;
    s_cat(ch__5, a__1, i__1, &c__2, (ftnlen)79);
    do_fio(&c__1, ch__5, (ftnlen)79);
    e_wsfe();
    ci__1.cierr = 0;
    ci__1.ciunit = 6;
/* Writing concatenation */
    i__5[0] = 1, a__3[0] = "(";
    i__2 = i10 + 48;
    chax_(ch__2, (ftnlen)1, &i__2);
    i__5[1] = 1, a__3[1] = ch__2;
    i__3 = i1 + 48;
    chax_(ch__3, (ftnlen)1, &i__3);
    i__5[2] = 1, a__3[2] = ch__3;
    i__5[3] = 4, a__3[3] = "x,a)";
    ci__1.cifmt = (s_cat(ch__4, a__3, i__5, &c__4, (ftnlen)7), ch__4);
    s_wsfe(&ci__1);
    do_fio(&c__1, "^", (ftnlen)1);
    e_wsfe();
    ci__1.cierr = 0;
    ci__1.ciunit = 15;
/* Writing concatenation */
    i__5[0] = 1, a__3[0] = "(";
    i__2 = i10 + 48;
    chax_(ch__2, (ftnlen)1, &i__2);
    i__5[1] = 1, a__3[1] = ch__2;
    i__3 = i1 + 48;
    chax_(ch__3, (ftnlen)1, &i__3);
    i__5[2] = 1, a__3[2] = ch__3;
    i__5[3] = 4, a__3[3] = "x,a)";
    ci__1.cifmt = (s_cat(ch__4, a__3, i__5, &c__4, (ftnlen)7), ch__4);
    s_wsfe(&ci__1);
    do_fio(&c__1, "^", (ftnlen)1);
    e_wsfe();
    o__1.oerr = 0;
    o__1.ounit = 19;
    o__1.ofnmlen = 11;
    o__1.ofnm = "pmxaerr.dat";
    o__1.orl = 0;
    o__1.osta = 0;
    o__1.oacc = 0;
    o__1.ofm = 0;
    o__1.oblnk = 0;
    f_open(&o__1);
    s_wsfe(&io___270);
    do_fio(&c__1, (char *)&c1omget_1.nline, (ftnlen)sizeof(integer));
    e_wsfe();
    cl__1.cerr = 0;
    cl__1.cunit = 19;
    cl__1.csta = 0;
    f_clos(&cl__1);
    return 0;
} /* errmsg_ */


/*      block data */


/*  meter space (pts) = xb4mbr = musicsize*facmtr */


/*  From other */


/* Subroutine */ int m1rec1_(lineq, iccount, ibarcnt, ibaroff, nbars, ndxm, 
	lineq_len)
char *lineq;
integer *iccount, *ibarcnt, *ibaroff, *nbars, *ndxm;
ftnlen lineq_len;
{
    /* System generated locals */
    integer i__1, i__2;

    /* Builtin functions */
    integer i_indx(), s_cmp();
    /* Subroutine */ int s_stop();

    /* Local variables */
    extern /* Subroutine */ int errmsg_();
    extern integer ntindex_();


/*  This is called when (a) macro recording is just starting and */
/*  (b) at the start of a new line, if recording is on */

    inbuff_1.lbuf[0] = inbuff_1.lbuf[0];
    if (! commac_1.mrecord) {

/*  Starting the macro */

	c1ommac_1.ip1mac[commac_1.macnum - 1] = inbuff_1.ipbuf - 
		inbuff_1.lbuf[inbuff_1.ilbuf - 2] + *iccount;
	c1ommac_1.il1mac[commac_1.macnum - 1] = inbuff_1.ilbuf - 1;
	c1ommac_1.ic1mac[commac_1.macnum - 1] = *iccount;
	commac_1.mrecord = TRUE_;
    }
    if (*iccount < 128) {
	i__1 = *iccount;
	*ndxm = i_indx(lineq + i__1, "M", 128 - i__1, (ftnlen)1);
	if (*ndxm > 0) {
	    i__1 = *iccount;
	    i__2 = 128 - *iccount;
	    *ndxm = ntindex_(lineq + i__1, "M", &i__2, 128 - i__1, (ftnlen)1);
	}
	if (*ndxm > 0) {

/*  This line ends the macro. */

	    i__1 = *iccount + *ndxm;
	    if (s_cmp(lineq + i__1, " ", *iccount + *ndxm + 1 - i__1, (ftnlen)
		    1) != 0) {
		i__1 = *iccount + *ndxm + 1;
		i__2 = *ibarcnt - *ibaroff + *nbars + 1;
		errmsg_(lineq, &i__1, &i__2, "Improper macro termination!", (
			ftnlen)128, (ftnlen)27);
		s_stop("1", (ftnlen)1);
	    }
	    c1ommac_1.ip2mac[commac_1.macnum - 1] = inbuff_1.ipbuf - 
		    inbuff_1.lbuf[inbuff_1.ilbuf - 2] + *iccount + *ndxm;
	    c1ommac_1.il2mac[commac_1.macnum - 1] = inbuff_1.ilbuf - 1;
	    commac_1.mrecord = FALSE_;
	}
    }
    return 0;
} /* m1rec1_ */

/* Subroutine */ int setmac_(lineq, iccount, ibarcnt, ibaroff, nbars, charq, 
	durq, ivx, nline, lineq_len, charq_len, durq_len)
char *lineq;
integer *iccount, *ibarcnt, *ibaroff, *nbars;
char *charq, *durq;
integer *ivx, *nline;
ftnlen lineq_len;
ftnlen charq_len;
ftnlen durq_len;
{
    /* System generated locals */
    integer i__1, i__2;

    /* Builtin functions */
    integer s_wsle(), e_wsle(), do_lio(), i_indx();
    /* Subroutine */ int s_stop();
    integer i_nint();
    /* Subroutine */ int s_copy();

    /* Local variables */
    static real fnum;
    static integer ndxm;
    extern /* Subroutine */ int m1rec1_(), getbuf_(), errmsg_(), readnum_(), 
	    g1etchar_();

    /* Fortran I/O blocks */
    static cilist io___271 = { 0, 6, 0, 0, 0 };
    static cilist io___272 = { 0, 6, 0, 0, 0 };
    static cilist io___273 = { 0, 6, 0, 0, 0 };
    static cilist io___275 = { 0, 6, 0, 0, 0 };
    static cilist io___276 = { 0, 6, 0, 0, 0 };



/*  Macro action */

    g1etchar_(lineq, iccount, charq, (ftnlen)128, (ftnlen)1);
    if (*(unsigned char *)charq == 'S' && *ivx != 1) {
	s_wsle(&io___271);
	e_wsle();
	s_wsle(&io___272);
	e_wsle();
	s_wsle(&io___273);
	do_lio(&c__9, &c__1, "*********WARNING*********", (ftnlen)25);
	e_wsle();
	i__1 = *ibarcnt - *ibaroff + *nbars + 1;
	errmsg_(lineq, iccount, &i__1, "\"MS...\" only put in parts by scor2\
prt if in voice #1!", (ftnlen)128, (ftnlen)53);
    }
    if (i_indx("RSP ", charq, (ftnlen)4, (ftnlen)1) == 0) {
	i__1 = *ibarcnt - *ibaroff + *nbars + 1;
	errmsg_(lineq, iccount, &i__1, "Illegal character after \"M\" (macro\
)!", (ftnlen)128, (ftnlen)36);
	s_stop("1", (ftnlen)1);
    } else if (*(unsigned char *)charq != ' ') {

/*  Record or playback a macro.  Get the number of the macro. */

	g1etchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	if (i_indx("123456789", durq, (ftnlen)9, (ftnlen)1) == 0) {
	    i__1 = *ibarcnt - *ibaroff + *nbars + 1;
	    errmsg_(lineq, iccount, &i__1, "Must input number after \"MR\"\
,\"MP\", or \"MS\"!", (ftnlen)128, (ftnlen)43);
	    s_stop("1", (ftnlen)1);
	}
	readnum_(lineq, iccount, durq, &fnum, (ftnlen)128, (ftnlen)1);
	commac_1.macnum = i_nint(&fnum);
	if (*(unsigned char *)durq != ' ') {
	    i__1 = *ibarcnt - *ibaroff + *nbars + 1;
	    errmsg_(lineq, iccount, &i__1, "Macro number must be followed by\
 a blank!", (ftnlen)128, (ftnlen)41);
	    s_stop("1", (ftnlen)1);
	}
	if (i_indx("RS", charq, (ftnlen)2, (ftnlen)1) > 0) {

/*  Record or save a macro */

	    if (commac_1.macnum < 1 || commac_1.macnum > 20) {
		i__1 = *iccount - 1;
		i__2 = *ibarcnt - *ibaroff + *nbars + 1;
		errmsg_(lineq, &i__1, &i__2, "Macro number not in range 1-20!"
			, (ftnlen)128, (ftnlen)31);
		s_stop("1", (ftnlen)1);
	    } else if (bit_test(commac_1.macuse,commac_1.macnum)) {
		s_wsle(&io___275);
		e_wsle();
		s_wsle(&io___276);
		do_lio(&c__9, &c__1, "WARNING: Redefining macro # ", (ftnlen)
			28);
		do_lio(&c__3, &c__1, (char *)&commac_1.macnum, (ftnlen)sizeof(
			integer));
		e_wsle();
	    }
	    commac_1.macuse = bit_set(commac_1.macuse,commac_1.macnum);
	    if (*(unsigned char *)charq == 'R') {
		m1rec1_(lineq, iccount, ibarcnt, ibaroff, nbars, &ndxm, (
			ftnlen)128);
	    } else if (*(unsigned char *)charq == 'S') {

/*  Save (Record but don't activate) */

L1:
		m1rec1_(lineq, iccount, ibarcnt, ibaroff, nbars, &ndxm, (
			ftnlen)128);
		if (commac_1.mrecord) {
		    getbuf_(lineq, (ftnlen)128);
		    ++(*nline);
		    *iccount = 0;
		    goto L1;
		}
		*iccount = *iccount + ndxm + 1;
	    }
	} else {

/*  Playback the macro */

	    if (! bit_test(commac_1.macuse,commac_1.macnum)) {
		i__1 = *iccount - 1;
		i__2 = *ibarcnt - *ibaroff + *nbars + 1;
		errmsg_(lineq, &i__1, &i__2, "Cannot play a macro that has n\
ot been recorded!", (ftnlen)128, (ftnlen)47);
		s_stop("1", (ftnlen)1);
	    }
	    commac_1.icchold = *iccount;
	    s_copy(commac_1.lnholdq, lineq, (ftnlen)128, (ftnlen)128);
	    *iccount = 128;
	    commac_1.mplay = TRUE_;
	    c1ommac_1.ilmac = c1ommac_1.il1mac[commac_1.macnum - 1];
	}
    }
    return 0;
} /* setmac_ */

/* Subroutine */ int g1etset_(nv, noinst, mtrnuml, mtrdenl, mtrnmp, mtrdnp, 
	xmtrnum0, newkey, npages, nsyst, musize, bottreb)
integer *nv, *noinst, *mtrnuml, *mtrdenl, *mtrnmp, *mtrdnp;
real *xmtrnum0;
integer *newkey, *npages, *nsyst, *musize;
logical *bottreb;
{
    /* System generated locals */
    address a__1[2], a__2[3];
    integer i__1, i__2[2], i__3[3];
    real r__1;
    char ch__1[3], ch__2[1], ch__3[50];

    /* Builtin functions */
    integer s_cmp(), s_wsle(), do_lio(), e_wsle();
    /* Subroutine */ int s_stop();
    integer i_nint(), s_wsfe(), do_fio(), e_wsfe(), i_indx();
    /* Subroutine */ int s_cat();

    /* Local variables */
    static integer i__, iv;
    extern /* Character */ VOID chax_();
    static char lineq[128];
    static integer lpath, iinst;
    extern doublereal readin_();
    extern /* Subroutine */ int getbuf_(), errmsg_();
    static logical newway;
    static integer iccount;

    /* Fortran I/O blocks */
    static cilist io___280 = { 0, 6, 0, 0, 0 };
    static cilist io___281 = { 0, 6, 0, "(1x,a30,i3)", 0 };
    static cilist io___284 = { 0, 6, 0, 0, 0 };



/*  Get the first line */

    iccount = 0;
    c1omget_1.nline = 1;
L9:
    getbuf_(lineq, (ftnlen)128);
    if (*(unsigned char *)lineq == '%') {
	++c1omget_1.nline;
	goto L9;
    }
    if (s_cmp(lineq, "---", (ftnlen)3, (ftnlen)3) == 0) {

/*  Have TeX input until next line that starts with '---' */

L3:
	++c1omget_1.nline;
	getbuf_(lineq, (ftnlen)128);
	if (inbuff_1.ilbuf > inbuff_1.nlbuf) {
	    goto L1;
	}
	goto L2;
L1:
	s_wsle(&io___280);
	do_lio(&c__9, &c__1, "You did not terminate type 0 TeX input with \"\
---\"", (ftnlen)49);
	e_wsle();
	s_stop("1", (ftnlen)1);
L2:
	if (s_cmp(lineq, "---", (ftnlen)3, (ftnlen)3) != 0) {
	    goto L3;
	}

/*  Force a new line read on first call to readin */

	iccount = 128;
    }

/*  Here, lineq and nline are first non-TeX lines. */

    r__1 = readin_(lineq, &iccount, &c1omget_1.nline, (ftnlen)128);
    *nv = i_nint(&r__1);
    if (*nv > 15) {
	s_wsfe(&io___281);
	do_fio(&c__1, "Number of voices cannot exceed", (ftnlen)30);
	do_fio(&c__1, (char *)&c__15, (ftnlen)sizeof(integer));
	e_wsfe();
	s_stop("1", (ftnlen)1);
    }
    r__1 = readin_(lineq, &iccount, &c1omget_1.nline, (ftnlen)128);
    *noinst = i_nint(&r__1);
    newway = *noinst <= 0;
    if (newway) {
	*noinst = -(*noinst);
    }
    i__1 = *noinst;
    for (iinst = 1; iinst <= i__1; ++iinst) {

/*  Seve # of staves per inst in case later drop some inst's. */

	if (newway) {
	    r__1 = readin_(lineq, &iccount, &c1omget_1.nline, (ftnlen)128);
	    c1omget_1.nsperi[iinst - 1] = i_nint(&r__1);
	} else if (iinst > 1) {
	    c1omget_1.nsperi[iinst - 1] = 1;
	} else {
	    c1omget_1.nsperi[iinst - 1] = *nv - *noinst + 1;
	}
/* L10: */
    }
    r__1 = readin_(lineq, &iccount, &c1omget_1.nline, (ftnlen)128);
    *mtrnuml = i_nint(&r__1);
    r__1 = readin_(lineq, &iccount, &c1omget_1.nline, (ftnlen)128);
    *mtrdenl = i_nint(&r__1);
/* c */
/* c  Kluge!!! */
/* c */
/*      if (mtrdenl .eq. 1) then */
/*        mtrdenl = 2 */
/*        mtrnuml = mtrnuml*2 */
/*      end if */
    r__1 = readin_(lineq, &iccount, &c1omget_1.nline, (ftnlen)128);
    *mtrnmp = i_nint(&r__1);
    r__1 = readin_(lineq, &iccount, &c1omget_1.nline, (ftnlen)128);
    *mtrdnp = i_nint(&r__1);
    *xmtrnum0 = readin_(lineq, &iccount, &c1omget_1.nline, (ftnlen)128);
    r__1 = readin_(lineq, &iccount, &c1omget_1.nline, (ftnlen)128);
    *newkey = i_nint(&r__1);
    r__1 = readin_(lineq, &iccount, &c1omget_1.nline, (ftnlen)128);
    *npages = i_nint(&r__1);
    r__1 = readin_(lineq, &iccount, &c1omget_1.nline, (ftnlen)128);
    *nsyst = i_nint(&r__1);
    r__1 = readin_(lineq, &iccount, &c1omget_1.nline, (ftnlen)128);
    *musize = i_nint(&r__1);
    c1omget_1.fracindent = readin_(lineq, &iccount, &c1omget_1.nline, (ftnlen)
	    128);
    if (*npages > *nsyst) {
	s_wsle(&io___284);
	do_lio(&c__9, &c__1, "Error in input file: npages > nsyst", (ftnlen)
		35);
	e_wsle();
	s_stop("1", (ftnlen)1);
    }

/*  Next noinst non-comment lines are names of instruments. */

    i__1 = abs(*noinst);
    for (i__ = 1; i__ <= i__1; ++i__) {
L5:
	getbuf_(lineq, (ftnlen)128);
	++c1omget_1.nline;
	if (*(unsigned char *)lineq == '%') {
	    goto L5;
	}
/* L4: */
    }

/*  Mext non-comment line has nv clef names */

L6:
    getbuf_(lineq, (ftnlen)128);
    ++c1omget_1.nline;
    if (*(unsigned char *)lineq == '%') {
	goto L6;
    }
    i__1 = *nv;
    for (iv = 1; iv <= i__1; ++iv) {
/*        if (index('brnamstf0123456',lineq(iv:iv)) .eq. 0) then */
	if (i_indx("brnamstf01234567", lineq + (iv - 1), (ftnlen)16, (ftnlen)
		1) == 0) {
	    errmsg_(lineq, &iv, &c__0, "There should be a clef symbol here!", 
		    (ftnlen)128, (ftnlen)35);
	    s_stop("1", (ftnlen)1);
	}
/* L7: */
    }
    i__1 = *nv;
    if (s_cmp(lineq + i__1, " ", *nv + 1 - i__1, (ftnlen)1) != 0) {
	i__1 = *nv + 1;
	errmsg_(lineq, &i__1, &c__0, "There should be a blank here!", (ftnlen)
		128, (ftnlen)29);
	s_stop("1", (ftnlen)1);
    }

/* Set flag if voice 1 is treble, since it affects vertical spacing */

    *bottreb = *(unsigned char *)lineq == 't';

/*  Mext non-comment line has path name */

L8:
    getbuf_(lineq, (ftnlen)128);
    ++c1omget_1.nline;
    if (*(unsigned char *)lineq == '%') {
	goto L8;
    }
    lpath = i_indx(lineq, " ", (ftnlen)128, (ftnlen)1) - 1;
/* Writing concatenation */
    i__2[0] = 2, a__1[0] = "/:";
    chax_(ch__2, (ftnlen)1, &c__92);
    i__2[1] = 1, a__1[1] = ch__2;
    s_cat(ch__1, a__1, i__2, &c__2, (ftnlen)3);
    if (i_indx(ch__1, lineq + (lpath - 1), (ftnlen)3, (ftnlen)1) == 0) {
/* Writing concatenation */
	i__3[0] = 47, a__2[0] = "Last character of pathname is not \"/\",\"\
:\", or \"";
	chax_(ch__2, (ftnlen)1, &c__92);
	i__3[1] = 1, a__2[1] = ch__2;
	i__3[2] = 2, a__2[2] = "\"!";
	s_cat(ch__3, a__2, i__3, &c__3, (ftnlen)50);
	errmsg_(lineq, &lpath, &c__0, ch__3, (ftnlen)128, (ftnlen)50);
	s_stop("1", (ftnlen)1);
    }
    return 0;
} /* g1etset_ */

/* Subroutine */ int checkdyn_(lineq, iccount, ibar, lineq_len)
char *lineq;
integer *iccount, *ibar;
ftnlen lineq_len;
{
    /* System generated locals */
    address a__1[3];
    integer i__1, i__2[3], i__3;
    real r__1;
    char ch__1[4], ch__2[1];
    icilist ici__1;

    /* Builtin functions */
    integer i_indx();
    /* Subroutine */ int s_stop(), s_cat();
    integer s_rsfi(), do_fio(), e_rsfi(), i_nint();

    /* Local variables */
    static integer ipm, iend;
    extern /* Character */ VOID chax_();
    static integer idno;
    static real fnum;
    static char durq[1];
    extern /* Subroutine */ int errmsg_(), readnum_();
    static char dynsymq[4];

    for (iend = *iccount + 2; iend <= 128; ++iend) {
	ipm = i_indx("- +", lineq + (iend - 1), (ftnlen)3, (ftnlen)1);
	if (ipm > 0) {
	    goto L2;
	}
/* L1: */
    }
L2:
    if (iend - *iccount > 5 || iend - *iccount < 2) {
	i__1 = iend - 1;
	errmsg_(lineq, &i__1, ibar, "Wrong length for dynamic mark!", (ftnlen)
		128, (ftnlen)30);
	s_stop("1", (ftnlen)1);
    }
    i__1 = *iccount;
    ici__1.icierr = 0;
    ici__1.iciend = 0;
    ici__1.icirnum = 1;
    ici__1.icirlen = iend - 1 - i__1;
    ici__1.iciunit = lineq + i__1;
/* Writing concatenation */
    i__2[0] = 2, a__1[0] = "(a";
    i__3 = iend + 47 - *iccount;
    chax_(ch__2, (ftnlen)1, &i__3);
    i__2[1] = 1, a__1[1] = ch__2;
    i__2[2] = 1, a__1[2] = ")";
    ici__1.icifmt = (s_cat(ch__1, a__1, i__2, &c__3, (ftnlen)4), ch__1);
    s_rsfi(&ici__1);
    do_fio(&c__1, dynsymq, (ftnlen)4);
    e_rsfi();
    idno = (i_indx("ppppppp pp  p   mp  mf  f   fp  sf  ff  fff ffff", 
	    dynsymq, (ftnlen)48, (ftnlen)4) + 3) / 4;
    if (idno == 0) {
	i__1 = *iccount + 1;
	errmsg_(lineq, &i__1, ibar, "Illegal dynamic mark!", (ftnlen)128, (
		ftnlen)21);
	s_stop("1", (ftnlen)1);
    }
    *iccount = iend;
    if (ipm != 2) {

/*  There is a vertical shift, have "+" or "-" */

	++(*iccount);
	if (i_indx("0123456789", lineq + (*iccount - 1), (ftnlen)10, (ftnlen)
		1) == 0) {
	    errmsg_(lineq, iccount, ibar, "Expected integer here for vertica\
l offset!", (ftnlen)128, (ftnlen)42);
	    s_stop("1", (ftnlen)1);
	}
	readnum_(lineq, iccount, durq, &fnum, (ftnlen)128, (ftnlen)1);
	idno = i_nint(&fnum);
	if (idno > 31) {
	    i__1 = *iccount - 1;
	    errmsg_(lineq, &i__1, ibar, "Vertical offset for dynamic mark mu\
st be (-31,31)!", (ftnlen)128, (ftnlen)50);
	    s_stop("1", (ftnlen)1);
	}
	ipm = i_indx("- +", durq, (ftnlen)3, (ftnlen)1);
	if (ipm == 0) {
	    errmsg_(lineq, iccount, ibar, "Expected \"+\", \"-\", or blank h\
ere!", (ftnlen)128, (ftnlen)33);
	    s_stop("1", (ftnlen)1);
	}
	if (ipm != 2) {

/*  There is a horizontal shift */

	    ++(*iccount);
	    if (i_indx(".0123456789", lineq + (*iccount - 1), (ftnlen)11, (
		    ftnlen)1) == 0) {
		errmsg_(lineq, iccount, ibar, "Expected number here for hori\
zontal offset!", (ftnlen)128, (ftnlen)43);
		s_stop("1", (ftnlen)1);
	    }
	    readnum_(lineq, iccount, durq, &fnum, (ftnlen)128, (ftnlen)1);
	    r__1 = fnum * 10;
	    idno = i_nint(&r__1);
	    if (idno > 63) {
		i__1 = *iccount - 1;
		errmsg_(lineq, &i__1, ibar, "Horizontal offset for dynamic m\
ark must be (-6.3,6.3)!", (ftnlen)128, (ftnlen)54);
		s_stop("1", (ftnlen)1);
	    } else if (*(unsigned char *)durq != ' ') {
		errmsg_(lineq, iccount, ibar, "There should be a blank here!",
			 (ftnlen)128, (ftnlen)29);
		s_stop("1", (ftnlen)1);
	    }
	}

/*  iccount should be on the blank at the end of the entire symbol */

    }
    return 0;
} /* checkdyn_ */

/* Subroutine */ int g1etx_(lineq, iccount, notxtup, shifton, ibar, udsp, 
	wheadpt, lineq_len)
char *lineq;
integer *iccount;
logical *notxtup, *shifton;
integer *ibar;
real *udsp, *wheadpt;
ftnlen lineq_len;
{
    /* System generated locals */
    integer i__1;

    /* Builtin functions */
    integer i_indx();
    /* Subroutine */ int s_stop();

    /* Local variables */
    static real fnum;
    static char dumq[1], charq[1];
    static integer ipbsc, npbsc;
    static logical number;
    extern /* Subroutine */ int errmsg_(), readnum_(), g1etchar_();


/*  Parse "X" commands.  Ignore all "B"; "P" means to ignore whole symbol. */
/*  In scor2prt, must strip out "P", copy only "B" and "P"-type "X"-symbols. */

    number = FALSE_;
    npbsc = 0;
L1:
    g1etchar_(lineq, iccount, charq, (ftnlen)128, (ftnlen)1);
    if (i_indx("PBS:", charq, (ftnlen)4, (ftnlen)1) > 0) {

/*  Continue checking here even if "P". */

	ipbsc = i_indx("PBS:", charq, (ftnlen)4, (ftnlen)1);
	if (bit_test(npbsc,ipbsc)) {
	    errmsg_(lineq, iccount, ibar, "Only one allowed per symbol!", (
		    ftnlen)128, (ftnlen)28);
	    s_stop("1", (ftnlen)1);
	} else if (! (*notxtup) && ipbsc > 2) {
	    errmsg_(lineq, iccount, ibar, "Not allowed in xtuplet!", (ftnlen)
		    128, (ftnlen)23);
	    s_stop("1", (ftnlen)1);
	}
	npbsc = bit_set(npbsc,ipbsc);
	goto L1;
    } else if (i_indx("+-.0123456789", charq, (ftnlen)13, (ftnlen)1) > 0) {
	number = TRUE_;
	if (i_indx("+-", charq, (ftnlen)2, (ftnlen)1) > 0) {
	    g1etchar_(lineq, iccount, dumq, (ftnlen)128, (ftnlen)1);
	    if (i_indx(".0123456789", dumq, (ftnlen)11, (ftnlen)1) == 0) {
		errmsg_(lineq, iccount, ibar, "Expected a number here!", (
			ftnlen)128, (ftnlen)23);
		s_stop("1", (ftnlen)1);
	    }
	}
	readnum_(lineq, iccount, dumq, &fnum, (ftnlen)128, (ftnlen)1);
	if (*(unsigned char *)charq == '-') {
	    fnum = -fnum;
	}
	if (*(unsigned char *)dumq != 'p') {
	    --(*iccount);
	    fnum *= *wheadpt;
	}
	goto L1;
    } else if (*(unsigned char *)charq != ' ') {
	errmsg_(lineq, iccount, ibar, "Not allowed in \"X\" symbol!", (ftnlen)
		128, (ftnlen)26);
	s_stop("1", (ftnlen)1);
    }

/*  Done with parsing.  Other checks */

    if ((6 & npbsc) == 6 || (24 & npbsc) == 24) {
	i__1 = *iccount - 1;
	errmsg_(lineq, &i__1, ibar, "Cannot have both \"P\" and \"B\" or \"\
S\" and \":\"!", (ftnlen)128, (ftnlen)44);
	s_stop("1", (ftnlen)1);
    }
    if (bit_test(npbsc,4)) {
	if (number) {
	    if (*shifton) {
		i__1 = *iccount - 1;
		errmsg_(lineq, &i__1, ibar, "Started a group shift without s\
topping prior one!", (ftnlen)128, (ftnlen)49);
		s_stop("1", (ftnlen)1);
	    } else {
		*shifton = TRUE_;
	    }
	} else {
	    if (! (*shifton)) {
		i__1 = *iccount - 1;
		errmsg_(lineq, &i__1, ibar, "Ended a group shift without sta\
rting one!", (ftnlen)128, (ftnlen)41);
		s_stop("1", (ftnlen)1);
	    } else {
		*shifton = FALSE_;
	    }
	}
    }

/*  P off, S off, c off => normal user-defined space.  Add to udsp (later fsyst) */

    if ((npbsc & 26) == 0) {
	*udsp += fnum;
    }
    if (! number && ! bit_test(npbsc,4)) {
	i__1 = *iccount - 1;
	errmsg_(lineq, &i__1, ibar, "Must have either a number or a colon \
in \"X\" symbol!", (ftnlen)128, (ftnlen)51);
	s_stop("1", (ftnlen)1);
    }
    return 0;
} /* g1etx_ */

/* Subroutine */ int pmxb_(inlast, poevec, ncalls, optimize)
logical *inlast;
real *poevec;
integer *ncalls;
logical *optimize;
{
    /* System generated locals */
    address a__1[12], a__2[4], a__3[3], a__4[2], a__5[5], a__6[2], a__7[8], 
	    a__8[14], a__9[6];
    integer i__1, i__2, i__3[12], i__4[4], i__5, i__6[3], i__7[2], i__8[5], 
	    i__9[2], i__10, i__11[8], i__12[14], i__13[6];
    real r__1, r__2;
    char ch__1[1], ch__2[46], ch__3[19], ch__4[20], ch__5[8], ch__6[107], 
	    ch__7[12], ch__8[14], ch__9[15], ch__10[13], ch__11[9], ch__12[11]
	    , ch__13[22], ch__14[4], ch__15[16], ch__16[33], ch__17[18], 
	    ch__18[82], ch__19[71], ch__20[60], ch__21[45], ch__22[6], ch__23[
	    17], ch__24[70], ch__25[27], ch__26[40], ch__27[69], ch__28[41], 
	    ch__29[44], ch__30[5], ch__31[24], ch__32[76];
    cilist ci__1;
    olist o__1;
    cllist cl__1;
    alist al__1;

    /* Builtin functions */
    integer s_wsle(), e_wsle(), do_lio(), s_wsfe(), do_fio(), e_wsfe(), 
	    s_rsfe(), e_rsfe(), s_rsle(), e_rsle();
    double r_mod();
    integer i_nint(), pow_ii(), f_open();
    /* Subroutine */ int s_cat();
    double r_lg10();
    /* Subroutine */ int s_stop();
    integer i_indx();
    double r_dim();
    integer i_dim();
    /* Subroutine */ int s_copy();
    integer lbit_shift(), f_clos(), f_rew();

    /* Local variables */
    static integer i__, ia, ig, il, ip, it, kv, ip2, icc, ipa, ipi;
    static real esk;
    static integer iiv;
    static real poe, frac;
    static integer ifig, jfig, ndig;
    extern /* Character */ VOID chax_();
    static real hesk[23];
    static integer ioff;
    static char fmtq[24];
    static logical loop;
    static real hpts[23];
    extern doublereal feon_();
    static logical lrpt;
    static real wdpt;
    static logical rrpt;
    static integer icrd, idyn;
    static real tglp1;
    static logical clchb;
    static integer ipage, lbase, lclef, nclef;
    static char clefq[1*15], charq[1];
    static logical clchv[15], slint;
    static integer istop[80];
    static real squez[80], etait, etatc;
    static integer lpath, iauto;
    static real slfac1, etacs1;
    static integer nsyst, ninow, lnote, ipnow;
    static real fsyst;
    static integer isdat;
    extern integer ncmid_();
    static integer ipnew, idynd;
    static real hardb4;
    static integer ibcoff;
    static logical evolta;
    static integer numbms[15], istart[80];
    static logical cwrest[15], svolta;
    static char notexq[79];
    static logical onvolt;
    static real tstart[80];
    static integer nsystp[30];
    static real etatop, etabot;
    static integer inhnoh;
    extern /* Subroutine */ int getset_();
    static integer npages, ibmrep, nhstot, jprntb, nhssys;
    extern /* Subroutine */ int addmidi_();
    static logical istype0;
    extern /* Subroutine */ int outbar_();
    static real ptsndb, ptsndv;
    extern /* Subroutine */ int wsclef_();
    static integer islnow, iplnow, nbarss, lenbeat, ndigbn, indsym, mtrnms, 
	    ibarcnt, iptemp, islide, iudorn;
    extern /* Subroutine */ int topfile_(), clefsym_();
    static real xntrial;
    static logical vshrink;
    extern integer ifnodur_();
    extern /* Subroutine */ int getnote_();
    static real ptsdflt, elsktot;
    static integer isyscnt;
    extern /* Subroutine */ int wgmeter_();
    static integer isystpg;
    static real xnstbot;
    extern /* Subroutine */ int setbits_();
    static integer isdata;
    extern /* Subroutine */ int make1bar_(), make2bar_();
    static integer lvoltxt;
    extern /* Subroutine */ int askfig_();
    static real xnsttop[30], xmtrnum0;
    extern integer igetbits_();
    extern /* Subroutine */ int newvoice_();
    static logical lrptpend;
    extern /* Subroutine */ int setmeter_(), puttitle_();
    static char basenameq[24], pathnameq[40];
    extern /* Subroutine */ int midievent_();
    static real xintstaff[30];

    /* Fortran I/O blocks */
    static cilist io___300 = { 0, 6, 0, 0, 0 };
    static cilist io___301 = { 0, 6, 0, 0, 0 };
    static cilist io___302 = { 0, 6, 0, 0, 0 };
    static cilist io___303 = { 0, 15, 0, "(a)", 0 };
    static cilist io___305 = { 0, 12, 0, "(a)", 0 };
    static cilist io___307 = { 0, 12, 0, 0, 0 };
    static cilist io___309 = { 0, 12, 0, 0, 0 };
    static cilist io___325 = { 0, 6, 0, 0, 0 };
    static cilist io___326 = { 0, 12, 0, 0, 0 };
    static cilist io___333 = { 0, 13, 0, 0, 0 };
    static cilist io___335 = { 0, 14, 0, "(a)", 0 };
    static cilist io___339 = { 0, 11, 0, "(a)", 0 };
    static cilist io___342 = { 0, 11, 0, "(a)", 0 };
    static cilist io___355 = { 0, 6, 0, "(/,a19,i4,a1,i4)", 0 };
    static cilist io___356 = { 0, 15, 0, "(/,a19,i4,a1,i4)", 0 };
    static cilist io___367 = { 0, 11, 0, "(a)", 0 };
    static cilist io___376 = { 0, 11, 0, "(a)", 0 };
    static cilist io___377 = { 0, 11, 0, "(a)", 0 };
    static cilist io___378 = { 0, 12, 0, 0, 0 };
    static cilist io___380 = { 0, 6, 0, 0, 0 };
    static cilist io___381 = { 0, 6, 0, 0, 0 };
    static cilist io___384 = { 0, 11, 0, "(a)", 0 };
    static cilist io___385 = { 0, 11, 0, "(a)", 0 };
    static cilist io___386 = { 0, 11, 0, "(a)", 0 };
    static cilist io___387 = { 0, 11, 0, "(a)", 0 };
    static cilist io___388 = { 0, 11, 0, "(a)", 0 };
    static cilist io___391 = { 0, 11, 0, "(a)", 0 };
    static cilist io___392 = { 0, 11, 0, "(a)", 0 };
    static cilist io___394 = { 0, 11, 0, "(a)", 0 };
    static cilist io___395 = { 0, 11, 0, "(a)", 0 };
    static cilist io___404 = { 0, 11, 0, "(a)", 0 };
    static cilist io___405 = { 0, 12, 0, 0, 0 };
    static cilist io___407 = { 0, 14, 0, "(a9,i2,a10)", 0 };
    static cilist io___410 = { 0, 11, 0, fmtq, 0 };
    static cilist io___412 = { 0, 6, 0, 0, 0 };
    static cilist io___413 = { 0, 6, 0, 0, 0 };
    static cilist io___414 = { 0, 11, 0, "(a)", 0 };
    static cilist io___415 = { 0, 11, 0, "(a12,2i1,a1)", 0 };
    static cilist io___416 = { 0, 11, 0, "(a13,i2,a1,i1,a1)", 0 };
    static cilist io___417 = { 0, 11, 0, "(a18,i1,a2)", 0 };
    static cilist io___418 = { 0, 11, 0, "(a18,i2,a2)", 0 };
    static cilist io___420 = { 0, 11, 0, "(a11,i1,a2)", 0 };
    static cilist io___421 = { 0, 11, 0, "(a11,i2,a2)", 0 };
    static cilist io___422 = { 0, 11, 0, "(a11,i3,a2)", 0 };
    static cilist io___423 = { 0, 11, 0, "(a)", 0 };
    static cilist io___425 = { 0, 11, 0, "(a)", 0 };
    static cilist io___426 = { 0, 11, 0, "(a)", 0 };
    static cilist io___427 = { 0, 11, 0, "(a)", 0 };
    static cilist io___428 = { 0, 11, 0, "(a)", 0 };
    static cilist io___429 = { 0, 11, 0, "(a)", 0 };
    static cilist io___431 = { 0, 11, 0, fmtq, 0 };
    static cilist io___432 = { 0, 11, 0, "(a)", 0 };
    static cilist io___433 = { 0, 11, 0, fmtq, 0 };
    static cilist io___434 = { 0, 11, 0, "(a)", 0 };
    static cilist io___435 = { 0, 11, 0, "(a)", 0 };
    static cilist io___436 = { 0, 11, 0, "(a)", 0 };
    static cilist io___437 = { 0, 11, 0, "(a)", 0 };
    static cilist io___438 = { 0, 11, 0, "(a)", 0 };
    static cilist io___439 = { 0, 11, 0, "(a)", 0 };
    static cilist io___440 = { 0, 11, 0, "(a)", 0 };
    static cilist io___441 = { 0, 11, 0, "(a)", 0 };
    static cilist io___442 = { 0, 11, 0, "(a)", 0 };
    static cilist io___443 = { 0, 11, 0, "(a)", 0 };
    static cilist io___444 = { 0, 11, 0, "(a)", 0 };
    static cilist io___445 = { 0, 11, 0, "(a)", 0 };
    static cilist io___446 = { 0, 11, 0, "(a)", 0 };
    static cilist io___447 = { 0, 11, 0, "(a16,i1,a14)", 0 };
    static cilist io___448 = { 0, 11, 0, "(a)", 0 };
    static cilist io___449 = { 0, 12, 1, 0, 0 };
    static cilist io___452 = { 0, 11, 0, "(a)", 0 };
    static cilist io___453 = { 0, 11, 0, "(a)", 0 };
    static cilist io___454 = { 0, 11, 0, "(a)", 0 };
    static cilist io___455 = { 0, 11, 0, "(a)", 0 };
    static cilist io___456 = { 0, 11, 0, "(a,2i1,a)", 0 };
    static cilist io___457 = { 0, 11, 0, "(a)", 0 };
    static cilist io___458 = { 0, 11, 0, "(a)", 0 };
    static cilist io___478 = { 0, 11, 0, "(a11,f5.1,a4)", 0 };
    static cilist io___479 = { 0, 11, 0, "(a)", 0 };
    static cilist io___480 = { 0, 11, 0, "(a)", 0 };
    static cilist io___481 = { 0, 11, 0, "(a)", 0 };
    static cilist io___482 = { 0, 11, 0, "(a)", 0 };
    static cilist io___483 = { 0, 6, 0, 0, 0 };
    static cilist io___484 = { 0, 11, 0, "(a)", 0 };
    static cilist io___485 = { 0, 11, 0, "(a)", 0 };
    static cilist io___486 = { 0, 11, 0, fmtq, 0 };
    static cilist io___487 = { 0, 11, 0, "(a)", 0 };
    static cilist io___488 = { 0, 11, 0, "(a)", 0 };
    static cilist io___489 = { 0, 11, 0, "(a)", 0 };
    static cilist io___490 = { 0, 14, 0, "(a9,i2,a10)", 0 };
    static cilist io___491 = { 0, 6, 0, 0, 0 };
    static cilist io___492 = { 0, 6, 0, 0, 0 };
    static cilist io___493 = { 0, 6, 0, 0, 0 };
    static cilist io___494 = { 0, 15, 0, "(/,a)", 0 };
    static cilist io___495 = { 0, 15, 0, "(a)", 0 };


/* ccccccccccccccccccccccccc */
/* c */
/* c To Do */
/* c */
/* c  Resolve disagreement in final poe for 1st system, compared with *.mx2 */
/* c  Shift slurs on right- or left-shifted main notes (2/7/99) */
/* c  Various end-of-input-block repeat problems (ick142.pmx). */
/* c  Force multiplicity for un-beamed xtups. */
/* c  Clef change at end of piece */
/* c  Global "A" option to maximize "X" at a given time tick. */
/* c  Tighten test for end-of-bar hardspace, flgndv(ivx) due to right-shifted */
/* c       note.  See trubl18.pmx */
/* c  Tab character as space. */
/* c  Clef interference with second line of music. */
/* c  Add space for interferences between *different* lines of music? */
/* c  Shift arpeggios, both automatic and manual. */
/* c  Different musicsize for different instruments. */
/* c  Spacing checks for accid's on left-shifted chord notes */
/* c  Spacing checks for double dots */
/* c  Allow forced line breaks w/o setting nsyst. */
/* c  Cresc-Decresc. (Enhance MusiXTeX first?) */
/* c  Dynamic Marks. */
/* c  Bug with Voltas at line end (MusiXTeX problem?). */
/* c  Subtle bug w/ slur hgt over line brk, see trubl15.pmx */
/* c  Stem-end slurs. */
/* c  Allow units in indentation. */
/* c  Make inline TeX more context sensitive. */
/* c  Werner's 4/2/98 problem with "o?" */
/* c  Scor2prt converts e.g. "r0+0" into "r0 0", which seems to be wrong. */
/* c    converts e.g. "r2db" into "r2d", which might be wrong. */
/* c  Werner's generalsignature problem with Key change and new transposition. */
/* c    (wibug8.pmx) */
/* c  Unequal xtuplets */
/* c  Print both sets of bar #'s in tex file. */
/* c  Make barlines invisible \def\xbar{\empty} , fix fbar. */
/* c  Auto-tie slurs  'At' */
/* c  Forced line break anywhere (e.g. at a mid-bar repeat). */
/* c  Clef change at very start of file. */
/* c  Tighten test for M as macro terminator. */
/* c  Fix title so not separate limit on author length + composer length. */
/* c  Arpeggios in xtups. */
/* c */
/* c mx10b */
/* c  Option for instrument name at top center. Last item in P command: */
/* c    P[n]c         text is instrument name (use in parts) */
/* c    P[n]cstuff    text is stuff (up to 1st blank) */
/* c    P[n]c"stuff with spaces"   text is stuff with spaces */
/* c */
/* c Post version 1.43 */
/* c  Reduced space rqmt for multiplicity-0 graces (no flag) */
/* c  Removed last sepsym in centered whole-bar rests, fixes volta height bug. */
/* c */
/* c Version 1.43 */
/* c  Fix spacing for end-of-line signature change. */
/* c  Adjust left-shift of grace group for shifted accidentals. */
/* c  Put in extra space for left-shifted accidentals. */
/* c  Fix bug with dot-shift before accid-shift on chord note. */
/* c  Space-check for right-shifted main notes. */
/* c  Enable forcing stem direction of single notes in non-beamed xtups. */
/* c  Disallow clef change after last note before end of input block (pmxa) */
/* c  Print meter change before page break */
/* c  increase length of strings for \titles macro */
/* c version 1.42 */
/* c  Loosen up input syntax for "X" commands.  Subroutine getx() */
/* c  "B" and "P" in "X" commands */
/* c mx09b */
/* c  Allow multiple rests at start of xtup */
/* c  Add 64th rest */
/* c  Fix xtup numbers over rests. (subroutine levrn) */
/* c  Initialize notcrd=.false. every gulp. Avoids undefined state with e.g. */
/* c    c za / ( c a ... */
/* c  Allow double dots to be shifted. */
/* c  Fix spacing with double dotted notes; permit splitting small note. */
/* c  Fix \dotted printout so it works with old compiler */
/* c mx08b */
/* c  Automatic spaces if needed for shifted accidentals. */
/* c  Some Dynamics */
/* c  Increase accid. horiz. shift resolution to .o5 (use one more bit in nacc) */
/* c version 1.41 */
/* c  Allow ":" as last char of path name */
/* c  Dotted slurs "sb" */
/* c  Continue bar numbering at movement break "L[integer]Mc" */
/* c mx07b */
/* c  Whole-bar rests with double lines of music.  Fixed all options ? */
/* c  Shift accidentals, either [+|-][integer][+|-][number] or [<|>][number]. */
/* c  Option to suppress centering full-bar rests. "o" */
/* c mx06b */
/* c  Shift accid on left-shifted chord note. */
/* c  Rest as first note of xtup. */
/* c  Wrong slopes with small widths.  Scale slfac1 by widthpt_default/widthpt */
/* c  Allow Rb for single bar at movemnet break or end of piece. (islur(25)) */
/* c  Change # of inst at a movement break.  noinst is total # and must be used */
/* c    in 1st movement.  ninow is current.  nspern(1,...,ninow) is current */
/* c    staves/inst, nsperi(1,...,noinst) is original.  rename tells whether to */
/* c    reprint names in parindent at a movement break.  Default is .false. */
/* c    unless ninow changes, then .true.  But can force either with r+/- as */
/* c    option in 'M' */
/* c mx04b */
/* c  Double-dotted notes, separate+beamed, main+chord, still no extra space. */
/* c  ???  Don't shift slur ends on whole notes. */
/* c  (pmxa) Write line number of error in pmxaerr.dat */
/* c mx02b */
/* c  Admit "RD" before "/" (search for "rptfq2:" ) */
/* c  In doslur, for multi-line staves, single notes, check forced stem dir'n */
/* c    before setting stemup (used to set horiz offset). */
/* cccccccccccccccccccccccccccccc */

/*  FYI /all/ differs in appearance in function ncmid */


/*  islur is used as a bank of switches */

/*  bit  meaning */
/*  0     slur activity on this note */
/*  1     t-slur here. */
/*  2     force 0-slope beam starting on this note */
/*  3     Double dotted note! */
/*  4     grace before main note */
/*  5     left repeat */
/*  6     right repeat */
/*  7     start Volta */
/*  8     doublebar */
/*  9     end Volta */
/*  10    on=>endvoltabox */
/*  11    on=>clefchange */
/*  12-14 0=>treble, ... , 6=>bass */
/*  15    on=> start new block for clef change (maybe diff. voice) */
/*  16    literal TeX string */
/*  17    1=up, 0=down stem for single note (override) See bit 30! */
/*  18    if on, prohibit beaming */
/*  19    if on, full bar rest as pause */
/*  20    Beam multiplicity down-up */
/*  21    Forced multiplicity for any beam including xtups */
/*  22-24 Value of forced multiplicity */
/*  25    single barline at movement break */
/*  26    doubleBAR (see bits 5,6,8) */
/*  27-28 Forced beam fine-tune height (1 to 3) */
/*  29    Blank rest */
/*  30    If on, get stem dir'n from bit 17 */
/*  31    If on, suppress printing number with xtuplet starting here */


/*  Bit values for 2nd bank of switches, ipl */

/*  0-7   Location in list [0,200] */
/*  8     \loff */
/*  9     \roff */
/*  10    chord present? */
/*  11-16 Forced beam height adjustment (-30 to +30) */
/*  17-22 Forced beam slope adjustment (-30 to +30) */
/*  23-26 Slur index for Way-after grace.  Inserted when slur is started. */
/*  27      Unused? */
/*  28    key change: only in voice 1 */
/*  29    Grace after main note. (Type A) */
/*  30    In forced beam.  Signals need to check beam heights */
/*  31    Grace way after main note. (stretch to next note, type W) */

/*  Set up iornq as bitmap. */
/*  0     Ornament "(".  Was user-defined horizontal slur shift on this note */
/*               until 9/24/97; changed that to irest(21) */
/*  1-13  stmgx+Tupf._) */
/*  14    Down fermata, was F */
/*  15    Trill w/o "tr", was U */
/*  16-18 Editorial s,f,n */
/*  19-20 >^ */
/*  21    "?" for editorial accid, w/ or w/o s,f,n */
/*  22    Set if ihornb governs ornament height.  Same in icrdorn. */
/*  23    Set in getorn if ANY note at time of this main note has ornament. */
/*             This is ONLY used in beamstrt to signal whether to do more */
/*             tests for whether ihornb is needed.  (ihornb is only needed */
/*             if nonchord+upbm, chord+upbm+top_note, chord+dnbm+bot_note) */
/*  24    Slur on after or way-after grace.  Use as signal to START slur. */
/*  25    Tweak orn ht. Same in icrdorn for chord note */
/*  26    Insert user-defined space before this note (was 22) */
/*  27    Arpeggio stop or start (if 2 at same time), or all-in-this-chord */
/*  28-31   Not used? */

/*   And now irest is also a set of switches */

/*  0        rest=1, no rest = 0 */
/*  1        There will be a vertical shift for number of this xtup */
/*  2-6      Height shift, 1 => -15, 31 => +15  Indicate by +/- [n] after 'n' */
/*  7        There is a horizontal shift for xtup number */
/*  9-13     Horiz shift, 1=>-1.5, ... , 31=>+1.5 */
/*  14       Flip up/down-ness of xtup number */
/*  15       Single-voice, single note shift  X(...)[p]S */
/*  16       Start single-voice, multinote shift with this note X(...)[p]: */
/*  17       End single-voice, multinote shift after this note. Enter symbol */
/*              after note. X: */
/*  18       User-defined hardspace after last note of bar, *after* this note. */
/*              Value still stored in udoff(ivx,nudoff(ivx)), not with other */
/*              hardspaces in udsp, to avoid confusion with time checks. */
/*  19       Move the dot.  Data stored in ndotmv,updot,rtdot */
/*  20       Set if right-shifted main or chord note here.  Use for space checks. */
/*  21       User-defined hardspace in xtup */
/*  22       User-defined slur shift horizontal slur shift. */
/*  23       Set on last note before staff-jumping a beam. */
/*  24       Set on first note after staff-jumping a beam */
/*  25       Suppress rest centering. "ro" */
/*  26       Dynamic on this note */
/*  27       Set if left-shifted main or chord note here.  Use for space checks. */
/*  28       Set if xtup starts on this note. */
/*  29       Set on lowest-voice note at same time as 1st note after jump-beam. */

/*  nacc:  Accidental stuff */

/*  0-1      0=no accid, 1=fl, 2=sh, 3=na */
/*  2        double */
/*  3        big */
/*  4-9      vertshift-32 */
/*  10-16    20*(horiz. shift + 3.2) */

/*  isdat1: Slur information */

/* c  0-2      iv */
/*  13-17    iv */
/*  3-10     ip */
/*  11       start/stop switch */
/*  12       kv-1 */
/*  19-25    ichar(code$) */
/*  26       force direction? */
/*  27       forced dir'n = up if on, set in sslur; also */
/*           final direction, set in doslur when beam is started, used on term. */
/*  28-31    ndxslur, set in doslur when beam is started, used on term. */

/*  isdat2 */

/*  0        Chord switch.  Not set on main note. */
/*  1-2      left/right notehead shift.  Set only for chord note. */
/*  3        tie positioning */
/*  4        dotted slur */
/*  6-11     voff1 1-63  =>  -31...+31 */
/*  12-18    hoff1 1-127 => -6.3...+6.3 */
/*  19-25    nolev */

/* ccccccccccccccccccccccccccccccc */
    /* Parameter adjustments */
    --poevec;

    /* Function Body */
    if (! (*optimize)) {
	s_wsle(&io___300);
	e_wsle();
	s_wsle(&io___301);
	do_lio(&c__9, &c__1, "Starting second PMX pass", (ftnlen)24);
	e_wsle();
	s_wsle(&io___302);
	e_wsle();
	s_wsfe(&io___303);
	do_fio(&c__1, "Starting second PMX pass", (ftnlen)24);
	e_wsfe();
    }
    ++(*ncalls);
    comlast_1.islast = *inlast;
    commac_1.macuse = 0;
    isyscnt = 0;
    all_1.stemmax = (float)8.2;
    all_1.stemmin = (float)3.9;
    all_1.stemlen = (float)6.;
    chax_(ch__1, (ftnlen)1, &c__92);
    *(unsigned char *)all_1.sq = *(unsigned char *)&ch__1[0];
    combc_1.bcspec = TRUE_;
    comas3_1.topmods = FALSE_;
    s_rsfe(&io___305);
    do_fio(&c__1, basenameq, (ftnlen)24);
    e_rsfe();
    s_rsle(&io___307);
    do_lio(&c__3, &c__1, (char *)&lbase, (ftnlen)sizeof(integer));
    e_rsle();
    s_rsle(&io___309);
    do_lio(&c__4, &c__1, (char *)&comask_1.fbar, (ftnlen)sizeof(real));
    do_lio(&c__4, &c__1, (char *)&comask_1.wheadpt, (ftnlen)sizeof(real));
    do_lio(&c__4, &c__1, (char *)&etait, (ftnlen)sizeof(real));
    do_lio(&c__4, &c__1, (char *)&etatc, (ftnlen)sizeof(real));
    do_lio(&c__4, &c__1, (char *)&etacs1, (ftnlen)sizeof(real));
    do_lio(&c__4, &c__1, (char *)&etatop, (ftnlen)sizeof(real));
    do_lio(&c__4, &c__1, (char *)&etabot, (ftnlen)sizeof(real));
    do_lio(&c__3, &c__1, (char *)&cominbot_1.inbothd, (ftnlen)sizeof(integer))
	    ;
    do_lio(&c__3, &c__1, (char *)&inhnoh, (ftnlen)sizeof(integer));
    do_lio(&c__3, &c__1, (char *)&comtop_1.isig, (ftnlen)sizeof(integer));
    e_rsle();
    inbuff_1.ilbuf = 1;
    inbuff_1.ipbuf = 0;
    getset_(&all_1.nv, &comnotes_1.noinst, &all_1.mtrnuml, &all_1.mtrdenl, &
	    all_1.mtrnmp, &all_1.mtrdnp, &xmtrnum0, &npages, &nsyst, &
	    all_1.musicsize, &comtop_1.fracindent, &istype0, comtop_1.inameq, 
	    clefq, all_1.sepsymq, pathnameq, &lpath, &comtop_1.isig0, (ftnlen)
	    79, (ftnlen)1, (ftnlen)1, (ftnlen)40);
    if (commidi_1.ismidi) {

/*  Initial key signature and meter for pickup bar */

	midievent_("k", &comtop_1.isig, &c__0, (ftnlen)1);
	if (xmtrnum0 > comtol_1.tol) {

/*  We have a pickup.  Some tricky stuff to get a meter: */

	    xntrial = xmtrnum0;
	    for (ip2 = 0; ip2 <= 5; ++ip2) {
		if ((r__1 = r_mod(&xntrial, &c_b1232), dabs(r__1)) < 
			comtol_1.tol) {
		    goto L6;
		}
		xntrial *= 2;
/* L5: */
	    }
	    s_wsle(&io___325);
	    do_lio(&c__9, &c__1, "Problem finding meter for pickup bar", (
		    ftnlen)36);
	    e_wsle();
	    xntrial = (float)1.;
	    ip2 = 0;
L6:
	    i__1 = i_nint(&xntrial);
	    i__2 = pow_ii(&c__2, &ip2) * all_1.mtrdenl;
	    midievent_("m", &i__1, &i__2, (ftnlen)1);
	} else {

/*  No pickup, enter the starting meter */

	    midievent_("m", &all_1.mtrnuml, &all_1.mtrdenl, (ftnlen)1);
	}
    }

/*  Set musicsize from value passed in common, due to possible reset by S[n]m16 */

    all_1.musicsize = commus_1.musize;
    s_rsle(&io___326);
    do_lio(&c__3, &c__1, (char *)&npages, (ftnlen)sizeof(integer));
    do_lio(&c__4, &c__1, (char *)&comtop_1.widthpt, (ftnlen)sizeof(real));
    do_lio(&c__4, &c__1, (char *)&comtop_1.height, (ftnlen)sizeof(real));
    do_lio(&c__3, &c__1, (char *)&nsyst, (ftnlen)sizeof(integer));
    i__1 = npages;
    for (ipa = 1; ipa <= i__1; ++ipa) {
	do_lio(&c__3, &c__1, (char *)&nsystp[ipa - 1], (ftnlen)sizeof(integer)
		);
	do_lio(&c__4, &c__1, (char *)&xnsttop[ipa - 1], (ftnlen)sizeof(real));
	do_lio(&c__4, &c__1, (char *)&xintstaff[ipa - 1], (ftnlen)sizeof(real)
		);
    }
    do_lio(&c__3, &c__1, (char *)&iauto, (ftnlen)sizeof(integer));
    e_rsle();

/*  If default width ever changes, must adjust this stmt. */

    slfac1 = (float)2.98156 / comtop_1.widthpt;
    all_1.figbass = FALSE_;
    s_rsle(&io___333);
    do_lio(&c__3, &c__1, (char *)&ifig, (ftnlen)sizeof(integer));
    e_rsle();
    if (ifig == 1) {
	all_1.figbass = TRUE_;
	o__1.oerr = 0;
	o__1.ounit = 14;
	o__1.ofnm = 0;
	o__1.orl = 0;
	o__1.osta = "SCRATCH";
	o__1.oacc = 0;
	o__1.ofm = 0;
	o__1.oblnk = 0;
	f_open(&o__1);
	s_wsfe(&io___335);
/* Writing concatenation */
	i__3[0] = 1, a__1[0] = all_1.sq;
	i__3[1] = 3, a__1[1] = "def";
	i__3[2] = 1, a__1[2] = all_1.sq;
	i__3[3] = 8, a__1[3] = "fixdrop{";
	i__3[4] = 1, a__1[4] = all_1.sq;
	i__3[5] = 7, a__1[5] = "advance";
	i__3[6] = 1, a__1[6] = all_1.sq;
	i__3[7] = 10, a__1[7] = "sysno by 1";
	i__3[8] = 1, a__1[8] = all_1.sq;
	i__3[9] = 6, a__1[9] = "ifcase";
	i__3[10] = 1, a__1[10] = all_1.sq;
	i__3[11] = 6, a__1[11] = "sysno%";
	s_cat(ch__2, a__1, i__3, &c__12, (ftnlen)46);
	do_fio(&c__1, ch__2, (ftnlen)46);
	e_wsfe();
    }
    comget_1.lastchar = FALSE_;
    ibcoff = 0;
    if (xmtrnum0 > (float)0.) {
	ibcoff = -1;
    }
    o__1.oerr = 0;
    o__1.ounit = 11;
    o__1.ofnm = 0;
    o__1.orl = 0;
    o__1.osta = "SCRATCH";
    o__1.oacc = 0;
    o__1.ofm = 0;
    o__1.oblnk = 0;
    f_open(&o__1);
    topfile_(basenameq, &lbase, &all_1.nv, clefq, &comnotes_1.noinst, &
	    all_1.musicsize, xintstaff, &all_1.mtrnmp, &all_1.mtrdnp, &
	    vshrink, &comask_1.fbar, (ftnlen)24, (ftnlen)1);

/*  ninow is working value of # of instruments.  noinst is max #, and # at start. */

    ninow = comnotes_1.noinst;

/*  Save original printed meter in case movement breaks */

    comget_1.movnmp = all_1.mtrnmp;
    comget_1.movdnp = all_1.mtrdnp;

/*  vshrink for the first page is calculated in topfile, */
/*  and if true set interstaff=10.  vshrink affects Titles. */
/*  Must also save vshrink for page ending. */

    if (comlast_1.islast && all_1.figbass && all_1.musicsize == 16) {
	s_wsfe(&io___339);
/* Writing concatenation */
	i__4[0] = 1, a__2[0] = all_1.sq;
	i__4[1] = 4, a__2[1] = "font";
	i__4[2] = 1, a__2[2] = all_1.sq;
	i__4[3] = 13, a__2[3] = "figfont=cmr8%";
	s_cat(ch__3, a__2, i__4, &c__4, (ftnlen)19);
	do_fio(&c__1, ch__3, (ftnlen)19);
	e_wsfe();
    }
    lenbeat = ifnodur_(&all_1.mtrdenl, "x", (ftnlen)1);
    if (all_1.mtrdenl == 2) {
	lenbeat = 16;
    }
    all_1.lenb1 = all_1.mtrnuml * lenbeat;
    if (all_1.mtrdenl == 2) {
	all_1.lenb1 <<= 1;
    }
    setmeter_(&all_1.mtrnuml, &all_1.mtrdenl, &combeam_1.ibmtyp, &ibmrep);
    r__1 = xmtrnum0 * lenbeat;
    all_1.lenb0 = i_nint(&r__1);
    if (all_1.mtrdenl == 2) {
	all_1.lenb0 <<= 1;
    }
    if (all_1.lenb0 != 0) {
	if (comlast_1.islast) {
	    s_wsfe(&io___342);
/* Writing concatenation */
	    i__4[0] = 1, a__2[0] = all_1.sq;
	    i__4[1] = 7, a__2[1] = "advance";
	    i__4[2] = 1, a__2[2] = all_1.sq;
	    i__4[3] = 11, a__2[3] = "barno by -1";
	    s_cat(ch__4, a__2, i__4, &c__4, (ftnlen)20);
	    do_fio(&c__1, ch__4, (ftnlen)20);
	    e_wsfe();
	}
	all_1.lenbar = all_1.lenb0;
    } else {
	all_1.lenbar = all_1.lenb1;
    }

/*  Initialize full-program variables */

    comask_1.fixednew = (float)0.;
    comask_1.scaldold = (float)0.;
    comget_1.fintstf = (float)-1.;
    comget_1.gintstf = (float)1.;
    comas2_1.nasksys = 0;
    ibarcnt = 0;
    all_1.iline = 0;
    comget_1.movbrk = 0;
    isystpg = 0;
    ipage = 1;
    all_1.iccount = 128;
    comas3_1.iask = 0;
    nhstot = 0;
    comnsp_1.nb = 1;
    if (! (*optimize)) {
	jprntb = 81;
    }
    comtop_1.idsig = 0;

/*  Next 5 are raise-barno parameters.  irzbnd is integer part of default level. */

    comsln_1.irzbnd = 3;
    if (comtop_1.isig == 3 && *(unsigned char *)&clefq[all_1.nv - 1] == 't') {
	comsln_1.irzbnd = 4;
    }
    comsln_1.is1n1 = 0;
    comsln_1.isnx = 0;
    compoi_1.ispoi = FALSE_;
    slint = FALSE_;
    lrptpend = FALSE_;
    comget_1.rptnd1 = FALSE_;
    *(unsigned char *)comget_1.rptfq2 = 'E';
    comget_1.rptprev = FALSE_;
    onvolt = FALSE_;
    comnsp_1.flgndb = FALSE_;
    comget_1.fbon = FALSE_;
    comnotes_1.shifton = FALSE_;
    comget_1.ornrpt = FALSE_;
    comnotes_1.setis = FALSE_;
/*      notcrd = .true. */
    comarp_1.lowdot = FALSE_;
    comnvi_1.rename = FALSE_;
    comnotes_1.nobar1 = FALSE_;

/*  ixrest = 1 or 2 if xtup has started with a rest */

    for (commvl_1.ivx = 1; commvl_1.ivx <= 15; ++commvl_1.ivx) {
	strtmid_1.ixrest[commvl_1.ivx - 1] = 0;
/* L1: */
    }
    comnotes_1.npreslur = 0;
    nhssys = 0;
    comslur_1.listslur = 0;
    for (i__ = 1; i__ <= 101; ++i__) {
	all_1.isdat1[i__ - 1] = 0;
	all_1.isdat2[i__ - 1] = 0;
/* L31: */
    }
    all_1.nsdat = 0;

/*  Initialize for loop over gulps */

    all_1.firstgulp = TRUE_;

/*  Start a gulp */

L30:
    loop = TRUE_;
    comnotes_1.notcrd = TRUE_;
    all_1.nbars = 0;
    comfig_1.nfigs = 0;
    comgrace_1.ngrace = 0;
    comtrill_1.ntrill = 0;
    comtrill_1.ncrd = 0;
    comtrill_1.nudorn = 0;
    comgrace_1.nlit = 0;
    comgrace_1.nvolt = 0;
    comgrace_1.ibarmbr = 0;
    comudsp_1.nudsp = 0;
    comdyn_1.ndyn = 0;

/*  Now initialize up to nv.  Do it in getnote as r'qd for 2nd voices per syst. */
/*  and also if nv increases in an 'M' directive. */

    i__1 = all_1.nv;
    for (all_1.iv = 1; all_1.iv <= i__1; ++all_1.iv) {
	newvoice_(&all_1.iv, clefq + (all_1.iv - 1), &c_false, (ftnlen)1);
/* L4: */
    }

/*  Check if endsymbol was set earlier */

    if (comget_1.rptnd1) {
	comget_1.rptnd1 = FALSE_;
	*(unsigned char *)comget_1.rptfq2 = *(unsigned char *)comget_1.rptfq1;
    } else {

/*  Only use if movbrk>0, to signal default ('RD') */

	*(unsigned char *)comget_1.rptfq2 = 'E';
    }
    all_1.iv = 1;
    commvl_1.ivx = 1;
L2:
    if (loop) {

/*  Within this loop, nv voices are filled up for the duration of the block. */
/*  On exit (loop=.false.) the following are set: nnl(nv),itsofar(nv) */
/*  nolev(nv,nnl(nv)),nodur(..),accq(..),irest(..). */
/*  nbars is for this input block. */
/*  Only at the beginning of an input block will there be a possible mtr change, */
/*  signalled by a nonzero mtrnuml. (which will be re-zeroed right after change) */

	getnote_(&loop);
	if (comget_1.lastchar) {
	    goto L40;
	}
	goto L2;
    }

/*  Finished an input block (gulp). */

    if (commidi_1.ismidi) {

/*  Put rests into midi array for 2nd lines that were not used in this gulp. */

	i__1 = all_1.nv;
	for (all_1.iv = 1; all_1.iv <= i__1; ++all_1.iv) {
	    if (commidi_1.twoline[all_1.iv - 1] && commvl_1.nvmx[all_1.iv - 1]
		     == 1) {
		if (all_1.firstgulp && all_1.lenb0 != 0) {
		    r__1 = (all_1.nbars - (float)1.) * all_1.lenbar + 
			    all_1.lenb0;
		    addmidi_(&commidi_1.midchan[all_1.iv + 14], &c__0, &c__0, 
			    &c__0, &r__1, &c_true, &c_false);
		} else {
		    r__1 = all_1.nbars * (float)1. * all_1.lenbar;
		    addmidi_(&commidi_1.midchan[all_1.iv + 14], &c__0, &c__0, 
			    &c__0, &r__1, &c_true, &c_false);
		}
	    }
/* L60: */
	}
    }
    comgrace_1.nvolt = 0;
    for (all_1.iv = 1; all_1.iv <= 15; ++all_1.iv) {
	comudsp_1.nudoff[all_1.iv - 1] = 0;
	comcc_1.ndotmv[all_1.iv - 1] = 0;
/* L28: */
    }

/*  Put in titles at top of p.1.  Must wait until now to have read title info. */

    if (ibarcnt == 0) {
	puttitle_(&inhnoh, &xnsttop[ipage - 1], &etatop, all_1.sq, &etait, &
		etatc, &etacs1, &all_1.nv, &vshrink, all_1.sepsymq, (ftnlen)1,
		 (ftnlen)1);
    }
    i__1 = all_1.nbars;
    for (all_1.ibar = 1; all_1.ibar <= i__1; ++all_1.ibar) {
	++ibarcnt;
	comask_1.bar1syst = ibarcnt == iauto;
/* Computing MAX */
	r__1 = ibarcnt + (float).001 + ibcoff;
	i__2 = 0, i__5 = (integer) r_lg10(&r__1);
	ndig = max(i__2,i__5);
	if (comlast_1.islast) {
	    ci__1.cierr = 0;
	    ci__1.ciunit = 11;
/* Writing concatenation */
	    i__6[0] = 6, a__3[0] = "(a11,i";
	    i__2 = ndig + 50;
	    chax_(ch__1, (ftnlen)1, &i__2);
	    i__6[1] = 1, a__3[1] = ch__1;
	    i__6[2] = 1, a__3[2] = ")";
	    ci__1.cifmt = (s_cat(ch__5, a__3, i__6, &c__3, (ftnlen)8), ch__5);
	    s_wsfe(&ci__1);
	    do_fio(&c__1, "% Bar count", (ftnlen)11);
	    i__5 = ibarcnt + ibcoff;
	    do_fio(&c__1, (char *)&i__5, (ftnlen)sizeof(integer));
	    e_wsfe();
	}
	if (all_1.ibar != comgrace_1.ibarmbr) {
	    if (! (*optimize)) {
		i__2 = ibarcnt + ibcoff;
		outbar_(&i__2, &jprntb);
	    }
	} else {
	    if (! (*optimize)) {
		s_wsfe(&io___355);
		do_fio(&c__1, " Multibar rest, bars", (ftnlen)20);
		i__2 = ibarcnt + ibcoff;
		do_fio(&c__1, (char *)&i__2, (ftnlen)sizeof(integer));
		do_fio(&c__1, "-", (ftnlen)1);
		i__5 = ibarcnt + ibcoff + comgrace_1.mbrest - 1;
		do_fio(&c__1, (char *)&i__5, (ftnlen)sizeof(integer));
		e_wsfe();
		s_wsfe(&io___356);
		do_fio(&c__1, " Multibar rest, bars", (ftnlen)20);
		i__2 = ibarcnt + ibcoff;
		do_fio(&c__1, (char *)&i__2, (ftnlen)sizeof(integer));
		do_fio(&c__1, "-", (ftnlen)1);
		i__5 = ibarcnt + ibcoff + comgrace_1.mbrest - 1;
		do_fio(&c__1, (char *)&i__5, (ftnlen)sizeof(integer));
		e_wsfe();
		jprntb = 0;
	    }
	    ibcoff = ibcoff + comgrace_1.mbrest - 1;
	    if (all_1.ibar == 1 && all_1.firstgulp) {
		comgrace_1.xb4mbr = comstart_1.facmtr * all_1.musicsize;
	    }
	}

/*  Move the read to after end-of-bar hardspace checks, so we get right poenom */
/*  at end of a line. */
/*       if (bar1syst) read(12,*) poenom */

/*  Check for clef at start of bar.  No slide yet.  Also flags at end of prev. */
/*  bar.  This block is run at the start of every bar.  May fail for flag at */
/*  end of last bar.  To account for necc. hardspaces, compute and store */
/*    nhssys = # of hard spaces for this system */
/*    hesk(nhssys) = elemskips avialable */
/*    hpts(nhssys) = hard points needed, including notehead */
/*  Here, merely insert placeholder into output.  Later, when poe is computed, */
/*  compute additional pts and store them in hpttot(1...nhstot).  Finally in */
/*  subroutine askfig, write true pts where placeholders are. */

	ioff = 0;
	if (all_1.ibar > 1) {
	    ioff = all_1.nib[(all_1.ibar - 1) * 15 - 15];
	}
	clchb = bit_test(all_1.islur[(ioff + 1) * 15 - 15],15);
	if (! (clchb || comnsp_1.flgndb)) {
	    goto L23;
	}

/*  Must check available space */

	ptsndb = (float)0.;

/*  Zero out block signal */

	if (clchb) {
	    all_1.islur[(ioff + 1) * 15 - 15] = bit_clear(all_1.islur[(ioff + 
		    1) * 15 - 15],15);
	}

/*  In this loop, we determine how much hardspace is needed (if any) */
/*  9/7/97  Note that for last bar in input block, if number of lines of */
/*    music decreases in new block, highest numbered ones won't be checked */
/*    since the loop below covers the new nvmx(iv), not necessarily the old */
/*    one. */
/*  4/18/98 Apparently nmxsav was a solution to the above problem */

	i__2 = all_1.nv;
	for (all_1.iv = 1; all_1.iv <= i__2; ++all_1.iv) {
	    i__5 = comnsp_1.nvmxsav[all_1.iv - 1];
	    for (kv = 1; kv <= i__5; ++kv) {
		commvl_1.ivx = comnsp_1.ivmxsav[all_1.iv + kv * 15 - 16];
		ptsndv = comnsp_1.flgndv[commvl_1.ivx - 1] * comask_1.wheadpt;
		ioff = 0;
		if (all_1.ibar > 1) {
		    ioff = all_1.nib[commvl_1.ivx + (all_1.ibar - 1) * 15 - 
			    16];
		    ip = ioff;
		    if (all_1.ibar > 2) {
			ip = ioff - all_1.nib[commvl_1.ivx + (all_1.ibar - 2) 
				* 15 - 16];
		    }
		    comnsp_1.prevtn[commvl_1.ivx - 1] = all_1.tnote[(
			    all_1.ipl[commvl_1.ivx + ip * 15 - 16] & 255) - 1]
			    ;

/* If ibar=1 (1st bar in input block), prevtn(ivx) was set at end of makeabar. */

		}

/*  Only allow clef changes when ivx <= nv */

		if (commvl_1.ivx <= all_1.nv) {
		    clchv[all_1.iv - 1] = clchb && bit_test(all_1.islur[
			    all_1.iv + (ioff + 1) * 15 - 16],11);
		    if (clchv[all_1.iv - 1]) {

/*  Clef change in this voice.  Turn off signal.  Get space avail. */

			all_1.islur[all_1.iv + (ioff + 1) * 15 - 16] = 
				bit_clear(all_1.islur[all_1.iv + (ioff + 1) * 
				15 - 16],11);
			if ((r__1 = comnsp_1.prevtn[all_1.iv - 1] - 
				comnsp_1.space[comnsp_1.nb - 1], dabs(r__1)) <
				 comtol_1.tol) {
			    ptsndv += combmh_1.clefend * comask_1.wheadpt;
			}
		    }
		}
/* Computing MAX */
		r__1 = ptsndb, r__2 = ptsndv + comask_1.wheadpt * 
			spfacs_1.xspfac;
		ptsndb = dmax(r__1,r__2);
/* L16: */
	    }
	}

/* ????  where is nb set???  nb probably in left over from makeabar */

	r__1 = comnsp_1.space[comnsp_1.nb - 1] * squez[comnsp_1.nb - 1];
	esk = feon_(&r__1);
	ptsdflt = esk * comask_1.poenom - comask_1.wheadpt;
	if ((ptsndb > ptsdflt || comnsp_1.ptsgnd > (float)0.) && 
		comget_1.movbrk == 0) {

/*  Must ADD hardspace!  So put in a placeholder, and store params for later. */

	    if (comlast_1.islast) {
		s_wsfe(&io___367);
/* Writing concatenation */
		i__7[0] = 1, a__4[0] = all_1.sq;
		i__7[1] = 18, a__4[1] = "xardspace{    pt}%";
		s_cat(ch__3, a__4, i__7, &c__2, (ftnlen)19);
		do_fio(&c__1, ch__3, (ftnlen)19);
		e_wsfe();
	    }
	    ++nhssys;
	    if (ptsndb - ptsdflt > comnsp_1.ptsgnd - comask_1.poenom * 
		    comnsp_1.eskgnd) {
		hesk[nhssys - 1] = esk;
		hpts[nhssys - 1] = ptsndb + comask_1.wheadpt;
	    } else {
		hesk[nhssys - 1] = comnsp_1.eskgnd;
		hpts[nhssys - 1] = comnsp_1.ptsgnd + comask_1.wheadpt;
	    }
	    comask_1.fixednew += hpts[nhssys - 1];
	    comask_1.scaldold += hesk[nhssys - 1];
	}
	if (clchb) {
	    i__5 = all_1.nv;
	    for (all_1.iv = 1; all_1.iv <= i__5; ++all_1.iv) {
		if (clchv[all_1.iv - 1]) {
/* Writing concatenation */
		    i__7[0] = 1, a__4[0] = all_1.sq;
		    i__7[1] = 6, a__4[1] = "znotes";
		    s_cat(notexq, a__4, i__7, &c__2, (ftnlen)79);
		    lnote = 7;
		    i__2 = all_1.iv;
		    for (iiv = 2; iiv <= i__2; ++iiv) {
/* Writing concatenation */
			i__7[0] = lnote, a__4[0] = notexq;
			i__7[1] = 1, a__4[1] = all_1.sepsymq + (iiv - 2);
			s_cat(notexq, a__4, i__7, &c__2, (ftnlen)79);
			++lnote;
/* L24: */
		    }

/*  Recompute ioff since it will vary from voice to voice */

		    if (all_1.ibar == 1) {
			ioff = 0;
		    } else {
			ioff = all_1.nib[all_1.iv + (all_1.ibar - 1) * 15 - 
				16];
		    }

/*  Must call clefsym to get nclef, even if there is a movement break */

		    clefsym_(&all_1.islur[all_1.iv + (ioff + 1) * 15 - 16], 
			    fmtq, &lclef, &nclef, (ftnlen)24);
		    if (comget_1.movbrk == 0 && comlast_1.islast) {
			s_wsfe(&io___376);
/* Writing concatenation */
			i__4[0] = lnote, a__2[0] = notexq;
			i__4[1] = lclef, a__2[1] = fmtq;
			i__4[2] = 1, a__2[2] = all_1.sq;
			i__4[3] = 3, a__2[3] = "en%";
			s_cat(ch__6, a__2, i__4, &c__4, (ftnlen)107);
			do_fio(&c__1, ch__6, lnote + lclef + 4);
			e_wsfe();
		    }
		    wsclef_(&all_1.iv, &ninow, clefq, &nclef, (ftnlen)1);
		}
/* L17: */
	    }
	    if (comlast_1.islast) {
		s_wsfe(&io___377);
/* Writing concatenation */
		i__7[0] = 1, a__4[0] = all_1.sq;
		i__7[1] = 11, a__4[1] = "pmxnewclefs";
		s_cat(ch__7, a__4, i__7, &c__2, (ftnlen)12);
		do_fio(&c__1, ch__7, (ftnlen)12);
		e_wsfe();
	    }
	}
L23:

/*  End of loop for end-of-bar hardspaces and non-movbrk clef symbol. */

	if (comask_1.bar1syst) {
	    s_rsle(&io___378);
	    do_lio(&c__4, &c__1, (char *)&comask_1.poenom, (ftnlen)sizeof(
		    real));
	    e_rsle();
	}

/*  Repeat symbols.  Haven't slid down yet, so use islur(1,nib(1,ibar-1)+1) */

	if (all_1.ibar == 1) {
	    islnow = all_1.islur[0];
	} else {
	    islnow = all_1.islur[(all_1.nib[(all_1.ibar - 1) * 15 - 15] + 1) *
		     15 - 15];
	}

/*  Check for R-symbols set at end of prior input block */

	if (comget_1.movbrk == 0 && *(unsigned char *)comget_1.rptfq2 != 'E') 
		{
	    if (*(unsigned char *)comget_1.rptfq2 == 'D') {
		islnow = bit_set(islnow,26);
	    } else if (*(unsigned char *)comget_1.rptfq2 == 'r') {
		islnow = bit_set(islnow,6);
	    } else if (*(unsigned char *)comget_1.rptfq2 == 'd') {
		islnow = bit_set(islnow,8);
	    } else if (*(unsigned char *)comget_1.rptfq2 == 'b') {
		islnow = bit_set(islnow,25);
	    } else {
		s_wsle(&io___380);
		e_wsle();
		s_wsle(&io___381);
		do_lio(&c__9, &c__1, "Illegal symbol with \"R\" at end of in\
put block:", (ftnlen)46);
		do_lio(&c__9, &c__1, comget_1.rptfq2, (ftnlen)1);
		e_wsle();
		s_stop("1", (ftnlen)1);
	    }
	    *(unsigned char *)comget_1.rptfq2 = 'E';
	}
	if ((islnow & 352) != 0) {

/*  Bit 5(lrpt), 6(rrpt), or 8(doublebar) has been set */

	    lrpt = bit_test(islnow,5);
	    rrpt = bit_test(islnow,6);
	    lrptpend = lrpt && comask_1.bar1syst;
	    if (lrpt && ! lrptpend) {
		if (rrpt) {
		    if (comlast_1.islast) {
			s_wsfe(&io___384);
/* Writing concatenation */
			i__7[0] = 1, a__4[0] = all_1.sq;
			i__7[1] = 18, a__4[1] = "setleftrightrepeat";
			s_cat(ch__3, a__4, i__7, &c__2, (ftnlen)19);
			do_fio(&c__1, ch__3, (ftnlen)19);
			e_wsfe();
		    }
		    comask_1.fixednew = comask_1.fixednew + comask_1.wheadpt *
			     spfacs_1.lrrptfac - (float).4;
		} else {
		    if (comlast_1.islast) {
			s_wsfe(&io___385);
/* Writing concatenation */
			i__7[0] = 1, a__4[0] = all_1.sq;
			i__7[1] = 13, a__4[1] = "setleftrepeat";
			s_cat(ch__8, a__4, i__7, &c__2, (ftnlen)14);
			do_fio(&c__1, ch__8, (ftnlen)14);
			e_wsfe();
		    }
		    comask_1.fixednew = comask_1.fixednew + comask_1.wheadpt *
			     spfacs_1.rptfac - (float).4;
		}
	    } else if (rrpt) {
		if (comlast_1.islast) {
		    s_wsfe(&io___386);
/* Writing concatenation */
		    i__7[0] = 1, a__4[0] = all_1.sq;
		    i__7[1] = 14, a__4[1] = "setrightrepeat";
		    s_cat(ch__9, a__4, i__7, &c__2, (ftnlen)15);
		    do_fio(&c__1, ch__9, (ftnlen)15);
		    e_wsfe();
		}
		comask_1.fixednew = comask_1.fixednew + comask_1.wheadpt * 
			spfacs_1.rptfac - (float).4;
	    } else if (bit_test(islnow,8)) {
		if (comlast_1.islast) {
		    s_wsfe(&io___387);
/* Writing concatenation */
		    i__7[0] = 1, a__4[0] = all_1.sq;
		    i__7[1] = 12, a__4[1] = "setdoublebar";
		    s_cat(ch__10, a__4, i__7, &c__2, (ftnlen)13);
		    do_fio(&c__1, ch__10, (ftnlen)13);
		    e_wsfe();
		}
		comask_1.fixednew = comask_1.fixednew + comask_1.wheadpt * 
			spfacs_1.dbarfac - (float).4;
	    }
	} else if (bit_test(islnow,26)) {

/*  doubleBAR */

	    if (comlast_1.islast) {
		s_wsfe(&io___388);
/* Writing concatenation */
		i__7[0] = 1, a__4[0] = all_1.sq;
		i__7[1] = 12, a__4[1] = "setdoubleBAR";
		s_cat(ch__10, a__4, i__7, &c__2, (ftnlen)13);
		do_fio(&c__1, ch__10, (ftnlen)13);
		e_wsfe();
	    }
	    comask_1.fixednew = comask_1.fixednew + comask_1.wheadpt * 
		    spfacs_1.ddbarfac - (float).4;
	}

/*  1st and 2nd endings */

	svolta = bit_test(islnow,7);
	evolta = bit_test(islnow,9);
	if (evolta) {
	    if (bit_test(islnow,10)) {
		if (comlast_1.islast) {
		    s_wsfe(&io___391);
/* Writing concatenation */
		    i__7[0] = 1, a__4[0] = all_1.sq;
		    i__7[1] = 11, a__4[1] = "endvoltabox";
		    s_cat(ch__7, a__4, i__7, &c__2, (ftnlen)12);
		    do_fio(&c__1, ch__7, (ftnlen)12);
		    e_wsfe();
		}
	    } else {
		if (comlast_1.islast) {
		    s_wsfe(&io___392);
/* Writing concatenation */
		    i__7[0] = 1, a__4[0] = all_1.sq;
		    i__7[1] = 8, a__4[1] = "endvolta";
		    s_cat(ch__11, a__4, i__7, &c__2, (ftnlen)9);
		    do_fio(&c__1, ch__11, (ftnlen)9);
		    e_wsfe();
		}
	    }
	    onvolt = FALSE_;
	}
	if (svolta) {
	    ++comgrace_1.nvolt;
	    lvoltxt = i_indx(comgrace_1.voltxtq + (comgrace_1.nvolt - 1) * 10,
		     " ", (ftnlen)10, (ftnlen)1) - 1;
	    if (lvoltxt == 1) {
		if (comlast_1.islast) {
		    s_wsfe(&io___394);
/* Writing concatenation */
		    i__4[0] = 1, a__2[0] = all_1.sq;
		    i__4[1] = 8, a__2[1] = "Setvolta";
		    i__4[2] = 1, a__2[2] = comgrace_1.voltxtq + (
			    comgrace_1.nvolt - 1) * 10;
		    i__4[3] = 1, a__2[3] = "%";
		    s_cat(ch__12, a__2, i__4, &c__4, (ftnlen)11);
		    do_fio(&c__1, ch__12, (ftnlen)11);
		    e_wsfe();
		}
	    } else {
		if (comlast_1.islast) {
		    s_wsfe(&io___395);
/* Writing concatenation */
		    i__8[0] = 1, a__5[0] = all_1.sq;
		    i__8[1] = 8, a__5[1] = "Setvolta";
		    i__8[2] = 1, a__5[2] = "{";
		    i__8[3] = lvoltxt, a__5[3] = comgrace_1.voltxtq + (
			    comgrace_1.nvolt - 1) * 10;
		    i__8[4] = 2, a__5[4] = "}%";
		    s_cat(ch__13, a__5, i__8, &c__5, (ftnlen)22);
		    do_fio(&c__1, ch__13, lvoltxt + 12);
		    e_wsfe();
		}
	    }
	    onvolt = TRUE_;
	}
	if (all_1.ibar > 1) {
	    ipnow = all_1.nib[(all_1.ibar - 1) * 15 - 15] + 1;
	} else {
	    ipnow = 1;
	}
	iplnow = all_1.ipl[ipnow * 15 - 15];
	if (comask_1.bar1syst) {
	    ++all_1.iline;

/*  End an old system, Start a new system */

	    if (all_1.iline != 1) {

/*  Not first line. */
/*  Get corrected poe = points/elemskip for *previous* system */

		wdpt = comtop_1.widthpt * (1 - comtop_1.fracindent);
		poe = (wdpt - fsyst * all_1.musicsize - nbarss * (float).4 - 
			comask_1.fixednew) / (elsktot + comask_1.fbar * 
			nbarss - comask_1.scaldold);
		++isyscnt;
		poevec[isyscnt] = poe;

/*  Transfer data for system into global arrays to hold until very end */

		i__5 = comas2_1.nasksys;
		for (ia = 1; ia <= i__5; ++ia) {
		    ++comas3_1.iask;
		    comas3_1.ask[comas3_1.iask - 1] = comas2_1.wasksys[ia - 1]
			     / poe - (r__1 = comas2_1.elasksys[ia - 1], dabs(
			    r__1));

/*  Only admit negative ask if it was user-defined space, signalled by elask<=0. */

		    if (comas2_1.elasksys[ia - 1] > (float)0.) {
			comas3_1.ask[comas3_1.iask - 1] = r_dim(&comas3_1.ask[
				comas3_1.iask - 1], &c_b1398);
		    }
/* L9: */
		}
		i__5 = nhssys;
		for (ia = 1; ia <= i__5; ++ia) {
		    ++nhstot;
/* Computing MAX */
		    r__1 = hpts[ia - 1] - hesk[ia - 1] * poe;
		    comhsp_1.hpttot[nhstot - 1] = dmax(r__1,(float)0.);
/* L25: */
		}

/*  Reset counters for new system */

		comask_1.scaldold = (float)0.;
		comask_1.fixednew = (float)0.;
		comas2_1.nasksys = 0;
		nhssys = 0;
	    }

/*  End of if block for first bar of non-first system. Still 1st bar, any system */

	    if (comlast_1.islast && all_1.figbass) {
		s_wsfe(&io___404);
/* Writing concatenation */
		i__7[0] = 1, a__4[0] = all_1.sq;
		i__7[1] = 8, a__4[1] = "fixdrop%";
		s_cat(ch__11, a__4, i__7, &c__2, (ftnlen)9);
		do_fio(&c__1, ch__11, (ftnlen)9);
		e_wsfe();
	    }
	    ++isystpg;
	    if (isystpg == nsystp[ipage - 1]) {
		isystpg = 0;
	    }
	    s_rsle(&io___405);
	    do_lio(&c__3, &c__1, (char *)&nbarss, (ftnlen)sizeof(integer));
	    do_lio(&c__4, &c__1, (char *)&elsktot, (ftnlen)sizeof(real));
	    do_lio(&c__4, &c__1, (char *)&fsyst, (ftnlen)sizeof(real));
	    do_lio(&c__4, &c__1, (char *)&frac, (ftnlen)sizeof(real));
	    do_lio(&c__4, &c__1, (char *)&comeon_1.eonk, (ftnlen)sizeof(real))
		    ;
	    do_lio(&c__4, &c__1, (char *)&comeon_1.ewmxk, (ftnlen)sizeof(real)
		    );
	    e_rsle();
	    if (all_1.iline > 1) {
		comtop_1.fracindent = frac;
	    }
	    if (all_1.figbass) {
		all_1.ifigdrop[all_1.iline - 1] = 4;
	    }
	    all_1.slfac = slfac1 * all_1.musicsize * elsktot;
	    if (all_1.iline != 1) {

/*  For the line just _finished_, put figdrop in separate file. */

		if (all_1.figbass) {
		    s_wsfe(&io___407);
/* Writing concatenation */
		    i__7[0] = 1, a__4[0] = all_1.sq;
		    i__7[1] = 8, a__4[1] = "figdrop=";
		    s_cat(ch__11, a__4, i__7, &c__2, (ftnlen)9);
		    do_fio(&c__1, ch__11, (ftnlen)9);
		    do_fio(&c__1, (char *)&all_1.ifigdrop[all_1.iline - 2], (
			    ftnlen)sizeof(integer));
/* Writing concatenation */
		    i__9[0] = 1, a__6[0] = all_1.sq;
		    i__9[1] = 3, a__6[1] = "or%";
		    s_cat(ch__14, a__6, i__9, &c__2, (ftnlen)4);
		    do_fio(&c__1, ch__14, (ftnlen)4);
		    e_wsfe();
		}

/*  Check slurs in top staff for interference w/ barno. Only check when */
/*  # if digits in barno >= |isig|  But to keep on/off phasing, must ALWAYS */
/*  keep track of ons and offs when |isig|<=3. */

		r__1 = ibarcnt + ibcoff + (float).01;
		ndigbn = (integer) r_lg10(&r__1) + 1;
		comsln_1.isnx = 0;
		if (ndigbn >= abs(comtop_1.isig) && comsln_1.is1n1 > 0) {

/*  There's a slur in top voice over the line break, hgt=is1n1, idcode=is2n1 */
/*  Look for termination in remainder of this input block.  If not found, */
/*  just use is1n1.  Remember, haven't slid down yet. */

		    ioff = 0;
		    if (all_1.ibar > 1) {
			ioff = all_1.nib[commvl_1.ivmx[all_1.nv + 
				commvl_1.nvmx[all_1.nv - 1] * 15 - 16] + (
				all_1.ibar - 1) * 15 - 16];
		    }
		    i__5 = all_1.nsdat;
		    for (isdat = 1; isdat <= i__5; ++isdat) {
/*                if (igetbits(isdat1(isdat),3,0).eq.ivmx(nv,nvmx(nv)) */
			if (igetbits_(&all_1.isdat1[isdat - 1], &c__5, &c__13)
				 == commvl_1.ivmx[all_1.nv + commvl_1.nvmx[
				all_1.nv - 1] * 15 - 16] && ! bit_test(
				all_1.isdat1[isdat - 1],11) && igetbits_(&
				all_1.isdat1[isdat - 1], &c__7, &c__19) == 
				comsln_1.is2n1) {

/*  Found slur ending.  Just check note height, can't do fine adjustments. */

/* Computing MAX */
			    i__2 = comsln_1.is1n1, i__10 = igetbits_(&
				    all_1.isdat2[all_1.nsdat - 1], &c__7, &
				    c__19);
			    comsln_1.is1n1 = max(i__2,i__10);
			    goto L51;
			}
/* L50: */
		    }

/*  If exiting loop normally, did not find end of slur.  c'est la vie. */

L51:
		    i__5 = ncmid_(&all_1.nv, &c__1) + 1 + comsln_1.irzbnd;
		    comsln_1.isnx = i_dim(&comsln_1.is1n1, &i__5);
		    if (comsln_1.isnx > 0) {

/*  AHA! Slur likely to interfere with barno. */

			slint = TRUE_;
			s_copy(fmtq, "(a16,i1,a14)", (ftnlen)24, (ftnlen)12);
			if (comsln_1.irzbnd + comsln_1.isnx > 9) {
			    s_copy(fmtq, "(a16,i2,a14)", (ftnlen)24, (ftnlen)
				    12);
			}
			if (comlast_1.islast) {
			    s_wsfe(&io___410);
/* Writing concatenation */
			    i__4[0] = 1, a__2[0] = all_1.sq;
			    i__4[1] = 3, a__2[1] = "def";
			    i__4[2] = 1, a__2[2] = all_1.sq;
			    i__4[3] = 11, a__2[3] = "raisebarno{";
			    s_cat(ch__15, a__2, i__4, &c__4, (ftnlen)16);
			    do_fio(&c__1, ch__15, (ftnlen)16);
			    i__5 = comsln_1.irzbnd + comsln_1.isnx;
			    do_fio(&c__1, (char *)&i__5, (ftnlen)sizeof(
				    integer));
/* Writing concatenation */
			    i__6[0] = 2, a__3[0] = ".5";
			    i__6[1] = 1, a__3[1] = all_1.sq;
			    i__6[2] = 11, a__3[2] = "internote}%";
			    s_cat(ch__8, a__3, i__6, &c__3, (ftnlen)14);
			    do_fio(&c__1, ch__8, (ftnlen)14);
			    e_wsfe();
			}
		    }
		}
		if (comget_1.movbrk > 0) {

/*              movbrk = 0 */
/*  Move the reset down, so can use movbrk>0 to stop extra meter prints. */

/*  New movement.  Redefine stoppiece, contpiece.  These will be called either */
/*     explicitly or as part of alaligne. */
/*  indsym = 0,1,2 for doubleBAR , doublebar, rightrepeat. */
/*     This is passed to \newmovement. */

		    if (*(unsigned char *)comget_1.rptfq2 == 'E') {
			*(unsigned char *)comget_1.rptfq2 = 'D';
		    }
		    indsym = i_indx("Ddrb", comget_1.rptfq2, (ftnlen)4, (
			    ftnlen)1) - 1;
		    *(unsigned char *)comget_1.rptfq2 = 'E';

/*  Also check for Rd or Rr set the normal way */

		    if (bit_test(islnow,8)) {
			indsym = 1;
		    } else if (bit_test(islnow,6)) {
			indsym = 2;
		    }
		    if (indsym < 0) {
			s_wsle(&io___412);
			e_wsle();
			s_wsle(&io___413);
			do_lio(&c__9, &c__1, "Illegal end symbol before \"/\""
				, (ftnlen)29);
			e_wsle();
			s_stop("1", (ftnlen)1);
		    }

/*  Check for continuation (no bar number reset) */

		    if (comlast_1.islast && comnotes_1.nobar1) {
			s_wsfe(&io___414);
/* Writing concatenation */
			i__11[0] = 1, a__7[0] = all_1.sq;
			i__11[1] = 7, a__7[1] = "advance";
			i__11[2] = 1, a__7[2] = all_1.sq;
			i__11[3] = 6, a__7[3] = "barno1";
			i__11[4] = 1, a__7[4] = all_1.sq;
			i__11[5] = 10, a__7[5] = "startbarno";
			i__11[6] = 1, a__7[6] = all_1.sq;
			i__11[7] = 6, a__7[7] = "barno%";
			s_cat(ch__16, a__7, i__11, &c__8, (ftnlen)33);
			do_fio(&c__1, ch__16, (ftnlen)33);
			e_wsfe();
		    }
		    if (comget_1.movgap < 10) {
			if (comlast_1.islast) {
			    s_wsfe(&io___415);
/* Writing concatenation */
			    i__7[0] = 1, a__4[0] = all_1.sq;
			    i__7[1] = 11, a__4[1] = "newmovement";
			    s_cat(ch__7, a__4, i__7, &c__2, (ftnlen)12);
			    do_fio(&c__1, ch__7, (ftnlen)12);
			    do_fio(&c__1, (char *)&comget_1.movgap, (ftnlen)
				    sizeof(integer));
			    do_fio(&c__1, (char *)&indsym, (ftnlen)sizeof(
				    integer));
			    do_fio(&c__1, "%", (ftnlen)1);
			    e_wsfe();
			}
		    } else {
			if (comlast_1.islast) {
			    s_wsfe(&io___416);
/* Writing concatenation */
			    i__7[0] = 1, a__4[0] = all_1.sq;
			    i__7[1] = 12, a__4[1] = "newmovement{";
			    s_cat(ch__10, a__4, i__7, &c__2, (ftnlen)13);
			    do_fio(&c__1, ch__10, (ftnlen)13);
			    do_fio(&c__1, (char *)&comget_1.movgap, (ftnlen)
				    sizeof(integer));
			    do_fio(&c__1, "}", (ftnlen)1);
			    do_fio(&c__1, (char *)&indsym, (ftnlen)sizeof(
				    integer));
			    do_fio(&c__1, "%", (ftnlen)1);
			    e_wsfe();
			}
		    }

/*  Change generalmeter if necessary */

		    if (comlast_1.islast) {
			wgmeter_(&all_1.mtrnmp, &all_1.mtrdnp);
		    }

/*  (Moved all name-writing to getnote, right when 'M' is detected) */

		    if (bit_test(iplnow,28)) {

/*  Key signature at movement break */

			iplnow = bit_clear(iplnow,28);
			if (comtop_1.isig > 0) {
			    if (comlast_1.islast) {
				s_wsfe(&io___417);
/* Writing concatenation */
				i__7[0] = 1, a__4[0] = all_1.sq;
				i__7[1] = 17, a__4[1] = "generalsignature{";
				s_cat(ch__17, a__4, i__7, &c__2, (ftnlen)18);
				do_fio(&c__1, ch__17, (ftnlen)18);
				do_fio(&c__1, (char *)&comtop_1.isig, (ftnlen)
					sizeof(integer));
				do_fio(&c__1, "}%", (ftnlen)2);
				e_wsfe();
			    }
			} else {
			    if (comlast_1.islast) {
				s_wsfe(&io___418);
/* Writing concatenation */
				i__7[0] = 1, a__4[0] = all_1.sq;
				i__7[1] = 17, a__4[1] = "generalsignature{";
				s_cat(ch__17, a__4, i__7, &c__2, (ftnlen)18);
				do_fio(&c__1, ch__17, (ftnlen)18);
				do_fio(&c__1, (char *)&comtop_1.isig, (ftnlen)
					sizeof(integer));
				do_fio(&c__1, "}%", (ftnlen)2);
				e_wsfe();
			    }
			}
		    }
		    if (comget_1.parmov >= (float)-.1) {

/*  Resent paragraph indentation */

			ipi = comget_1.parmov * comtop_1.widthpt + (float).1;
			if (ipi < 10) {
			    if (comlast_1.islast) {
				s_wsfe(&io___420);
/* Writing concatenation */
				i__7[0] = 1, a__4[0] = all_1.sq;
				i__7[1] = 10, a__4[1] = "parindent ";
				s_cat(ch__12, a__4, i__7, &c__2, (ftnlen)11);
				do_fio(&c__1, ch__12, (ftnlen)11);
				do_fio(&c__1, (char *)&ipi, (ftnlen)sizeof(
					integer));
				do_fio(&c__1, "pt", (ftnlen)2);
				e_wsfe();
			    }
			} else if (ipi < 100) {
			    if (comlast_1.islast) {
				s_wsfe(&io___421);
/* Writing concatenation */
				i__7[0] = 1, a__4[0] = all_1.sq;
				i__7[1] = 10, a__4[1] = "parindent ";
				s_cat(ch__12, a__4, i__7, &c__2, (ftnlen)11);
				do_fio(&c__1, ch__12, (ftnlen)11);
				do_fio(&c__1, (char *)&ipi, (ftnlen)sizeof(
					integer));
				do_fio(&c__1, "pt", (ftnlen)2);
				e_wsfe();
			    }
			} else {
			    if (comlast_1.islast) {
				s_wsfe(&io___422);
/* Writing concatenation */
				i__7[0] = 1, a__4[0] = all_1.sq;
				i__7[1] = 10, a__4[1] = "parindent ";
				s_cat(ch__12, a__4, i__7, &c__2, (ftnlen)11);
				do_fio(&c__1, ch__12, (ftnlen)11);
				do_fio(&c__1, (char *)&ipi, (ftnlen)sizeof(
					integer));
				do_fio(&c__1, "pt", (ftnlen)2);
				e_wsfe();
			    }
			}
		    }
		}
		if (isystpg == 1) {

/*  First line on a page (not 1st page, still first bar).  Tidy up old page */
/*  then eject. */

		    if (onvolt) {
			if (comlast_1.islast) {
			    s_wsfe(&io___423);
/* Writing concatenation */
			    i__7[0] = 1, a__4[0] = all_1.sq;
			    i__7[1] = 12, a__4[1] = "endvoltabox%";
			    s_cat(ch__10, a__4, i__7, &c__2, (ftnlen)13);
			    do_fio(&c__1, ch__10, (ftnlen)13);
			    e_wsfe();
			}
			onvolt = FALSE_;
		    }

/*  Check for meter change at start of a new PAGE */

		    if (all_1.mtrnuml > 0) {

/*  Meter change at start of a new page.  Ugly repeated coding here. */

			mtrnms = all_1.mtrnuml;
			setmeter_(&all_1.mtrnuml, &all_1.mtrdenl, &
				combeam_1.ibmtyp, &ibmrep);
			all_1.mtrnuml = mtrnms;
			if (comget_1.movbrk == 0 && comlast_1.islast) {
			    wgmeter_(&all_1.mtrnmp, &all_1.mtrdnp);
			}
		    }

/*  Key signature change? */

		    if (bit_test(iplnow,28) && comget_1.movbrk == 0) {
/* Writing concatenation */
			i__11[0] = 1, a__7[0] = all_1.sq;
			i__11[1] = 4, a__7[1] = "xbar";
			i__11[2] = 1, a__7[2] = all_1.sq;
			i__11[3] = 10, a__7[3] = "addspace{-";
			i__11[4] = 1, a__7[4] = all_1.sq;
			i__11[5] = 14, a__7[5] = "afterruleskip}";
			i__11[6] = 1, a__7[6] = all_1.sq;
			i__11[7] = 17, a__7[7] = "generalsignature{";
			s_cat(notexq, a__7, i__11, &c__8, (ftnlen)79);
			lnote = 49;
			if (comtop_1.isig < 0) {
/* Writing concatenation */
			    i__7[0] = 49, a__4[0] = notexq;
			    i__7[1] = 1, a__4[1] = "-";
			    s_cat(notexq, a__4, i__7, &c__2, (ftnlen)79);
			    lnote = 50;
			}
			if (comlast_1.islast) {
			    s_wsfe(&io___425);
/* Writing concatenation */
			    i__6[0] = lnote, a__3[0] = notexq;
			    i__5 = abs(comtop_1.isig) + 48;
			    chax_(ch__1, (ftnlen)1, &i__5);
			    i__6[1] = 1, a__3[1] = ch__1;
			    i__6[2] = 2, a__3[2] = "}%";
			    s_cat(ch__18, a__3, i__6, &c__3, (ftnlen)82);
			    do_fio(&c__1, ch__18, lnote + 3);
			    e_wsfe();
			}
			if (comlast_1.islast) {
			    s_wsfe(&io___426);
/* Writing concatenation */
			    i__3[0] = 1, a__1[0] = all_1.sq;
			    i__3[1] = 14, a__1[1] = "zchangecontext";
			    i__3[2] = 1, a__1[2] = all_1.sq;
			    i__3[3] = 10, a__1[3] = "addspace{-";
			    i__3[4] = 1, a__1[4] = all_1.sq;
			    i__3[5] = 14, a__1[5] = "afterruleskip}";
			    i__3[6] = 1, a__1[6] = all_1.sq;
			    i__3[7] = 3, a__1[7] = "def";
			    i__3[8] = 1, a__1[8] = all_1.sq;
			    i__3[9] = 13, a__1[9] = "writezbarno{}";
			    i__3[10] = 1, a__1[10] = all_1.sq;
			    i__3[11] = 11, a__1[11] = "zstoppiece%";
			    s_cat(ch__19, a__1, i__3, &c__12, (ftnlen)71);
			    do_fio(&c__1, ch__19, (ftnlen)71);
			    e_wsfe();
			}
		    } else if (all_1.mtrnuml > 0 && comget_1.movbrk == 0) {

/*  Meter change but no signatuire change */

			if (comlast_1.islast) {
			    s_wsfe(&io___427);
/* Writing concatenation */
			    i__3[0] = 1, a__1[0] = all_1.sq;
			    i__3[1] = 14, a__1[1] = "xchangecontext";
			    i__3[2] = 1, a__1[2] = all_1.sq;
			    i__3[3] = 10, a__1[3] = "addspace{-";
			    i__3[4] = 1, a__1[4] = all_1.sq;
			    i__3[5] = 14, a__1[5] = "afterruleskip}";
			    i__3[6] = 1, a__1[6] = all_1.sq;
			    i__3[7] = 3, a__1[7] = "let";
			    i__3[8] = 1, a__1[8] = all_1.sq;
			    i__3[9] = 4, a__1[9] = "bnat";
			    i__3[10] = 1, a__1[10] = all_1.sq;
			    i__3[11] = 9, a__1[11] = "barnoadd%";
			    s_cat(ch__20, a__1, i__3, &c__12, (ftnlen)60);
			    do_fio(&c__1, ch__20, (ftnlen)60);
			    e_wsfe();
			}
			if (comlast_1.islast) {
			    s_wsfe(&io___428);
/* Writing concatenation */
			    i__3[0] = 1, a__1[0] = all_1.sq;
			    i__3[1] = 3, a__1[1] = "def";
			    i__3[2] = 1, a__1[2] = all_1.sq;
			    i__3[3] = 9, a__1[3] = "barnoadd{";
			    i__3[4] = 1, a__1[4] = all_1.sq;
			    i__3[5] = 3, a__1[5] = "let";
			    i__3[6] = 1, a__1[6] = all_1.sq;
			    i__3[7] = 8, a__1[7] = "barnoadd";
			    i__3[8] = 1, a__1[8] = all_1.sq;
			    i__3[9] = 5, a__1[9] = "bnat}";
			    i__3[10] = 1, a__1[10] = all_1.sq;
			    i__3[11] = 11, a__1[11] = "zstoppiece%";
			    s_cat(ch__21, a__1, i__3, &c__12, (ftnlen)45);
			    do_fio(&c__1, ch__21, (ftnlen)45);
			    e_wsfe();
			}
		    } else {
			if (comlast_1.islast) {
			    s_wsfe(&io___429);
/* Writing concatenation */
			    i__7[0] = 1, a__4[0] = all_1.sq;
			    i__7[1] = 10, a__4[1] = "stoppiece%";
			    s_cat(ch__12, a__4, i__7, &c__2, (ftnlen)11);
			    do_fio(&c__1, ch__12, (ftnlen)11);
			    e_wsfe();
			}
		    }
		    if (! vshrink) {
			xnstbot = xnsttop[ipage - 1] * etabot / etatop;
			if (xnstbot < (float)9.95) {
			    s_copy(fmtq, "(a,f3.1,a)", (ftnlen)24, (ftnlen)10)
				    ;
			} else {
			    s_copy(fmtq, "(a,f4.1,a)", (ftnlen)24, (ftnlen)10)
				    ;
			}
			if (comlast_1.islast) {
			    s_wsfe(&io___431);
/* Writing concatenation */
			    i__7[0] = 1, a__4[0] = all_1.sq;
			    i__7[1] = 5, a__4[1] = "vskip";
			    s_cat(ch__22, a__4, i__7, &c__2, (ftnlen)6);
			    do_fio(&c__1, ch__22, (ftnlen)6);
			    do_fio(&c__1, (char *)&xnstbot, (ftnlen)sizeof(
				    real));
/* Writing concatenation */
			    i__4[0] = 1, a__2[0] = all_1.sq;
			    i__4[1] = 10, a__2[1] = "Interligne";
			    i__4[2] = 1, a__2[2] = all_1.sq;
			    i__4[3] = 6, a__2[3] = "eject%";
			    s_cat(ch__17, a__2, i__4, &c__4, (ftnlen)18);
			    do_fio(&c__1, ch__17, (ftnlen)18);
			    e_wsfe();
			}
		    } else {
			if (comlast_1.islast) {
			    s_wsfe(&io___432);
/* Writing concatenation */
			    i__4[0] = 1, a__2[0] = all_1.sq;
			    i__4[1] = 5, a__2[1] = "vfill";
			    i__4[2] = 1, a__2[2] = all_1.sq;
			    i__4[3] = 6, a__2[3] = "eject%";
			    s_cat(ch__10, a__2, i__4, &c__4, (ftnlen)13);
			    do_fio(&c__1, ch__10, (ftnlen)13);
			    e_wsfe();
			}
		    }
		    ++ipage;
		    vshrink = xintstaff[ipage - 1] > (float)20.;
		    if (vshrink) {
			comarp_1.xinsnow = (float)10.;
		    } else {
			comarp_1.xinsnow = xintstaff[ipage - 1];
		    }
		    if (comget_1.fintstf > (float)0. && ipage > 1) {
			comarp_1.xinsnow = comarp_1.xinsnow * 
				comget_1.fintstf / comget_1.gintstf;
			comget_1.fintstf = (float)-1.;
		    }
		    if (comarp_1.xinsnow < (float)9.95) {
			s_copy(fmtq, "(a,f3.1,a)", (ftnlen)24, (ftnlen)10);
		    } else if (comarp_1.xinsnow < (float)99.95) {
			s_copy(fmtq, "(a,f4.1,a)", (ftnlen)24, (ftnlen)10);
		    } else {
			s_copy(fmtq, "(a,f5.1,a)", (ftnlen)24, (ftnlen)10);
		    }

/*  Vertical spacing parameters, then restart */

		    if (comlast_1.islast) {
			s_wsfe(&io___433);
/* Writing concatenation */
			i__7[0] = 1, a__4[0] = all_1.sq;
			i__7[1] = 11, a__4[1] = "interstaff{";
			s_cat(ch__7, a__4, i__7, &c__2, (ftnlen)12);
			do_fio(&c__1, ch__7, (ftnlen)12);
			do_fio(&c__1, (char *)&comarp_1.xinsnow, (ftnlen)
				sizeof(real));
/* Writing concatenation */
			i__6[0] = 1, a__3[0] = "}";
			i__6[1] = 1, a__3[1] = all_1.sq;
			i__6[2] = 9, a__3[2] = "contpiece";
			s_cat(ch__12, a__3, i__6, &c__3, (ftnlen)11);
			do_fio(&c__1, ch__12, (ftnlen)11);
			e_wsfe();
		    }

/*  Check for meter change at start of a new PAGE */

		    if (all_1.mtrnuml > 0) {

/*  Meter change at start of a new page */

			setmeter_(&all_1.mtrnuml, &all_1.mtrdenl, &
				combeam_1.ibmtyp, &ibmrep);
			if (comget_1.movbrk == 0) {
			    if (comlast_1.islast) {
				wgmeter_(&all_1.mtrnmp, &all_1.mtrdnp);
			    }
			    if (all_1.mtrdnp > 0) {
				if (comlast_1.islast) {
				    s_wsfe(&io___434);
/* Writing concatenation */
				    i__7[0] = 1, a__4[0] = all_1.sq;
				    i__7[1] = 10, a__4[1] = "newtimes2%";
				    s_cat(ch__12, a__4, i__7, &c__2, (ftnlen)
					    11);
				    do_fio(&c__1, ch__12, (ftnlen)11);
				    e_wsfe();
				}
				if (all_1.ibar == comgrace_1.ibarmbr) {
				    comgrace_1.xb4mbr = comstart_1.facmtr * 
					    all_1.musicsize;
				}
			    }
			}
		    }

/*  If no real titles here, which there probably will never be, make vertical */
/*  space at page top with \titles{...}.  headlog=.false.<=>no real titles */

		    puttitle_(&inhnoh, &xnsttop[ipage - 1], &etatop, all_1.sq,
			     &etait, &etatc, &etacs1, &all_1.nv, &vshrink, 
			    all_1.sepsymq, (ftnlen)1, (ftnlen)1);
		} else {

/*  First bar of system, not a new page, force line break */

		    if (bit_test(iplnow,28)) {

/*  Signature change */

/* Writing concatenation */
			i__11[0] = 1, a__7[0] = all_1.sq;
			i__11[1] = 4, a__7[1] = "xbar";
			i__11[2] = 1, a__7[2] = all_1.sq;
			i__11[3] = 10, a__7[3] = "addspace{-";
			i__11[4] = 1, a__7[4] = all_1.sq;
			i__11[5] = 14, a__7[5] = "afterruleskip}";
			i__11[6] = 1, a__7[6] = all_1.sq;
			i__11[7] = 17, a__7[7] = "generalsignature{";
			s_cat(notexq, a__7, i__11, &c__8, (ftnlen)79);
			lnote = 49;
			if (comtop_1.isig < 0) {
/* Writing concatenation */
			    i__7[0] = 49, a__4[0] = notexq;
			    i__7[1] = 1, a__4[1] = "-";
			    s_cat(notexq, a__4, i__7, &c__2, (ftnlen)79);
			    lnote = 50;
			}
			if (comlast_1.islast) {
			    s_wsfe(&io___435);
/* Writing concatenation */
			    i__6[0] = lnote, a__3[0] = notexq;
			    i__5 = abs(comtop_1.isig) + 48;
			    chax_(ch__1, (ftnlen)1, &i__5);
			    i__6[1] = 1, a__3[1] = ch__1;
			    i__6[2] = 2, a__3[2] = "}%";
			    s_cat(ch__18, a__3, i__6, &c__3, (ftnlen)82);
			    do_fio(&c__1, ch__18, lnote + 3);
			    e_wsfe();
			}
			if (comlast_1.islast) {
			    s_wsfe(&io___436);
/* Writing concatenation */
			    i__4[0] = 1, a__2[0] = all_1.sq;
			    i__4[1] = 7, a__2[1] = "advance";
			    i__4[2] = 1, a__2[2] = all_1.sq;
			    i__4[3] = 8, a__2[3] = "barno-1%";
			    s_cat(ch__23, a__2, i__4, &c__4, (ftnlen)17);
			    do_fio(&c__1, ch__23, (ftnlen)17);
			    e_wsfe();
			}
			if (all_1.mtrnuml != 0) {

/*  Meter+sig change, new line, may need mods if movement break here. */

			    setmeter_(&all_1.mtrnuml, &all_1.mtrdenl, &
				    combeam_1.ibmtyp, &ibmrep);
			    if (comlast_1.islast) {
				wgmeter_(&all_1.mtrnmp, &all_1.mtrdnp);
				s_wsfe(&io___437);
/* Writing concatenation */
				i__3[0] = 1, a__1[0] = all_1.sq;
				i__3[1] = 14, a__1[1] = "xchangecontext";
				i__3[2] = 1, a__1[2] = all_1.sq;
				i__3[3] = 10, a__1[3] = "addspace{-";
				i__3[4] = 1, a__1[4] = all_1.sq;
				i__3[5] = 14, a__1[5] = "afterruleskip}";
				i__3[6] = 1, a__1[6] = all_1.sq;
				i__3[7] = 3, a__1[7] = "def";
				i__3[8] = 1, a__1[8] = all_1.sq;
				i__3[9] = 13, a__1[9] = "writezbarno{}";
				i__3[10] = 1, a__1[10] = all_1.sq;
				i__3[11] = 10, a__1[11] = "zalaligne%";
				s_cat(ch__24, a__1, i__3, &c__12, (ftnlen)70);
				do_fio(&c__1, ch__24, (ftnlen)70);
				e_wsfe();
				s_wsfe(&io___438);
/* Writing concatenation */
				i__4[0] = 1, a__2[0] = all_1.sq;
				i__4[1] = 10, a__2[1] = "addspace{-";
				i__4[2] = 1, a__2[2] = all_1.sq;
				i__4[3] = 15, a__2[3] = "afterruleskip}%";
				s_cat(ch__25, a__2, i__4, &c__4, (ftnlen)27);
				do_fio(&c__1, ch__25, (ftnlen)27);
				e_wsfe();
				wgmeter_(&all_1.mtrnmp, &all_1.mtrdnp);
				s_wsfe(&io___439);
/* Writing concatenation */
				i__7[0] = 1, a__4[0] = all_1.sq;
				i__7[1] = 14, a__4[1] = "zchangecontext";
				s_cat(ch__9, a__4, i__7, &c__2, (ftnlen)15);
				do_fio(&c__1, ch__9, (ftnlen)15);
				e_wsfe();
			    }
			} else {
			    if (comlast_1.islast) {
				s_wsfe(&io___440);
/* Writing concatenation */
				i__3[0] = 1, a__1[0] = all_1.sq;
				i__3[1] = 14, a__1[1] = "xchangecontext";
				i__3[2] = 1, a__1[2] = all_1.sq;
				i__3[3] = 10, a__1[3] = "addspace{-";
				i__3[4] = 1, a__1[4] = all_1.sq;
				i__3[5] = 14, a__1[5] = "afterruleskip}";
				i__3[6] = 1, a__1[6] = all_1.sq;
				i__3[7] = 3, a__1[7] = "def";
				i__3[8] = 1, a__1[8] = all_1.sq;
				i__3[9] = 13, a__1[9] = "writezbarno{}";
				i__3[10] = 1, a__1[10] = all_1.sq;
				i__3[11] = 10, a__1[11] = "zalaligne%";
				s_cat(ch__24, a__1, i__3, &c__12, (ftnlen)70);
				do_fio(&c__1, ch__24, (ftnlen)70);
				e_wsfe();
			    }
			}
		    } else if (all_1.mtrnuml == 0) {

/*  No meter change */

			if (comlast_1.islast) {
			    s_wsfe(&io___441);
/* Writing concatenation */
			    i__7[0] = 1, a__4[0] = all_1.sq;
			    i__7[1] = 8, a__4[1] = "alaligne";
			    s_cat(ch__11, a__4, i__7, &c__2, (ftnlen)9);
			    do_fio(&c__1, ch__11, (ftnlen)9);
			    e_wsfe();
			}
		    } else {

/*  New meter, no new sig, end of line, not new page. */

/* \generalmeter{\meterfrac{3}{4}}% */
/* \xchangecontext\addspace{-\afterruleskip}% */
/* \zalaligne\generalmeter{\meterfrac{3}{4}}\addspace{-\afterruleskip}% */
/* \zchangecontext */

			setmeter_(&all_1.mtrnuml, &all_1.mtrdenl, &
				combeam_1.ibmtyp, &ibmrep);
			if (comget_1.movbrk == 0) {
			    if (comlast_1.islast) {
				wgmeter_(&all_1.mtrnmp, &all_1.mtrdnp);
			    }
			    if (all_1.mtrdnp > 0) {
				if (comlast_1.islast) {
				    s_wsfe(&io___442);
/* Writing concatenation */
				    i__3[0] = 1, a__1[0] = all_1.sq;
				    i__3[1] = 3, a__1[1] = "let";
				    i__3[2] = 1, a__1[2] = all_1.sq;
				    i__3[3] = 4, a__1[3] = "bnat";
				    i__3[4] = 1, a__1[4] = all_1.sq;
				    i__3[5] = 8, a__1[5] = "barnoadd";
				    i__3[6] = 1, a__1[6] = all_1.sq;
				    i__3[7] = 3, a__1[7] = "def";
				    i__3[8] = 1, a__1[8] = all_1.sq;
				    i__3[9] = 9, a__1[9] = "barnoadd{";
				    i__3[10] = 1, a__1[10] = all_1.sq;
				    i__3[11] = 7, a__1[11] = "empty}%";
				    s_cat(ch__26, a__1, i__3, &c__12, (ftnlen)
					    40);
				    do_fio(&c__1, ch__26, (ftnlen)40);
				    e_wsfe();
				    s_wsfe(&io___443);
/* Writing concatenation */
				    i__12[0] = 1, a__8[0] = all_1.sq;
				    i__12[1] = 14, a__8[1] = "xchangecontext";
				    i__12[2] = 1, a__8[2] = all_1.sq;
				    i__12[3] = 10, a__8[3] = "addspace{-";
				    i__12[4] = 1, a__8[4] = all_1.sq;
				    i__12[5] = 14, a__8[5] = "afterruleskip}";
				    i__12[6] = 1, a__8[6] = all_1.sq;
				    i__12[7] = 9, a__8[7] = "zalaligne";
				    i__12[8] = 1, a__8[8] = all_1.sq;
				    i__12[9] = 3, a__8[9] = "let";
				    i__12[10] = 1, a__8[10] = all_1.sq;
				    i__12[11] = 8, a__8[11] = "barnoadd";
				    i__12[12] = 1, a__8[12] = all_1.sq;
				    i__12[13] = 4, a__8[13] = "bnat";
				    s_cat(ch__27, a__8, i__12, &c__14, (
					    ftnlen)69);
				    do_fio(&c__1, ch__27, (ftnlen)69);
				    e_wsfe();
				    wgmeter_(&all_1.mtrnmp, &all_1.mtrdnp);
				    s_wsfe(&io___444);
/* Writing concatenation */
				    i__13[0] = 1, a__9[0] = all_1.sq;
				    i__13[1] = 10, a__9[1] = "addspace{-";
				    i__13[2] = 1, a__9[2] = all_1.sq;
				    i__13[3] = 14, a__9[3] = "afterruleskip}";
				    i__13[4] = 1, a__9[4] = all_1.sq;
				    i__13[5] = 14, a__9[5] = "zchangecontext";
				    s_cat(ch__28, a__9, i__13, &c__6, (ftnlen)
					    41);
				    do_fio(&c__1, ch__28, (ftnlen)41);
				    e_wsfe();
				}
				if (all_1.ibar == comgrace_1.ibarmbr) {
				    comgrace_1.xb4mbr = comstart_1.facmtr * 
					    all_1.musicsize;
				}
			    } else {
				if (comlast_1.islast) {
				    s_wsfe(&io___445);
/* Writing concatenation */
				    i__7[0] = 1, a__4[0] = all_1.sq;
				    i__7[1] = 8, a__4[1] = "alaligne";
				    s_cat(ch__11, a__4, i__7, &c__2, (ftnlen)
					    9);
				    do_fio(&c__1, ch__11, (ftnlen)9);
				    e_wsfe();
				}
			    }
			} else {
			    if (comlast_1.islast) {
				s_wsfe(&io___446);
/* Writing concatenation */
				i__7[0] = 1, a__4[0] = all_1.sq;
				i__7[1] = 8, a__4[1] = "alaligne";
				s_cat(ch__11, a__4, i__7, &c__2, (ftnlen)9);
				do_fio(&c__1, ch__11, (ftnlen)9);
				e_wsfe();
			    }
			}
		    }
		}
		if (slint) {
		    slint = FALSE_;
		    if (comlast_1.islast) {
			s_wsfe(&io___447);
/* Writing concatenation */
			i__4[0] = 1, a__2[0] = all_1.sq;
			i__4[1] = 3, a__2[1] = "def";
			i__4[2] = 1, a__2[2] = all_1.sq;
			i__4[3] = 11, a__2[3] = "raisebarno{";
			s_cat(ch__15, a__2, i__4, &c__4, (ftnlen)16);
			do_fio(&c__1, ch__15, (ftnlen)16);
			do_fio(&c__1, (char *)&comsln_1.irzbnd, (ftnlen)
				sizeof(integer));
/* Writing concatenation */
			i__6[0] = 2, a__3[0] = ".5";
			i__6[1] = 1, a__3[1] = all_1.sq;
			i__6[2] = 11, a__3[2] = "internote}%";
			s_cat(ch__8, a__3, i__6, &c__3, (ftnlen)14);
			do_fio(&c__1, ch__8, (ftnlen)14);
			e_wsfe();
		    }
		}
		comget_1.movbrk = 0;
	    }

/*  Clean up if we squelched bar number reset at movement break */

	    if (comnotes_1.nobar1) {
		if (comlast_1.islast) {
		    s_wsfe(&io___448);
/* Writing concatenation */
		    i__7[0] = 1, a__4[0] = all_1.sq;
		    i__7[1] = 11, a__4[1] = "startbarno1";
		    s_cat(ch__7, a__4, i__7, &c__2, (ftnlen)12);
		    do_fio(&c__1, ch__7, (ftnlen)12);
		    e_wsfe();
		}
		comnotes_1.nobar1 = FALSE_;
	    }
	    i__5 = s_rsle(&io___449);
	    if (i__5 != 0) {
		goto L14;
	    }
	    i__5 = do_lio(&c__3, &c__1, (char *)&iauto, (ftnlen)sizeof(
		    integer));
	    if (i__5 != 0) {
		goto L14;
	    }
	    i__5 = e_rsle();
	    if (i__5 != 0) {
		goto L14;
	    }
L14:

/*  We come thru here for the 1st bar of every system, so initialize is1n1 */

	    comsln_1.is1n1 = 0;
	} else {

/*  Not first bar of system */

	    if (bit_test(iplnow,28)) {

/*  Signature change */

		if (all_1.mtrnuml != 0) {

/*  Meter+signature change mid line, assume no movement break */

		    setmeter_(&all_1.mtrnuml, &all_1.mtrdenl, &
			    combeam_1.ibmtyp, &ibmrep);
		    if (comlast_1.islast) {
			wgmeter_(&all_1.mtrnmp, &all_1.mtrdnp);
		    }
/* Writing concatenation */
		    i__7[0] = 1, a__4[0] = all_1.sq;
		    i__7[1] = 17, a__4[1] = "generalsignature{";
		    s_cat(notexq, a__4, i__7, &c__2, (ftnlen)79);
		    lnote = 18;
		    if (comtop_1.isig < 0) {
/* Writing concatenation */
			i__7[0] = 18, a__4[0] = notexq;
			i__7[1] = 1, a__4[1] = "-";
			s_cat(notexq, a__4, i__7, &c__2, (ftnlen)79);
			lnote = 19;
		    }
		    if (comlast_1.islast) {
			iptemp = abs(comtop_1.isig) + 48;
			chax_(ch__1, (ftnlen)1, &iptemp);
			*(unsigned char *)charq = *(unsigned char *)&ch__1[0];
/* Writing concatenation */
			i__8[0] = lnote, a__5[0] = notexq;
			i__8[1] = 1, a__5[1] = charq;
			i__8[2] = 1, a__5[2] = "}";
			i__8[3] = 1, a__5[3] = all_1.sq;
			i__8[4] = 15, a__5[4] = "xchangecontext%";
			s_cat(notexq, a__5, i__8, &c__5, (ftnlen)79);
			s_wsfe(&io___452);
			do_fio(&c__1, notexq, lnote + 18);
			e_wsfe();
		    }
		} else {

/*  Signature change only */

/* Writing concatenation */
		    i__11[0] = 1, a__7[0] = all_1.sq;
		    i__11[1] = 4, a__7[1] = "xbar";
		    i__11[2] = 1, a__7[2] = all_1.sq;
		    i__11[3] = 10, a__7[3] = "addspace{-";
		    i__11[4] = 1, a__7[4] = all_1.sq;
		    i__11[5] = 14, a__7[5] = "afterruleskip}";
		    i__11[6] = 1, a__7[6] = all_1.sq;
		    i__11[7] = 17, a__7[7] = "generalsignature{";
		    s_cat(notexq, a__7, i__11, &c__8, (ftnlen)79);
		    lnote = 49;
		    if (comtop_1.isig < 0) {
/* Writing concatenation */
			i__7[0] = 49, a__4[0] = notexq;
			i__7[1] = 1, a__4[1] = "-";
			s_cat(notexq, a__4, i__7, &c__2, (ftnlen)79);
			lnote = 50;
		    }
		    if (comlast_1.islast) {
			s_wsfe(&io___453);
/* Writing concatenation */
			i__6[0] = lnote, a__3[0] = notexq;
			i__5 = abs(comtop_1.isig) + 48;
			chax_(ch__1, (ftnlen)1, &i__5);
			i__6[1] = 1, a__3[1] = ch__1;
			i__6[2] = 2, a__3[2] = "}%";
			s_cat(ch__18, a__3, i__6, &c__3, (ftnlen)82);
			do_fio(&c__1, ch__18, lnote + 3);
			e_wsfe();
		    }
		    if (comlast_1.islast) {
			s_wsfe(&io___454);
/* Writing concatenation */
			i__13[0] = 1, a__9[0] = all_1.sq;
			i__13[1] = 14, a__9[1] = "zchangecontext";
			i__13[2] = 1, a__9[2] = all_1.sq;
			i__13[3] = 12, a__9[3] = "addspace{-.5";
			i__13[4] = 1, a__9[4] = all_1.sq;
			i__13[5] = 15, a__9[5] = "afterruleskip}%";
			s_cat(ch__29, a__9, i__13, &c__6, (ftnlen)44);
			do_fio(&c__1, ch__29, (ftnlen)44);
			e_wsfe();
		    }
		}
	    } else if (all_1.mtrnuml == 0) {

/*  No meter change */

		if (comlast_1.islast) {
		    s_wsfe(&io___455);
/* Writing concatenation */
		    i__7[0] = 1, a__4[0] = all_1.sq;
		    i__7[1] = 4, a__4[1] = "xbar";
		    s_cat(ch__30, a__4, i__7, &c__2, (ftnlen)5);
		    do_fio(&c__1, ch__30, (ftnlen)5);
		    e_wsfe();
		}
	    } else {

/*  Change meter midline */

		setmeter_(&all_1.mtrnuml, &all_1.mtrdenl, &combeam_1.ibmtyp, &
			ibmrep);
		if (comget_1.movbrk == 0) {
		    if (comlast_1.islast) {
			wgmeter_(&all_1.mtrnmp, &all_1.mtrdnp);
		    }
		    if (all_1.mtrdnp > 0) {
			if (comlast_1.islast) {
			    s_wsfe(&io___456);
/* Writing concatenation */
			    i__7[0] = 1, a__4[0] = all_1.sq;
			    i__7[1] = 10, a__4[1] = "newtimes0%";
			    s_cat(ch__12, a__4, i__7, &c__2, (ftnlen)11);
			    do_fio(&c__1, ch__12, (ftnlen)11);
			    e_wsfe();
			}
			if (all_1.ibar == comgrace_1.ibarmbr) {
			    comgrace_1.xb4mbr = comstart_1.facmtr * 
				    all_1.musicsize;
			}
		    } else {
			if (comlast_1.islast) {
			    s_wsfe(&io___457);
/* Writing concatenation */
			    i__7[0] = 1, a__4[0] = all_1.sq;
			    i__7[1] = 4, a__4[1] = "xbar";
			    s_cat(ch__30, a__4, i__7, &c__2, (ftnlen)5);
			    do_fio(&c__1, ch__30, (ftnlen)5);
			    e_wsfe();
			}
		    }
		}
	    }
	}

/*  Now that xbar's are written, can put in left-repeats at line beginnings */

	if (lrptpend) {
	    if (comlast_1.islast) {
		s_wsfe(&io___458);
/* Writing concatenation */
		i__13[0] = 1, a__9[0] = all_1.sq;
		i__13[1] = 7, a__9[1] = "advance";
		i__13[2] = 1, a__9[2] = all_1.sq;
		i__13[3] = 7, a__9[3] = "barno-1";
		i__13[4] = 1, a__9[4] = all_1.sq;
		i__13[5] = 10, a__9[5] = "leftrepeat";
		s_cat(ch__25, a__9, i__13, &c__6, (ftnlen)27);
		do_fio(&c__1, ch__25, (ftnlen)27);
		e_wsfe();
	    }
	    lrptpend = FALSE_;
	}
	if (all_1.ibar > 1) {

/*  For bars after first, slide all stuff down to beginning of arrays */

	    i__5 = all_1.nv;
	    for (all_1.iv = 1; all_1.iv <= i__5; ++all_1.iv) {
		i__2 = commvl_1.nvmx[all_1.iv - 1];
		for (kv = 1; kv <= i__2; ++kv) {
		    commvl_1.ivx = commvl_1.ivmx[all_1.iv + kv * 15 - 16];
		    ioff = all_1.nib[commvl_1.ivx + (all_1.ibar - 1) * 15 - 
			    16];
		    i__10 = all_1.nib[commvl_1.ivx + all_1.ibar * 15 - 16] - 
			    ioff;
		    for (ip = 1; ip <= i__10; ++ip) {
			all_1.nolev[commvl_1.ivx + ip * 15 - 16] = 
				all_1.nolev[commvl_1.ivx + (ip + ioff) * 15 - 
				16];
			all_1.nodur[commvl_1.ivx + ip * 15 - 16] = 
				all_1.nodur[commvl_1.ivx + (ip + ioff) * 15 - 
				16];
			all_1.nacc[commvl_1.ivx + ip * 15 - 16] = all_1.nacc[
				commvl_1.ivx + (ip + ioff) * 15 - 16];
			all_1.irest[commvl_1.ivx + ip * 15 - 16] = 
				all_1.irest[commvl_1.ivx + (ip + ioff) * 15 - 
				16];
			all_1.islur[commvl_1.ivx + ip * 15 - 16] = 
				all_1.islur[commvl_1.ivx + (ip + ioff) * 15 - 
				16];
			all_1.ipl[commvl_1.ivx + ip * 15 - 16] = all_1.ipl[
				commvl_1.ivx + (ip + ioff) * 15 - 16];
			all_1.iornq[commvl_1.ivx + ip * 15 - 1] = all_1.iornq[
				commvl_1.ivx + (ip + ioff) * 15 - 1];
			if (commvl_1.ivx == 1 && all_1.figbass) {
			    all_1.isfig[ip - 1] = all_1.isfig[ip + ioff - 1];
			}
/* L12: */
		    }
		    if (commvl_1.ivx <= all_1.nv && comcc_1.ncc[all_1.iv - 1] 
			    > 1) {
			islide = 0;
			i__10 = comcc_1.ncc[all_1.iv - 1];
			for (icc = 1; icc <= i__10; ++icc) {
			    if (comcc_1.tcc[all_1.iv + icc * 15 - 16] <= (
				    real) all_1.lenbar) {

/*  This time will drop <=0 when slid. */

				islide = icc - 1;
				comcc_1.ncmidcc[all_1.iv - 1] = 
					comcc_1.ncmidcc[all_1.iv + icc * 15 - 
					16];
			    } else {
				comcc_1.tcc[all_1.iv + (icc - islide) * 15 - 
					16] = comcc_1.tcc[all_1.iv + icc * 15 
					- 16] - all_1.lenbar;
				comcc_1.ncmidcc[all_1.iv + (icc - islide) * 
					15 - 16] = comcc_1.ncmidcc[all_1.iv + 
					icc * 15 - 16];
			    }
/* L13: */
			}
			comcc_1.ncc[all_1.iv - 1] -= islide;
			comcc_1.tcc[all_1.iv - 1] = (float)0.;
		    }
/* L11: */
		}
	    }
	    i__2 = comgrace_1.ngrace;
	    for (ig = 1; ig <= i__2; ++ig) {
		comgrace_1.ipg[ig - 1] -= all_1.nib[comgrace_1.ivg[ig - 1] + (
			all_1.ibar - 1) * 15 - 16];
		if (all_1.ibar > 2) {
		    comgrace_1.ipg[ig - 1] += all_1.nib[comgrace_1.ivg[ig - 1]
			     + (all_1.ibar - 2) * 15 - 16];
		}
/* L15: */
	    }
	    i__2 = comgrace_1.nlit;
	    for (il = 1; il <= i__2; ++il) {
		comgrace_1.iplit[il - 1] -= all_1.nib[comgrace_1.ivlit[il - 1]
			 + (all_1.ibar - 1) * 15 - 16];
		if (all_1.ibar > 2) {
		    comgrace_1.iplit[il - 1] += all_1.nib[comgrace_1.ivlit[il 
			    - 1] + (all_1.ibar - 2) * 15 - 16];
		}
/* L21: */
	    }
	    i__2 = comtrill_1.ntrill;
	    for (it = 1; it <= i__2; ++it) {
		comtrill_1.iptrill[it - 1] -= all_1.nib[comtrill_1.ivtrill[it 
			- 1] + (all_1.ibar - 1) * 15 - 16];
		if (all_1.ibar > 2) {
		    comtrill_1.iptrill[it - 1] += all_1.nib[
			    comtrill_1.ivtrill[it - 1] + (all_1.ibar - 2) * 
			    15 - 16];
		}
/* L22: */
	    }
	    i__2 = comtrill_1.ncrd;
	    for (icrd = 1; icrd <= i__2; ++icrd) {
		commvl_1.ivx = 15 & lbit_shift(comtrill_1.icrdat[icrd - 1], (
			ftnlen)-8);
		ipnew = (255 & comtrill_1.icrdat[icrd - 1]) - all_1.nib[
			commvl_1.ivx + (all_1.ibar - 1) * 15 - 16];
		if (all_1.ibar > 2) {
		    ipnew += all_1.nib[commvl_1.ivx + (all_1.ibar - 2) * 15 - 
			    16];
		}
		comtrill_1.icrdat[icrd - 1] = -256 & comtrill_1.icrdat[icrd - 
			1];
		comtrill_1.icrdat[icrd - 1] = max(0,ipnew) | 
			comtrill_1.icrdat[icrd - 1];
/* L27: */
	    }
	    i__2 = comtrill_1.nudorn;
	    for (iudorn = 1; iudorn <= i__2; ++iudorn) {
		commvl_1.ivx = 15 & lbit_shift(comtrill_1.kudorn[iudorn - 1], 
			(ftnlen)-8);
		ipnew = (255 & comtrill_1.kudorn[iudorn - 1]) - all_1.nib[
			commvl_1.ivx + (all_1.ibar - 1) * 15 - 16];
		if (all_1.ibar > 2) {
		    ipnew += all_1.nib[commvl_1.ivx + (all_1.ibar - 2) * 15 - 
			    16];
		}
		comtrill_1.kudorn[iudorn - 1] = -256 & comtrill_1.kudorn[
			iudorn - 1];
		comtrill_1.kudorn[iudorn - 1] = max(0,ipnew) | 
			comtrill_1.kudorn[iudorn - 1];
/* L29: */
	    }
	    i__2 = comdyn_1.ndyn;
	    for (idyn = 1; idyn <= i__2; ++idyn) {
		idynd = comdyn_1.idyndat[idyn - 1];
		commvl_1.ivx = 15 & idynd;
		ipnew = igetbits_(&idynd, &c__8, &c__4) - all_1.nib[
			commvl_1.ivx + (all_1.ibar - 1) * 15 - 16];
		if (all_1.ibar > 2) {
		    ipnew += all_1.nib[commvl_1.ivx + (all_1.ibar - 2) * 15 - 
			    16];
		}
		ipnew = i_dim(&ipnew, &c__0);
		setbits_(&idynd, &c__8, &c__4, &ipnew);
		comdyn_1.idyndat[idyn - 1] = idynd;
/* L42: */
	    }
	    i__2 = all_1.nsdat;
	    for (isdat = 1; isdat <= i__2; ++isdat) {
		isdata = all_1.isdat1[isdat - 1];
		commvl_1.ivx = commvl_1.ivmx[igetbits_(&isdata, &c__5, &c__13)
			 + (igetbits_(&isdata, &c__1, &c__12) + 1) * 15 - 16];
		ipnew = igetbits_(&isdata, &c__8, &c__3) - all_1.nib[
			commvl_1.ivx + (all_1.ibar - 1) * 15 - 16];
		if (all_1.ibar > 2) {
		    ipnew += all_1.nib[commvl_1.ivx + (all_1.ibar - 2) * 15 - 
			    16];
		}
		ipnew = i_dim(&ipnew, &c__0);
		setbits_(&isdata, &c__8, &c__3, &ipnew);
		all_1.isdat1[isdat - 1] = isdata;
/* L41: */
	    }

/*  Bookkeeping for figures.  This will set nfigs = 0 if there are no figs left. */
/*  If there are figs left, it will reset all times relative to start of */
/*  current bar. */

	    if (all_1.figbass) {
		islide = 0;
		i__2 = comfig_1.nfigs;
		for (jfig = 1; jfig <= i__2; ++jfig) {
		    if (comfig_1.itfig[jfig - 1] < all_1.lenbar) {

/*  This figure was already used */

			islide = jfig;
		    } else {
			comfig_1.itfig[jfig - islide - 1] = comfig_1.itfig[
				jfig - 1] - all_1.lenbar;
			s_copy(comfig_1.figq + (jfig - islide - 1) * 6, 
				comfig_1.figq + (jfig - 1) * 6, (ftnlen)6, (
				ftnlen)6);
			comgrace_1.itoff[jfig - islide - 1] = 
				comgrace_1.itoff[jfig - 1];
		    }
/* L20: */
		}
		comfig_1.nfigs -= islide;
	    }
	}

/*  The following may not be needed by makeabar, but just in case... */

	if (all_1.firstgulp && all_1.lenb0 != 0) {
	    if (all_1.ibar == 1) {
		all_1.lenbar = all_1.lenb0;
	    } else {
		all_1.lenbar = all_1.lenb1;
	    }
	}
	make1bar_(&ibmrep, &tglp1, tstart, cwrest, squez, istop, numbms, 
		istart);
	make2bar_(&ninow, &tglp1, tstart, cwrest, squez, istop, numbms, 
		istart, clefq, (ftnlen)1);

/*  Hardspace before barline? */

	hardb4 = (float)0.;
	i__2 = all_1.nv;
	for (all_1.iv = 1; all_1.iv <= i__2; ++all_1.iv) {
	    i__5 = commvl_1.nvmx[all_1.iv - 1];
	    for (kv = 1; kv <= i__5; ++kv) {
		commvl_1.ivx = commvl_1.ivmx[all_1.iv + kv * 15 - 16];
		if (bit_test(all_1.irest[commvl_1.ivx + all_1.nn[commvl_1.ivx 
			- 1] * 15 - 16],18)) {
		    ++comudsp_1.nudoff[commvl_1.ivx - 1];
/* Computing MAX */
		    r__1 = hardb4, r__2 = comudsp_1.udoff[commvl_1.ivx + 
			    comudsp_1.nudoff[commvl_1.ivx - 1] * 15 - 16];
		    hardb4 = dmax(r__1,r__2);
		}
/* L35: */
	    }
	}
	if (hardb4 > (float)0.) {
	    if (comlast_1.islast) {
		s_wsfe(&io___478);
/* Writing concatenation */
		i__7[0] = 1, a__4[0] = all_1.sq;
		i__7[1] = 10, a__4[1] = "hardspace{";
		s_cat(ch__12, a__4, i__7, &c__2, (ftnlen)11);
		do_fio(&c__1, ch__12, (ftnlen)11);
		do_fio(&c__1, (char *)&hardb4, (ftnlen)sizeof(real));
		do_fio(&c__1, "pt}%", (ftnlen)4);
		e_wsfe();
	    }
	    comask_1.fixednew -= hardb4;
	}
/* L10: */
    }
    all_1.firstgulp = FALSE_;
    all_1.lenb0 = 0;
    goto L30;
L40:
    cl__1.cerr = 0;
    cl__1.cunit = 12;
    cl__1.csta = 0;
    f_clos(&cl__1);
    cl__1.cerr = 0;
    cl__1.cunit = 13;
    cl__1.csta = 0;
    f_clos(&cl__1);
    inbuff_1.ilbuf = 1;
    inbuff_1.ipbuf = 0;
    wdpt = comtop_1.widthpt;
    if (all_1.iline == 1) {
	wdpt = comtop_1.widthpt * (1 - comtop_1.fracindent);
    }
    poe = (wdpt - fsyst * all_1.musicsize - nbarss * (float).4 - 
	    comask_1.fixednew) / (elsktot + comask_1.fbar * nbarss - 
	    comask_1.scaldold);
    poevec[nsyst] = poe;
    if (! comlast_1.islast) {
	cl__1.cerr = 0;
	cl__1.cunit = 11;
	cl__1.csta = 0;
	f_clos(&cl__1);
	cl__1.cerr = 0;
	cl__1.cunit = 16;
	cl__1.csta = 0;
	f_clos(&cl__1);
	if (all_1.figbass) {
	    cl__1.cerr = 0;
	    cl__1.cunit = 14;
	    cl__1.csta = 0;
	    f_clos(&cl__1);
	}
	return 0;
    }
    i__1 = comas2_1.nasksys;
    for (ia = 1; ia <= i__1; ++ia) {
	++comas3_1.iask;
	comas3_1.ask[comas3_1.iask - 1] = comas2_1.wasksys[ia - 1] / poe - (
		r__1 = comas2_1.elasksys[ia - 1], dabs(r__1));
	if (comas2_1.elasksys[ia - 1] > (float)0.) {
	    comas3_1.ask[comas3_1.iask - 1] = r_dim(&comas3_1.ask[
		    comas3_1.iask - 1], &c_b1398);
	}
/* L19: */
    }
    i__1 = nhssys;
    for (ia = 1; ia <= i__1; ++ia) {
	++nhstot;
/* Computing MAX */
	r__1 = hpts[ia - 1] - hesk[ia - 1] * poe;
	comhsp_1.hpttot[nhstot - 1] = dmax(r__1,(float)0.);
/* L26: */
    }
    if (comlast_1.islast && onvolt) {
	s_wsfe(&io___479);
/* Writing concatenation */
	i__7[0] = 1, a__4[0] = all_1.sq;
	i__7[1] = 11, a__4[1] = "endvoltabox";
	s_cat(ch__7, a__4, i__7, &c__2, (ftnlen)12);
	do_fio(&c__1, ch__7, (ftnlen)12);
	e_wsfe();
    }
    if (*(unsigned char *)comget_1.rptfq2 != 'E') {

/* Terminal repeat.  Right or double? */

	if (*(unsigned char *)comget_1.rptfq2 == 'r') {
	    if (comlast_1.islast) {
		s_wsfe(&io___480);
/* Writing concatenation */
		i__4[0] = 1, a__2[0] = all_1.sq;
		i__4[1] = 14, a__2[1] = "setrightrepeat";
		i__4[2] = 1, a__2[2] = all_1.sq;
		i__4[3] = 8, a__2[3] = "endpiece";
		s_cat(ch__31, a__2, i__4, &c__4, (ftnlen)24);
		do_fio(&c__1, ch__31, (ftnlen)24);
		e_wsfe();
	    }
	} else if (*(unsigned char *)comget_1.rptfq2 == 'd') {
	    if (comlast_1.islast) {
		s_wsfe(&io___481);
/* Writing concatenation */
		i__4[0] = 1, a__2[0] = all_1.sq;
		i__4[1] = 12, a__2[1] = "setdoublebar";
		i__4[2] = 1, a__2[2] = all_1.sq;
		i__4[3] = 8, a__2[3] = "endpiece";
		s_cat(ch__13, a__2, i__4, &c__4, (ftnlen)22);
		do_fio(&c__1, ch__13, (ftnlen)22);
		e_wsfe();
	    }
	} else if (*(unsigned char *)comget_1.rptfq2 == 'b') {
	    if (comlast_1.islast) {
		s_wsfe(&io___482);
/* Writing concatenation */
		i__7[0] = 1, a__4[0] = all_1.sq;
		i__7[1] = 8, a__4[1] = "endpiece";
		s_cat(ch__11, a__4, i__7, &c__2, (ftnlen)9);
		do_fio(&c__1, ch__11, (ftnlen)9);
		e_wsfe();
	    }
	} else {
	    s_wsle(&io___483);
	    do_lio(&c__9, &c__1, "R? , ? not \"d\",\"r\",or\"b\"; rptfq2:", (
		    ftnlen)33);
	    do_lio(&c__9, &c__1, comget_1.rptfq2, (ftnlen)1);
	    e_wsle();
	    if (comlast_1.islast) {
		s_wsfe(&io___484);
/* Writing concatenation */
		i__7[0] = 1, a__4[0] = all_1.sq;
		i__7[1] = 8, a__4[1] = "Endpiece";
		s_cat(ch__11, a__4, i__7, &c__2, (ftnlen)9);
		do_fio(&c__1, ch__11, (ftnlen)9);
		e_wsfe();
	    }
	}
    } else {
	if (comlast_1.islast) {
	    s_wsfe(&io___485);
/* Writing concatenation */
	    i__7[0] = 1, a__4[0] = all_1.sq;
	    i__7[1] = 8, a__4[1] = "Endpiece";
	    s_cat(ch__11, a__4, i__7, &c__2, (ftnlen)9);
	    do_fio(&c__1, ch__11, (ftnlen)9);
	    e_wsfe();
	}
    }
    if (! vshrink) {
	xnstbot = xnsttop[ipage - 1] * etabot / etatop;
	if (xnstbot < (float)9.95) {
	    s_copy(fmtq, "(a,f3.1,a)", (ftnlen)24, (ftnlen)10);
	} else {
	    s_copy(fmtq, "(a,f4.1,a)", (ftnlen)24, (ftnlen)10);
	}
	if (comlast_1.islast) {
	    s_wsfe(&io___486);
/* Writing concatenation */
	    i__7[0] = 1, a__4[0] = all_1.sq;
	    i__7[1] = 5, a__4[1] = "vskip";
	    s_cat(ch__22, a__4, i__7, &c__2, (ftnlen)6);
	    do_fio(&c__1, ch__22, (ftnlen)6);
	    do_fio(&c__1, (char *)&xnstbot, (ftnlen)sizeof(real));
/* Writing concatenation */
	    i__13[0] = 1, a__9[0] = all_1.sq;
	    i__13[1] = 10, a__9[1] = "Interligne";
	    i__13[2] = 1, a__9[2] = all_1.sq;
	    i__13[3] = 5, a__9[3] = "eject";
	    i__13[4] = 1, a__9[4] = all_1.sq;
	    i__13[5] = 9, a__9[5] = "endmuflex";
	    s_cat(ch__25, a__9, i__13, &c__6, (ftnlen)27);
	    do_fio(&c__1, ch__25, (ftnlen)27);
	    e_wsfe();
	}
	if (comlast_1.islast) {
	    s_wsfe(&io___487);
/* Writing concatenation */
	    i__7[0] = 1, a__4[0] = all_1.sq;
	    i__7[1] = 3, a__4[1] = "bye";
	    s_cat(ch__14, a__4, i__7, &c__2, (ftnlen)4);
	    do_fio(&c__1, ch__14, (ftnlen)4);
	    e_wsfe();
	}
    } else {
	if (comlast_1.islast) {
	    s_wsfe(&io___488);
/* Writing concatenation */
	    i__13[0] = 1, a__9[0] = all_1.sq;
	    i__13[1] = 5, a__9[1] = "vfill";
	    i__13[2] = 1, a__9[2] = all_1.sq;
	    i__13[3] = 5, a__9[3] = "eject";
	    i__13[4] = 1, a__9[4] = all_1.sq;
	    i__13[5] = 9, a__9[5] = "endmuflex";
	    s_cat(ch__13, a__9, i__13, &c__6, (ftnlen)22);
	    do_fio(&c__1, ch__13, (ftnlen)22);
	    e_wsfe();
	}
	if (comlast_1.islast) {
	    s_wsfe(&io___489);
/* Writing concatenation */
	    i__7[0] = 1, a__4[0] = all_1.sq;
	    i__7[1] = 3, a__4[1] = "bye";
	    s_cat(ch__14, a__4, i__7, &c__2, (ftnlen)4);
	    do_fio(&c__1, ch__14, (ftnlen)4);
	    e_wsfe();
	}
    }
    al__1.aerr = 0;
    al__1.aunit = 11;
    f_rew(&al__1);
    if (all_1.figbass) {
	s_wsfe(&io___490);
/* Writing concatenation */
	i__7[0] = 1, a__4[0] = all_1.sq;
	i__7[1] = 8, a__4[1] = "figdrop=";
	s_cat(ch__11, a__4, i__7, &c__2, (ftnlen)9);
	do_fio(&c__1, ch__11, (ftnlen)9);
	do_fio(&c__1, (char *)&all_1.ifigdrop[all_1.iline - 1], (ftnlen)
		sizeof(integer));
/* Writing concatenation */
	i__9[0] = 1, a__6[0] = all_1.sq;
	i__9[1] = 4, a__6[1] = "fi}%";
	s_cat(ch__30, a__6, i__9, &c__2, (ftnlen)5);
	do_fio(&c__1, ch__30, (ftnlen)5);
	e_wsfe();
	al__1.aerr = 0;
	al__1.aunit = 14;
	f_rew(&al__1);
    }
    askfig_(pathnameq, &lpath, basenameq, &lbase, &all_1.figbass, &istype0, (
	    ftnlen)40, (ftnlen)24);
    if (! (*optimize)) {
	s_wsle(&io___491);
	e_wsle();
	s_wsle(&io___492);
/* Writing concatenation */
	i__4[0] = 8, a__2[0] = "Writing ";
	i__4[1] = lpath, a__2[1] = pathnameq;
	i__4[2] = lbase, a__2[2] = basenameq;
	i__4[3] = 4, a__2[3] = ".tex";
	s_cat(ch__32, a__2, i__4, &c__4, (ftnlen)76);
	do_lio(&c__9, &c__1, ch__32, lpath + 8 + lbase + 4);
	e_wsle();
	s_wsle(&io___493);
	do_lio(&c__9, &c__1, "Done with second PMX pass.", (ftnlen)26);
	e_wsle();
	s_wsfe(&io___494);
/* Writing concatenation */
	i__4[0] = 8, a__2[0] = "Writing ";
	i__4[1] = lpath, a__2[1] = pathnameq;
	i__4[2] = lbase, a__2[2] = basenameq;
	i__4[3] = 4, a__2[3] = ".tex";
	s_cat(ch__32, a__2, i__4, &c__4, (ftnlen)76);
	do_fio(&c__1, ch__32, lpath + 8 + lbase + 4);
	e_wsfe();
	s_wsfe(&io___495);
	do_fio(&c__1, " Done with second PMX pass.  Now run TeX", (ftnlen)40);
	e_wsfe();
    }
    return 0;
} /* pmxb_ */

/* Subroutine */ int make2bar_(ninow, tglp1, tstart, cwrest, squez, istop, 
	numbms, istart, clefq, clefq_len)
integer *ninow;
real *tglp1, *tstart;
logical *cwrest;
real *squez;
integer *istop, *numbms, *istart;
char *clefq;
ftnlen clefq_len;
{
    /* System generated locals */
    address a__1[6], a__2[3], a__3[2], a__4[4], a__5[8], a__6[5], a__7[7];
    integer i__1, i__2, i__3[6], i__4[3], i__5, i__6[2], i__7[4], i__8, i__9[
	    8], i__10, i__11[5], i__12[7], i__13, i__14;
    real r__1;
    logical L__1;
    char ch__1[82], ch__2[12], ch__3[1], ch__4[17], ch__5[16], ch__6[11], 
	    ch__7[10], ch__8[44], ch__9[81], ch__10[113], ch__11[3], ch__12[9]
	    , ch__13[129], ch__14[6], ch__15[4], ch__16[30], ch__17[7], 
	    ch__18[14], ch__19[22], ch__20[80];
    cilist ci__1;
    icilist ici__1;

    /* Builtin functions */
    integer s_wsfi(), do_fio(), e_wsfi();
    /* Subroutine */ int s_cat();
    integer s_wsfe(), e_wsfe(), lbit_shift(), i_nint(), s_wsle(), do_lio(), 
	    e_wsle();
    /* Subroutine */ int s_stop();
    integer pow_ii();
    double r_lg10();

    /* Local variables */
    static integer ib, ig, il, in, ip, kv, iib, icm, ing;
    static real esk, xnd;
    static integer iiv;
    static real wgr, pts;
    extern integer log2_();
    static integer iacc, kacc, macc, ifig, icrd, ndig;
    extern /* Character */ VOID chax_();
    extern doublereal feon_();
    static integer lcwr[15];
    extern /* Character */ VOID udqq_();
    static char cwrq[79*15];
    static real ptgr[37], spgr, zero;
    static integer nodu;
    static real tnow;
    extern /* Subroutine */ int eskb4_(), doacc_();
    static logical isacc;
    static integer nclef, iaskb[15];
    static logical iscln, issig;
    static integer nornb[15];
    static logical isarp, isdot;
    static integer lnote;
    static char noteq[8];
    static logical iscwr;
    static char soutq[80];
    static integer lsout, itrpt, itsig;
    extern integer ncmid_();
    static integer iirpt;
    static logical found1;
    static integer lclow;
    extern /* Subroutine */ int dodyn_(), docrd_(), beamn1_(), notex_();
    static integer lchead;
    extern /* Subroutine */ int addask_();
    static integer ibmchk;
    static logical isclef, isflag, isaccs, bspend, isgaft;
    static real ptclef[15];
    static integer ihornb[360]	/* was [15][24] */;
    static real eskndg[15], ptsndg[15];
    static logical rpndot;
    static char notexq[79];
    static logical stemup;
    static integer lnoten;
    extern /* Subroutine */ int wsclef_();
    static real eonsqz;
    extern /* Subroutine */ int chkarp_();
    static integer ihshft;
    extern /* Subroutine */ int addstr_();
    extern integer lenstr_();
    static real offnsk;
    extern /* Subroutine */ int putfig_(), putarp_(), precrd_(), doslur_();
    static integer islhgt, iphold;
    extern /* Subroutine */ int notefq_(), putorn_(), dotmov_(), beamid_();
    static integer itleft, itendb;
    extern integer iashft_();
    static integer nolevc;
    extern /* Subroutine */ int addmidi_(), beamend_();
    static integer ivlast, mtrspc;
    extern /* Subroutine */ int dograce_();
    static logical isgrace;
    static integer icashft;
    static real ptbneed, ptsneed;
    extern /* Subroutine */ int clefsym_(), endslur_(), setbits_();
    static logical isrshft, isfirst, nofirst;
    static integer itright;
    static char slurudq[1];
    extern /* Subroutine */ int putshft_();
    extern integer igetbits_();
    extern logical isdotted_();
    extern /* Subroutine */ int beamstrt_();
    static real ptsavail;
    extern /* Subroutine */ int midievent_();

    /* Fortran I/O blocks */
    static icilist io___506 = { 0, noteq, 0, "(1H{,i3,1H})", 5, 1 };
    static icilist io___508 = { 0, noteq, 0, "(1H{,i2,1H})", 4, 1 };
    static icilist io___509 = { 0, noteq, 0, "(i1)", 1, 1 };
    static cilist io___512 = { 0, 11, 0, "(a)", 0 };
    static cilist io___515 = { 0, 11, 0, "(a)", 0 };
    static icilist io___518 = { 0, soutq+8, 0, "(f4.2)", 4, 1 };
    static icilist io___519 = { 0, soutq+10, 0, "(i2)", 2, 1 };
    static icilist io___520 = { 0, soutq+11, 0, "(i1)", 1, 1 };
    static cilist io___525 = { 0, 6, 0, 0, 0 };
    static cilist io___526 = { 0, 6, 0, 0, 0 };
    static cilist io___542 = { 0, 6, 0, 0, 0 };
    static cilist io___555 = { 0, 11, 0, "(a)", 0 };
    static cilist io___556 = { 0, 11, 0, "(a)", 0 };
    static cilist io___557 = { 0, 11, 0, "(a)", 0 };
    static cilist io___558 = { 0, 11, 0, "(a)", 0 };
    static cilist io___559 = { 0, 11, 0, "(a)", 0 };
    static cilist io___560 = { 0, 6, 0, 0, 0 };
    static cilist io___561 = { 0, 11, 0, "(a)", 0 };
    static cilist io___562 = { 0, 11, 0, "(a)", 0 };
    static icilist io___565 = { 0, notexq+11, 0, "(i2)", 2, 1 };
    static icilist io___570 = { 0, notexq+6, 0, "(f3.1)", 3, 1 };
    static icilist io___571 = { 0, notexq+6, 0, "(f4.1)", 4, 1 };
    static icilist io___573 = { 0, notexq+5, 0, "(f3.1)", 3, 1 };
    static icilist io___574 = { 0, notexq+5, 0, "(f4.1)", 4, 1 };
    static cilist io___576 = { 0, 6, 0, 0, 0 };
    static cilist io___577 = { 0, 11, 0, "(a)", 0 };
    static cilist io___578 = { 0, 11, 0, "(a)", 0 };
    static cilist io___587 = { 0, 6, 0, 0, 0 };
    static cilist io___600 = { 0, 11, 0, "(a)", 0 };
    static cilist io___603 = { 0, 11, 0, "(a)", 0 };
    static cilist io___606 = { 0, 11, 0, "(a)", 0 };
    static cilist io___607 = { 0, 11, 0, "(a)", 0 };



/*  Factors for grace note, clef spacing. (fraction of wheadpt) */
/*  In 1.04, moved to block data subprogram */


/*  Set up main ib loop within which a block (notes group) is written */

    /* Parameter adjustments */
    --clefq;
    --istart;
    --numbms;
    --istop;
    --squez;
    --cwrest;
    --tstart;

    /* Function Body */
    i__1 = all_1.nv;
    for (all_1.iv = 1; all_1.iv <= i__1; ++all_1.iv) {
	i__2 = commvl_1.nvmx[all_1.iv - 1];
	for (kv = 1; kv <= i__2; ++kv) {
	    commvl_1.ivx = commvl_1.ivmx[all_1.iv + kv * 15 - 16];
	    all_1.ibmcnt[commvl_1.ivx - 1] = 1;
	    all_1.beamon[commvl_1.ivx - 1] = FALSE_;
	    nornb[commvl_1.ivx - 1] = 0;
	    iaskb[commvl_1.ivx - 1] = 1;
	    comxtup_1.vxtup[commvl_1.ivx - 1] = FALSE_;
/* L25: */
	}
    }
    comas1_1.naskb = 0;
    ifig = 1;
    comxtup_1.ixtup = 0;
    icashft = 0;
    bspend = FALSE_;
    iscwr = FALSE_;
    rpndot = FALSE_;
    i__2 = comnsp_1.nb;
    for (ib = 1; ib <= i__2; ++ib) {

/*  Check for segno */

	if (bit_test(all_1.iornq[all_1.ipo[istart[ib] - 1] * 15],4) && 
		all_1.ivxo[istart[ib] - 1] == 1) {
	    if (comgrace_1.noffseg <= -10) {
		s_wsfi(&io___506);
		do_fio(&c__1, (char *)&comgrace_1.noffseg, (ftnlen)sizeof(
			integer));
		e_wsfi();
		lnoten = 5;
	    } else if (comgrace_1.noffseg < 0 || comgrace_1.noffseg >= 10) {
		s_wsfi(&io___508);
		do_fio(&c__1, (char *)&comgrace_1.noffseg, (ftnlen)sizeof(
			integer));
		e_wsfi();
		lnoten = 4;
	    } else {
		s_wsfi(&io___509);
		do_fio(&c__1, (char *)&comgrace_1.noffseg, (ftnlen)sizeof(
			integer));
		e_wsfi();
		lnoten = 1;
	    }
/* Writing concatenation */
	    i__3[0] = 1, a__1[0] = all_1.sq;
	    i__3[1] = 6, a__1[1] = "znotes";
	    i__3[2] = 1, a__1[2] = all_1.sq;
	    i__3[3] = 6, a__1[3] = "segnoo";
	    i__3[4] = lnoten, a__1[4] = noteq;
	    i__3[5] = 1, a__1[5] = "9";
	    s_cat(notexq, a__1, i__3, &c__6, (ftnlen)79);
	    lnote = lnoten + 15;
	    i__1 = all_1.nv;
	    for (all_1.iv = 2; all_1.iv <= i__1; ++all_1.iv) {
/* Writing concatenation */
		i__3[0] = lnote, a__1[0] = notexq;
		i__3[1] = 1, a__1[1] = "&";
		i__3[2] = 1, a__1[2] = all_1.sq;
		i__3[3] = 6, a__1[3] = "segnoo";
		i__3[4] = lnoten, a__1[4] = noteq;
		i__3[5] = 1, a__1[5] = "9";
		s_cat(notexq, a__1, i__3, &c__6, (ftnlen)79);
		lnote = lnote + lnoten + 9;
/* L130: */
	    }
	    if (comlast_1.islast) {
		s_wsfe(&io___512);
/* Writing concatenation */
		i__4[0] = lnote, a__2[0] = notexq;
		i__4[1] = 1, a__2[1] = all_1.sq;
		i__4[2] = 2, a__2[2] = "en";
		s_cat(ch__1, a__2, i__4, &c__3, (ftnlen)82);
		do_fio(&c__1, ch__1, lnote + 3);
		e_wsfe();
	    }
	    lnote = 0;
	}

/*  Check for new clefs */

	isclef = FALSE_;
	if (bit_test(all_1.islur[all_1.ivxo[istart[ib] - 1] + all_1.ipo[
		istart[ib] - 1] * 15 - 16],15)) {

/*  In preceding line, fl32 gave wrong result for ... .gt.0 !!! */

	    i__1 = istop[ib];
	    for (in = istart[ib]; in <= i__1; ++in) {
		if (bit_test(all_1.islur[all_1.ivxo[in - 1] + all_1.ipo[in - 
			1] * 15 - 16],11)) {
		    i__5 = lbit_shift(all_1.islur[all_1.ivxo[in - 1] + 
			    all_1.ipo[in - 1] * 15 - 16], (ftnlen)-12) & 7;
		    wsclef_(&all_1.ivxo[in - 1], ninow, clefq + 1, &i__5, (
			    ftnlen)1);
		}
/* L140: */
	    }
	    if (comlast_1.islast) {
		s_wsfe(&io___515);
/* Writing concatenation */
		i__6[0] = 1, a__3[0] = all_1.sq;
		i__6[1] = 11, a__3[1] = "pmxnewclefs";
		s_cat(ch__2, a__3, i__6, &c__2, (ftnlen)12);
		do_fio(&c__1, ch__2, (ftnlen)12);
		e_wsfe();
	    }
	    isclef = TRUE_;
	}

/*  Start a notes group.  We're just gonna define every one using pnotes{n}, */
/*    where \def\pnotes#1{\vnotes#1\elemskip} */

/* Writing concatenation */
	i__6[0] = 1, a__3[0] = all_1.sq;
	i__6[1] = 7, a__3[1] = "pnotes{";
	s_cat(soutq, a__3, i__6, &c__2, (ftnlen)80);
	r__1 = comnsp_1.space[ib - 1] / squez[ib];
	eonsqz = squez[ib] * feon_(&r__1);
	if (eonsqz > (float).995) {
	    s_wsfi(&io___518);
	    do_fio(&c__1, (char *)&eonsqz, (ftnlen)sizeof(real));
	    e_wsfi();
	} else if (eonsqz > (float).095) {
/* Writing concatenation */
	    i__6[0] = 8, a__3[0] = soutq;
	    i__6[1] = 2, a__3[1] = "0.";
	    s_cat(soutq, a__3, i__6, &c__2, (ftnlen)80);
	    s_wsfi(&io___519);
	    r__1 = eonsqz * 100;
	    i__1 = i_nint(&r__1);
	    do_fio(&c__1, (char *)&i__1, (ftnlen)sizeof(integer));
	    e_wsfi();
	} else {
/* Writing concatenation */
	    i__6[0] = 8, a__3[0] = soutq;
	    i__6[1] = 3, a__3[1] = "0.0";
	    s_cat(soutq, a__3, i__6, &c__2, (ftnlen)80);
	    s_wsfi(&io___520);
	    r__1 = eonsqz * 100;
	    i__1 = i_nint(&r__1);
	    do_fio(&c__1, (char *)&i__1, (ftnlen)sizeof(integer));
	    e_wsfi();
	}
/* Writing concatenation */
	i__6[0] = 12, a__3[0] = soutq;
	i__6[1] = 1, a__3[1] = "}";
	s_cat(soutq, a__3, i__6, &c__2, (ftnlen)80);
	lsout = 13;

/*  Check whole block, flag accidentals etc that are too close, one per *time*. */
/*  Note about bar starts and after rpt's/boublebars: There is an afterruleskip */
/*    (fbar*wheadpt) following, but rpts seem to occupy some of that gap, so */
/*    (dotsfac*wheadpt) is presumed to be filled up. */

	in = istart[ib] - 1;
	itrpt = -1;
	itsig = -1;

/*  Begin big manual loop which ends at 112 */

L111:
	++in;
	if (in > istop[ib]) {
	    goto L112;
	}
	ip = all_1.ipo[in - 1];
	commvl_1.ivx = all_1.ivxo[in - 1];
	if (commvl_1.ivx <= all_1.nv) {
	    all_1.iv = commvl_1.ivx;
	} else {
	    i__1 = all_1.nv;
	    for (all_1.iv = 1; all_1.iv <= i__1; ++all_1.iv) {
		if (commvl_1.nvmx[all_1.iv - 1] == 2 && commvl_1.ivmx[
			all_1.iv + 14] == commvl_1.ivx) {
		    goto L129;
		}
/* L128: */
	    }
	    s_wsle(&io___525);
	    do_lio(&c__9, &c__1, "Trouble finding iv!, ivx,nvmx,ivmx:", (
		    ftnlen)35);
	    do_lio(&c__3, &c__1, (char *)&commvl_1.ivx, (ftnlen)sizeof(
		    integer));
	    do_lio(&c__3, &c__1, (char *)&commvl_1.nvmx[0], (ftnlen)sizeof(
		    integer));
	    do_lio(&c__3, &c__1, (char *)&commvl_1.nvmx[1], (ftnlen)sizeof(
		    integer));
	    e_wsle();
	    s_wsle(&io___526);
	    do_lio(&c__3, &c__1, (char *)&commvl_1.ivmx[0], (ftnlen)sizeof(
		    integer));
	    do_lio(&c__3, &c__1, (char *)&commvl_1.ivmx[15], (ftnlen)sizeof(
		    integer));
	    do_lio(&c__3, &c__1, (char *)&commvl_1.ivmx[1], (ftnlen)sizeof(
		    integer));
	    do_lio(&c__3, &c__1, (char *)&commvl_1.ivmx[16], (ftnlen)sizeof(
		    integer));
	    e_wsle();
	    s_stop("", (ftnlen)0);
	}
L129:

/*  Remember, rpts & internal sigs can only come at start of (internal) block */

	isacc = (all_1.nacc[commvl_1.ivx + ip * 15 - 16] & 3) > 0;
	isaccs = isacc || bit_test(all_1.iornq[commvl_1.ivx + ip * 15 - 1],0);
	isarp = bit_test(all_1.iornq[commvl_1.ivx + ip * 15 - 1],27);
	if (bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 16],10)) {

/*  Check chord notes for accidentals and arpeggios. */

	    chkarp_(&found1, &comtrill_1.ncrd, comtrill_1.icrdat, 
		    comtrill_1.icrdot, &commvl_1.ivx, &ip, &isaccs, &isarp, &
		    icashft);
	}

/*  When we get motivated, will do spacing for arpeggios here. */

	if (commvl_1.ivx == 1 && (all_1.islur[commvl_1.ivx + ip * 15 - 16] & 
		96) > 0) {
	    itrpt = i_nint(&all_1.to[in - 1]);
	}
	issig = bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 16],28);
	if (commvl_1.ivx == 1 && issig) {
	    itsig = i_nint(&all_1.to[in - 1]);
	}
	isgrace = bit_test(all_1.islur[commvl_1.ivx + ip * 15 - 16],4) && ! 
		bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 16],29) && ! 
		bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 16],31);
	isgaft = FALSE_;
	if (ip > 1) {
	    xnd = all_1.tnote[(255 & all_1.ipl[commvl_1.ivx + (ip - 1) * 15 - 
		    16]) - 1];
	    isgaft = bit_test(all_1.ipl[commvl_1.ivx + (ip - 1) * 15 - 16],29)
		     || bit_test(all_1.ipl[commvl_1.ivx + (ip - 1) * 15 - 16],
		    31);
	    isgrace = isgrace || isgaft;
	}
	iscln = isclef && bit_test(all_1.islur[commvl_1.ivx + ip * 15 - 16],
		11);

/*  Is prev. note non-beamed, up-stemmed, & flagged? Recall if ip>1, have nd */

	isflag = ip > 1 && xnd > comtol_1.tol && xnd < (float)16. - 
		comtol_1.tol;
	if (isflag) {
	    i__5 = ip - 1;
	    i__1 = ncmid_(&all_1.iv, &i__5);
	    udqq_(ch__3, (ftnlen)1, &all_1.nolev[commvl_1.ivx + (ip - 1) * 15 
		    - 16], &i__1, &all_1.islur[commvl_1.ivx + (ip - 1) * 15 - 
		    16], &commvl_1.nvmx[all_1.iv - 1], &commvl_1.ivx, &
		    all_1.nv);
	    isflag = ! bit_test(all_1.irest[commvl_1.ivx + (ip - 1) * 15 - 16]
		    ,0) && *(unsigned char *)&ch__3[0] == 'u';
	}
	if (isflag) {
	    i__1 = numbms[commvl_1.ivx];
	    for (ibmchk = 1; ibmchk <= i__1; ++ibmchk) {
		if (ip - 1 < all_1.ibm1[commvl_1.ivx + ibmchk * 15 - 16]) {
		    goto L117;
		} else if (ip - 1 <= all_1.ibm2[commvl_1.ivx + ibmchk * 15 - 
			16]) {
		    isflag = FALSE_;
		    goto L117;
		}
/* L116: */
	    }
	}
L117:

/*  If isflag, then won't need to check for dot on prev. note. */

	isdot = ip > 1;
	if (isdot) {
	    i__1 = ip - 1;
	    isdot = isdotted_(all_1.nodur, &commvl_1.ivx, &i__1);
	}
	isrshft = ip > 1;
	if (isrshft) {
	    isrshft = bit_test(all_1.irest[commvl_1.ivx + (ip - 1) * 15 - 16],
		    20);
	}
	if (! (isaccs || isgrace || iscln || isflag || isrshft || isdot || 
		bit_test(all_1.iornq[commvl_1.ivx + ip * 15 - 1],26) || 
		bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],21) || 
		isarp || bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],27)
		)) {
	    goto L111;
	}

/*  Here is an accid,grace,clef,flag,rtshft,dot,udsp,arpeg,left-shift. */
/*  Check if need extra space. */

	pts = comask_1.wheadpt;
	if (isgrace) {
	    i__1 = comgrace_1.ngrace;
	    for (ig = 1; ig <= i__1; ++ig) {
		if (! isgaft) {
		    if (comgrace_1.ipg[ig - 1] == ip && comgrace_1.ivg[ig - 1]
			     == commvl_1.ivx) {
			goto L123;
		    }
		} else if (ip > 1) {
		    if (comgrace_1.ipg[ig - 1] == ip - 1 && comgrace_1.ivg[ig 
			    - 1] == commvl_1.ivx) {
			goto L123;
		    }
		}
/* L122: */
	    }
	    s_wsle(&io___542);
	    do_lio(&c__9, &c__1, "Problem finding grace index in makeabar", (
		    ftnlen)39);
	    e_wsle();
	    s_stop("", (ftnlen)0);
L123:

/*  wgr = distance to backspace (in headwidths), less main acc. */
/*  ptgr = same in pts,+ main acc.  Not used for after-grace. */
/*  spgr = total space needed (w/o main acc). NB apt=wheadpt, don't get confused. */
/*   Also, spgr is same for b4 or after, but xb4fac-space will be in diff. place. */

	    if (comgrace_1.nng[ig - 1] == 1) {
		wgr = spfacs_1.grafac;
		if (comgrace_1.multg[ig - 1] == 0) {
		    wgr += (float)-.4;
		}
	    } else {
		wgr = comgrace_1.nng[ig - 1] * spfacs_1.emgfac;
		i__1 = comgrace_1.nng[ig - 1];
		for (ing = 2; ing <= i__1; ++ing) {
		    if (comgrace_1.naccg[comgrace_1.ngstrt[ig - 1] - 1 + ing 
			    - 1] > 0) {
			wgr += spfacs_1.acgfac;
		    }
/* L126: */
		}
	    }
	    ptgr[ig - 1] = wgr * comask_1.wheadpt;
	    spgr = ptgr[ig - 1] + spfacs_1.xb4fac * comask_1.wheadpt;
	    if (isaccs) {
		ptgr[ig - 1] += spfacs_1.accfac * comask_1.wheadpt;
	    }
	    if (comgrace_1.naccg[comgrace_1.ngstrt[ig - 1] - 1] > 0) {
		spgr += comask_1.wheadpt * spfacs_1.agc1fac;
	    }
	    pts += spgr;
	}
	if (iscln) {
	    pts += spfacs_1.clefac * comask_1.wheadpt;

/*  How far to backspace when printing the clef */

	    ptclef[commvl_1.ivx - 1] = (float)0.;
	    if (isaccs) {
		ptclef[commvl_1.ivx - 1] += spfacs_1.accfac * 
			comask_1.wheadpt;
	    }
	    if (isgrace) {
		ptclef[commvl_1.ivx - 1] += spgr;
	    }
/*     print*,'+CLEF, ptclef, pts->',ptclef(ivx),pts */
	}
	if (isrshft) {
	    pts += spfacs_1.rtshfac * comask_1.wheadpt;
	} else if (isflag) {
	    pts += spfacs_1.flagfac * comask_1.wheadpt;
/*     print*,'+FLAG, pts->',pts */
	} else if (isdot) {
	    pts += spfacs_1.dotfac * comask_1.wheadpt;
/*     print*,'+DOT, pts->',pts */
	}
	if (all_1.to[in - 1] == (real) itrpt) {

/*  Repeat, need a little extra space */

	    pts += spfacs_1.dotsfac * comask_1.wheadpt;
/*     print*,'ITRPT, pts->',pts */
	}
	if (isarp) {
	    pts += spfacs_1.arpfac * comask_1.wheadpt;
/*     print*,'Due to isarp, pts, arpfac:',pts,arpfac */
	}
	if (bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],27)) {
	    pts += comask_1.wheadpt;
	}
	pts += spfacs_1.xspfac * comask_1.wheadpt;
/*     print*,'FINISH, xspfac,pts->',xspfac,pts */

/*  Get available space in elemskips (esk) */

	isfirst = ip == 1 || all_1.to[in - 1] == (real) itrpt || all_1.to[in 
		- 1] == (real) itsig;
	if (isfirst) {

/*  At start of bar or after repeat sign or new signature */

	    if (all_1.to[in - 1] == (real) itsig) {
		esk = (float)0.;
	    } else {
		esk = comask_1.fbar;
	    }
	} else {

/*  Not 1st note of bar */

	    esk = all_1.eskz[commvl_1.ivx + ip * 15 - 16] - all_1.eskz[
		    commvl_1.ivx + (ip - 1) * 15 - 16];
	}
	if (isgrace) {

/*  Since graces can be very long, cannot assume no interference if prior */
/*  note uses >1 noteskip.  So must get elsk's back to prior note, whether or */
/*  not it used only one noteskip.  But if it was xtup. don't need to call eskb4. */

/*          if ((ip.le.2 .or. nodur(ivx,ip-2).gt.0) .and. */
/* Computing MAX */
	    i__1 = 1, i__5 = ip - 2;
	    if ((ip <= 2 || all_1.nodur[commvl_1.ivx + max(i__1,i__5) * 15 - 
		    16] > 0) && all_1.to[in - 1] != (real) itsig) {
		eskb4_(&ip, &commvl_1.ivx, &in, &ib, comnsp_1.space, &tstart[
			1], &comask_1.fbar, &itrpt, &esk);
	    }
	}

/*  Done getting available elemskips.  Remove headwidth it first.  Must do here */
/*  rather than earlier since check uses isfirst */

	if (isfirst) {
	    pts -= comask_1.wheadpt;
	}
	if (isaccs) {

/*  Combine chord accidental space rqmts with main note, accounting for lshft's. */
/*  icashft already includes lshft's of chord notes.  First do main note a-shft */

	    ihshft = igetbits_(&all_1.nacc[commvl_1.ivx + ip * 15 - 16], &
		    c__7, &c__10);

/*  Correct for main note left shift if needed */

	    if (bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 16],8)) {
		if (ihshft == 0) {
		    ihshft = 44;
		} else {
		    ihshft += -20;
		}
	    }
	    if (ihshft != 0) {
/* Computing MAX */
		i__1 = 0, i__5 = 64 - ihshft;
		ihshft = max(i__1,i__5);
	    }
	    ihshft = max(ihshft,icashft);

/*  If there's a grace, correct amount of backspacing needed */

	    if (isgrace && ihshft != 0) {
		ptgr[ig - 1] += ihshft * (float).05 * comask_1.wheadpt;
	    }
	}

/*  Try big accidentals first */

	ptbneed = pts;
	if (isaccs) {
	    ptbneed += comask_1.wheadpt * spfacs_1.bacfac;

/*  Now if there are *any* left-shifted accids and *any* left-shifted noteheads, */
/*  we must reduce pts by wheadpt since it was already included w/ accids. */

	    if (ihshft > 0) {
		if (bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],27)) {
		    ptbneed -= comask_1.wheadpt;
		}
		ptbneed += ihshft * (float).05 * comask_1.wheadpt;
	    }
	}
	if (comask_1.poenom * esk > ptbneed) {

/*  Set flag for big accidental */

	    if (isacc) {
		all_1.nacc[commvl_1.ivx + ip * 15 - 16] = bit_set(all_1.nacc[
			commvl_1.ivx + ip * 15 - 16],3);
	    }
	    goto L99;
	}

/*  Cannot use big, so try small */

	ptsneed = pts;
	if (isaccs) {
	    ptsneed += spfacs_1.accfac * comask_1.wheadpt;

/*  Repeated coding from above :-( */

	    if (ihshft > 0) {
		if (bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],27)) {
		    ptsneed -= comask_1.wheadpt;
		}
		ptsneed += ihshft * (float).05 * comask_1.wheadpt;
	    }
	}
	if (comask_1.poenom * esk < ptsneed) {
	    addask_(&all_1.to[in - 1], &ptsneed, &esk, &comask_1.fixednew, &
		    comask_1.scaldold, &c_b1398, &c_false);
	}
L99:
	if (icashft > 0) {
	    icashft = 0;
	}
	if (bit_test(all_1.iornq[commvl_1.ivx + ip * 15 - 1],26)) {

/*  User-defined space.  Warning, "zero" may change value in addask! */

	    zero = (float)0.;
	    addask_(&all_1.to[in - 1], &ptsneed, &zero, &comask_1.fixednew, &
		    comask_1.scaldold, tglp1, &c_true);
	}

/*  End of big manual loop over "in" for accidental checking */

	goto L111;
L112:

/* End of ask analysis for this block.  Check for internal repeat or sig change. */

	if (ib > 1 && all_1.ivxo[istart[ib] - 1] == 1) {
	    iirpt = all_1.islur[all_1.ipo[istart[ib] - 1] * 15 - 15] & 
		    67109216;
	    if (iirpt > 0) {

/* Internal repeat */

		if (comlast_1.islast) {
		    s_wsfe(&io___555);
/* Writing concatenation */
		    i__7[0] = 1, a__4[0] = all_1.sq;
		    i__7[1] = 7, a__4[1] = "advance";
		    i__7[2] = 1, a__4[2] = all_1.sq;
		    i__7[3] = 8, a__4[3] = "barno-1%";
		    s_cat(ch__4, a__4, i__7, &c__4, (ftnlen)17);
		    do_fio(&c__1, ch__4, (ftnlen)17);
		    e_wsfe();
		}
		if (iirpt == 96) {
		    if (comlast_1.islast) {
			s_wsfe(&io___556);
/* Writing concatenation */
			i__6[0] = 1, a__3[0] = all_1.sq;
			i__6[1] = 15, a__3[1] = "leftrightrepeat";
			s_cat(ch__5, a__3, i__6, &c__2, (ftnlen)16);
			do_fio(&c__1, ch__5, (ftnlen)16);
			e_wsfe();
		    }
		    comask_1.fixednew += spfacs_1.lrrptfac * comask_1.wheadpt;
		} else if (bit_test(iirpt,5)) {
		    if (comlast_1.islast) {
			s_wsfe(&io___557);
/* Writing concatenation */
			i__6[0] = 1, a__3[0] = all_1.sq;
			i__6[1] = 10, a__3[1] = "leftrepeat";
			s_cat(ch__6, a__3, i__6, &c__2, (ftnlen)11);
			do_fio(&c__1, ch__6, (ftnlen)11);
			e_wsfe();
		    }
		    comask_1.fixednew += spfacs_1.rptfac * comask_1.wheadpt;
		} else if (bit_test(iirpt,6)) {
		    if (comlast_1.islast) {
			s_wsfe(&io___558);
/* Writing concatenation */
			i__6[0] = 1, a__3[0] = all_1.sq;
			i__6[1] = 11, a__3[1] = "rightrepeat";
			s_cat(ch__2, a__3, i__6, &c__2, (ftnlen)12);
			do_fio(&c__1, ch__2, (ftnlen)12);
			e_wsfe();
		    }
		    comask_1.fixednew += spfacs_1.rptfac * comask_1.wheadpt;
		} else if (bit_test(iirpt,8)) {
		    if (comlast_1.islast) {
			s_wsfe(&io___559);
/* Writing concatenation */
			i__6[0] = 1, a__3[0] = all_1.sq;
			i__6[1] = 9, a__3[1] = "doublebar";
			s_cat(ch__7, a__3, i__6, &c__2, (ftnlen)10);
			do_fio(&c__1, ch__7, (ftnlen)10);
			e_wsfe();
		    }
		} else {
		    s_wsle(&io___560);
		    do_lio(&c__9, &c__1, "Unexpected mid-bar repeat command \
R*", (ftnlen)36);
		    e_wsle();
		    s_stop("1", (ftnlen)1);
		}
		comask_1.scaldold -= comask_1.fbar;
	    }
	    if (bit_test(all_1.ipl[all_1.ipo[istart[ib] - 1] * 15 - 15],28)) {

/*  Internal signature change. */

/* Writing concatenation */
		i__6[0] = 1, a__3[0] = all_1.sq;
		i__6[1] = 17, a__3[1] = "generalsignature{";
		s_cat(notexq, a__3, i__6, &c__2, (ftnlen)79);
		lnote = 18;
		if (comtop_1.isig < 0) {
/* Writing concatenation */
		    i__6[0] = lnote, a__3[0] = notexq;
		    i__6[1] = 1, a__3[1] = "-";
		    s_cat(notexq, a__3, i__6, &c__2, (ftnlen)79);
		    ++lnote;
		}
		if (comlast_1.islast) {
		    s_wsfe(&io___561);
/* Writing concatenation */
		    i__4[0] = lnote, a__2[0] = notexq;
		    i__1 = abs(comtop_1.isig) + 48;
		    chax_(ch__3, (ftnlen)1, &i__1);
		    i__4[1] = 1, a__2[1] = ch__3;
		    i__4[2] = 2, a__2[2] = "}%";
		    s_cat(ch__1, a__2, i__4, &c__3, (ftnlen)82);
		    do_fio(&c__1, ch__1, lnote + 3);
		    e_wsfe();
		}
		if (comlast_1.islast) {
		    s_wsfe(&io___562);
/* Writing concatenation */
		    i__3[0] = 1, a__1[0] = all_1.sq;
		    i__3[1] = 14, a__1[1] = "zchangecontext";
		    i__3[2] = 1, a__1[2] = all_1.sq;
		    i__3[3] = 12, a__1[3] = "addspace{-.5";
		    i__3[4] = 1, a__1[4] = all_1.sq;
		    i__3[5] = 15, a__1[5] = "afterruleskip}%";
		    s_cat(ch__8, a__1, i__3, &c__6, (ftnlen)44);
		    do_fio(&c__1, ch__8, (ftnlen)44);
		    e_wsfe();
		}
		lnote = 0;
	    }
	}
	comnsp_1.flgndb = FALSE_;

/*  Done with start-of-block stuff.  Begin main loop over voices. */

	i__1 = all_1.nv;
	for (all_1.iv = 1; all_1.iv <= i__1; ++all_1.iv) {
	    i__5 = commvl_1.nvmx[all_1.iv - 1];
	    for (kv = 1; kv <= i__5; ++kv) {
		commvl_1.ivx = commvl_1.ivmx[all_1.iv + kv * 15 - 16];
		icm = commidi_1.midchan[all_1.iv + kv * 15 - 16];
		all_1.figcheck = all_1.figbass && commvl_1.ivx == 1 && 
			comfig_1.nfigs > 0;
		if (commvl_1.ivx > 1) {
		    if (commvl_1.ivx <= all_1.nv) {
			addstr_(all_1.sepsymq + (all_1.iv - 2), &c__1, soutq, 
				&lsout, (ftnlen)1, (ftnlen)80);
		    } else {
/* Writing concatenation */
			i__6[0] = 1, a__3[0] = all_1.sq;
			i__6[1] = 9, a__3[1] = "nextvoice";
			s_cat(ch__7, a__3, i__6, &c__2, (ftnlen)10);
			addstr_(ch__7, &c__10, soutq, &lsout, (ftnlen)10, (
				ftnlen)80);
		    }
		}
		if (comhead_1.ihdht > 0 && commvl_1.ivx == all_1.nv) {

/*  Write header.  First adjust height if needed to miss barno. */

		    if (comask_1.bar1syst && all_1.iline != 1) {
			comhead_1.ihdht = comsln_1.irzbnd + 15 + 
				comsln_1.isnx;
		    }

/*  Add user-defined vertical shift */

		    comhead_1.ihdht += comhead_1.ihdvrt;
		    lchead = lenstr_(comhead_1.headrq, &c__80, (ftnlen)80);
/* Writing concatenation */
		    i__6[0] = 1, a__3[0] = all_1.sq;
		    i__6[1] = 10, a__3[1] = "zcharnote{";
		    s_cat(notexq, a__3, i__6, &c__2, (ftnlen)79);
		    s_wsfi(&io___565);
		    do_fio(&c__1, (char *)&comhead_1.ihdht, (ftnlen)sizeof(
			    integer));
		    e_wsfi();
/* Writing concatenation */
		    i__3[0] = 13, a__1[0] = notexq;
		    i__3[1] = 2, a__1[1] = "}{";
		    i__3[2] = 1, a__1[2] = all_1.sq;
		    i__3[3] = 7, a__1[3] = "bigfont";
		    i__3[4] = 1, a__1[4] = all_1.sq;
		    i__3[5] = 10, a__1[5] = "kern-30pt ";
		    s_cat(notexq, a__1, i__3, &c__6, (ftnlen)79);
		    addstr_(notexq, &c__34, soutq, &lsout, (ftnlen)79, (
			    ftnlen)80);
/* Writing concatenation */
		    i__6[0] = lchead, a__3[0] = comhead_1.headrq;
		    i__6[1] = 1, a__3[1] = "}";
		    s_cat(ch__9, a__3, i__6, &c__2, (ftnlen)81);
		    i__8 = lchead + 1;
		    addstr_(ch__9, &i__8, soutq, &lsout, lchead + 1, (ftnlen)
			    80);
		    comhead_1.ihdht = 0;
		}
		if (comhead_1.lower && commvl_1.ivx == all_1.nv) {
		    lclow = lenstr_(comhead_1.lowerq, &c__80, (ftnlen)80);
/* Writing concatenation */
		    i__9[0] = 1, a__5[0] = all_1.sq;
		    i__9[1] = 14, a__5[1] = "zcharnote{-6}{";
		    i__9[2] = 1, a__5[2] = all_1.sq;
		    i__9[3] = 5, a__5[3] = "tempo";
		    i__9[4] = 1, a__5[4] = all_1.sq;
		    i__9[5] = 10, a__5[5] = "kern-10pt ";
		    i__9[6] = lclow, a__5[6] = comhead_1.lowerq;
		    i__9[7] = 1, a__5[7] = "}";
		    s_cat(ch__10, a__5, i__9, &c__8, (ftnlen)113);
		    i__8 = lclow + 33;
		    addstr_(ch__10, &i__8, soutq, &lsout, lclow + 33, (ftnlen)
			    80);
		    comhead_1.lower = FALSE_;
		}
		tnow = tstart[ib];
		nofirst = TRUE_;

/*  Done setting up voice ivx for start of block ib.  Loop over notes in voice. */

		i__8 = istop[ib];
		for (all_1.jn = istart[ib]; all_1.jn <= i__8; ++all_1.jn) {
		    if (all_1.ivxo[all_1.jn - 1] != commvl_1.ivx) {
			goto L10;
		    }
		    ip = all_1.ipo[all_1.jn - 1];
		    if (nofirst) {
			comoct_1.noctup = 0;
			if (ncmid_(&all_1.iv, &ip) == 23) {
			    comoct_1.noctup = -2;
			}
			nofirst = FALSE_;
		    }

/*  Check for internal floating figure (before last note of group). */

L12:
		    if (all_1.figcheck && (real) comfig_1.itfig[ifig - 1] < 
			    tnow - comtol_1.tol) {

/*  Bypassed figure location. Backup, place fig, return. */

			offnsk = (tnow - comfig_1.itfig[ifig - 1]) / 
				comnsp_1.space[ib - 1];
			putfig_(&ifig, &offnsk, &all_1.figcheck, soutq, &
				lsout, (ftnlen)80);
			goto L12;
		    }

/*  Put in \sk if needed */

		    if (all_1.to[all_1.jn - 1] > tnow + comtol_1.tol) {
/* Writing concatenation */
			i__6[0] = 1, a__3[0] = all_1.sq;
			i__6[1] = 2, a__3[1] = "sk";
			s_cat(ch__11, a__3, i__6, &c__2, (ftnlen)3);
			addstr_(ch__11, &c__3, soutq, &lsout, (ftnlen)3, (
				ftnlen)80);
			tnow += comnsp_1.space[ib - 1];
			goto L12;
		    }

/*  Check for user-defined shifts */

		    if (bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],15) 
			    || bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 
			    16],16)) {
			putshft_(&commvl_1.ivx, &c_true, soutq, &lsout, (
				ftnlen)80);
		    }
L21:
		    if (iaskb[commvl_1.ivx - 1] <= comas1_1.naskb && tnow > 
			    comas1_1.task[iaskb[commvl_1.ivx - 1] - 1] - 
			    comtol_1.tol) {
			if (comas1_1.task[iaskb[commvl_1.ivx - 1] - 1] > 
				tstart[ib] - comtol_1.tol) {

/*  Insert placeholder for accidental skip */

/* Writing concatenation */
			    i__6[0] = 1, a__3[0] = all_1.sq;
			    i__6[1] = 8, a__3[1] = "ask     ";
			    s_cat(ch__12, a__3, i__6, &c__2, (ftnlen)9);
			    addstr_(ch__12, &c__9, soutq, &lsout, (ftnlen)9, (
				    ftnlen)80);
			    ++comas2_1.nasksys;
			    comas2_1.wasksys[comas2_1.nasksys - 1] = 
				    comas1_1.wask[iaskb[commvl_1.ivx - 1] - 1]
				    ;
			    if (comas1_1.wask[iaskb[commvl_1.ivx - 1] - 1] > (
				    float)0.) {
				comas2_1.elasksys[comas2_1.nasksys - 1] = 
					comas1_1.elask[iaskb[commvl_1.ivx - 1]
					 - 1];
			    } else {

/*  This is a signal to permit negative ask's.  Should really have elask>=0. */

				comas2_1.elasksys[comas2_1.nasksys - 1] = 
					-comas1_1.elask[iaskb[commvl_1.ivx - 
					1] - 1];
			    }
			}

/*  May have skipped some task's in earlier blocks (due to void voice) */

			++iaskb[commvl_1.ivx - 1];
			goto L21;
		    }
		    if (all_1.figcheck && (r__1 = comfig_1.itfig[ifig - 1] - 
			    tnow, dabs(r__1)) < comtol_1.tol) {

/*  Figure on a note.  NB: later special check for late figs. */

			putfig_(&ifig, &c_b1398, &all_1.figcheck, soutq, &
				lsout, (ftnlen)80);
		    }

/*  Check for new clef here. */

		    if (isclef && bit_test(all_1.islur[commvl_1.ivx + ip * 15 
			    - 16],11)) {
/*     print*,'At clef insertion, ptclef:',ptclef(iv) */
			if (ptclef[all_1.iv - 1] > (float)0.) {
/* Writing concatenation */
			    i__6[0] = 1, a__3[0] = all_1.sq;
			    i__6[1] = 5, a__3[1] = "off{-";
			    s_cat(notexq, a__3, i__6, &c__2, (ftnlen)79);
			    if (ptclef[all_1.iv - 1] < (float)9.95) {
				s_wsfi(&io___570);
				do_fio(&c__1, (char *)&ptclef[all_1.iv - 1], (
					ftnlen)sizeof(real));
				e_wsfi();
				lnote = 9;
			    } else {
				s_wsfi(&io___571);
				do_fio(&c__1, (char *)&ptclef[all_1.iv - 1], (
					ftnlen)sizeof(real));
				e_wsfi();
				lnote = 10;
			    }
/* Writing concatenation */
			    i__6[0] = lnote, a__3[0] = notexq;
			    i__6[1] = 3, a__3[1] = "pt}";
			    s_cat(notexq, a__3, i__6, &c__2, (ftnlen)79);
			    lnote += 3;
			    addstr_(notexq, &lnote, soutq, &lsout, (ftnlen)79,
				     (ftnlen)80);
/*     print*,'Just added: ',notexq(1:lnote) */
			}
			clefsym_(&all_1.islur[all_1.iv + ip * 15 - 16], 
				notexq, &lnote, &nclef, (ftnlen)79);
			addstr_(notexq, &lnote, soutq, &lsout, (ftnlen)79, (
				ftnlen)80);
			if (ptclef[all_1.iv - 1] > (float)0.) {
/* Writing concatenation */
			    i__6[0] = 1, a__3[0] = all_1.sq;
			    i__6[1] = 4, a__3[1] = "off{";
			    s_cat(notexq, a__3, i__6, &c__2, (ftnlen)79);
			    if (ptclef[all_1.iv - 1] < (float)9.95) {
				s_wsfi(&io___573);
				do_fio(&c__1, (char *)&ptclef[all_1.iv - 1], (
					ftnlen)sizeof(real));
				e_wsfi();
				lnote = 8;
			    } else {
				s_wsfi(&io___574);
				do_fio(&c__1, (char *)&ptclef[all_1.iv - 1], (
					ftnlen)sizeof(real));
				e_wsfi();
				lnote = 9;
			    }
/* Writing concatenation */
			    i__6[0] = lnote, a__3[0] = notexq;
			    i__6[1] = 3, a__3[1] = "pt}";
			    s_cat(notexq, a__3, i__6, &c__2, (ftnlen)79);
			    lnote += 3;
			    addstr_(notexq, &lnote, soutq, &lsout, (ftnlen)79,
				     (ftnlen)80);
			}
		    }

/*  Checking for literal TeX string BEFORE starting beams!! */

		    if (bit_test(all_1.islur[commvl_1.ivx + ip * 15 - 16],16))
			     {
			i__10 = comgrace_1.nlit;
			for (il = 1; il <= i__10; ++il) {
			    if (comgrace_1.iplit[il - 1] == ip && 
				    comgrace_1.ivlit[il - 1] == commvl_1.ivx) 
				    {
				goto L125;
			    }
/* L124: */
			}
			s_wsle(&io___576);
			do_lio(&c__9, &c__1, "Problem finding index for lite\
ral string", (ftnlen)40);
			e_wsle();
			s_stop("", (ftnlen)0);
L125:

/*  Write a type 1 tex string. */

			if (comgrace_1.lenlit[il - 1] < 71) {

/*  Add normally */

			    addstr_(comgrace_1.litq + (il - 1 << 7), &
				    comgrace_1.lenlit[il - 1], soutq, &lsout, 
				    (ftnlen)128, (ftnlen)80);
			} else {

/*  Longer than 71.  Write souq, Write string, start new soutq. */

			    if (comlast_1.islast) {
				s_wsfe(&io___577);
/* Writing concatenation */
				i__6[0] = lsout, a__3[0] = soutq;
				i__6[1] = 1, a__3[1] = "%";
				s_cat(ch__9, a__3, i__6, &c__2, (ftnlen)81);
				do_fio(&c__1, ch__9, lsout + 1);
				e_wsfe();
			    }
			    if (comlast_1.islast) {
				s_wsfe(&io___578);
/* Writing concatenation */
				i__6[0] = comgrace_1.lenlit[il - 1], a__3[0] =
					 comgrace_1.litq + (il - 1 << 7);
				i__6[1] = 1, a__3[1] = "%";
				s_cat(ch__13, a__3, i__6, &c__2, (ftnlen)129);
				do_fio(&c__1, ch__13, comgrace_1.lenlit[il - 
					1] + 1);
				e_wsfe();
			    }
			    lsout = 0;
			}
		    }

/*  Arpeggio on a main (non-chordal) note? */

		    if (bit_test(all_1.iornq[commvl_1.ivx + ip * 15 - 1],27)) 
			    {
			i__10 = ncmid_(&all_1.iv, &ip);
			putarp_(&tnow, &all_1.iv, &all_1.nolev[commvl_1.ivx + 
				ip * 15 - 16], &i__10, soutq, &lsout, (ftnlen)
				80);
		    }

/*  See if a beam starts here */

		    if (numbms[commvl_1.ivx] > 0 && all_1.ibmcnt[commvl_1.ivx 
			    - 1] <= numbms[commvl_1.ivx] && all_1.ibm1[
			    commvl_1.ivx + all_1.ibmcnt[commvl_1.ivx - 1] * 
			    15 - 16] == ip) {
			if (! bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 
				16],24)) {

/*  Not a jump start */

			    beamstrt_(notexq, &lnote, nornb, ihornb, 
				    comnsp_1.space, &squez[1], &ib, (ftnlen)
				    79);

/*  Shift beam start if notehead was shifted */

			    if (bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 
				    16],8)) {
/* Writing concatenation */
				i__6[0] = 1, a__3[0] = all_1.sq;
				i__6[1] = 5, a__3[1] = "loff{";
				s_cat(ch__14, a__3, i__6, &c__2, (ftnlen)6);
				addstr_(ch__14, &c__6, soutq, &lsout, (ftnlen)
					6, (ftnlen)80);
			    } else if (bit_test(all_1.ipl[commvl_1.ivx + ip * 
				    15 - 16],9)) {
/* Writing concatenation */
				i__6[0] = 1, a__3[0] = all_1.sq;
				i__6[1] = 5, a__3[1] = "roff{";
				s_cat(ch__14, a__3, i__6, &c__2, (ftnlen)6);
				addstr_(ch__14, &c__6, soutq, &lsout, (ftnlen)
					6, (ftnlen)80);
			    }
			    if (lnote > 0) {
				addstr_(notexq, &lnote, soutq, &lsout, (
					ftnlen)79, (ftnlen)80);
			    }
			    if (bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 
				    16],8) || bit_test(all_1.ipl[commvl_1.ivx 
				    + ip * 15 - 16],9)) {
				addstr_("}", &c__1, soutq, &lsout, (ftnlen)1, 
					(ftnlen)80);
			    }
			}
			if (strtmid_1.ixrest[commvl_1.ivx - 1] == 0) {
			    all_1.beamon[commvl_1.ivx - 1] = TRUE_;
			    bspend = TRUE_;
			}
		    }

/*  Setup for chords and possible slurs in chords */

		    if (bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 16],10)) {
			precrd_(&commvl_1.ivx, &ip, &all_1.nolev[commvl_1.ivx 
				+ ip * 15 - 16]);
		    }

/*  Is there slur or grace activity? */

		    isgrace = bit_test(all_1.islur[commvl_1.ivx + ip * 15 - 
			    16],4);
		    if (ip > 1) {
			isgrace = isgrace || bit_test(all_1.ipl[commvl_1.ivx 
				+ (ip - 1) * 15 - 16],31);
		    }

/*  isgrace if not 1st note in bar and previous note has Way-after grace. */

		    if (bit_test(all_1.islur[commvl_1.ivx + ip * 15 - 16],0) 
			    || isgrace) {
			if (bit_test(all_1.islur[commvl_1.ivx + ip * 15 - 16],
				0)) {
			    i__10 = ncmid_(&all_1.iv, &ip);
			    doslur_(&all_1.nolev[commvl_1.ivx + ip * 15 - 16],
				     all_1.isdat1, all_1.isdat2, all_1.isdat3,
				     &all_1.nsdat, &ip, &all_1.iv, &kv, &
				    all_1.nv, &all_1.beamon[commvl_1.ivx - 1],
				     &i__10, soutq, &lsout, all_1.ulq + (
				    commvl_1.ivx + all_1.ibmcnt[commvl_1.ivx 
				    - 1] * 15 - 16), &all_1.islur[
				    commvl_1.ivx + ip * 15 - 16], &all_1.ipl[
				    commvl_1.ivx + ip * 15 - 16], &
				    all_1.iornq[commvl_1.ivx + ip * 15 - 1], &
				    islhgt, &all_1.tno[(255 & all_1.ipl[
				    commvl_1.ivx + ip * 15 - 16]) - 1], &
				    all_1.nacc[commvl_1.ivx + ip * 15 - 16], (
				    ftnlen)80, (ftnlen)1);
			}
			if (isgrace) {

/* Grace note. */

			    iphold = ip;
			    isgrace = FALSE_;
			    if (ip > 1) {
				isgrace = bit_test(all_1.ipl[commvl_1.ivx + (
					ip - 1) * 15 - 16],31);
			    }
			    if (isgrace) {
				--iphold;
			    }
			    isgrace = isgrace || ! bit_test(all_1.ipl[
				    commvl_1.ivx + ip * 15 - 16],31) && ! 
				    bit_test(all_1.ipl[commvl_1.ivx + ip * 15 
				    - 16],29);

/* Place grace now if (a) Way-after from prev note and ip>1 or (b) Pre-grace */
/*   on current note.  Do A-grace on current note, and W-grace at barend, later. */

			    if (isgrace) {
				i__10 = ncmid_(&all_1.iv, &ip);
				dograce_(&commvl_1.ivx, &iphold, ptgr, soutq, 
					&lsout, &i__10, &all_1.nacc[
					commvl_1.ivx + ip * 15 - 16], &ig, &
					all_1.ipl[commvl_1.ivx + iphold * 15 
					- 16], &c_false, (ftnlen)80);
				if (comgrace_1.slurg[ig - 1]) {

/* Terminate slur started in dograce.  Get direction of main note stem */

				    if (! all_1.beamon[commvl_1.ivx - 1]) {

/*  Separate note.  Get stem direction. */

					i__10 = ncmid_(&all_1.iv, &ip);
					udqq_(ch__3, (ftnlen)1, &all_1.nolev[
						commvl_1.ivx + ip * 15 - 16], 
						&i__10, &all_1.islur[
						commvl_1.ivx + ip * 15 - 16], 
						&commvl_1.nvmx[all_1.iv - 1], 
						&commvl_1.ivx, &all_1.nv);
					stemup = *(unsigned char *)&ch__3[0] 
						== 'u';
				    } else {

/*  In a beam */

					stemup = *(unsigned char *)&all_1.ulq[
						commvl_1.ivx + all_1.ibmcnt[
						commvl_1.ivx - 1] * 15 - 16] 
						== 'u';
				    }
				    L__1 = ! comgrace_1.upg[ig - 1];
				    i__10 = ncmid_(&all_1.iv, &ip);
				    endslur_(&stemup, &L__1, &all_1.nolev[
					    commvl_1.ivx + ip * 15 - 16], &
					    c__0, &comslur_1.ndxslur, &c__0, &
					    i__10, soutq, &lsout, (ftnlen)80);
				}
			    }
			}
			if (bit_test(all_1.iornq[commvl_1.ivx + ip * 15 - 1],
				24)) {

/*  Start slur on main note for After- or Way-after-grace. */

/*                ndxslur = log2(511-listslur) */
			    i__10 = 4095 - comslur_1.listslur;
			    comslur_1.ndxslur = log2_(&i__10);

/*  Get note name */

			    i__10 = ncmid_(&all_1.iv, &ip);
			    notefq_(noteq, &lnoten, &all_1.nolev[commvl_1.ivx 
				    + ip * 15 - 16], &i__10, (ftnlen)8);

/*  Get slur direction */

			    *(unsigned char *)slurudq = 'u';
			    if (! all_1.beamon[commvl_1.ivx - 1]) {
				i__10 = ncmid_(&all_1.iv, &ip);
				udqq_(ch__3, (ftnlen)1, &all_1.nolev[
					commvl_1.ivx + ip * 15 - 16], &i__10, 
					&all_1.islur[commvl_1.ivx + ip * 15 - 
					16], &commvl_1.nvmx[all_1.iv - 1], &
					commvl_1.ivx, &all_1.nv);
				if (*(unsigned char *)&ch__3[0] == 'u') {
				    *(unsigned char *)slurudq = 'd';
				}
			    } else {
				if (*(unsigned char *)&all_1.ulq[commvl_1.ivx 
					+ all_1.ibmcnt[commvl_1.ivx - 1] * 15 
					- 16] == 'u') {
				    *(unsigned char *)slurudq = 'd';
				}
			    }
/*                notexq = sq//'islur'//slurudq//chax(48+ndxslur) */
/*     *              //noteq(1:lnoten) */
/*                call addstr(notexq,8+lnoten,soutq,lsout) */
			    if (comslur_1.ndxslur < 10) {
/* Writing concatenation */
				i__11[0] = 1, a__6[0] = all_1.sq;
				i__11[1] = 5, a__6[1] = "islur";
				i__11[2] = 1, a__6[2] = slurudq;
				i__10 = comslur_1.ndxslur + 48;
				chax_(ch__3, (ftnlen)1, &i__10);
				i__11[3] = 1, a__6[3] = ch__3;
				i__11[4] = lnoten, a__6[4] = noteq;
				s_cat(notexq, a__6, i__11, &c__5, (ftnlen)79);
				i__10 = lnoten + 8;
				addstr_(notexq, &i__10, soutq, &lsout, (
					ftnlen)79, (ftnlen)80);
			    } else {
/* Writing concatenation */
				i__12[0] = 1, a__7[0] = all_1.sq;
				i__12[1] = 5, a__7[1] = "islur";
				i__12[2] = 1, a__7[2] = slurudq;
				i__12[3] = 2, a__7[3] = "{1";
				i__10 = comslur_1.ndxslur + 38;
				chax_(ch__3, (ftnlen)1, &i__10);
				i__12[4] = 1, a__7[4] = ch__3;
				i__12[5] = 1, a__7[5] = "}";
				i__12[6] = lnoten, a__7[6] = noteq;
				s_cat(notexq, a__7, i__12, &c__7, (ftnlen)79);
				i__10 = lnoten + 11;
				addstr_(notexq, &i__10, soutq, &lsout, (
					ftnlen)79, (ftnlen)80);
			    }
			    setbits_(&all_1.ipl[commvl_1.ivx + ip * 15 - 16], 
				    &c__4, &c__23, &comslur_1.ndxslur);
			    if (bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 
				    16],31)) {
				comslur_1.listslur = bit_set(
					comslur_1.listslur,comslur_1.ndxslur);
			    }

/*  Starting slur on W-grace on THIS note.  Record ndxslur. */

			}
		    }

/*  Process dynamic marks */

		    if (bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],26))
			     {
			i__10 = ncmid_(&all_1.iv, &ip);
			dodyn_(&commvl_1.ivx, &ip, &all_1.nolev[commvl_1.ivx 
				+ ip * 15 - 16], &i__10, &all_1.ipl[
				commvl_1.ivx + ip * 15 - 16], &all_1.islur[
				commvl_1.ivx + ip * 15 - 16], &commvl_1.nvmx[
				all_1.iv - 1], &all_1.nv, &all_1.beamon[
				commvl_1.ivx - 1], soutq, &lsout, (ftnlen)80);
		    }

/*  Check for chord notes.  Moved up from below, 10/27/96 so chord orns done 1st. */

		    if (bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 16],10)) {

/*  Need a duration to set type of note head */

/*             if (.not. vxtup(ivx)) then */

/*  Clumsy test, but vxtup is not set until main note is processed. */

			if (! (comxtup_1.vxtup[commvl_1.ivx - 1] || bit_test(
				all_1.irest[commvl_1.ivx + ip * 15 - 16],28)))
				 {
			    nodu = all_1.nodur[commvl_1.ivx + ip * 15 - 16];
			} else if (all_1.mult[commvl_1.ivx + ip * 15 - 16] < 
				0) {
			    nodu = 32;
			} else {
			    nodu = 16;
			}
			i__10 = ncmid_(&all_1.iv, &ip);
			docrd_(&commvl_1.ivx, &ip, &nodu, &i__10, &all_1.iv, &
				tnow, soutq, &lsout, all_1.ulq, &all_1.ibmcnt[
				commvl_1.ivx - 1], &all_1.islur[commvl_1.ivx 
				+ ip * 15 - 16], &commvl_1.nvmx[all_1.iv - 1],
				 &all_1.nv, &all_1.beamon[commvl_1.ivx - 1], &
				all_1.nolev[commvl_1.ivx + ip * 15 - 16], 
				ihornb, nornb, &all_1.stemlen, (ftnlen)80, (
				ftnlen)1);
		    }

/*  Now that chords are done, add stuff to midi file */

		    if (commidi_1.ismidi) {
			i__10 = all_1.nacc[commvl_1.ivx + ip * 15 - 16] & 7;
			L__1 = bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 
				16],0);
			addmidi_(&icm, &all_1.nolev[commvl_1.ivx + ip * 15 - 
				16], &i__10, &comtop_1.isig, &all_1.tnote[(
				all_1.ipl[commvl_1.ivx + ip * 15 - 16] & 255) 
				- 1], &L__1, &c_false);
		    }

/*  Check for main-note ornaments. ')' on dotted notes go in with note, not here. */
/*  Bits 0-13: (stmgx+Tupf._) ; 14: Down fermata, was F */
/*  15: Trill w/o "tr", was U , 16-18 edit. accid., 19-21 TBD */

		    isacc = (all_1.iornq[commvl_1.ivx + ip * 15 - 1] & 
			    4194287) > 0;

/*  isacc=.true. if any ornament except segno */

		    if (bit_test(all_1.iornq[commvl_1.ivx + ip * 15 - 1],13) 
			    && all_1.nodur[commvl_1.ivx + ip * 15 - 16] > 0) {

/*  If ).  is only ornament, bypass.  If with others, temporarirly zero the bit. */

			i__10 = log2_(&all_1.nodur[commvl_1.ivx + ip * 15 - 
				16]);
			if (pow_ii(&c__2, &i__10) != all_1.nodur[commvl_1.ivx 
				+ ip * 15 - 16]) {
			    if ((all_1.iornq[commvl_1.ivx + ip * 15 - 1] & 
				    516079) == 0) {

/*  ). is the only non-segno ornament */

				isacc = FALSE_;
			    } else {

/*  There are other ornaments in addition */

				rpndot = TRUE_;
				all_1.iornq[commvl_1.ivx + ip * 15 - 1] = 
					bit_clear(all_1.iornq[commvl_1.ivx + 
					ip * 15 - 1],13);
			    }
			}
		    }
		    if (isacc && ! comcwrf_1.cwrferm[commvl_1.ivx - 1]) {

/*  Check for centered whole-bar rest with fermata (bits 10 or 14). */

			if ((all_1.iornq[commvl_1.ivx + ip * 15 - 1] & 17408) 
				> 0 && bit_test(all_1.irest[commvl_1.ivx + ip 
				* 15 - 16],0) && all_1.nodur[commvl_1.ivx + 
				ip * 15 - 16] == all_1.lenbar && ! (
				all_1.firstgulp && all_1.ibar == 1 && 
				all_1.lenb0 > 0)) {
			    comcwrf_1.cwrferm[commvl_1.ivx - 1] = TRUE_;
			    goto L30;
			}
			i__10 = ncmid_(&all_1.iv, &ip);
			L__1 = bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 16]
				,10);
			putorn_(&all_1.iornq[commvl_1.ivx + ip * 15 - 1], &
				all_1.nolev[commvl_1.ivx + ip * 15 - 16], &
				all_1.nolev[commvl_1.ivx + ip * 15 - 16], &
				all_1.nodur[commvl_1.ivx + ip * 15 - 16], 
				nornb, all_1.ulq, &all_1.ibmcnt[commvl_1.ivx 
				- 1], &commvl_1.ivx, &i__10, &all_1.islur[
				commvl_1.ivx + ip * 15 - 16], &commvl_1.nvmx[
				all_1.iv - 1], &all_1.nv, ihornb, &
				all_1.stemlen, notexq, &lnote, &ip, &islhgt, &
				all_1.beamon[commvl_1.ivx - 1], &L__1, (
				ftnlen)1, (ftnlen)79);
			addstr_(notexq, &lnote, soutq, &lsout, (ftnlen)79, (
				ftnlen)80);
		    }
		    if (rpndot) {
			all_1.iornq[commvl_1.ivx + ip * 15 - 1] = bit_set(
				all_1.iornq[commvl_1.ivx + ip * 15 - 1],13);
			rpndot = FALSE_;
		    }
L30:

/*  Check for main note accidental */

		    if ((all_1.nacc[commvl_1.ivx + ip * 15 - 16] & 3) > 0) {
			i__10 = igetbits_(&all_1.nacc[commvl_1.ivx + ip * 15 
				- 16], &c__7, &c__10) - 64;
			i__13 = igetbits_(&all_1.nacc[commvl_1.ivx + ip * 15 
				- 16], &c__6, &c__4);
			L__1 = bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 16]
				,8);
			i__14 = ncmid_(&all_1.iv, &ip);
			doacc_(&i__10, &i__13, &L__1, notexq, &lnote, &
				all_1.nacc[commvl_1.ivx + ip * 15 - 16], &
				all_1.nolev[commvl_1.ivx + ip * 15 - 16], &
				i__14, (ftnlen)79);
			addstr_(notexq, &lnote, soutq, &lsout, (ftnlen)79, (
				ftnlen)80);
		    }

/*  Lower dot for lower-voice notes.  Conditions are: */
/*   1. Dotted time value */
/*   2. Lower voice of two */
/*   3. Note is on a line */
/*   4. Not a rest */
/* .  5. Flag (lowdot) is set to true */
/*   6. Not in an xtuplet */

		    if (comarp_1.lowdot && commvl_1.nvmx[all_1.iv - 1] == 2 &&
			     commvl_1.ivx <= all_1.nv && all_1.nodur[
			    commvl_1.ivx + ip * 15 - 16] != 0) {
			i__10 = log2_(&all_1.nodur[commvl_1.ivx + ip * 15 - 
				16]);
			if (! bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 
				16],0) && pow_ii(&c__2, &i__10) != 
				all_1.nodur[commvl_1.ivx + ip * 15 - 16] && (
				all_1.nolev[commvl_1.ivx + ip * 15 - 16] - 
				ncmid_(&commvl_1.ivx, &ip)) % 2 == 0) {
			    if (bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 
				    16],19)) {

/*  Note already in movdot list.  Drop by 2. */

				comcc_1.updot[commvl_1.ivx + (comcc_1.ndotmv[
					commvl_1.ivx - 1] + 1) * 15 - 16] += (
					float)-2.;
			    } else {

/*  Not in list so just move it right now */

				i__10 = igetbits_(&all_1.islur[commvl_1.ivx + 
					ip * 15 - 16], &c__1, &c__3);
				dotmov_(&c_b2065, &c_b1398, soutq, &lsout, &
					i__10, (ftnlen)80);
			    }
			}
		    }

/*  Check for dotted notes with moved dots */

		    if (bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],19))
			     {
			++comcc_1.ndotmv[commvl_1.ivx - 1];
			i__10 = igetbits_(&all_1.islur[commvl_1.ivx + ip * 15 
				- 16], &c__1, &c__3);
			dotmov_(&comcc_1.updot[commvl_1.ivx + comcc_1.ndotmv[
				commvl_1.ivx - 1] * 15 - 16], &comcc_1.rtdot[
				commvl_1.ivx + comcc_1.ndotmv[commvl_1.ivx - 
				1] * 15 - 16], soutq, &lsout, &i__10, (ftnlen)
				80);
		    }

/*  Zero out slur-height marker for raising ornaments */

		    islhgt = 0;

/*  Now start with spacing notes.  Is a beam start pending? */

		    if (bspend && all_1.ibm2[commvl_1.ivx + all_1.ibmcnt[
			    commvl_1.ivx - 1] * 15 - 16] > all_1.ibm1[
			    commvl_1.ivx + all_1.ibmcnt[commvl_1.ivx - 1] * 
			    15 - 16]) {
			if (strtmid_1.ixrest[commvl_1.ivx - 1] == 4) {

/*  Special path for single note at end of otherwise beamed xtup */

			    strtmid_1.ixrest[commvl_1.ivx - 1] = 0;
			} else {
			    beamn1_(notexq, &lnote, (ftnlen)79);
			}
			bspend = FALSE_;

/*  Is a beam ending? */

		    } else if (numbms[commvl_1.ivx] > 0 && all_1.ibmcnt[
			    commvl_1.ivx - 1] <= numbms[commvl_1.ivx] && 
			    all_1.ibm2[commvl_1.ivx + all_1.ibmcnt[
			    commvl_1.ivx - 1] * 15 - 16] == ip) {
			if (bspend) {

/*  Must be a single-note ending of a jump-beam */

			    combjmp_1.isbjmp = TRUE_;
			    bspend = FALSE_;
			}
			beamend_(notexq, &lnote, (ftnlen)79);
			comxtup_1.vxtup[commvl_1.ivx - 1] = FALSE_;
			nornb[commvl_1.ivx - 1] = 0;
			++all_1.ibmcnt[commvl_1.ivx - 1];
			all_1.beamon[commvl_1.ivx - 1] = FALSE_;

/*  Or if we're in the middle of a beam */

		    } else if (numbms[commvl_1.ivx] > 0 && all_1.beamon[
			    commvl_1.ivx - 1]) {
			beamid_(notexq, &lnote, (ftnlen)79);

/*      Or whole-bar rest */

		    } else if (bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 
			    16],0) && all_1.nodur[commvl_1.ivx + ip * 15 - 16]
			     == all_1.lenbar && ! (all_1.firstgulp && 
			    all_1.ibar == 1 && all_1.lenb0 > 0) && ! bit_test(
			    all_1.irest[commvl_1.ivx + ip * 15 - 16],25) && ! 
			    bit_test(all_1.islur[commvl_1.ivx + ip * 15 - 16],
			    29)) {

/*  Rule out pickup bar, blank rests, non-centered.  Remember islur b19=> rp */

			cwrest[commvl_1.ivx] = TRUE_;
			iscwr = TRUE_;
			notex_(cwrq + (commvl_1.ivx - 1) * 79, &lcwr[
				commvl_1.ivx - 1], (ftnlen)79);
			tnow += all_1.lenbar;
			goto L10;
		    } else if (strtmid_1.ixrest[commvl_1.ivx - 1] == 0) {

/*  Write a separate note */

			notex_(notexq, &lnote, (ftnlen)79);
		    }

/*  Right offset?  This may cause trouble */

		    if (bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 16],8)) {
/* Writing concatenation */
			i__6[0] = 1, a__3[0] = all_1.sq;
			i__6[1] = 5, a__3[1] = "loff{";
			s_cat(ch__14, a__3, i__6, &c__2, (ftnlen)6);
			addstr_(ch__14, &c__6, soutq, &lsout, (ftnlen)6, (
				ftnlen)80);
		    } else if (bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 16]
			    ,9)) {
/* Writing concatenation */
			i__6[0] = 1, a__3[0] = all_1.sq;
			i__6[1] = 5, a__3[1] = "roff{";
			s_cat(ch__14, a__3, i__6, &c__2, (ftnlen)6);
			addstr_(ch__14, &c__6, soutq, &lsout, (ftnlen)6, (
				ftnlen)80);
		    }
		    if (strtmid_1.ixrest[commvl_1.ivx - 1] == 0 && lnote > 0) 
			    {
			addstr_(notexq, &lnote, soutq, &lsout, (ftnlen)79, (
				ftnlen)80);
		    }
		    if (bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 16],8) || 
			    bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 16],9)
			    ) {
			addstr_("}", &c__1, soutq, &lsout, (ftnlen)1, (ftnlen)
				80);
		    }

/*  Terminate user-defined offsets.  Fix format */

		    if (bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],15) 
			    || bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 
			    16],17)) {
			putshft_(&commvl_1.ivx, &c_false, soutq, &lsout, (
				ftnlen)80);
		    }

/*  Deal with After- and Way-after-graces.  First, if end of bar, compute space */
/*    needed since it wasn't done during general ask-checks. If extra space is */
/*    rq'd, convert GW to GA.  Therefore GW at end of bar never needs extra sp. */
/*    But will still need to add extra space as hardspace. */

		    if (ip == all_1.nn[commvl_1.ivx - 1] && (bit_test(
			    all_1.ipl[commvl_1.ivx + ip * 15 - 16],31) || 
			    bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 16],
			    29))) {
			i__10 = comgrace_1.ngrace;
			for (ig = 1; ig <= i__10; ++ig) {
			    if (comgrace_1.ipg[ig - 1] == ip && 
				    comgrace_1.ivg[ig - 1] == commvl_1.ivx) {
				goto L78;
			    }
/* L77: */
			}
			s_wsle(&io___587);
			do_lio(&c__9, &c__1, "Problem finding grace index \
at \"do 77\"", (ftnlen)38);
			e_wsle();
			s_stop("1", (ftnlen)1);
L78:

/*  Get elemskip to end of bar.  WON'T WORK IF XTUPS !! */

			esk = (float)0.;
			i__10 = comnsp_1.nb;
			for (iib = ib; iib <= i__10; ++iib) {
			    if (iib == ib) {
				itleft = i_nint(&all_1.to[(255 & all_1.ipl[
					commvl_1.ivx + ip * 15 - 16]) - 1]);
			    } else {
				itleft = i_nint(&tstart[ib]);
			    }
			    if (iib < comnsp_1.nb) {
				itright = i_nint(&tstart[iib + 1]);
			    } else {
				itright = all_1.lenbar;
			    }
			    esk += feon_(&comnsp_1.space[ib - 1]) * (itright 
				    - itleft) / comnsp_1.space[ib - 1];
/* L40: */
			}
			ptsavail = comask_1.poenom * esk - comask_1.wheadpt;
			if (comgrace_1.nng[ig - 1] == 1) {
			    wgr = spfacs_1.grafac;
			} else {
			    wgr = comgrace_1.nng[ig - 1] * spfacs_1.emgfac;
			    i__10 = comgrace_1.nng[ig - 1];
			    for (ing = 1; ing <= i__10; ++ing) {
				if (comgrace_1.naccg[comgrace_1.ngstrt[ig - 1]
					 - 1 + ing - 1] > 0) {
				    wgr += spfacs_1.acgfac;
				}
/* L41: */
			    }
			}
			ptgr[ig - 1] = wgr * comask_1.wheadpt;
			ptsneed = (wgr + (float).5) * comask_1.wheadpt;
			ptsndg[commvl_1.ivx - 1] = (float)0.;
			if (ptsavail < ptsneed) {
			    ptsndg[commvl_1.ivx - 1] = ptsneed;
			    eskndg[commvl_1.ivx - 1] = esk;
			    if (bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 
				    16],31)) {

/*  Convert GW to GA */

				all_1.ipl[commvl_1.ivx + ip * 15 - 16] = 
					bit_set(bit_clear(all_1.ipl[
					commvl_1.ivx + ip * 15 - 16],31),29);
			    }
			}
		    }

/*  Check for GA */

		    if (bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 16],29)) {
			i__10 = ncmid_(&all_1.iv, &ip);
			dograce_(&commvl_1.ivx, &ip, ptgr, soutq, &lsout, &
				i__10, &all_1.nacc[commvl_1.ivx + ip * 15 - 
				16], &ig, &all_1.ipl[commvl_1.ivx + ip * 15 - 
				16], &c_false, (ftnlen)80);
		    }

/*  Update running time */

		    tnow += comnsp_1.space[ib - 1];
L10:
		    ;
		}

/*  Have finished last note in this voice and block */

		r__1 = all_1.to[istop[ib] - 1] + comnsp_1.space[ib - 1];
		itendb = i_nint(&r__1);
L17:
		if (all_1.figcheck && comfig_1.itfig[ifig - 1] < itendb) {

/*  There's at least one figure left. offnsk could be <0 */

		    offnsk = (tnow - comfig_1.itfig[ifig - 1]) / 
			    comnsp_1.space[ib - 1];
		    putfig_(&ifig, &offnsk, &all_1.figcheck, soutq, &lsout, (
			    ftnlen)80);
		    goto L17;
		}

/*  Check for flag, dot, or upstem on last note of bar. */

		if (ib == comnsp_1.nb) {
		    ip = all_1.ipo[(255 & all_1.ipl[commvl_1.ivx + all_1.nn[
			    commvl_1.ivx - 1] * 15 - 16]) - 1];
		    comnsp_1.flgndv[commvl_1.ivx - 1] = (float)0.;
		    if ((r__1 = all_1.tnote[(255 & all_1.ipl[commvl_1.ivx + 
			    ip * 15 - 16]) - 1] - comnsp_1.space[ib - 1], 
			    dabs(r__1)) < comtol_1.tol) {
			if (comnsp_1.space[ib - 1] < (float)16. - 
				comtol_1.tol) {

/*  Note in last space, smaller than a quarter note. */

			    i__8 = ncmid_(&all_1.iv, &ip);
			    udqq_(ch__3, (ftnlen)1, &all_1.nolev[commvl_1.ivx 
				    + ip * 15 - 16], &i__8, &all_1.islur[
				    commvl_1.ivx + ip * 15 - 16], &
				    commvl_1.nvmx[all_1.iv - 1], &
				    commvl_1.ivx, &all_1.nv);
			    if (! bit_test(all_1.irest[commvl_1.ivx + ip * 15 
				    - 16],0) && *(unsigned char *)&ch__3[0] ==
				     'u' || isdotted_(all_1.nodur, &
				    commvl_1.ivx, &ip)) {

/*  Upstem non-rest, or dotted */

/* Computing MAX */
				i__8 = 1, i__10 = numbms[commvl_1.ivx];
				if (numbms[commvl_1.ivx] > 0 && ip == 
					all_1.ibm2[commvl_1.ivx + max(i__8,
					i__10) * 15 - 16] && ! isdotted_(
					all_1.nodur, &commvl_1.ivx, &ip)) {

/*  In beam and not dotted, so use smaller space */

				    comnsp_1.flgndv[commvl_1.ivx - 1] = 
					    spfacs_1.upstmfac;
				} else {
				    comnsp_1.flgndv[commvl_1.ivx - 1] = 
					    spfacs_1.flagfac;
				}
			    }
			} else {

/*  Last space, nonflagged (no beam) only worry dot or up */

			    if (isdotted_(all_1.nodur, &commvl_1.ivx, &ip)) {
				comnsp_1.flgndv[commvl_1.ivx - 1] = 
					spfacs_1.flagfac;
			    } else /* if(complicated condition) */ {
				i__8 = ncmid_(&all_1.iv, &ip);
				udqq_(ch__3, (ftnlen)1, &all_1.nolev[
					commvl_1.ivx + ip * 15 - 16], &i__8, &
					all_1.islur[commvl_1.ivx + ip * 15 - 
					16], &commvl_1.nvmx[all_1.iv - 1], &
					commvl_1.ivx, &all_1.nv);
				if (all_1.tnote[(255 & all_1.ipl[commvl_1.ivx 
					+ ip * 15 - 16]) - 1] < (float)64. && 
					*(unsigned char *)&ch__3[0] == 'u') {

/*  Upstem on last note , non-flagged */

				    comnsp_1.flgndv[commvl_1.ivx - 1] = 
					    spfacs_1.upstmfac;
				}
			    }
			}
		    }

/*  Check for right-shifted chordal note */

		    if (bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],20))
			     {
			comnsp_1.flgndv[commvl_1.ivx - 1] = spfacs_1.rtshfac;
		    }
		    comnsp_1.flgndb = comnsp_1.flgndb || comnsp_1.flgndv[
			    commvl_1.ivx - 1] > (float)0.;
		    if (commidi_1.ismidi) {

/*  For midi, set flags for accidentals on last note of bar.  Assume they affect */
/*    first note of next bar whether or not tied. */
/*  Note has already been done, so next entry into addmidi is 1st in new bar. */
/*  First do main note, then chord notes */

/*  Gyrations needed to account for multi-bar tied full-bar notes? */
/* c  Old old    lbacc(icm) = iand(nacc(ivx,ip),7) */
/*   New old    if (lbacc(icm).eq.0) lbacc(icm) = iand(nacc(ivx,ip),7) */

			if ((all_1.nacc[commvl_1.ivx + ip * 15 - 16] & 7) > 0)
				 {

/*  Explicit accidental on last main note in bar */

			    i__8 = comslm_1.naccbl[icm];
			    for (kacc = 1; kacc <= i__8; ++kacc) {
				if (comslm_1.laccbl[icm + (kacc << 4) - 16] ==
					 all_1.nolev[commvl_1.ivx + ip * 15 - 
					16]) {
				    goto L56;
				}
/* L55: */
			    }
			    ++comslm_1.naccbl[icm];
			    comslm_1.laccbl[icm + (comslm_1.naccbl[icm] << 4) 
				    - 16] = all_1.nolev[commvl_1.ivx + ip * 
				    15 - 16];
			    i__8 = all_1.nacc[commvl_1.ivx + ip * 15 - 16] & 
				    7;
			    comslm_1.jaccbl[icm + (comslm_1.naccbl[icm] << 4) 
				    - 16] = iashft_(&i__8);
			}
L56:
			if (bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 16],
				10) && commidi_1.crdacc) {
			    i__8 = comtrill_1.icrd2;
			    for (icrd = comtrill_1.icrd1; icrd <= i__8; 
				    ++icrd) {
				iacc = igetbits_(&comtrill_1.icrdat[icrd - 1],
					 &c__3, &c__20);
				if (iacc > 0) {

/*  Explicit accidental on chord note at end of bar */

				    nolevc = igetbits_(&comtrill_1.icrdat[
					    icrd - 1], &c__7, &c__12);
				    i__10 = comslm_1.naccbl[icm];
				    for (kacc = 1; kacc <= i__10; ++kacc) {
					if (comslm_1.laccbl[icm + (kacc << 4) 
						- 16] == nolevc) {
					    goto L59;
					}
/* L58: */
				    }
				    ++comslm_1.naccbl[icm];
				    comslm_1.laccbl[icm + (comslm_1.naccbl[
					    icm] << 4) - 16] = nolevc;
				    comslm_1.jaccbl[icm + (comslm_1.naccbl[
					    icm] << 4) - 16] = iashft_(&iacc);
				}
L59:
/* L57: */
				;
			    }
			}
/*              if (lbacc(icm).eq.0 .and. accb4(icm)) then */
			i__8 = commidi_1.naccim[icm];
			for (kacc = 1; kacc <= i__8; ++kacc) {

/*  If naccim(icm)>0, */
/*  possible implicit accidental from earlier in the bar.  Check for prior accid */
/*  in this bar at relevant note levels, main and chord notes.  Only act if no */
/*  explicit action from just above.  Assuming any accid on last note in bar, */
/*  either explicit or implicit, has same effect on 1st note of next bar. */

			    if (all_1.nolev[commvl_1.ivx + ip * 15 - 16] == 
				    commidi_1.laccim[icm + (kacc << 4) - 16]) 
				    {
				goto L66;
			    }
			    if (bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 
				    16],10)) {
				i__10 = comtrill_1.icrd2;
				for (icrd = comtrill_1.icrd1; icrd <= i__10; 
					++icrd) {
				    if ((lbit_shift(comtrill_1.icrdat[icrd - 
					    1], (ftnlen)-12) & 127) == 
					    commidi_1.laccim[icm + (kacc << 4)
					     - 16]) {
					goto L66;
				    }
/* L67: */
				}
			    }
			    goto L65;
L66:

/*  So far we know there is a main or chord note at level laccim(icm,kacc). So */
/*   it will get a bl-accid if it didn't just already get one. */

			    i__10 = comslm_1.naccbl[icm];
			    for (macc = 1; macc <= i__10; ++macc) {
				if (comslm_1.laccbl[icm + (macc << 4) - 16] ==
					 commidi_1.laccim[icm + (kacc << 4) - 
					16]) {
				    goto L65;
				}
/* L68: */
			    }
			    ++comslm_1.naccbl[icm];
			    comslm_1.laccbl[icm + (comslm_1.naccbl[icm] << 4) 
				    - 16] = commidi_1.laccim[icm + (kacc << 4)
				     - 16];
			    comslm_1.jaccbl[icm + (comslm_1.naccbl[icm] << 4) 
				    - 16] = commidi_1.jaccim[icm + (kacc << 4)
				     - 16];
L65:
			    ;
			}
		    }
		}
/* L11: */
	    }
	}

/*  Close out the notes group */

/* Writing concatenation */
	i__6[0] = 1, a__3[0] = all_1.sq;
	i__6[1] = 2, a__3[1] = "en";
	s_cat(ch__11, a__3, i__6, &c__2, (ftnlen)3);
	addstr_(ch__11, &c__3, soutq, &lsout, (ftnlen)3, (ftnlen)80);
	if (comlast_1.islast && lsout > 0) {
	    s_wsfe(&io___600);
/* Writing concatenation */
	    i__6[0] = lsout, a__3[0] = soutq;
	    i__6[1] = 1, a__3[1] = "%";
	    s_cat(ch__9, a__3, i__6, &c__2, (ftnlen)81);
	    do_fio(&c__1, ch__9, lsout + 1);
	    e_wsfe();
	}
/* L16: */
    }

/*  Check for way-after graces at end of bar.  We could not link these to notes */
/*  as in midbar since there is no note following grace!  Also, set flag if */
/*  hardspace is needed. Also, save nvmx, ivmx for use in space checks on reloop. */

    isgrace = FALSE_;
    i__2 = all_1.nv;
    for (all_1.iv = 1; all_1.iv <= i__2; ++all_1.iv) {
	comnsp_1.nvmxsav[all_1.iv - 1] = commvl_1.nvmx[all_1.iv - 1];
	i__5 = commvl_1.nvmx[all_1.iv - 1];
	for (kv = 1; kv <= i__5; ++kv) {
	    comnsp_1.ivmxsav[all_1.iv + kv * 15 - 16] = commvl_1.ivmx[
		    all_1.iv + kv * 15 - 16];
	    commvl_1.ivx = commvl_1.ivmx[all_1.iv + kv * 15 - 16];
	    comnsp_1.ptsgnd = (float)0.;
	    if ((bit_test(all_1.ipl[commvl_1.ivx + all_1.nn[commvl_1.ivx - 1] 
		    * 15 - 16],29) || bit_test(all_1.ipl[commvl_1.ivx + 
		    all_1.nn[commvl_1.ivx - 1] * 15 - 16],31)) && ptsndg[
		    commvl_1.ivx - 1] > (float)0.) {
		comnsp_1.flgndb = TRUE_;
		if (ptsndg[commvl_1.ivx - 1] > comnsp_1.ptsgnd) {
		    comnsp_1.ptsgnd = ptsndg[commvl_1.ivx - 1];
		    comnsp_1.eskgnd = eskndg[commvl_1.ivx - 1];
		}
	    }
	    if (bit_test(all_1.ipl[commvl_1.ivx + all_1.nn[commvl_1.ivx - 1] *
		     15 - 16],31)) {

/*  This voice has a way-after grace here at end of bar */

		if (! isgrace) {

/*  This is the first one, so set up the string */

		    isgrace = TRUE_;
		    ivlast = 1;
/* Writing concatenation */
		    i__6[0] = 1, a__3[0] = all_1.sq;
		    i__6[1] = 6, a__3[1] = "znotes";
		    s_cat(soutq, a__3, i__6, &c__2, (ftnlen)80);
		    lsout = 7;
		}
		i__1 = all_1.iv - 1;
		for (iiv = ivlast; iiv <= i__1; ++iiv) {
		    addstr_(all_1.sepsymq + (iiv - 1), &c__1, soutq, &lsout, (
			    ftnlen)1, (ftnlen)80);
/* L76: */
		}
		ivlast = all_1.iv;

/*  No need to put in 'nextvoice', even if 2 lines/staff */

		i__1 = ncmid_(&all_1.iv, &all_1.nn[commvl_1.ivx - 1]);
		dograce_(&commvl_1.ivx, &all_1.nn[commvl_1.ivx - 1], ptgr, 
			soutq, &lsout, &i__1, &all_1.nacc[commvl_1.ivx + 
			all_1.nn[commvl_1.ivx - 1] * 15 - 16], &ig, &
			all_1.ipl[commvl_1.ivx + all_1.nn[commvl_1.ivx - 1] * 
			15 - 16], &c_true, (ftnlen)80);
	    }
/* L75: */
	}
    }
    if (isgrace) {
/* Writing concatenation */
	i__6[0] = 1, a__3[0] = all_1.sq;
	i__6[1] = 3, a__3[1] = "en%";
	s_cat(ch__15, a__3, i__6, &c__2, (ftnlen)4);
	addstr_(ch__15, &c__4, soutq, &lsout, (ftnlen)4, (ftnlen)80);
	if (comlast_1.islast && lsout > 0) {
	    s_wsfe(&io___603);
	    do_fio(&c__1, soutq, lsout);
	    e_wsfe();
	}
    }
    lsout = 0;

/*  Write multibar rest.  Assuming nv = 1  and do not worry about cwbrest */
/*  This has to be the only use of atnextbar */

    if (all_1.ibar == comgrace_1.ibarmbr) {
/* Writing concatenation */
	i__9[0] = 1, a__5[0] = all_1.sq;
	i__9[1] = 3, a__5[1] = "def";
	i__9[2] = 1, a__5[2] = all_1.sq;
	i__9[3] = 10, a__5[3] = "atnextbar{";
	i__9[4] = 1, a__5[4] = all_1.sq;
	i__9[5] = 6, a__5[5] = "znotes";
	i__9[6] = 1, a__5[6] = all_1.sq;
	i__9[7] = 7, a__5[7] = "mbrest{";
	s_cat(ch__16, a__5, i__9, &c__8, (ftnlen)30);
	addstr_(ch__16, &c__30, soutq, &lsout, (ftnlen)30, (ftnlen)80);
	r__1 = comgrace_1.mbrest + (float).01;
	ndig = (integer) r_lg10(&r__1) + 1;
	ici__1.icierr = 0;
	ici__1.icirnum = 1;
	ici__1.icirlen = 3;
	ici__1.iciunit = soutq + 30;
/* Writing concatenation */
	i__4[0] = 2, a__2[0] = "(i";
	i__5 = ndig + 48;
	chax_(ch__3, (ftnlen)1, &i__5);
	i__4[1] = 1, a__2[1] = ch__3;
	i__4[2] = 1, a__2[2] = ")";
	ici__1.icifmt = (s_cat(ch__15, a__2, i__4, &c__3, (ftnlen)4), ch__15);
	s_wsfi(&ici__1);
	do_fio(&c__1, (char *)&comgrace_1.mbrest, (ftnlen)sizeof(integer));
	e_wsfi();
	lsout += ndig;
	addstr_("}{", &c__2, soutq, &lsout, (ftnlen)2, (ftnlen)80);
	mtrspc = comgrace_1.xb4mbr + (float).5;
	comgrace_1.xb4mbr = (float)0.;
	if (mtrspc == 0) {
	    ndig = 1;
	} else {
	    r__1 = mtrspc + (float).01;
	    ndig = (integer) r_lg10(&r__1) + 1;
	}
	i__5 = lsout;
	ici__1.icierr = 0;
	ici__1.icirnum = 1;
	ici__1.icirlen = lsout + 2 - i__5;
	ici__1.iciunit = soutq + i__5;
/* Writing concatenation */
	i__4[0] = 2, a__2[0] = "(i";
	i__2 = ndig + 48;
	chax_(ch__3, (ftnlen)1, &i__2);
	i__4[1] = 1, a__2[1] = ch__3;
	i__4[2] = 1, a__2[2] = ")";
	ici__1.icifmt = (s_cat(ch__15, a__2, i__4, &c__3, (ftnlen)4), ch__15);
	s_wsfi(&ici__1);
	do_fio(&c__1, (char *)&mtrspc, (ftnlen)sizeof(integer));
	e_wsfi();
	lsout += ndig;
/* Writing concatenation */
	i__4[0] = 2, a__2[0] = "}0";
	i__4[1] = 1, a__2[1] = all_1.sq;
	i__4[2] = 4, a__2[2] = "en}%";
	s_cat(ch__17, a__2, i__4, &c__3, (ftnlen)7);
	addstr_(ch__17, &c__7, soutq, &lsout, (ftnlen)7, (ftnlen)80);
	if (comlast_1.islast) {
	    s_wsfe(&io___606);
	    do_fio(&c__1, soutq, lsout);
	    e_wsfe();
	}
	lsout = 0;
	r__1 = comgrace_1.mbrest - 1 + (float).01;
	ndig = (integer) r_lg10(&r__1) + 1;
	if (comgrace_1.mbrest == 1) {
	    ndig = 1;
	}
	if (comlast_1.islast) {
	    ci__1.cierr = 0;
	    ci__1.ciunit = 11;
/* Writing concatenation */
	    i__4[0] = 6, a__2[0] = "(a14,i";
	    i__5 = ndig + 48;
	    chax_(ch__3, (ftnlen)1, &i__5);
	    i__4[1] = 1, a__2[1] = ch__3;
	    i__4[2] = 4, a__2[2] = ",a1)";
	    ci__1.cifmt = (s_cat(ch__6, a__2, i__4, &c__3, (ftnlen)11), ch__6)
		    ;
	    s_wsfe(&ci__1);
/* Writing concatenation */
	    i__7[0] = 1, a__4[0] = all_1.sq;
	    i__7[1] = 7, a__4[1] = "advance";
	    i__7[2] = 1, a__4[2] = all_1.sq;
	    i__7[3] = 5, a__4[3] = "barno";
	    s_cat(ch__18, a__4, i__7, &c__4, (ftnlen)14);
	    do_fio(&c__1, ch__18, (ftnlen)14);
	    i__2 = comgrace_1.mbrest - 1;
	    do_fio(&c__1, (char *)&i__2, (ftnlen)sizeof(integer));
	    do_fio(&c__1, "%", (ftnlen)1);
	    e_wsfe();
	}
    } else if (iscwr) {

/*  Centered whole-bar rests */

/* Writing concatenation */
	i__3[0] = 1, a__1[0] = all_1.sq;
	i__3[1] = 3, a__1[1] = "def";
	i__3[2] = 1, a__1[2] = all_1.sq;
	i__3[3] = 10, a__1[3] = "atnextbar{";
	i__3[4] = 1, a__1[4] = all_1.sq;
	i__3[5] = 6, a__1[5] = "znotes";
	s_cat(ch__19, a__1, i__3, &c__6, (ftnlen)22);
	addstr_(ch__19, &c__22, soutq, &lsout, (ftnlen)22, (ftnlen)80);
	i__5 = all_1.nv;
	for (all_1.iv = 1; all_1.iv <= i__5; ++all_1.iv) {
	    lnote = 0;
	    i__2 = commvl_1.nvmx[all_1.iv - 1];
	    for (kv = 1; kv <= i__2; ++kv) {
		commvl_1.ivx = commvl_1.ivmx[all_1.iv + kv * 15 - 16];
		if (cwrest[commvl_1.ivx]) {
		    if (lnote == 0) {
/* Writing concatenation */
			i__6[0] = 1, a__3[0] = all_1.sq;
			i__6[1] = 10, a__3[1] = "centerbar{";
			s_cat(notexq, a__3, i__6, &c__2, (ftnlen)79);
			lnote = 11;
		    }
/*              notexq = notexq(1:lnote)//cwrq(ivx)(1:lcwr(ivx)) */
/*              lnote = lnote+lcwr(ivx) */
/*              if (cwrferm(ivx)) then */
/* c */
/* c  Fermata on centered rest.  Will need to fix up level. */
/* c */
/*                notexq = notexq(1:lnote)//sq//'fermataup7' */
/*                lnote = lnote+11 */
/*                cwrferm(ivx) = .false. */
/*              end if */
		    if (! comcwrf_1.cwrferm[commvl_1.ivx - 1]) {
/* Writing concatenation */
			i__6[0] = lnote, a__3[0] = notexq;
			i__6[1] = lcwr[commvl_1.ivx - 1], a__3[1] = cwrq + (
				commvl_1.ivx - 1) * 79;
			s_cat(notexq, a__3, i__6, &c__2, (ftnlen)79);
			lnote += lcwr[commvl_1.ivx - 1];
		    } else {

/*  Fermata on centered rest.  Will need to fix up level. */

/* Writing concatenation */
			i__7[0] = lnote, a__4[0] = notexq;
			i__7[1] = 1, a__4[1] = all_1.sq;
			i__7[2] = 10, a__4[2] = "fermataup7";
			i__7[3] = lcwr[commvl_1.ivx - 1], a__4[3] = cwrq + (
				commvl_1.ivx - 1) * 79;
			s_cat(notexq, a__4, i__7, &c__4, (ftnlen)79);
			lnote = lnote + 11 + lcwr[commvl_1.ivx - 1];
			comcwrf_1.cwrferm[commvl_1.ivx - 1] = FALSE_;
		    }
		}
/* L61: */
	    }
	    if (lnote > 0) {
/* Writing concatenation */
		i__6[0] = lnote, a__3[0] = notexq;
		i__6[1] = 1, a__3[1] = "}";
		s_cat(ch__20, a__3, i__6, &c__2, (ftnlen)80);
		i__2 = lnote + 1;
		addstr_(ch__20, &i__2, soutq, &lsout, lnote + 1, (ftnlen)80);
	    }
	    if (all_1.iv != all_1.nv) {
		addstr_(all_1.sepsymq + (all_1.iv - 1), &c__1, soutq, &lsout, 
			(ftnlen)1, (ftnlen)80);
	    }
/* L60: */
	}
/* Writing concatenation */
	i__6[0] = 1, a__3[0] = all_1.sq;
	i__6[1] = 3, a__3[1] = "en}";
	s_cat(ch__15, a__3, i__6, &c__2, (ftnlen)4);
	addstr_(ch__15, &c__4, soutq, &lsout, (ftnlen)4, (ftnlen)80);
	if (comlast_1.islast && lsout > 0) {
	    s_wsfe(&io___607);
/* Writing concatenation */
	    i__6[0] = lsout, a__3[0] = soutq;
	    i__6[1] = 1, a__3[1] = "%";
	    s_cat(ch__9, a__3, i__6, &c__2, (ftnlen)81);
	    do_fio(&c__1, ch__9, lsout + 1);
	    e_wsfe();
	}
    }

/*  End of block for centered whole-bar rests and multi-bar rests */

/*  If at end of block, save durations of last notes in bar, for possible use */
/*  if clef changes at start of next bar */

    if (all_1.ibar == all_1.nbars) {
	i__5 = all_1.nv;
	for (all_1.iv = 1; all_1.iv <= i__5; ++all_1.iv) {
	    i__2 = commvl_1.nvmx[all_1.iv - 1];
	    for (kv = 1; kv <= i__2; ++kv) {
		commvl_1.ivx = commvl_1.ivmx[all_1.iv + kv * 15 - 16];
/*          prevtn(ivx) = tnote(iand(ipl(ivx,nn(iv)),255)) */
		comnsp_1.prevtn[commvl_1.ivx - 1] = all_1.tnote[(all_1.ipl[
			commvl_1.ivx + all_1.nn[commvl_1.ivx - 1] * 15 - 16] &
			 255) - 1];
/* L63: */
	    }
	}
    }

/*  Update time for midi.  This is only used for the event track */

    if (commidi_1.ismidi) {
	comevent_1.miditime += all_1.lenbar * 15;

/*  If pickup, write the real time signature to the event track.  Cannot use */
/*    mtrnuml since it was reset to 0, have to recompute it */

	if (all_1.lenb0 == all_1.lenbar) {
	    i__2 = all_1.mtrdenl * all_1.lenb1 / 64;
	    midievent_("m", &i__2, &all_1.mtrdenl, (ftnlen)1);
	}
    }
    return 0;
} /* make2bar_ */

/* Subroutine */ int make1bar_(ibmrep, tglp1, tstart, cwrest, squez, istop, 
	numbms, istart)
integer *ibmrep;
real *tglp1, *tstart;
logical *cwrest;
real *squez;
integer *istop, *numbms, *istart;
{
    /* System generated locals */
    integer i__1, i__2, i__3, i__4, i__5, i__6;
    real r__1, r__2;

    /* Builtin functions */
    integer s_wsle(), do_lio(), e_wsle();

    /* Local variables */
    static integer ib, in, ip, kv, ib1, ib2, ip1, cnn[15], inj, iin, iiv, isl;
    static real xit[15];
    extern doublereal feon_();
    static integer irep;
    static real tmin;
    static integer iivx, ntot, itbb1, itbb2, itbb3, inip1;
    static real tglp2;
    extern /* Subroutine */ int addfb_();
    static integer mapfb[16];
    static real deskb;
    extern doublereal fnote_();
    static real eskzb;
    static integer ibrep;
    static real tminn;
    static integer nxtup, nip1fb, nip2fb, ib1now, ib2now, ifbadd, nfbbar;
    static real t1xtup[20];
    static logical infbmx[15];
    static integer ifbnow[15], numnew, mapnow;
    static logical inxtup[15];
    static integer nxtnow[15];
    static real xsquez;
    extern /* Subroutine */ int logbeam_(), findbeam_();
    extern doublereal getsquez_();

    /* Fortran I/O blocks */
    static cilist io___643 = { 0, 6, 0, 0, 0 };



/*  Above are factors for grace note, clef spacing. (fraction of wheadpt) */
/*  In 1.04, moved to block data subprogram */

    /* Parameter adjustments */
    --istart;
    --numbms;
    --istop;
    --squez;
    --cwrest;
    --tstart;

    /* Function Body */
    if (commidi_1.ismidi) {

/*  Initialize for this bar the accidental counter for the midi file. */
/*    naccim(icm) = # of accidentals from earlier in the bar */

	i__1 = all_1.nv;
	for (all_1.iv = 1; all_1.iv <= i__1; ++all_1.iv) {
	    i__2 = commvl_1.nvmx[all_1.iv - 1];
	    for (kv = 1; kv <= i__2; ++kv) {
		commidi_1.naccim[commidi_1.midchan[all_1.iv + kv * 15 - 16]] =
			 0;
/* L45: */
	    }
	}
    }

/*  Time from start of gulp to end of bar, used with forced beams */

    tglp2 = (real) (all_1.lenb0 + all_1.ibar * all_1.lenb1);
    if (all_1.lenb0 > 0) {
	tglp2 -= all_1.lenb1;
    }
    *tglp1 = tglp2 - all_1.lenbar;

/*  infbmx will only be true if in xtup that is NOT in explicit forced beam. */

    i__2 = all_1.nv;
    for (all_1.iv = 1; all_1.iv <= i__2; ++all_1.iv) {
	i__1 = commvl_1.nvmx[all_1.iv - 1];
	for (kv = 1; kv <= i__1; ++kv) {
	    commvl_1.ivx = commvl_1.ivmx[all_1.iv + kv * 15 - 16];
	    cwrest[commvl_1.ivx] = FALSE_;
	    infbmx[commvl_1.ivx - 1] = FALSE_;
	    inxtup[commvl_1.ivx - 1] = FALSE_;
	    if (all_1.ibar > 1) {
		all_1.nn[commvl_1.ivx - 1] = all_1.nib[commvl_1.ivx + 
			all_1.ibar * 15 - 16] - all_1.nib[commvl_1.ivx + (
			all_1.ibar - 1) * 15 - 16];
	    } else {
		all_1.nn[commvl_1.ivx - 1] = all_1.nib[commvl_1.ivx + 
			all_1.ibar * 15 - 16];
	    }
/* L1: */
	}
    }

/* initialize list note counter, time(iv), curr. note(iv).  The loop to 4 */
/*   ONLY initializes each voice. */

    in = 1;
    nxtup = 0;
    comarp_1.narp = 0;
    i__1 = all_1.nv;
    for (all_1.iv = 1; all_1.iv <= i__1; ++all_1.iv) {
	i__2 = commvl_1.nvmx[all_1.iv - 1];
	for (kv = 1; kv <= i__2; ++kv) {
	    commvl_1.ivx = commvl_1.ivmx[all_1.iv + kv * 15 - 16];
	    comcwrf_1.cwrferm[commvl_1.ivx - 1] = FALSE_;
	    cnn[commvl_1.ivx - 1] = 1;
	    all_1.ivxo[in - 1] = commvl_1.ivx;
	    all_1.ipo[in - 1] = cnn[commvl_1.ivx - 1];
	    all_1.tnote[in - 1] = fnote_(all_1.nodur, &commvl_1.ivx, &c__1);
	    all_1.to[in - 1] = (float)0.;
	    xit[commvl_1.ivx - 1] = all_1.tnote[in - 1];

/*  Note that xit(ivx) is to END of note in voice, but it1xtup is start time. */

	    if (all_1.nodur[commvl_1.ivx + all_1.ipo[in - 1] * 15 - 16] == 0) 
		    {

/*  First note of xtuplet at start of bar in voice ivx. */

		++nxtup;
		nxtnow[commvl_1.ivx - 1] = nxtup;
		inxtup[commvl_1.ivx - 1] = TRUE_;
		t1xtup[nxtup - 1] = (float)0.;

/*  Xtup at start of bar.  If no explicit forced beam, start one, set */
/*  signal infbmx, and save number ifbnow for use at termination. */

		if (comfb_1.nfb[commvl_1.ivx - 1] > 0) {
		    i__3 = comfb_1.nfb[commvl_1.ivx - 1];
		    for (comfb_1.ifb = 1; comfb_1.ifb <= i__3; ++comfb_1.ifb) 
			    {
			if (comfb_1.t1fb[commvl_1.ivx + comfb_1.ifb * 15 - 16]
				 > *tglp1 + xit[commvl_1.ivx - 1] + 
				comtol_1.tol) {

/*  No explicit fb here; so exit loop and insert one. */

			    goto L61;
			} else if (comfb_1.t1fb[commvl_1.ivx + comfb_1.ifb * 
				15 - 16] < *tglp1 + xit[commvl_1.ivx - 1] + 
				comtol_1.tol && comfb_1.t2fb[commvl_1.ivx + 
				comfb_1.ifb * 15 - 16] > *tglp1 + xit[
				commvl_1.ivx - 1] + comtol_1.tol) {

/*  IS explicit fb here; must NOT insert one */

			    goto L62;
			}
/* L60: */
		    }
		}
L61:

/*  If here, xtup isn't in explicit fb, so must insert one */

		infbmx[commvl_1.ivx - 1] = TRUE_;
		r__1 = t1xtup[nxtup - 1] + *tglp1;
		addfb_(comfb_1.nfb, &commvl_1.ivx, &r__1, comfb_1.t1fb, 
			comfb_1.t2fb, comfb_1.ulfbq, &ifbadd, (ftnlen)1);
		ifbnow[commvl_1.ivx - 1] = ifbadd;
	    }
L62:
	    if ((r__1 = xit[commvl_1.ivx - 1] - all_1.lenbar, dabs(r__1)) < 
		    comtol_1.tol) {
		xit[commvl_1.ivx - 1] = (float)1e3;
	    }
	    ++in;
/* L4: */
	}
    }

/*  Build the list:  This is a manual loop starting at 5 */

L5:

/*  Determine which voice comes next from end of notes done so far. */
/*  tmin is the earliest ending time of notes done so far */

    tmin = (float)1e3;
    i__2 = all_1.nv;
    for (iiv = 1; iiv <= i__2; ++iiv) {
	i__1 = commvl_1.nvmx[iiv - 1];
	for (kv = 1; kv <= i__1; ++kv) {
	    iivx = commvl_1.ivmx[iiv + kv * 15 - 16];
/* Computing MIN */
	    r__1 = tmin, r__2 = xit[iivx - 1];
	    tminn = dmin(r__1,r__2);
	    if (tminn < tmin - comtol_1.tol) {
		tmin = tminn;
		commvl_1.ivx = iivx;
	    }
/* L6: */
	}
    }
    if ((r__1 = tmin - (float)1e3, dabs(r__1)) < comtol_1.tol) {
	goto L7;
    }
    all_1.ivxo[in - 1] = commvl_1.ivx;
    ++cnn[commvl_1.ivx - 1];
    all_1.ipo[in - 1] = cnn[commvl_1.ivx - 1];
    all_1.to[in - 1] = tmin;

/*  Check if this voice is done */

    all_1.tnote[in - 1] = fnote_(all_1.nodur, &commvl_1.ivx, &cnn[
	    commvl_1.ivx - 1]);
    if (cnn[commvl_1.ivx - 1] == all_1.nn[commvl_1.ivx - 1]) {
	xit[commvl_1.ivx - 1] = (float)1e3;
    } else {
	xit[commvl_1.ivx - 1] += all_1.tnote[in - 1];
    }

/*  Flag xtups */

    if (all_1.nodur[commvl_1.ivx + cnn[commvl_1.ivx - 1] * 15 - 16] == 0) {
	if (! inxtup[commvl_1.ivx - 1]) {

/*  First note of xtup, not at start of bar. */

	    ++nxtup;
	    nxtnow[commvl_1.ivx - 1] = nxtup;
	    inxtup[commvl_1.ivx - 1] = TRUE_;
	    t1xtup[nxtup - 1] = xit[commvl_1.ivx - 1] - all_1.tnote[in - 1];

/*  (Note: can't be on last note in voice, so xit(ivx) <> 1000) */
/*  Put xtuplet in a forced beam if not already in forced beam */

	    if (comfb_1.nfb[commvl_1.ivx - 1] > 0) {
		i__1 = comfb_1.nfb[commvl_1.ivx - 1];
		for (comfb_1.ifb = 1; comfb_1.ifb <= i__1; ++comfb_1.ifb) {
		    if (comfb_1.t1fb[commvl_1.ivx + comfb_1.ifb * 15 - 16] > *
			    tglp1 + xit[commvl_1.ivx - 1] + comtol_1.tol) {

/*  NO explicit bm; put one in */

			goto L71;
		    } else if (comfb_1.t1fb[commvl_1.ivx + comfb_1.ifb * 15 - 
			    16] < *tglp1 + xit[commvl_1.ivx - 1] + 
			    comtol_1.tol && comfb_1.t2fb[commvl_1.ivx + 
			    comfb_1.ifb * 15 - 16] > *tglp1 + xit[
			    commvl_1.ivx - 1] + comtol_1.tol) {

/*  IS explicit bm.  Don't put one */

			goto L72;
		    }
/* L70: */
		}
	    }
L71:

/*  If here, no explicit bm, so put one in */

	    infbmx[commvl_1.ivx - 1] = TRUE_;
	    r__1 = t1xtup[nxtup - 1] + *tglp1;
	    addfb_(comfb_1.nfb, &commvl_1.ivx, &r__1, comfb_1.t1fb, 
		    comfb_1.t2fb, comfb_1.ulfbq, &ifbadd, (ftnlen)1);
	    ifbnow[commvl_1.ivx - 1] = ifbadd;
	}
L72:
	;
    } else if (inxtup[commvl_1.ivx - 1]) {

/*  This test is sufficient because already know nodur>0 */

	inxtup[commvl_1.ivx - 1] = FALSE_;
	if (infbmx[commvl_1.ivx - 1]) {

/*  Xtup is in auto-forced beam, so end it */

	    comfb_1.t2fb[commvl_1.ivx + ifbnow[commvl_1.ivx - 1] * 15 - 16] = 
		    t1xtup[nxtnow[commvl_1.ivx - 1] - 1] + all_1.nodur[
		    commvl_1.ivx + cnn[commvl_1.ivx - 1] * 15 - 16] + *tglp1;
	    infbmx[commvl_1.ivx - 1] = FALSE_;
	}
    }
    if (bit_test(all_1.irest[all_1.ivxo[in - 1] + all_1.ipo[in - 1] * 15 - 16]
	    ,24)) {

/*  For staff jumped beam, flag the first note (lowest voice) at same time */

	inj = in;
	if (all_1.ivxo[in - 1] > 1) {
	    for (iin = in - 1; iin >= 1; --iin) {
		if (all_1.to[iin - 1] + comtol_1.tol < all_1.to[in - 1]) {
		    goto L41;
		}
		if ((r__1 = all_1.to[iin - 1] - all_1.to[in - 1], dabs(r__1)) 
			< comtol_1.tol) {
		    inj = iin;
		    goto L40;
		}
L40:
		;
	    }
	}
L41:
	all_1.irest[all_1.ivxo[inj - 1] + all_1.ipo[inj - 1] * 15 - 16] = 
		bit_set(all_1.irest[all_1.ivxo[inj - 1] + all_1.ipo[inj - 1] *
		 15 - 16],29);
    }
    ++in;
    goto L5;
L7:
    ntot = in - 1;
    i__1 = ntot - 1;
    for (in = 1; in <= i__1; ++in) {
	all_1.tno[in - 1] = all_1.to[in] - all_1.to[in - 1];
/* L8: */
    }
    all_1.tno[ntot - 1] = all_1.tnote[ntot - 1];

/*  Debug writes */

/*      write(*,'()') */
/*      write(*,'(a)')' Greetings from PMXB' */
/*      write(*,'(16i5)')(ivxo(in),in=1,ntot) */
/*      write(*,'(16i5)')(ipo(in),in=1,ntot) */
/*      write(*,'(16f5.1)')(to(in),in=1,ntot) */
/*      write(*,'(16f5.1)')(tno(in),in=1,ntot) */
/*      write(*,'(16i5)')(nodur(ivxo(in),ipo(in)),in=1,ntot) */
/*      write(*,'(16f5.1)')(fnote(nodur,ivxo(in),ipo(in)),in=1,ntot) */

/*  Done w/ list. Loop for parsing into note blocks: */

    ib = 1;
    istart[1] = 1;
    comnsp_1.space[0] = (float)0.;
    in = 1;

/*  A manual loop to set space(ib) and istop(ib) */

L9:
/* Computing MIN */
    i__1 = in + 1;
    commvl_1.ivx = all_1.ivxo[min(i__1,ntot) - 1];
/* Computing MIN */
    i__1 = in + 1;
    ip = all_1.ipo[min(i__1,ntot) - 1];
    isl = all_1.islur[commvl_1.ivx + ip * 15 - 16];
    if (in == ntot || (commvl_1.ivx == 1 && ((isl & 67109216) > 0 || bit_test(
	    all_1.ipl[ip * 15 - 15],28) || bit_test(all_1.iornq[ip * 15],4)) 
	    || bit_test(isl,15)) || bit_test(all_1.irest[commvl_1.ivx + ip * 
	    15 - 16],29)) {
/*    *      .or. ornq(1,ip).eq.'g')) .or. btest(isl,15) )) then */
/*  Bits 1-13: stmgx+Tupf._) */
/*  14: Down fermata, was F */
/*  15: Trill w/o "tr", was U */

/*  Checking for start of 2nd part of jumped beam */


/*  Bar end, segno, int. rpt or sig change, clef,end of 1st part of jumped beam; */
/*    flow out of if-loop and into block-wrapup */

/*  10/18/97:  Problem with clef alignment.  Got isl{15} set on lowest-numbered */
/*  voice, but it wasn't first in the list at the same time.  So check if */
/*  prior notes in list have same time */
/*  5/25/98: This stuff causes trouble with just "c2 Ct c", maybe when clef */
/*  changes on last note in the list? */

	if (bit_test(isl,15) && in < ntot) {
	    for (iin = in; iin >= 1; --iin) {
		if (all_1.tno[iin - 1] > comtol_1.tol) {
		    in = iin;
		    all_1.islur[commvl_1.ivx + ip * 15 - 16] = bit_clear(
			    all_1.islur[commvl_1.ivx + ip * 15 - 16],15);
		    all_1.islur[all_1.ivxo[in] + all_1.ipo[in] * 15 - 16] = 
			    bit_set(all_1.islur[all_1.ivxo[in] + all_1.ipo[in]
			     * 15 - 16],15);
		    goto L51;
		}
/* L50: */
	    }
L51:
	    ;
	}
	if (comnsp_1.space[ib - 1] < comtol_1.tol) {
	    comnsp_1.space[ib - 1] = all_1.tno[in - 1];
	    squez[ib] = (float)1.;
	}
	istop[ib] = in;
    } else if (comnsp_1.space[ib - 1] < comtol_1.tol) {

/*  space hasn't been set yet, so tentatively set: */

	comnsp_1.space[ib - 1] = all_1.tno[in - 1];
	if (comnsp_1.space[ib - 1] < comtol_1.tol) {
	    ++in;
	} else {
	    squez[ib] = getsquez_(&in, &ntot, &comnsp_1.space[ib - 1], 
		    all_1.tnote, all_1.to);
	    istop[ib] = in;
	}
	goto L9;
    } else if (all_1.tno[in] < comtol_1.tol) {

/*  This is not the last note in the group, so */

	++in;
	goto L9;
    } else if ((r__1 = all_1.tno[in] - comnsp_1.space[ib - 1], dabs(r__1)) < 
	    comtol_1.tol) {
	i__1 = in + 1;
	xsquez = getsquez_(&i__1, &ntot, &comnsp_1.space[ib - 1], all_1.tnote,
		 all_1.to);
	if ((r__1 = xsquez - squez[ib], dabs(r__1)) < comtol_1.tol) {

/*  Keep spacing the same, update tentative stop point */

	    ++in;
	    istop[ib] = in;
	    goto L9;
	}
    }

/* At this point istart and istop are good, so finalize block */

    tstart[ib] = all_1.to[istart[ib] - 1];
    if (istop[ib] == ntot) {
	goto L15;
    }
    ++ib;
    istart[ib] = istop[ib - 1] + 1;
    in = istart[ib];

/* Set tentative block space and squeeze-factor for upcoming block */

    comnsp_1.space[ib - 1] = all_1.tno[in - 1];
    if (comnsp_1.space[ib - 1] > comtol_1.tol) {
	squez[ib] = getsquez_(&in, &ntot, &comnsp_1.space[ib - 1], 
		all_1.tnote, all_1.to);
    }
    istop[ib] = in;
    goto L9;
L15:
    comnsp_1.nb = ib;

/*  Invert the list of places into ipl(0-7), making it easier to analyze a voice */

    i__1 = ntot;
    for (in = 1; in <= i__1; ++in) {
	all_1.ipl[all_1.ivxo[in - 1] + all_1.ipo[in - 1] * 15 - 16] |= in;
/* L13: */
    }

/*  Compute elemskips from start of bar to each note in the bar, for beam slopes */

    eskzb = (float)0.;
    ib = 1;
    i__1 = ntot;
    for (in = 1; in <= i__1; ++in) {
	if (in == istart[ib]) {
	    r__1 = comnsp_1.space[ib - 1] / squez[ib];
	    deskb = squez[ib] * feon_(&r__1);
	} else if (all_1.tno[in - 2] > comtol_1.tol) {
	    eskzb += deskb;
	}
	all_1.eskz[all_1.ivxo[in - 1] + all_1.ipo[in - 1] * 15 - 16] = eskzb;
	if (in == istop[ib]) {
	    eskzb += deskb;
	    ++ib;
	}
/* L30: */
    }

/*  Debug writes */

/*      print* */
/*      write(*,'(16f5.1)')(eskz(ivxo(in),ipo(in)),in=1,ntot) */
/*      print*,'PMXB has now got blocks' */
/*      write(*,'(16i5)')(istart(ib),ib=1,nb) */
/*      write(*,'(16i5)')(istop(ib),ib=1,nb) */
/*      write(*,'(16f5.1)')(space(ib),ib=1,nb) */
/*      write(*,'(16f5.1)')(squez(ib),ib=1,nb) */
/*      write(*,'(16f5.1)')(fnote(nodur,ivxo(in),ipo(in)),in=1,ntot) */
/* c     write(*,'(26i3)')(iand(islur(ivxo(in),ipo(in)),30720)/2048, */
/*    *                  in=1,ntot) */
/*     write(*,'(1x,26a3)')(ornq(ivxo(in),ipo(in)),in=1,ntot) */


/*  Analyze for beams. */

    i__1 = all_1.nv;
    for (all_1.iv = 1; all_1.iv <= i__1; ++all_1.iv) {
	i__2 = commvl_1.nvmx[all_1.iv - 1];
	for (kv = 1; kv <= i__2; ++kv) {
	    commvl_1.ivx = commvl_1.ivmx[all_1.iv + kv * 15 - 16];
	    numbms[commvl_1.ivx] = 0;
	    mapfb[0] = 0;
	    mapfb[1] = 0;
	    mapfb[2] = 0;
	    mapfb[3] = 0;

/*  First forced beams. */

	    if (comfb_1.nfb[commvl_1.ivx - 1] > 0) {

/*  tglp2 is time from start of gulp to end of current bar. */

		nfbbar = 0;
		i__3 = comfb_1.nfb[commvl_1.ivx - 1];
		for (comfb_1.ifb = 1; comfb_1.ifb <= i__3; ++comfb_1.ifb) {
		    if (comfb_1.t1fb[commvl_1.ivx + comfb_1.ifb * 15 - 16] > 
			    tglp2 - comtol_1.tol) {
			goto L81;
		    }
		    ++nfbbar;
		    ++numbms[commvl_1.ivx];
		    numnew = numbms[commvl_1.ivx];

/*  Times from beginning of bar */

		    itbb1 = (integer) (comfb_1.t1fb[commvl_1.ivx + 
			    comfb_1.ifb * 15 - 16] - *tglp1 + comtol_1.tol);
		    itbb2 = (integer) (comfb_1.t2fb[commvl_1.ivx + 
			    comfb_1.ifb * 15 - 16] - *tglp1 + comtol_1.tol);
		    i__4 = all_1.nn[commvl_1.ivx - 1];
		    for (ip = 1; ip <= i__4; ++ip) {
			if ((integer) (all_1.to[(255 & all_1.ipl[commvl_1.ivx 
				+ ip * 15 - 16]) - 1] + comtol_1.tol) == 
				itbb1) {
			    nip1fb = ip;
			    i__5 = all_1.nn[commvl_1.ivx - 1];
			    for (ip1 = ip; ip1 <= i__5; ++ip1) {
/*                  if (to(iand(255,ipl(ivx,ip1)))+nodur(ivx,ip1) */
/*     *                     .eq.itbb2) then */
				inip1 = 255 & all_1.ipl[commvl_1.ivx + ip1 * 
					15 - 16];
				if ((r__1 = all_1.to[inip1 - 1] + all_1.tnote[
					inip1 - 1] - itbb2, dabs(r__1)) < 
					comtol_1.tol) {
				    nip2fb = ip1;
				    itbb3 = itbb2 - 2;
				    goto L85;
				}
/* L84: */
			    }
			}
/* L83: */
		    }
		    s_wsle(&io___643);
		    do_lio(&c__9, &c__1, "Timing problem w/ fixed beams", (
			    ftnlen)29);
		    e_wsle();
L85:
		    logbeam_(&numnew, &nip1fb, &nip2fb);

/*  Set up mapfb for forced beam just logged: */

		    ib1 = itbb1 / 2;
		    ib2 = itbb3 / 2;
		    ibrep = all_1.lenbar / *ibmrep / 2;
		    i__4 = *ibmrep;
		    for (irep = 1; irep <= i__4; ++irep) {
/* Computing MAX */
			i__5 = 0, i__6 = ib1 - (irep - 1) * ibrep;
			ib1now = max(i__5,i__6);
/* Computing MIN */
			i__5 = irep * ibrep - 1, i__6 = ib2 - (irep - 1) * 
				ibrep;
			ib2now = min(i__5,i__6);
			mapnow = 0;
			i__5 = ib2now;
			for (ib = ib1now; ib <= i__5; ++ib) {
			    mapnow = bit_set(mapnow,ib);
/* L87: */
			}
			mapfb[irep - 1] |= mapnow;
/* L86: */
		    }
/* L80: */
		}
L81:

/*  Slide down, reduce nfb(ivx).  This lets us count up from 1 for each new bar. */
/*  Remember, makeabar is called 1/bar, and it calls findbeam once per voice. */

		if (nfbbar > 0) {
		    comfb_1.nfb[commvl_1.ivx - 1] -= nfbbar;
		    i__3 = comfb_1.nfb[commvl_1.ivx - 1];
		    for (comfb_1.ifb = 1; comfb_1.ifb <= i__3; ++comfb_1.ifb) 
			    {
			comfb_1.t1fb[commvl_1.ivx + comfb_1.ifb * 15 - 16] = 
				comfb_1.t1fb[commvl_1.ivx + (comfb_1.ifb + 
				nfbbar) * 15 - 16];
			comfb_1.t2fb[commvl_1.ivx + comfb_1.ifb * 15 - 16] = 
				comfb_1.t2fb[commvl_1.ivx + (comfb_1.ifb + 
				nfbbar) * 15 - 16];
			*(unsigned char *)&comfb_1.ulfbq[commvl_1.ivx + 
				comfb_1.ifb * 15 - 16] = *(unsigned char *)&
				comfb_1.ulfbq[commvl_1.ivx + (comfb_1.ifb + 
				nfbbar) * 15 - 16];
/* L82: */
		    }
		}
	    }
	    comfb_1.ifb = 0;

/*  Done with forced beam masks for this bar and voice.  Now get normal beams. */

	    findbeam_(ibmrep, &numbms[1], mapfb);
/* L20: */
	}
    }
    return 0;
} /* make1bar_ */

/* Subroutine */ int puttitle_(inhnoh, xnsttop, etatop, sq, etait, etatc, 
	etacs1, nv, vshrink, sepsymq, sq_len, sepsymq_len)
integer *inhnoh;
real *xnsttop, *etatop;
char *sq;
real *etait, *etatc, *etacs1;
integer *nv;
logical *vshrink;
char *sepsymq;
ftnlen sq_len;
ftnlen sepsymq_len;
{
    /* System generated locals */
    address a__1[2], a__2[3], a__3[3], a__4[4];
    integer i__1[2], i__2, i__3[3], i__4, i__5[3], i__6[4];
    real r__1;
    char ch__1[8], ch__2[1], ch__3[10], ch__4[148], ch__5[129], ch__6[133];
    icilist ici__1;

    /* Builtin functions */
    /* Subroutine */ int s_cat();
    double r_lg10();
    integer s_wsfi(), do_fio(), e_wsfi(), s_wsfe(), e_wsfe();
    /* Subroutine */ int s_copy();

    /* Local variables */
    static integer iv, lcq, ndig;
    extern /* Character */ VOID chax_();
    static real xcsil, xtcil, vskil, xitil, glueil;
    extern integer lenstr_();
    extern /* Subroutine */ int printl_();
    static char notexq[127];
    static integer lenline;
    extern /* Subroutine */ int writflot_();

    /* Fortran I/O blocks */
    static cilist io___657 = { 0, 11, 0, "(a)", 0 };
    static cilist io___660 = { 0, 11, 0, "(a)", 0 };
    static cilist io___663 = { 0, 11, 0, "(a)", 0 };



/*  Called once per page, at top of page!  If vshrink, only called for p.1. */
/*  Actual titles only allowed on p.1. (set by headlog). */

    /* Parameter adjustments */
    --sepsymq;

    /* Function Body */
/* Writing concatenation */
    i__1[0] = 1, a__1[0] = sq;
    i__1[1] = 6, a__1[1] = "znotes";
    s_cat(notexq, a__1, i__1, &c__2, (ftnlen)127);
    lenline = 7;
    i__2 = *nv - 1;
    for (iv = 1; iv <= i__2; ++iv) {
/* Writing concatenation */
	i__1[0] = lenline, a__1[0] = notexq;
	i__1[1] = 1, a__1[1] = sepsymq + iv;
	s_cat(notexq, a__1, i__1, &c__2, (ftnlen)127);
	++lenline;
/* L22: */
    }
/* Writing concatenation */
    i__3[0] = lenline, a__2[0] = notexq;
    i__3[1] = 1, a__2[1] = sq;
    i__3[2] = 10, a__2[2] = "zcharnote{";
    s_cat(notexq, a__2, i__3, &c__3, (ftnlen)127);
    lenline += 11;
    if (! comtitl_1.headlog) {
	comtitl_1.inhead = *inhnoh;
    }
    if (*vshrink) {
	comtitl_1.inhead = 16;
    }
    r__1 = comtitl_1.inhead + (float).01;
    ndig = (integer) r_lg10(&r__1) + 1;
    i__2 = lenline;
    ici__1.icierr = 0;
    ici__1.icirnum = 1;
    ici__1.icirlen = lenline + ndig + 10 - i__2;
    ici__1.iciunit = notexq + i__2;
/* Writing concatenation */
    i__3[0] = 2, a__2[0] = "(i";
    i__4 = ndig + 48;
    chax_(ch__2, (ftnlen)1, &i__4);
    i__3[1] = 1, a__2[1] = ch__2;
    i__3[2] = 5, a__2[2] = ",a10)";
    ici__1.icifmt = (s_cat(ch__1, a__2, i__3, &c__3, (ftnlen)8), ch__1);
    s_wsfi(&ici__1);
    do_fio(&c__1, (char *)&comtitl_1.inhead, (ftnlen)sizeof(integer));
/* Writing concatenation */
    i__5[0] = 2, a__3[0] = "}{";
    i__5[1] = 1, a__3[1] = sq;
    i__5[2] = 7, a__3[2] = "titles{";
    s_cat(ch__3, a__3, i__5, &c__3, (ftnlen)10);
    do_fio(&c__1, ch__3, (ftnlen)10);
    e_wsfi();
    lenline = lenline + ndig + 10;

/*  Vertical skip at top of page (\Il) = etatop*glueil.  Needed whether */
/*    headers are present or not. */

    glueil = *xnsttop / *etatop;
    vskil = *etatop * glueil;
    if (*vshrink) {
	vskil = (float)2.;
    }
    writflot_(&vskil, notexq, &lenline, (ftnlen)127);
    if (! comtitl_1.headlog) {
	if (comlast_1.islast) {
	    s_wsfe(&io___657);
/* Writing concatenation */
	    i__6[0] = lenline, a__4[0] = notexq;
	    i__6[1] = 17, a__4[1] = "}{}{0}{}{0}{}{0}}";
	    i__6[2] = 1, a__4[2] = sq;
	    i__6[3] = 3, a__4[3] = "en%";
	    s_cat(ch__4, a__4, i__6, &c__4, (ftnlen)148);
	    do_fio(&c__1, ch__4, lenline + 21);
	    e_wsfe();
	}
    } else {
/* Writing concatenation */
	i__1[0] = lenline, a__1[0] = notexq;
	i__1[1] = 2, a__1[1] = "}{";
	s_cat(notexq, a__1, i__1, &c__2, (ftnlen)127);
	lenline += 2;
	lcq = lenstr_(comtitl_1.instrq, &c__60, (ftnlen)60);
	if (lcq > 0) {
	    xitil = *etait * glueil;
	    if (*vshrink) {
		xitil = (float)2.;
	    }
/* Writing concatenation */
	    i__3[0] = lenline, a__2[0] = notexq;
	    i__3[1] = lcq, a__2[1] = comtitl_1.instrq;
	    i__3[2] = 2, a__2[2] = "}{";
	    s_cat(notexq, a__2, i__3, &c__3, (ftnlen)127);

/* Null out instrument once used */

	    s_copy(comtitl_1.instrq, " ", (ftnlen)60, (ftnlen)1);
	    lenline = lenline + lcq + 2;
	    writflot_(&xitil, notexq, &lenline, (ftnlen)127);
	} else {
/* Writing concatenation */
	    i__1[0] = lenline, a__1[0] = notexq;
	    i__1[1] = 3, a__1[1] = "}{0";
	    s_cat(notexq, a__1, i__1, &c__2, (ftnlen)127);
	    lenline += 3;
	}
	if (comlast_1.islast) {
	    s_wsfe(&io___660);
/* Writing concatenation */
	    i__1[0] = lenline, a__1[0] = notexq;
	    i__1[1] = 2, a__1[1] = "}%";
	    s_cat(ch__5, a__1, i__1, &c__2, (ftnlen)129);
	    do_fio(&c__1, ch__5, lenline + 2);
	    e_wsfe();
	}
	s_copy(notexq, "{", (ftnlen)127, (ftnlen)1);
	lenline = 1;
	lcq = lenstr_(comtitl_1.titleq, &c__60, (ftnlen)60);
	if (lcq > 0) {
/* Writing concatenation */
	    i__1[0] = lenline, a__1[0] = notexq;
	    i__1[1] = lcq, a__1[1] = comtitl_1.titleq;
	    s_cat(notexq, a__1, i__1, &c__2, (ftnlen)127);
	    lenline += lcq;
	} else {
	    printl_(" ", (ftnlen)1);
	    printl_("WARNING", (ftnlen)7);
	    printl_("  In a title block, you have specified instrument and/or"
		    , (ftnlen)56);
	    printl_("  composer but no title for the piece.", (ftnlen)38);
	}
/* Writing concatenation */
	i__1[0] = lenline, a__1[0] = notexq;
	i__1[1] = 2, a__1[1] = "}{";
	s_cat(notexq, a__1, i__1, &c__2, (ftnlen)127);
	lenline += 2;
	xtcil = *etatc * glueil;
	lcq = lenstr_(comtitl_1.compoq, &c__60, (ftnlen)60);
	if (lcq == 0) {
	    xtcil *= 2;
	}
	if (*vshrink) {
	    xtcil = (float)2.;
	}
	writflot_(&xtcil, notexq, &lenline, (ftnlen)127);
/* Writing concatenation */
	i__1[0] = lenline, a__1[0] = notexq;
	i__1[1] = 2, a__1[1] = "}{";
	s_cat(notexq, a__1, i__1, &c__2, (ftnlen)127);
	lenline += 2;
	if (lcq > 0) {
/* Writing concatenation */
	    i__3[0] = lenline, a__2[0] = notexq;
	    i__3[1] = lcq, a__2[1] = comtitl_1.compoq;
	    i__3[2] = 2, a__2[2] = "}{";
	    s_cat(notexq, a__2, i__3, &c__3, (ftnlen)127);
	    lenline = lenline + 2 + lcq;

/*  Null out compoq so it does not get written later */

	    s_copy(comtitl_1.compoq, " ", (ftnlen)60, (ftnlen)1);
	    xcsil = *etacs1 * glueil;
	    if (*vshrink) {
		xcsil = (float)2.;
	    }
	    writflot_(&xcsil, notexq, &lenline, (ftnlen)127);
	} else {
/* Writing concatenation */
	    i__1[0] = lenline, a__1[0] = notexq;
	    i__1[1] = 3, a__1[1] = "}{0";
	    s_cat(notexq, a__1, i__1, &c__2, (ftnlen)127);
	    lenline += 3;
	}
	if (comlast_1.islast) {
	    s_wsfe(&io___663);
/* Writing concatenation */
	    i__6[0] = lenline, a__4[0] = notexq;
	    i__6[1] = 2, a__4[1] = "}}";
	    i__6[2] = 1, a__4[2] = sq;
	    i__6[3] = 3, a__4[3] = "en%";
	    s_cat(ch__6, a__4, i__6, &c__4, (ftnlen)133);
	    do_fio(&c__1, ch__6, lenline + 6);
	    e_wsfe();
	}
	comtitl_1.headlog = FALSE_;
    }
    return 0;
} /* puttitle_ */

/* Subroutine */ int getnote_(loop)
logical *loop;
{
    /* System generated locals */
    address a__1[4], a__2[2], a__3[3], a__4[5], a__5[6];
    integer i__1, i__2, i__3, i__4[4], i__5[2], i__6[3], i__7[5], i__8[6];
    real r__1;
    char ch__1[1], ch__2[11], ch__3[12], ch__4[10], ch__5[13], ch__6[1], 
	    ch__7[69], ch__8[3], ch__9[9], ch__10[61], ch__11[8], ch__12[82], 
	    ch__13[62], ch__14[122], ch__15[15];

    /* Builtin functions */
    integer i_indx(), s_wsfe(), do_fio(), e_wsfe(), s_cmp(), s_wsle(), do_lio(
	    ), e_wsle();
    /* Subroutine */ int s_stop();
    integer i_nint(), lbit_shift();
    double log();
    /* Subroutine */ int s_cat(), s_copy();
    integer s_wsfi(), e_wsfi();

    /* Local variables */
    static integer j, ic, kv, ing, ipm, ndx, iiv, iis, isl, iip, npg1, num1, 
	    iadj, nadj, lclf;
    extern /* Character */ VOID chax_();
    static integer nole, ioct;
    static real fnum;
    static char dotq[1], durq[1], dumq[1];
    extern /* Subroutine */ int getx_();
    static integer itup, nnnl, ntup, ndxm, nfig1;
    extern /* Subroutine */ int mrec1_();
    static integer ipg1r, lhead;
    static char clefq[1], charq[1], lineq[128];
    static logical moved;
    static integer ifnum;
    extern /* Subroutine */ int sslur_();
    static integer nvold, iinow, iinst;
    static char hdlndq[59];
    static logical quoted;
    extern integer lenstr_();
    static integer numnum;
    extern /* Subroutine */ int getorn_();
    static integer nnlivx;
    extern /* Subroutine */ int littex_(), getfig_();
    static integer nactmp;
    extern /* Subroutine */ int getdyn_(), getbuf_();
    extern integer ncmidf_();
    static integer nnliiv, ibaroff, lenbeat;
    extern /* Subroutine */ int getchar_(), getmidi_();
    static integer ibarcnt;
    extern /* Subroutine */ int readnum_();
    static integer iofforn, numshft;
    static real xofforn;
    extern integer ifnolev_();
    extern /* Subroutine */ int setbits_(), chkpm4ac_();
    extern integer ifnodur_();
    static real fmovbrk;
    extern integer numclef_();
    static integer itother, ltopnam, namstrt;
    static real tintstf;
    static integer lvoltxt;
    extern integer igetbits_();
    extern /* Subroutine */ int newvoice_();
    static integer idotform;
    extern /* Subroutine */ int readmeter_(), midievent_();

    /* Fortran I/O blocks */
    static cilist io___666 = { 0, 11, 0, "(a)", 0 };
    static cilist io___674 = { 0, 6, 0, 0, 0 };
    static cilist io___689 = { 0, 6, 0, 0, 0 };
    static cilist io___694 = { 0, 6, 0, 0, 0 };
    static cilist io___700 = { 0, 11, 0, "(a)", 0 };
    static cilist io___701 = { 0, 11, 0, "(a)", 0 };
    static cilist io___702 = { 0, 11, 0, "(a)", 0 };
    static cilist io___706 = { 0, 11, 0, "(a)", 0 };
    static cilist io___707 = { 0, 11, 0, "(a)", 0 };
    static cilist io___708 = { 0, 11, 0, "(a11,i2,a)", 0 };
    static cilist io___709 = { 0, 11, 0, "(a9,i2,a)", 0 };
    static cilist io___711 = { 0, 11, 0, "(a8,i1,a3)", 0 };
    static cilist io___712 = { 0, 11, 0, "(a8,i1,a)", 0 };
    static cilist io___713 = { 0, 6, 0, 0, 0 };
    static cilist io___714 = { 0, 6, 0, 0, 0 };
    static cilist io___727 = { 0, 6, 0, 0, 0 };
    static icilist io___728 = { 0, hdlndq+26, 0, "(i1)", 1, 1 };
    static icilist io___730 = { 0, hdlndq+27, 0, "(i2,a1)", 3, 1 };
    static icilist io___731 = { 0, hdlndq+27, 0, "(i3,a1)", 4, 1 };
    static cilist io___732 = { 0, 11, 0, "(a)", 0 };
    static cilist io___733 = { 0, 11, 0, "(a)", 0 };
    static cilist io___734 = { 0, 11, 0, "(a)", 0 };
    static cilist io___735 = { 0, 11, 0, "(a)", 0 };



/*  nvmx is either 1 or 2.  ivmx(iv,1)=iv, ; ivmx(iv,2)>nv if defined */
/*  ivx is current ivmx, and is the index for all notes, acc's etc. */

L1:
    getchar_(lineq, &all_1.iccount, charq, (ftnlen)128, (ftnlen)1);
    if (comget_1.lastchar) {
	return 0;
    }
    if (*(unsigned char *)charq == ' ') {
	goto L1;
    }
    if (*(unsigned char *)charq == '%') {

/*  Check for a bar number format: */

	if (all_1.iccount == 1 && *(unsigned char *)&lineq[1] == ' ' && 
		i_indx("bB1234567890", lineq + 2, (ftnlen)12, (ftnlen)1) > 0) 
		{
	    if (comlast_1.islast) {
		s_wsfe(&io___666);
		do_fio(&c__1, lineq, lenstr_(lineq, &c__128, (ftnlen)128));
		e_wsfe();
	    }
	}
	all_1.iccount = 128;
	goto L1;
    }

/*  Closing repeat iff charq='/' and the prev. char was 'R' with 'd' or 'r' */

    if (comget_1.rptprev) {
	comget_1.rptnd1 = *(unsigned char *)charq == '/';
	comget_1.rptprev = FALSE_;
    }

/*  Repeat at end of a piece */

    if (*(unsigned char *)charq >= 97 && *(unsigned char *)charq <= 103 || *(
	    unsigned char *)charq == 'r') {

/*  This is a note/rest. */

	idotform = 0;
	numnum = 0;

/*  If start of line of music, set pitch from previous */

	if (commvl_1.ivx <= all_1.nv) {
	    kv = 1;
	} else {
	    kv = 2;
	}
	if (all_1.nnl[commvl_1.ivx - 1] == 0) {
	    comnotes_2.lastlev = comnotes_2.ndlev[all_1.iv + kv * 15 - 16];
	}

/*  notcrd is used to tell if orn. goes on main note or chord note */

	comnotes_2.notcrd = TRUE_;

/*  Increase note count, then loop 'til blank. Label 28 is for dotted shortcuts. */

L28:
	++all_1.nnl[commvl_1.ivx - 1];
	if (comget_1.ornrpt) {

/*  Replicate ornament bits, also bit 23 for beam handling if chord. */

	    all_1.iornq[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 1] 
		    |= all_1.iornq[commvl_1.ivx - 1];
	    if ((all_1.iornq[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 
		    - 1] & 32896) > 0) {

/*  This is a trill (bit 7 or 15) so must dup the parameters */

		++comtrill_1.ntrill;
		comtrill_1.ivtrill[comtrill_1.ntrill - 1] = commvl_1.ivx;
		comtrill_1.iptrill[comtrill_1.ntrill - 1] = all_1.nnl[
			commvl_1.ivx - 1];
		comtrill_1.xnsktr[comtrill_1.ntrill - 1] = comtrill_1.xnsktr[
			comtrill_1.ntrill - 2];
	    }
	}
	if (comget_1.fbon) {
	    all_1.ipl[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] = 
		    bit_set(all_1.ipl[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 
		    1] * 15 - 16],30);
	}
	*(unsigned char *)dotq = 'x';
	if (*(unsigned char *)charq == 'r') {
	    all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] 
		    = bit_set(all_1.irest[commvl_1.ivx + all_1.nnl[
		    commvl_1.ivx - 1] * 15 - 16],0);
	}
	if (bit_test(all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
		15 - 16],0)) {

/*  Rest stuff.  First check if previous note was full-bar-pause */

	    i__1 = all_1.iccount;
	    if (s_cmp(lineq + i__1, " ", all_1.iccount + 1 - i__1, (ftnlen)1) 
		    == 0 && all_1.nnl[commvl_1.ivx - 1] > 1) {
		if (bit_test(all_1.islur[commvl_1.ivx + (all_1.nnl[
			commvl_1.ivx - 1] - 1) * 15 - 16],19)) {
		    all_1.islur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
			    15 - 16] = bit_set(all_1.islur[commvl_1.ivx + 
			    all_1.nnl[commvl_1.ivx - 1] * 15 - 16],19);
		}
	    }

/*  Set default rest level at 0 unless 2 voices/staff in which case it's -4 or 2 */
/*  for voice a or b.  Set a-types at 0 as encountered and adjust later */
/*  after '//'.  (Override heights will be set to 100+offset) */

	    if (commvl_1.ivx <= all_1.nv) {
		all_1.nolev[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = 0;
	    } else {
		all_1.nolev[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = 2;
	    }
	}
L2:
	getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
	ic = *(unsigned char *)durq;
	if (ic <= 57 && ic >= 48) {

/*  Digit */

	    if (numnum == 0) {
		comnotes_2.nnodur = ic - 48;
		numnum = 1;
		goto L2;
	    } else if (numnum == 1) {
		ioct = ic - 48;
		numnum = 2;
		goto L2;
	    } else {
		s_wsle(&io___674);
		do_lio(&c__9, &c__1, ">2 digits in note sym., ivx,nn:", (
			ftnlen)31);
		do_lio(&c__3, &c__1, (char *)&commvl_1.ivx, (ftnlen)sizeof(
			integer));
		do_lio(&c__3, &c__1, (char *)&all_1.nnl[commvl_1.ivx - 1], (
			ftnlen)sizeof(integer));
		e_wsle();
		s_stop("", (ftnlen)0);
	    }
	} else if (*(unsigned char *)durq == 'd') {
	    *(unsigned char *)dotq = *(unsigned char *)durq;
	    i__1 = all_1.iccount;
	    if (s_cmp(lineq + i__1, "d", all_1.iccount + 1 - i__1, (ftnlen)1) 
		    == 0) {

/*  Double dot. */

		++all_1.iccount;
		all_1.islur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = bit_set(all_1.islur[commvl_1.ivx + all_1.nnl[
			commvl_1.ivx - 1] * 15 - 16],3);
	    }
	    i__1 = all_1.iccount;
	    if (i_indx("+-", lineq + i__1, (ftnlen)2, all_1.iccount + 1 - 
		    i__1) > 0) {

/*  move a dot, unless next char is not part of a number */

		i__1 = all_1.iccount + 1;
		if (i_indx("0123456789.", lineq + i__1, (ftnlen)11, 
			all_1.iccount + 2 - i__1) == 0) {
		    goto L2;
		}
		all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = bit_set(all_1.irest[commvl_1.ivx + all_1.nnl[
			commvl_1.ivx - 1] * 15 - 16],19);
		getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
		++comcc_1.ndotmv[commvl_1.ivx - 1];
		++all_1.iccount;
		readnum_(lineq, &all_1.iccount, dumq, &comcc_1.updot[
			commvl_1.ivx + comcc_1.ndotmv[commvl_1.ivx - 1] * 15 
			- 16], (ftnlen)128, (ftnlen)1);
		if (*(unsigned char *)durq == '-') {
		    comcc_1.updot[commvl_1.ivx + comcc_1.ndotmv[commvl_1.ivx 
			    - 1] * 15 - 16] = -comcc_1.updot[commvl_1.ivx + 
			    comcc_1.ndotmv[commvl_1.ivx - 1] * 15 - 16];
		}
		if (i_indx("+-", dumq, (ftnlen)2, (ftnlen)1) > 0) {

/*  Vertical shift also */

		    ++all_1.iccount;
		    readnum_(lineq, &all_1.iccount, durq, &comcc_1.rtdot[
			    commvl_1.ivx + comcc_1.ndotmv[commvl_1.ivx - 1] * 
			    15 - 16], (ftnlen)128, (ftnlen)1);
		    if (*(unsigned char *)dumq == '-') {
			comcc_1.rtdot[commvl_1.ivx + comcc_1.ndotmv[
				commvl_1.ivx - 1] * 15 - 16] = -comcc_1.rtdot[
				commvl_1.ivx + comcc_1.ndotmv[commvl_1.ivx - 
				1] * 15 - 16];
		    }
		} else {
		    comcc_1.rtdot[commvl_1.ivx + comcc_1.ndotmv[commvl_1.ivx 
			    - 1] * 15 - 16] = (float)0.;
		}
		--all_1.iccount;
	    }
	    goto L2;
	} else if (*(unsigned char *)durq == 'p') {

/*  Full-bar rest as pause */

	    all_1.islur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] 
		    = bit_set(all_1.islur[commvl_1.ivx + all_1.nnl[
		    commvl_1.ivx - 1] * 15 - 16],19);
	    goto L2;
	} else if (*(unsigned char *)durq == 'b') {

/*  Blank rest */

	    all_1.islur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] 
		    = bit_set(all_1.islur[commvl_1.ivx + all_1.nnl[
		    commvl_1.ivx - 1] * 15 - 16],29);
	    goto L2;
	} else if (i_indx("fsn", durq, (ftnlen)3, (ftnlen)1) > 0) {

/*  Accidental */

	    if (all_1.nacc[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
		    16] == 0) {

/*  No accidental has been set yet */

		all_1.nacc[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = i_indx("fsn", durq, (ftnlen)3, (ftnlen)1);
	    } else {

/*  Repeated accid, so must be double */

		all_1.nacc[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = bit_set(all_1.nacc[commvl_1.ivx + all_1.nnl[
			commvl_1.ivx - 1] * 15 - 16],2);
	    }
	    goto L2;
	} else if (i_indx("+-<>", durq, (ftnlen)4, (ftnlen)1) > 0) {
	    ipm = i_indx("- +", durq, (ftnlen)3, (ftnlen)1) - 2;
	    if (! bit_test(all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx 
		    - 1] * 15 - 16],0)) {

/*  A note, not a rest. */

		chkpm4ac_(lineq, &all_1.iccount, &all_1.nacc[commvl_1.ivx + 
			all_1.nnl[commvl_1.ivx - 1] * 15 - 16], &moved, (
			ftnlen)128);
		if (moved) {
		    goto L2;
		}

/*  Octave jump with a note */

		if (numnum < 2) {
		    comnotes_2.lastlev += ipm * 7;
		} else {
		    ioct += ipm;
		}
		goto L2;
	    } else {

/*  Override default height of a rest */

/*            call getchar(lineq,iccount,durq) */
		++all_1.iccount;
		readnum_(lineq, &all_1.iccount, durq, &fnum, (ftnlen)128, (
			ftnlen)1);
		i__1 = all_1.iccount - 2;
		if (s_cmp(lineq + i__1, ".", all_1.iccount - 1 - i__1, (
			ftnlen)1) == 0) {

/*  Kluge in case there is a shortcut ".". It will have been sucked up by */
/*  readnum.  (Same doesn't hold for ",") */

		    all_1.iccount += -2;
		    goto L2;
		}
		all_1.nolev[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = ipm * i_nint(&fnum) + 100;

/*  There may be more characters for this rest */

		--all_1.iccount;
		goto L2;
	    }
	} else if (*(unsigned char *)durq == 'x') {

/*  xtuplet: Set all durations to 0 except last one.  Set flag on this note. */

	    all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] 
		    = bit_set(all_1.irest[commvl_1.ivx + all_1.nnl[
		    commvl_1.ivx - 1] * 15 - 16],28);

/*  Next input will be digit */

	    ++all_1.iccount;
	    readnum_(lineq, &all_1.iccount, durq, &fnum, (ftnlen)128, (ftnlen)
		    1);
	    ntup = i_nint(&fnum);

/*  Only other possibilities here are ' ' or 'n' */

	    if (*(unsigned char *)durq == 'n') {

/*  Alter xtup number */

		i__1 = all_1.iccount;
		if (s_cmp(lineq + i__1, " ", all_1.iccount + 1 - i__1, (
			ftnlen)1) == 0) {

/*  If the only modifier is 'n', cancel the number */

		    all_1.islur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
			    15 - 16] = bit_set(all_1.islur[commvl_1.ivx + 
			    all_1.nnl[commvl_1.ivx - 1] * 15 - 16],31);
		} else {
		    numshft = 0;
L30:
		    getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (
			    ftnlen)1);
		    if (*(unsigned char *)durq == 'f') {

/*  Flip up-down-ness */

			all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1]
				 * 15 - 16] = bit_set(all_1.irest[
				commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
				15 - 16],14);
			goto L30;
		    } else if (*(unsigned char *)durq != ' ') {

/*  Vertical or horiz shift; durq must be +/- */

			++numshft;
			iofforn = 1;
			if (*(unsigned char *)durq == '-') {
			    iofforn = -1;
			}
			++all_1.iccount;
			readnum_(lineq, &all_1.iccount, durq, &xofforn, (
				ftnlen)128, (ftnlen)1);
			--all_1.iccount;
			if (numshft == 1) {

/*  Vertical shift */

			    iofforn = iofforn * i_nint(&xofforn) + 16;

/*  Turn on bit 1; set bits 2-6 to iofforn */

			    all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx 
				    - 1] * 15 - 16] |= (iofforn << 2) + 2;
			} else {

/*  Horizontal shift */

			    r__1 = xofforn * 10;
			    iofforn = iofforn * i_nint(&r__1) + 16;
			    all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx 
				    - 1] * 15 - 16] = bit_set(all_1.irest[
				    commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1]
				     * 15 - 16],7);
			    all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx 
				    - 1] * 15 - 16] |= iofforn << 9;
			}
			goto L30;
		    }
		}
	    }

/*  Set note level of 1st note of xtup, provided not a rest */

	    if (! bit_test(all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx 
		    - 1] * 15 - 16],0)) {
		if (numnum == 2) {
		    comnotes_2.lastlev = ifnolev_(charq, &ioct, (ftnlen)1);
		    all_1.nolev[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
			    15 - 16] = comnotes_2.lastlev;
		} else {
		    comnotes_2.lastlev = comnotes_2.lastlev - 3 + (ifnolev_(
			    charq, &c__10, (ftnlen)1) - comnotes_2.lastlev + 
			    3) % 7;
		    all_1.nolev[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
			    15 - 16] = comnotes_2.lastlev;
		}
	    }
	    for (comnotes_2.npreslur = comnotes_2.npreslur; 
		    comnotes_2.npreslur >= 1; --comnotes_2.npreslur) {

/*  Set note level for preslur on starting note of xtuplet */

		setbits_(&all_1.isdat2[all_1.nsdat - comnotes_2.npreslur], &
			c__7, &c__19, &comnotes_2.lastlev);
/* L40: */
	    }
	    numnum = 0;
	    all_1.nodur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] 
		    = 0;
	    i__1 = ntup;
	    for (itup = 2; itup <= i__1; ++itup) {
		if (comget_1.ornrpt) {
		    all_1.iornq[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
			    15 - 1] |= all_1.iornq[commvl_1.ivx + (all_1.nnl[
			    commvl_1.ivx - 1] - 1) * 15 - 1] & 10026991;
		    if ((all_1.iornq[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 
			    1] * 15 - 1] & 32896) > 0) {

/*  This is a trill (bit 7 or 15) so must dup the parameters */

			++comtrill_1.ntrill;
			comtrill_1.ivtrill[comtrill_1.ntrill - 1] = 
				commvl_1.ivx;
			comtrill_1.iptrill[comtrill_1.ntrill - 1] = all_1.nnl[
				commvl_1.ivx - 1];
			comtrill_1.xnsktr[comtrill_1.ntrill - 1] = 
				comtrill_1.xnsktr[comtrill_1.ntrill - 2];
		    }
		}
		++all_1.nnl[commvl_1.ivx - 1];
		if (comget_1.fbon) {
		    all_1.ipl[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 
			    - 16] = bit_set(all_1.ipl[commvl_1.ivx + 
			    all_1.nnl[commvl_1.ivx - 1] * 15 - 16],30);
		}
L7:
		getchar_(lineq, &all_1.iccount, charq, (ftnlen)128, (ftnlen)1)
			;
		if (*(unsigned char *)charq == ' ') {
		    goto L7;
		} else if (*(unsigned char *)charq == 'o') {

/*  Ornament in xtuplet.  "o" symbol must come AFTER the affected note */

		    if (comnotes_2.notcrd) {
			nole = all_1.nolev[commvl_1.ivx + (all_1.nnl[
				commvl_1.ivx - 1] - 1) * 15 - 16];
		    } else {
			nole = 127 & lbit_shift(comtrill_1.icrdat[
				comtrill_1.ncrd - 1], (ftnlen)-12);
		    }
		    i__2 = all_1.nnl[commvl_1.ivx - 1] - 1;
		    getorn_(lineq, &all_1.iccount, &all_1.iornq[commvl_1.ivx 
			    + (all_1.nnl[commvl_1.ivx - 1] - 1) * 15 - 1], &
			    all_1.iornq[commvl_1.ivx - 1], &comget_1.ornrpt, &
			    comgrace_1.noffseg, &i__2, &commvl_1.ivx, &
			    c_false, &comnotes_2.notcrd, &nole, (ftnlen)128);
		    goto L7;
		} else if (i_indx("st()", charq, (ftnlen)4, (ftnlen)1) > 0) {
		    nnlivx = all_1.nnl[commvl_1.ivx - 1] - 1;
		    if (*(unsigned char *)charq == '(') {

/*  Detected preslur in xtuplet loop, non-chord note */

			++nnlivx;
			++comnotes_2.npreslur;
		    }
		    all_1.islur[commvl_1.ivx + nnlivx * 15 - 16] = bit_set(
			    all_1.islur[commvl_1.ivx + nnlivx * 15 - 16],0);
		    if (*(unsigned char *)charq == 't') {
			all_1.islur[commvl_1.ivx + nnlivx * 15 - 16] = 
				bit_set(all_1.islur[commvl_1.ivx + nnlivx * 
				15 - 16],1);
		    }
		    if (commvl_1.ivx <= all_1.nv) {
			kv = 1;
		    } else {
			kv = 2;
		    }
		    sslur_(lineq, &all_1.iccount, &all_1.iv, &kv, &nnlivx, 
			    all_1.isdat1, all_1.isdat2, all_1.isdat3, &
			    all_1.nsdat, &comnotes_2.notcrd, &all_1.nolev[
			    commvl_1.ivx + nnlivx * 15 - 16], (ftnlen)128);
		    goto L7;
		} else if (*(unsigned char *)charq == *(unsigned char *)
			all_1.sq) {
		    littex_(all_1.islur, &all_1.nnl[commvl_1.ivx - 1], &
			    commvl_1.ivx, &comas3_1.topmods, lineq, &
			    all_1.iccount, (ftnlen)128);
		    goto L7;
		} else if (i_indx("0123456789#-nx_", charq, (ftnlen)15, (
			ftnlen)1) > 0) {

/*  Figure.  Must come AFTER the first note of xtup */

		    nfig1 = comfig_1.nfigs + 1;
		    getfig_(&comgrace_1.itoff[nfig1 - 1], charq, lineq, &
			    all_1.iccount, &all_1.isfig[all_1.nnl[
			    commvl_1.ivx - 1] - 1], &comfig_1.itfig[nfig1 - 1]
			    , all_1.itsofar, &c__0, comfig_1.figq + (nfig1 - 
			    1) * 6, &commvl_1.ivx, &comfig_1.nfigs, (ftnlen)1,
			     (ftnlen)128, (ftnlen)6);
		    goto L7;
		} else if (*(unsigned char *)charq == 'X') {
/* Computing MAX */
		    i__2 = 1, i__3 = all_1.nnl[commvl_1.ivx - 1] - 1;
		    getx_(lineq, &all_1.iccount, &all_1.irest[commvl_1.ivx + 
			    max(i__2,i__3) * 15 - 16], &comnotes_2.shifton, &
			    comask_1.wheadpt, &all_1.iornq[commvl_1.ivx + 
			    all_1.nnl[commvl_1.ivx - 1] * 15 - 1], &
			    commvl_1.ivx, &all_1.irest[commvl_1.ivx + 
			    all_1.nnl[commvl_1.ivx - 1] * 15 - 16], &
			    all_1.itsofar[commvl_1.ivx - 1], &ntup, &itup, &
			    comnotes_2.nnodur, dotq, (ftnlen)128, (ftnlen)1);
		    goto L7;
		} else if (*(unsigned char *)charq == 'z') {

/*  Chord note in xtup.  Goes with *prior* note. */

		    comnotes_2.notcrd = FALSE_;
		    ++comtrill_1.ncrd;
		    all_1.ipl[commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 1] - 1)
			     * 15 - 16] = bit_set(all_1.ipl[commvl_1.ivx + (
			    all_1.nnl[commvl_1.ivx - 1] - 1) * 15 - 16],10);
		    numnum = 0;
		    comtrill_1.icrdat[comtrill_1.ncrd - 1] = all_1.nnl[
			    commvl_1.ivx - 1] - 1 | commvl_1.ivx << 8;
		    comtrill_1.icrdorn[comtrill_1.ncrd - 1] = 0;

/*  Get note name */

		    getchar_(lineq, &all_1.iccount, charq, (ftnlen)128, (
			    ftnlen)1);

/*  Get optional inputs */

L34:
		    getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (
			    ftnlen)1);

/*  When chord note is done, will get ' ', making ndx=0, so go past this block */

		    ndx = i_indx("fsn+-<>12345678re", durq, (ftnlen)17, (
			    ftnlen)1);
		    if (ndx > 0) {
			if (ndx <= 3) {
			    if (! bit_test(comtrill_1.icrdat[comtrill_1.ncrd 
				    - 1],19)) {
				comtrill_1.icrdat[comtrill_1.ncrd - 1] = 
					bit_set(comtrill_1.icrdat[
					comtrill_1.ncrd - 1],19);
				comtrill_1.icrdat[comtrill_1.ncrd - 1] |= ndx 
					<< 20;
			    } else {
				comtrill_1.icrdat[comtrill_1.ncrd - 1] = 
					bit_set(comtrill_1.icrdat[
					comtrill_1.ncrd - 1],22);
			    }
			} else if (ndx <= 7) {

/* +/-/</> Check whether octave or accidental shift */

			    nactmp = 0;
			    chkpm4ac_(lineq, &all_1.iccount, &nactmp, &moved, 
				    (ftnlen)128);
			    if (moved) {

/*  Transfer accidental shift values */

				i__2 = igetbits_(&nactmp, &c__6, &c__4);
				setbits_(&comtrill_1.icrdot[comtrill_1.ncrd - 
					1], &c__6, &c__14, &i__2);
				i__2 = igetbits_(&nactmp, &c__7, &c__10);
				setbits_(&comtrill_1.icrdot[comtrill_1.ncrd - 
					1], &c__7, &c__20, &i__2);
			    } else {
				if (*(unsigned char *)durq == '+') {
				    comnotes_2.lastlev += 7;
				} else if (*(unsigned char *)durq == '-') {
				    comnotes_2.lastlev += -7;
				}
			    }
			} else if (*(unsigned char *)durq == 'e') {
			    comtrill_1.icrdat[comtrill_1.ncrd - 1] = bit_set(
				    comtrill_1.icrdat[comtrill_1.ncrd - 1],23)
				    ;
			    all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx 
				    - 1] * 15 - 16] = bit_set(all_1.irest[
				    commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1]
				     * 15 - 16],27);
			} else if (*(unsigned char *)durq == 'r') {
			    comtrill_1.icrdat[comtrill_1.ncrd - 1] = bit_set(
				    comtrill_1.icrdat[comtrill_1.ncrd - 1],24)
				    ;
			    all_1.irest[commvl_1.ivx + (all_1.nnl[
				    commvl_1.ivx - 1] - 1) * 15 - 16] = 
				    bit_set(all_1.irest[commvl_1.ivx + (
				    all_1.nnl[commvl_1.ivx - 1] - 1) * 15 - 
				    16],20);
			} else {

/* must be a number, save it in ioct */

			    numnum = 1;
			    ioct = ndx - 5;
			}
			goto L34;
		    }
		    if (numnum == 1) {
			comnotes_2.lastlev = ifnolev_(charq, &ioct, (ftnlen)1)
				;
		    } else {
			comnotes_2.lastlev = comnotes_2.lastlev - 3 + (
				ifnolev_(charq, &c__10, (ftnlen)1) - 
				comnotes_2.lastlev + 3) % 7;
		    }
		    comtrill_1.icrdat[comtrill_1.ncrd - 1] |= 
			    comnotes_2.lastlev << 12;
		    for (comnotes_2.npreslur = comnotes_2.npreslur; 
			    comnotes_2.npreslur >= 1; --comnotes_2.npreslur) {

/*  Set note level for preslur on chord note in xtup */

			setbits_(&all_1.isdat2[all_1.nsdat - 
				comnotes_2.npreslur], &c__7, &c__19, &
				comnotes_2.lastlev);

/*  Following lines copied from loop for non-xtup, chord note, preslur */
/*  Initially I assigned the slur(s) to next note, so fix. */

			all_1.islur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1]
				 * 15 - 16] = bit_clear(all_1.islur[
				commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
				15 - 16],0);
			all_1.islur[commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 
				1] - 1) * 15 - 16] = bit_set(all_1.islur[
				commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 1] - 
				1) * 15 - 16],0);
			all_1.isdat2[all_1.nsdat - comnotes_2.npreslur] = 
				bit_set(all_1.isdat2[all_1.nsdat - 
				comnotes_2.npreslur],0);
			i__2 = igetbits_(&all_1.isdat1[all_1.nsdat - 
				comnotes_2.npreslur], &c__8, &c__3) - 1;
			setbits_(&all_1.isdat1[all_1.nsdat - 
				comnotes_2.npreslur], &c__8, &c__3, &i__2);
/* L41: */
		    }
		    goto L7;
		}

/*  End of loop for xtup options. If here, charq must be a (non-crd) note name. */
/*  or rest */

		if (*(unsigned char *)charq == 'r') {
		    all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
			    15 - 16] = bit_set(all_1.irest[commvl_1.ivx + 
			    all_1.nnl[commvl_1.ivx - 1] * 15 - 16],0);
		    i__2 = all_1.iccount;
		    if (i_indx("+-", lineq + i__2, (ftnlen)2, all_1.iccount + 
			    1 - i__2) > 0) {

/*  Override height of embedded xtup rest */

			getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (
				ftnlen)1);
			ipm = i_indx("- +", durq, (ftnlen)3, (ftnlen)1) - 2;
			++all_1.iccount;
			readnum_(lineq, &all_1.iccount, durq, &fnum, (ftnlen)
				128, (ftnlen)1);
			all_1.nolev[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1]
				 * 15 - 16] = ipm * i_nint(&fnum) + 100;
			--all_1.iccount;
		    } else if (commvl_1.ivx <= all_1.nv) {
			all_1.nolev[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1]
				 * 15 - 16] = 0;
		    } else {
			all_1.nolev[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1]
				 * 15 - 16] = 2;
		    }
		}
		comnotes_2.notcrd = TRUE_;
L8:
		getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
		if (*(unsigned char *)durq != ' ') {
		    if (i_indx("+-<>", durq, (ftnlen)4, (ftnlen)1) > 0) {

/*  Accidental horizontal shift */

			chkpm4ac_(lineq, &all_1.iccount, &all_1.nacc[
				commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
				15 - 16], &moved, (ftnlen)128);
			if (! moved) {
			    if (*(unsigned char *)durq == '+') {
				comnotes_2.lastlev += 7;
			    } else if (*(unsigned char *)durq == '-') {
				comnotes_2.lastlev += -7;
			    }
			}
		    } else if (i_indx("fsn", durq, (ftnlen)3, (ftnlen)1) > 0) 
			    {
			if (all_1.nacc[commvl_1.ivx + all_1.nnl[commvl_1.ivx 
				- 1] * 15 - 16] == 0) {

/*  No accid set yet */

			    all_1.nacc[commvl_1.ivx + all_1.nnl[commvl_1.ivx 
				    - 1] * 15 - 16] = i_indx("fsn", durq, (
				    ftnlen)3, (ftnlen)1);
			} else {

/*  Symbol must be repeated, so it's a double */

			    all_1.nacc[commvl_1.ivx + all_1.nnl[commvl_1.ivx 
				    - 1] * 15 - 16] = bit_set(all_1.nacc[
				    commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1]
				     * 15 - 16],2);
			}
		    } else if (i_indx("ul", durq, (ftnlen)2, (ftnlen)1) > 0) {

/*  Force stem direction for non-beamed xtup note */

			all_1.islur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1]
				 * 15 - 16] = bit_set(all_1.islur[
				commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
				15 - 16],30);
			if (*(unsigned char *)durq == 'u') {
			    all_1.islur[commvl_1.ivx + all_1.nnl[commvl_1.ivx 
				    - 1] * 15 - 16] = bit_set(all_1.islur[
				    commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1]
				     * 15 - 16],17);
			}
		    } else if (*(unsigned char *)durq == 'e') {

/*  Left-shift main xtup note */

			all_1.ipl[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] *
				 15 - 16] = bit_set(all_1.ipl[commvl_1.ivx + 
				all_1.nnl[commvl_1.ivx - 1] * 15 - 16],8);
			all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1]
				 * 15 - 16] = bit_set(all_1.irest[
				commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
				15 - 16],27);
		    } else if (*(unsigned char *)durq == 'r') {

/*  Right-shift main xtup note */

			all_1.ipl[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] *
				 15 - 16] = bit_set(all_1.ipl[commvl_1.ivx + 
				all_1.nnl[commvl_1.ivx - 1] * 15 - 16],9);
			all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1]
				 * 15 - 16] = bit_set(all_1.irest[
				commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
				15 - 16],20);
		    } else {

/*  Must be an octave number */

			i__2 = *(unsigned char *)durq - 48;
			comnotes_2.lastlev = ifnolev_(charq, &i__2, (ftnlen)1)
				;
		    }
		    goto L8;
		}
		if (itup < ntup) {

/*  Last note is handled *after* flowing out of the xtup if block, but still */
/*    within block for a note-rest.  Set note level now (rest already done) */

		    if (! bit_test(all_1.irest[commvl_1.ivx + all_1.nnl[
			    commvl_1.ivx - 1] * 15 - 16],0)) {
			comnotes_2.lastlev = comnotes_2.lastlev - 3 + (
				ifnolev_(charq, &c__10, (ftnlen)1) - 
				comnotes_2.lastlev + 3) % 7;
			all_1.nolev[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1]
				 * 15 - 16] = comnotes_2.lastlev;
		    }
		    all_1.nodur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
			    15 - 16] = 0;
		    for (comnotes_2.npreslur = comnotes_2.npreslur; 
			    comnotes_2.npreslur >= 1; --comnotes_2.npreslur) {

/*  Set note level for preslur on internal xtup note */

			setbits_(&all_1.isdat2[all_1.nsdat - 
				comnotes_2.npreslur], &c__7, &c__19, &
				comnotes_2.lastlev);
/* L42: */
		    }
		}
/* L6: */
	    }
	    if (comget_1.ornrpt) {
		all_1.iornq[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			1] |= all_1.iornq[commvl_1.ivx + (all_1.nnl[
			commvl_1.ivx - 1] - 1) * 15 - 1] & 10026991;
		if ((all_1.iornq[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
			15 - 1] & 32896) > 0) {

/*  This is a trill (bit 7 or 15) so must dup the parameters */

		    ++comtrill_1.ntrill;
		    comtrill_1.ivtrill[comtrill_1.ntrill - 1] = commvl_1.ivx;
		    comtrill_1.iptrill[comtrill_1.ntrill - 1] = all_1.nnl[
			    commvl_1.ivx - 1];
		    comtrill_1.xnsktr[comtrill_1.ntrill - 1] = 
			    comtrill_1.xnsktr[comtrill_1.ntrill - 2];
		}
	    }

/*  End of if-block for xtuplet input */

	} else if (*(unsigned char *)durq == 'm') {

/*  Multi-bar rest: next 1 or two digits are # of bars. */
/*  For some purposes, pretend its one bar only */

	    all_1.nodur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] 
		    = all_1.lenbar;
	    comgrace_1.ibarmbr = all_1.nbars + 1;
	    comgrace_1.mbrest = 0;
	    comgrace_1.xb4mbr = (float)0.;
L20:
	    getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (*(unsigned char *)durq >= 48 && *(unsigned char *)durq <= 57) 
		    {
		comgrace_1.mbrest = comgrace_1.mbrest * 10 + *(unsigned char *
			)durq - 48;
		goto L20;
	    }
	} else if (i_indx("ul", durq, (ftnlen)2, (ftnlen)1) > 0) {

/*  Set stem flipper */

	    all_1.islur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] 
		    = bit_set(all_1.islur[commvl_1.ivx + all_1.nnl[
		    commvl_1.ivx - 1] * 15 - 16],30);
	    if (*(unsigned char *)durq == 'u') {
		all_1.islur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = bit_set(all_1.islur[commvl_1.ivx + all_1.nnl[
			commvl_1.ivx - 1] * 15 - 16],17);
	    }
	    goto L2;
	} else if (*(unsigned char *)durq == 'a') {

/*  "Alone", i.e., prohibit beam */

	    all_1.islur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] 
		    = bit_set(all_1.islur[commvl_1.ivx + all_1.nnl[
		    commvl_1.ivx - 1] * 15 - 16],18);
	    goto L2;
	} else if (*(unsigned char *)durq == 'r') {

/*  Right offset by one notehead */

	    all_1.ipl[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] = 
		    bit_set(all_1.ipl[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 
		    1] * 15 - 16],9);
	    all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] 
		    = bit_set(all_1.irest[commvl_1.ivx + all_1.nnl[
		    commvl_1.ivx - 1] * 15 - 16],20);
	    goto L2;
	} else if (*(unsigned char *)durq == 'e') {

/*  Left offset by one notehead */

	    all_1.ipl[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] = 
		    bit_set(all_1.ipl[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 
		    1] * 15 - 16],8);
	    all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] 
		    = bit_set(all_1.irest[commvl_1.ivx + all_1.nnl[
		    commvl_1.ivx - 1] * 15 - 16],27);
	    goto L2;
	} else if (*(unsigned char *)durq == ',') {

/*  2:1 pattern */

	    idotform = 3;

/*  Now flow to duration setting, as if durq=' ' */

	} else if (*(unsigned char *)durq == '.') {

/*  Dotted pattern.  Close out note.  Mult time by 3/4. */
/*  Set time for next note to 1/4.  Start the note. */

	    idotform = 1;
	} else if (*(unsigned char *)durq == 'o') {

/*  Suppress rest centering */

	    all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] 
		    = bit_set(all_1.irest[commvl_1.ivx + all_1.nnl[
		    commvl_1.ivx - 1] * 15 - 16],25);
	    goto L2;
	} else if (*(unsigned char *)durq != ' ') {
	    s_wsle(&io___689);
	    do_lio(&c__9, &c__1, "Illegal character in note: ", (ftnlen)27);
	    do_lio(&c__9, &c__1, durq, (ftnlen)1);
	    do_lio(&c__9, &c__1, ", ivx,nn:", (ftnlen)9);
	    do_lio(&c__3, &c__1, (char *)&commvl_1.ivx, (ftnlen)sizeof(
		    integer));
	    do_lio(&c__3, &c__1, (char *)&all_1.nnl[commvl_1.ivx - 1], (
		    ftnlen)sizeof(integer));
	    e_wsle();
	    s_stop("", (ftnlen)0);
	}

/*  Done with note/rest options.  Set level and duration. */

	if (! bit_test(all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] 
		* 15 - 16],0)) {
	    if (numnum == 2) {
		comnotes_2.lastlev = ifnolev_(charq, &ioct, (ftnlen)1);
		all_1.nolev[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = comnotes_2.lastlev;
	    } else {
		comnotes_2.lastlev = comnotes_2.lastlev - 3 + (ifnolev_(charq,
			 &c__10, (ftnlen)1) - comnotes_2.lastlev + 3) % 7;
		all_1.nolev[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = comnotes_2.lastlev;
	    }
	    for (comnotes_2.npreslur = comnotes_2.npreslur; 
		    comnotes_2.npreslur >= 1; --comnotes_2.npreslur) {

/*  Set level for preslur on normal note, non-chord */

		setbits_(&all_1.isdat2[all_1.nsdat - comnotes_2.npreslur], &
			c__7, &c__19, &comnotes_2.lastlev);
/* L43: */
	    }
	}
	if (idotform > 0) {
	    if (idotform == 1) {
		all_1.nodur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = ifnodur_(&comnotes_2.nnodur, dotq, (ftnlen)1) * 
			3 / 2;
	    } else if (idotform == 2) {
		all_1.nodur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = all_1.nodur[commvl_1.ivx + (all_1.nnl[
			commvl_1.ivx - 1] - 1) * 15 - 16] / 3;
	    } else if (idotform == 3) {
		all_1.nodur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = ifnodur_(&comnotes_2.nnodur, dotq, (ftnlen)1);
	    } else if (idotform == 4) {
		all_1.nodur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = all_1.nodur[commvl_1.ivx + (all_1.nnl[
			commvl_1.ivx - 1] - 1) * 15 - 16] / 2;
	    }
	} else if (bit_test(all_1.islur[commvl_1.ivx + all_1.nnl[commvl_1.ivx 
		- 1] * 15 - 16],19)) {

/*  Set duration of full-bar rest as pause */

	    all_1.nodur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] 
		    = all_1.lenbar;

/*  Use a one-line function to set nnodur.  It gives inverse of ifnodur. */

	    i__1 = (integer) (log(all_1.lenbar + (float).1) / (float).69315) 
		    + 48;
	    chax_(ch__1, (ftnlen)1, &i__1);
	    comnotes_2.nnodur = i_indx("62514x0x37", ch__1, (ftnlen)10, (
		    ftnlen)1) - 1;
	} else if (comgrace_1.ibarmbr != all_1.nbars + 1) {
	    all_1.nodur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] 
		    = ifnodur_(&comnotes_2.nnodur, dotq, (ftnlen)1);
	    if (bit_test(all_1.islur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 
		    1] * 15 - 16],3)) {
		all_1.nodur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = all_1.nodur[commvl_1.ivx + all_1.nnl[
			commvl_1.ivx - 1] * 15 - 16] * 7 / 6;
	    }
	}
	if (comnotes_2.shifton && ! bit_test(all_1.irest[commvl_1.ivx + 
		all_1.nnl[commvl_1.ivx - 1] * 15 - 16],16)) {

/*  Shift is on, and this is not first shifted note.  Check for duration change */

	    if (all_1.nodur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
		    16] != all_1.nodur[commvl_1.ivx + (all_1.nnl[commvl_1.ivx 
		    - 1] - 1) * 15 - 16]) {

/*  Must stop and restart the offset. */

		all_1.irest[commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 1] - 1) *
			 15 - 16] = bit_set(all_1.irest[commvl_1.ivx + (
			all_1.nnl[commvl_1.ivx - 1] - 1) * 15 - 16],17);
		all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = bit_set(all_1.irest[commvl_1.ivx + all_1.nnl[
			commvl_1.ivx - 1] * 15 - 16],16);
		++comudsp_1.nudoff[commvl_1.ivx - 1];
		comudsp_1.udoff[commvl_1.ivx + comudsp_1.nudoff[commvl_1.ivx 
			- 1] * 15 - 16] = comudsp_1.udoff[commvl_1.ivx + (
			comudsp_1.nudoff[commvl_1.ivx - 1] - 1) * 15 - 16];
	    }
	}
	all_1.itsofar[commvl_1.ivx - 1] += all_1.nodur[commvl_1.ivx + 
		all_1.nnl[commvl_1.ivx - 1] * 15 - 16];
	if ((all_1.itsofar[commvl_1.ivx - 1] - all_1.lenb0) % all_1.lenbar == 
		0) {

/*  Finished a bar */

	    ++all_1.nbars;
	    all_1.nib[commvl_1.ivx + all_1.nbars * 15 - 16] = all_1.nnl[
		    commvl_1.ivx - 1];
	    if (all_1.firstgulp && all_1.lenb0 != 0 && all_1.nbars == 1) {

/*  Just finished the pickup bar for this voice. */

		all_1.lenbar = all_1.lenb1;
	    }
	}
	if (idotform == 1) {
	    getchar_(lineq, &all_1.iccount, charq, (ftnlen)128, (ftnlen)1);
	    idotform = 2;
	    numnum = 1;
	    goto L28;
	} else if (idotform == 3) {
	    getchar_(lineq, &all_1.iccount, charq, (ftnlen)128, (ftnlen)1);
	    idotform = 4;
	    numnum = 1;
	    goto L28;
	}

/*  End of sub block for note-rest */

    } else if (*(unsigned char *)charq == 'z') {

/*  Chord note.  Must have note name, may have octave#,+,-,s,f,n,d */
/*  Actually the 'd' is not used, since time value comes from */
/*    basic note. Unless dot is to be shifted! */
/*  Doesn't increase # of notes, so must handle separately */
/*  ncrd: index of crd */
/*  Set bit 10 of ipl on main note as flag */
/*  Bits in icrdat: */
/*     0-7   ip within voice */
/*     8-11  ivx */
/*     12-18 note level */
/*     19    accidental? */
/*     20-22 accidental value (1=natural, 2=flat, 3=sharp, 6=dflat, 7=dsharp) */
/*     23    shift left */
/*     24    shift right */
/*     25    arpeggio start or stop */
/*     26    flag for moved dot (here, not icrdot, since this is always reset!) */

/*  Bits in icrdot: */
/*     0-6   10*abs(vertical dot shift in \internote) + 64 */
/*     7-13  10*abs(horizontal dot shift in \internote) + 64 */
/*     14-19 vert accidental shift-32 */
/*     20-26 10*(horiz accidental shift-3.2) */

/*  Bits in icrdorn are same as in iornq, even tho most orns won't go in crds. */

	++comtrill_1.ncrd;
	all_1.ipl[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] = 
		bit_set(all_1.ipl[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] *
		 15 - 16],10);
	numnum = 0;
	comtrill_1.icrdat[comtrill_1.ncrd - 1] = all_1.nnl[commvl_1.ivx - 1] |
		 commvl_1.ivx << 8;
	comtrill_1.icrdot[comtrill_1.ncrd - 1] = 0;
	comtrill_1.icrdorn[comtrill_1.ncrd - 1] = 0;

/*  Get note name */

	getchar_(lineq, &all_1.iccount, charq, (ftnlen)128, (ftnlen)1);

/*  Get optional inputs */

L25:
	getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
	ndx = i_indx("fsn+-<>12345678red", durq, (ftnlen)18, (ftnlen)1);
	if (ndx > 0) {
	    if (ndx <= 3) {
		if (! bit_test(comtrill_1.icrdat[comtrill_1.ncrd - 1],19)) {
		    comtrill_1.icrdat[comtrill_1.ncrd - 1] = bit_set(
			    comtrill_1.icrdat[comtrill_1.ncrd - 1],19);
		    comtrill_1.icrdat[comtrill_1.ncrd - 1] |= ndx << 20;
		} else {
		    comtrill_1.icrdat[comtrill_1.ncrd - 1] = bit_set(
			    comtrill_1.icrdat[comtrill_1.ncrd - 1],22);
		}
	    } else if (ndx <= 7) {

/* +/-/</> Check whether octave or accidental shift */

		nactmp = 0;
		chkpm4ac_(lineq, &all_1.iccount, &nactmp, &moved, (ftnlen)128)
			;
		if (moved) {

/*  Transfer accidental shift values */

		    i__1 = igetbits_(&nactmp, &c__6, &c__4);
		    setbits_(&comtrill_1.icrdot[comtrill_1.ncrd - 1], &c__6, &
			    c__14, &i__1);
		    i__1 = igetbits_(&nactmp, &c__7, &c__10);
		    setbits_(&comtrill_1.icrdot[comtrill_1.ncrd - 1], &c__7, &
			    c__20, &i__1);
		} else {
		    if (*(unsigned char *)durq == '+') {
			comnotes_2.lastlev += 7;
		    } else if (*(unsigned char *)durq == '-') {
			comnotes_2.lastlev += -7;
		    }
		}
	    } else if (*(unsigned char *)durq == 'e') {
		comtrill_1.icrdat[comtrill_1.ncrd - 1] = bit_set(
			comtrill_1.icrdat[comtrill_1.ncrd - 1],23);
		all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = bit_set(all_1.irest[commvl_1.ivx + all_1.nnl[
			commvl_1.ivx - 1] * 15 - 16],27);
	    } else if (*(unsigned char *)durq == 'r') {
		comtrill_1.icrdat[comtrill_1.ncrd - 1] = bit_set(
			comtrill_1.icrdat[comtrill_1.ncrd - 1],24);
		all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = bit_set(all_1.irest[commvl_1.ivx + all_1.nnl[
			commvl_1.ivx - 1] * 15 - 16],20);
	    } else if (*(unsigned char *)durq == 'd') {

/*  Must keep 'd' optional (backward compatibility), unless it is moved! */

		i__1 = all_1.iccount;
		if (i_indx("+-", lineq + i__1, (ftnlen)2, all_1.iccount + 1 - 
			i__1) > 0) {

/*  move a dot, unless next char is not part of a number */

		    i__1 = all_1.iccount + 1;
		    if (i_indx("0123456789.", lineq + i__1, (ftnlen)11, 
			    all_1.iccount + 2 - i__1) == 0) {
			goto L25;
		    }
		    comtrill_1.icrdat[comtrill_1.ncrd - 1] = bit_set(
			    comtrill_1.icrdat[comtrill_1.ncrd - 1],26);
		    getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (
			    ftnlen)1);
		    ++all_1.iccount;
		    readnum_(lineq, &all_1.iccount, dumq, &fnum, (ftnlen)128, 
			    (ftnlen)1);
		    if (*(unsigned char *)durq == '+') {
			r__1 = fnum * 10;
			comtrill_1.icrdot[comtrill_1.ncrd - 1] |= i_nint(&
				r__1) + 64;
		    } else {
			r__1 = fnum * 10;
			comtrill_1.icrdot[comtrill_1.ncrd - 1] |= -i_nint(&
				r__1) + 64;
		    }
		    if (i_indx("+-", dumq, (ftnlen)2, (ftnlen)1) > 0) {

/*  Vertical shift specified also */

			++all_1.iccount;
			readnum_(lineq, &all_1.iccount, durq, &fnum, (ftnlen)
				128, (ftnlen)1);
			if (*(unsigned char *)dumq == '+') {
			    r__1 = fnum * 10;
			    ifnum = i_nint(&r__1) + 64;
			} else {
			    r__1 = fnum * 10;
			    ifnum = -i_nint(&r__1) + 64;
			}
		    } else {
			ifnum = 64;
		    }
		    comtrill_1.icrdot[comtrill_1.ncrd - 1] |= ifnum << 7;
		    --all_1.iccount;
		}
	    } else {

/* must be a single digit, save it in ioct */

		numnum = 1;
		ioct = ndx - 7;
	    }
	    goto L25;
	}
	if (numnum == 1) {
	    comnotes_2.lastlev = ifnolev_(charq, &ioct, (ftnlen)1);
	} else {
	    comnotes_2.lastlev = comnotes_2.lastlev - 3 + (ifnolev_(charq, &
		    c__10, (ftnlen)1) - comnotes_2.lastlev + 3) % 7;
	}
	comtrill_1.icrdat[comtrill_1.ncrd - 1] |= comnotes_2.lastlev << 12;
	for (comnotes_2.npreslur = comnotes_2.npreslur; comnotes_2.npreslur >=
		 1; --comnotes_2.npreslur) {
	    setbits_(&all_1.isdat2[all_1.nsdat - comnotes_2.npreslur], &c__7, 
		    &c__19, &comnotes_2.lastlev);

/*  Set level for chord note. */
/*  Initially I assigned the slur(s) to next note, so fix. */

	    all_1.islur[commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 1] + 1) * 15 
		    - 16] = bit_clear(all_1.islur[commvl_1.ivx + (all_1.nnl[
		    commvl_1.ivx - 1] + 1) * 15 - 16],0);
	    all_1.islur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] 
		    = bit_set(all_1.islur[commvl_1.ivx + all_1.nnl[
		    commvl_1.ivx - 1] * 15 - 16],0);
	    all_1.isdat2[all_1.nsdat - comnotes_2.npreslur] = bit_set(
		    all_1.isdat2[all_1.nsdat - comnotes_2.npreslur],0);
	    i__1 = igetbits_(&all_1.isdat1[all_1.nsdat - comnotes_2.npreslur],
		     &c__8, &c__3) - 1;
	    setbits_(&all_1.isdat1[all_1.nsdat - comnotes_2.npreslur], &c__8, 
		    &c__3, &i__1);
/* L44: */
	}
	if (comnotes_2.notcrd) {

/*  This is the first chord note in this chord. */

/* Computing MIN */
	    i__1 = all_1.nolev[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
		    15 - 16];
	    comtrill_1.minlev = min(i__1,comnotes_2.lastlev);
/* Computing MAX */
	    i__1 = all_1.nolev[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
		    15 - 16];
	    comtrill_1.maxlev = max(i__1,comnotes_2.lastlev);
	} else {
	    comtrill_1.minlev = min(comtrill_1.minlev,comnotes_2.lastlev);
	    comtrill_1.maxlev = max(comtrill_1.maxlev,comnotes_2.lastlev);
	}
	comnotes_2.notcrd = FALSE_;
    } else if (*(unsigned char *)charq == 'G') {

/* Grace, comes *before* main note: */
/* UNLESS there's an 'A' or 'W' after the 'G' */
/*   ngrace = # of grace note groups so far in block */
/*   ivg(ngrace), ipg(ngrace) */
/*   nng(ngrace) = # of notes in this group: default = 1 */
/*   ngstrt(ngrace) = starting position in nolevg of levels for this grace */
/*   multg(ngrace) = multiplicity: default = 1;  input as 'm(digit)' */
/*   upg(ngrace) = logical for beam or stem dirn: default T, input'u,l' */
/*   slurg(ngrace) = logical for slur; default F, input 's' */
/*   slashg(ngrace) = T if slash; default is F, input 'x' */
/* These data MUST precede note name of first note */
/*   nolevg, naccg: lists of levels and accid's, indexed as described above. */

	++comgrace_1.ngrace;
	comgrace_1.ivg[comgrace_1.ngrace - 1] = commvl_1.ivx;
	comgrace_1.ipg[comgrace_1.ngrace - 1] = all_1.nnl[commvl_1.ivx - 1] + 
		1;
	if (comgrace_1.ngrace == 1) {
	    comgrace_1.ngstrt[comgrace_1.ngrace - 1] = 1;
	} else {
	    comgrace_1.ngstrt[comgrace_1.ngrace - 1] = comgrace_1.ngstrt[
		    comgrace_1.ngrace - 2] + comgrace_1.nng[comgrace_1.ngrace 
		    - 2];
	}
	all_1.islur[commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 1] + 1) * 15 - 
		16] = bit_set(all_1.islur[commvl_1.ivx + (all_1.nnl[
		commvl_1.ivx - 1] + 1) * 15 - 16],4);
	comgrace_1.nng[comgrace_1.ngrace - 1] = 1;
	comgrace_1.multg[comgrace_1.ngrace - 1] = 1;
	comgrace_1.upg[comgrace_1.ngrace - 1] = TRUE_;
	comgrace_1.slurg[comgrace_1.ngrace - 1] = FALSE_;
	comgrace_1.slashg[comgrace_1.ngrace - 1] = FALSE_;
L18:
	getchar_(lineq, &all_1.iccount, charq, (ftnlen)128, (ftnlen)1);
	if (i_indx("WA", charq, (ftnlen)2, (ftnlen)1) > 0) {

/*  Grace is on note that was already done, so shift flags forward one note. */
/*  This puts flag on actual note with grace; later for W will go ahead one more. */

	    comgrace_1.ipg[comgrace_1.ngrace - 1] = all_1.nnl[commvl_1.ivx - 
		    1];
	    all_1.islur[commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 1] + 1) * 15 
		    - 16] = bit_clear(all_1.islur[commvl_1.ivx + (all_1.nnl[
		    commvl_1.ivx - 1] + 1) * 15 - 16],4);
	    all_1.islur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] 
		    = bit_set(all_1.islur[commvl_1.ivx + all_1.nnl[
		    commvl_1.ivx - 1] * 15 - 16],4);
	    if (comgrace_1.slurg[comgrace_1.ngrace - 1]) {
		all_1.iornq[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			1] = bit_set(all_1.iornq[commvl_1.ivx + all_1.nnl[
			commvl_1.ivx - 1] * 15 - 1],24);
	    }
	    if (*(unsigned char *)charq == 'A') {

/*  close After, clear way-after bit, to ensure priority of most recent A/W */

		all_1.ipl[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = bit_set(bit_clear(all_1.ipl[commvl_1.ivx + 
			all_1.nnl[commvl_1.ivx - 1] * 15 - 16],31),29);
	    } else {

/*  Way after; later assign to following note, and position like normal grace. */

		all_1.ipl[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = bit_set(bit_clear(all_1.ipl[commvl_1.ivx + 
			all_1.nnl[commvl_1.ivx - 1] * 15 - 16],29),31);
	    }
	} else if (*(unsigned char *)charq == 'm') {
	    getchar_(lineq, &all_1.iccount, charq, (ftnlen)128, (ftnlen)1);
	    comgrace_1.multg[comgrace_1.ngrace - 1] = *(unsigned char *)charq 
		    - 48;
	} else if (i_indx("123456789", charq, (ftnlen)9, (ftnlen)1) > 0) {
	    readnum_(lineq, &all_1.iccount, durq, &fnum, (ftnlen)128, (ftnlen)
		    1);
	    --all_1.iccount;
	    comgrace_1.nng[comgrace_1.ngrace - 1] = i_nint(&fnum);
	} else if (*(unsigned char *)charq == 'l') {
	    comgrace_1.upg[comgrace_1.ngrace - 1] = FALSE_;
	} else if (*(unsigned char *)charq == 's') {
	    comgrace_1.slurg[comgrace_1.ngrace - 1] = TRUE_;
	    if (all_1.nnl[commvl_1.ivx - 1] > 0) {

/*  If A- or W-grace, set signal to start slur on main note. */

		if (bit_test(all_1.ipl[commvl_1.ivx + all_1.nnl[commvl_1.ivx 
			- 1] * 15 - 16],31) || bit_test(all_1.ipl[
			commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16],
			29)) {
		    all_1.iornq[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
			    15 - 1] = bit_set(all_1.iornq[commvl_1.ivx + 
			    all_1.nnl[commvl_1.ivx - 1] * 15 - 1],24);
		}
	    }
	} else if (*(unsigned char *)charq == 'x') {
	    comgrace_1.slashg[comgrace_1.ngrace - 1] = TRUE_;
	} else if (*(unsigned char *)charq == 'u') {
	}
	if (i_indx("abcdefg", charq, (ftnlen)7, (ftnlen)1) == 0) {
	    goto L18;
	}

/*  At this point, charq is first note name in grace */

	i__1 = comgrace_1.ngstrt[comgrace_1.ngrace - 1] + comgrace_1.nng[
		comgrace_1.ngrace - 1] - 1;
	for (ing = comgrace_1.ngstrt[comgrace_1.ngrace - 1]; ing <= i__1; 
		++ing) {
	    comgrace_1.naccg[ing - 1] = 0;
	    ioct = 0;
	    if (ing > comgrace_1.ngstrt[comgrace_1.ngrace - 1]) {
L55:
		getchar_(lineq, &all_1.iccount, charq, (ftnlen)128, (ftnlen)1)
			;
		if (*(unsigned char *)charq == ' ') {
		    goto L55;
		}
	    }
L9:
	    getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (*(unsigned char *)durq != ' ') {
		if (*(unsigned char *)durq == '+') {
		    comnotes_2.lastlev += 7;
		} else if (*(unsigned char *)durq == '-') {
		    comnotes_2.lastlev += -7;
		} else if (i_indx("fsn", durq, (ftnlen)3, (ftnlen)1) > 0) {
		    if (comgrace_1.naccg[ing - 1] == 0) {
			comgrace_1.naccg[ing - 1] = i_indx("fsn", durq, (
				ftnlen)3, (ftnlen)1);
		    } else {

/*  Double accidental */

			comgrace_1.naccg[ing - 1] = bit_set(comgrace_1.naccg[
				ing - 1],2);
		    }
		} else {
		    ioct = *(unsigned char *)durq - 48;
		}
		goto L9;
	    }
	    if (ioct > 0) {
		comnotes_2.lastlev = ifnolev_(charq, &ioct, (ftnlen)1);
	    } else {
		if (all_1.nnl[commvl_1.ivx - 1] == 0 && ing == 
			comgrace_1.ngstrt[comgrace_1.ngrace - 1]) {
		    if (commvl_1.ivx <= all_1.nv) {
			kv = 1;
		    } else {
			kv = 2;
		    }
		    comnotes_2.lastlev = comnotes_2.ndlev[all_1.iv + kv * 15 
			    - 16];
		}
		comnotes_2.lastlev = comnotes_2.lastlev - 3 + (ifnolev_(charq,
			 &c__10, (ftnlen)1) - comnotes_2.lastlev + 3) % 7;
	    }
	    comgrace_1.nolevg[ing - 1] = comnotes_2.lastlev;
/* L19: */
	}

/*  Grace could come before first note of block, so reset end level. */

	if (all_1.nnl[commvl_1.ivx - 1] == 0) {
	    if (commvl_1.ivx <= all_1.nv) {
		kv = 1;
	    } else {
		kv = 2;
	    }
	    comnotes_2.ndlev[all_1.iv + kv * 15 - 16] = comnotes_2.lastlev;
	}
    } else if (*(unsigned char *)charq == *(unsigned char *)all_1.sq) {

/*  Literal TeX string */

	i__1 = all_1.nnl[commvl_1.ivx - 1] + 1;
	littex_(all_1.islur, &i__1, &commvl_1.ivx, &comas3_1.topmods, lineq, &
		all_1.iccount, (ftnlen)128);
    } else if (*(unsigned char *)charq == 'o') {

/*  Ornament on non-xtup note.  Symbol must come AFTER the affected note */

	if (comnotes_2.notcrd) {
	    nole = all_1.nolev[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
		    15 - 16];
	} else {
	    nole = 127 & lbit_shift(comtrill_1.icrdat[comtrill_1.ncrd - 1], (
		    ftnlen)-12);
	}
	getorn_(lineq, &all_1.iccount, &all_1.iornq[commvl_1.ivx + all_1.nnl[
		commvl_1.ivx - 1] * 15 - 1], &all_1.iornq[commvl_1.ivx - 1], &
		comget_1.ornrpt, &comgrace_1.noffseg, &all_1.nnl[commvl_1.ivx 
		- 1], &commvl_1.ivx, &c_true, &comnotes_2.notcrd, &nole, (
		ftnlen)128);
    } else if (i_indx("st()", charq, (ftnlen)4, (ftnlen)1) > 0) {
	nnlivx = all_1.nnl[commvl_1.ivx - 1];
	if (*(unsigned char *)charq == '(') {

/* Detect preslur on normal non-chord note */

	    ++nnlivx;
	    ++comnotes_2.npreslur;
	}
	all_1.islur[commvl_1.ivx + nnlivx * 15 - 16] = bit_set(all_1.islur[
		commvl_1.ivx + nnlivx * 15 - 16],0);
	if (*(unsigned char *)charq == 't') {
	    all_1.islur[commvl_1.ivx + nnlivx * 15 - 16] = bit_set(
		    all_1.islur[commvl_1.ivx + nnlivx * 15 - 16],1);
	}
	if (commvl_1.ivx <= all_1.nv) {
	    kv = 1;
	} else {
	    kv = 2;
	}
	sslur_(lineq, &all_1.iccount, &all_1.iv, &kv, &nnlivx, all_1.isdat1, 
		all_1.isdat2, all_1.isdat3, &all_1.nsdat, &comnotes_2.notcrd, 
		&all_1.nolev[commvl_1.ivx + nnlivx * 15 - 16], (ftnlen)128);
    } else if (*(unsigned char *)charq == '?') {

/*  Arpeggio */

	if (bit_test(all_1.ipl[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 
		15 - 16],10)) {

/*  This is a chordal note.  Set a bit in icrdat.  But if *main* (spacing) note */
/*  of chord, will not set icrdat(25), but iornq(27) */

	    comtrill_1.icrdat[comtrill_1.ncrd - 1] = bit_set(
		    comtrill_1.icrdat[comtrill_1.ncrd - 1],25);
	} else {
	    all_1.iornq[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 1] =
		     bit_set(all_1.iornq[commvl_1.ivx + all_1.nnl[
		    commvl_1.ivx - 1] * 15 - 1],27);
	}
    } else if (i_indx("0123456789#-nx_", charq, (ftnlen)15, (ftnlen)1) > 0) {

/*  We have a figure.  Must come AFTER the note it goes under */

	nfig1 = comfig_1.nfigs + 1;
	getfig_(&comgrace_1.itoff[nfig1 - 1], charq, lineq, &all_1.iccount, &
		all_1.isfig[all_1.nnl[commvl_1.ivx - 1] - 1], &comfig_1.itfig[
		nfig1 - 1], all_1.itsofar, &all_1.nodur[commvl_1.ivx + 
		all_1.nnl[commvl_1.ivx - 1] * 15 - 16], comfig_1.figq + (
		nfig1 - 1) * 6, &commvl_1.ivx, &comfig_1.nfigs, (ftnlen)1, (
		ftnlen)128, (ftnlen)6);
    } else if (*(unsigned char *)charq == '[') {

/*  Start forced beam.  Record barno & time since start of inp. blk.  Set signal */

	++comfb_1.nfb[commvl_1.ivx - 1];
	comget_1.fbon = TRUE_;
	*(unsigned char *)&comfb_1.ulfbq[commvl_1.ivx + comfb_1.nfb[
		commvl_1.ivx - 1] * 15 - 16] = 'x';
	comfb_1.t1fb[commvl_1.ivx + comfb_1.nfb[commvl_1.ivx - 1] * 15 - 16] =
		 (real) all_1.itsofar[commvl_1.ivx - 1];
	nadj = 0;
L17:
	getchar_(lineq, &all_1.iccount, charq, (ftnlen)128, (ftnlen)1);
	if (i_indx("ul", charq, (ftnlen)2, (ftnlen)1) > 0) {
	    *(unsigned char *)&comfb_1.ulfbq[commvl_1.ivx + comfb_1.nfb[
		    commvl_1.ivx - 1] * 15 - 16] = *(unsigned char *)charq;
	    goto L17;
	} else if (*(unsigned char *)charq == 'j') {

/*  Continuing a jumped beam here */

	    all_1.irest[commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 1] + 1) * 15 
		    - 16] = bit_set(all_1.irest[commvl_1.ivx + (all_1.nnl[
		    commvl_1.ivx - 1] + 1) * 15 - 16],24);
	    goto L17;
	} else if (*(unsigned char *)charq == 'h') {
	    all_1.islur[commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 1] + 1) * 15 
		    - 16] = bit_set(all_1.islur[commvl_1.ivx + (all_1.nnl[
		    commvl_1.ivx - 1] + 1) * 15 - 16],2);
	    goto L17;
	} else if (*(unsigned char *)charq == 'm') {

/*  Force multiplicity.  Next input is digit */

	    getchar_(lineq, &all_1.iccount, charq, (ftnlen)128, (ftnlen)1);
	    all_1.islur[commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 1] + 1) * 15 
		    - 16] = bit_set(all_1.islur[commvl_1.ivx + (all_1.nnl[
		    commvl_1.ivx - 1] + 1) * 15 - 16],21);
	    i__1 = *(unsigned char *)charq - 48;
	    setbits_(&all_1.islur[commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 1] 
		    + 1) * 15 - 16], &c__3, &c__22, &i__1);
	    goto L17;
	} else if (*(unsigned char *)charq != ' ') {

/*  Must be '+/-' for height or slope shift */

	    ++nadj;

/*  nadj = 1,2, or 3 for normal start level, slope, or beam-thk start level. */

	    ++all_1.iccount;
	    readnum_(lineq, &all_1.iccount, durq, &fnum, (ftnlen)128, (ftnlen)
		    1);
	    --all_1.iccount;
	    iadj = i_nint(&fnum);
	    if (*(unsigned char *)charq == '-') {
		iadj = -iadj;
	    }
	    if (nadj == 1) {

/*  This is a level shift.  Note if 0 was entered, iadj = 30 */

		all_1.ipl[commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 1] + 1) * 
			15 - 16] |= iadj + 30 << 11;
	    } else if (nadj == 2) {

/*  Must be a slope shift */

		all_1.ipl[commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 1] + 1) * 
			15 - 16] |= iadj + 30 << 17;
	    } else {

/*  Beam-thk fine tune */

		all_1.islur[commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 1] + 1) *
			 15 - 16] |= iadj << 27;
	    }
	    goto L17;
	}
    } else if (*(unsigned char *)charq == ']') {
	getchar_(lineq, &all_1.iccount, charq, (ftnlen)128, (ftnlen)1);
	if (i_indx("j ", charq, (ftnlen)2, (ftnlen)1) > 0) {

/*  Since ']' comes AFTER note, itsofar has been updated.  Set ending signal. */

	    comfb_1.t2fb[commvl_1.ivx + comfb_1.nfb[commvl_1.ivx - 1] * 15 - 
		    16] = (real) all_1.itsofar[commvl_1.ivx - 1];
	    comget_1.fbon = FALSE_;
	    if (*(unsigned char *)charq == 'j') {
		all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 
			16] = bit_set(all_1.irest[commvl_1.ivx + all_1.nnl[
			commvl_1.ivx - 1] * 15 - 16],23);
	    }
	} else if (*(unsigned char *)charq == '[') {

/*  Only other possibility is "[" for multiplicity down-up signal */

	    all_1.islur[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] 
		    = bit_set(all_1.islur[commvl_1.ivx + all_1.nnl[
		    commvl_1.ivx - 1] * 15 - 16],20);
	}
    } else if (*(unsigned char *)charq == 'D') {
	getdyn_(&commvl_1.ivx, &all_1.nnl[commvl_1.ivx - 1], &all_1.irest[
		commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16], lineq, 
		&all_1.iccount, (ftnlen)128);
    } else if (*(unsigned char *)charq == 'h') {

/*  Heading or height.  For heading, only OK if at start of block */
/*  Check whether at beginning of a block */

	if (all_1.iv != 1 || all_1.nnl[0] != 0) {
	    s_wsle(&io___694);
	    do_lio(&c__9, &c__1, "You entered \"h\" not at beginning of block"
		    , (ftnlen)41);
	    e_wsle();
	    s_stop("", (ftnlen)0);
	}
	getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
	comhead_1.ihdvrt = 0;
	if (i_indx("+-", durq, (ftnlen)2, (ftnlen)1) > 0) {

/* Vertical offset */

	    ++all_1.iccount;
	    readnum_(lineq, &all_1.iccount, charq, &fnum, (ftnlen)128, (
		    ftnlen)1);
	    comhead_1.ihdvrt = fnum + (float).1;
	    if (*(unsigned char *)durq == '-') {
		comhead_1.ihdvrt = -comhead_1.ihdvrt;
	    }
	    *(unsigned char *)durq = *(unsigned char *)charq;
	}
	if (*(unsigned char *)durq != ' ') {

/*  Height symbol.  Read past (until next blank) */

L3:
	    getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (*(unsigned char *)durq != ' ') {
		goto L3;
	    }
	} else {

/*  Set flag for header & read it in */

	    comhead_1.ihdht = 16;
	    getbuf_(comhead_1.headrq, (ftnlen)80);
	    all_1.iccount = 128;
	}
    } else if (*(unsigned char *)charq == 'L') {

/*  Linebreak, already handled in pmxa, but check for movement break */

	++all_1.iccount;
	readnum_(lineq, &all_1.iccount, durq, &fmovbrk, (ftnlen)128, (ftnlen)
		1);
	if (*(unsigned char *)durq == 'P') {
	    ++all_1.iccount;
	    readnum_(lineq, &all_1.iccount, durq, &fnum, (ftnlen)128, (ftnlen)
		    1);
	}
	if (*(unsigned char *)durq == 'M') {
	    comget_1.movbrk = i_nint(&fmovbrk);
	    comget_1.movgap = 0;
	    comget_1.parmov = (float)-1.;
	    getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
L31:
	    if (*(unsigned char *)durq == '+') {

/*  Get vertical space (\internotes) */

		++all_1.iccount;
		readnum_(lineq, &all_1.iccount, durq, &fnum, (ftnlen)128, (
			ftnlen)1);
		comget_1.movgap = i_nint(&fnum);
		goto L31;
	    } else if (*(unsigned char *)durq == 'i') {
		++all_1.iccount;
		readnum_(lineq, &all_1.iccount, durq, &comget_1.parmov, (
			ftnlen)128, (ftnlen)1);
		goto L31;
	    } else if (*(unsigned char *)durq == 'c') {
		comnotes_2.nobar1 = TRUE_;
		getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
		goto L31;
	    } else if (*(unsigned char *)durq == 'r') {

/*  "rename" can be set on or off. */

		getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
		comnvi_1.rename = *(unsigned char *)durq == '+';
		getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
		goto L31;
	    } else if (*(unsigned char *)durq == 'n') {

/*  Change # of voices.  Input ninow, iiorig(1...ninow).  Will use names, */
/*  staves per inst. and clefs  corr. to iiorig in original list of instruments. */

		nvold = all_1.nv;
		all_1.nv = 0;
		comnvi_1.rename = TRUE_;
		getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
		comnotes_2.ninow = *(unsigned char *)durq - 48;
		iiv = 0;
		i__1 = comnotes_2.ninow;
		for (iinow = 1; iinow <= i__1; ++iinow) {
		    getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (
			    ftnlen)1);
		    comnvi_1.iiorig[iinow - 1] = *(unsigned char *)durq - 48;
		    comnvi_1.nspern[iinow - 1] = comnvi_1.nsperi[
			    comnvi_1.iiorig[iinow - 1] - 1];
		    all_1.nv += comnvi_1.nspern[iinow - 1];
		    *(unsigned char *)&all_1.sepsymq[iiv + comnvi_1.nspern[
			    iinow - 1] - 1] = '&';
		    if (comnvi_1.nspern[iinow - 1] > 1) {
			i__2 = comnvi_1.nspern[iinow - 1] - 1;
			for (iis = 1; iis <= i__2; ++iis) {
			    *(unsigned char *)&all_1.sepsymq[iiv + iis - 1] = 
				    '|';
/* L64: */
			}
			iiv += comnvi_1.nspern[iinow - 1];
		    }
/* L63: */
		}
		if (comlast_1.islast) {
		    s_wsfe(&io___700);
/* Writing concatenation */
		    i__4[0] = 1, a__1[0] = all_1.sq;
		    i__4[1] = 7, a__1[1] = "newnoi{";
		    i__1 = comnotes_2.ninow + 48;
		    chax_(ch__1, (ftnlen)1, &i__1);
		    i__4[2] = 1, a__1[2] = ch__1;
		    i__4[3] = 2, a__1[3] = "}%";
		    s_cat(ch__2, a__1, i__4, &c__4, (ftnlen)11);
		    do_fio(&c__1, ch__2, (ftnlen)11);
		    e_wsfe();
		}
		if (all_1.nv == 1 && nvold > 1) {
		    if (comlast_1.islast) {
			s_wsfe(&io___701);
/* Writing concatenation */
			i__5[0] = 1, a__2[0] = all_1.sq;
			i__5[1] = 11, a__2[1] = "nostartrule";
			s_cat(ch__3, a__2, i__5, &c__2, (ftnlen)12);
			do_fio(&c__1, ch__3, (ftnlen)12);
			e_wsfe();
		    }
		} else if (all_1.nv > 1 && nvold == 1) {
		    if (comlast_1.islast) {
			s_wsfe(&io___702);
/* Writing concatenation */
			i__5[0] = 1, a__2[0] = all_1.sq;
			i__5[1] = 9, a__2[1] = "startrule";
			s_cat(ch__4, a__2, i__5, &c__2, (ftnlen)10);
			do_fio(&c__1, ch__4, (ftnlen)10);
			e_wsfe();
		    }
		}
		iiv = 0;
		i__1 = comnotes_2.ninow;
		for (iinow = 1; iinow <= i__1; ++iinow) {
		    i__2 = comnvi_1.nspern[iinow - 1];
		    for (iis = 1; iis <= i__2; ++iis) {
			++iiv;

/*  May not really need to re-enter clefs, but it's easier to program since */
/*  clef names are not saved but are needed in newvoice to set ncmidcc. */

			getchar_(lineq, &all_1.iccount, clefq, (ftnlen)128, (
				ftnlen)1);
			newvoice_(&iiv, clefq, &c_true, (ftnlen)1);
			if (comnvi_1.nspern[iinow - 1] == 1) {
			    i__3 = numclef_(clefq, (ftnlen)1) + 48;
			    chax_(ch__1, (ftnlen)1, &i__3);
			    s_copy(hdlndq, ch__1, (ftnlen)59, (ftnlen)1);
			    lclf = 1;
			} else if (iis == 1) {
/* Writing concatenation */
			    i__5[0] = 1, a__2[0] = "{";
			    i__3 = numclef_(clefq, (ftnlen)1) + 48;
			    chax_(ch__1, (ftnlen)1, &i__3);
			    i__5[1] = 1, a__2[1] = ch__1;
			    s_cat(hdlndq, a__2, i__5, &c__2, (ftnlen)59);
			    lclf = 2;
			} else if (iis < comnvi_1.nspern[iinow - 1]) {
/* Writing concatenation */
			    i__5[0] = lclf, a__2[0] = hdlndq;
			    i__3 = numclef_(clefq, (ftnlen)1) + 48;
			    chax_(ch__1, (ftnlen)1, &i__3);
			    i__5[1] = 1, a__2[1] = ch__1;
			    s_cat(hdlndq, a__2, i__5, &c__2, (ftnlen)59);
			    ++lclf;
			} else {
/* Writing concatenation */
			    i__6[0] = lclf, a__3[0] = hdlndq;
			    i__3 = numclef_(clefq, (ftnlen)1) + 48;
			    chax_(ch__1, (ftnlen)1, &i__3);
			    i__6[1] = 1, a__3[1] = ch__1;
			    i__6[2] = 1, a__3[2] = "}";
			    s_cat(hdlndq, a__3, i__6, &c__3, (ftnlen)59);
			    lclf += 2;
			}
/* L61: */
		    }

/*  setstaffs & setclef go by instrument, not voice */

		    if (comlast_1.islast) {
			if (iinow < 10) {
			    s_wsfe(&io___706);
/* Writing concatenation */
			    i__7[0] = 1, a__4[0] = all_1.sq;
			    i__7[1] = 9, a__4[1] = "setstaffs";
			    i__2 = iinow + 48;
			    chax_(ch__1, (ftnlen)1, &i__2);
			    i__7[2] = 1, a__4[2] = ch__1;
			    i__3 = comnvi_1.nspern[iinow - 1] + 48;
			    chax_(ch__6, (ftnlen)1, &i__3);
			    i__7[3] = 1, a__4[3] = ch__6;
			    i__7[4] = 1, a__4[4] = "%";
			    s_cat(ch__5, a__4, i__7, &c__5, (ftnlen)13);
			    do_fio(&c__1, ch__5, (ftnlen)13);
			    e_wsfe();
			    s_wsfe(&io___707);
/* Writing concatenation */
			    i__7[0] = 1, a__4[0] = all_1.sq;
			    i__7[1] = 7, a__4[1] = "setclef";
			    i__2 = iinow + 48;
			    chax_(ch__1, (ftnlen)1, &i__2);
			    i__7[2] = 1, a__4[2] = ch__1;
			    i__7[3] = lclf, a__4[3] = hdlndq;
			    i__7[4] = 1, a__4[4] = "%";
			    s_cat(ch__7, a__4, i__7, &c__5, (ftnlen)69);
			    do_fio(&c__1, ch__7, lclf + 10);
			    e_wsfe();
			} else {
			    s_wsfe(&io___708);
/* Writing concatenation */
			    i__5[0] = 1, a__2[0] = all_1.sq;
			    i__5[1] = 10, a__2[1] = "setstaffs{";
			    s_cat(ch__2, a__2, i__5, &c__2, (ftnlen)11);
			    do_fio(&c__1, ch__2, (ftnlen)11);
			    do_fio(&c__1, (char *)&iinow, (ftnlen)sizeof(
				    integer));
/* Writing concatenation */
			    i__6[0] = 1, a__3[0] = "}";
			    i__2 = comnvi_1.nspern[iinow - 1] + 48;
			    chax_(ch__1, (ftnlen)1, &i__2);
			    i__6[1] = 1, a__3[1] = ch__1;
			    i__6[2] = 1, a__3[2] = "%";
			    s_cat(ch__8, a__3, i__6, &c__3, (ftnlen)3);
			    do_fio(&c__1, ch__8, (ftnlen)3);
			    e_wsfe();
			    s_wsfe(&io___709);
/* Writing concatenation */
			    i__5[0] = 1, a__2[0] = all_1.sq;
			    i__5[1] = 8, a__2[1] = "setclef{";
			    s_cat(ch__9, a__2, i__5, &c__2, (ftnlen)9);
			    do_fio(&c__1, ch__9, (ftnlen)9);
			    do_fio(&c__1, (char *)&iinow, (ftnlen)sizeof(
				    integer));
/* Writing concatenation */
			    i__6[0] = 1, a__3[0] = "}";
			    i__6[1] = lclf, a__3[1] = hdlndq;
			    i__6[2] = 1, a__3[2] = "%";
			    s_cat(ch__10, a__3, i__6, &c__3, (ftnlen)61);
			    do_fio(&c__1, ch__10, lclf + 2);
			    e_wsfe();
			}
		    }
/* L60: */
		}

/*  Loop back up, this may not be last option in M.  Note flow out if durq=' ' */

		getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
		goto L31;
	    }

/*  Write instrument names */

	    if (! comnvi_1.rename) {
		i__1 = comnotes_2.ninow;
		for (iinst = 1; iinst <= i__1; ++iinst) {
		    if (comlast_1.islast) {
			s_wsfe(&io___711);
/* Writing concatenation */
			i__5[0] = 1, a__2[0] = all_1.sq;
			i__5[1] = 7, a__2[1] = "setname";
			s_cat(ch__11, a__2, i__5, &c__2, (ftnlen)8);
			do_fio(&c__1, ch__11, (ftnlen)8);
			do_fio(&c__1, (char *)&iinst, (ftnlen)sizeof(integer))
				;
			do_fio(&c__1, "{}%", (ftnlen)3);
			e_wsfe();
		    }
/* L62: */
		}
	    } else {
		i__1 = comnotes_2.ninow;
		for (iinst = 1; iinst <= i__1; ++iinst) {
		    if (comlast_1.islast) {
			s_wsfe(&io___712);
/* Writing concatenation */
			i__5[0] = 1, a__2[0] = all_1.sq;
			i__5[1] = 7, a__2[1] = "setname";
			s_cat(ch__11, a__2, i__5, &c__2, (ftnlen)8);
			do_fio(&c__1, ch__11, (ftnlen)8);
			do_fio(&c__1, (char *)&iinst, (ftnlen)sizeof(integer))
				;
/* Writing concatenation */
			i__6[0] = 1, a__3[0] = "{";
			i__6[1] = comtop_1.lnam[comnvi_1.iiorig[iinst - 1] - 
				1], a__3[1] = comtop_1.inameq + (
				comnvi_1.iiorig[iinst - 1] - 1) * 79;
			i__6[2] = 2, a__3[2] = "}%";
			s_cat(ch__12, a__3, i__6, &c__3, (ftnlen)82);
			do_fio(&c__1, ch__12, comtop_1.lnam[comnvi_1.iiorig[
				iinst - 1] - 1] + 3);
			e_wsfe();
		    }
/* L65: */
		}
		comnvi_1.rename = FALSE_;
	    }
	}
    } else if (*(unsigned char *)charq == '|') {

/*  End of bar symbol.  Check about end of bar hardspace. */

	if (bit_test(all_1.iornq[commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 1] 
		+ 1) * 15 - 1],26)) {

/*  There was a hardspace followed by a bar line.  Remove it from the hardspace */
/*  list, store with shifts instead, set special bit.  Need to repeat this code */
/*  at '/'. */

	    all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] 
		    = bit_set(all_1.irest[commvl_1.ivx + all_1.nnl[
		    commvl_1.ivx - 1] * 15 - 16],18);
	    ++comudsp_1.nudoff[commvl_1.ivx - 1];
	    comudsp_1.udoff[commvl_1.ivx + comudsp_1.nudoff[commvl_1.ivx - 1] 
		    * 15 - 16] = comudsp_1.udsp[comudsp_1.nudsp - 1];
	    --comudsp_1.nudsp;
	    all_1.iornq[commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 1] + 1) * 15 
		    - 1] = bit_clear(all_1.iornq[commvl_1.ivx + (all_1.nnl[
		    commvl_1.ivx - 1] + 1) * 15 - 1],26);
	}
    } else if (i_indx("wS", charq, (ftnlen)2, (ftnlen)1) > 0) {

/*  Width symbol or new nsyst.  Read past (until blank) */

L4:
	getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
	if (*(unsigned char *)durq != ' ') {
	    goto L4;
	}
    } else if (*(unsigned char *)charq == 'l') {

/*  Lower string.  Only OK if at start of block */
/*  Check whether at beginning of a block */

	if (all_1.iv != 1 || all_1.nnl[0] != 0) {
	    s_wsle(&io___713);
	    do_lio(&c__9, &c__1, "You entered \"l\" not at beginning of block"
		    , (ftnlen)41);
	    e_wsle();
	    s_stop("", (ftnlen)0);
	}

/*  Set flag for lower string & read it in */

	comhead_1.lower = TRUE_;
	getbuf_(comhead_1.lowerq, (ftnlen)80);
	all_1.iccount = 128;
    } else if (*(unsigned char *)charq == 'm') {

/*  Meter change.  Only allow at beginning of block. */
/*    mtrnuml, mtrdenl (logical) and p (printable) will be input. */
/*    mtrnuml=0 initially. (In common) */

/*  Check whether at beginning of a block */

	if (all_1.iv != 1 || all_1.nnl[0] != 0) {
	    s_wsle(&io___714);
	    do_lio(&c__9, &c__1, "You entered \"m\" not at beginning of block"
		    , (ftnlen)41);
	    e_wsle();
	    s_stop("", (ftnlen)0);
	}
	readmeter_(lineq, &all_1.iccount, &all_1.mtrnuml, &all_1.mtrdenl, (
		ftnlen)128);
	readmeter_(lineq, &all_1.iccount, &all_1.mtrnmp, &all_1.mtrdnp, (
		ftnlen)128);
	lenbeat = ifnodur_(&all_1.mtrdenl, "x", (ftnlen)1);
	if (all_1.mtrdenl == 2) {
	    lenbeat = 16;
	}
	all_1.lenbar = all_1.mtrnuml * lenbeat;
	if (all_1.mtrdenl == 2) {
	    all_1.lenbar <<= 1;
	}
	all_1.lenb1 = all_1.lenbar;
	all_1.lenb0 = 0;
	if (commidi_1.ismidi) {
	    midievent_("m", &all_1.mtrnuml, &all_1.mtrdenl, (ftnlen)1);
	}
    } else if (*(unsigned char *)charq == 'C') {

/*  Clef change on next note.  Set bits 11-15.  Won't allow in 2nd line of music. */

	if (all_1.nnl[all_1.iv - 1] > 0) {
	    ++comcc_1.ncc[all_1.iv - 1];
	}
	comcc_1.tcc[all_1.iv + comcc_1.ncc[all_1.iv - 1] * 15 - 16] = (real) 
		all_1.itsofar[all_1.iv - 1];
	isl = bit_set(all_1.islur[all_1.iv + (all_1.nnl[all_1.iv - 1] + 1) * 
		15 - 16],11);
	getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);

/*  Store clef number, or 7 if clef number = 9 (French violin clef) */

/* Computing MIN */
	i__1 = numclef_(durq, (ftnlen)1);
	isl |= min(i__1,7) << 12;
/* c        if (durq .ne. 'f') then */
/*        if (index('f7',durq) .eq. 0) then */
/*          ncmidcc(iv,ncc(iv)) = 35-2*iand(7,ishft(isl,-12)) */
/*        else */
/* c */
/* c  French violin clef */
/* c */
/*          ncmidcc(iv,ncc(iv)) = 37 */
/*        end if */
	comcc_1.ncmidcc[all_1.iv + comcc_1.ncc[all_1.iv - 1] * 15 - 16] = 
		ncmidf_(durq, (ftnlen)1);

/*  Set marker on note with lowest voice # starting at same time. */

	if (all_1.iv == 1) {
	    isl = bit_set(isl,15);
	} else {
	    i__1 = all_1.iv;
	    for (iiv = 1; iiv <= i__1; ++iiv) {
		nnliiv = all_1.nnl[iiv - 1];
		if (iiv == all_1.iv) {
		    ++nnliiv;
		}
		itother = 0;
		i__2 = nnliiv;
		for (iip = 1; iip <= i__2; ++iip) {
		    if (itother < all_1.itsofar[all_1.iv - 1]) {
			itother += all_1.nodur[iiv + iip * 15 - 16];
			goto L14;
		    } else if (itother == all_1.itsofar[all_1.iv - 1]) {
			all_1.islur[iiv + iip * 15 - 16] = bit_set(
				all_1.islur[iiv + iip * 15 - 16],15);
			goto L15;
		    }
L14:
		    ;
		}
/* L13: */
	    }
L15:
	    ;
	}
/*       islur(iv,nnl(iv)+1) = isl */

/*  Need 'or' since may have set bit 15 in the above loop */

	all_1.islur[all_1.iv + (all_1.nnl[all_1.iv - 1] + 1) * 15 - 16] = isl 
		| all_1.islur[all_1.iv + (all_1.nnl[all_1.iv - 1] + 1) * 15 - 
		16];
    } else if (*(unsigned char *)charq == 'R') {

/*  Repeats.  set bits 5, 6, and/or 8 of islur(1,ip+1) */

L10:
	getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);

/*  Save designator in case it's a terminal Rr or Rd */

	if (*(unsigned char *)durq == 'l') {
	    all_1.islur[(all_1.nnl[0] + 1) * 15 - 15] = bit_set(all_1.islur[(
		    all_1.nnl[0] + 1) * 15 - 15],5);
	    goto L10;
	} else if (i_indx("rdDb", durq, (ftnlen)4, (ftnlen)1) > 0) {
	    if (*(unsigned char *)durq == 'r') {
		all_1.islur[(all_1.nnl[0] + 1) * 15 - 15] = bit_set(
			all_1.islur[(all_1.nnl[0] + 1) * 15 - 15],6);
	    } else if (*(unsigned char *)durq == 'd') {
		all_1.islur[(all_1.nnl[0] + 1) * 15 - 15] = bit_set(
			all_1.islur[(all_1.nnl[0] + 1) * 15 - 15],8);
	    } else if (*(unsigned char *)durq == 'D') {
		all_1.islur[(all_1.nnl[0] + 1) * 15 - 15] = bit_set(
			all_1.islur[(all_1.nnl[0] + 1) * 15 - 15],26);
	    } else if (*(unsigned char *)durq == 'b') {
		all_1.islur[(all_1.nnl[0] + 1) * 15 - 15] = bit_set(
			all_1.islur[(all_1.nnl[0] + 1) * 15 - 15],25);
	    }
	    comget_1.rptprev = TRUE_;
	    *(unsigned char *)comget_1.rptfq1 = *(unsigned char *)durq;
	    goto L10;
	}
    } else if (*(unsigned char *)charq == 'V') {

/*  Ending */

	nnnl = all_1.nnl[0] + 1;
	lvoltxt = 0;
L11:
	getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
	if (*(unsigned char *)durq == 'b' || *(unsigned char *)durq == 'x') {

/*  End Volta, set bit9, and bit10 on if 'b' (end w/ box) */

	    all_1.islur[nnnl * 15 - 15] = bit_set(all_1.islur[nnnl * 15 - 15],
		    9);
	    if (*(unsigned char *)durq == 'b') {
		all_1.islur[nnnl * 15 - 15] = bit_set(all_1.islur[nnnl * 15 - 
			15],10);
	    }
	    goto L11;
	} else if (*(unsigned char *)durq != ' ') {

/*  Start volta; Get text */

	    if (lvoltxt == 0) {

/*  First character for text */

		lvoltxt = 1;
		all_1.islur[nnnl * 15 - 15] = bit_set(all_1.islur[nnnl * 15 - 
			15],7);
		++comgrace_1.nvolt;
		s_copy(comgrace_1.voltxtq + (comgrace_1.nvolt - 1) * 10, durq,
			 (ftnlen)10, (ftnlen)1);
	    } else {
/* Writing concatenation */
		i__5[0] = lvoltxt, a__2[0] = comgrace_1.voltxtq + (
			comgrace_1.nvolt - 1) * 10;
		i__5[1] = 1, a__2[1] = durq;
		s_cat(comgrace_1.voltxtq + (comgrace_1.nvolt - 1) * 10, a__2, 
			i__5, &c__2, (ftnlen)10);
		++lvoltxt;
	    }
	    goto L11;
	}
    } else if (*(unsigned char *)charq == 'B') {
	combc_1.bcspec = ! combc_1.bcspec;
    } else if (*(unsigned char *)charq == 'P') {

/*  Page numbers.  Print stuff right now. */

	npg1 = 0;

/*  Will use ltopnam to signal whether there's a centered heading */

	ltopnam = 0;
	ipg1r = 0;
L16:
	getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
	if (*(unsigned char *)durq >= 48 && *(unsigned char *)durq <= 57) {
	    npg1 = npg1 * 10 + *(unsigned char *)durq - 48;
	    goto L16;
	} else if (*(unsigned char *)durq == 'l') {
	    if (npg1 == 0 || npg1 % 2 == 1) {
		ipg1r = 1;
	    }
	    goto L16;
	} else if (*(unsigned char *)durq == 'r') {
	    if (npg1 > 0 && npg1 % 2 == 0) {
		ipg1r = 1;
	    }
	    goto L16;
	} else if (*(unsigned char *)durq == 'c') {

/*  Top-centered name.  Assume this is last option.  Read the name. */
/*  May surround name in double quotes (to allow blanks). */

	    getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (*(unsigned char *)durq == ' ') {
		ltopnam = lenstr_(comtrans_1.cheadq, &c__60, (ftnlen)60);
	    } else {
		namstrt = all_1.iccount;
		if (*(unsigned char *)durq == '"') {

/*  Using quote delimiters. */

		    quoted = TRUE_;
		    ++namstrt;
		} else {
		    quoted = FALSE_;
		}
		for (all_1.iccount = namstrt + 1; all_1.iccount <= 128; 
			++all_1.iccount) {
		    if (quoted && *(unsigned char *)&lineq[all_1.iccount - 1] 
			    == '"' || ! quoted && *(unsigned char *)&lineq[
			    all_1.iccount - 1] == ' ') {
			goto L36;
		    }

/*  On exit, iccount is OK, and name is in (namstrt:iccount-1) */

/* L35: */
		}
		s_wsle(&io___727);
		do_lio(&c__9, &c__1, "Awww, cmon, should not be here.", (
			ftnlen)31);
		e_wsle();
		s_stop("", (ftnlen)0);
L36:
		ltopnam = all_1.iccount - namstrt;
		s_copy(comtrans_1.cheadq, lineq + (namstrt - 1), (ftnlen)60, 
			all_1.iccount - 1 - (namstrt - 1));
	    }
	}

/*  Done getting data, now assemble the command */

	if (npg1 == 0) {
	    npg1 = 1;
	}
/* Writing concatenation */
	i__8[0] = 1, a__5[0] = all_1.sq;
	i__8[1] = 3, a__5[1] = "def";
	i__8[2] = 1, a__5[2] = all_1.sq;
	i__8[3] = 11, a__5[3] = "atnextline{";
	i__8[4] = 1, a__5[4] = all_1.sq;
	i__8[5] = 10, a__5[5] = "toppageno{";
	s_cat(hdlndq, a__5, i__8, &c__6, (ftnlen)59);
	if (npg1 < 10) {

/*  Note we are overwriting the last "{" */

	    s_wsfi(&io___728);
	    do_fio(&c__1, (char *)&npg1, (ftnlen)sizeof(integer));
	    e_wsfi();
	    lhead = 27;
/*        else */
	} else if (npg1 < 100) {
	    s_wsfi(&io___730);
	    do_fio(&c__1, (char *)&npg1, (ftnlen)sizeof(integer));
	    do_fio(&c__1, "}", (ftnlen)1);
	    e_wsfi();
	    lhead = 30;
	} else {
	    s_wsfi(&io___731);
	    do_fio(&c__1, (char *)&npg1, (ftnlen)sizeof(integer));
	    do_fio(&c__1, "}", (ftnlen)1);
	    e_wsfi();
	    lhead = 31;
	}
/* Writing concatenation */
	i__6[0] = lhead, a__3[0] = hdlndq;
	i__1 = ipg1r + 48;
	chax_(ch__1, (ftnlen)1, &i__1);
	i__6[1] = 1, a__3[1] = ch__1;
	i__6[2] = 1, a__3[2] = "{";
	s_cat(hdlndq, a__3, i__6, &c__3, (ftnlen)59);
	lhead += 2;
	if (ltopnam == 0) {
	    if (comlast_1.islast) {
		s_wsfe(&io___732);
/* Writing concatenation */
		i__5[0] = lhead, a__2[0] = hdlndq;
		i__5[1] = 3, a__2[1] = "}}%";
		s_cat(ch__13, a__2, i__5, &c__2, (ftnlen)62);
		do_fio(&c__1, ch__13, lhead + 3);
		e_wsfe();
	    }
	} else {
	    if (comlast_1.islast) {
		s_wsfe(&io___733);
/* Writing concatenation */
		i__6[0] = lhead, a__3[0] = hdlndq;
		i__6[1] = ltopnam, a__3[1] = comtrans_1.cheadq;
		i__6[2] = 3, a__3[2] = "}}%";
		s_cat(ch__14, a__3, i__6, &c__3, (ftnlen)122);
		do_fio(&c__1, ch__14, lhead + ltopnam + 3);
		e_wsfe();
	    }
	}
    } else if (*(unsigned char *)charq == 'W') {

/*  Just get two more characters (.n), they were used in pmxa */

	getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
	getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
    } else if (*(unsigned char *)charq == 'T') {
	comtitl_1.headlog = TRUE_;
	comtitl_1.inhead = 0;
	getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
	if (*(unsigned char *)durq == 'i') {
	    getbuf_(comtitl_1.instrq, (ftnlen)60);

/*  A kluge for parts from separate score file for later movements. */

	    if (*(unsigned char *)comtitl_1.instrq == ' ') {
		comtitl_1.headlog = FALSE_;
	    }
	    s_copy(comtrans_1.cheadq, comtitl_1.instrq, (ftnlen)60, (ftnlen)
		    60);
	} else if (*(unsigned char *)durq == 't') {
	    getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);

/*  Optionally can include extra vertical \internotes above inbothd */

	    if (i_indx("-+0123456789", durq, (ftnlen)12, (ftnlen)1) > 0) {
		ipm = 1;
		if (i_indx("+-", durq, (ftnlen)2, (ftnlen)1) > 0) {

/*  Don't trust readnum to round this negative integer properly */

		    ++all_1.iccount;
		    if (*(unsigned char *)durq == '-') {
			ipm = -1;
		    }
		}
		readnum_(lineq, &all_1.iccount, durq, &fnum, (ftnlen)128, (
			ftnlen)1);
		comtitl_1.inhead = ipm * i_nint(&fnum);
	    }
	    getbuf_(comtitl_1.titleq, (ftnlen)60);
	} else {
	    getbuf_(comtitl_1.compoq, (ftnlen)60);
	}
	comtitl_1.inhead += cominbot_1.inbothd;
	all_1.iccount = 128;
    } else if (*(unsigned char *)charq == 'A') {

/*  Accidental handling etc. */

L27:
	getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
	if (*(unsigned char *)durq == 'r') {
	    if (comlast_1.islast) {
		commidi_1.relacc = TRUE_;
		s_wsfe(&io___734);
/* Writing concatenation */
		i__5[0] = 1, a__2[0] = all_1.sq;
		i__5[1] = 14, a__2[1] = "relativeaccid%";
		s_cat(ch__15, a__2, i__5, &c__2, (ftnlen)15);
		do_fio(&c__1, ch__15, (ftnlen)15);
		e_wsfe();
	    }
	    goto L27;
	} else if (*(unsigned char *)durq == 's') {
	    spfacs_1.bacfac = (float)1e6;
	    goto L27;
	} else if (*(unsigned char *)durq == 'b') {
	    if (comlast_1.islast) {
		s_wsfe(&io___735);
/* Writing concatenation */
		i__5[0] = 1, a__2[0] = all_1.sq;
		i__5[1] = 9, a__2[1] = "bigaccid%";
		s_cat(ch__4, a__2, i__5, &c__2, (ftnlen)10);
		do_fio(&c__1, ch__4, (ftnlen)10);
		e_wsfe();
	    }
	    spfacs_1.accfac = spfacs_1.bacfac;
	    goto L27;
	} else if (*(unsigned char *)durq == 'a') {
	    getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
	    readnum_(lineq, &all_1.iccount, durq, &fnum, (ftnlen)128, (ftnlen)
		    1);
	    --all_1.iccount;
	    goto L27;
	} else if (*(unsigned char *)durq == 'i') {
	    getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
	    readnum_(lineq, &all_1.iccount, durq, &tintstf, (ftnlen)128, (
		    ftnlen)1);
	    if (! all_1.firstgulp) {
		comget_1.fintstf = tintstf;
	    }

/*  Local corrections for first page were handled by pmxa */

	    --all_1.iccount;
	    goto L27;
	} else if (*(unsigned char *)durq == 'I') {
	    getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
	    readnum_(lineq, &all_1.iccount, durq, &comget_1.gintstf, (ftnlen)
		    128, (ftnlen)1);
	    --all_1.iccount;
	    goto L27;
	} else if (*(unsigned char *)durq == 'd') {
	    comarp_1.lowdot = TRUE_;
	    goto L27;
	} else if (*(unsigned char *)durq == 'o') {
	    goto L27;
	}
    } else if (*(unsigned char *)charq == 'K') {
	getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
	num1 = 44 - *(unsigned char *)durq;
	++all_1.iccount;
	readnum_(lineq, &all_1.iccount, durq, &fnum, (ftnlen)128, (ftnlen)1);
	num1 *= i_nint(&fnum);

/*  On exit, durq='+','-'.  But only need isig if after start, else done in pmxa */

	++all_1.iccount;
	readnum_(lineq, &all_1.iccount, charq, &fnum, (ftnlen)128, (ftnlen)1);
	if (num1 == 0) {

/*  Key change, not transposition. */

	    all_1.ipl[commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 1] + 1) * 15 - 
		    16] = bit_set(all_1.ipl[commvl_1.ivx + (all_1.nnl[
		    commvl_1.ivx - 1] + 1) * 15 - 16],28);
	    comtop_1.lastisig = comtop_1.isig;
	    comtop_1.isig = i_nint(&fnum);
	    if (*(unsigned char *)durq == '-') {
		comtop_1.isig = -comtop_1.isig;
	    }
	    comtop_1.isig += comtop_1.idsig;
	    if (commidi_1.ismidi) {
		midievent_("k", &comtop_1.isig, &c__0, (ftnlen)1);
	    }
	} else {

/*  num1 .ne. 0, so transposition, so must be at beginning.  isig came with K... */
/*  but was passed to pmxb through pmxtex.dat.  isig0 comes from setup data */
/*  (signature before transposition).  idsig must be added to future key changes. */

	    comtrans_1.ntrans = num1;
	    comtop_1.idsig = comtop_1.isig - comtop_1.isig0;
	}
    } else if (*(unsigned char *)charq == '/') {
	if (bit_test(all_1.iornq[commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 1] 
		+ 1) * 15 - 1],26)) {

/*  There was a hardspace followed by end of block.  Remove it from the hardspace */
/*  list, store with shifts instead, set special bit.  This code also at '|' */

	    all_1.irest[commvl_1.ivx + all_1.nnl[commvl_1.ivx - 1] * 15 - 16] 
		    = bit_set(all_1.irest[commvl_1.ivx + all_1.nnl[
		    commvl_1.ivx - 1] * 15 - 16],18);
	    ++comudsp_1.nudoff[commvl_1.ivx - 1];
	    comudsp_1.udoff[commvl_1.ivx + comudsp_1.nudoff[commvl_1.ivx - 1] 
		    * 15 - 16] = comudsp_1.udsp[comudsp_1.nudsp - 1];
	    --comudsp_1.nudsp;
	    all_1.iornq[commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 1] + 1) * 15 
		    - 1] = bit_clear(all_1.iornq[commvl_1.ivx + (all_1.nnl[
		    commvl_1.ivx - 1] + 1) * 15 - 1],26);
	}
	getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);

/*  Save ending note level: */

	if (commvl_1.ivx <= all_1.nv) {

/*  This is the first line of music on this staff.  If previous block had only 1 */
/*  voice, save last pitch from line 1 of prev. block to line 2, in case a */
/*  2nd line is started just below */

	    if (! comnotes_2.was2[all_1.iv - 1]) {
		comnotes_2.ndlev[all_1.iv + 14] = comnotes_2.ndlev[all_1.iv - 
			1];
	    }
	    comnotes_2.was2[all_1.iv - 1] = FALSE_;
	    comnotes_2.ndlev[all_1.iv - 1] = comnotes_2.lastlev;
	} else {

/*  This is the 2nd line of music on this staff. */

	    comnotes_2.was2[all_1.iv - 1] = TRUE_;
	    comnotes_2.ndlev[all_1.iv + 14] = comnotes_2.lastlev;
	}
	if (*(unsigned char *)durq == ' ' && all_1.iv == all_1.nv) {

/*  End of input block */

	    *loop = FALSE_;
	} else {

/*  Start a new line of music */

	    if (all_1.lenb0 != 0 && all_1.firstgulp) {
		all_1.lenbar = all_1.lenb0;
	    }
	    all_1.nbars = 0;
	    if (*(unsigned char *)durq == ' ') {

/*  New line of music is on next staff */

		++all_1.iv;
		commvl_1.ivx = all_1.iv;
	    } else {

/*  durq must be 2nd '/'.  New line of music is on same staff.  Set up for it */

		commvl_1.ivx = all_1.nv + 1;
		i__1 = all_1.nv;
		for (iiv = 1; iiv <= i__1; ++iiv) {
		    if (commvl_1.nvmx[iiv - 1] == 2) {
			++commvl_1.ivx;
		    }
/* L23: */
		}
		commvl_1.nvmx[all_1.iv - 1] = 2;
		commvl_1.ivmx[all_1.iv + 14] = commvl_1.ivx;
		all_1.itsofar[commvl_1.ivx - 1] = 0;
		all_1.nnl[commvl_1.ivx - 1] = 0;
		comfb_1.nfb[commvl_1.ivx - 1] = 0;
		comudsp_1.nudoff[commvl_1.ivx - 1] = 0;
		comcc_1.ndotmv[commvl_1.ivx - 1] = 0;
		for (j = 1; j <= 200; ++j) {
		    all_1.irest[commvl_1.ivx + j * 15 - 16] = 0;
		    all_1.islur[commvl_1.ivx + j * 15 - 16] = 0;
		    all_1.nacc[commvl_1.ivx + j * 15 - 16] = 0;
		    all_1.iornq[commvl_1.ivx + j * 15 - 1] = 0;
		    all_1.ipl[commvl_1.ivx + j * 15 - 16] = 0;
/* L24: */
		}

/*  Go back and lower the rests in voice "a" that don't have over-ridden heights */

		i__1 = all_1.nnl[all_1.iv - 1];
		for (j = 1; j <= i__1; ++j) {
		    if (bit_test(all_1.irest[all_1.iv + j * 15 - 16],0) && 
			    all_1.nolev[all_1.iv + j * 15 - 16] == 0) {
			all_1.nolev[all_1.iv + j * 15 - 16] = -4;
		    }
/* L26: */
		}
	    }
	}
	all_1.iccount = 128;
    } else if (*(unsigned char *)charq == 'X') {

/*  3rd arg is only for termination of group shifts.  Use "max" to avoid zero index, */
/*    which only happens for normal X at block start, and we took special measures to */
/*    keep group shifts for crossing block boundaries. */

/* Computing MAX */
	i__1 = 1, i__2 = all_1.nnl[commvl_1.ivx - 1];
	getx_(lineq, &all_1.iccount, &all_1.irest[commvl_1.ivx + max(i__1,
		i__2) * 15 - 16], &comnotes_2.shifton, &comask_1.wheadpt, &
		all_1.iornq[commvl_1.ivx + (all_1.nnl[commvl_1.ivx - 1] + 1) *
		 15 - 1], &commvl_1.ivx, &all_1.irest[commvl_1.ivx + (
		all_1.nnl[commvl_1.ivx - 1] + 1) * 15 - 16], &all_1.itsofar[
		commvl_1.ivx - 1], &c__0, &c__0, &c__0, " ", (ftnlen)128, (
		ftnlen)1);
    } else if (*(unsigned char *)charq == 'I') {

/*  Midi controls. */

	getmidi_(&all_1.nv, lineq, &all_1.iccount, &ibarcnt, &ibaroff, &
		all_1.nbars, &all_1.lenbar, &all_1.mtrdenl, &c_false, (ftnlen)
		128);
    } else if (*(unsigned char *)charq == 'M') {

/*  Macro action */

	getchar_(lineq, &all_1.iccount, charq, (ftnlen)128, (ftnlen)1);
	if (i_indx("RS", charq, (ftnlen)2, (ftnlen)1) > 0) {

/*  Record or save a macro.  Get the number of the macro. */

	    getchar_(lineq, &all_1.iccount, durq, (ftnlen)128, (ftnlen)1);
	    readnum_(lineq, &all_1.iccount, durq, &fnum, (ftnlen)128, (ftnlen)
		    1);
	    commac_1.macnum = i_nint(&fnum);
	    commac_1.macuse = bit_set(commac_1.macuse,commac_1.macnum);
	    if (*(unsigned char *)charq == 'R') {
		mrec1_(lineq, &all_1.iccount, &ndxm, (ftnlen)128);
	    } else {

/*  Save (Record but don't activate) */

L5:
		mrec1_(lineq, &all_1.iccount, &ndxm, (ftnlen)128);
		if (commac_1.mrecord) {
		    getbuf_(lineq, (ftnlen)128);
		    all_1.iccount = 0;
		    goto L5;
		}
		all_1.iccount = all_1.iccount + ndxm + 1;
	    }
	} else if (*(unsigned char *)charq == 'P') {

/*  Playback the macro */

	    getchar_(lineq, &all_1.iccount, charq, (ftnlen)128, (ftnlen)1);
	    readnum_(lineq, &all_1.iccount, durq, &fnum, (ftnlen)128, (ftnlen)
		    1);
	    commac_1.macnum = i_nint(&fnum);
	    commac_1.icchold = all_1.iccount;
	    s_copy(commac_1.lnholdq, lineq, (ftnlen)128, (ftnlen)128);
	    all_1.iccount = 128;
	    c1ommac_1.ilmac = c1ommac_1.il1mac[commac_1.macnum - 1];
	    commac_1.mplay = TRUE_;
	}
    }
    return 0;
} /* getnote_ */

/* Subroutine */ int getchar_(lineq, iccount, charq, lineq_len, charq_len)
char *lineq;
integer *iccount;
char *charq;
ftnlen lineq_len;
ftnlen charq_len;
{
    /* Builtin functions */
    /* Subroutine */ int s_copy();

    /* Local variables */
    static integer ndxm;
    extern /* Subroutine */ int mrec1_(), read10_();


/*  Gets the next character out of lineq*128.  If pointer iccount=128 on entry, */
/*  then reads in a new line.  Resets iccount.  Ends program if no more input. */

    if (*iccount == 128) {
	read10_(lineq, &comget_1.lastchar, (ftnlen)128);
	if (comget_1.lastchar) {
	    return 0;
	}
	if (! commac_1.endmac) {
	    *iccount = 0;
	} else {
	    commac_1.endmac = FALSE_;
	    *iccount = commac_1.icchold;
	    s_copy(lineq, commac_1.lnholdq, (ftnlen)128, (ftnlen)128);
	}
	if (commac_1.mrecord) {
	    mrec1_(lineq, iccount, &ndxm, (ftnlen)128);
	}
    }
    ++(*iccount);
    *(unsigned char *)charq = *(unsigned char *)&lineq[*iccount - 1];
    return 0;
/* L999: */
    comget_1.lastchar = TRUE_;
    return 0;
} /* getchar_ */

integer log2_(n)
integer *n;
{
    /* System generated locals */
    integer ret_val;

    /* Builtin functions */
    double log();

    ret_val = log(*n * (float)1.) / (float).6931472 + (float)1e-4;
    return ret_val;
} /* log2_ */

integer ifnolev_(noq, oct, noq_len)
char *noq;
integer *oct;
ftnlen noq_len;
{
    /* System generated locals */
    integer ret_val;

    ret_val = *oct * 7 + (*(unsigned char *)noq - 92) % 7 + 1 + 
	    comtrans_1.ntrans;
    return ret_val;
} /* ifnolev_ */

integer ifnodur_(idur, dotq, dotq_len)
integer *idur;
char *dotq;
ftnlen dotq_len;
{
    /* System generated locals */
    integer ret_val;

    /* Builtin functions */
    integer s_wsle(), do_lio(), e_wsle();
    /* Subroutine */ int s_stop();

    /* Fortran I/O blocks */
    static cilist io___743 = { 0, 6, 0, 0, 0 };


    if (*idur == 6) {
	ret_val = 1;
    } else if (*idur == 3) {
	ret_val = 2;
    } else if (*idur == 1) {
	ret_val = 4;
    } else if (*idur == 8) {
	ret_val = 8;
    } else if (*idur == 4) {
	ret_val = 16;
    } else if (*idur == 2) {
	ret_val = 32;
    } else if (*idur == 0) {
	ret_val = 64;
    } else if (*idur == 9) {
	ret_val = 128;
    } else if (*idur == 16) {

/*  Only used for denominator of time signatures, not for notes */

	ret_val = 4;
    } else {
	s_wsle(&io___743);
	do_lio(&c__9, &c__1, "You entered an invalid note value", (ftnlen)33);
	e_wsle();
	s_stop("", (ftnlen)0);
    }
    if (*(unsigned char *)dotq == 'd') {
	ret_val = ret_val * 3 / 2;
    }
    return ret_val;
} /* ifnodur_ */

integer ncmidf_(clefq, clefq_len)
char *clefq;
ftnlen clefq_len;
{
    /* System generated locals */
    integer ret_val;

    /* Builtin functions */
    integer i_indx();


/*  Return middle line of a clef */

/*      if (clefq.eq.'t' .or. clefq.eq.'0') then */
/*        ncmidf = 35 */
/*      else if (clefq.eq.'s' .or. clefq.eq.'1') then */
/*        ncmidf = 33 */
/*      else if (clefq.eq.'m' .or. clefq.eq.'2') then */
/*        ncmidf = 31 */
/*      else if (clefq.eq.'a' .or. clefq.eq.'3') then */
/*        ncmidf = 29 */
/*      else if (clefq.eq.'n' .or. clefq.eq.'4') then */
/*        ncmidf = 27 */
/*      else if (clefq.eq.'r' .or. clefq.eq.'5') then */
/*        ncmidf = 25 */
/*      else if (clefq.eq.'f' .or. clefq.eq.'7') then */
/*        ncmidf = 37 */
/*      else */
/*        ncmidf = 23 */
/*      end if */
    ret_val = (i_indx(" b6r5n4a3m2s1t0f7", clefq, (ftnlen)17, (ftnlen)1) / 2 
	    << 1) + 21;
    return ret_val;
} /* ncmidf_ */

/* Subroutine */ int beamstrt_(notexq, lnote, nornb, ihornb, space, squez, ib,
	 notexq_len)
char *notexq;
integer *lnote, *nornb, *ihornb;
real *space, *squez;
integer *ib;
ftnlen notexq_len;
{
    /* System generated locals */
    address a__1[3], a__2[2];
    integer i__1, i__2, i__3[3], i__4[2], i__5;
    real r__1;
    icilist ici__1;

    /* Builtin functions */
    /* Subroutine */ int s_cat();
    integer i_nint(), s_wsfi(), do_fio(), e_wsfi(), pow_ii();
    /* Subroutine */ int s_copy();
    integer lbit_shift();

    /* Local variables */
    static integer ip, ibc, inb, ipb[24], nnb, iud, imp, iup;
    static logical xto;
    static integer ipb1, iadj, icrd;
    static real smed;
    extern doublereal feon_();
    static integer iasl, levc, iorn;
    static real ymin, ybot;
    static integer levx;
    static real xnsk, sumx, sumy;
    extern integer ncmid_();
    static real ybeam;
    static integer ipmid;
    static real bmlev;
    static integer iflop, icrdx, multb, ltemp;
    static char noteq[8], tempq[79];
    extern integer levrn_();
    static integer nlnum;
    extern /* Subroutine */ int notex_();
    static real zmult;
    extern /* Subroutine */ int ntrbbb_();
    static real xnlmid;
    extern /* Subroutine */ int notefq_();
    static integer lnoten;
    extern /* Subroutine */ int setupb_();
    static real xslope;
    extern /* Subroutine */ int putxtn_();
    static integer maxdrop;
    static logical addbrack;
    extern /* Subroutine */ int addblank_();
    static integer nomornlev;

    /* Parameter adjustments */
    --squez;
    --space;
    ihornb -= 16;
    --nornb;

    /* Function Body */
    ibc = all_1.ibmcnt[commvl_1.ivx - 1];
    ipb1 = all_1.ibm1[commvl_1.ivx + ibc * 15 - 16];
    multb = all_1.mult[commvl_1.ivx + ipb1 * 15 - 16];

/*  Move the following into SetupB, since xtup may be embedded and not start */
/*  on same note as beam. */
/*      if (btest(irest(ivx,ipb1),28)) then */

/*  Compute slopes and note offsets from start of beam.  Inside SetupB, set */
/*  eloff = distance from start of xtup to number. */

    if (strtmid_1.ixrest[commvl_1.ivx - 1] == 0) {
	setupb_(comxtup_1.xelsk, &nnb, &sumx, &sumy, ipb, &smed, &
		strtmid_1.ixrest[commvl_1.ivx - 1]);
    }
    *lnote = 0;
    if (bit_test(all_1.irest[commvl_1.ivx + ipb1 * 15 - 16],28) && 
	    strtmid_1.ixrest[commvl_1.ivx - 1] != 2) {
	comxtup_1.vxtup[commvl_1.ivx - 1] = TRUE_;

/*  irest(28)=>Xtup starts on this note.  Set up for xtuplet. */
/*  Number goes on notehead side at middle note (or gap) of xtup, unless that */
/*  puts it in staff, then it flops to stem (or beam) side. */
/*               __          __ */
/*         |    |  |   O    |  | */
/*         O      |    |      O */
/*       |___|    O  |__|     | */

/*  iud   -1     -1    1      1    ...stem direction */
/* iflop   0      1   -1      0    ...direction of flop */
/*  iup   -1      1   -1      1    ...direction of number and bracket */

	iud = 1;
	if (*(unsigned char *)&all_1.ulq[commvl_1.ivx + ibc * 15 - 16] == 'u')
		 {
	    iud = -1;
	}

/*  Get ip#, note level of middle note (or gap) in xtup */

	ipmid = ipb1 + comxtup_1.ntupv[commvl_1.ivx - 1] / 2;
	i__1 = ncmid_(&all_1.iv, &ipmid);
	xnlmid = (real) levrn_(&all_1.nolev[commvl_1.ivx + ipmid * 15 - 16], &
		all_1.irest[commvl_1.ivx + ipmid * 15 - 16], &iud, &i__1, &
		all_1.mult[commvl_1.ivx + ipmid * 15 - 16]);
	if (comxtup_1.ntupv[commvl_1.ivx - 1] % 2 == 0) {
	    if (comxtup_1.ntupv[commvl_1.ivx - 1] % 2 == 0) {
		i__2 = ipmid - 1;
		i__1 = ncmid_(&all_1.iv, &i__2);
		xnlmid = (xnlmid + levrn_(&all_1.nolev[commvl_1.ivx + (ipmid 
			- 1) * 15 - 16], &all_1.irest[commvl_1.ivx + (ipmid - 
			1) * 15 - 16], &iud, &i__1, &all_1.mult[commvl_1.ivx 
			+ (ipmid - 1) * 15 - 16])) / 2;
	    }
	}
	iflop = 0;
	if ((r__1 = xnlmid - ncmid_(&all_1.iv, &ipb1), dabs(r__1)) < (float)
		3.) {
	    iflop = -iud;
	}
	iup = iud + (iflop << 1);
	if (bit_test(all_1.irest[commvl_1.ivx + ipb1 * 15 - 16],14)) {

/*  Alter iud, iflop, iup to flip number/bracket. (Stare at above pic) */

	    iup = -iup;
	    iflop = 0;
	    if (iud * iup < 0) {
		iflop = iup;
	    }
	}

/*  Place xtup number if needed */

	if (! bit_test(all_1.islur[commvl_1.ivx + ipb1 * 15 - 16],31) || 
		multb <= 0) {
	    i__1 = ncmid_(&all_1.iv, &ipb1);
	    putxtn_(&comxtup_1.ntupv[commvl_1.ivx - 1], &iflop, &multb, &iud, 
		    &comask_1.wheadpt, &comask_1.poenom, &comxtup_1.nolev1[
		    commvl_1.ivx - 1], &comxtup_1.islope[commvl_1.ivx - 1], &
		    all_1.slfac, &xnlmid, &all_1.islur[commvl_1.ivx + ipb1 * 
		    15 - 16], lnote, notexq, &i__1, &nlnum, &comxtup_1.eloff[
		    commvl_1.ivx - 1], &iup, &all_1.irest[commvl_1.ivx + ipb1 
		    * 15 - 16], (ftnlen)79);
	}

/*  Why was this here ???????? */

	if (multb <= 0) {

/*  Put in the bracket. scale = stretch factor for bracket if there are asx's */
/*  xnsk = length of the bracket in \noteskips = (\elemskips)/(eon) */

	    r__1 = space[*ib] / squez[*ib];
	    xnsk = (all_1.eskz[commvl_1.ivx + (ipb1 + comxtup_1.ntupv[
		    commvl_1.ivx - 1] - 1) * 15 - 16] - all_1.eskz[
		    commvl_1.ivx + ipb1 * 15 - 16]) / squez[*ib] / feon_(&
		    r__1);
	    if (iup == 1) {
		if (*lnote > 0) {
/* Writing concatenation */
		    i__3[0] = *lnote, a__1[0] = notexq;
		    i__3[1] = 1, a__1[1] = all_1.sq;
		    i__3[2] = 5, a__1[2] = "ovbkt";
		    s_cat(notexq, a__1, i__3, &c__3, (ftnlen)79);
		} else {
/* Writing concatenation */
		    i__4[0] = 1, a__2[0] = all_1.sq;
		    i__4[1] = 5, a__2[1] = "ovbkt";
		    s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
		}
	    } else {
		if (*lnote > 0) {
/* Writing concatenation */
		    i__3[0] = *lnote, a__1[0] = notexq;
		    i__3[1] = 1, a__1[1] = all_1.sq;
		    i__3[2] = 5, a__1[2] = "unbkt";
		    s_cat(notexq, a__1, i__3, &c__3, (ftnlen)79);
		} else {

/*  Introduced 12/5/98, req'd due to possible presence of in-line TeX */

/* Writing concatenation */
		    i__4[0] = 1, a__2[0] = all_1.sq;
		    i__4[1] = 5, a__2[1] = "unbkt";
		    s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
		}
	    }
	    *lnote += 6;
	    if (all_1.iline == 1) {
		smed /= (float)1. - comtop_1.fracindent;
	    }
	    xslope = smed * (float)1.8 * all_1.slfac;
	    comxtup_1.islope[commvl_1.ivx - 1] = i_nint(&xslope);
	    r__1 = smed * comxtup_1.eloff[commvl_1.ivx - 1];
	    comxtup_1.nolev1[commvl_1.ivx - 1] = nlnum - i_nint(&r__1);
	    if (comxtup_1.islope[commvl_1.ivx - 1] == 0) {
		--comxtup_1.nolev1[commvl_1.ivx - 1];
	    }
	    if (iup == 1) {
		comxtup_1.nolev1[commvl_1.ivx - 1] += 4;
	    }
	    i__1 = ncmid_(&all_1.iv, &ipb1);
	    notefq_(noteq, &lnoten, &comxtup_1.nolev1[commvl_1.ivx - 1], &
		    i__1, (ftnlen)8);
	    if (lnoten == 1) {
		addblank_(noteq, &lnoten, (ftnlen)8);
	    }
/* Writing concatenation */
	    i__3[0] = *lnote, a__1[0] = notexq;
	    i__3[1] = lnoten, a__1[1] = noteq;
	    i__3[2] = 1, a__1[2] = "{";
	    s_cat(notexq, a__1, i__3, &c__3, (ftnlen)79);
	    *lnote = *lnote + lnoten + 1;
	    if (xnsk < (float).995) {
		i__1 = *lnote;
		ici__1.icierr = 0;
		ici__1.icirnum = 1;
		ici__1.icirlen = *lnote + 4 - i__1;
		ici__1.iciunit = notexq + i__1;
		ici__1.icifmt = "(i1,f3.2)";
		s_wsfi(&ici__1);
		do_fio(&c__1, (char *)&c__0, (ftnlen)sizeof(integer));
		do_fio(&c__1, (char *)&xnsk, (ftnlen)sizeof(real));
		e_wsfi();
		*lnote += 4;
	    } else if (xnsk < (float)9.995) {
		i__1 = *lnote;
		ici__1.icierr = 0;
		ici__1.icirnum = 1;
		ici__1.icirlen = *lnote + 4 - i__1;
		ici__1.iciunit = notexq + i__1;
		ici__1.icifmt = "(f4.2)";
		s_wsfi(&ici__1);
		do_fio(&c__1, (char *)&xnsk, (ftnlen)sizeof(real));
		e_wsfi();
		*lnote += 4;
	    } else {
		i__1 = *lnote;
		ici__1.icierr = 0;
		ici__1.icirnum = 1;
		ici__1.icirlen = *lnote + 5 - i__1;
		ici__1.iciunit = notexq + i__1;
		ici__1.icifmt = "(f5.2)";
		s_wsfi(&ici__1);
		do_fio(&c__1, (char *)&xnsk, (ftnlen)sizeof(real));
		e_wsfi();
		*lnote += 5;
	    }
/* Writing concatenation */
	    i__4[0] = *lnote, a__2[0] = notexq;
	    i__4[1] = 1, a__2[1] = "}";
	    s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
	    ++(*lnote);
	    if (comxtup_1.islope[commvl_1.ivx - 1] < 0 || comxtup_1.islope[
		    commvl_1.ivx - 1] >= 10) {
/* Writing concatenation */
		i__4[0] = *lnote, a__2[0] = notexq;
		i__4[1] = 1, a__2[1] = "{";
		s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
		++(*lnote);
		if (comxtup_1.islope[commvl_1.ivx - 1] < -9) {
		    i__1 = *lnote;
		    ici__1.icierr = 0;
		    ici__1.icirnum = 1;
		    ici__1.icirlen = *lnote + 3 - i__1;
		    ici__1.iciunit = notexq + i__1;
		    ici__1.icifmt = "(i3)";
		    s_wsfi(&ici__1);
		    do_fio(&c__1, (char *)&comxtup_1.islope[commvl_1.ivx - 1],
			     (ftnlen)sizeof(integer));
		    e_wsfi();
		    *lnote += 3;
		} else {
		    i__1 = *lnote;
		    ici__1.icierr = 0;
		    ici__1.icirnum = 1;
		    ici__1.icirlen = *lnote + 2 - i__1;
		    ici__1.iciunit = notexq + i__1;
		    ici__1.icifmt = "(i2)";
		    s_wsfi(&ici__1);
		    do_fio(&c__1, (char *)&comxtup_1.islope[commvl_1.ivx - 1],
			     (ftnlen)sizeof(integer));
		    e_wsfi();
		    *lnote += 2;
		}
/* Writing concatenation */
		i__4[0] = *lnote, a__2[0] = notexq;
		i__4[1] = 1, a__2[1] = "}";
		s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
		++(*lnote);
	    } else {
		i__1 = *lnote;
		ici__1.icierr = 0;
		ici__1.icirnum = 1;
		ici__1.icirlen = *lnote + 1 - i__1;
		ici__1.iciunit = notexq + i__1;
		ici__1.icifmt = "(i1)";
		s_wsfi(&ici__1);
		do_fio(&c__1, (char *)&comxtup_1.islope[commvl_1.ivx - 1], (
			ftnlen)sizeof(integer));
		e_wsfi();
		++(*lnote);
	    }
	    if (strtmid_1.ixrest[commvl_1.ivx - 1] == 1) {

/*  Put in the rest.  Possible problem: Rest is a spacing char, but between */
/*  beamstrt and beamn1 some non-spacing chars. are inserted. */

		if (multb == 0) {
/* Writing concatenation */
		    i__3[0] = *lnote, a__1[0] = notexq;
		    i__3[1] = 1, a__1[1] = all_1.sq;
		    i__3[2] = 2, a__1[2] = "qp";
		    s_cat(notexq, a__1, i__3, &c__3, (ftnlen)79);
		    *lnote += 3;
		} else {
/* Writing concatenation */
		    i__3[0] = *lnote, a__1[0] = notexq;
		    i__3[1] = 1, a__1[1] = all_1.sq;
		    i__3[2] = 6, a__1[2] = "hpause";
		    s_cat(notexq, a__1, i__3, &c__3, (ftnlen)79);
		    *lnote += 7;
		}

/*  No need to come back through this subroutine (as would if rest starts bar */
/*  & multb>0), so do not advance ibm1. But must check in beamn1 and do nothing. */

		strtmid_1.ixrest[commvl_1.ivx - 1] = 0;
	    }
	    return 0;
	}

/*  End if block for non-beamed xtup start...note we returned */

	if (strtmid_1.ixrest[commvl_1.ivx - 1] == 1) {

/*  Insert rest at start of beamed xtup.  See above note for possible problem. */

	    i__1 = 4 - multb;
	    all_1.nodur[commvl_1.ivx + ipb1 * 15 - 16] = pow_ii(&c__2, &i__1);
	    notex_(tempq, &ltemp, (ftnlen)79);
	    if (*lnote > 0) {
/* Writing concatenation */
		i__4[0] = *lnote, a__2[0] = notexq;
		i__4[1] = ltemp, a__2[1] = tempq;
		s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
	    } else {
		s_copy(notexq, tempq, (ftnlen)79, ltemp);
	    }
	    *lnote += ltemp;

/*  Re-zero just in case! */

	    all_1.nodur[commvl_1.ivx + ipb1 * 15 - 16] = 0;
	    ++all_1.ibm1[commvl_1.ivx + ibc * 15 - 16];

/*  See if next note is a non-rest */

	    if (! bit_test(all_1.irest[commvl_1.ivx + (ipb1 + 1) * 15 - 16],0)
		    ) {
		strtmid_1.ixrest[commvl_1.ivx - 1] = 2;
	    } else {

/*  Suppress reprinting xtup number next time through beamstrt */

		all_1.islur[commvl_1.ivx + (ipb1 + 1) * 15 - 16] = bit_set(
			all_1.islur[commvl_1.ivx + (ipb1 + 1) * 15 - 16],31);

/*  Set new xtup start flag */

		all_1.irest[commvl_1.ivx + (ipb1 + 1) * 15 - 16] = bit_set(
			all_1.irest[commvl_1.ivx + (ipb1 + 1) * 15 - 16],28);
	    }
	    return 0;
	}
    }
    if (comxtup_1.vxtup[commvl_1.ivx - 1] && ipb1 == all_1.ibm2[commvl_1.ivx 
	    + ibc * 15 - 16]) {

/*  Move actual note writing to beamend */

	strtmid_1.ixrest[commvl_1.ivx - 1] = 4;
	return 0;
    }

/*  Adjust start level and slope if needed */

    iadj = (63 & lbit_shift(all_1.ipl[commvl_1.ivx + ipb1 * 15 - 16], (ftnlen)
	    -11)) - 30;
    if (iadj != -30) {
	comxtup_1.nolev1[commvl_1.ivx - 1] += iadj;
    }
    iadj = (63 & lbit_shift(all_1.ipl[commvl_1.ivx + ipb1 * 15 - 16], (ftnlen)
	    -17)) - 30;
    if (iadj != -30) {
	comxtup_1.islope[commvl_1.ivx - 1] += iadj;
    }
    iadj = 3 & lbit_shift(all_1.islur[commvl_1.ivx + ipb1 * 15 - 16], (ftnlen)
	    -27);
    addbrack = FALSE_;
    if (bit_test(all_1.ipl[commvl_1.ivx + ipb1 * 15 - 16],30)) {

/*  Check for altered starting polarity.  Only in forced beams. Nominal start */
/*  level is nolev1. So beam level is nolev1 +/- 6, to be compared w/ nolev(.,.). */

	if (*(unsigned char *)&all_1.ulq[commvl_1.ivx + ibc * 15 - 16] == 'u' 
		&& comxtup_1.nolev1[commvl_1.ivx - 1] + 6 < all_1.nolev[
		commvl_1.ivx + ipb1 * 15 - 16]) {
	    if (*lnote == 0) {
/* Writing concatenation */
		i__4[0] = 1, a__2[0] = all_1.sq;
		i__4[1] = 5, a__2[1] = "loff{";
		s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
	    } else {
/* Writing concatenation */
		i__3[0] = *lnote, a__1[0] = notexq;
		i__3[1] = 1, a__1[1] = all_1.sq;
		i__3[2] = 5, a__1[2] = "loff{";
		s_cat(notexq, a__1, i__3, &c__3, (ftnlen)79);
	    }
	    *lnote += 6;
	    addbrack = TRUE_;
	} else if (*(unsigned char *)&all_1.ulq[commvl_1.ivx + ibc * 15 - 16] 
		== 'l' && comxtup_1.nolev1[commvl_1.ivx - 1] - 6 > 
		all_1.nolev[commvl_1.ivx + ipb1 * 15 - 16]) {
	    if (*lnote == 0) {
/* Writing concatenation */
		i__4[0] = 1, a__2[0] = all_1.sq;
		i__4[1] = 5, a__2[1] = "roff{";
		s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
	    } else {
/* Writing concatenation */
		i__3[0] = *lnote, a__1[0] = notexq;
		i__3[1] = 1, a__1[1] = all_1.sq;
		i__3[2] = 5, a__1[2] = "roff{";
		s_cat(notexq, a__1, i__3, &c__3, (ftnlen)79);
	    }
	    *lnote += 6;
	    addbrack = TRUE_;
	}

/*  Check for end level in forced beam.  Have to do it here since with multiple */
/*  voices, xelsk will not be preserved. */

	if (*(unsigned char *)&all_1.ulq[commvl_1.ivx + all_1.ibmcnt[
		commvl_1.ivx - 1] * 15 - 16] == 'u') {
	    bmlev = comxtup_1.nolev1[commvl_1.ivx - 1] + 6 + comxtup_1.islope[
		    commvl_1.ivx - 1] * comxtup_1.xelsk[nnb - 1] / 
		    all_1.slfac;
	    strtmid_1.flipend[commvl_1.ivx - 1] = bmlev < (real) all_1.nolev[
		    commvl_1.ivx + all_1.ibm2[commvl_1.ivx + ibc * 15 - 16] * 
		    15 - 16];
	} else if (*(unsigned char *)&all_1.ulq[commvl_1.ivx + all_1.ibmcnt[
		commvl_1.ivx - 1] * 15 - 16] == 'l') {
	    bmlev = comxtup_1.nolev1[commvl_1.ivx - 1] - 6 + comxtup_1.islope[
		    commvl_1.ivx - 1] * comxtup_1.xelsk[nnb - 1] / 
		    all_1.slfac;
	    strtmid_1.flipend[commvl_1.ivx - 1] = bmlev > (real) all_1.nolev[
		    commvl_1.ivx + all_1.ibm2[commvl_1.ivx + ibc * 15 - 16] * 
		    15 - 16];
	}
    }
    i__1 = multb + iadj;
    ntrbbb_(&i__1, "i", all_1.ulq + (commvl_1.ivx + ibc * 15 - 16), &
	    commvl_1.ivx, notexq, lnote, (ftnlen)1, (ftnlen)1, (ftnlen)79);

/*   Put in name of start level and slope, after correcting nolev1 if xtup */
/*   started with a rest. */

    if (strtmid_1.ixrest[commvl_1.ivx - 1] == 2) {
	r__1 = comxtup_1.nolev1[commvl_1.ivx - 1] + comxtup_1.xelsk[0] * 
		comxtup_1.islope[commvl_1.ivx - 1] / all_1.slfac;
	comxtup_1.nolev1[commvl_1.ivx - 1] = i_nint(&r__1);
    }
    i__1 = ncmid_(&all_1.iv, &ipb1);
    notefq_(noteq, &lnoten, &comxtup_1.nolev1[commvl_1.ivx - 1], &i__1, (
	    ftnlen)8);
/* Computing MIN */
    i__2 = (i__1 = comxtup_1.islope[commvl_1.ivx - 1], abs(i__1));
    iasl = min(i__2,9);
    if (comxtup_1.islope[commvl_1.ivx - 1] < 0) {
/* Writing concatenation */
	i__3[0] = *lnote, a__1[0] = notexq;
	i__3[1] = lnoten, a__1[1] = noteq;
	i__3[2] = 1, a__1[2] = "{";
	s_cat(notexq, a__1, i__3, &c__3, (ftnlen)79);
	*lnote = *lnote + 4 + lnoten;
	i__1 = *lnote - 3;
	ici__1.icierr = 0;
	ici__1.icirnum = 1;
	ici__1.icirlen = *lnote - i__1;
	ici__1.iciunit = notexq + i__1;
	ici__1.icifmt = "(i2,a1)";
	s_wsfi(&ici__1);
	i__2 = -iasl;
	do_fio(&c__1, (char *)&i__2, (ftnlen)sizeof(integer));
	do_fio(&c__1, "}", (ftnlen)1);
	e_wsfi();
    } else {
/* Writing concatenation */
	i__4[0] = *lnote, a__2[0] = notexq;
	i__4[1] = lnoten, a__2[1] = noteq;
	s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
	*lnote = *lnote + 1 + lnoten;
	ici__1.icierr = 0;
	ici__1.icirnum = 1;
	ici__1.icirlen = 1;
	ici__1.iciunit = notexq + (*lnote - 1);
	ici__1.icifmt = "(i1)";
	s_wsfi(&ici__1);
	do_fio(&c__1, (char *)&iasl, (ftnlen)sizeof(integer));
	e_wsfi();
    }

/*  Check for beam-thk fine-tuning */

    if (iadj > 0) {
	i__1 = multb + 1;
	for (imp = multb + iadj; imp >= i__1; --imp) {
	    ntrbbb_(&imp, "t", all_1.ulq + (commvl_1.ivx + ibc * 15 - 16), &
		    commvl_1.ivx, notexq, lnote, (ftnlen)1, (ftnlen)1, (
		    ftnlen)79);
/* L1: */
	}
    }

/*  If we shifted, must close with right bracket */

    if (addbrack) {
/* Writing concatenation */
	i__4[0] = *lnote, a__2[0] = notexq;
	i__4[1] = 1, a__2[1] = "}";
	s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
	++(*lnote);
    }

/*  Get 'floor' zmin for figures */

    if (all_1.figbass && all_1.iv == 1) {
	zmult = (multb - 1) * (float)1.2;
	ymin = (float)100.;
	i__1 = nnb;
	for (inb = 1; inb <= i__1; ++inb) {
	    if (all_1.isfig[ipb[inb - 1] - 1]) {
		if (*(unsigned char *)&all_1.ulq[ibc * 15 - 15] == 'u') {
		    ybot = (real) all_1.nolev[ipb[inb - 1] * 15 - 15];
		} else {
		    ybot = comxtup_1.islope[commvl_1.ivx - 1] / all_1.slfac * 
			    comxtup_1.xelsk[inb - 1] + comxtup_1.nolev1[
			    commvl_1.ivx - 1] - all_1.stemlen - zmult;
		}
		ymin = dmin(ymin,ybot);
	    }
/* L3: */
	}
	maxdrop = ncmid_(&c__1, &ipb1) - 4 - ymin + (float)5.01;
/* Computing MAX */
	i__1 = all_1.ifigdrop[all_1.iline - 1];
	all_1.ifigdrop[all_1.iline - 1] = max(i__1,maxdrop);
    }

/*  Compute ornament levels if needed */

    nomornlev = ncmid_(&all_1.iv, &ipb1) + 5;
    iorn = 0;
    i__1 = nnb;
    for (inb = 1; inb <= i__1; ++inb) {
	ip = ipb[inb - 1];
	if (! bit_test(all_1.iornq[commvl_1.ivx + ip * 15 - 1],23)) {
	    goto L8;
	}

/*  Bits 0-13: (stmgx+Tupf._) , 14: Down fermata, was F */
/*  15: Trill w/o "tr", was U , 16-18 Editorial s,f,n , 19-21 TBD */

	if (! bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 16],10)) {

/*  Non-chord.  There IS an ornament.  Need ihornb only if upbeam, and if */
/*  ornament is 1,2,3,5,6,7,8,9,10,15-21 (up- but not domn ferm.) */

	    if (*(unsigned char *)&all_1.ulq[commvl_1.ivx + ibc * 15 - 16] == 
		    'u' && (all_1.iornq[commvl_1.ivx + ipb[inb - 1] * 15 - 1] 
		    & 4163566) > 0) {
		++iorn;
		all_1.iornq[commvl_1.ivx + ip * 15 - 1] = bit_set(all_1.iornq[
			commvl_1.ivx + ip * 15 - 1],22);
		ybeam = comxtup_1.nolev1[commvl_1.ivx - 1] + all_1.stemlen + 
			comxtup_1.islope[commvl_1.ivx - 1] * comxtup_1.xelsk[
			inb - 1] / all_1.slfac - 1 + (multb - 1) * (float)1.2;
/* Computing MAX */
		r__1 = ybeam + (float)3.;
		i__2 = i_nint(&r__1);
		ihornb[commvl_1.ivx + iorn * 15] = max(i__2,nomornlev);
	    }
	} else {

/* In a chord.  Orn may be on main note or non-main or both.  Set ihornb if */
/* upbeam and highest note has orn, or down beam and lowest.  Find 1st chord note */

	    i__2 = comtrill_1.ncrd;
	    for (comtrill_1.icrd1 = 1; comtrill_1.icrd1 <= i__2; 
		    ++comtrill_1.icrd1) {
		if ((255 & comtrill_1.icrdat[comtrill_1.icrd1 - 1]) == ip && (
			15 & lbit_shift(comtrill_1.icrdat[comtrill_1.icrd1 - 
			1], (ftnlen)-8)) == commvl_1.ivx) {
		    goto L11;
		}
/* L10: */
	    }
L11:

/* Find outermost note, min or max depending on beam direction ulq.  xto is true */
/* if there's an ornament on that note.  Expand orn list to include ._, since if */
/* on extreme chord note in beam, will move. */
/* So ornaments are all except 0,4,13 (,g,) */

	    levx = all_1.nolev[commvl_1.ivx + ip * 15 - 16];
	    xto = (all_1.iornq[commvl_1.ivx + ipb[inb - 1] * 15 - 1] & 
		    4186094) > 0;
	    icrdx = 0;
	    i__2 = comtrill_1.ncrd;
	    for (icrd = comtrill_1.icrd1; icrd <= i__2; ++icrd) {
		if ((255 & comtrill_1.icrdat[icrd - 1]) != ip || (15 & 
			lbit_shift(comtrill_1.icrdat[icrd - 1], (ftnlen)-8)) 
			!= commvl_1.ivx) {
		    goto L13;
		}
		levc = 127 & lbit_shift(comtrill_1.icrdat[icrd - 1], (ftnlen)
			-12);
		if (*(unsigned char *)&all_1.ulq[commvl_1.ivx + ibc * 15 - 16]
			 == 'u' && levc > levx || *(unsigned char *)&
			all_1.ulq[commvl_1.ivx + ibc * 15 - 16] == 'l' && 
			levc < levx) {
		    levx = levc;
		    icrdx = icrd;
		    xto = (comtrill_1.icrdorn[icrd - 1] & 4186094) > 0;
		}
/* L12: */
	    }
L13:

/*  If there's orn on extreme note, do stuff */

	    if (xto) {
		++iorn;
		if (*(unsigned char *)&all_1.ulq[commvl_1.ivx + ibc * 15 - 16]
			 == 'u') {
		    ybeam = comxtup_1.nolev1[commvl_1.ivx - 1] + 
			    all_1.stemlen + comxtup_1.islope[commvl_1.ivx - 1]
			     * comxtup_1.xelsk[inb - 1] / all_1.slfac - 1 + (
			    multb - 1) * (float)1.2;
/* Computing MAX */
		    r__1 = ybeam + (float)3.;
		    i__2 = i_nint(&r__1);
		    ihornb[commvl_1.ivx + iorn * 15] = max(i__2,nomornlev);
		} else {
		    ybeam = comxtup_1.nolev1[commvl_1.ivx - 1] - 
			    all_1.stemlen + comxtup_1.islope[commvl_1.ivx - 1]
			     * comxtup_1.xelsk[inb - 1] / all_1.slfac + 1 - (
			    multb - 1) * (float)1.2;
/* Computing MIN */
		    r__1 = ybeam - (float)3.;
		    i__2 = i_nint(&r__1), i__5 = nomornlev - 10;
		    ihornb[commvl_1.ivx + iorn * 15] = min(i__2,i__5);
		}
		if (icrdx == 0) {

/*  Affected ornament is on main note */

		    all_1.iornq[commvl_1.ivx + ip * 15 - 1] = bit_set(
			    all_1.iornq[commvl_1.ivx + ip * 15 - 1],22);
		} else {
		    comtrill_1.icrdorn[icrdx - 1] = bit_set(
			    comtrill_1.icrdorn[icrdx - 1],22);
		}
	    }
	}
L8:
	;
    }

/*  Henceforth nornb will be a counter. */

    if (iorn > 0) {
	nornb[commvl_1.ivx] = 1;
    }
    if (strtmid_1.ixrest[commvl_1.ivx - 1] == 2) {
	strtmid_1.ixrest[commvl_1.ivx - 1] = 0;
    }
    return 0;
} /* beamstrt_ */

/* Subroutine */ int beamn1_(notexq, lnote, notexq_len)
char *notexq;
integer *lnote;
ftnlen notexq_len;
{
    /* System generated locals */
    address a__1[4], a__2[3], a__3[2];
    integer i__1, i__2[4], i__3[3], i__4[2];

    /* Builtin functions */
    integer pow_ii();
    /* Subroutine */ int s_cat();

    /* Local variables */
    static integer nd, im, ip1, len;
    extern integer log2_(), ncmid_();
    static integer ndsav;
    static char noteq[8];
    extern /* Subroutine */ int notex_();
    static integer multr;
    extern /* Subroutine */ int ntrbbb_(), notefq_();
    static logical isdotm;
    static integer lnoten, multip;
    extern /* Subroutine */ int istring_(), addblank_();

    ip1 = all_1.ibm1[commvl_1.ivx + all_1.ibmcnt[commvl_1.ivx - 1] * 15 - 16];
    multip = all_1.mult[commvl_1.ivx + ip1 * 15 - 16];
    if (multip <= 0 && bit_test(all_1.irest[commvl_1.ivx + ip1 * 15 - 16],0)) 
	    {
	*lnote = 0;

/*  The rest was already written in beamstrt, so just get out of here */

	return 0;
    }
    if (comxtup_1.vxtup[commvl_1.ivx - 1] && multip <= 0) {

/*  Xtuplet with no beam, just put in the right kind of note */

	if (bit_test(all_1.islur[commvl_1.ivx + ip1 * 15 - 16],30)) {

/*  Forced stem direction */

	    ndsav = all_1.nodur[commvl_1.ivx + ip1 * 15 - 16];
	    i__1 = 4 - multip;
	    all_1.nodur[commvl_1.ivx + ip1 * 15 - 16] = pow_ii(&c__2, &i__1);
	    notex_(notexq, lnote, (ftnlen)79);
	    all_1.nodur[commvl_1.ivx + ip1 * 15 - 16] = ndsav;
	} else {
	    i__1 = ncmid_(&all_1.iv, &ip1);
	    notefq_(noteq, &lnoten, &all_1.nolev[commvl_1.ivx + all_1.ipo[
		    all_1.jn - 1] * 15 - 16], &i__1, (ftnlen)8);
	    if (lnoten == 1) {
		addblank_(noteq, &lnoten, (ftnlen)8);
	    }
	    if (multip == 0) {
/* Writing concatenation */
		i__2[0] = 1, a__1[0] = all_1.sq;
		i__2[1] = 1, a__1[1] = "q";
		i__2[2] = 1, a__1[2] = all_1.ulq + (commvl_1.ivx + 
			all_1.ibmcnt[commvl_1.ivx - 1] * 15 - 16);
		i__2[3] = 8, a__1[3] = noteq;
		s_cat(notexq, a__1, i__2, &c__4, (ftnlen)79);
	    } else if (multip == -1) {
/* Writing concatenation */
		i__2[0] = 1, a__1[0] = all_1.sq;
		i__2[1] = 1, a__1[1] = "h";
		i__2[2] = 1, a__1[2] = all_1.ulq + (commvl_1.ivx + 
			all_1.ibmcnt[commvl_1.ivx - 1] * 15 - 16);
		i__2[3] = 8, a__1[3] = noteq;
		s_cat(notexq, a__1, i__2, &c__4, (ftnlen)79);
	    }
	    *lnote = lnoten + 3;
	}
	return 0;
    }

/*  Check if mult. decreases from 1st note to 2nd */

    if (all_1.ibm2[commvl_1.ivx + all_1.ibmcnt[commvl_1.ivx - 1] * 15 - 16] > 
	    ip1) {
	if (! bit_test(all_1.irest[commvl_1.ivx + (ip1 + 1) * 15 - 16],0)) {
	    multr = all_1.mult[commvl_1.ivx + (ip1 + 1) * 15 - 16];
	} else {
	    multr = all_1.mult[commvl_1.ivx + (ip1 + 2) * 15 - 16];
	}
	*lnote = 0;
	if (multr < multip) {
	    i__1 = multr + 1;
	    for (im = multip; im >= i__1; --im) {
		ntrbbb_(&im, "r", all_1.ulq + (commvl_1.ivx + all_1.ibmcnt[
			commvl_1.ivx - 1] * 15 - 16), &commvl_1.ivx, notexq, 
			lnote, (ftnlen)1, (ftnlen)1, (ftnlen)79);
/* L1: */
	    }
	}
    }

/*  Put in the note */

    if (*lnote > 0) {
/* Writing concatenation */
	i__3[0] = *lnote, a__2[0] = notexq;
	i__3[1] = 1, a__2[1] = all_1.sq;
	i__3[2] = 2, a__2[2] = "qb";
	s_cat(notexq, a__2, i__3, &c__3, (ftnlen)79);
    } else {
/* Writing concatenation */
	i__4[0] = 1, a__3[0] = all_1.sq;
	i__4[1] = 2, a__3[1] = "qb";
	s_cat(notexq, a__3, i__4, &c__2, (ftnlen)79);
    }
    *lnote += 3;

/*  Check for dot */

    isdotm = FALSE_;
    if (! comxtup_1.vxtup[commvl_1.ivx - 1]) {
	nd = all_1.nodur[commvl_1.ivx + all_1.ipo[all_1.jn - 1] * 15 - 16];
	if (nd != 0) {
	    i__1 = log2_(&nd);
	    if (pow_ii(&c__2, &i__1) != nd) {
		if (! bit_test(all_1.iornq[commvl_1.ivx + ip1 * 15 - 1],13)) {
		    if (! bit_test(all_1.islur[commvl_1.ivx + ip1 * 15 - 16],
			    3)) {
/* Writing concatenation */
			i__4[0] = *lnote, a__3[0] = notexq;
			i__4[1] = 1, a__3[1] = "p";
			s_cat(notexq, a__3, i__4, &c__2, (ftnlen)79);
		    } else {

/*  Double dot */

/* Writing concatenation */
			i__4[0] = *lnote, a__3[0] = notexq;
			i__4[1] = 2, a__3[1] = "pp";
			s_cat(notexq, a__3, i__4, &c__2, (ftnlen)79);
			++(*lnote);
		    }
		} else {
/* Writing concatenation */
		    i__4[0] = *lnote, a__3[0] = notexq;
		    i__4[1] = 1, a__3[1] = "m";
		    s_cat(notexq, a__3, i__4, &c__2, (ftnlen)79);
		    isdotm = TRUE_;
		}
		++(*lnote);
	    }
	}
    }

/*  Do the number; 0 if 12 */

    if (! bit_test(all_1.irest[commvl_1.ivx + ip1 * 15 - 16],24)) {
	i__1 = commvl_1.ivx % 12;
	istring_(&i__1, noteq, &len, (ftnlen)8);
    } else {
	i__1 = combjmp_1.ivbjmp % 12;
	istring_(&i__1, noteq, &len, (ftnlen)8);
	combjmp_1.isbjmp = TRUE_;
    }
/* Writing concatenation */
    i__4[0] = *lnote, a__3[0] = notexq;
    i__4[1] = len, a__3[1] = noteq;
    s_cat(notexq, a__3, i__4, &c__2, (ftnlen)79);
    *lnote += len;
    i__1 = ncmid_(&all_1.iv, &ip1);
    notefq_(noteq, &lnoten, &all_1.nolev[commvl_1.ivx + all_1.ipo[all_1.jn - 
	    1] * 15 - 16], &i__1, (ftnlen)8);
/* Writing concatenation */
    i__4[0] = *lnote, a__3[0] = notexq;
    i__4[1] = lnoten, a__3[1] = noteq;
    s_cat(notexq, a__3, i__4, &c__2, (ftnlen)79);
    *lnote += lnoten;
    if (isdotm) {
	if (lnoten == 1) {
/* Writing concatenation */
	    i__2[0] = *lnote, a__1[0] = notexq;
	    i__2[1] = 1, a__1[1] = "{";
	    i__2[2] = 1, a__1[2] = noteq;
	    i__2[3] = 1, a__1[3] = "}";
	    s_cat(notexq, a__1, i__2, &c__4, (ftnlen)79);
	    *lnote += 3;
	} else {
	    i__1 = lnoten - 2;
/* Writing concatenation */
	    i__4[0] = *lnote, a__3[0] = notexq;
	    i__4[1] = lnoten - 1 - i__1, a__3[1] = noteq + i__1;
	    s_cat(notexq, a__3, i__4, &c__2, (ftnlen)79);
	    ++(*lnote);
	}
    }
    return 0;
} /* beamn1_ */

/* Subroutine */ int beamend_(notexq, lnote, notexq_len)
char *notexq;
integer *lnote;
ftnlen notexq_len;
{
    /* System generated locals */
    address a__1[4], a__2[3], a__3[2];
    integer i__1, i__2[4], i__3[3], i__4[2];
    char ch__1[1];

    /* Builtin functions */
    integer pow_ii();
    /* Subroutine */ int s_cat();

    /* Local variables */
    static integer ip, mp, len, imp;
    extern integer log2_();
    extern /* Character */ VOID chax_();
    static integer ivbm;
    static char ulqq[1];
    extern integer ncmid_();
    static integer ndsav;
    static char tempq[4], noteq[8];
    extern /* Subroutine */ int notex_(), ntrbbb_(), notefq_();
    static logical isdotm;
    static integer lnoten, multip;
    extern /* Subroutine */ int istring_(), addblank_();

    ip = all_1.ipo[all_1.jn - 1];
    multip = all_1.mult[commvl_1.ivx + ip * 15 - 16];
    if (strtmid_1.ixrest[commvl_1.ivx - 1] == 4) {

/*  This is the LAST note in the xtup (i.e., all rests before).  Make single. */

	i__1 = 4 - multip;
	all_1.nodur[commvl_1.ivx + ip * 15 - 16] = pow_ii(&c__2, &i__1);
	notex_(notexq, lnote, (ftnlen)79);
	strtmid_1.ixrest[commvl_1.ivx - 1] = 0;
	return 0;
    }
    if (comxtup_1.vxtup[commvl_1.ivx - 1] && multip <= 0) {

/*  Xtuplet with no beam, just put in the right kind of note */

	if (bit_test(all_1.islur[commvl_1.ivx + ip * 15 - 16],30)) {

/*  Forced stem direction */

	    ndsav = all_1.nodur[commvl_1.ivx + ip * 15 - 16];
	    i__1 = 4 - multip;
	    all_1.nodur[commvl_1.ivx + ip * 15 - 16] = pow_ii(&c__2, &i__1);
	    notex_(notexq, lnote, (ftnlen)79);
	    all_1.nodur[commvl_1.ivx + ip * 15 - 16] = ndsav;
	} else {
	    i__1 = ncmid_(&all_1.iv, &ip);
	    notefq_(noteq, &lnoten, &all_1.nolev[commvl_1.ivx + ip * 15 - 16],
		     &i__1, (ftnlen)8);
	    if (lnoten == 1) {
		addblank_(noteq, &lnoten, (ftnlen)8);
	    }
	    if (multip == 0) {
/* Writing concatenation */
		i__2[0] = 1, a__1[0] = all_1.sq;
		i__2[1] = 1, a__1[1] = "q";
		i__2[2] = 1, a__1[2] = all_1.ulq + (commvl_1.ivx + 
			all_1.ibmcnt[commvl_1.ivx - 1] * 15 - 16);
		i__2[3] = 8, a__1[3] = noteq;
		s_cat(notexq, a__1, i__2, &c__4, (ftnlen)79);
	    } else if (multip == -1) {
/* Writing concatenation */
		i__2[0] = 1, a__1[0] = all_1.sq;
		i__2[1] = 1, a__1[1] = "h";
		i__2[2] = 1, a__1[2] = all_1.ulq + (commvl_1.ivx + 
			all_1.ibmcnt[commvl_1.ivx - 1] * 15 - 16);
		i__2[3] = 8, a__1[3] = noteq;
		s_cat(notexq, a__1, i__2, &c__4, (ftnlen)79);
	    }
	    *lnote = lnoten + 3;
	}
	return 0;
    }
    i__1 = ncmid_(&all_1.iv, &ip);
    notefq_(noteq, &lnoten, &all_1.nolev[commvl_1.ivx + ip * 15 - 16], &i__1, 
	    (ftnlen)8);
    *lnote = 0;

/* New way, with flipend, which was computed in beamstrt. */

    if (bit_test(all_1.ipl[commvl_1.ivx + ip * 15 - 16],30) && 
	    strtmid_1.flipend[commvl_1.ivx - 1]) {
	i__1 = 225 - *(unsigned char *)&all_1.ulq[commvl_1.ivx + all_1.ibmcnt[
		commvl_1.ivx - 1] * 15 - 16];
	chax_(ch__1, (ftnlen)1, &i__1);
	*(unsigned char *)&all_1.ulq[commvl_1.ivx + all_1.ibmcnt[commvl_1.ivx 
		- 1] * 15 - 16] = *(unsigned char *)&ch__1[0];
    }
    if (ip > all_1.ibm1[commvl_1.ivx + all_1.ibmcnt[commvl_1.ivx - 1] * 15 - 
	    16]) {

/* This is not a one-noter from beam-jump.  Check if multiplicity has increased */

	if (bit_test(all_1.irest[commvl_1.ivx + (ip - 1) * 15 - 16],0)) {

/*  Prior note is a rest, check one before that */

	    mp = all_1.mult[commvl_1.ivx + (ip - 2) * 15 - 16];
	} else {
	    mp = all_1.mult[commvl_1.ivx + (ip - 1) * 15 - 16];
	}
	if (multip > mp) {

/*  Assume 1-3, 2-3, or 1-2 */

	    i__1 = mp + 1;
	    for (imp = multip; imp >= i__1; --imp) {
		ntrbbb_(&imp, "t", all_1.ulq + (commvl_1.ivx + all_1.ibmcnt[
			commvl_1.ivx - 1] * 15 - 16), &commvl_1.ivx, notexq, 
			lnote, (ftnlen)1, (ftnlen)1, (ftnlen)79);
/* L2: */
	    }
	}
    }

/* Now the normal beam termination */

    if (! bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],23)) {

/*  Don't terminate if starting a beam jump */

	*(unsigned char *)ulqq = *(unsigned char *)&all_1.ulq[commvl_1.ivx + 
		all_1.ibmcnt[commvl_1.ivx - 1] * 15 - 16];
	if (! combjmp_1.isbjmp) {
	    ivbm = commvl_1.ivx;
	} else {
	    ivbm = combjmp_1.ivbjmp;
	    i__1 = 225 - *(unsigned char *)ulqq;
	    chax_(ch__1, (ftnlen)1, &i__1);
	    *(unsigned char *)ulqq = *(unsigned char *)&ch__1[0];
	}
	ntrbbb_(&c__1, "t", ulqq, &ivbm, notexq, lnote, (ftnlen)1, (ftnlen)1, 
		(ftnlen)79);
    } else {
	combjmp_1.ivbjmp = commvl_1.ivx;
    }

/*  And now the note */

    if (*lnote > 0) {
/* Writing concatenation */
	i__3[0] = *lnote, a__2[0] = notexq;
	i__3[1] = 1, a__2[1] = all_1.sq;
	i__3[2] = 2, a__2[2] = "qb";
	s_cat(notexq, a__2, i__3, &c__3, (ftnlen)79);
    } else {
/* Writing concatenation */
	i__4[0] = 1, a__3[0] = all_1.sq;
	i__4[1] = 2, a__3[1] = "qb";
	s_cat(notexq, a__3, i__4, &c__2, (ftnlen)79);
    }
    *lnote += 3;
    isdotm = FALSE_;
    if (! comxtup_1.vxtup[commvl_1.ivx - 1]) {
	i__1 = log2_(&all_1.nodur[commvl_1.ivx + ip * 15 - 16]);
	if (pow_ii(&c__2, &i__1) != all_1.nodur[commvl_1.ivx + ip * 15 - 16]) 
		{
	    if (! bit_test(all_1.iornq[commvl_1.ivx + ip * 15 - 1],13)) {
/* Writing concatenation */
		i__4[0] = *lnote, a__3[0] = notexq;
		i__4[1] = 1, a__3[1] = "p";
		s_cat(notexq, a__3, i__4, &c__2, (ftnlen)79);
	    } else {
/* Writing concatenation */
		i__4[0] = *lnote, a__3[0] = notexq;
		i__4[1] = 1, a__3[1] = "m";
		s_cat(notexq, a__3, i__4, &c__2, (ftnlen)79);
		isdotm = TRUE_;
	    }
	    ++(*lnote);
	}
    }
    if (! combjmp_1.isbjmp) {
	i__1 = commvl_1.ivx % 12;
	istring_(&i__1, tempq, &len, (ftnlen)4);
    } else {
	i__1 = combjmp_1.ivbjmp % 12;
	istring_(&i__1, tempq, &len, (ftnlen)4);
	combjmp_1.isbjmp = FALSE_;
    }
/* Writing concatenation */
    i__4[0] = *lnote, a__3[0] = notexq;
    i__4[1] = len, a__3[1] = tempq;
    s_cat(notexq, a__3, i__4, &c__2, (ftnlen)79);
    *lnote += len;
/* Writing concatenation */
    i__4[0] = *lnote, a__3[0] = notexq;
    i__4[1] = lnoten, a__3[1] = noteq;
    s_cat(notexq, a__3, i__4, &c__2, (ftnlen)79);
    *lnote += lnoten;
    if (isdotm) {
	if (lnoten == 1) {
/* Writing concatenation */
	    i__2[0] = *lnote, a__1[0] = notexq;
	    i__2[1] = 1, a__1[1] = "{";
	    i__2[2] = 1, a__1[2] = noteq;
	    i__2[3] = 1, a__1[3] = "}";
	    s_cat(notexq, a__1, i__2, &c__4, (ftnlen)79);
	    *lnote += 3;
	} else {
	    i__1 = lnoten - 2;
/* Writing concatenation */
	    i__4[0] = *lnote, a__3[0] = notexq;
	    i__4[1] = lnoten - 1 - i__1, a__3[1] = noteq + i__1;
	    s_cat(notexq, a__3, i__4, &c__2, (ftnlen)79);
	    ++(*lnote);
	}
    }
    return 0;
} /* beamend_ */

/* Subroutine */ int beamid_(notexq, lnote, notexq_len)
char *notexq;
integer *lnote;
ftnlen notexq_len;
{
    /* System generated locals */
    address a__1[4], a__2[3], a__3[2];
    integer i__1, i__2[4], i__3, i__4[3], i__5[2];
    real r__1;

    /* Builtin functions */
    integer pow_ii();
    /* Subroutine */ int s_cat();

    /* Local variables */
    static integer im, ip, len, iud, mua, mub, iup;
    extern integer ncmid_();
    static integer ipmid, iflop, ndsav;
    static char noteq[8], tempq[4];
    extern /* Subroutine */ int notex_();
    extern integer levrn_();
    static integer nlnum, multl, multr;
    extern /* Subroutine */ int ntrbbb_();
    static integer ipleft;
    extern /* Subroutine */ int notefq_();
    static real xnlmid;
    static logical isdotm;
    static integer lnoten, multip;
    extern /* Subroutine */ int putxtn_();
    static integer ipright;
    extern /* Subroutine */ int istring_(), addblank_();
    extern logical isdotted_();

    *lnote = 0;
    ip = all_1.ipo[all_1.jn - 1];
    if (! bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],0)) {
	multip = all_1.mult[commvl_1.ivx + ip * 15 - 16];
/*          if (btest(islur(ivx,ip-1),3)) multip = multip+1 */

/*  (Above test OK since must have ip>1).  Double dotted note preceding */

/*  Move the following, because can't ask for note until after checking for */
/*  embedded xtup with number, due to ordering/octave feature. */

/*         call notefq(noteq,lnoten,nolev(ivx,ip),ncmid(iv,ip)) */
    }
    if (bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],28)) {
	comxtup_1.vxtup[commvl_1.ivx - 1] = TRUE_;
    }
    if (comxtup_1.vxtup[commvl_1.ivx - 1]) {

/*  In an xtup */

	if (bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],0)) {

/*  Intermediate rest in xtup, put in the rest.  Reset nodur so notex works OK */

	    i__1 = 4 - all_1.mult[commvl_1.ivx + ip * 15 - 16];
	    all_1.nodur[commvl_1.ivx + ip * 15 - 16] = pow_ii(&c__2, &i__1);
	    notex_(notexq, lnote, (ftnlen)79);

/*  Re-zero so next note does not get confused */

	    all_1.nodur[commvl_1.ivx + ip * 15 - 16] = 0;
	    return 0;
	}
	if (multip <= 0) {

/*  Xtuplet with no beam, just put in the right kind of note */

	    if (bit_test(all_1.islur[commvl_1.ivx + ip * 15 - 16],30)) {

/*  Forced stem direction */

		ndsav = all_1.nodur[commvl_1.ivx + ip * 15 - 16];
		i__1 = 4 - multip;
		all_1.nodur[commvl_1.ivx + ip * 15 - 16] = pow_ii(&c__2, &
			i__1);
		notex_(notexq, lnote, (ftnlen)79);
		all_1.nodur[commvl_1.ivx + ip * 15 - 16] = ndsav;
	    } else {
		i__1 = ncmid_(&all_1.iv, &ip);
		notefq_(noteq, &lnoten, &all_1.nolev[commvl_1.ivx + ip * 15 - 
			16], &i__1, (ftnlen)8);
		if (lnoten == 1) {
		    addblank_(noteq, &lnoten, (ftnlen)8);
		}
		if (multip == 0) {
/* Writing concatenation */
		    i__2[0] = 1, a__1[0] = all_1.sq;
		    i__2[1] = 1, a__1[1] = "q";
		    i__2[2] = 1, a__1[2] = all_1.ulq + (commvl_1.ivx + 
			    all_1.ibmcnt[commvl_1.ivx - 1] * 15 - 16);
		    i__2[3] = 8, a__1[3] = noteq;
		    s_cat(notexq, a__1, i__2, &c__4, (ftnlen)79);
		} else if (multip == -1) {
/* Writing concatenation */
		    i__2[0] = 1, a__1[0] = all_1.sq;
		    i__2[1] = 1, a__1[1] = "h";
		    i__2[2] = 1, a__1[2] = all_1.ulq + (commvl_1.ivx + 
			    all_1.ibmcnt[commvl_1.ivx - 1] * 15 - 16);
		    i__2[3] = 8, a__1[3] = noteq;
		    s_cat(notexq, a__1, i__2, &c__4, (ftnlen)79);
		}
		*lnote = lnoten + 3;
	    }
	    return 0;
	} else if (all_1.nodur[commvl_1.ivx + ip * 15 - 16] == 0) {

/*  In the beamed xtup but not the last note */

	    if (all_1.nodur[commvl_1.ivx + (ip - 1) * 15 - 16] > 0) {

/*  Embedded Xtup, mult>0, starts here.  Put in number if needed */

		iud = 1;
		if (*(unsigned char *)&all_1.ulq[commvl_1.ivx + all_1.ibmcnt[
			commvl_1.ivx - 1] * 15 - 16] == 'u') {
		    iud = -1;
		}

/*  Get ip#, notelevel of middle note (or gap) in xtup */

		ipmid = ip + comxtup_1.ntupv[commvl_1.ivx - 1] / 2;
		i__1 = ncmid_(&all_1.iv, &ipmid);
		xnlmid = (real) levrn_(&all_1.nolev[commvl_1.ivx + ipmid * 15 
			- 16], &all_1.irest[commvl_1.ivx + ipmid * 15 - 16], &
			iud, &i__1, &all_1.mult[commvl_1.ivx + ipmid * 15 - 
			16]);
		if (comxtup_1.ntupv[commvl_1.ivx - 1] % 2 == 0) {
		    i__3 = ipmid - 1;
		    i__1 = ncmid_(&all_1.iv, &i__3);
		    xnlmid = (xnlmid + levrn_(&all_1.nolev[commvl_1.ivx + (
			    ipmid - 1) * 15 - 16], &all_1.irest[commvl_1.ivx 
			    + (ipmid - 1) * 15 - 16], &iud, &i__1, &
			    all_1.mult[commvl_1.ivx + (ipmid - 1) * 15 - 16]))
			     / 2;
		}
		iflop = 0;
		if ((r__1 = xnlmid - ncmid_(&all_1.iv, &ip), dabs(r__1)) < (
			float)3.) {
		    iflop = -iud;
		}
		iup = iud + (iflop << 1);
		if (bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],14)) {
		    iup = -iup;
		    iflop = 0;
		    if (iud * iup < 0) {
			iflop = iup;
		    }
		}

/*  Place number if needed */

		if (! bit_test(all_1.islur[commvl_1.ivx + ip * 15 - 16],31)) {
		    i__1 = ncmid_(&all_1.iv, &ip);
		    putxtn_(&comxtup_1.ntupv[commvl_1.ivx - 1], &iflop, &
			    multip, &iud, &comask_1.wheadpt, &comask_1.poenom,
			     &comxtup_1.nolev1[commvl_1.ivx - 1], &
			    comxtup_1.islope[commvl_1.ivx - 1], &all_1.slfac, 
			    &xnlmid, &all_1.islur[commvl_1.ivx + ip * 15 - 16]
			    , lnote, notexq, &i__1, &nlnum, &comxtup_1.eloff[
			    commvl_1.ivx - 1], &iup, &all_1.irest[
			    commvl_1.ivx + ip * 15 - 16], (ftnlen)79);
		}
		i__1 = ncmid_(&all_1.iv, &ip);
		notefq_(noteq, &lnoten, &all_1.nolev[commvl_1.ivx + ip * 15 - 
			16], &i__1, (ftnlen)8);
	    } else {

/*  Intermediate note of xtup */

		i__1 = ncmid_(&all_1.iv, &ip);
		notefq_(noteq, &lnoten, &all_1.nolev[commvl_1.ivx + ip * 15 - 
			16], &i__1, (ftnlen)8);
	    }
	} else {

/*  Last note of xtup (but not last note of beam!) */

	    i__1 = ncmid_(&all_1.iv, &ip);
	    notefq_(noteq, &lnoten, &all_1.nolev[commvl_1.ivx + ip * 15 - 16],
		     &i__1, (ftnlen)8);
	}
    } else if (bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],0)) {
	notex_(notexq, lnote, (ftnlen)79);
	return 0;
    } else {
	i__1 = ncmid_(&all_1.iv, &ip);
	notefq_(noteq, &lnoten, &all_1.nolev[commvl_1.ivx + ip * 15 - 16], &
		i__1, (ftnlen)8);
    }

/* Check if multiplicity changes in a way requiring action */

    ipleft = ip - 1;
    if (bit_test(all_1.irest[commvl_1.ivx + ipleft * 15 - 16],0)) {
	--ipleft;
    }
    if (! bit_test(all_1.islur[commvl_1.ivx + ipleft * 15 - 16],20)) {
	multl = all_1.mult[commvl_1.ivx + ipleft * 15 - 16];
    } else {
	multl = 1;
    }
    mub = multip - multl;
    ipright = ip + 1;
    if (bit_test(all_1.irest[commvl_1.ivx + ipright * 15 - 16],0)) {
	--ipright;
    }
    if (! bit_test(all_1.islur[commvl_1.ivx + ip * 15 - 16],20)) {
	multr = all_1.mult[commvl_1.ivx + ipright * 15 - 16];
    } else {
	multr = 1;
    }
    mua = multr - multip;
    if (mub > 0 || mua < 0) {

/*  Multiplicity has increased from left or will decrease to right. Need action. */

	if (mua >= 0) {
	    ntrbbb_(&multip, "n", all_1.ulq + (commvl_1.ivx + all_1.ibmcnt[
		    commvl_1.ivx - 1] * 15 - 16), &commvl_1.ivx, notexq, 
		    lnote, (ftnlen)1, (ftnlen)1, (ftnlen)79);
	} else if (multl >= multr) {
	    i__1 = multr + 1;
	    for (im = multip; im >= i__1; --im) {
		ntrbbb_(&im, "t", all_1.ulq + (commvl_1.ivx + all_1.ibmcnt[
			commvl_1.ivx - 1] * 15 - 16), &commvl_1.ivx, notexq, 
			lnote, (ftnlen)1, (ftnlen)1, (ftnlen)79);
/* L1: */
	    }
	} else {
	    i__1 = multip;
	    for (im = multr + 1; im <= i__1; ++im) {
		ntrbbb_(&im, "r", all_1.ulq + (commvl_1.ivx + all_1.ibmcnt[
			commvl_1.ivx - 1] * 15 - 16), &commvl_1.ivx, notexq, 
			lnote, (ftnlen)1, (ftnlen)1, (ftnlen)79);
/* L2: */
	    }
	    ntrbbb_(&multr, "n", all_1.ulq + (commvl_1.ivx + all_1.ibmcnt[
		    commvl_1.ivx - 1] * 15 - 16), &commvl_1.ivx, notexq, 
		    lnote, (ftnlen)1, (ftnlen)1, (ftnlen)79);
	}
    }

/* Now put in the note */

    if (*lnote > 0) {
/* Writing concatenation */
	i__4[0] = *lnote, a__2[0] = notexq;
	i__4[1] = 1, a__2[1] = all_1.sq;
	i__4[2] = 2, a__2[2] = "qb";
	s_cat(notexq, a__2, i__4, &c__3, (ftnlen)79);
    } else {
/* Writing concatenation */
	i__5[0] = 1, a__3[0] = all_1.sq;
	i__5[1] = 2, a__3[1] = "qb";
	s_cat(notexq, a__3, i__5, &c__2, (ftnlen)79);
    }
    *lnote += 3;
    isdotm = FALSE_;
    if (isdotted_(all_1.nodur, &commvl_1.ivx, &ip)) {

/* rule out ')' */

	if (! bit_test(all_1.iornq[commvl_1.ivx + ip * 15 - 1],13)) {
	    if (! bit_test(all_1.islur[commvl_1.ivx + ip * 15 - 16],3)) {
/* Writing concatenation */
		i__5[0] = *lnote, a__3[0] = notexq;
		i__5[1] = 1, a__3[1] = "p";
		s_cat(notexq, a__3, i__5, &c__2, (ftnlen)79);
	    } else {

/*  Double dot */

/* Writing concatenation */
		i__5[0] = *lnote, a__3[0] = notexq;
		i__5[1] = 2, a__3[1] = "pp";
		s_cat(notexq, a__3, i__5, &c__2, (ftnlen)79);
		++(*lnote);
	    }
	} else {
/* Writing concatenation */
	    i__5[0] = *lnote, a__3[0] = notexq;
	    i__5[1] = 1, a__3[1] = "m";
	    s_cat(notexq, a__3, i__5, &c__2, (ftnlen)79);
	    isdotm = TRUE_;
	}
	++(*lnote);
    }
    if (! combjmp_1.isbjmp) {
	i__1 = commvl_1.ivx % 12;
	istring_(&i__1, tempq, &len, (ftnlen)4);
    } else {
	i__1 = combjmp_1.ivbjmp % 12;
	istring_(&i__1, tempq, &len, (ftnlen)4);
    }
/* Writing concatenation */
    i__5[0] = *lnote, a__3[0] = notexq;
    i__5[1] = len, a__3[1] = tempq;
    s_cat(notexq, a__3, i__5, &c__2, (ftnlen)79);
    *lnote += len;
/* Writing concatenation */
    i__5[0] = *lnote, a__3[0] = notexq;
    i__5[1] = lnoten, a__3[1] = noteq;
    s_cat(notexq, a__3, i__5, &c__2, (ftnlen)79);
    *lnote += lnoten;
    if (isdotm) {
	if (lnoten == 2) {
/* Writing concatenation */
	    i__2[0] = *lnote, a__1[0] = notexq;
	    i__2[1] = 1, a__1[1] = "{";
	    i__2[2] = 1, a__1[2] = noteq + 1;
	    i__2[3] = 1, a__1[3] = "}";
	    s_cat(notexq, a__1, i__2, &c__4, (ftnlen)79);
	    *lnote += 3;
	} else {
	    i__1 = lnoten - 2;
/* Writing concatenation */
	    i__5[0] = *lnote, a__3[0] = notexq;
	    i__5[1] = lnoten - 1 - i__1, a__3[1] = noteq + i__1;
	    s_cat(notexq, a__3, i__5, &c__2, (ftnlen)79);
	    ++(*lnote);
	}
    }
    return 0;
} /* beamid_ */

/* Subroutine */ int ntrbbb_(n, char1q, ulqq, iv, notexq, lnote, char1q_len, 
	ulqq_len, notexq_len)
integer *n;
char *char1q, *ulqq;
integer *iv;
char *notexq;
integer *lnote;
ftnlen char1q_len;
ftnlen ulqq_len;
ftnlen notexq_len;
{
    /* System generated locals */
    address a__1[3], a__2[2];
    integer i__1[3], i__2[2], i__3;
    char ch__1[1];

    /* Builtin functions */
    /* Subroutine */ int s_cat();

    /* Local variables */
    static integer im, len;
    extern /* Character */ VOID chax_();
    static char tempq[4];
    extern /* Subroutine */ int istring_();


/*  This appends to notexq e.g. '\ibbbu1' */

    if (*lnote > 0) {
/* Writing concatenation */
	i__1[0] = *lnote, a__1[0] = notexq;
	chax_(ch__1, (ftnlen)1, &c__92);
	i__1[1] = 1, a__1[1] = ch__1;
	i__1[2] = 1, a__1[2] = char1q;
	s_cat(notexq, a__1, i__1, &c__3, (ftnlen)79);
    } else {
/* Writing concatenation */
	chax_(ch__1, (ftnlen)1, &c__92);
	i__2[0] = 1, a__2[0] = ch__1;
	i__2[1] = 1, a__2[1] = char1q;
	s_cat(notexq, a__2, i__2, &c__2, (ftnlen)79);
    }
    *lnote += 2;
    i__3 = *n;
    for (im = 1; im <= i__3; ++im) {
/* Writing concatenation */
	i__2[0] = *lnote, a__2[0] = notexq;
	i__2[1] = 1, a__2[1] = "b";
	s_cat(notexq, a__2, i__2, &c__2, (ftnlen)79);
	++(*lnote);
/* L3: */
    }

/*  add the number, 0 if 12 */

    i__3 = *iv % 12;
    istring_(&i__3, tempq, &len, (ftnlen)4);
/* Writing concatenation */
    i__1[0] = *lnote, a__1[0] = notexq;
    i__1[1] = 1, a__1[1] = ulqq;
    i__1[2] = len, a__1[2] = tempq;
    s_cat(notexq, a__1, i__1, &c__3, (ftnlen)79);
    *lnote = *lnote + 1 + len;
    return 0;
} /* ntrbbb_ */

/* Subroutine */ int addstr_(notexq, lnote, soutq, lsout, notexq_len, 
	soutq_len)
char *notexq;
integer *lnote;
char *soutq;
integer *lsout;
ftnlen notexq_len;
ftnlen soutq_len;
{
    /* System generated locals */
    address a__1[2];
    integer i__1[2];
    char ch__1[81];

    /* Builtin functions */
    integer s_wsfe();
    /* Subroutine */ int s_cat();
    integer do_fio(), e_wsfe();
    /* Subroutine */ int s_copy();

    /* Fortran I/O blocks */
    static cilist io___829 = { 0, 11, 0, "(a)", 0 };


    if (*lsout + *lnote > 72) {
	if (comlast_1.islast) {
	    s_wsfe(&io___829);
/* Writing concatenation */
	    i__1[0] = *lsout, a__1[0] = soutq;
	    i__1[1] = 1, a__1[1] = "%";
	    s_cat(ch__1, a__1, i__1, &c__2, (ftnlen)81);
	    do_fio(&c__1, ch__1, *lsout + 1);
	    e_wsfe();
	}
	*lsout = 0;
    }
    if (*lsout > 0) {
/* Writing concatenation */
	i__1[0] = *lsout, a__1[0] = soutq;
	i__1[1] = *lnote, a__1[1] = notexq;
	s_cat(soutq, a__1, i__1, &c__2, (ftnlen)80);
    } else {
	s_copy(soutq, notexq, (ftnlen)80, (*lnote));
    }
    *lsout += *lnote;
    return 0;
} /* addstr_ */

/* Subroutine */ int notefq_(noteq, lnote, nolev, ncmid, noteq_len)
char *noteq;
integer *lnote, *nolev, *ncmid;
ftnlen noteq_len;
{
    /* System generated locals */
    integer i__1;
    char ch__1[1], ch__2[1];
    icilist ici__1;

    /* Builtin functions */
    /* Subroutine */ int s_copy();
    integer s_wsfi(), do_fio(), e_wsfi();

    /* Local variables */
    static integer i__;
    extern /* Character */ VOID chax_();
    static integer iname, ioctup;
    static char noteqt[1];
    extern /* Character */ VOID upcaseq_();
    static integer nupfroma;


/*  Returns name of note level with octave transpositions, updates noctup. */

    nupfroma = (*nolev + 1) % 7;
    iname = nupfroma + 97;
    ioctup = (*nolev + 1) / 7 - 4;
    chax_(ch__1, (ftnlen)1, &iname);
    *(unsigned char *)noteqt = *(unsigned char *)&ch__1[0];
    if (*ncmid == 23) {
	upcaseq_(ch__1, (ftnlen)1, noteqt, (ftnlen)1);
	*(unsigned char *)noteqt = *(unsigned char *)&ch__1[0];
    }
    if (ioctup == comoct_1.noctup) {
	s_copy(noteq, noteqt, (ftnlen)8, (ftnlen)1);
	*lnote = 1;

/*  Must ALWAYS check if lnote=1 for use with functions requiring a blank */

    } else if (ioctup > comoct_1.noctup) {

/*  Raise octave.  Encase in {} */

	ici__1.icierr = 0;
	ici__1.icirnum = 1;
	ici__1.icirlen = 8;
	ici__1.iciunit = noteq;
	ici__1.icifmt = "(8a1)";
	s_wsfi(&ici__1);
	do_fio(&c__1, "{", (ftnlen)1);
	i__1 = ioctup - 1;
	for (i__ = comoct_1.noctup; i__ <= i__1; ++i__) {
	    chax_(ch__2, (ftnlen)1, &c__39);
	    *(unsigned char *)&ch__1[0] = *(unsigned char *)&ch__2[0];
	    do_fio(&c__1, ch__1, (ftnlen)1);
	}
	do_fio(&c__1, noteqt, (ftnlen)1);
	do_fio(&c__1, "}", (ftnlen)1);
	e_wsfi();
	*lnote = ioctup + 3 - comoct_1.noctup;
	comoct_1.noctup = ioctup;
    } else {

/*  Lower octave */

	ici__1.icierr = 0;
	ici__1.icirnum = 1;
	ici__1.icirlen = 8;
	ici__1.iciunit = noteq;
	ici__1.icifmt = "(8a1)";
	s_wsfi(&ici__1);
	do_fio(&c__1, "{", (ftnlen)1);
	i__1 = comoct_1.noctup - 1;
	for (i__ = ioctup; i__ <= i__1; ++i__) {
	    chax_(ch__2, (ftnlen)1, &c__96);
	    *(unsigned char *)&ch__1[0] = *(unsigned char *)&ch__2[0];
	    do_fio(&c__1, ch__1, (ftnlen)1);
	}
	do_fio(&c__1, noteqt, (ftnlen)1);
	do_fio(&c__1, "}", (ftnlen)1);
	e_wsfi();
	*lnote = comoct_1.noctup + 3 - ioctup;
	comoct_1.noctup = ioctup;
    }
    return 0;
} /* notefq_ */

/* Subroutine */ int notex_(notexq, lnote, notexq_len)
char *notexq;
integer *lnote;
ftnlen notexq_len;
{
    /* System generated locals */
    address a__1[4], a__2[3], a__3[5], a__4[2];
    integer i__1, i__2, i__3[4], i__4[3], i__5[5], i__6[2];
    real r__1;
    char ch__1[1];

    /* Builtin functions */
    integer i_nint();
    /* Subroutine */ int s_cat(), s_copy();
    integer pow_ii(), s_wsfi(), do_fio(), e_wsfi(), i_sign();

    /* Local variables */
    static integer ip;
    static char udq[1];
    extern integer log2_();
    extern /* Character */ VOID chax_();
    static integer nole, ldot, nodu;
    static char dotq[2];
    extern /* Character */ VOID udqq_();
    static real zmin;
    extern integer ncmid_();
    static real fnole;
    static char noteq[8];
    static integer lrest;
    static char restq[8];
    extern /* Subroutine */ int notefq_();
    static integer lnoten;
    extern /* Subroutine */ int addblank_();

    /* Fortran I/O blocks */
    static icilist io___847 = { 0, noteq, 0, "(i2)", 2, 1 };
    static icilist io___848 = { 0, noteq+1, 0, "(i2)", 2, 1 };
    static icilist io___849 = { 0, noteq+1, 0, "(i3)", 3, 1 };



/*  Returns non-beamed full note name */

    ip = all_1.ipo[all_1.jn - 1];
    nole = all_1.nolev[commvl_1.ivx + ip * 15 - 16];
    nodu = all_1.nodur[commvl_1.ivx + ip * 15 - 16];
    if (! bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],0)) {
	i__1 = ncmid_(&all_1.iv, &ip);
	udqq_(ch__1, (ftnlen)1, &nole, &i__1, &all_1.islur[commvl_1.ivx + ip *
		 15 - 16], &commvl_1.nvmx[all_1.iv - 1], &commvl_1.ivx, &
		all_1.nv);
	*(unsigned char *)udq = *(unsigned char *)&ch__1[0];
    }

/*  Check figure level */

    if (all_1.figbass && commvl_1.ivx == 1 && all_1.isfig[ip - 1] && ! 
	    bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],0)) {
	if (*(unsigned char *)udq == 'u') {

/*  Upper stem, fnole (in noleunits) set by notehead */

	    fnole = (real) nole;
	} else {

/*  Lower stem, fnole set by bottom of stem */

	    fnole = nole - all_1.stemlen;
	}
	zmin = fnole - ncmid_(&c__1, &ip) + 4;
/* Computing MAX */
	r__1 = 4 - zmin;
	i__1 = all_1.ifigdrop[all_1.iline - 1], i__2 = i_nint(&r__1);
	all_1.ifigdrop[all_1.iline - 1] = max(i__1,i__2);
    }
    if (! bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],0)) {
	i__1 = ncmid_(&all_1.iv, &ip);
	notefq_(noteq, &lnoten, &nole, &i__1, (ftnlen)8);
	if (lnoten == 1) {
	    addblank_(noteq, &lnoten, (ftnlen)8);
	}
	if (nodu == 1) {
/* Writing concatenation */
	    i__3[0] = 1, a__1[0] = all_1.sq;
	    i__3[1] = 4, a__1[1] = "cccc";
	    i__3[2] = 1, a__1[2] = udq;
	    i__3[3] = lnoten, a__1[3] = noteq;
	    s_cat(notexq, a__1, i__3, &c__4, (ftnlen)79);
	    *lnote = lnoten + 6;
	} else if (nodu == 2) {
/* Writing concatenation */
	    i__3[0] = 1, a__1[0] = all_1.sq;
	    i__3[1] = 3, a__1[1] = "ccc";
	    i__3[2] = 1, a__1[2] = udq;
	    i__3[3] = lnoten, a__1[3] = noteq;
	    s_cat(notexq, a__1, i__3, &c__4, (ftnlen)79);
	    *lnote = lnoten + 5;
	} else if (nodu == 4) {
/* Writing concatenation */
	    i__3[0] = 1, a__1[0] = all_1.sq;
	    i__3[1] = 2, a__1[1] = "cc";
	    i__3[2] = 1, a__1[2] = udq;
	    i__3[3] = lnoten, a__1[3] = noteq;
	    s_cat(notexq, a__1, i__3, &c__4, (ftnlen)79);
	    *lnote = lnoten + 4;
	} else if (nodu == 8) {
/* Writing concatenation */
	    i__3[0] = 1, a__1[0] = all_1.sq;
	    i__3[1] = 1, a__1[1] = "c";
	    i__3[2] = 1, a__1[2] = udq;
	    i__3[3] = lnoten, a__1[3] = noteq;
	    s_cat(notexq, a__1, i__3, &c__4, (ftnlen)79);
	    *lnote = lnoten + 3;
	} else if (nodu == 16) {
/* Writing concatenation */
	    i__3[0] = 1, a__1[0] = all_1.sq;
	    i__3[1] = 1, a__1[1] = "q";
	    i__3[2] = 1, a__1[2] = udq;
	    i__3[3] = lnoten, a__1[3] = noteq;
	    s_cat(notexq, a__1, i__3, &c__4, (ftnlen)79);
	    *lnote = lnoten + 3;
	} else if (nodu == 32) {
/* Writing concatenation */
	    i__3[0] = 1, a__1[0] = all_1.sq;
	    i__3[1] = 1, a__1[1] = "h";
	    i__3[2] = 1, a__1[2] = udq;
	    i__3[3] = lnoten, a__1[3] = noteq;
	    s_cat(notexq, a__1, i__3, &c__4, (ftnlen)79);
	    *lnote = lnoten + 3;
	} else if (nodu == 64) {
/* Writing concatenation */
	    i__4[0] = 1, a__2[0] = all_1.sq;
	    i__4[1] = 2, a__2[1] = "wh";
	    i__4[2] = lnoten, a__2[2] = noteq;
	    s_cat(notexq, a__2, i__4, &c__3, (ftnlen)79);
	    *lnote = lnoten + 3;
	} else if (nodu == 128) {
/*          notexq =sq//'zbreve'//noteq(1:lnoten)//sq//'sk' */
/*          lnote = lnoten+10 */
/* Writing concatenation */
	    i__4[0] = 1, a__2[0] = all_1.sq;
	    i__4[1] = 5, a__2[1] = "breve";
	    i__4[2] = lnoten, a__2[2] = noteq;
	    s_cat(notexq, a__2, i__4, &c__3, (ftnlen)79);
	    *lnote = lnoten + 6;
	} else {
	    s_copy(dotq, "p", (ftnlen)2, (ftnlen)1);
	    ldot = 1;
	    if (bit_test(all_1.iornq[commvl_1.ivx + ip * 15 - 1],13)) {

/*  Dotted note with ')' ornament */

		s_copy(dotq, "m", (ftnlen)2, (ftnlen)1);
	    } else if (bit_test(all_1.islur[commvl_1.ivx + ip * 15 - 16],3)) {

/*  Double dot */

		s_copy(dotq, "pp", (ftnlen)2, (ftnlen)2);
		ldot = 2;
	    }
	    if (nodu >= 96) {
/* Writing concatenation */
		i__3[0] = 1, a__1[0] = all_1.sq;
		i__3[1] = 2, a__1[1] = "wh";
		i__3[2] = ldot, a__1[2] = dotq;
		i__3[3] = lnoten, a__1[3] = noteq;
		s_cat(notexq, a__1, i__3, &c__4, (ftnlen)79);
		*lnote = lnoten + 3 + ldot;
	    } else if (nodu >= 48) {
/* Writing concatenation */
		i__5[0] = 1, a__3[0] = all_1.sq;
		i__5[1] = 1, a__3[1] = "h";
		i__5[2] = 1, a__3[2] = udq;
		i__5[3] = ldot, a__3[3] = dotq;
		i__5[4] = lnoten, a__3[4] = noteq;
		s_cat(notexq, a__3, i__5, &c__5, (ftnlen)79);
		*lnote = lnoten + 3 + ldot;
	    } else if (nodu >= 24) {
/* Writing concatenation */
		i__5[0] = 1, a__3[0] = all_1.sq;
		i__5[1] = 1, a__3[1] = "q";
		i__5[2] = 1, a__3[2] = udq;
		i__5[3] = ldot, a__3[3] = dotq;
		i__5[4] = lnoten, a__3[4] = noteq;
		s_cat(notexq, a__3, i__5, &c__5, (ftnlen)79);
		*lnote = lnoten + 3 + ldot;
	    } else if (nodu >= 12) {
/* Writing concatenation */
		i__5[0] = 1, a__3[0] = all_1.sq;
		i__5[1] = 1, a__3[1] = "c";
		i__5[2] = 1, a__3[2] = udq;
		i__5[3] = ldot, a__3[3] = dotq;
		i__5[4] = lnoten, a__3[4] = noteq;
		s_cat(notexq, a__3, i__5, &c__5, (ftnlen)79);
		*lnote = lnoten + 3 + ldot;
	    } else if (nodu >= 6) {
/* Writing concatenation */
		i__5[0] = 1, a__3[0] = all_1.sq;
		i__5[1] = 2, a__3[1] = "cc";
		i__5[2] = 1, a__3[2] = udq;
		i__5[3] = ldot, a__3[3] = dotq;
		i__5[4] = lnoten, a__3[4] = noteq;
		s_cat(notexq, a__3, i__5, &c__5, (ftnlen)79);
		*lnote = lnoten + 4 + ldot;
		compoi_1.ispoi = TRUE_;
	    } else {
/* Writing concatenation */
		i__5[0] = 1, a__3[0] = all_1.sq;
		i__5[1] = 3, a__3[1] = "ccc";
		i__5[2] = 1, a__3[2] = udq;
		i__5[3] = ldot, a__3[3] = dotq;
		i__5[4] = lnoten, a__3[4] = noteq;
		s_cat(notexq, a__3, i__5, &c__5, (ftnlen)79);
		*lnote = lnoten + 5 + ldot;
		compoi_1.ispoi = TRUE_;
	    }
	    if (*(unsigned char *)dotq == 'm') {

/*  Need another call to the note, in case the first one has octave shifts */

		if (lnoten == 2) {
/* Writing concatenation */
		    i__3[0] = *lnote, a__1[0] = notexq;
		    i__3[1] = 1, a__1[1] = "{";
		    i__3[2] = 1, a__1[2] = noteq + 1;
		    i__3[3] = 1, a__1[3] = "}";
		    s_cat(notexq, a__1, i__3, &c__4, (ftnlen)79);
		    *lnote += 3;
		} else {
		    i__1 = lnoten - 2;
/* Writing concatenation */
		    i__6[0] = *lnote, a__4[0] = notexq;
		    i__6[1] = lnoten - 1 - i__1, a__4[1] = noteq + i__1;
		    s_cat(notexq, a__4, i__6, &c__2, (ftnlen)79);
		    ++(*lnote);
		}
	    }
	}
    } else if (bit_test(all_1.islur[commvl_1.ivx + ip * 15 - 16],29)) {

/*  Blank rest */

/* Writing concatenation */
	i__6[0] = 1, a__4[0] = all_1.sq;
	i__6[1] = 2, a__4[1] = "sk";
	s_cat(notexq, a__4, i__6, &c__2, (ftnlen)79);
	*lnote = 3;
    } else {

/*  Non-blank rest */

	*lnote = 0;
	nole = (nole + 20) % 100 - 20;

/*  Kluge to get pause symbol for rp: */

	if (bit_test(all_1.islur[commvl_1.ivx + ip * 15 - 16],19)) {
	    nodu = 64;
	}
	if (nodu <= 28) {

/*  Normal rest < or = double-dotted quarter */

	    lrest = 3;
	    if (nodu > 14) {
/* Writing concatenation */
		i__6[0] = 1, a__4[0] = all_1.sq;
		i__6[1] = 2, a__4[1] = "qp";
		s_cat(restq, a__4, i__6, &c__2, (ftnlen)8);
	    } else if (nodu > 7) {
/* Writing concatenation */
		i__6[0] = 1, a__4[0] = all_1.sq;
		i__6[1] = 2, a__4[1] = "ds";
		s_cat(restq, a__4, i__6, &c__2, (ftnlen)8);
	    } else if (nodu > 3) {
/* Writing concatenation */
		i__6[0] = 1, a__4[0] = all_1.sq;
		i__6[1] = 2, a__4[1] = "qs";
		s_cat(restq, a__4, i__6, &c__2, (ftnlen)8);
	    } else if (nodu > 1) {
/* Writing concatenation */
		i__6[0] = 1, a__4[0] = all_1.sq;
		i__6[1] = 2, a__4[1] = "hs";
		s_cat(restq, a__4, i__6, &c__2, (ftnlen)8);
	    } else {
/* Writing concatenation */
		i__6[0] = 1, a__4[0] = all_1.sq;
		i__6[1] = 3, a__4[1] = "qqs";
		s_cat(restq, a__4, i__6, &c__2, (ftnlen)8);
		lrest = 4;
	    }
	    i__1 = log2_(&nodu);
	    if (pow_ii(&c__2, &i__1) != nodu) {

/*  One or two dots on rest */

/* Writing concatenation */
		i__6[0] = 3, a__4[0] = restq;
		i__6[1] = 1, a__4[1] = "p";
		s_cat(restq, a__4, i__6, &c__2, (ftnlen)8);
		lrest = 4;
		i__1 = log2_(&nodu);
		if (nodu << 1 > pow_ii(&c__2, &i__1) * 3) {

/*  Double dotted rest */

/* Writing concatenation */
		    i__6[0] = 4, a__4[0] = restq;
		    i__6[1] = 1, a__4[1] = "p";
		    s_cat(restq, a__4, i__6, &c__2, (ftnlen)8);
		    lrest = 5;
		}
	    }
	    s_copy(notexq, restq, (ftnlen)79, (ftnlen)8);
	    *lnote = lrest;

/*  At this point notexq=restq,lnote=lrest are name of rest.  Now raise if necc. */

	    if (nole != 0) {
		if (abs(nole) < 10) {
		    i__1 = abs(nole) + 48;
		    chax_(ch__1, (ftnlen)1, &i__1);
		    s_copy(noteq, ch__1, (ftnlen)8, (ftnlen)1);
		    lnoten = 1;
		} else {
		    s_wsfi(&io___847);
		    i__1 = abs(nole);
		    do_fio(&c__1, (char *)&i__1, (ftnlen)sizeof(integer));
		    e_wsfi();
		    lnoten = 2;
		}
		if (nole > 0) {
/* Writing concatenation */
		    i__5[0] = 1, a__3[0] = all_1.sq;
		    i__5[1] = 5, a__3[1] = "raise";
		    i__5[2] = lnoten, a__3[2] = noteq;
		    i__5[3] = 1, a__3[3] = all_1.sq;
		    i__5[4] = 9, a__3[4] = "internote";
		    s_cat(notexq, a__3, i__5, &c__5, (ftnlen)79);
		} else {
/* Writing concatenation */
		    i__5[0] = 1, a__3[0] = all_1.sq;
		    i__5[1] = 5, a__3[1] = "lower";
		    i__5[2] = lnoten, a__3[2] = noteq;
		    i__5[3] = 1, a__3[3] = all_1.sq;
		    i__5[4] = 9, a__3[4] = "internote";
		    s_cat(notexq, a__3, i__5, &c__5, (ftnlen)79);
		}
		*lnote = lnoten + 16;
		i__1 = log2_(&nodu);
		if (pow_ii(&c__2, &i__1) != nodu) {

/*  Have dot in raised rest.  must put in hbox! */

/* Writing concatenation */
		    i__4[0] = *lnote, a__2[0] = notexq;
		    i__4[1] = 1, a__2[1] = all_1.sq;
		    i__4[2] = 5, a__2[2] = "hbox{";
		    s_cat(notexq, a__2, i__4, &c__3, (ftnlen)79);
		    *lnote += 6;
		}
/* Writing concatenation */
		i__6[0] = *lnote, a__4[0] = notexq;
		i__6[1] = lrest, a__4[1] = restq;
		s_cat(notexq, a__4, i__6, &c__2, (ftnlen)79);
		*lnote += lrest;
		i__1 = log2_(&nodu);
		if (pow_ii(&c__2, &i__1) != nodu) {
/* Writing concatenation */
		    i__6[0] = *lnote, a__4[0] = notexq;
		    i__6[1] = 1, a__4[1] = "}";
		    s_cat(notexq, a__4, i__6, &c__2, (ftnlen)79);
		    ++(*lnote);
		}
	    }
	} else {

/*  Half or whole rest */

	    if (nole == 0) {

/*  Half or whole rest is not raised or lowered */

		if (nodu <= 56) {
/* Writing concatenation */
		    i__6[0] = 1, a__4[0] = all_1.sq;
		    i__6[1] = 6, a__4[1] = "hpause";
		    s_cat(notexq, a__4, i__6, &c__2, (ftnlen)79);
		    *lnote = 7;
/*            else if (nodu .le. 112) then */
/*              notexq =sq//'pause' */
/*              lnote = 6 */
		} else if (nodu <= 112) {
/*              if (.not.btest(islur(ivx,ip),19)) then */
		    if (! bit_test(all_1.islur[commvl_1.ivx + ip * 15 - 16],
			    19) || bit_test(all_1.irest[commvl_1.ivx + ip * 
			    15 - 16],25)) {
/* Writing concatenation */
			i__6[0] = 1, a__4[0] = all_1.sq;
			i__6[1] = 5, a__4[1] = "pause";
			s_cat(notexq, a__4, i__6, &c__2, (ftnlen)79);
		    } else {
/* Writing concatenation */
			i__6[0] = 1, a__4[0] = all_1.sq;
			i__6[1] = 5, a__4[1] = "pausc";
			s_cat(notexq, a__4, i__6, &c__2, (ftnlen)79);
		    }
		    *lnote = 6;
		} else {
/* Writing concatenation */
		    i__6[0] = 1, a__4[0] = all_1.sq;
		    i__6[1] = 5, a__4[1] = "PAuse";
		    s_cat(notexq, a__4, i__6, &c__2, (ftnlen)79);
		    *lnote = 6;
		}
		i__1 = log2_(&nodu);
		if (pow_ii(&c__2, &i__1) != nodu) {

/*  Dotted rest, hpause or longer */

/* Writing concatenation */
		    i__6[0] = *lnote, a__4[0] = notexq;
		    i__6[1] = 1, a__4[1] = "p";
		    s_cat(notexq, a__4, i__6, &c__2, (ftnlen)79);
		    ++(*lnote);
		    i__1 = log2_(&nodu);
		    if (nodu << 1 > pow_ii(&c__2, &i__1) * 3) {

/*  Double dotted long rest */

/* Writing concatenation */
			i__6[0] = *lnote, a__4[0] = notexq;
			i__6[1] = 1, a__4[1] = "p";
			s_cat(notexq, a__4, i__6, &c__2, (ftnlen)79);
			++(*lnote);
		    }
		}
	    } else {

/*  Raised or lowered half or whole rest */

		if (nodu == 32) {
/* Writing concatenation */
		    i__6[0] = 1, a__4[0] = all_1.sq;
		    i__6[1] = 10, a__4[1] = "lifthpause";
		    s_cat(notexq, a__4, i__6, &c__2, (ftnlen)79);
		    *lnote = 11;
		} else if (nodu == 48) {
/* Writing concatenation */
		    i__6[0] = 1, a__4[0] = all_1.sq;
		    i__6[1] = 11, a__4[1] = "lifthpausep";
		    s_cat(notexq, a__4, i__6, &c__2, (ftnlen)79);
		    *lnote = 12;
		} else if (nodu == 56) {
/* Writing concatenation */
		    i__6[0] = 1, a__4[0] = all_1.sq;
		    i__6[1] = 12, a__4[1] = "lifthpausepp";
		    s_cat(notexq, a__4, i__6, &c__2, (ftnlen)79);
		    *lnote = 13;
		} else if (nodu == 64) {
/* Writing concatenation */
		    i__6[0] = 1, a__4[0] = all_1.sq;
		    i__6[1] = 9, a__4[1] = "liftpause";
		    s_cat(notexq, a__4, i__6, &c__2, (ftnlen)79);
		    *lnote = 10;
		} else if (nodu == 96) {
/* Writing concatenation */
		    i__6[0] = 1, a__4[0] = all_1.sq;
		    i__6[1] = 10, a__4[1] = "liftpausep";
		    s_cat(notexq, a__4, i__6, &c__2, (ftnlen)79);
		    *lnote = 11;
		} else if (nodu == 112) {
/* Writing concatenation */
		    i__6[0] = 1, a__4[0] = all_1.sq;
		    i__6[1] = 11, a__4[1] = "liftpausepp";
		    s_cat(notexq, a__4, i__6, &c__2, (ftnlen)79);
		    *lnote = 12;
		} else {

/*  Assume double whole rest */

/* Writing concatenation */
		    i__6[0] = 1, a__4[0] = all_1.sq;
		    i__6[1] = 9, a__4[1] = "liftPAuse";
		    s_cat(notexq, a__4, i__6, &c__2, (ftnlen)79);
		    *lnote = 10;
		}

/*  Set up height spec */

		i__1 = abs(nole) / 2;
		nole = i_sign(&i__1, &nole);
		if (nole <= 9 && nole >= 0) {
		    i__1 = nole + 48;
		    chax_(ch__1, (ftnlen)1, &i__1);
		    s_copy(noteq, ch__1, (ftnlen)8, (ftnlen)1);
		    lnoten = 1;
		} else {
		    s_copy(noteq, "{", (ftnlen)8, (ftnlen)1);
		    if (nole >= -9) {
			s_wsfi(&io___848);
			do_fio(&c__1, (char *)&nole, (ftnlen)sizeof(integer));
			e_wsfi();
			lnoten = 3;
		    } else {
			s_wsfi(&io___849);
			do_fio(&c__1, (char *)&nole, (ftnlen)sizeof(integer));
			e_wsfi();
			lnoten = 4;
		    }
/* Writing concatenation */
		    i__6[0] = lnoten, a__4[0] = noteq;
		    i__6[1] = 1, a__4[1] = "}";
		    s_cat(noteq, a__4, i__6, &c__2, (ftnlen)8);
		    ++lnoten;
		}
/* Writing concatenation */
		i__6[0] = *lnote, a__4[0] = notexq;
		i__6[1] = lnoten, a__4[1] = noteq;
		s_cat(notexq, a__4, i__6, &c__2, (ftnlen)79);
		*lnote += lnoten;
	    }
	}
    }
    return 0;
} /* notex_ */

/* Character */ VOID udqq_(ret_val, ret_val_len, nole, ncm, isl, nvmx, ivx, 
	nv)
char *ret_val;
ftnlen ret_val_len;
integer *nole, *ncm, *isl, *nvmx, *ivx, *nv;
{
    /* System generated locals */
    real r__1;
    char ch__2[1];

    /* Local variables */
    extern /* Character */ VOID ulfq_();
    static char udqqq[1];


/*  Stem direction for single notes */

    if (bit_test(*isl,30)) {

/*  Absolute override */

	if (bit_test(*isl,17)) {
	    *(unsigned char *)udqqq = 'u';
	} else {
	    *(unsigned char *)udqqq = 'l';
	}
    } else if (*nvmx == 1) {

/*  Single voice per staff, default */

	r__1 = *nole * (float)1.;
	ulfq_(ch__2, (ftnlen)1, &r__1, ncm);
	*(unsigned char *)udqqq = *(unsigned char *)&ch__2[0];
    } else {

/*  Multi-voice per staff, 1st is lower, 2nd upper */

	if (*ivx <= *nv) {
	    *(unsigned char *)udqqq = 'l';
	} else {
	    *(unsigned char *)udqqq = 'u';
	}
    }
    *(unsigned char *)ret_val = *(unsigned char *)udqqq;
    return ;
} /* udqq_ */

/* Subroutine */ int findbeam_(ibmrep, numbms, mapfb)
integer *ibmrep, *numbms, *mapfb;
{
    /* Initialized data */

    static integer nip1[48] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
    static integer nip2[48] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
    static integer nummask[3] = { 29,49,12 };
    static integer mask[147]	/* was [49][3] */ = { 65535,4095,65520,255,
	    65280,63,252,16128,64512,15,240,3840,61440,7,14,112,224,1792,3584,
	    28672,57344,3,12,48,192,768,3072,12288,49152,0,0,0,0,0,0,0,0,0,0,
	    0,0,0,0,0,0,0,0,0,0,16777215,65535,16776960,4095,65520,1048320,
	    16773120,255,65280,16711680,63,252,16128,64512,4128768,16515072,
	    15,60,240,3840,15360,61440,983040,3932160,15728640,7,14,112,224,
	    1792,3584,28672,57344,458752,917504,7340032,14680064,3,12,48,192,
	    768,3072,12288,49152,196608,786432,3145728,12582912,4095,255,4080,
	    15,240,3840,3,12,48,192,768,3072,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
    static logical eqonly[147]	/* was [49][3] */ = { TRUE_,TRUE_,TRUE_,
	    FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,
	    FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,
	    FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,
	    FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,
	    FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,
	    FALSE_,TRUE_,TRUE_,TRUE_,TRUE_,TRUE_,TRUE_,TRUE_,FALSE_,FALSE_,
	    FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,
	    FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,
	    FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,
	    FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,
	    FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,
	    FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,
	    FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,
	    FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,
	    FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,
	    FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_,FALSE_ };

    /* System generated locals */
    integer i__1, i__2, i__3, i__4;
    real r__1, r__2;

    /* Builtin functions */
    integer lbit_shift(), s_wsle(), do_lio(), e_wsle();
    double r_mod();

    /* Local variables */
    static integer ib, ip, ir, it, is, ib1, ib2, ir1, is1, is2, it2, iip, ipr[
	    48], itr[48], mape, mapm, irep, maps, nreal, itend, itoff, maskm, 
	    nodue[48], itseg, mtemp;
    static logical short__[48];
    static integer itnow, ithalf, numnew;
    extern /* Subroutine */ int logbeam_();
    static integer masknow;

    /* Fortran I/O blocks */
    static cilist io___884 = { 0, 6, 0, 0, 0 };



/*  Called once per voice per bar, after setting forced beams. */

    /* Parameter adjustments */
    --mapfb;
    --numbms;

    /* Function Body */
    ip = 0;
    nreal = 0;
    itnow = 0;
L1:
    ++ip;
    if (ip > all_1.nn[commvl_1.ivx - 1]) {
	goto L9;
    }
L11:
    if (all_1.nodur[commvl_1.ivx + ip * 15 - 16] == 0) {

/*  Ignore all xtup notes except the last, the one with nodur > 0 . */
/*  Xtups are irrelevant here since they are already all in forced beams. */
/*  Will update itnow by nodur at the END of this loop */

	++ip;
	goto L11;
    }
    ++nreal;
    nodue[nreal - 1] = all_1.nodur[commvl_1.ivx + ip * 15 - 16];
    short__[nreal - 1] = nodue[nreal - 1] < 16 && ! bit_test(all_1.irest[
	    commvl_1.ivx + ip * 15 - 16],0) && ! bit_test(all_1.islur[
	    commvl_1.ivx + ip * 15 - 16],18);

/*  Rule out notes that have 'alone'-flag set */

    ipr[nreal - 1] = ip;
    itr[nreal - 1] = itnow;
    if (nodue[nreal - 1] == 1) {

/*  64th gap */

	if (itnow % 2 == 0) {

/*  Start of 32nd gap, lump with following note */

	    ++ip;
	    nodue[nreal - 1] = all_1.nodur[commvl_1.ivx + ip * 15 - 16] + 1;
	    itnow += nodue[nreal - 1];
	} else {

/*  End of 32nd gap, lump with preceeding note */

	    --nreal;
	    ++nodue[nreal - 1];
	    ++itnow;
	}
    } else {
	itnow += all_1.nodur[commvl_1.ivx + ip * 15 - 16];
    }
    goto L1;
L9:
    ir1 = 1;
    itseg = all_1.lenbar / *ibmrep;
    i__1 = *ibmrep;
    for (irep = 1; irep <= i__1; ++irep) {

/*  Set bitmaps for all shorts neighbored by a short. Each bit represents a */
/*  span of 32nd note.  maps, mapm, mape record start, full duration, and end */
/*  of consecutive span of beamable (<1/4) notes. */

	maps = 0;
	mapm = 0;
	mape = 0;
	itend = itseg * irep;
	itoff = itend - itseg;
	i__2 = nreal;
	for (ir = ir1; ir <= i__2; ++ir) {
	    it2 = itr[ir - 1] + nodue[ir - 1] - 2;
	    if (it2 >= itend) {
		ir1 = ir;
		goto L14;
	    }
/*         if (short(ir).and.((ir.gt.1.and.short(ir-1)).or.(ir.lt.nreal */
/* Computing MAX */
	    i__3 = ir - 1;
	    if (short__[ir - 1] && (ir > 1 && short__[max(i__3,1) - 1] || ir <
		     nreal && short__[ir])) {
		ib1 = (itr[ir - 1] - itoff) / 2;
		ib2 = (it2 - itoff) / 2;
		if (max(ib1,ib2) > 47 || ir > 48 || min(ib1,ib2) < 0) {
		    return 0;
		}

/*  Must have an odd number obe beats in a long bar.  Auto-beam won't work */

		nip1[ib1] = ipr[ir - 1];
		nip2[ib2] = ipr[ir - 1];

/*  nip1,2(ib) = 0 unless a real note starts,ends on bit ib; then = ip */

		maps = bit_set(maps,ib1);
		mape = bit_set(mape,ib2);
		i__3 = ib2;
		for (ib = ib1; ib <= i__3; ++ib) {
		    mapm = bit_set(mapm,ib);
/* L3: */
		}
	    }
/* L2: */
	}
L14:
	if (mapm == 0) {
	    goto L13;
	}

/*  Zero out bits from forced beams */

	maps &= ~ mapfb[irep];
	mapm &= ~ mapfb[irep];
	mape &= ~ mapfb[irep];

/*  Compare map with template. */

	i__2 = nummask[combeam_1.ibmtyp - 1];
	for (it = 1; it <= i__2; ++it) {
	    masknow = mask[it + combeam_1.ibmtyp * 49 - 50];
	    if ((masknow & mapm) == masknow) {

/*  Find least significant bit in the mask to check start time */

		mtemp = masknow;
		maskm = masknow;
		for (is1 = 0; is1 <= 47; ++is1) {
		    if ((1 & mtemp) == 1) {
			goto L6;
		    }
		    mtemp = lbit_shift(mtemp, (ftnlen)-1);
/* L5: */
		}
L6:
		if ((lbit_shift((ftnlen)1, is1) & maps) == 0) {
		    goto L4;
		}

/*  is1 is the bit where the beam starts.  Continue shifting to */
/*  find most significant bit in the mask to check ending time */

		for (is2 = is1; is2 <= 47; ++is2) {
		    mtemp = lbit_shift(mtemp, (ftnlen)-1);
		    if ((1 & ~ mtemp) == 1) {
			goto L8;
		    }
/* L7: */
		}
L8:

/*  is2 is now the bit on which the beam ends. */

		if ((lbit_shift((ftnlen)1, is2) & mape) == 0) {
		    goto L4;
		}

/*  Did we pick out a single note from the middle of a longer sequence? */

		if (nip1[is1] == nip2[is2]) {
		    goto L4;
		}

/*  We almost have a beam.  Check equality of notes if needed. */

		if (eqonly[it + combeam_1.ibmtyp * 49 - 50]) {
		    i__3 = nip2[is2];
		    for (ip = nip1[is1]; ip <= i__3; ++ip) {
			if (all_1.nodur[commvl_1.ivx + ip * 15 - 16] != 8) {

/*  There is a non-1/8th note in this beam. Exit if not 2 quarters */

			    if (is2 - is1 != 15) {
				goto L4;
			    }

/*  Beam is 2 quarters long.  Check if can split in half. */

			    ithalf = 0;
			    i__4 = nip2[is2];
			    for (iip = nip1[is1]; iip <= i__4; ++iip) {
				ithalf += all_1.nodur[commvl_1.ivx + iip * 15 
					- 16];
				if (ithalf > 16) {
				    goto L4;
				}
				if (ithalf == 16) {
				    goto L21;
				}
/* L20: */
			    }
			    s_wsle(&io___884);
			    do_lio(&c__9, &c__1, "Problem in findbeam, pleas\
e call Dr. Don", (ftnlen)40);
			    e_wsle();
			    goto L4;
L21:

/*  Otherwise, split in half by keeping only the first half.  Other half will */
/*  be picked up later, assuming masks are listed longest first. */

			    is2 = is1 + 7;

/*  Reset maskm (since only used part of mask), used later to zero out */
/*  bits that contain beams */

			    maskm = 0;
			    i__4 = is2;
			    for (is = is1; is <= i__4; ++is) {
				maskm = bit_set(maskm,is);
/* L15: */
			    }
			    goto L16;
			}
/* L10: */
		    }
		}
L16:

/*  This is a beam.  If last "effective" ends on odd 64th, add 1 more */

/*            if (abs(mod(to(iand(255,ipl(ivx,nip2(is2)))) */
/*     *           +nodur(ivx,nip2(is2)),2.)) .gt. tol) then */
		r__2 = all_1.to[(255 & all_1.ipl[commvl_1.ivx + nip2[is2] * 
			15 - 16]) - 1] + all_1.nodur[commvl_1.ivx + nip2[is2] 
			* 15 - 16] + comtol_1.tol * (float).5;
		if ((r__1 = r_mod(&r__2, &c_b3023), dabs(r__1)) > 
			comtol_1.tol) {
		    ++nip2[is2];
		}
		++numbms[commvl_1.ivx];
		numnew = numbms[commvl_1.ivx];
		logbeam_(&numnew, &nip1[is1], &nip2[is2]);

/*  Zero out the appropriate bits so these notes don't get used again */

		mapm &= ~ maskm;
		if (mapm == 0) {
		    goto L13;
		}
		maps &= ~ maskm;
		mape &= ~ maskm;
	    }
L4:
	    ;
	}
L13:
	;
    }
    return 0;
} /* findbeam_ */

/* Subroutine */ int logbeam_(numnew, nip1, nip2)
integer *numnew, *nip1, *nip2;
{
    /* System generated locals */
    integer i__1, i__2;
    real r__1;
    char ch__1[1];

    /* Builtin functions */
    double log();

    /* Local variables */
    static integer ib, iip;
    static real sum;
    static integer iip1;
    extern integer log2_();
    static integer iiip;
    extern /* Character */ VOID ulfq_();
    extern integer ncmid_();
    static integer multx, nrests, numnow;
    static logical isxtup;
    extern integer igetbits_();

    all_1.ibm1[commvl_1.ivx + *numnew * 15 - 16] = *nip1;
    all_1.ibm2[commvl_1.ivx + *numnew * 15 - 16] = *nip2;
    numnow = *numnew;
    if (*numnew > 1) {

/*  If it starts before any others, must put it in order */

	for (ib = *numnew - 1; ib >= 1; --ib) {
	    if (all_1.ibm1[commvl_1.ivx + ib * 15 - 16] < *nip1) {
		goto L12;
	    }
	    all_1.ibm1[commvl_1.ivx + (ib + 1) * 15 - 16] = all_1.ibm1[
		    commvl_1.ivx + ib * 15 - 16];
	    all_1.ibm2[commvl_1.ivx + (ib + 1) * 15 - 16] = all_1.ibm2[
		    commvl_1.ivx + ib * 15 - 16];
	    *(unsigned char *)&all_1.ulq[commvl_1.ivx + (ib + 1) * 15 - 16] = 
		    *(unsigned char *)&all_1.ulq[commvl_1.ivx + ib * 15 - 16];
	    all_1.ibm1[commvl_1.ivx + ib * 15 - 16] = *nip1;
	    all_1.ibm2[commvl_1.ivx + ib * 15 - 16] = *nip2;
	    numnow = ib;
/* L11: */
	}
L12:
	;
    }
    sum = (float)0.;

/* Beam has non-xtup within */

    nrests = 0;
    isxtup = FALSE_;
    i__1 = *nip2;
    for (iip = *nip1; iip <= i__1; ++iip) {
	if (bit_test(all_1.islur[commvl_1.ivx + *nip1 * 15 - 16],21)) {

/*  Forced multiplicity */

	    all_1.mult[commvl_1.ivx + iip * 15 - 16] = igetbits_(&all_1.islur[
		    commvl_1.ivx + *nip1 * 15 - 16], &c__3, &c__22);
	} else if (! isxtup) {
	    if (all_1.nodur[commvl_1.ivx + iip * 15 - 16] > 0) {
		all_1.mult[commvl_1.ivx + iip * 15 - 16] = 4 - log2_(&
			all_1.nodur[commvl_1.ivx + iip * 15 - 16]);
	    } else {

/*  Start xtup within forced beam */

		isxtup = TRUE_;
		iip1 = iip;
	    }
	} else if (isxtup && all_1.nodur[commvl_1.ivx + iip * 15 - 16] > 0) {

/*  End of xtup within forced beam */

	    multx = (integer) ((log(iip + (float)1. - iip1) * (float).952 - 
		    log(all_1.nodur[commvl_1.ivx + iip * 15 - 16] / (float)2.)
		    ) / (float).69315 + (float)13.429) - 10;
	    i__2 = iip;
	    for (iiip = iip1; iiip <= i__2; ++iiip) {
		all_1.mult[commvl_1.ivx + iiip * 15 - 16] = multx;
/* L74: */
	    }
	    isxtup = FALSE_;
	}
	if (bit_test(all_1.irest[commvl_1.ivx + iip * 15 - 16],0)) {
	    ++nrests;
	} else {
	    sum += all_1.nolev[commvl_1.ivx + iip * 15 - 16];
	}
/* L9: */
    }

/*  Set beam up-down-ness */

    if (comfb_1.ifb > 0 && *(unsigned char *)&comfb_1.ulfbq[commvl_1.ivx + 
	    max(1,comfb_1.ifb) * 15 - 16] != 'x') {
	*(unsigned char *)&all_1.ulq[commvl_1.ivx + comfb_1.ifb * 15 - 16] = *
		(unsigned char *)&comfb_1.ulfbq[commvl_1.ivx + comfb_1.ifb * 
		15 - 16];

/*  This probably works only because forced beams are done first, so they */
/*  don't have to be re-sorted within each voice. ???? */

    } else if (commvl_1.nvmx[all_1.iv - 1] == 2) {

/*  Multi-voice per staff */

	if (commvl_1.ivx <= all_1.nv) {
	    *(unsigned char *)&all_1.ulq[commvl_1.ivx + numnow * 15 - 16] = 
		    'l';
	} else {
	    *(unsigned char *)&all_1.ulq[commvl_1.ivx + numnow * 15 - 16] = 
		    'u';
	}
    } else {

/*  Defaults */

	r__1 = sum / (*nip2 - *nip1 + 1 - nrests);
	i__1 = ncmid_(&all_1.iv, nip1);
	ulfq_(ch__1, (ftnlen)1, &r__1, &i__1);
	*(unsigned char *)&all_1.ulq[commvl_1.ivx + numnow * 15 - 16] = *(
		unsigned char *)&ch__1[0];
/*    *      ulfq(sum/(nip2-nip1+1),ncmid(iv,nip1)) */
    }
    return 0;
} /* logbeam_ */

/* Character */ VOID ulfq_(ret_val, ret_val_len, xnolev, ncm)
char *ret_val;
ftnlen ret_val_len;
real *xnolev;
integer *ncm;
{
    static real test;


/*  Stem directions */

    test = *xnolev - *ncm;
    if (test < (float)-.001 || test < (float).001 && combc_1.bcspec && *ncm ==
	     23) {
	*(unsigned char *)ret_val = 'u';
    } else {
	*(unsigned char *)ret_val = 'l';
    }
    return ;
} /* ulfq_ */

/* Character */ VOID udfq_(ret_val, ret_val_len, nolev, ncm)
char *ret_val;
ftnlen ret_val_len;
integer *nolev, *ncm;
{
    static integer ntest;


/*  Slur directions */

    ntest = *nolev - *ncm;
    if (ntest < 0 || ntest == 0 && combc_1.bcspec && *ncm == 23) {
	*(unsigned char *)ret_val = 'd';
    } else {
	*(unsigned char *)ret_val = 'u';
    }
    return ;
} /* udfq_ */

integer numclef_(clefq, clefq_len)
char *clefq;
ftnlen clefq_len;
{
    /* System generated locals */
    integer ret_val;

    /* Builtin functions */
    integer i_indx();


/*  Returns the number to be used as argument of \setclef (for MusiXTeX only) */
/*        if (ichar(clefq) .lt. 55) then */
    if (*(unsigned char *)clefq <= 55) {
	ret_val = *(unsigned char *)clefq - 48;
	if (ret_val == 7) {
	    ret_val = 9;
	}
    } else {
	ret_val = i_indx("tsmanrbxxf", clefq, (ftnlen)10, (ftnlen)1) - 1;
    }
    return ret_val;
} /* numclef_ */

doublereal feon_(time)
real *time;
{
    /* System generated locals */
    real ret_val;
    doublereal d__1, d__2;

    /* Builtin functions */
    double sqrt(), pow_dd();

    d__1 = (doublereal) sqrt(*time / 2);
    d__2 = (doublereal) ((float)1. - comeon_1.eonk);
    ret_val = pow_dd(&d__1, &d__2) * comeon_1.ewmxk;
    return ret_val;
} /* feon_ */

/* Subroutine */ int setmeter_(mtrnuml, mtrdenl, ibmtyp, ibmrep)
integer *mtrnuml, *mtrdenl, *ibmtyp, *ibmrep;
{

/*  Sets last 2 args depending on 1st 2, (logical) num, denom. */
/*  ibmtyp = 1, 2, or 3 defines set of masks for beam groupings. */
/*  1: all duple meters */
/*  2: triple w/ denom=4, subdivide in groups of 2 8ths */
/*  3: triple w/ denom=8, subdivide in groups of 3 8ths */
/*  Note that lenbar is set at top or when 'm' symbol is read in getnote */

    if (*mtrdenl == 4) {
	if (*mtrnuml % 3 == 0) {
	    *ibmtyp = 2;
	    *ibmrep = *mtrnuml / 3;
	} else {
	    *ibmtyp = 1;
	    *ibmrep = *mtrnuml / 2;
	}
    } else if (*mtrdenl == 2) {
	*ibmtyp = 1;
	if (*mtrnuml == 3) {
	    *ibmrep = 3;
	} else {
	    *ibmrep = (*mtrnuml << 1) / *mtrdenl;
	}
    } else {

/*  Assumes mtrdenl=8 and 3/8, 6/8, 9/8, or 12/8 */

	*ibmtyp = 3;
	*ibmrep = *mtrnuml / 3;
    }

/*  Reset so we don't keep writing new meters */

    *mtrnuml = 0;

/*  Prevent ibmrep=0.  Needed for odd bars, e.g. 1/8, where beams don't matter */

    *ibmrep = max(*ibmrep,1);
    return 0;
} /* setmeter_ */

/* Subroutine */ int wgmeter_(mtrnmp, mtrdnp)
integer *mtrnmp, *mtrdnp;
{
    /* System generated locals */
    address a__1[4];
    integer i__1[4], i__2;
    char ch__1[1], ch__2[25], ch__3[26], ch__4[21], ch__5[24];

    /* Builtin functions */
    integer s_wsfe();
    /* Subroutine */ int s_cat();
    integer do_fio(), e_wsfe();

    /* Local variables */
    static char sq[1];
    extern /* Character */ VOID chax_();

    /* Fortran I/O blocks */
    static cilist io___899 = { 0, 11, 0, "(a25,i1,a2,i1,a3)", 0 };
    static cilist io___900 = { 0, 11, 0, "(a25,i1,a2,i2,a3)", 0 };
    static cilist io___901 = { 0, 11, 0, "(a25,i2,a2,i1,a3)", 0 };
    static cilist io___902 = { 0, 11, 0, "(a25,i2,a2,i2,a3)", 0 };
    static cilist io___903 = { 0, 11, 0, "(a26,i1,a2,i1,a3)", 0 };
    static cilist io___904 = { 0, 11, 0, "(a21,i1,a2)", 0 };
    static cilist io___905 = { 0, 11, 0, "(a)", 0 };
    static cilist io___906 = { 0, 11, 0, "(a)", 0 };
    static cilist io___907 = { 0, 11, 0, "(a)", 0 };



/*  Writes meter stuff to file 11, so only called if islast=.true. */

    if (*mtrdnp == 0) {
	return 0;
    }
    chax_(ch__1, (ftnlen)1, &c__92);
    *(unsigned char *)sq = *(unsigned char *)&ch__1[0];
    if (*mtrnmp > 0 && *mtrnmp <= 9) {
	if (*mtrdnp < 10) {
	    s_wsfe(&io___899);
/* Writing concatenation */
	    i__1[0] = 1, a__1[0] = sq;
	    i__1[1] = 13, a__1[1] = "generalmeter{";
	    i__1[2] = 1, a__1[2] = sq;
	    i__1[3] = 10, a__1[3] = "meterfrac{";
	    s_cat(ch__2, a__1, i__1, &c__4, (ftnlen)25);
	    do_fio(&c__1, ch__2, (ftnlen)25);
	    do_fio(&c__1, (char *)&(*mtrnmp), (ftnlen)sizeof(integer));
	    do_fio(&c__1, "}{", (ftnlen)2);
	    do_fio(&c__1, (char *)&(*mtrdnp), (ftnlen)sizeof(integer));
	    do_fio(&c__1, "}}%", (ftnlen)3);
	    e_wsfe();
	} else {
	    s_wsfe(&io___900);
/* Writing concatenation */
	    i__1[0] = 1, a__1[0] = sq;
	    i__1[1] = 13, a__1[1] = "generalmeter{";
	    i__1[2] = 1, a__1[2] = sq;
	    i__1[3] = 10, a__1[3] = "meterfrac{";
	    s_cat(ch__2, a__1, i__1, &c__4, (ftnlen)25);
	    do_fio(&c__1, ch__2, (ftnlen)25);
	    do_fio(&c__1, (char *)&(*mtrnmp), (ftnlen)sizeof(integer));
	    do_fio(&c__1, "}{", (ftnlen)2);
	    do_fio(&c__1, (char *)&(*mtrdnp), (ftnlen)sizeof(integer));
	    do_fio(&c__1, "}}%", (ftnlen)3);
	    e_wsfe();
	}
    } else if (*mtrnmp >= 10) {
	if (*mtrdnp < 10) {
	    s_wsfe(&io___901);
/* Writing concatenation */
	    i__1[0] = 1, a__1[0] = sq;
	    i__1[1] = 13, a__1[1] = "generalmeter{";
	    i__1[2] = 1, a__1[2] = sq;
	    i__1[3] = 10, a__1[3] = "meterfrac{";
	    s_cat(ch__2, a__1, i__1, &c__4, (ftnlen)25);
	    do_fio(&c__1, ch__2, (ftnlen)25);
	    do_fio(&c__1, (char *)&(*mtrnmp), (ftnlen)sizeof(integer));
	    do_fio(&c__1, "}{", (ftnlen)2);
	    do_fio(&c__1, (char *)&(*mtrdnp), (ftnlen)sizeof(integer));
	    do_fio(&c__1, "}}%", (ftnlen)3);
	    e_wsfe();
	} else {
	    s_wsfe(&io___902);
/* Writing concatenation */
	    i__1[0] = 1, a__1[0] = sq;
	    i__1[1] = 13, a__1[1] = "generalmeter{";
	    i__1[2] = 1, a__1[2] = sq;
	    i__1[3] = 10, a__1[3] = "meterfrac{";
	    s_cat(ch__2, a__1, i__1, &c__4, (ftnlen)25);
	    do_fio(&c__1, ch__2, (ftnlen)25);
	    do_fio(&c__1, (char *)&(*mtrnmp), (ftnlen)sizeof(integer));
	    do_fio(&c__1, "}{", (ftnlen)2);
	    do_fio(&c__1, (char *)&(*mtrdnp), (ftnlen)sizeof(integer));
	    do_fio(&c__1, "}}%", (ftnlen)3);
	    e_wsfe();
	}
    } else if (*mtrnmp < 0) {
	s_wsfe(&io___903);
/* Writing concatenation */
	i__1[0] = 1, a__1[0] = sq;
	i__1[1] = 13, a__1[1] = "generalmeter{";
	i__1[2] = 1, a__1[2] = sq;
	i__1[3] = 11, a__1[3] = "meterfracS{";
	s_cat(ch__3, a__1, i__1, &c__4, (ftnlen)26);
	do_fio(&c__1, ch__3, (ftnlen)26);
	i__2 = -(*mtrnmp);
	do_fio(&c__1, (char *)&i__2, (ftnlen)sizeof(integer));
	do_fio(&c__1, "}{", (ftnlen)2);
	do_fio(&c__1, (char *)&(*mtrdnp), (ftnlen)sizeof(integer));
	do_fio(&c__1, "}}%", (ftnlen)3);
	e_wsfe();
    } else if (*mtrdnp <= 4) {
	s_wsfe(&io___904);
/* Writing concatenation */
	i__1[0] = 1, a__1[0] = sq;
	i__1[1] = 13, a__1[1] = "generalmeter{";
	i__1[2] = 1, a__1[2] = sq;
	i__1[3] = 6, a__1[3] = "meterN";
	s_cat(ch__4, a__1, i__1, &c__4, (ftnlen)21);
	do_fio(&c__1, ch__4, (ftnlen)21);
	do_fio(&c__1, (char *)&(*mtrdnp), (ftnlen)sizeof(integer));
	do_fio(&c__1, "}%", (ftnlen)2);
	e_wsfe();
    } else if (*mtrdnp == 5) {
	s_wsfe(&io___905);
/* Writing concatenation */
	i__1[0] = 1, a__1[0] = sq;
	i__1[1] = 12, a__1[1] = "generalmeter";
	i__1[2] = 1, a__1[2] = sq;
	i__1[3] = 10, a__1[3] = "allabreve%";
	s_cat(ch__5, a__1, i__1, &c__4, (ftnlen)24);
	do_fio(&c__1, ch__5, (ftnlen)24);
	e_wsfe();
    } else if (*mtrdnp == 6) {
	s_wsfe(&io___906);
/* Writing concatenation */
	i__1[0] = 1, a__1[0] = sq;
	i__1[1] = 12, a__1[1] = "generalmeter";
	i__1[2] = 1, a__1[2] = sq;
	i__1[3] = 7, a__1[3] = "meterC%";
	s_cat(ch__4, a__1, i__1, &c__4, (ftnlen)21);
	do_fio(&c__1, ch__4, (ftnlen)21);
	e_wsfe();
    } else if (*mtrdnp == 7) {
	s_wsfe(&io___907);
/* Writing concatenation */
	i__1[0] = 1, a__1[0] = sq;
	i__1[1] = 12, a__1[1] = "generalmeter";
	i__1[2] = 1, a__1[2] = sq;
	i__1[3] = 10, a__1[3] = "meterIIIS%";
	s_cat(ch__5, a__1, i__1, &c__4, (ftnlen)24);
	do_fio(&c__1, ch__5, (ftnlen)24);
	e_wsfe();
    }
    return 0;
} /* wgmeter_ */

/* Character */ VOID upcaseq_(ret_val, ret_val_len, chq, chq_len)
char *ret_val;
ftnlen ret_val_len;
char *chq;
ftnlen chq_len;
{
    /* System generated locals */
    address a__1[2];
    integer i__1, i__2[2];
    char ch__2[1], ch__3[53];

    /* Builtin functions */
    integer s_wsle();
    /* Subroutine */ int s_cat();
    integer do_lio(), e_wsle();
    /* Subroutine */ int s_stop();

    /* Local variables */
    extern /* Character */ VOID chax_();

    /* Fortran I/O blocks */
    static cilist io___908 = { 0, 6, 0, 0, 0 };


    if (*(unsigned char *)chq >= 61 && *(unsigned char *)chq < 122) {
	i__1 = *(unsigned char *)chq - 32;
	chax_(ch__2, (ftnlen)1, &i__1);
	*(unsigned char *)ret_val = *(unsigned char *)&ch__2[0];
    } else {
	*(unsigned char *)ret_val = *(unsigned char *)chq;
	s_wsle(&io___908);
/* Writing concatenation */
	i__2[0] = 52, a__1[0] = "Warning, upcaseq was called with improper a\
rgument: ";
	i__2[1] = 1, a__1[1] = chq;
	s_cat(ch__3, a__1, i__2, &c__2, (ftnlen)53);
	do_lio(&c__9, &c__1, ch__3, (ftnlen)53);
	e_wsle();
	s_stop("", (ftnlen)0);
    }
    return ;
} /* upcaseq_ */

/* Subroutine */ int addblank_(noteq, lnoten, noteq_len)
char *noteq;
integer *lnoten;
ftnlen noteq_len;
{
    /* System generated locals */
    address a__1[2];
    integer i__1[2];

    /* Builtin functions */
    /* Subroutine */ int s_copy(), s_cat();

    /* Local variables */
    static char tchar[1];

    s_copy(tchar, noteq, (ftnlen)1, (ftnlen)8);
/* Writing concatenation */
    i__1[0] = 1, a__1[0] = " ";
    i__1[1] = 1, a__1[1] = tchar;
    s_cat(noteq, a__1, i__1, &c__2, (ftnlen)8);
    *lnoten = 2;
    return 0;
} /* addblank_ */

/* Subroutine */ int doslur_(nolev, isdat1, isdat2, isdat3, nsdat, ip, iv, kv,
	 nv, beamon, ncm, soutq, lsout, ulq, islur, ipl, iornq, islhgt, tno, 
	nacc, soutq_len, ulq_len)
integer *nolev, *isdat1, *isdat2, *isdat3, *nsdat, *ip, *iv, *kv, *nv;
logical *beamon;
integer *ncm;
char *soutq;
integer *lsout;
char *ulq;
integer *islur, *ipl, *iornq, *islhgt;
real *tno;
integer *nacc;
ftnlen soutq_len;
ftnlen ulq_len;
{
    /* System generated locals */
    address a__1[3], a__2[2], a__3[4];
    integer i__1, i__2, i__3[3], i__4[2], i__5[4], i__6;
    char ch__1[1], ch__2[6];
    icilist ici__1;

    /* Builtin functions */
    integer s_wsle(), e_wsle(), do_lio(), s_wsfe(), do_fio(), e_wsfe();
    /* Subroutine */ int s_stop(), s_cat(), s_copy();
    integer s_wsfi(), e_wsfi();

    /* Local variables */
    static integer j, icm;
    extern integer log2_();
    static integer imid;
    extern /* Character */ VOID chax_(), udfq_(), udqq_();
    extern integer lfmt1_();
    static integer ihoff;
    static logical iscrd;
    static integer isdat, ivoff;
    static real shift;
    static integer iupdn, lform, lnote;
    static char noteq[8];
    static logical tmove;
    static integer idcode, isdata;
    extern /* Subroutine */ int addstr_();
    static integer isdats;
    static logical settie, sfound, tfound;
    static integer isdatt;
    extern /* Subroutine */ int notefq_();
    static integer lnoten, nolevt, nolevs;
    static logical stemup;
    static char notexq[79];
    extern /* Subroutine */ int setbits_();
    static integer numdrop;
    static char slurudq[1];
    static integer ivoffinc;
    extern integer igetbits_();

    /* Fortran I/O blocks */
    static cilist io___928 = { 0, 6, 0, 0, 0 };
    static cilist io___929 = { 0, 6, 0, 0, 0 };
    static cilist io___930 = { 0, 15, 0, "(/,a)", 0 };
    static cilist io___938 = { 0, 6, 0, 0, 0 };



/*  Called once per main note. */


/*  Bits in isdat1: */
/*  13-17    iv */
/*  3-10     ip */
/*  11       start/stop switch */
/*  12       kv-1 */
/*  19-25    ichar(code$) */
/*  26       force direction? */
/*  27       forced dir'n = up if on, set in sslur; also */
/*           final direction, set in doslur when beam is started, used on term. */
/*  28-31    ndxslur, set in doslur when beam is started, used on term. */

/*  Bits in isdat2 */
/*  0        Chord switch.  Not set on main note. */
/*  1-2      left/right notehead shift.  Set only for chord note. */
/*  3        tie positioning */
/*  4        dotted flag */
/*  6-11     voff1 1-63  =>  -31...+31 */
/*  12-18    hoff1 1-127 => -6.3...+6.3 */
/*  19-25    nolev */

/*  Bits in isdat3: Only used for slur endings */
/*  0        set if midslur (at least one argument) */
/*  1        set if curve (2 more args) */
/*  2-7      32+first arg (height correction) (1st arg may be negative) */
/*  8-10     second arg (initial slope) */
/*  11-13    third arg (closing slope) */

/*  In listslur bit ib is on if slur index ib is in use, ib=0-8. */
/*  ndxslur = slur index */
/*  Height of slur is nole+ivoff+iupdn.  iupdn is +/-1 if t&s slurs on same note, */
/*  s-slur is blank (idcode=32), t-slur is idcode=1. */
/*  ivoff is user-defined shift or shift due to . or _ , or chord adjustment. */
/*  Ivoff will be set for ./_ only if no user-defined shift is specified. */
/*  If highest note has upslur, save slur height in islhgt in case */
/*  ornament must be moved. */

    /* Parameter adjustments */
    --isdat3;
    --isdat2;
    --isdat1;

    /* Function Body */
    *islhgt = 0;
    if (*beamon) {
	stemup = *(unsigned char *)ulq == 'u';
    } else if (commvl_1.nvmx[*iv - 1] == 2) {
	if (! bit_test(*islur,30)) {

/*  Single note, 2 lines of music, stem direction not forced */

	    stemup = commvl_1.ivx > *nv;
	} else {
	    stemup = bit_test(*islur,17);
	}
    } else {
	udqq_(ch__1, (ftnlen)1, nolev, ncm, islur, &commvl_1.nvmx[*iv - 1], &
		commvl_1.ivx, nv);
	stemup = *(unsigned char *)&ch__1[0] == 'u';
    }
    iscrd = bit_test(*ipl,10);
    if (bit_test(*islur,1)) {

/*  't'-slur (idcode=1) somewhere on this note.  Find it, check height against */
/*    's'-slur (idcode=32) */

	sfound = FALSE_;
	tfound = FALSE_;
	tmove = FALSE_;
	i__1 = *nsdat;
	for (isdat = 1; isdat <= i__1; ++isdat) {
	    if (*iv == igetbits_(&isdat1[isdat], &c__5, &c__13) && *ip == 
		    igetbits_(&isdat1[isdat], &c__8, &c__3) && *kv == 
		    igetbits_(&isdat1[isdat], &c__1, &c__12) + 1) {
		if (! tfound) {
		    tfound = igetbits_(&isdat1[isdat], &c__7, &c__19) == 1;
		    if (tfound) {
			nolevt = igetbits_(&isdat2[isdat], &c__7, &c__19);
			isdatt = isdat;
			if (sfound) {
			    goto L6;
			}
		    }
		}
		if (! sfound) {
		    sfound = igetbits_(&isdat1[isdat], &c__7, &c__19) == 32;
		    if (sfound) {
			nolevs = igetbits_(&isdat2[isdat], &c__7, &c__19);
			isdats = isdat;
			if (tfound) {
			    goto L6;
			}
		    }
		}
	    }
/* L5: */
	}

/*  Will come thru here if there is a t with no s, so comment out the following */
/*        print*,'Did not find s+t-slurs in doslur' */

L6:
	if (sfound && tfound) {
	    tmove = nolevs == nolevt && (bit_test(isdat1[isdats],11) && 
		    bit_test(isdat1[isdatt],11) || ! bit_test(isdat1[isdats],
		    11) && ! bit_test(isdat1[isdatt],11));
	}

/*  Check if 2 starts or two stops */


/*  This is a flag for later changing slur level, after we know slur dir'n. */

    }
    if (commidi_1.ismidi) {
	settie = FALSE_;
	comslm_1.dbltie = FALSE_;
    }
    i__1 = *nsdat;
    for (isdat = 1; isdat <= i__1; ++isdat) {
	isdata = isdat1[isdat];
	if (*iv == igetbits_(&isdata, &c__5, &c__13) && *ip == igetbits_(&
		isdata, &c__8, &c__3) && *kv == igetbits_(&isdata, &c__1, &
		c__12) + 1) {

/*  Since iv and kv match, ivx will be correct */

	    idcode = igetbits_(&isdata, &c__7, &c__19);
	    ivoff = igetbits_(&isdat2[isdat], &c__6, &c__6) - 32;
	    ihoff = igetbits_(&isdat2[isdat], &c__7, &c__12) - 64;
	    iupdn = 0;
	    *(unsigned char *)slurudq = 'd';
	    nolevs = igetbits_(&isdat2[isdat], &c__7, &c__19);
	    if (bit_test(isdata,11)) {

/*  Turnon, so get slur direction */

		if (bit_test(isdata,26)) {

/*  Force slur direction */

		    if (bit_test(isdata,27)) {
			*(unsigned char *)slurudq = 'u';
		    }
		} else if (commvl_1.nvmx[*iv - 1] == 1) {

/*  Only one voice per line */

		    if (! (*beamon)) {

/*  Separate note. */

			udfq_(ch__1, (ftnlen)1, nolev, ncm);
			*(unsigned char *)slurudq = *(unsigned char *)&ch__1[
				0];
		    } else {

/*  In a beam */

			if (*(unsigned char *)ulq != 'u') {
			    *(unsigned char *)slurudq = 'u';
			}
		    }
		    if (iscrd) {
			if (nolevs > *ncm) {
			    *(unsigned char *)slurudq = 'u';
			} else {
			    *(unsigned char *)slurudq = 'd';
			}
		    }
		} else {

/*  Two voices per line.  Get default */

		    if (commvl_1.ivx > *nv) {
			*(unsigned char *)slurudq = 'u';
		    }

/*  Upper voice of the two, so up slur */

		}

/*  Save up/down-ness for use at termination */

		if (*(unsigned char *)slurudq == 'u') {
		    isdata = bit_set(isdata,27);
		}

/*  End of section for setting slur direction, still in "Turnon" if-block. */

		if (idcode == 1 && tmove) {
		    iupdn = 1;
		    if (*(unsigned char *)slurudq == 'd') {
			iupdn = -1;
		    }
		}
		if (bit_test(*iornq,11) || bit_test(*iornq,12)) {

/*  Raise or lower slur by one unit provided . or _ is on same side as slur */

		    if (stemup && *(unsigned char *)slurudq == 'd' || ! 
			    stemup && *(unsigned char *)slurudq == 'u') {

/*  Must move the slur for _ or . */

			if (stemup) {
			    ivoffinc = -1;
			} else {
			    ivoffinc = 1;
			}
			if ((stemup && *nolev >= *ncm - 2 || ! stemup && *
				nolev <= *ncm + 2) && (i__2 = *ncm - *nolev, 
				abs(i__2)) % 2 == 0) {
			    ivoffinc <<= 1;
			}
			ivoff += ivoffinc;
		    }
		}
/*            if (listslur .eq. 511) then */
		if (comslur_1.listslur == 4095) {
		    s_wsle(&io___928);
		    e_wsle();
		    s_wsle(&io___929);
		    do_lio(&c__9, &c__1, "You defined the thirteenth slur, o\
ne too many!", (ftnlen)46);
		    e_wsle();
		    s_wsfe(&io___930);
		    do_fio(&c__1, "You defined the thirteenth slur, one too \
many!", (ftnlen)46);
		    e_wsfe();
		    s_stop("1", (ftnlen)1);
		}

/*  Get index of next slur not in use, starting from 8 down */

/*            ndxslur = log2(511-listslur) */
		i__2 = 4095 - comslur_1.listslur;
		comslur_1.ndxslur = log2_(&i__2);

/*  Record slur index */

		comslur_1.listslur = bit_set(comslur_1.listslur,
			comslur_1.ndxslur);

/*  Save for use on termination */

		setbits_(&isdata, &c__4, &c__28, &comslur_1.ndxslur);

/*  Shift for stem? */

/*            if (stemup .and. slurudq.eq.'u') ihoff = ihoff+8 */
		if (stemup && *(unsigned char *)slurudq == 'u' && *tno < (
			float)63.) {
		    ihoff += 8;
		}
		if (bit_test(isdat2[isdat],3)) {

/*  Tie spacing, (slur start) */

		    if (*(unsigned char *)slurudq == 'd') {
			++ivoff;
			ihoff += 8;
		    } else if (*(unsigned char *)slurudq == 'u') {
			--ivoff;
/*                if (.not.stemup) ihoff = ihoff+8 */
			if (! (stemup && *tno < (float)63.)) {
			    ihoff += 8;
			}

/*  (already shifted if (stemup.and.tno.gt.63.) and slurudq='u') */

		    }
		}
		if (iscrd) {

/*  Additional horiz shifts for h-shifted noteheads? */

		    if (bit_test(isdat2[isdat],1)) {

/*  Slur start on left-shifted chord notehead.  ASSUME downstem. */

			if (nolevs == comtrill_1.minlev && *(unsigned char *)
				slurudq == 'd') {
			    ihoff += -2;
			} else {
			    ihoff += -10;
			}
		    } else if (bit_test(isdat2[isdat],2)) {

/*  Right shifted chord notehead.  ASSUME upstem. */

			if (nolevs == comtrill_1.maxlev && *(unsigned char *)
				slurudq == 'u') {
			    ihoff += 2;
			} else {
			    ihoff += 10;
			}
		    }
		}
		if (ihoff == 0) {

/*  Write stuff for non-shifted start */

/* Writing concatenation */
		    chax_(ch__1, (ftnlen)1, &c__92);
		    i__3[0] = 1, a__1[0] = ch__1;
		    i__3[1] = 5, a__1[1] = "islur";
		    i__3[2] = 1, a__1[2] = slurudq;
		    s_cat(notexq, a__1, i__3, &c__3, (ftnlen)79);
		    lnote = 7;
		} else {
/* Writing concatenation */
		    chax_(ch__1, (ftnlen)1, &c__92);
		    i__3[0] = 1, a__1[0] = ch__1;
		    i__3[1] = 2, a__1[1] = "is";
		    i__3[2] = 1, a__1[2] = slurudq;
		    s_cat(notexq, a__1, i__3, &c__3, (ftnlen)79);
		    lnote = 4;
		}
		if (bit_test(isdat2[isdat],4)) {

/*  Dotted slur */

		    s_copy(noteq, notexq, (ftnlen)8, (ftnlen)79);
/* Writing concatenation */
		    chax_(ch__1, (ftnlen)1, &c__92);
		    i__3[0] = 1, a__1[0] = ch__1;
		    i__3[1] = 6, a__1[1] = "dotted";
		    i__3[2] = 8, a__1[2] = noteq;
		    s_cat(notexq, a__1, i__3, &c__3, (ftnlen)79);
		    lnote += 7;
		}

/*  Add slur index to string */

		if (comslur_1.ndxslur < 10) {
/* Writing concatenation */
		    i__4[0] = lnote, a__2[0] = notexq;
		    i__2 = comslur_1.ndxslur + 48;
		    chax_(ch__1, (ftnlen)1, &i__2);
		    i__4[1] = 1, a__2[1] = ch__1;
		    s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
		    ++lnote;
		} else {
/* Writing concatenation */
		    i__5[0] = lnote, a__3[0] = notexq;
		    i__5[1] = 2, a__3[1] = "{1";
		    i__2 = comslur_1.ndxslur + 38;
		    chax_(ch__1, (ftnlen)1, &i__2);
		    i__5[2] = 1, a__3[2] = ch__1;
		    i__5[3] = 1, a__3[3] = "}";
		    s_cat(notexq, a__3, i__5, &c__4, (ftnlen)79);
		    lnote += 4;
		}

/*  Add note name to string */

		i__2 = nolevs + iupdn + ivoff;
		notefq_(noteq, &lnoten, &i__2, ncm, (ftnlen)8);
/* Writing concatenation */
		i__4[0] = lnote, a__2[0] = notexq;
		i__4[1] = lnoten, a__2[1] = noteq;
		s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
		lnote += lnoten;

/*  Save height (for ornament and barnobox interference) if topmost slur is up */

		if (*(unsigned char *)slurudq == 'u' && (! bit_test(isdat2[
			isdat],0) || nolevs == comtrill_1.maxlev)) {
		    *islhgt = nolevs + iupdn + ivoff;

/*  Save height & idcode if top voice and slur start */

		    if (commvl_1.ivx == commvl_1.ivmx[*nv + commvl_1.nvmx[*nv 
			    - 1] * 15 - 16] && *islhgt > comsln_1.is1n1) {
			comsln_1.is1n1 = *islhgt;
			comsln_1.is2n1 = idcode;
		    }
		}
		if ((real) ihoff != (float)0.) {
		    shift = ihoff * (float).1;
/* Writing concatenation */
		    i__4[0] = lnote, a__2[0] = notexq;
		    i__4[1] = 1, a__2[1] = "{";
		    s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
		    ++lnote;
		    lform = lfmt1_(&shift);
		    i__2 = lnote;
		    ici__1.icierr = 0;
		    ici__1.icirnum = 1;
		    ici__1.icirlen = lnote + lform - i__2;
		    ici__1.iciunit = notexq + i__2;
/* Writing concatenation */
		    i__3[0] = 2, a__1[0] = "(f";
		    i__6 = lform + 48;
		    chax_(ch__1, (ftnlen)1, &i__6);
		    i__3[1] = 1, a__1[1] = ch__1;
		    i__3[2] = 3, a__1[2] = ".1)";
		    ici__1.icifmt = (s_cat(ch__2, a__1, i__3, &c__3, (ftnlen)
			    6), ch__2);
		    s_wsfi(&ici__1);
		    do_fio(&c__1, (char *)&shift, (ftnlen)sizeof(real));
		    e_wsfi();
		    lnote += lform;
/* Writing concatenation */
		    i__4[0] = lnote, a__2[0] = notexq;
		    i__4[1] = 1, a__2[1] = "}";
		    s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
		    ++lnote;
		}
		addstr_(notexq, &lnote, soutq, lsout, (ftnlen)79, (ftnlen)80);

/*  Zero out ip1 to avoid problems if slur goes to next input blk. */

		setbits_(&isdata, &c__8, &c__3, &c__0);

/*  Set slur-on data for midi.  Only treat null-index slurs for now. */

		if (commidi_1.ismidi && idcode == 32) {
/*              levson(midchan(iv,kv)) = nolev */
		    comslm_1.levson[commidi_1.midchan[*iv + *kv * 15 - 16]] = 
			    nolevs;
		    if (settie) {
			comslm_1.dbltie = TRUE_;
		    }

/*  Only way settie=T is if we just set a tie ending.  So there's also a slur */
/*   start here, so set a flag telling addmidi not to zero out levson */

		}
	    } else {

/*  Slur is ending.  Back thru list to find starting slur */

		for (j = isdat - 1; j >= 1; --j) {
		    if (*iv == igetbits_(&isdat1[j], &c__5, &c__13) && *kv == 
			    igetbits_(&isdat1[j], &c__1, &c__12) + 1) {
			if (idcode == igetbits_(&isdat1[j], &c__7, &c__19)) {
			    comslur_1.ndxslur = igetbits_(&isdat1[j], &c__4, &
				    c__28);
			    if (bit_test(isdat1[j],27)) {
				*(unsigned char *)slurudq = 'u';
			    }
			    goto L4;
			}
		    }
/* L3: */
		}
		s_wsle(&io___938);
		do_lio(&c__9, &c__1, "Bad place in doslur", (ftnlen)19);
		e_wsle();
		s_stop("1", (ftnlen)1);
L4:
		if (bit_test(isdat3[isdat],0)) {

/*  Deal with \curve or \midslur */

		    if (bit_test(isdat3[isdat],1)) {
/* Writing concatenation */
			chax_(ch__1, (ftnlen)1, &c__92);
			i__4[0] = 1, a__2[0] = ch__1;
			i__4[1] = 5, a__2[1] = "curve";
			s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
			lnote = 6;
		    } else {
/* Writing concatenation */
			chax_(ch__1, (ftnlen)1, &c__92);
			i__4[0] = 1, a__2[0] = ch__1;
			i__4[1] = 7, a__2[1] = "midslur";
			s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
			lnote = 8;
		    }
		    imid = igetbits_(&isdat3[isdat], &c__6, &c__2) - 32;
		    if (imid < 0 || imid > 9) {

/*  Need brackets */

/* Writing concatenation */
			i__4[0] = lnote, a__2[0] = notexq;
			i__4[1] = 1, a__2[1] = "{";
			s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
			++lnote;
			if (imid < -9) {
			    i__2 = lnote;
			    ici__1.icierr = 0;
			    ici__1.icirnum = 1;
			    ici__1.icirlen = lnote + 3 - i__2;
			    ici__1.iciunit = notexq + i__2;
			    ici__1.icifmt = "(i3)";
			    s_wsfi(&ici__1);
			    do_fio(&c__1, (char *)&imid, (ftnlen)sizeof(
				    integer));
			    e_wsfi();
			    lnote += 3;
			} else if (imid < 0 || imid > 9) {
			    i__2 = lnote;
			    ici__1.icierr = 0;
			    ici__1.icirnum = 1;
			    ici__1.icirlen = lnote + 2 - i__2;
			    ici__1.iciunit = notexq + i__2;
			    ici__1.icifmt = "(i2)";
			    s_wsfi(&ici__1);
			    do_fio(&c__1, (char *)&imid, (ftnlen)sizeof(
				    integer));
			    e_wsfi();
			    lnote += 2;
			} else {
			    i__2 = lnote;
			    ici__1.icierr = 0;
			    ici__1.icirnum = 1;
			    ici__1.icirlen = lnote + 1 - i__2;
			    ici__1.iciunit = notexq + i__2;
			    ici__1.icifmt = "(i1)";
			    s_wsfi(&ici__1);
			    do_fio(&c__1, (char *)&imid, (ftnlen)sizeof(
				    integer));
			    e_wsfi();
			    ++lnote;
			}
/* Writing concatenation */
			i__4[0] = lnote, a__2[0] = notexq;
			i__4[1] = 1, a__2[1] = "}";
			s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
			++lnote;
		    } else {

/*  1=<imid=<9, no brackets */

/* Writing concatenation */
			i__4[0] = lnote, a__2[0] = notexq;
			*(unsigned char *)&ch__1[0] = imid + 48;
			i__4[1] = 1, a__2[1] = ch__1;
			s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
			++lnote;
		    }
		    if (bit_test(isdat3[isdat],1)) {

/*  \curve; 3 args */

/* Writing concatenation */
			i__4[0] = lnote, a__2[0] = notexq;
			*(unsigned char *)&ch__1[0] = igetbits_(&isdat3[isdat]
				, &c__3, &c__8) + 48;
			i__4[1] = 1, a__2[1] = ch__1;
			s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
/* Writing concatenation */
			i__4[0] = lnote + 1, a__2[0] = notexq;
			*(unsigned char *)&ch__1[0] = igetbits_(&isdat3[isdat]
				, &c__3, &c__11) + 48;
			i__4[1] = 1, a__2[1] = ch__1;
			s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
			lnote += 2;
		    }
		    addstr_(notexq, &lnote, soutq, lsout, (ftnlen)79, (ftnlen)
			    80);
		}

/*  Shift slur ending for stem on any note? */

/*            if (.not.stemup .and. slurudq.eq.'d') ihoff = ihoff-8 */
		if (! stemup && *(unsigned char *)slurudq == 'd' && *tno < (
			float)63.) {
		    ihoff += -8;
		}
		if (bit_test(isdat2[isdat],3)) {

/*  Shift ending for tie spacing */

		    if (*(unsigned char *)slurudq == 'u') {
			ihoff += -8;
			--ivoff;
		    } else if (*(unsigned char *)slurudq == 'd') {
			++ivoff;
/*                if (stemup) ihoff = ihoff-8 */
			if (stemup || *tno > (float)63.) {
			    ihoff += -8;
			}
		    }
		}
		if (iscrd) {

/*  Shift termination for shifted notehead? */

		    if (bit_test(isdat2[isdat],1)) {

/*  Left-shifted chord notehead.  ASSUME downstem. */

			if (nolevs == comtrill_1.minlev && *(unsigned char *)
				slurudq == 'd') {
			    ihoff += -2;
			} else {
			    ihoff += -10;
			}
		    } else if (bit_test(isdat2[isdat],2)) {

/*  Right shifted chord notehead.  ASSUME upstem. */

			if (nolevs == comtrill_1.maxlev && *(unsigned char *)
				slurudq == 'u') {
			    ihoff += 2;
			} else {
			    ihoff += 10;
			}
		    }
		}
		if (ihoff == 0) {
/* Writing concatenation */
		    chax_(ch__1, (ftnlen)1, &c__92);
		    i__4[0] = 1, a__2[0] = ch__1;
		    i__4[1] = 5, a__2[1] = "tslur";
		    s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
		    lnote = 6;
		} else {

/*  Shift needed */

/* Writing concatenation */
		    chax_(ch__1, (ftnlen)1, &c__92);
		    i__4[0] = 1, a__2[0] = ch__1;
		    i__4[1] = 2, a__2[1] = "ts";
		    s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
		    lnote = 3;
		}
		if (comslur_1.ndxslur < 10) {
/* Writing concatenation */
		    i__4[0] = lnote, a__2[0] = notexq;
		    i__2 = comslur_1.ndxslur + 48;
		    chax_(ch__1, (ftnlen)1, &i__2);
		    i__4[1] = 1, a__2[1] = ch__1;
		    s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
		    ++lnote;
		} else {
/* Writing concatenation */
		    i__5[0] = lnote, a__3[0] = notexq;
		    i__5[1] = 2, a__3[1] = "{1";
		    i__2 = comslur_1.ndxslur + 38;
		    chax_(ch__1, (ftnlen)1, &i__2);
		    i__5[2] = 1, a__3[2] = ch__1;
		    i__5[3] = 1, a__3[3] = "}";
		    s_cat(notexq, a__3, i__5, &c__4, (ftnlen)79);
		    lnote += 4;
		}
		if (bit_test(*iornq,11) || bit_test(*iornq,12)) {

/*  Raise or lower slur by one unit provided . or _ is on same side as slur */

		    if (stemup && *(unsigned char *)slurudq == 'd' || ! 
			    stemup && *(unsigned char *)slurudq == 'u') {
			if (stemup) {
			    ivoffinc = -1;
			} else {
			    ivoffinc = 1;
			}
			if ((stemup && *nolev >= *ncm - 2 || ! stemup && *
				nolev <= *ncm + 2) && (i__2 = *ncm - *nolev, 
				abs(i__2)) % 2 == 0) {
			    ivoffinc <<= 1;
			}
		    }
		    ivoff += ivoffinc;
		}
		if (idcode == 1 && tmove) {

/*  t-slur height adjustment */

		    iupdn = 1;
		    if (*(unsigned char *)slurudq == 'd') {
			iupdn = -1;
		    }
		}
		i__2 = nolevs + iupdn + ivoff;
		notefq_(noteq, &lnoten, &i__2, ncm, (ftnlen)8);
		if (*(unsigned char *)slurudq == 'u' && (! bit_test(isdat2[
			isdat],0) || nolevs == comtrill_1.maxlev)) {
		    *islhgt = nolevs + iupdn + ivoff;

/*  If topvoice, upslur, and idcode checks, no more need to keep hgt for barno. */

		    if (commvl_1.ivx == commvl_1.ivmx[*nv + commvl_1.nvmx[*nv 
			    - 1] * 15 - 16] && comsln_1.is1n1 > 0) {
			if (idcode == comsln_1.is2n1) {
			    comsln_1.is1n1 = 0;
			}
		    }
		}
/* Writing concatenation */
		i__4[0] = lnote, a__2[0] = notexq;
		i__4[1] = lnoten, a__2[1] = noteq;
		s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
		lnote += lnoten;
		if (ihoff != 0) {
		    shift = ihoff * (float).1;
/* Writing concatenation */
		    i__4[0] = lnote, a__2[0] = notexq;
		    i__4[1] = 1, a__2[1] = "{";
		    s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
		    ++lnote;
		    lform = lfmt1_(&shift);
		    i__2 = lnote;
		    ici__1.icierr = 0;
		    ici__1.icirnum = 1;
		    ici__1.icirlen = lnote + lform - i__2;
		    ici__1.iciunit = notexq + i__2;
/* Writing concatenation */
		    i__3[0] = 2, a__1[0] = "(f";
		    i__6 = lform + 48;
		    chax_(ch__1, (ftnlen)1, &i__6);
		    i__3[1] = 1, a__1[1] = ch__1;
		    i__3[2] = 3, a__1[2] = ".1)";
		    ici__1.icifmt = (s_cat(ch__2, a__1, i__3, &c__3, (ftnlen)
			    6), ch__2);
		    s_wsfi(&ici__1);
		    do_fio(&c__1, (char *)&shift, (ftnlen)sizeof(real));
		    e_wsfi();
		    lnote += lform;
/* Writing concatenation */
		    i__4[0] = lnote, a__2[0] = notexq;
		    i__4[1] = 1, a__2[1] = "}";
		    s_cat(notexq, a__2, i__4, &c__2, (ftnlen)79);
		    ++lnote;
		}
		addstr_(notexq, &lnote, soutq, lsout, (ftnlen)79, (ftnlen)80);

/*  Clear the bit from list of slurs in use */

		comslur_1.listslur = bit_clear(comslur_1.listslur,
			comslur_1.ndxslur);

/*  Zero out the entire strings for start and stop */

		isdata = 0;
		isdat2[isdat] = 0;
		isdat1[j] = 0;
		isdat2[j] = 0;
		isdat3[isdat] = 0;

/*  Set midi info for slur ending */

		if (commidi_1.ismidi && idcode == 32) {
		    icm = commidi_1.midchan[*iv + *kv * 15 - 16];
		    if (comslm_1.slmon[icm]) {
/*                if (nolev.eq.levson(icm) .and. iand(7,nacc).eq.0) then */
			if (nolevs == comslm_1.levson[icm] && (7 & *nacc) == 
				0) {

/*  There is a tie here.  NB!!! assumed no accidental on 2nd member of tie. */

/*                  levsoff(icm) = nolev */
			    comslm_1.levsoff[icm] = nolevs;
			    settie = TRUE_;
			} else {
			    comslm_1.levsoff[icm] = 0;
			    comslm_1.levson[icm] = 0;
			    comslm_1.slmon[icm] = FALSE_;
			}
		    }
		}
	    }
	    isdat1[isdat] = isdata;
	}
/* L1: */
    }

/*  Clear and collapse the slur data list */

    numdrop = 0;
    i__1 = *nsdat;
    for (isdat = 1; isdat <= i__1; ++isdat) {
	if (isdat1[isdat] == 0) {
	    ++numdrop;
	} else if (numdrop > 0) {
	    isdat1[isdat - numdrop] = isdat1[isdat];
	    isdat2[isdat - numdrop] = isdat2[isdat];
	    isdat3[isdat - numdrop] = isdat3[isdat];
	    isdat1[isdat] = 0;
	    isdat2[isdat] = 0;
	    isdat3[isdat] = 0;
	}
/* L2: */
    }
    *nsdat -= numdrop;
/*      call report(nsdat,isdat1,isdat2) */
    return 0;
} /* doslur_ */

/* Subroutine */ int addfb_(nfb, iv, tnew, t1fb, t2fb, ulfbq, ifbadd, 
	ulfbq_len)
integer *nfb, *iv;
real *tnew, *t1fb, *t2fb;
char *ulfbq;
integer *ifbadd;
ftnlen ulfbq_len;
{
    static integer ifb;

    /* Parameter adjustments */
    ulfbq -= 16;
    t2fb -= 16;
    t1fb -= 16;
    --nfb;

    /* Function Body */
    *ifbadd = 1;
    ++nfb[*iv];
    for (ifb = nfb[*iv] - 1; ifb >= 1; --ifb) {
	if (*tnew < t1fb[*iv + ifb * 15] - comtol_1.tol) {
	    t1fb[*iv + (ifb + 1) * 15] = t1fb[*iv + ifb * 15];
	    t2fb[*iv + (ifb + 1) * 15] = t2fb[*iv + ifb * 15];
	    *(unsigned char *)&ulfbq[*iv + (ifb + 1) * 15] = *(unsigned char *
		    )&ulfbq[*iv + ifb * 15];
	} else {
	    *ifbadd = ifb + 1;
	    goto L2;
	}
/* L1: */
    }
L2:
    t1fb[*iv + *ifbadd * 15] = *tnew;
    *(unsigned char *)&ulfbq[*iv + *ifbadd * 15] = 'x';
    return 0;
} /* addfb_ */

/* Subroutine */ int addask_(taskn, waskn, elaskn, fixednew, scaldold, tglp1, 
	isudsp)
real *taskn, *waskn, *elaskn, *fixednew, *scaldold, *tglp1;
logical *isudsp;
{
    /* System generated locals */
    integer i__1;
    real r__1;

    /* Builtin functions */
    integer s_wsle(), do_lio(), e_wsle();
    /* Subroutine */ int s_stop();

    /* Local variables */
    static integer iudsp;

    /* Fortran I/O blocks */
    static cilist io___944 = { 0, 6, 0, 0, 0 };


    if (*isudsp) {

/*  Find which udsp we're dealing with */

	i__1 = comudsp_1.nudsp;
	for (iudsp = 1; iudsp <= i__1; ++iudsp) {
	    if ((r__1 = *taskn + *tglp1 - comudsp_1.tudsp[iudsp - 1], dabs(
		    r__1)) < comtol_1.tol) {
		goto L2;
	    }
/* L1: */
	}
	s_wsle(&io___944);
	do_lio(&c__9, &c__1, "You should note BEEE here in addask!", (ftnlen)
		36);
	e_wsle();
	s_stop("1", (ftnlen)1);
L2:

/*  Fixednew and scaldold must not be changed, since udsp's are already included */
/*  in fsyst from pmxa, and udsp don't involve scaled space.. */

	if (comas1_1.naskb > 0 && (r__1 = *taskn - comas1_1.task[max(1,
		comas1_1.naskb) - 1], dabs(r__1)) < comtol_1.tol) {

/*  Must add user-defined space to what's there already. */

	    comas1_1.wask[comas1_1.naskb - 1] += comudsp_1.udsp[iudsp - 1];
	} else {

/*  This place has no other space. */

	    ++comas1_1.naskb;
	    comas1_1.task[comas1_1.naskb - 1] = *taskn;
	    comas1_1.wask[comas1_1.naskb - 1] = comudsp_1.udsp[iudsp - 1];
	    comas1_1.elask[comas1_1.naskb - 1] = (float)0.;
	}
    } else {

/*  This is a normal space, no effect if smaller than existing space */

	if (comas1_1.naskb > 0 && (r__1 = *taskn - comas1_1.task[max(1,
		comas1_1.naskb) - 1], dabs(r__1)) < comtol_1.tol) {

/*  We already put in some space at this time */
/*  Check if new one needs more space than old one at same time */

	    if (*waskn > comas1_1.wask[comas1_1.naskb - 1]) {
		--comas1_1.naskb;
	    } else {
		return 0;
	    }
	}
	++comas1_1.naskb;
	comas1_1.task[comas1_1.naskb - 1] = *taskn;
	comas1_1.wask[comas1_1.naskb - 1] = *waskn;
	comas1_1.elask[comas1_1.naskb - 1] = *elaskn;
	*fixednew += *waskn;
	*scaldold += *elaskn;
    }
    return 0;
} /* addask_ */

/* Subroutine */ int askfig_(pathnameq, lpath, basenameq, lbase, figbass, 
	istype0, pathnameq_len, basenameq_len)
char *pathnameq;
integer *lpath;
char *basenameq;
integer *lbase;
logical *figbass, *istype0;
ftnlen pathnameq_len;
ftnlen basenameq_len;
{
    /* System generated locals */
    address a__1[3], a__2[2];
    integer i__1[3], i__2[2], i__3;
    char ch__1[1], ch__2[68], ch__3[15], ch__4[5], ch__5[4];
    olist o__1;
    cllist cl__1;
    alist al__1;

    /* Builtin functions */
    /* Subroutine */ int s_cat();
    integer f_open(), f_rew(), f_clos(), s_wsfe(), do_fio(), e_wsfe(), s_rsfe(
	    ), e_rsfe(), s_cmp(), s_wsfi(), e_wsfi(), i_indx();

    /* Local variables */
    static integer il;
    static char sq[1];
    static integer ihs;
    extern /* Character */ VOID chax_();
    static logical done;
    extern integer llen_();
    static char outq[129];
    extern /* Subroutine */ int moveln_();
    static integer lenout;
    extern /* Subroutine */ int putast_();
    static integer indxask;

    /* Fortran I/O blocks */
    static cilist io___948 = { 0, 12, 0, "(a)", 0 };
    static cilist io___950 = { 0, 11, 1, "(a129)", 0 };
    static icilist io___952 = { 0, outq+11, 0, "(f4.1)", 4, 1 };
    static cilist io___955 = { 0, 12, 0, "(a)", 0 };
    static cilist io___956 = { 0, 16, 1, "(a129)", 0 };
    static cilist io___957 = { 0, 12, 0, "(a)", 0 };


    chax_(ch__1, (ftnlen)1, &c__92);
    *(unsigned char *)sq = *(unsigned char *)&ch__1[0];
    o__1.oerr = 0;
    o__1.ounit = 12;
    o__1.ofnmlen = *lpath + *lbase + 4;
/* Writing concatenation */
    i__1[0] = *lpath, a__1[0] = pathnameq;
    i__1[1] = *lbase, a__1[1] = basenameq;
    i__1[2] = 4, a__1[2] = ".tex";
    s_cat(ch__2, a__1, i__1, &c__3, (ftnlen)68);
    o__1.ofnm = ch__2;
    o__1.orl = 0;
    o__1.osta = 0;
    o__1.oacc = 0;
    o__1.ofm = 0;
    o__1.oblnk = 0;
    f_open(&o__1);

/*  Transfer first 5 lines of main internal TeX file */

    for (il = 1; il <= 5; ++il) {
	moveln_(&c__11, &c__12, &done);
/* L11: */
    }
    if (*istype0) {

/*  Transfer literal TeX stuff from special scratch file */

	al__1.aerr = 0;
	al__1.aunit = 17;
	f_rew(&al__1);
L10:
	moveln_(&c__17, &c__12, &done);
	if (! done) {
	    goto L10;
	}
	cl__1.cerr = 0;
	cl__1.cunit = 17;
	cl__1.csta = 0;
	f_clos(&cl__1);
    }

/*  Transfer next 2 lines from main scratch file */

    for (il = 1; il <= 2; ++il) {
	moveln_(&c__11, &c__12, &done);
/* L3: */
    }
    if (compoi_1.ispoi) {
	s_wsfe(&io___948);
/* Writing concatenation */
	i__2[0] = 1, a__2[0] = sq;
	i__2[1] = 14, a__2[1] = "input musixpoi";
	s_cat(ch__3, a__2, i__2, &c__2, (ftnlen)15);
	do_fio(&c__1, ch__3, (ftnlen)15);
	e_wsfe();
    }
    if (*figbass) {

/*  Transfer .fig data from scratch (unit 14) into external .tex (unit 12) */

L4:
	moveln_(&c__14, &c__12, &done);
	if (! done) {
	    goto L4;
	}
	cl__1.cerr = 0;
	cl__1.cunit = 14;
	cl__1.csta = 0;
	f_clos(&cl__1);
    }
    comas3_1.iask = 0;
    ihs = 0;
L1:
    i__3 = s_rsfe(&io___950);
    if (i__3 != 0) {
	goto L999;
    }
    i__3 = do_fio(&c__1, outq, (ftnlen)129);
    if (i__3 != 0) {
	goto L999;
    }
    i__3 = e_rsfe();
    if (i__3 != 0) {
	goto L999;
    }

/*  Hardspaces. */

/* Writing concatenation */
    i__2[0] = 1, a__2[0] = sq;
    i__2[1] = 4, a__2[1] = "xard";
    s_cat(ch__4, a__2, i__2, &c__2, (ftnlen)5);
    if (s_cmp(outq, ch__4, (ftnlen)5, (ftnlen)5) == 0) {
	++ihs;
	*(unsigned char *)&outq[1] = 'h';
	s_wsfi(&io___952);
	do_fio(&c__1, (char *)&comhsp_1.hpttot[ihs - 1], (ftnlen)sizeof(real))
		;
	e_wsfi();
	lenout = 19;
	goto L9;
    }

/*  This part hard-wires ask's into new .tex file as ast's */

L2:
/* Writing concatenation */
    i__2[0] = 1, a__2[0] = sq;
    i__2[1] = 3, a__2[1] = "ask";
    s_cat(ch__5, a__2, i__2, &c__2, (ftnlen)4);
    indxask = i_indx(outq, ch__5, (ftnlen)129, (ftnlen)4);
    if (indxask != 0) {
	++comas3_1.iask;
	putast_(&comas3_1.ask[comas3_1.iask - 1], &indxask, outq, (ftnlen)129)
		;
	goto L2;
    }
    lenout = llen_(outq, &c__129, (ftnlen)129);
L9:
    s_wsfe(&io___955);
    do_fio(&c__1, outq, lenout);
    e_wsfe();

/*  If this is the line with "readmod", check for topmods. */

    if (comas3_1.topmods && s_cmp(outq + 1, "readmod", (ftnlen)7, (ftnlen)7) 
	    == 0) {
	comas3_1.topmods = FALSE_;
	al__1.aerr = 0;
	al__1.aunit = 16;
	f_rew(&al__1);
	for (il = 1; il <= 1000; ++il) {
	    i__3 = s_rsfe(&io___956);
	    if (i__3 != 0) {
		goto L8;
	    }
	    i__3 = do_fio(&c__1, outq, (ftnlen)129);
	    if (i__3 != 0) {
		goto L8;
	    }
	    i__3 = e_rsfe();
	    if (i__3 != 0) {
		goto L8;
	    }
	    lenout = llen_(outq, &c__129, (ftnlen)129);

/*  We inserted the '%' in subroutine littex, to guarantee including blank. */

	    s_wsfe(&io___957);
	    do_fio(&c__1, outq, lenout);
	    e_wsfe();
/* L7: */
	}
L8:
	cl__1.cerr = 0;
	cl__1.cunit = 16;
	cl__1.csta = 0;
	f_clos(&cl__1);
    }
    goto L1;
L999:
    cl__1.cerr = 0;
    cl__1.cunit = 11;
    cl__1.csta = 0;
    f_clos(&cl__1);
    cl__1.cerr = 0;
    cl__1.cunit = 12;
    cl__1.csta = 0;
    f_clos(&cl__1);
    return 0;
} /* askfig_ */

integer llen_(strq, n, strq_len)
char *strq;
integer *n;
ftnlen strq_len;
{
    /* System generated locals */
    integer ret_val;

    for (ret_val = *n; ret_val >= 0; --ret_val) {
	if (*(unsigned char *)&strq[ret_val - 1] != ' ') {
	    return ret_val;
	}
/* L1: */
    }
    return ret_val;
} /* llen_ */

/* Subroutine */ int putast_(elask, indxask, outq, outq_len)
real *elask;
integer *indxask;
char *outq;
ftnlen outq_len;
{
    /* System generated locals */
    address a__1[3];
    integer i__1, i__2[3];
    icilist ici__1;

    /* Builtin functions */
    integer s_wsfi(), do_fio(), e_wsfi();
    /* Subroutine */ int s_copy(), s_cat();

    /* Local variables */
    static integer lp;
    static char tag[129], fmtq[9];

    /* Fortran I/O blocks */
    static icilist io___960 = { 0, fmtq, 0, "(a5,i1,a3)", 9, 1 };


    if (*elask >= (float)0.) {
	if (*elask < (float).995) {
	    lp = 3;
	} else if (*elask < (float)9.995) {
	    lp = 4;
	} else {
	    lp = 5;
	}
	s_wsfi(&io___960);
	do_fio(&c__1, "(a2,f", (ftnlen)5);
	do_fio(&c__1, (char *)&lp, (ftnlen)sizeof(integer));
	do_fio(&c__1, ".2)", (ftnlen)3);
	e_wsfi();
    } else {
	lp = 5;
	s_copy(fmtq, "(a2,f5.1)", (ftnlen)9, (ftnlen)9);
    }

/*  Overwrite as follows:  ...xyz*ask     *lmnop... -> */
/*                         ...xyz*ast{.nn}*lmnop... */
/*                         ...xyz*ast{n.nn}*lmnop... */
/*                         ...xyz*ast{nn.nn}*lmnop... */
/*  or for negative,       ...xyz*ast{-nn.n}*lmnop... */
    i__1 = *indxask + 8;
    s_copy(tag, outq + i__1, (ftnlen)129, 129 - i__1);
    i__1 = *indxask + 2;
    ici__1.icierr = 0;
    ici__1.icirnum = 1;
    ici__1.icirlen = 129 - i__1;
    ici__1.iciunit = outq + i__1;
    ici__1.icifmt = fmtq;
    s_wsfi(&ici__1);
    do_fio(&c__1, "t{", (ftnlen)2);
    do_fio(&c__1, (char *)&(*elask), (ftnlen)sizeof(real));
    e_wsfi();
/* Writing concatenation */
    i__2[0] = *indxask + 4 + lp, a__1[0] = outq;
    i__2[1] = 1, a__1[1] = "}";
    i__2[2] = 129, a__1[2] = tag;
    s_cat(outq, a__1, i__2, &c__3, (ftnlen)129);
    return 0;
} /* putast_ */

/* Subroutine */ int sslur_(lineq, iccount, iv, kv, ip, isdat1, isdat2, 
	isdat3, nsdat, notcrd, nolev, lineq_len)
char *lineq;
integer *iccount, *iv, *kv, *ip, *isdat1, *isdat2, *isdat3, *nsdat;
logical *notcrd;
integer *nolev;
ftnlen lineq_len;
{
    /* System generated locals */
    integer i__1, i__2;

    /* Builtin functions */
    integer i_indx(), i_nint();

    /* Local variables */
    static real fnum;
    static char dumq[1], durq[1];
    static integer ihoff, isdat, ivoff, icurv1, idcode, nolevc, numint;
    extern /* Subroutine */ int getchar_(), readnum_(), setbits_();
    extern integer igetbits_();


/*  Reads in slur data.  Record all h/v-shifts for non-chords, user-specified */
/*  ones for chords. */

/*  See subroutine doslur for bit values in isdat1,2,3 */

/*      invoff = .false. */

/*  Counter for signed integers.  1st is height, 2nd is horiz, 3rd is curve */

    /* Parameter adjustments */
    --isdat3;
    --isdat2;
    --isdat1;

    /* Function Body */
    numint = 0;
    ivoff = 0;
    ihoff = 0;
    ++(*nsdat);
    setbits_(&isdat1[*nsdat], &c__5, &c__13, iv);
    i__1 = *kv - 1;
    setbits_(&isdat1[*nsdat], &c__1, &c__12, &i__1);
    setbits_(&isdat1[*nsdat], &c__8, &c__3, ip);
    isdat3[*nsdat] = 0;

/*  Get id letter */

    if (*(unsigned char *)&lineq[*iccount - 1] == 't') {

/*  Old-style t-slur. Use special idcode = 1 */

	idcode = 1;
    } else {
	getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	if (i_indx("uldtb+- ", durq, (ftnlen)8, (ftnlen)1) > 0) {

/*  Null id */

	    idcode = 32;
	    --(*iccount);
	} else {
	    idcode = *(unsigned char *)durq;
	}
    }
    setbits_(&isdat1[*nsdat], &c__7, &c__19, &idcode);

/*  Set start/stop: look thru list from end for same idcode,iv,kv */

    for (isdat = *nsdat - 1; isdat >= 1; --isdat) {
	if (idcode == igetbits_(&isdat1[isdat], &c__7, &c__19) && *iv == 
		igetbits_(&isdat1[isdat], &c__5, &c__13) && *kv - 1 == 
		igetbits_(&isdat1[isdat], &c__1, &c__12)) {

/*  Matched idcode & ivx.  On/off?.  If on, new is turnoff, leave bit 11 at 0. */

	    if (bit_test(isdat1[isdat],11)) {
		goto L3;
	    }

/*  Found slur is a turnoff, so new one is a turnon.  Jump down to set bit */

	    goto L4;
	}
/* L2: */
    }

/*  If here, this is turnon. */

L4:
    isdat1[*nsdat] = bit_set(isdat1[*nsdat],11);
L3:

/*  Now done with initial turnon- or turnoff-specifics.  Loop for rest of input */

L1:
    getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
    if (i_indx("uld", durq, (ftnlen)3, (ftnlen)1) > 0) {

/*  Force direction */

	isdat1[*nsdat] = bit_set(isdat1[*nsdat],26);
	if (*(unsigned char *)durq == 'u') {
	    isdat1[*nsdat] = bit_set(isdat1[*nsdat],27);
	}
	goto L1;
    } else if (i_indx("+-", durq, (ftnlen)2, (ftnlen)1) > 0) {
	++numint;
	if (numint == 1) {

/*  Vertical offset */

	    ++(*iccount);
	    readnum_(lineq, iccount, dumq, &fnum, (ftnlen)128, (ftnlen)1);
	    --(*iccount);
	    ivoff = i_nint(&fnum);
	    if (*(unsigned char *)durq == '-') {
		ivoff = -ivoff;
	    }
	} else if (numint == 2) {

/*  Horizontal offset */

	    ++(*iccount);
	    readnum_(lineq, iccount, dumq, &fnum, (ftnlen)128, (ftnlen)1);
	    --(*iccount);

/*  fnum is abs(hshift), must be 0 to 6.3 */

	    ihoff = fnum * 10 + (float).5;
	    if (*(unsigned char *)durq == '-') {
		ihoff = -ihoff;
	    }

/*  Later will set bits to 1...127 to represent -6.3,...+6.3 */

	} else {

/*  Must be the 3rd signed integer, so it's a curve specification */

	    isdat3[*nsdat] = bit_set(isdat3[*nsdat],0);
	    ++(*iccount);
	    readnum_(lineq, iccount, dumq, &fnum, (ftnlen)128, (ftnlen)1);
	    icurv1 = i_nint(&fnum);
	    if (*(unsigned char *)durq == '-') {
		icurv1 = -icurv1;
	    }
	    i__1 = icurv1 + 32;
	    setbits_(&isdat3[*nsdat], &c__6, &c__2, &i__1);
	    if (*(unsigned char *)dumq != ':') {

/*  Back up the pointer and loop for more input */

		--(*iccount);
	    } else {

/*  Expect two single digits as parameters for curve */

		isdat3[*nsdat] = bit_set(isdat3[*nsdat],1);
		i__1 = *iccount;
		i__2 = *(unsigned char *)&lineq[i__1] - 48;
		setbits_(&isdat3[*nsdat], &c__3, &c__8, &i__2);
		i__1 = *iccount + 1;
		i__2 = *(unsigned char *)&lineq[i__1] - 48;
		setbits_(&isdat3[*nsdat], &c__3, &c__11, &i__2);
		*iccount += 2;
	    }
	}
	goto L1;
    } else if (*(unsigned char *)durq == 't') {
	isdat2[*nsdat] = bit_set(isdat2[*nsdat],3);
	goto L1;
    } else if (*(unsigned char *)durq == 'b') {
	isdat2[*nsdat] = bit_set(isdat2[*nsdat],4);
	goto L1;
    }

/*  Record shifts */

    i__1 = ivoff + 32;
    setbits_(&isdat2[*nsdat], &c__6, &c__6, &i__1);
    i__1 = ihoff + 64;
    setbits_(&isdat2[*nsdat], &c__7, &c__12, &i__1);

/*  Record chord flag, note level, notehead shift */

    if (*notcrd) {
	setbits_(&isdat2[*nsdat], &c__7, &c__19, nolev);
    } else {
	nolevc = igetbits_(&comtrill_1.icrdat[comtrill_1.ncrd - 1], &c__7, &
		c__12);
	setbits_(&isdat2[*nsdat], &c__7, &c__19, &nolevc);
	isdat2[*nsdat] = bit_set(isdat2[*nsdat],0);
	i__1 = igetbits_(&comtrill_1.icrdat[comtrill_1.ncrd - 1], &c__2, &
		c__23);
	setbits_(&isdat2[*nsdat], &c__2, &c__1, &i__1);
    }
    return 0;
} /* sslur_ */

/* Subroutine */ int setupb_(xelsk, nnb, sumx, sumy, ipb, smed, ixrest)
real *xelsk;
integer *nnb;
real *sumx, *sumy;
integer *ipb;
real *smed;
integer *ixrest;
{
    /* System generated locals */
    integer i__1, i__2;
    real r__1, r__2;

    /* Builtin functions */
    double r_sign();
    integer i_nint(), i_sign();
    double sqrt();

    /* Local variables */
    static integer i__, j;
    static real t;
    static integer n1, ip;
    static real yb1;
    static integer ibc, inb, jnb;
    static real off;
    static integer nsc, iul;
    static real syb, sum, ssq, off1, off2;
    static logical l1ng, l2ng;
    static real beta, smin, eskz0;
    static integer ipxt1;
    extern integer ncmid_();
    static real ybeam, xboff, slope[800], ynote;
    extern /* Subroutine */ int setbm2_();
    static integer nscmid;
    static real dnolev;
    static integer nolevo;
    static real xnolev2, deficit;
    static integer ipxtmid;


/* The outer combo algorithm */

    /* Parameter adjustments */
    --ipb;
    --xelsk;

    /* Function Body */
    ibc = all_1.ibmcnt[commvl_1.ivx - 1];
    n1 = 255 & all_1.ipl[commvl_1.ivx + all_1.ibm1[commvl_1.ivx + ibc * 15 - 
	    16] * 15 - 16];

/*  Set flag for xtup beam starting with rest (no others can start with rest) */

    if (bit_test(all_1.irest[commvl_1.ivx + all_1.ipo[n1 - 1] * 15 - 16],0)) {
	*ixrest = 1;
    }

/* Figure how many elemskips to each note. Use the list, counting only non-rests. */

    eskz0 = all_1.eskz[commvl_1.ivx + all_1.ibm1[commvl_1.ivx + ibc * 15 - 16]
	     * 15 - 16];
    *nnb = 0;
    *sumx = (float)0.;
    *sumy = (float)0.;
    ipxt1 = 0;
    i__1 = all_1.ibm2[commvl_1.ivx + ibc * 15 - 16];
    for (ip = all_1.ibm1[commvl_1.ivx + ibc * 15 - 16]; ip <= i__1; ++ip) {
	if (! bit_test(all_1.irest[commvl_1.ivx + ip * 15 - 16],0)) {
	    ++(*nnb);
	    ipb[*nnb] = ip;
	    xelsk[*nnb] = all_1.eskz[commvl_1.ivx + ip * 15 - 16] - eskz0;
	    *sumx += xelsk[*nnb];
	    *sumy += all_1.nolev[commvl_1.ivx + ipb[*nnb] * 15 - 16];
	}

/*  New xtup stuff here.  Final object is to get distance from start of xtup */
/*    to number. May also want to count xtup here, for first time. */

	if (ipxt1 == 0 && all_1.nodur[commvl_1.ivx + ip * 15 - 16] == 0) {

/*  Xtup is starting here */

	    ipxt1 = ip;
	} else if (ipxt1 > 0 && all_1.nodur[commvl_1.ivx + ip * 15 - 16] > 0) 
		{

/*  Xtup ends here.  Set number of notes in xtup.  This may not be necessary. */

	    comxtup_2.ntupv[commvl_1.ivx - 1] = ip + 1 - ipxt1;

/*  Middle note of xtup if ntupv odd, note to left of gap if even. */

	    ipxtmid = (ip + ipxt1) / 2;
	    comxtup_2.eloff[commvl_1.ivx - 1] = all_1.eskz[commvl_1.ivx + 
		    ipxtmid * 15 - 16] - all_1.eskz[commvl_1.ivx + ipxt1 * 15 
		    - 16];
	    if (comxtup_2.ntupv[commvl_1.ivx - 1] % 2 == 0) {
		comxtup_2.eloff[commvl_1.ivx - 1] += (all_1.eskz[commvl_1.ivx 
			+ (ipxtmid + 1) * 15 - 16] - all_1.eskz[commvl_1.ivx 
			+ ipxtmid * 15 - 16]) * (float).5;
	    }
	    ipxt1 = 0;
	}
/* L2: */
    }
    *smed = (float)0.;
    if (! bit_test(all_1.islur[commvl_1.ivx + ipb[1] * 15 - 16],2)) {

/* No forced 0 slope */

	if (*nnb == 1) {
	    goto L6;
	}
	nsc = 0;
	i__1 = *nnb - 1;
	for (inb = 1; inb <= i__1; ++inb) {
	    i__2 = *nnb;
	    for (jnb = inb + 1; jnb <= i__2; ++jnb) {
		++nsc;
		slope[nsc - 1] = (all_1.nolev[commvl_1.ivx + ipb[jnb] * 15 - 
			16] - all_1.nolev[commvl_1.ivx + ipb[inb] * 15 - 16]) 
			/ (xelsk[jnb] - xelsk[inb]);
		if ((r__1 = slope[nsc - 1], dabs(r__1)) < (float)1e-4) {
		    ++nsc;
		    slope[nsc - 1] = slope[nsc - 2];
		    ++nsc;
		    slope[nsc - 1] = slope[nsc - 2];
		}
/* L5: */
	    }
	}
	if (nsc == 1) {
	    *smed = slope[0];
	    goto L6;
	}
	nscmid = nsc / 2 + 1;
	i__2 = nscmid;
	for (i__ = 1; i__ <= i__2; ++i__) {
	    i__1 = nsc;
	    for (j = i__ + 1; j <= i__1; ++j) {
		if (slope[j - 1] < slope[i__ - 1]) {
		    t = slope[j - 1];
		    slope[j - 1] = slope[i__ - 1];
		    slope[i__ - 1] = t;
		}
/* L7: */
	    }
	}
	*smed = slope[nscmid - 1];
	if (nsc == nsc / 2 << 1) {

/*  Even number of slopes in the list, so median is ambiguous */

	    if ((r__2 = slope[nscmid - 2], dabs(r__2)) < (r__1 = slope[nscmid 
		    - 1], dabs(r__1)) - comtol_1.tol) {

/*  Lower-numbered one is truly less in absolute value, so use it */

		*smed = slope[nscmid - 2];
	    } else if ((r__1 = slope[nscmid - 2] + slope[nscmid - 1], dabs(
		    r__1)) < comtol_1.tol) {

/*  Two slopes are effectively equal.  Take the one with sign of the average */

		sum = (float)0.;
		i__1 = nsc;
		for (i__ = 1; i__ <= i__1; ++i__) {
		    sum += slope[i__ - 1];
/* L1: */
		}
		*smed = r_sign(smed, &sum);
	    }
	}
L6:
	r__1 = *smed * (float).5 * all_1.slfac;
	comxtup_2.islope[commvl_1.ivx - 1] = i_nint(&r__1);
	if ((i__1 = comxtup_2.islope[commvl_1.ivx - 1], abs(i__1)) > 9) {
	    comxtup_2.islope[commvl_1.ivx - 1] = i_sign(&c__9, &
		    comxtup_2.islope[commvl_1.ivx - 1]);
	}
    } else {

/*  Forced horizontal beam */

	comxtup_2.islope[commvl_1.ivx - 1] = 0;
    }
    beta = (*sumy - comxtup_2.islope[commvl_1.ivx - 1] / all_1.slfac * *sumx) 
	    / *nnb;

/*  If ixrest>0, this is a virtual nolev1 at location of rest.  Will first use */
/*  as is for placing xtup number and/or bracket, then reset it for start of */
/*  actual beam */

    comxtup_2.nolev1[commvl_1.ivx - 1] = i_nint(&beta);

/*  Check if any stems are too short */

    smin = (float)100.;
    iul = -1;
    if (*(unsigned char *)&all_1.ulq[commvl_1.ivx + ibc * 15 - 16] == 'u') {
	iul = 1;
    }
    ssq = (float)0.;
    syb = (float)0.;
    yb1 = comxtup_2.nolev1[commvl_1.ivx - 1] + iul * (all_1.stemlen + 
	    combmh_1.bmhgt * (all_1.mult[commvl_1.ivx + ipb[1] * 15 - 16] - 1)
	    );
    i__1 = *nnb;
    for (inb = 1; inb <= i__1; ++inb) {
	ybeam = yb1 + comxtup_2.islope[commvl_1.ivx - 1] * xelsk[inb] / 
		all_1.slfac - iul * combmh_1.bmhgt * (all_1.mult[commvl_1.ivx 
		+ ipb[inb] * 15 - 16] - 1);
	syb += ybeam;
	ynote = (real) all_1.nolev[commvl_1.ivx + ipb[inb] * 15 - 16];
	off = ybeam - ynote;
	if (inb == 1) {
	    off1 = off;
	} else if (inb == *nnb) {
	    off2 = off;
	}
	ssq += off * off;
/* Computing MIN */
	r__1 = smin, r__2 = iul * off;
	smin = dmin(r__1,r__2);
/* L4: */
    }
    dnolev = (float)0.;
    if (smin < all_1.stemmin) {
	deficit = all_1.stemmin - smin;
	nolevo = comxtup_2.nolev1[commvl_1.ivx - 1];
	r__1 = comxtup_2.nolev1[commvl_1.ivx - 1] + iul * deficit;
	comxtup_2.nolev1[commvl_1.ivx - 1] = i_nint(&r__1);
	dnolev = (real) (comxtup_2.nolev1[commvl_1.ivx - 1] - nolevo);
	off1 += dnolev;
	off2 += dnolev;
    }
/* Computing 2nd power */
    r__1 = dnolev;
    ssq = ssq + dnolev * 2 * (syb - *sumy) + r__1 * r__1;
    if (! comxtup_2.vxtup[commvl_1.ivx - 1] && sqrt(ssq / *nnb) > 
	    all_1.stemmax && (dabs(off1) < all_1.stemmax || dabs(off2) < 
	    all_1.stemmax) && ! bit_test(all_1.islur[commvl_1.ivx + ipb[1] * 
	    15 - 16],2)) {

/*  The first check is to save trouble of putting xtup's in setbm2. */
/*  The penultimate check is that first and last stems aren't both excessive. */
/*  The last check is that a 0 slope has not been forced */

	setbm2_(&xelsk[1], nnb, sumx, sumy, &ipb[1], &comxtup_2.islope[
		commvl_1.ivx - 1], &comxtup_2.nolev1[commvl_1.ivx - 1]);
    }

/*  Check if beam starts or ends too high or low. */

    xboff = combmh_1.bmhgt * (all_1.mult[commvl_1.ivx + ipb[1] * 15 - 16] - 1)
	    ;
    l1ng = iul * (comxtup_2.nolev1[commvl_1.ivx - 1] - ncmid_(&all_1.iv, &ipb[
	    1])) + xboff + 7 < (float)0.;
    xnolev2 = comxtup_2.nolev1[commvl_1.ivx - 1] + comxtup_2.islope[
	    commvl_1.ivx - 1] / all_1.slfac * xelsk[*nnb];
    l2ng = iul * (xnolev2 - ncmid_(&all_1.iv, &ipb[*nnb])) + xboff + 7 < (
	    float)0.;
    if (l1ng || l2ng) {

/*  Need to correct start or stop, also slope */

	if (l1ng) {
	    r__1 = ncmid_(&all_1.iv, &ipb[1]) - (xboff + (float)7.) * iul;
	    comxtup_2.nolev1[commvl_1.ivx - 1] = i_nint(&r__1);
	}
	if (l2ng) {
	    r__1 = ncmid_(&all_1.iv, &ipb[*nnb]) - (xboff + (float)7.) * iul;
	    xnolev2 = (real) i_nint(&r__1);
	}

/*  Since one or the other end has changed, need to change slope */

	if (! bit_test(all_1.islur[commvl_1.ivx + ipb[1] * 15 - 16],2)) {
	    r__1 = all_1.slfac * (xnolev2 - comxtup_2.nolev1[commvl_1.ivx - 1]
		    ) / xelsk[*nnb];
	    comxtup_2.islope[commvl_1.ivx - 1] = i_nint(&r__1);
	}
    }
    return 0;
} /* setupb_ */

/* Subroutine */ int setbm2_(xelsk, nnb, sumx, sumy, ipb, islope, nolev1)
real *xelsk;
integer *nnb;
real *sumx, *sumy;
integer *ipb, *islope, *nolev1;
{
    /* System generated locals */
    integer i__1;
    real r__1, r__2;

    /* Builtin functions */
    integer i_nint(), i_sign();

    /* Local variables */
    static real em;
    static integer ibc, inb, iul;
    static real beta, smin, delta, ybeam, ynote, sumxx, sumxy, deficit;


/* The MEAN SQUARE slope algorithm */

    /* Parameter adjustments */
    --ipb;
    --xelsk;

    /* Function Body */
    ibc = all_1.ibmcnt[commvl_1.ivx - 1];
    sumxx = (float)0.;
    sumxy = (float)0.;
    i__1 = *nnb;
    for (inb = 1; inb <= i__1; ++inb) {
/* Computing 2nd power */
	r__1 = xelsk[inb];
	sumxx += r__1 * r__1;
	sumxy += xelsk[inb] * all_1.nolev[commvl_1.ivx + ipb[inb] * 15 - 16];
/* L2: */
    }
    delta = *nnb * sumxx - *sumx * *sumx;
    em = (*nnb * sumxy - *sumx * *sumy) / delta;
    r__1 = em * (float).5 * all_1.slfac;
    *islope = i_nint(&r__1);
    if (abs(*islope) > 9) {
	*islope = i_sign(&c__9, islope);
    }
    beta = (*sumy - *islope / all_1.slfac * *sumx) / *nnb;
    *nolev1 = i_nint(&beta);

/*   Check if any stems are too short */

    smin = (float)100.;
    iul = -1;
    if (*(unsigned char *)&all_1.ulq[commvl_1.ivx + ibc * 15 - 16] == 'u') {
	iul = 1;
    }
    i__1 = *nnb;
    for (inb = 1; inb <= i__1; ++inb) {
	ybeam = *nolev1 + iul * all_1.stemlen + *islope * xelsk[inb] / 
		all_1.slfac;
	ynote = (real) all_1.nolev[commvl_1.ivx + ipb[inb] * 15 - 16];
/* Computing MIN */
	r__1 = smin, r__2 = iul * (ybeam - ynote);
	smin = dmin(r__1,r__2);
/* L4: */
    }
    if (smin < all_1.stemmin) {
	deficit = all_1.stemmin - smin;
	r__1 = *nolev1 + iul * deficit;
	*nolev1 = i_nint(&r__1);
    }
    return 0;
} /* setbm2_ */

integer ncmid_(iv, ip)
integer *iv, *ip;
{
    /* System generated locals */
    integer ret_val;

    /* Builtin functions */
    integer s_wsle(), do_lio(), e_wsle();
    /* Subroutine */ int s_stop();

    /* Local variables */
    static integer icc;
    static real xtime;

    /* Fortran I/O blocks */
    static cilist io___1019 = { 0, 6, 0, 0, 0 };


    if (comcc_1.ncc[*iv - 1] == 1) {
	ret_val = comcc_1.ncmidcc[*iv - 1];
    } else {
	xtime = all_2.to[(255 & all_2.ipl[commvl_1.ivx + *ip * 15 - 16]) - 1];
	for (icc = comcc_1.ncc[*iv - 1]; icc >= 1; --icc) {
	    if (xtime > comcc_1.tcc[*iv + icc * 15 - 16] - comtol_1.tol) {
		ret_val = comcc_1.ncmidcc[*iv + icc * 15 - 16];
		return ret_val;
	    }
/* L1: */
	}
	s_wsle(&io___1019);
	do_lio(&c__9, &c__1, "Problem in ncmid()", (ftnlen)18);
	e_wsle();
	s_stop("", (ftnlen)0);
    }
    return ret_val;
} /* ncmid_ */

/* Subroutine */ int clefsym_(isl, notexq, lnote, nclef, notexq_len)
integer *isl;
char *notexq;
integer *lnote, *nclef;
ftnlen notexq_len;
{
    /* System generated locals */
    address a__1[4];
    integer i__1[4], i__2, i__3;
    char ch__1[1], ch__2[1], ch__3[1];

    /* Builtin functions */
    integer lbit_shift();
    /* Subroutine */ int s_cat();

    /* Local variables */
    extern /* Character */ VOID chax_();
    static integer nlev;


/*  Returns string calling Don's TeX macro \pmxclef, for drawing small clefs. */

    *nclef = lbit_shift(*isl, (ftnlen)-12) & 7;
    if (*nclef == 0) {

/*  treble */

	nlev = 2;
    } else if (*nclef > 6) {

/*  French violin */

	nlev = 0;
    } else if (*nclef < 5) {

/*  C-clef */

	nlev = (*nclef << 1) - 2;
    } else {

/*  F-clef */

	nlev = (*nclef << 1) - 6;
    }
/* Writing concatenation */
    chax_(ch__1, (ftnlen)1, &c__92);
    i__1[0] = 1, a__1[0] = ch__1;
    i__1[1] = 7, a__1[1] = "pmxclef";
    i__2 = min(*nclef,7) + 48;
    chax_(ch__2, (ftnlen)1, &i__2);
    i__1[2] = 1, a__1[2] = ch__2;
    i__3 = nlev + 48;
    chax_(ch__3, (ftnlen)1, &i__3);
    i__1[3] = 1, a__1[3] = ch__3;
    s_cat(notexq, a__1, i__1, &c__4, notexq_len);
    *lnote = 10;
    return 0;
} /* clefsym_ */

/* Subroutine */ int accsym_(nacc, acsymq, lacc, acsymq_len)
integer *nacc;
char *acsymq;
integer *lacc;
ftnlen acsymq_len;
{
    /* Builtin functions */
    /* Subroutine */ int s_copy();
    integer s_wsle(), do_lio(), e_wsle();

    /* Local variables */
    static integer iacc;

    /* Fortran I/O blocks */
    static cilist io___1022 = { 0, 6, 0, 0, 0 };


    iacc = *nacc & 7;
    if (iacc == 1) {
	s_copy(acsymq, "fl", (ftnlen)3, (ftnlen)2);
	*lacc = 2;
    } else if (iacc == 2) {
	s_copy(acsymq, "sh", (ftnlen)3, (ftnlen)2);
	*lacc = 2;
    } else if (iacc == 3) {
	s_copy(acsymq, "na", (ftnlen)3, (ftnlen)2);
	*lacc = 2;
    } else if (iacc == 5) {
	s_copy(acsymq, "dfl", (ftnlen)3, (ftnlen)3);
	*lacc = 3;
    } else if (iacc == 6) {
	s_copy(acsymq, "dsh", (ftnlen)3, (ftnlen)3);
	*lacc = 3;
    } else {
	s_wsle(&io___1022);
	do_lio(&c__9, &c__1, "bad accidental: ", (ftnlen)16);
	do_lio(&c__3, &c__1, (char *)&iacc, (ftnlen)sizeof(integer));
	e_wsle();
    }
    return 0;
} /* accsym_ */

/* Subroutine */ int littex_(islur, nnl, iv, topmods, lineq, iccount, 
	lineq_len)
integer *islur, *nnl, *iv;
logical *topmods;
char *lineq;
integer *iccount;
ftnlen lineq_len;
{
    /* System generated locals */
    address a__1[2], a__2[3];
    integer i__1[2], i__2[3];
    char ch__1[1], ch__2[129];
    olist o__1;

    /* Builtin functions */
    /* Subroutine */ int s_cat();
    integer s_wsle(), e_wsle(), do_lio(), s_wsfe(), do_fio(), e_wsfe();
    /* Subroutine */ int s_stop();
    integer f_open();

    /* Local variables */
    extern /* Character */ VOID chax_();
    static char durq[1];
    static logical merge;
    static integer itype;
    extern /* Subroutine */ int getchar_();

    /* Fortran I/O blocks */
    static cilist io___1026 = { 0, 6, 0, 0, 0 };
    static cilist io___1027 = { 0, 6, 0, 0, 0 };
    static cilist io___1028 = { 0, 15, 0, "(/,a)", 0 };
    static cilist io___1029 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1030 = { 0, 16, 0, "(a)", 0 };


    /* Parameter adjustments */
    islur -= 16;

    /* Function Body */
    merge = FALSE_;
    if (comgrace_1.nlit > 0) {
	merge = *iv == comgrace_1.ivlit[comgrace_1.nlit - 1] && *nnl == 
		comgrace_1.iplit[comgrace_1.nlit - 1];
    }
    ++comgrace_1.nlit;
    comgrace_1.ivlit[comgrace_1.nlit - 1] = *iv;
    comgrace_1.iplit[comgrace_1.nlit - 1] = *nnl;
    itype = 1;
L17:
    getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
    chax_(ch__1, (ftnlen)1, &c__92);
    if (*(unsigned char *)durq == *(unsigned char *)&ch__1[0]) {
	++itype;
	goto L17;
    }
/* Writing concatenation */
    chax_(ch__1, (ftnlen)1, &c__92);
    i__1[0] = 1, a__1[0] = ch__1;
    i__1[1] = 1, a__1[1] = durq;
    s_cat(comgrace_1.litq + (comgrace_1.nlit - 1 << 7), a__1, i__1, &c__2, (
	    ftnlen)128);
    comgrace_1.lenlit[comgrace_1.nlit - 1] = 2;
L18:
    getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
    chax_(ch__1, (ftnlen)1, &c__92);
    if (*(unsigned char *)durq == *(unsigned char *)&ch__1[0]) {
	getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	if (*(unsigned char *)durq != ' ') {

/*  Starting a new tex command within the string */

/* Writing concatenation */
	    i__2[0] = comgrace_1.lenlit[comgrace_1.nlit - 1], a__2[0] = 
		    comgrace_1.litq + (comgrace_1.nlit - 1 << 7);
	    chax_(ch__1, (ftnlen)1, &c__92);
	    i__2[1] = 1, a__2[1] = ch__1;
	    i__2[2] = 1, a__2[2] = durq;
	    s_cat(comgrace_1.litq + (comgrace_1.nlit - 1 << 7), a__2, i__2, &
		    c__3, (ftnlen)128);
	    comgrace_1.lenlit[comgrace_1.nlit - 1] += 2;
	    goto L18;
	}
    } else {
/* Writing concatenation */
	i__1[0] = comgrace_1.lenlit[comgrace_1.nlit - 1], a__1[0] = 
		comgrace_1.litq + (comgrace_1.nlit - 1 << 7);
	i__1[1] = 1, a__1[1] = durq;
	s_cat(comgrace_1.litq + (comgrace_1.nlit - 1 << 7), a__1, i__1, &c__2,
		 (ftnlen)128);
	++comgrace_1.lenlit[comgrace_1.nlit - 1];
	goto L18;
    }

/*  If here, just read backslash-blank so string is done */

    if (itype == 1) {
	islur[*iv + *nnl * 15] = bit_set(islur[*iv + *nnl * 15],16);
	if (merge) {

/*  There are 2 separate strings on the same note, so merge them. */

	    --comgrace_1.nlit;
/* Writing concatenation */
	    i__1[0] = comgrace_1.lenlit[comgrace_1.nlit - 1], a__1[0] = 
		    comgrace_1.litq + (comgrace_1.nlit - 1 << 7);
	    i__1[1] = comgrace_1.lenlit[comgrace_1.nlit], a__1[1] = 
		    comgrace_1.litq + (comgrace_1.nlit << 7);
	    s_cat(comgrace_1.litq + (comgrace_1.nlit - 1 << 7), a__1, i__1, &
		    c__2, (ftnlen)128);
	    comgrace_1.lenlit[comgrace_1.nlit - 1] += comgrace_1.lenlit[
		    comgrace_1.nlit];
	    if (comgrace_1.lenlit[comgrace_1.nlit - 1] > 128) {
		s_wsle(&io___1026);
		e_wsle();
		s_wsle(&io___1027);
		do_lio(&c__9, &c__1, "Merged type-1 TeX strings longer than \
128 characters", (ftnlen)52);
		e_wsle();
		s_wsfe(&io___1028);
		do_fio(&c__1, "Merged type-1 TeX strings longer than 128 cha\
racters", (ftnlen)52);
		e_wsfe();
		s_stop("1", (ftnlen)1);
	    }
	}
    } else {
	if (itype == 3) {

/*  Write the string NOW */

	    if (comlast_1.islast) {
		s_wsfe(&io___1029);
/* Writing concatenation */
		i__1[0] = comgrace_1.lenlit[comgrace_1.nlit - 1], a__1[0] = 
			comgrace_1.litq + (comgrace_1.nlit - 1 << 7);
		i__1[1] = 1, a__1[1] = "%";
		s_cat(ch__2, a__1, i__1, &c__2, (ftnlen)129);
		do_fio(&c__1, ch__2, comgrace_1.lenlit[comgrace_1.nlit - 1] + 
			1);
		e_wsfe();
	    }
	} else {

/*  Must go at top */

	    if (! (*topmods)) {
		*topmods = TRUE_;
		o__1.oerr = 0;
		o__1.ounit = 16;
		o__1.ofnm = 0;
		o__1.orl = 0;
		o__1.osta = "SCRATCH";
		o__1.oacc = 0;
		o__1.ofm = 0;
		o__1.oblnk = 0;
		f_open(&o__1);
	    }

/*  Must write '%' here rather than later, in case string ends with blank. */

	    s_wsfe(&io___1030);
/* Writing concatenation */
	    i__1[0] = comgrace_1.lenlit[comgrace_1.nlit - 1], a__1[0] = 
		    comgrace_1.litq + (comgrace_1.nlit - 1 << 7);
	    i__1[1] = 1, a__1[1] = "%";
	    s_cat(ch__2, a__1, i__1, &c__2, (ftnlen)129);
	    do_fio(&c__1, ch__2, comgrace_1.lenlit[comgrace_1.nlit - 1] + 1);
	    e_wsfe();
	}
	--comgrace_1.nlit;
    }
    return 0;
} /* littex_ */

/* Subroutine */ int putfig_(ifig, offnsk, figcheck, soutq, lsout, soutq_len)
integer *ifig;
real *offnsk;
logical *figcheck;
char *soutq;
integer *lsout;
ftnlen soutq_len;
{
    /* System generated locals */
    address a__1[2], a__2[3], a__3[6];
    integer i__1[2], i__2[3], i__3, i__4[6];
    real r__1;
    char ch__1[1], ch__2[12], ch__3[20], ch__4[19], ch__5[18], ch__6[17];

    /* Builtin functions */
    /* Subroutine */ int s_cat();
    integer s_wsfi(), do_fio(), e_wsfi();
    /* Subroutine */ int s_copy();

    /* Local variables */
    static integer ic;
    static char sq[1];
    static integer nof;
    static char ch1q[1], ch2q[1];
    extern /* Character */ VOID chax_();
    static integer nofa;
    static char figq[6];
    static integer lnof;
    static char nofq[2];
    static integer lnofa;
    static char nofaq[2];
    static integer lnote;
    extern /* Subroutine */ int addstr_();
    static char notexq[80];

    /* Fortran I/O blocks */
    static icilist io___1033 = { 0, notexq+5, 0, "(f6.2)", 6, 1 };
    static icilist io___1035 = { 0, notexq+5, 0, "(f5.2)", 5, 1 };
    static icilist io___1036 = { 0, notexq+5, 0, "(f4.2)", 4, 1 };
    static icilist io___1037 = { 0, notexq+5, 0, "(f3.2)", 3, 1 };
    static icilist io___1048 = { 0, notexq+5, 0, "(f6.2)", 6, 1 };
    static icilist io___1049 = { 0, notexq+5, 0, "(f5.2)", 5, 1 };
    static icilist io___1050 = { 0, notexq+5, 0, "(f4.2)", 4, 1 };
    static icilist io___1051 = { 0, notexq+5, 0, "(f3.2)", 3, 1 };


    chax_(ch__1, (ftnlen)1, &c__92);
    *(unsigned char *)sq = *(unsigned char *)&ch__1[0];
    if (dabs(*offnsk) > (float)1e-4) {

/*  Write offset for floating figure, to two decimal places */

/* Writing concatenation */
	i__1[0] = 1, a__1[0] = sq;
	i__1[1] = 4, a__1[1] = "off{";
	s_cat(notexq, a__1, i__1, &c__2, (ftnlen)80);
	if (-(*offnsk) < (float)-9.995) {
	    s_wsfi(&io___1033);
	    r__1 = -(*offnsk);
	    do_fio(&c__1, (char *)&r__1, (ftnlen)sizeof(real));
	    e_wsfi();
	    lnote = 11;
	} else if (-(*offnsk) < (float)-.995 || -(*offnsk) > (float)9.995) {
	    s_wsfi(&io___1035);
	    r__1 = -(*offnsk);
	    do_fio(&c__1, (char *)&r__1, (ftnlen)sizeof(real));
	    e_wsfi();
	    lnote = 10;
	} else if (-(*offnsk) < (float)-1e-4 || -(*offnsk) > (float).995) {
	    s_wsfi(&io___1036);
	    r__1 = -(*offnsk);
	    do_fio(&c__1, (char *)&r__1, (ftnlen)sizeof(real));
	    e_wsfi();
	    lnote = 9;
	} else {
	    s_wsfi(&io___1037);
	    r__1 = -(*offnsk);
	    do_fio(&c__1, (char *)&r__1, (ftnlen)sizeof(real));
	    e_wsfi();
	    lnote = 8;
	}
/* Writing concatenation */
	i__2[0] = lnote, a__2[0] = notexq;
	i__2[1] = 1, a__2[1] = sq;
	i__2[2] = 9, a__2[2] = "noteskip}";
	s_cat(notexq, a__2, i__2, &c__3, (ftnlen)80);
	i__3 = lnote + 10;
	addstr_(notexq, &i__3, soutq, lsout, (ftnlen)80, (ftnlen)80);
    }
    s_copy(figq, comfig_2.figqq + (*ifig - 1) * 6, (ftnlen)6, (ftnlen)6);
    ic = 1;
    nof = 0;
    nofa = -1;

/*  Beginning of loop */

L1:
    *(unsigned char *)ch1q = *(unsigned char *)&figq[ic - 1];

/*  Exit when first blank is encountered */

    if (*(unsigned char *)ch1q == ' ') {
	goto L2;
    }

/*  Just starting or not yet finished.  Set up vertical offset. */

    lnof = 1;
    i__3 = nof + 48;
    chax_(ch__1, (ftnlen)1, &i__3);
    s_copy(nofq, ch__1, (ftnlen)2, (ftnlen)1);
    if (nof > 9) {
	lnof = 2;
/* Writing concatenation */
	i__1[0] = 1, a__1[0] = "1";
	i__3 = nof + 38;
	chax_(ch__1, (ftnlen)1, &i__3);
	i__1[1] = 1, a__1[1] = ch__1;
	s_cat(nofq, a__1, i__1, &c__2, (ftnlen)2);
    }
    if (nofa == -1) {
	lnofa = 2;
	s_copy(nofaq, "-1", (ftnlen)2, (ftnlen)2);
    } else if (nofa < 10) {
	lnofa = 1;
	i__3 = nofa + 48;
	chax_(ch__1, (ftnlen)1, &i__3);
	s_copy(nofaq, ch__1, (ftnlen)2, (ftnlen)1);
    } else {
	lnofa = 2;
/* Writing concatenation */
	i__1[0] = 1, a__1[0] = "1";
	i__3 = nofa + 38;
	chax_(ch__1, (ftnlen)1, &i__3);
	i__1[1] = 1, a__1[1] = ch__1;
	s_cat(nofaq, a__1, i__1, &c__2, (ftnlen)2);
    }
    if (*(unsigned char *)ch1q == '0') {

/*  Continuation figure.  Next digit is length (in noteskips) */

	++ic;
	*(unsigned char *)ch2q = *(unsigned char *)&figq[ic - 1];
/* Writing concatenation */
	i__4[0] = 1, a__3[0] = sq;
	i__4[1] = 5, a__3[1] = "Cont{";
	i__4[2] = lnof, a__3[2] = nofq;
	i__4[3] = 2, a__3[3] = "}{";
	i__4[4] = 1, a__3[4] = ch2q;
	i__4[5] = 1, a__3[5] = "}";
	s_cat(ch__2, a__3, i__4, &c__6, (ftnlen)12);
	i__3 = lnof + 10;
	addstr_(ch__2, &i__3, soutq, lsout, lnof + 10, (ftnlen)80);
    } else if (*(unsigned char *)ch1q == '#' || *(unsigned char *)ch1q == '-' 
	    || *(unsigned char *)ch1q == 'n') {
	++ic;
	*(unsigned char *)ch2q = *(unsigned char *)&figq[ic - 1];
	if (*(unsigned char *)ch2q == ' ') {

/*  Figure is a stand-alone accidental, so must be centered */

	    if (*(unsigned char *)ch1q == '#') {
/* Writing concatenation */
		i__4[0] = 1, a__3[0] = sq;
		i__4[1] = 5, a__3[1] = "Figu{";
		i__4[2] = lnofa, a__3[2] = nofaq;
		i__4[3] = 2, a__3[3] = "}{";
		i__4[4] = 1, a__3[4] = sq;
		i__4[5] = 9, a__3[5] = "sharpfig}";
		s_cat(ch__3, a__3, i__4, &c__6, (ftnlen)20);
		i__3 = lnofa + 18;
		addstr_(ch__3, &i__3, soutq, lsout, lnofa + 18, (ftnlen)80);
	    } else if (*(unsigned char *)ch1q == '-') {
/* Writing concatenation */
		i__4[0] = 1, a__3[0] = sq;
		i__4[1] = 5, a__3[1] = "Figu{";
		i__4[2] = lnofa, a__3[2] = nofaq;
		i__4[3] = 2, a__3[3] = "}{";
		i__4[4] = 1, a__3[4] = sq;
		i__4[5] = 8, a__3[5] = "flatfig}";
		s_cat(ch__4, a__3, i__4, &c__6, (ftnlen)19);
		i__3 = lnofa + 17;
		addstr_(ch__4, &i__3, soutq, lsout, lnofa + 17, (ftnlen)80);
	    } else if (*(unsigned char *)ch1q == 'n') {
/* Writing concatenation */
		i__4[0] = 1, a__3[0] = sq;
		i__4[1] = 5, a__3[1] = "Figu{";
		i__4[2] = lnofa, a__3[2] = nofaq;
		i__4[3] = 2, a__3[3] = "}{";
		i__4[4] = 1, a__3[4] = sq;
		i__4[5] = 7, a__3[5] = "natfig}";
		s_cat(ch__5, a__3, i__4, &c__6, (ftnlen)18);
		i__3 = lnofa + 16;
		addstr_(ch__5, &i__3, soutq, lsout, lnofa + 16, (ftnlen)80);
	    }
	    goto L2;
	} else {

/*  Figure is an accidental followed by a number */
/*  First put the accidental (offset to the left) */

	    if (*(unsigned char *)ch1q == '#') {
/* Writing concatenation */
		i__4[0] = 1, a__3[0] = sq;
		i__4[1] = 5, a__3[1] = "Figu{";
		i__4[2] = lnofa, a__3[2] = nofaq;
		i__4[3] = 2, a__3[3] = "}{";
		i__4[4] = 1, a__3[4] = sq;
		i__4[5] = 6, a__3[5] = "fsmsh}";
		s_cat(ch__6, a__3, i__4, &c__6, (ftnlen)17);
		i__3 = lnofa + 15;
		addstr_(ch__6, &i__3, soutq, lsout, lnofa + 15, (ftnlen)80);
	    } else if (*(unsigned char *)ch1q == '-') {
/* Writing concatenation */
		i__4[0] = 1, a__3[0] = sq;
		i__4[1] = 5, a__3[1] = "Figu{";
		i__4[2] = lnofa, a__3[2] = nofaq;
		i__4[3] = 2, a__3[3] = "}{";
		i__4[4] = 1, a__3[4] = sq;
		i__4[5] = 6, a__3[5] = "fsmfl}";
		s_cat(ch__6, a__3, i__4, &c__6, (ftnlen)17);
		i__3 = lnofa + 15;
		addstr_(ch__6, &i__3, soutq, lsout, lnofa + 15, (ftnlen)80);
	    } else if (*(unsigned char *)ch1q == 'n') {
/* Writing concatenation */
		i__4[0] = 1, a__3[0] = sq;
		i__4[1] = 5, a__3[1] = "Figu{";
		i__4[2] = lnofa, a__3[2] = nofaq;
		i__4[3] = 2, a__3[3] = "}{";
		i__4[4] = 1, a__3[4] = sq;
		i__4[5] = 6, a__3[5] = "fsmna}";
		s_cat(ch__6, a__3, i__4, &c__6, (ftnlen)17);
		i__3 = lnofa + 15;
		addstr_(ch__6, &i__3, soutq, lsout, lnofa + 15, (ftnlen)80);
	    }

/*  Now put the number */

/* Writing concatenation */
	    i__4[0] = 1, a__3[0] = sq;
	    i__4[1] = 5, a__3[1] = "Figu{";
	    i__4[2] = lnof, a__3[2] = nofq;
	    i__4[3] = 2, a__3[3] = "}{";
	    i__4[4] = 1, a__3[4] = ch2q;
	    i__4[5] = 1, a__3[5] = "}";
	    s_cat(ch__2, a__3, i__4, &c__6, (ftnlen)12);
	    i__3 = lnof + 10;
	    addstr_(ch__2, &i__3, soutq, lsout, lnof + 10, (ftnlen)80);
	}
    } else if (*(unsigned char *)ch1q == '_') {

/*  Placeholder only (for lowering a figure).  Don't do anything! */

    } else {

/*  Figure is a single number */

/* Writing concatenation */
	i__4[0] = 1, a__3[0] = sq;
	i__4[1] = 5, a__3[1] = "Figu{";
	i__4[2] = lnof, a__3[2] = nofq;
	i__4[3] = 2, a__3[3] = "}{";
	i__4[4] = 1, a__3[4] = ch1q;
	i__4[5] = 1, a__3[5] = "}";
	s_cat(ch__2, a__3, i__4, &c__6, (ftnlen)12);
	i__3 = lnof + 10;
	addstr_(ch__2, &i__3, soutq, lsout, lnof + 10, (ftnlen)80);
    }
    if (ic >= 6) {
	goto L2;
    }
    ++ic;
    nof += 4;
    nofa += 4;
    goto L1;
L2:
    if (dabs(*offnsk) > (float)1e-4) {
/* Writing concatenation */
	i__1[0] = 1, a__1[0] = sq;
	i__1[1] = 4, a__1[1] = "off{";
	s_cat(notexq, a__1, i__1, &c__2, (ftnlen)80);
	if (*offnsk < (float)-9.995) {
	    s_wsfi(&io___1048);
	    do_fio(&c__1, (char *)&(*offnsk), (ftnlen)sizeof(real));
	    e_wsfi();
	    lnote = 11;
	} else if (*offnsk < (float)-.995 || *offnsk > (float)9.995) {
	    s_wsfi(&io___1049);
	    do_fio(&c__1, (char *)&(*offnsk), (ftnlen)sizeof(real));
	    e_wsfi();
	    lnote = 10;
	} else if (*offnsk < (float)-1e-4 || *offnsk > (float).995) {
	    s_wsfi(&io___1050);
	    do_fio(&c__1, (char *)&(*offnsk), (ftnlen)sizeof(real));
	    e_wsfi();
	    lnote = 9;
	} else {
	    s_wsfi(&io___1051);
	    do_fio(&c__1, (char *)&(*offnsk), (ftnlen)sizeof(real));
	    e_wsfi();
	    lnote = 8;
	}
/* Writing concatenation */
	i__2[0] = lnote, a__2[0] = notexq;
	i__2[1] = 1, a__2[1] = sq;
	i__2[2] = 9, a__2[2] = "noteskip}";
	s_cat(notexq, a__2, i__2, &c__3, (ftnlen)80);
	i__3 = lnote + 10;
	addstr_(notexq, &i__3, soutq, lsout, (ftnlen)80, (ftnlen)80);
    }
    if (*ifig < comfig_2.nfigs) {
	++(*ifig);
    } else {
	comfig_2.nfigs = 0;
	*figcheck = FALSE_;
    }
    return 0;
} /* putfig_ */

/* Subroutine */ int writflot_(x, notexq, lenline, notexq_len)
real *x;
char *notexq;
integer *lenline;
ftnlen notexq_len;
{
    /* System generated locals */
    integer i__1;
    icilist ici__1;

    /* Builtin functions */
    integer s_wsfi(), do_fio(), e_wsfi();

    if (*x < (float).95) {
	i__1 = *lenline;
	ici__1.icierr = 0;
	ici__1.icirnum = 1;
	ici__1.icirlen = *lenline + 2 - i__1;
	ici__1.iciunit = notexq + i__1;
	ici__1.icifmt = "(f2.1)";
	s_wsfi(&ici__1);
	do_fio(&c__1, (char *)&(*x), (ftnlen)sizeof(real));
	e_wsfi();
	*lenline += 2;
    } else if (*x < (float)9.95) {
	i__1 = *lenline;
	ici__1.icierr = 0;
	ici__1.icirnum = 1;
	ici__1.icirlen = *lenline + 3 - i__1;
	ici__1.iciunit = notexq + i__1;
	ici__1.icifmt = "(f3.1)";
	s_wsfi(&ici__1);
	do_fio(&c__1, (char *)&(*x), (ftnlen)sizeof(real));
	e_wsfi();
	*lenline += 3;
    } else {
	i__1 = *lenline;
	ici__1.icierr = 0;
	ici__1.icirnum = 1;
	ici__1.icirlen = *lenline + 4 - i__1;
	ici__1.iciunit = notexq + i__1;
	ici__1.icifmt = "(f4.1)";
	s_wsfi(&ici__1);
	do_fio(&c__1, (char *)&(*x), (ftnlen)sizeof(real));
	e_wsfi();
	*lenline += 4;
    }
    return 0;
} /* writflot_ */

/* Subroutine */ int readmeter_(lineq, iccount, mtrnum, mtrden, lineq_len)
char *lineq;
integer *iccount, *mtrnum, *mtrden;
ftnlen lineq_len;
{
    /* System generated locals */
    address a__1[3];
    integer i__1, i__2[3];
    char ch__1[4], ch__2[1];
    icilist ici__1;

    /* Builtin functions */
    integer i_indx();
    /* Subroutine */ int s_cat();
    integer s_rsfi(), do_fio(), e_rsfi();

    /* Local variables */
    static integer ns;
    extern /* Character */ VOID chax_();
    static char durq[1];
    extern /* Subroutine */ int getchar_();

    i__1 = *iccount;
    if (i_indx(lineq + i__1, "/", *iccount + 3 - i__1, (ftnlen)1) == 0) {

/*  No slashes, so use old method */

	getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	if (*(unsigned char *)durq == '-') {

/*  Negative numerator is used only to printed; signals vertical slash */

	    getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	    *mtrnum = -(*(unsigned char *)durq - 48);
	} else if (*(unsigned char *)durq == 'o') {

/*  Numerator is EXACTLY 1 */

	    *mtrnum = 1;
	} else {
	    *mtrnum = *(unsigned char *)durq - 48;
	    if (*mtrnum == 1) {

/*  Numerator is >9 */

		getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
		*mtrnum = *(unsigned char *)durq - 38;
	    }
	}
	getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	if (*(unsigned char *)durq == 'o') {
	    *mtrden = 1;
	} else {
	    *mtrden = *(unsigned char *)durq - 48;
	    if (*mtrden == 1) {
		getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
		*mtrden = *(unsigned char *)durq - 38;
	    }
	}
    } else {

/*  Expect the form m[n1]/[n2]/[n3]/[n4] . Advance iccount by one from '/' or 'm' */

	++(*iccount);
	ns = i_indx(lineq + (*iccount - 1), "/", 128 - (*iccount - 1), (
		ftnlen)1);
	ici__1.icierr = 0;
	ici__1.iciend = 0;
	ici__1.icirnum = 1;
	ici__1.icirlen = *iccount + ns - 2 - (*iccount - 1);
	ici__1.iciunit = lineq + (*iccount - 1);
/* Writing concatenation */
	i__2[0] = 2, a__1[0] = "(i";
	i__1 = ns + 47;
	chax_(ch__2, (ftnlen)1, &i__1);
	i__2[1] = 1, a__1[1] = ch__2;
	i__2[2] = 1, a__1[2] = ")";
	ici__1.icifmt = (s_cat(ch__1, a__1, i__2, &c__3, (ftnlen)4), ch__1);
	s_rsfi(&ici__1);
	do_fio(&c__1, (char *)&(*mtrnum), (ftnlen)sizeof(integer));
	e_rsfi();

/*  Reset iccount to start of second integer */

	*iccount += ns;

/*  There must be either a slash or a blank at pos'n 2 or 3 */

	ns = i_indx(lineq + (*iccount - 1), "/", (ftnlen)3, (ftnlen)1);
	if (ns == 0) {
	    ns = i_indx(lineq + (*iccount - 1), " ", (ftnlen)3, (ftnlen)1);
	}
	ici__1.icierr = 0;
	ici__1.iciend = 0;
	ici__1.icirnum = 1;
	ici__1.icirlen = *iccount + ns - 2 - (*iccount - 1);
	ici__1.iciunit = lineq + (*iccount - 1);
/* Writing concatenation */
	i__2[0] = 2, a__1[0] = "(i";
	i__1 = ns + 47;
	chax_(ch__2, (ftnlen)1, &i__1);
	i__2[1] = 1, a__1[1] = ch__2;
	i__2[2] = 1, a__1[2] = ")";
	ici__1.icifmt = (s_cat(ch__1, a__1, i__2, &c__3, (ftnlen)4), ch__1);
	s_rsfi(&ici__1);
	do_fio(&c__1, (char *)&(*mtrden), (ftnlen)sizeof(integer));
	e_rsfi();

/*  Set iccount to last character used */

	*iccount = *iccount + ns - 1;
    }
    return 0;
} /* readmeter_ */

/* Subroutine */ int readnum_(lineq, iccount, durq, fnum, lineq_len, durq_len)
char *lineq;
integer *iccount;
char *durq;
real *fnum;
ftnlen lineq_len;
ftnlen durq_len;
{
    /* System generated locals */
    address a__1[3];
    integer i__1[3];
    char ch__1[27], ch__2[6], ch__3[1];
    icilist ici__1;

    /* Builtin functions */
    integer i_indx(), s_wsle();
    /* Subroutine */ int s_cat();
    integer do_lio(), e_wsle();
    /* Subroutine */ int s_stop();
    integer s_rsfi(), do_fio(), e_rsfi();

    /* Local variables */
    static integer i1, i2, icf;
    extern /* Character */ VOID chax_();
    extern /* Subroutine */ int getchar_();

    /* Fortran I/O blocks */
    static cilist io___1056 = { 0, 6, 0, 0, 0 };



/*  This reads a number starting at position iccount.  Remember that on exit, */
/*  getchar leaves iccount at the last character retrieved.  So must only */
/*  call this routine *after* detecting a number or decimal. */
/*  On exit, durq is next character after end of number. */

    i1 = *iccount;
L1:
    getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
    if (i_indx("0123456789.", durq, (ftnlen)11, (ftnlen)1) > 0) {
	goto L1;
    }
    i2 = *iccount - 1;
    if (i2 < i1) {
	s_wsle(&io___1056);
/* Writing concatenation */
	i__1[0] = 7, a__1[0] = "Found \"";
	i__1[1] = 1, a__1[1] = durq;
	i__1[2] = 19, a__1[2] = "\" instead of number";
	s_cat(ch__1, a__1, i__1, &c__3, (ftnlen)27);
	do_lio(&c__9, &c__1, ch__1, (ftnlen)27);
	e_wsle();
	s_stop("1", (ftnlen)1);
    } else if (*(unsigned char *)&lineq[i1 - 1] == '.' && *(unsigned char *)&
	    lineq[i2 - 1] == '.') {
	--i2;
	--(*iccount);
    }
    icf = i2 - i1 + 49;
    ici__1.icierr = 0;
    ici__1.iciend = 0;
    ici__1.icirnum = 1;
    ici__1.icirlen = i2 - (i1 - 1);
    ici__1.iciunit = lineq + (i1 - 1);
/* Writing concatenation */
    i__1[0] = 2, a__1[0] = "(f";
    chax_(ch__3, (ftnlen)1, &icf);
    i__1[1] = 1, a__1[1] = ch__3;
    i__1[2] = 3, a__1[2] = ".0)";
    ici__1.icifmt = (s_cat(ch__2, a__1, i__1, &c__3, (ftnlen)6), ch__2);
    s_rsfi(&ici__1);
    do_fio(&c__1, (char *)&(*fnum), (ftnlen)sizeof(real));
    e_rsfi();
    return 0;
} /* readnum_ */

/* Subroutine */ int dotrill_(iv, ip, iornq, noteq, lnoten, notexq, lnote, 
	noteq_len, notexq_len)
integer *iv, *ip, *iornq;
char *noteq;
integer *lnoten;
char *notexq;
integer *lnote;
ftnlen noteq_len;
ftnlen notexq_len;
{
    /* System generated locals */
    address a__1[2], a__2[3];
    integer i__1, i__2[2], i__3[3], i__4;
    char ch__1[1], ch__2[6];
    icilist ici__1;

    /* Builtin functions */
    integer s_wsle(), do_lio(), e_wsle();
    /* Subroutine */ int s_stop(), s_cat();
    integer s_wsfi(), do_fio(), e_wsfi();

    /* Local variables */
    static integer itr;
    extern /* Character */ VOID chax_();
    static integer nfmt;
    static logical tronly;

    /* Fortran I/O blocks */
    static cilist io___1059 = { 0, 6, 0, 0, 0 };


    i__1 = comtrill_1.ntrill;
    for (itr = 1; itr <= i__1; ++itr) {
	if (*iv == comtrill_1.ivtrill[itr - 1] && *ip == comtrill_1.iptrill[
		itr - 1]) {
	    goto L2;
	}
/* L1: */
    }
    s_wsle(&io___1059);
    do_lio(&c__9, &c__1, "Problem in dotrill.  Call Dr. Don", (ftnlen)33);
    e_wsle();
    s_stop("", (ftnlen)0);
L2:
    tronly = comtrill_1.xnsktr[itr - 1] < (float).01;
    if (tronly) {
/* Writing concatenation */
	chax_(ch__1, (ftnlen)1, &c__92);
	i__2[0] = 1, a__1[0] = ch__1;
	i__2[1] = 9, a__1[1] = "zcharnote";
	s_cat(notexq, a__1, i__2, &c__2, (ftnlen)79);
	*lnote = 10;
    } else if (bit_test(*iornq,7)) {
/* Writing concatenation */
	chax_(ch__1, (ftnlen)1, &c__92);
	i__2[0] = 1, a__1[0] = ch__1;
	i__2[1] = 6, a__1[1] = "Trille";
	s_cat(notexq, a__1, i__2, &c__2, (ftnlen)79);
	*lnote = 7;
    } else {
/* Writing concatenation */
	chax_(ch__1, (ftnlen)1, &c__92);
	i__2[0] = 1, a__1[0] = ch__1;
	i__2[1] = 6, a__1[1] = "trille";
	s_cat(notexq, a__1, i__2, &c__2, (ftnlen)79);
	*lnote = 7;
    }
/* Writing concatenation */
    i__3[0] = *lnote, a__2[0] = notexq;
    i__3[1] = *lnoten, a__2[1] = noteq;
    i__3[2] = 1, a__2[2] = "{";
    s_cat(notexq, a__2, i__3, &c__3, (ftnlen)79);
    *lnote = *lnote + *lnoten + 1;

/*  Write trill duration to nearest tenth of a noteskip */

    if (tronly) {
/* Writing concatenation */
	i__3[0] = *lnote, a__2[0] = notexq;
	chax_(ch__1, (ftnlen)1, &c__92);
	i__3[1] = 1, a__2[1] = ch__1;
	i__3[2] = 6, a__2[2] = "it tr}";
	s_cat(notexq, a__2, i__3, &c__3, (ftnlen)79);
	*lnote += 7;
	return 0;
    }
    if (comtrill_1.xnsktr[itr - 1] < (float).95) {
	nfmt = 2;
    } else if (comtrill_1.xnsktr[itr - 1] < (float)9.95) {
	nfmt = 3;
    } else {
	nfmt = 4;
    }
    i__1 = *lnote;
    ici__1.icierr = 0;
    ici__1.icirnum = 1;
    ici__1.icirlen = *lnote + nfmt - i__1;
    ici__1.iciunit = notexq + i__1;
/* Writing concatenation */
    i__3[0] = 2, a__2[0] = "(f";
    i__4 = nfmt + 48;
    chax_(ch__1, (ftnlen)1, &i__4);
    i__3[1] = 1, a__2[1] = ch__1;
    i__3[2] = 3, a__2[2] = ".1)";
    ici__1.icifmt = (s_cat(ch__2, a__2, i__3, &c__3, (ftnlen)6), ch__2);
    s_wsfi(&ici__1);
    do_fio(&c__1, (char *)&comtrill_1.xnsktr[itr - 1], (ftnlen)sizeof(real));
    e_wsfi();
    *lnote += nfmt;
/* Writing concatenation */
    i__2[0] = *lnote, a__1[0] = notexq;
    i__2[1] = 1, a__1[1] = "}";
    s_cat(notexq, a__1, i__2, &c__2, (ftnlen)79);
    ++(*lnote);
    return 0;
} /* dotrill_ */

/* Subroutine */ int docrd_(ivx, ip, nodu, ncm, iv, tnow, soutq, lsout, ulq, 
	ibmcnt, islur, nvmx, nv, beamon, nolevm, ihornb, nornb, stemlen, 
	soutq_len, ulq_len)
integer *ivx, *ip, *nodu, *ncm, *iv;
real *tnow;
char *soutq;
integer *lsout;
char *ulq;
integer *ibmcnt, *islur, *nvmx, *nv;
logical *beamon;
integer *nolevm, *ihornb, *nornb;
real *stemlen;
ftnlen soutq_len;
ftnlen ulq_len;
{
    /* System generated locals */
    address a__1[2];
    integer i__1, i__2, i__3[2], i__4, i__5;
    logical L__1;
    char ch__1[1];

    /* Builtin functions */
    integer lbit_shift(), pow_ii();
    /* Subroutine */ int s_cat(), s_copy();

    /* Local variables */
    static integer kv;
    extern integer log2_();
    static integer icrd;
    extern /* Character */ VOID chax_();
    static integer lout, lsym;
    static char outq[79];
    extern /* Subroutine */ int doacc_();
    extern integer ncmid_();
    static integer lnote, nolev;
    static char noteq[8];
    extern /* Subroutine */ int addstr_();
    static integer nactmp;
    static logical isleft;
    extern /* Subroutine */ int notefq_();
    static real updotc, rtdotc;
    static integer lnoten;
    extern /* Subroutine */ int dotmov_(), putarp_();
    static char notexq[79], nosymq[7];
    extern /* Subroutine */ int putorn_(), addmidi_();
    static logical isright;
    extern /* Subroutine */ int setbits_(), addblank_();
    extern integer igetbits_();


/*  This subr. once produced notexq for entire chord.  10/18/97 altered to write */
/*    chord notes as we go.  10/22/97 find range of icrd first. */
/*    2/25/98 moved rangefinding to precrd so done before slurs, so now */
/*    on entry, icrd1, icrd2 define range of icrd for this chord. */

/*  Set counter (for this note) for chord notes present.  Set notmain=T. */
/*    Will test for notmain=.true. in addmidi to tell whether to save pitch. */

    /* Parameter adjustments */
    --nornb;
    ihornb -= 16;
    ulq -= 16;

    /* Function Body */
    commidi_1.nmidcrd = 0;
    commidi_1.notmain = TRUE_;
    commidi_1.crdacc = FALSE_;
    i__1 = comtrill_1.icrd2;
    for (icrd = comtrill_1.icrd1; icrd <= i__1; ++icrd) {
	lnote = 0;
	nolev = lbit_shift(comtrill_1.icrdat[icrd - 1], (ftnlen)-12) & 127;

/*  Lower dot for lower-voice notes?.  Conditions are: */
/*   1. Dotted time value */
/*   2. Lower voice of two */
/*   3. Note is on a line */
/*   4. Not a rest (cannot be a rest in a chord!) */
/* .  5. Flag (lowdot) is set to true */

	if (comarp_1.lowdot && *nvmx == 2 && *ivx <= *nv) {
	    i__2 = log2_(nodu);
	    if (pow_ii(&c__2, &i__2) != *nodu && (nolev - *ncm) % 2 == 0) {
		if (bit_test(comtrill_1.icrdat[icrd - 1],26)) {

/*  Note already in movdot list.  Drop by 2. */

		    i__2 = igetbits_(&comtrill_1.icrdot[icrd - 1], &c__7, &
			    c__0) - 20;
		    setbits_(&comtrill_1.icrdot[icrd - 1], &c__7, &c__0, &
			    i__2);
		} else {

/*  Not in list so just move it right now */

		    i__2 = igetbits_(islur, &c__1, &c__3);
		    dotmov_(&c_b2065, &c_b1398, soutq, lsout, &i__2, (ftnlen)
			    80);
		}
	    }
	}
	if (bit_test(comtrill_1.icrdat[icrd - 1],26)) {

/*  Move the dot. */

	    updotc = ((127 & comtrill_1.icrdot[icrd - 1]) - 64) * (float).1;
	    rtdotc = ((127 & lbit_shift(comtrill_1.icrdot[icrd - 1], (ftnlen)
		    -7)) - 64) * (float).1;
	    i__2 = igetbits_(islur, &c__1, &c__3);
	    dotmov_(&updotc, &rtdotc, soutq, lsout, &i__2, (ftnlen)80);
	}
	isleft = bit_test(comtrill_1.icrdat[icrd - 1],23);
	isright = bit_test(comtrill_1.icrdat[icrd - 1],24);

/*  Check for ornament in chord. */

	if (comtrill_1.icrdorn[icrd - 1] > 0) {
	    putorn_(&comtrill_1.icrdorn[icrd - 1], &nolev, nolevm, nodu, &
		    nornb[1], ulq + 16, ibmcnt, ivx, ncm, islur, nvmx, nv, &
		    ihornb[16], stemlen, outq, &lout, ip, &c__0, beamon, &
		    c_true, (ftnlen)1, (ftnlen)79);

/*     subroutin putorn(iornq,nolev,nolevm,nodur,nornb,ulq,ibmcnt,ivx, */
/*    *     ncm,islur,nvmx,nv,ihornb,stemlen,outq,lout,ip,islhgt, */
/*    *     notcrd,beamon,iscrd) */

	    addstr_(outq, &lout, soutq, lsout, (ftnlen)79, (ftnlen)80);
	}

/*  Chord-note symbol.  First check for breve */

	if (*nodu == 128) {
/* Writing concatenation */
	    chax_(ch__1, (ftnlen)1, &c__92);
	    i__3[0] = 1, a__1[0] = ch__1;
	    i__3[1] = 6, a__1[1] = "zbreve";
	    s_cat(nosymq, a__1, i__3, &c__2, (ftnlen)7);
	    lsym = 7;
	} else {

/*  Not a breve chord.  Get first letters in chord-note symbol */

	    if (isleft) {
/* Writing concatenation */
		chax_(ch__1, (ftnlen)1, &c__92);
		i__3[0] = 1, a__1[0] = ch__1;
		i__3[1] = 1, a__1[1] = "l";
		s_cat(nosymq, a__1, i__3, &c__2, (ftnlen)7);
	    } else if (isright) {
/* Writing concatenation */
		chax_(ch__1, (ftnlen)1, &c__92);
		i__3[0] = 1, a__1[0] = ch__1;
		i__3[1] = 1, a__1[1] = "r";
		s_cat(nosymq, a__1, i__3, &c__2, (ftnlen)7);
	    } else {
/* Writing concatenation */
		chax_(ch__1, (ftnlen)1, &c__92);
		i__3[0] = 1, a__1[0] = ch__1;
		i__3[1] = 1, a__1[1] = "z";
		s_cat(nosymq, a__1, i__3, &c__2, (ftnlen)7);
	    }
	    if (*nodu >= 64) {
/* Writing concatenation */
		i__3[0] = 2, a__1[0] = nosymq;
		i__3[1] = 1, a__1[1] = "w";
		s_cat(nosymq, a__1, i__3, &c__2, (ftnlen)7);
	    } else if (*nodu >= 32) {
/* Writing concatenation */
		i__3[0] = 2, a__1[0] = nosymq;
		i__3[1] = 1, a__1[1] = "h";
		s_cat(nosymq, a__1, i__3, &c__2, (ftnlen)7);
	    } else {
/* Writing concatenation */
		i__3[0] = 2, a__1[0] = nosymq;
		i__3[1] = 1, a__1[1] = "q";
		s_cat(nosymq, a__1, i__3, &c__2, (ftnlen)7);
	    }
	    i__2 = log2_(nodu);
	    if (pow_ii(&c__2, &i__2) == *nodu) {
		lsym = 3;
	    } else if (! bit_test(*islur,3)) {

/*  Single dot */

/* Writing concatenation */
		i__3[0] = 3, a__1[0] = nosymq;
		i__3[1] = 1, a__1[1] = "p";
		s_cat(nosymq, a__1, i__3, &c__2, (ftnlen)7);
		lsym = 4;
	    } else {

/*  Double dot */

/* Writing concatenation */
		i__3[0] = 3, a__1[0] = nosymq;
		i__3[1] = 2, a__1[1] = "pp";
		s_cat(nosymq, a__1, i__3, &c__2, (ftnlen)7);
		lsym = 5;
	    }
	}
	if (bit_test(comtrill_1.icrdat[icrd - 1],19)) {

/*  Accidental.  Build up bits 0-3 of nacc */

	    nactmp = igetbits_(&comtrill_1.icrdat[icrd - 1], &c__3, &c__20);

/*  Kluge for bigness.  Only means 'As' has not been issued */

	    if (spfacs_1.bacfac != (float)1e6) {
		nactmp += 8;
	    }
	    i__2 = igetbits_(&comtrill_1.icrdot[icrd - 1], &c__7, &c__20) - 
		    64;
	    i__4 = igetbits_(&comtrill_1.icrdot[icrd - 1], &c__6, &c__14);
	    L__1 = bit_test(comtrill_1.icrdat[icrd - 1],23);
	    i__5 = ncmid_(iv, ip);
	    doacc_(&i__2, &i__4, &L__1, notexq, &lnote, &nactmp, &nolev, &
		    i__5, (ftnlen)79);
/* Writing concatenation */
	    i__3[0] = lnote, a__1[0] = notexq;
	    i__3[1] = 7, a__1[1] = nosymq;
	    s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	    commidi_1.crdacc = TRUE_;
	} else {
	    s_copy(notexq, nosymq, (ftnlen)79, (ftnlen)7);
	}
	lnote += lsym;

/*  Get note name (again if accid, due to possible octave jump) */

	notefq_(noteq, &lnoten, &nolev, ncm, (ftnlen)8);
	if (lnoten == 1) {
	    addblank_(noteq, &lnoten, (ftnlen)8);
	}

/*  Put in note name */

/* Writing concatenation */
	i__3[0] = lnote, a__1[0] = notexq;
	i__3[1] = 8, a__1[1] = noteq;
	s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	lnote += lnoten;
	if (bit_test(comtrill_1.icrdat[icrd - 1],25)) {

/*  Arpeggio signal */

	    putarp_(tnow, iv, &nolev, ncm, soutq, lsout, (ftnlen)80);
	}
	addstr_(notexq, &lnote, soutq, lsout, (ftnlen)79, (ftnlen)80);
	if (commidi_1.ismidi) {

/*  Here is where we collect MIDI pitch info for the chord note.  By checking */
/*    notmain, addmidi(...) knows to just compute the */
/*    pitch number and store it in mcpitch(nmidcrd).  Then on call to addmidi() */
/*    for MAIN note, will put in note codes for all chord notes + main note. */

	    kv = 1;
	    if (*ivx > *iv) {
		kv = 2;
	    }
	    ++commidi_1.nmidcrd;
	    i__2 = igetbits_(&comtrill_1.icrdat[icrd - 1], &c__3, &c__20);
	    addmidi_(&commidi_1.midchan[*iv + kv * 15 - 16], &nolev, &i__2, &
		    comtop_1.isig, &c_b1232, &c_false, &c_false);
	}
/* L5: */
    }
    commidi_1.notmain = FALSE_;
    return 0;
} /* docrd_ */

/* Subroutine */ int dograce_(ivx, ip, ptgr, soutq, lsout, ncm, nacc, ig, ipl,
	 farend, soutq_len)
integer *ivx, *ip;
real *ptgr;
char *soutq;
integer *lsout, *ncm, *nacc, *ig, *ipl;
logical *farend;
ftnlen soutq_len;
{
    /* System generated locals */
    address a__1[2], a__2[3], a__3[4];
    integer i__1, i__2[2], i__3[3], i__4, i__5[4], i__6;
    real r__1;
    char ch__1[1], ch__2[6], ch__3[2], ch__4[5], ch__5[11], ch__6[7], ch__7[9]
	    , ch__8[12], ch__9[15], ch__10[16], ch__11[26], ch__12[29], 
	    ch__13[87], ch__14[4], ch__15[13], ch__16[82], ch__17[3];
    icilist ici__1;

    /* Builtin functions */
    integer s_wsle(), do_lio(), e_wsle();
    /* Subroutine */ int s_stop();
    integer s_wsfe(), do_fio(), e_wsfe();
    /* Subroutine */ int s_cat();
    integer i_nint(), s_wsfi(), e_wsfi(), i_sign();

    /* Local variables */
    static integer i__;
    static real x, y, em;
    static integer mg;
    static char sq[1];
    static integer ing, ngs;
    extern integer log2_();
    static integer lacc;
    static real beta;
    extern /* Character */ VOID chax_();
    static real sumx, sumy, delta, ptoff;
    static integer lnote;
    static char noteq[8];
    static real sumxx, sumxy, sumyy;
    static integer nolev1;
    static logical isgaft;
    extern /* Subroutine */ int accsym_(), addstr_();
    static integer islope;
    static logical iswaft;
    static char acsymq[3];
    extern /* Subroutine */ int notefq_();
    static integer lnoten, niptgr;
    static logical normsp;
    static char notexq[79];
    extern /* Subroutine */ int addblank_();
    extern integer igetbits_();

    /* Fortran I/O blocks */
    static cilist io___1082 = { 0, 6, 0, 0, 0 };
    static cilist io___1085 = { 0, 6, 0, 0, 0 };
    static cilist io___1086 = { 0, 6, 0, 0, 0 };
    static cilist io___1087 = { 0, 15, 0, "(/,a)", 0 };
    static icilist io___1090 = { 0, notexq, 0, "(i2)", 2, 1 };
    static cilist io___1091 = { 0, 6, 0, 0, 0 };
    static icilist io___1111 = { 0, notexq+18, 0, "(a1,f4.1)", 5, 1 };
    static icilist io___1112 = { 0, notexq+18, 0, "(f4.1)", 4, 1 };
    static icilist io___1114 = { 0, notexq+5, 0, "(f3.1)", 3, 1 };



/*  ip will be one LESS than current note, for way-after's before bar-end, */
/*    It is only used to find ig. */
/*  ig is returned to makeabar in case there's a slur that needs to be ended */

    /* Parameter adjustments */
    --ptgr;

    /* Function Body */
    chax_(ch__1, (ftnlen)1, &c__92);
    *(unsigned char *)sq = *(unsigned char *)&ch__1[0];
    isgaft = bit_test(*ipl,29);
    iswaft = bit_test(*ipl,31);
    normsp = ! isgaft;

/*  Find ig. */

    i__1 = comgrace_1.ngrace;
    for (*ig = 1; *ig <= i__1; ++(*ig)) {
	if (comgrace_1.ipg[*ig - 1] == *ip && comgrace_1.ivg[*ig - 1] == *ivx)
		 {
	    goto L121;
	}
/* L120: */
    }
    s_wsle(&io___1082);
    do_lio(&c__9, &c__1, "Problem finding grace index in dograce", (ftnlen)38)
	    ;
    e_wsle();
    s_stop("", (ftnlen)0);
L121:
    ngs = comgrace_1.ngstrt[*ig - 1];
    mg = comgrace_1.multg[*ig - 1];

/*  For way-after-graces at end of bar, must set the octave. */

    if (*farend) {
	comoct_1.noctup = 0;
	if (*ncm == 23) {
	    comoct_1.noctup = -2;
	}
    }
    if (comgrace_1.slurg[*ig - 1] && ! iswaft && ! isgaft) {
	if (comslur_1.listslur == 4095) {
	    s_wsle(&io___1085);
	    e_wsle();
	    s_wsle(&io___1086);
	    do_lio(&c__9, &c__1, "You defined the thirteenth slur, one too m\
any!", (ftnlen)46);
	    e_wsle();
	    s_wsfe(&io___1087);
	    do_fio(&c__1, "You defined the thirteenth slur, one too many!", (
		    ftnlen)46);
	    e_wsfe();
	    s_stop("1", (ftnlen)1);
	}

/*  Slur on fore-grace.  Get index of next slur not in use, from 11 down. */

	i__1 = 4095 - comslur_1.listslur;
	comslur_1.ndxslur = log2_(&i__1);
    }
    if (comgrace_1.nng[*ig - 1] == 1) {

/*  Single grace. */

	if (normsp) {

/*  Anything but GA */

/* Writing concatenation */
	    i__2[0] = 1, a__1[0] = sq;
	    i__2[1] = 5, a__1[1] = "shlft";
	    s_cat(ch__2, a__1, i__2, &c__2, (ftnlen)6);
	    addstr_(ch__2, &c__6, soutq, lsout, (ftnlen)6, (ftnlen)80);
	    niptgr = i_nint(&ptgr[*ig]);
	    if (niptgr < 10) {
/* Writing concatenation */
		i__1 = niptgr + 48;
		chax_(ch__1, (ftnlen)1, &i__1);
		i__2[0] = 1, a__1[0] = ch__1;
		i__2[1] = 1, a__1[1] = "{";
		s_cat(ch__3, a__1, i__2, &c__2, (ftnlen)2);
		addstr_(ch__3, &c__2, soutq, lsout, (ftnlen)2, (ftnlen)80);
	    } else if (niptgr < 100) {
		s_wsfi(&io___1090);
		do_fio(&c__1, (char *)&niptgr, (ftnlen)sizeof(integer));
		e_wsfi();
/* Writing concatenation */
		i__3[0] = 1, a__2[0] = "{";
		i__3[1] = 2, a__2[1] = notexq;
		i__3[2] = 2, a__2[2] = "}{";
		s_cat(ch__4, a__2, i__3, &c__3, (ftnlen)5);
		addstr_(ch__4, &c__5, soutq, lsout, (ftnlen)5, (ftnlen)80);
	    } else {
		s_wsle(&io___1091);
		do_lio(&c__9, &c__1, "Call Dr. Don if you really want grace \
note group > 99 pt", (ftnlen)56);
		e_wsle();
		s_stop("", (ftnlen)0);
	    }
	} else {
/* Writing concatenation */
	    i__2[0] = 1, a__1[0] = sq;
	    i__2[1] = 10, a__1[1] = "gaft{1.5}{";
	    s_cat(ch__5, a__1, i__2, &c__2, (ftnlen)11);
	    addstr_(ch__5, &c__11, soutq, lsout, (ftnlen)11, (ftnlen)80);

/*  GA.  Compute aftshft, for later use. */

	    comgrace_1.aftshft = spfacs_1.grafac;
	    if (comgrace_1.naccg[comgrace_1.ngstrt[*ig - 1] - 1] > 0) {
		comgrace_1.aftshft += spfacs_1.agc1fac;
	    }
	    comgrace_1.aftshft *= comask_1.wheadpt;
	}
	if (comgrace_1.slurg[*ig - 1] && ! isgaft && ! iswaft) {

/*  Start slur on pre-grace.  No accounting needed since will be ended very soon. */

	    notefq_(noteq, &lnoten, &comgrace_1.nolevg[ngs - 1], ncm, (ftnlen)
		    8);
	    if (comgrace_1.upg[*ig - 1]) {
/* Writing concatenation */
		i__2[0] = 1, a__1[0] = sq;
		i__2[1] = 6, a__1[1] = "islurd";
		s_cat(ch__6, a__1, i__2, &c__2, (ftnlen)7);
		addstr_(ch__6, &c__7, soutq, lsout, (ftnlen)7, (ftnlen)80);
	    } else {
/* Writing concatenation */
		i__2[0] = 1, a__1[0] = sq;
		i__2[1] = 6, a__1[1] = "isluru";
		s_cat(ch__6, a__1, i__2, &c__2, (ftnlen)7);
		addstr_(ch__6, &c__7, soutq, lsout, (ftnlen)7, (ftnlen)80);
	    }
	    if (comslur_1.ndxslur < 10) {
/* Writing concatenation */
		i__1 = comslur_1.ndxslur + 48;
		chax_(ch__1, (ftnlen)1, &i__1);
		i__2[0] = 1, a__1[0] = ch__1;
		i__2[1] = lnoten, a__1[1] = noteq;
		s_cat(ch__7, a__1, i__2, &c__2, (ftnlen)9);
		i__4 = lnoten + 1;
		addstr_(ch__7, &i__4, soutq, lsout, lnoten + 1, (ftnlen)80);
	    } else {
/* Writing concatenation */
		i__5[0] = 2, a__3[0] = "{1";
		i__1 = comslur_1.ndxslur + 38;
		chax_(ch__1, (ftnlen)1, &i__1);
		i__5[1] = 1, a__3[1] = ch__1;
		i__5[2] = 1, a__3[2] = "}";
		i__5[3] = lnoten, a__3[3] = noteq;
		s_cat(ch__8, a__3, i__5, &c__4, (ftnlen)12);
		i__4 = lnoten + 4;
		addstr_(ch__8, &i__4, soutq, lsout, lnoten + 4, (ftnlen)80);
	    }
	}
	if (comgrace_1.naccg[ngs - 1] > 0) {
	    notefq_(noteq, &lnoten, &comgrace_1.nolevg[ngs - 1], ncm, (ftnlen)
		    8);
	    if (lnoten == 1) {
		addblank_(noteq, &lnoten, (ftnlen)8);
	    }
	    accsym_(&comgrace_1.naccg[ngs - 1], acsymq, &lacc, (ftnlen)3);
/* Writing concatenation */
	    i__5[0] = 1, a__3[0] = sq;
	    i__5[1] = 3, a__3[1] = "big";
	    i__5[2] = lacc, a__3[2] = acsymq;
	    i__5[3] = lnoten, a__3[3] = noteq;
	    s_cat(ch__9, a__3, i__5, &c__4, (ftnlen)15);
	    i__1 = lacc + 4 + lnoten;
	    addstr_(ch__9, &i__1, soutq, lsout, lacc + 4 + lnoten, (ftnlen)80)
		    ;
	}
	if (comgrace_1.slashg[*ig - 1]) {
/* Writing concatenation */
	    i__2[0] = 1, a__1[0] = sq;
	    i__2[1] = 3, a__1[1] = "grc";
	    s_cat(notexq, a__1, i__2, &c__2, (ftnlen)79);
	    lnote = 4;
	} else if (mg == 0) {
/* Writing concatenation */
	    i__2[0] = 1, a__1[0] = sq;
	    i__2[1] = 2, a__1[1] = "zq";
	    s_cat(notexq, a__1, i__2, &c__2, (ftnlen)79);
	    lnote = 3;
	} else {
/* Writing concatenation */
	    i__2[0] = 1, a__1[0] = sq;
	    i__2[1] = 2, a__1[1] = "zc";
	    s_cat(notexq, a__1, i__2, &c__2, (ftnlen)79);
	    i__1 = mg;
	    for (i__ = 2; i__ <= i__1; ++i__) {
/* Writing concatenation */
		i__2[0] = i__ + 1, a__1[0] = notexq;
		i__2[1] = 1, a__1[1] = "c";
		s_cat(notexq, a__1, i__2, &c__2, (ftnlen)79);
/* L61: */
	    }
	    lnote = mg + 2;
	}
	if (comgrace_1.upg[*ig - 1]) {
/* Writing concatenation */
	    i__2[0] = lnote, a__1[0] = notexq;
	    i__2[1] = 1, a__1[1] = "u";
	    s_cat(notexq, a__1, i__2, &c__2, (ftnlen)79);
	} else {
/* Writing concatenation */
	    i__2[0] = lnote, a__1[0] = notexq;
	    i__2[1] = 1, a__1[1] = "l";
	    s_cat(notexq, a__1, i__2, &c__2, (ftnlen)79);
	}
	i__1 = lnote + 1;
	addstr_(notexq, &i__1, soutq, lsout, (ftnlen)79, (ftnlen)80);
	notefq_(noteq, &lnoten, &comgrace_1.nolevg[ngs - 1], ncm, (ftnlen)8);
	if (lnoten == 1) {
	    addblank_(noteq, &lnoten, (ftnlen)8);
	}
	addstr_(noteq, &lnoten, soutq, lsout, (ftnlen)8, (ftnlen)80);
	if (comgrace_1.slashg[*ig - 1]) {
/* Writing concatenation */
	    i__5[0] = 1, a__3[0] = sq;
	    i__5[1] = 5, a__3[1] = "off{-";
	    i__5[2] = 1, a__3[2] = sq;
	    i__5[3] = 9, a__3[3] = "noteskip}";
	    s_cat(ch__10, a__3, i__5, &c__4, (ftnlen)16);
	    addstr_(ch__10, &c__16, soutq, lsout, (ftnlen)16, (ftnlen)80);
	}

/*  Above code needed since slashg causes spacing */

	if (comgrace_1.slurg[*ig - 1] && (iswaft || isgaft)) {

/*  Terminate slur on single after-grace */

	    comslur_1.ndxslur = igetbits_(ipl, &c__4, &c__23);
	    notefq_(noteq, &lnoten, &comgrace_1.nolevg[ngs - 1], ncm, (ftnlen)
		    8);
/* Writing concatenation */
	    i__2[0] = 1, a__1[0] = sq;
	    i__2[1] = 5, a__1[1] = "tslur";
	    s_cat(ch__2, a__1, i__2, &c__2, (ftnlen)6);
	    addstr_(ch__2, &c__6, soutq, lsout, (ftnlen)6, (ftnlen)80);
	    if (comslur_1.ndxslur < 10) {
/* Writing concatenation */
		i__1 = comslur_1.ndxslur + 48;
		chax_(ch__1, (ftnlen)1, &i__1);
		i__2[0] = 1, a__1[0] = ch__1;
		i__2[1] = lnoten, a__1[1] = noteq;
		s_cat(ch__7, a__1, i__2, &c__2, (ftnlen)9);
		i__4 = lnoten + 1;
		addstr_(ch__7, &i__4, soutq, lsout, lnoten + 1, (ftnlen)80);
	    } else {
/* Writing concatenation */
		i__5[0] = 2, a__3[0] = "{1";
		i__1 = comslur_1.ndxslur + 38;
		chax_(ch__1, (ftnlen)1, &i__1);
		i__5[1] = 1, a__3[1] = ch__1;
		i__5[2] = 1, a__3[2] = "}";
		i__5[3] = lnoten, a__3[3] = noteq;
		s_cat(ch__8, a__3, i__5, &c__4, (ftnlen)12);
		i__4 = lnoten + 4;
		addstr_(ch__8, &i__4, soutq, lsout, lnoten + 4, (ftnlen)80);
	    }
	    comgrace_1.slurg[*ig - 1] = FALSE_;
	    comslur_1.listslur = bit_clear(comslur_1.listslur,
		    comslur_1.ndxslur);
	}
	addstr_("}", &c__1, soutq, lsout, (ftnlen)1, (ftnlen)80);
    } else {

/*  Multiple grace.  Put in literally.  Compute beam stuff */

	sumx = (float)0.;
	sumy = (float)0.;
	sumxy = (float)0.;
	sumxx = (float)0.;
	sumyy = (float)0.;
	x = (float)0.;
	i__1 = ngs + comgrace_1.nng[*ig - 1] - 1;
	for (ing = ngs; ing <= i__1; ++ing) {
	    if (ing > ngs && comgrace_1.naccg[ing - 1] > 0) {
		x += spfacs_1.acgfac;
	    }
	    y = (real) comgrace_1.nolevg[ing - 1];
	    sumx += x;
	    sumy += y;
	    sumxy += x * y;
	    sumxx += x * x;
	    sumyy += y * y;
	    x += spfacs_1.emgfac;
/* L118: */
	}
	delta = comgrace_1.nng[*ig - 1] * sumxx - sumx * sumx;
	em = (comgrace_1.nng[*ig - 1] * sumxy - sumx * sumy) / delta;
	r__1 = em * (float).5 * spfacs_1.gslfac;
	islope = i_nint(&r__1);
	if (abs(islope) > 9) {
	    islope = i_sign(&c__9, &islope);
	}
	beta = (sumy - islope / spfacs_1.gslfac * sumx) / comgrace_1.nng[*ig 
		- 1];
	nolev1 = i_nint(&beta);

/*  Back up */

/* Writing concatenation */
	i__5[0] = 1, a__3[0] = sq;
	i__5[1] = 12, a__3[1] = "tinynotesize";
	i__5[2] = 1, a__3[2] = sq;
	i__5[3] = 4, a__3[3] = "off{";
	s_cat(notexq, a__3, i__5, &c__4, (ftnlen)79);
	if (normsp) {
	    s_wsfi(&io___1111);
	    do_fio(&c__1, "-", (ftnlen)1);
	    do_fio(&c__1, (char *)&ptgr[*ig], (ftnlen)sizeof(real));
	    e_wsfi();
/* Writing concatenation */
	    i__2[0] = 23, a__1[0] = notexq;
	    i__2[1] = 3, a__1[1] = "pt}";
	    s_cat(ch__11, a__1, i__2, &c__2, (ftnlen)26);
	    addstr_(ch__11, &c__26, soutq, lsout, (ftnlen)26, (ftnlen)80);
	} else {
	    comgrace_1.aftshft = comask_1.wheadpt * (float)1.33;
	    if (comgrace_1.naccg[comgrace_1.ngstrt[*ig - 1] - 1] > 0) {
		comgrace_1.aftshft += comask_1.wheadpt * (float).5;
	    }
	    s_wsfi(&io___1112);
	    do_fio(&c__1, (char *)&comgrace_1.aftshft, (ftnlen)sizeof(real));
	    e_wsfi();
/* Writing concatenation */
	    i__5[0] = 22, a__3[0] = notexq;
	    i__5[1] = 3, a__3[1] = "pt}";
	    i__5[2] = 1, a__3[2] = sq;
	    i__5[3] = 3, a__3[3] = "bsk";
	    s_cat(ch__12, a__3, i__5, &c__4, (ftnlen)29);
	    addstr_(ch__12, &c__29, soutq, lsout, (ftnlen)29, (ftnlen)80);
	}

/*  Start the beam */

/* Writing concatenation */
	i__2[0] = 1, a__1[0] = sq;
	i__2[1] = 2, a__1[1] = "ib";
	s_cat(notexq, a__1, i__2, &c__2, (ftnlen)79);
	i__1 = mg;
	for (ing = 2; ing <= i__1; ++ing) {
/* Writing concatenation */
	    i__2[0] = ing + 1, a__1[0] = notexq;
	    i__2[1] = 1, a__1[1] = "b";
	    s_cat(notexq, a__1, i__2, &c__2, (ftnlen)79);
/* L119: */
	}
	if (comgrace_1.upg[*ig - 1]) {
/* Writing concatenation */
	    i__2[0] = mg + 2, a__1[0] = notexq;
	    i__2[1] = 1, a__1[1] = "u";
	    s_cat(notexq, a__1, i__2, &c__2, (ftnlen)79);
	} else {
/* Writing concatenation */
	    i__2[0] = mg + 2, a__1[0] = notexq;
	    i__2[1] = 1, a__1[1] = "l";
	    s_cat(notexq, a__1, i__2, &c__2, (ftnlen)79);
	}
/* Writing concatenation */
	i__2[0] = mg + 3, a__1[0] = notexq;
	i__2[1] = 1, a__1[1] = "0";
	s_cat(notexq, a__1, i__2, &c__2, (ftnlen)79);

/*  Get starting note for beam */

	notefq_(noteq, &lnoten, &nolev1, ncm, (ftnlen)8);
/* Writing concatenation */
	i__2[0] = mg + 4, a__1[0] = notexq;
	i__2[1] = lnoten, a__1[1] = noteq;
	s_cat(ch__13, a__1, i__2, &c__2, (ftnlen)87);
	i__1 = mg + 4 + lnoten;
	addstr_(ch__13, &i__1, soutq, lsout, mg + 4 + lnoten, (ftnlen)80);

/*  Put in the slope */

	if (islope >= 0) {
	    i__1 = islope + 48;
	    chax_(ch__1, (ftnlen)1, &i__1);
	    addstr_(ch__1, &c__1, soutq, lsout, (ftnlen)1, (ftnlen)80);
	} else {
/* Writing concatenation */
	    i__3[0] = 2, a__2[0] = "{-";
	    i__1 = 48 - islope;
	    chax_(ch__1, (ftnlen)1, &i__1);
	    i__3[1] = 1, a__2[1] = ch__1;
	    i__3[2] = 1, a__2[2] = "}";
	    s_cat(ch__14, a__2, i__3, &c__3, (ftnlen)4);
	    addstr_(ch__14, &c__4, soutq, lsout, (ftnlen)4, (ftnlen)80);
	}

/*  Start a slur on fore-grace */

	if (comgrace_1.slurg[*ig - 1] && ! isgaft && ! iswaft) {
	    notefq_(noteq, &lnoten, &comgrace_1.nolevg[ngs - 1], ncm, (ftnlen)
		    8);
	    if (comgrace_1.upg[*ig - 1]) {
/* Writing concatenation */
		i__2[0] = 1, a__1[0] = sq;
		i__2[1] = 6, a__1[1] = "islurd";
		s_cat(ch__6, a__1, i__2, &c__2, (ftnlen)7);
		addstr_(ch__6, &c__7, soutq, lsout, (ftnlen)7, (ftnlen)80);
	    } else {
/* Writing concatenation */
		i__2[0] = 1, a__1[0] = sq;
		i__2[1] = 6, a__1[1] = "isluru";
		s_cat(ch__6, a__1, i__2, &c__2, (ftnlen)7);
		addstr_(ch__6, &c__7, soutq, lsout, (ftnlen)7, (ftnlen)80);
	    }
	    if (comslur_1.ndxslur < 10) {
/* Writing concatenation */
		i__1 = comslur_1.ndxslur + 48;
		chax_(ch__1, (ftnlen)1, &i__1);
		i__2[0] = 1, a__1[0] = ch__1;
		i__2[1] = lnoten, a__1[1] = noteq;
		s_cat(ch__7, a__1, i__2, &c__2, (ftnlen)9);
		i__4 = lnoten + 1;
		addstr_(ch__7, &i__4, soutq, lsout, lnoten + 1, (ftnlen)80);
	    } else {
/* Writing concatenation */
		i__5[0] = 2, a__3[0] = "{1";
		i__1 = comslur_1.ndxslur + 38;
		chax_(ch__1, (ftnlen)1, &i__1);
		i__5[1] = 1, a__3[1] = ch__1;
		i__5[2] = 1, a__3[2] = "}";
		i__5[3] = lnoten, a__3[3] = noteq;
		s_cat(ch__8, a__3, i__5, &c__4, (ftnlen)12);
		i__4 = lnoten + 4;
		addstr_(ch__8, &i__4, soutq, lsout, lnoten + 4, (ftnlen)80);
	    }
	}

/*  Put in first note.  Call notefq again in case octave changed */

	notefq_(noteq, &lnoten, &comgrace_1.nolevg[ngs - 1], ncm, (ftnlen)8);
	if (comgrace_1.naccg[ngs - 1] == 0) {
/* Writing concatenation */
	    i__3[0] = 1, a__2[0] = sq;
	    i__3[1] = 4, a__2[1] = "zqb0";
	    i__3[2] = lnoten, a__2[2] = noteq;
	    s_cat(notexq, a__2, i__3, &c__3, (ftnlen)79);
	    lnote = lnoten + 5;
	} else {
	    if (lnoten == 1) {
		addblank_(noteq, &lnoten, (ftnlen)8);
	    }
	    accsym_(&comgrace_1.naccg[ngs - 1], acsymq, &lacc, (ftnlen)3);
/* Writing concatenation */
	    i__5[0] = 1, a__3[0] = sq;
	    i__5[1] = 3, a__3[1] = "big";
	    i__5[2] = lacc, a__3[2] = acsymq;
	    i__5[3] = lnoten, a__3[3] = noteq;
	    s_cat(notexq, a__3, i__5, &c__4, (ftnlen)79);
	    lnote = lacc + 4 + lnoten;
	    notefq_(noteq, &lnoten, &comgrace_1.nolevg[ngs - 1], ncm, (ftnlen)
		    8);
/* Writing concatenation */
	    i__5[0] = lnote, a__3[0] = notexq;
	    i__5[1] = 1, a__3[1] = sq;
	    i__5[2] = 4, a__3[2] = "zqb0";
	    i__5[3] = lnoten, a__3[3] = noteq;
	    s_cat(notexq, a__3, i__5, &c__4, (ftnlen)79);
	    lnote = lnote + 5 + lnoten;
	}
	addstr_(notexq, &lnote, soutq, lsout, (ftnlen)79, (ftnlen)80);
	i__1 = ngs + comgrace_1.nng[*ig - 1] - 1;
	for (ing = ngs + 1; ing <= i__1; ++ing) {

/*  Skip */

	    ptoff = comask_1.wheadpt * spfacs_1.emgfac;
	    if (comgrace_1.naccg[ing - 1] > 0) {
		ptoff += comask_1.wheadpt * spfacs_1.acgfac;
	    }
	    if (isgaft && ! iswaft) {
		comgrace_1.aftshft += ptoff;
	    }
/* Writing concatenation */
	    i__2[0] = 1, a__1[0] = sq;
	    i__2[1] = 4, a__1[1] = "off{";
	    s_cat(notexq, a__1, i__2, &c__2, (ftnlen)79);
	    s_wsfi(&io___1114);
	    do_fio(&c__1, (char *)&ptoff, (ftnlen)sizeof(real));
	    e_wsfi();
/* Writing concatenation */
	    i__2[0] = 8, a__1[0] = notexq;
	    i__2[1] = 3, a__1[1] = "pt}";
	    s_cat(ch__5, a__1, i__2, &c__2, (ftnlen)11);
	    addstr_(ch__5, &c__11, soutq, lsout, (ftnlen)11, (ftnlen)80);
	    if (ing == ngs + comgrace_1.nng[*ig - 1] - 1) {

/*  Terminate beam if needed */

		if (comgrace_1.upg[*ig - 1]) {
/* Writing concatenation */
		    i__2[0] = 1, a__1[0] = sq;
		    i__2[1] = 4, a__1[1] = "tbu0";
		    s_cat(ch__4, a__1, i__2, &c__2, (ftnlen)5);
		    addstr_(ch__4, &c__5, soutq, lsout, (ftnlen)5, (ftnlen)80)
			    ;
		} else {
/* Writing concatenation */
		    i__2[0] = 1, a__1[0] = sq;
		    i__2[1] = 4, a__1[1] = "tbl0";
		    s_cat(ch__4, a__1, i__2, &c__2, (ftnlen)5);
		    addstr_(ch__4, &c__5, soutq, lsout, (ftnlen)5, (ftnlen)80)
			    ;
		}

/*  Terminate after slur if needed */

		if ((isgaft || iswaft) && comgrace_1.slurg[*ig - 1]) {
		    if (iswaft) {
			comslur_1.ndxslur = igetbits_(ipl, &c__4, &c__23);
		    }
		    notefq_(noteq, &lnoten, &comgrace_1.nolevg[ing - 1], ncm, 
			    (ftnlen)8);
/* Writing concatenation */
		    i__2[0] = 1, a__1[0] = sq;
		    i__2[1] = 5, a__1[1] = "tslur";
		    s_cat(ch__2, a__1, i__2, &c__2, (ftnlen)6);
		    addstr_(ch__2, &c__6, soutq, lsout, (ftnlen)6, (ftnlen)80)
			    ;
		    if (comslur_1.ndxslur < 10) {
/* Writing concatenation */
			i__4 = comslur_1.ndxslur + 48;
			chax_(ch__1, (ftnlen)1, &i__4);
			i__2[0] = 1, a__1[0] = ch__1;
			i__2[1] = lnoten, a__1[1] = noteq;
			s_cat(ch__7, a__1, i__2, &c__2, (ftnlen)9);
			i__6 = lnoten + 1;
			addstr_(ch__7, &i__6, soutq, lsout, lnoten + 1, (
				ftnlen)80);
		    } else {
/* Writing concatenation */
			i__5[0] = 2, a__3[0] = "{1";
			i__4 = comslur_1.ndxslur + 38;
			chax_(ch__1, (ftnlen)1, &i__4);
			i__5[1] = 1, a__3[1] = ch__1;
			i__5[2] = 1, a__3[2] = "}";
			i__5[3] = lnoten, a__3[3] = noteq;
			s_cat(ch__8, a__3, i__5, &c__4, (ftnlen)12);
			i__6 = lnoten + 4;
			addstr_(ch__8, &i__6, soutq, lsout, lnoten + 4, (
				ftnlen)80);
		    }

/*  Stop slur terminator after exit from this subroutine */

		    comslur_1.listslur = bit_clear(comslur_1.listslur,
			    comslur_1.ndxslur);
		    comgrace_1.slurg[*ig - 1] = FALSE_;
		}
	    }

/*  Accidental if needed */

	    if (comgrace_1.naccg[ing - 1] > 0) {
		notefq_(noteq, &lnoten, &comgrace_1.nolevg[ing - 1], ncm, (
			ftnlen)8);
		if (lnoten == 1) {
		    addblank_(noteq, &lnoten, (ftnlen)8);
		}
		accsym_(&comgrace_1.naccg[ing - 1], acsymq, &lacc, (ftnlen)3);
/* Writing concatenation */
		i__5[0] = 1, a__3[0] = sq;
		i__5[1] = 3, a__3[1] = "big";
		i__5[2] = lacc, a__3[2] = acsymq;
		i__5[3] = lnoten, a__3[3] = noteq;
		s_cat(ch__9, a__3, i__5, &c__4, (ftnlen)15);
		i__4 = lacc + 4 + lnoten;
		addstr_(ch__9, &i__4, soutq, lsout, lacc + 4 + lnoten, (
			ftnlen)80);
	    }

/*  Put in the (beamed) grace note */

	    notefq_(noteq, &lnoten, &comgrace_1.nolevg[ing - 1], ncm, (ftnlen)
		    8);
/* Writing concatenation */
	    i__3[0] = 1, a__2[0] = sq;
	    i__3[1] = 4, a__2[1] = "zqb0";
	    i__3[2] = lnoten, a__2[2] = noteq;
	    s_cat(ch__15, a__2, i__3, &c__3, (ftnlen)13);
	    i__4 = lnoten + 5;
	    addstr_(ch__15, &i__4, soutq, lsout, lnoten + 5, (ftnlen)80);
/* L127: */
	}

/*  Terminate the grace */

/* Writing concatenation */
	i__5[0] = 1, a__3[0] = sq;
	i__5[1] = 14, a__3[1] = "normalnotesize";
	i__5[2] = 1, a__3[2] = sq;
	i__5[3] = 4, a__3[3] = "off{";
	s_cat(notexq, a__3, i__5, &c__4, (ftnlen)79);
	lnote = 20;
	ptoff = comask_1.wheadpt * spfacs_1.emgfac;
	if ((*nacc & 3) > 0) {
	    ptoff += comask_1.wheadpt * spfacs_1.accfac;
	}
	if (isgaft && ! iswaft) {
/* Writing concatenation */
	    i__2[0] = 20, a__1[0] = notexq;
	    i__2[1] = 1, a__1[1] = "-";
	    s_cat(notexq, a__1, i__2, &c__2, (ftnlen)79);
	    lnote = 21;
	    ptoff = comgrace_1.aftshft;
	}
	if (ptoff < (float)9.95) {
	    i__1 = lnote;
	    ici__1.icierr = 0;
	    ici__1.icirnum = 1;
	    ici__1.icirlen = lnote + 3 - i__1;
	    ici__1.iciunit = notexq + i__1;
	    ici__1.icifmt = "(f3.1)";
	    s_wsfi(&ici__1);
	    do_fio(&c__1, (char *)&ptoff, (ftnlen)sizeof(real));
	    e_wsfi();
	    lnote += 3;
	} else {
	    i__1 = lnote;
	    ici__1.icierr = 0;
	    ici__1.icirnum = 1;
	    ici__1.icirlen = lnote + 4 - i__1;
	    ici__1.iciunit = notexq + i__1;
	    ici__1.icifmt = "(f4.1)";
	    s_wsfi(&ici__1);
	    do_fio(&c__1, (char *)&ptoff, (ftnlen)sizeof(real));
	    e_wsfi();
	    lnote += 4;
	}
/* Writing concatenation */
	i__2[0] = lnote, a__1[0] = notexq;
	i__2[1] = 3, a__1[1] = "pt}";
	s_cat(ch__16, a__1, i__2, &c__2, (ftnlen)82);
	i__1 = lnote + 3;
	addstr_(ch__16, &i__1, soutq, lsout, lnote + 3, (ftnlen)80);
	if (isgaft && ! iswaft) {
/* Writing concatenation */
	    i__2[0] = 1, a__1[0] = sq;
	    i__2[1] = 2, a__1[1] = "sk";
	    s_cat(ch__17, a__1, i__2, &c__2, (ftnlen)3);
	    addstr_(ch__17, &c__3, soutq, lsout, (ftnlen)3, (ftnlen)80);
	}
    }
    return 0;
} /* dograce_ */

/* Subroutine */ int wsclef_(iv, ninow, clefq, nclef, clefq_len)
integer *iv, *ninow;
char *clefq;
integer *nclef;
ftnlen clefq_len;
{
    /* System generated locals */
    address a__1[3], a__2[2];
    integer i__1, i__2[3], i__3[2], i__4;
    char ch__1[1], ch__2[1], ch__3[9], ch__4[22];

    /* Builtin functions */
    integer s_wsle(), e_wsle(), do_lio();
    /* Subroutine */ int s_stop(), s_cat();
    integer s_wsfi(), do_fio(), e_wsfi(), s_wsfe(), e_wsfe();

    /* Local variables */
    static integer iv1, iv2, iiv;
    extern /* Character */ VOID chax_();
    static integer ltem;
    static char temq[20];
    static integer iinst;
    extern integer numclef_();

    /* Fortran I/O blocks */
    static cilist io___1117 = { 0, 6, 0, 0, 0 };
    static cilist io___1118 = { 0, 6, 0, 0, 0 };
    static icilist io___1122 = { 0, temq, 0, "(a9,i2,a1)", 20, 1 };
    static cilist io___1123 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1125 = { 0, 11, 0, "(a)", 0 };



/*  Writes \setclef for instrument containing voice iv */

    /* Parameter adjustments */
    --clefq;

    /* Function Body */
    if (*nclef < 7) {
	i__1 = *nclef + 48;
	chax_(ch__1, (ftnlen)1, &i__1);
	*(unsigned char *)&clefq[*iv] = *(unsigned char *)&ch__1[0];
    } else {
	*(unsigned char *)&clefq[*iv] = '9';
    }
    if (! comlast_1.islast) {
	return 0;
    }
    iv1 = 1;
    i__1 = *ninow;
    for (iinst = 1; iinst <= i__1; ++iinst) {
	if (*iv < iv1 + comnvi_1.nspern[iinst - 1]) {
	    goto L2;
	}
	iv1 += comnvi_1.nspern[iinst - 1];
/* L1: */
    }
    s_wsle(&io___1117);
    e_wsle();
    s_wsle(&io___1118);
    do_lio(&c__9, &c__1, "Should not be here in wsclef!", (ftnlen)29);
    e_wsle();
    s_stop("1", (ftnlen)1);
L2:
    iv2 = iv1 + comnvi_1.nspern[iinst - 1] - 1;
    if (iinst < 10) {
/* Writing concatenation */
	chax_(ch__1, (ftnlen)1, &c__92);
	i__2[0] = 1, a__1[0] = ch__1;
	i__2[1] = 7, a__1[1] = "setclef";
	i__1 = iinst + 48;
	chax_(ch__2, (ftnlen)1, &i__1);
	i__2[2] = 1, a__1[2] = ch__2;
	s_cat(temq, a__1, i__2, &c__3, (ftnlen)20);
	ltem = 9;
    } else {
	s_wsfi(&io___1122);
/* Writing concatenation */
	chax_(ch__1, (ftnlen)1, &c__92);
	i__3[0] = 1, a__2[0] = ch__1;
	i__3[1] = 8, a__2[1] = "setclef{";
	s_cat(ch__3, a__2, i__3, &c__2, (ftnlen)9);
	do_fio(&c__1, ch__3, (ftnlen)9);
	do_fio(&c__1, (char *)&iinst, (ftnlen)sizeof(integer));
	do_fio(&c__1, "}", (ftnlen)1);
	e_wsfi();
	ltem = 12;
    }
    if (iv1 == iv2) {
	s_wsfe(&io___1123);
/* Writing concatenation */
	i__2[0] = ltem, a__1[0] = temq;
	i__2[1] = 1, a__1[1] = clefq + *iv;
	i__2[2] = 1, a__1[2] = "%";
	s_cat(ch__4, a__1, i__2, &c__3, (ftnlen)22);
	do_fio(&c__1, ch__4, ltem + 2);
	e_wsfe();
    } else {
/* Writing concatenation */
	i__3[0] = ltem, a__2[0] = temq;
	i__3[1] = 1, a__2[1] = "{";
	s_cat(temq, a__2, i__3, &c__2, (ftnlen)20);
	++ltem;
	i__1 = iv2;
	for (iiv = iv1; iiv <= i__1; ++iiv) {
/* Writing concatenation */
	    i__3[0] = ltem, a__2[0] = temq;
	    i__4 = numclef_(clefq + iiv, (ftnlen)1) + 48;
	    chax_(ch__1, (ftnlen)1, &i__4);
	    i__3[1] = 1, a__2[1] = ch__1;
	    s_cat(temq, a__2, i__3, &c__2, (ftnlen)20);
	    ++ltem;
/* L3: */
	}
	s_wsfe(&io___1125);
/* Writing concatenation */
	i__3[0] = ltem, a__2[0] = temq;
	i__3[1] = 2, a__2[1] = "}%";
	s_cat(ch__4, a__2, i__3, &c__2, (ftnlen)22);
	do_fio(&c__1, ch__4, ltem + 2);
	e_wsfe();
    }
    return 0;
} /* wsclef_ */

/* Subroutine */ int endslur_(stemup, upslur, nolev, iupdn, ndxslur, ivoff, 
	ncm, soutq, lsout, soutq_len)
logical *stemup, *upslur;
integer *nolev, *iupdn, *ndxslur, *ivoff, *ncm;
char *soutq;
integer *lsout;
ftnlen soutq_len;
{
    /* System generated locals */
    address a__1[2], a__2[4];
    integer i__1[2], i__2, i__3[4];
    char ch__1[1];

    /* Builtin functions */
    /* Subroutine */ int s_cat();

    /* Local variables */
    extern /* Character */ VOID chax_();
    static logical shift;
    static integer lnote;
    static char noteq[8];
    extern /* Subroutine */ int addstr_(), notefq_();
    static integer lnoten;
    static char notexq[79];

    shift = ! (*stemup) && ! (*upslur);
    if (! shift) {

/*  No shift needed */

/* Writing concatenation */
	chax_(ch__1, (ftnlen)1, &c__92);
	i__1[0] = 1, a__1[0] = ch__1;
	i__1[1] = 5, a__1[1] = "tslur";
	s_cat(notexq, a__1, i__1, &c__2, (ftnlen)79);
	lnote = 6;
    } else {

/*  Shift needed */

/* Writing concatenation */
	chax_(ch__1, (ftnlen)1, &c__92);
	i__1[0] = 1, a__1[0] = ch__1;
	i__1[1] = 2, a__1[1] = "ts";
	s_cat(notexq, a__1, i__1, &c__2, (ftnlen)79);
	lnote = 3;
    }
/*      notexq = notexq(1:lnote)//chax(48+ndxslur) */
/*      lnote = lnote+1 */
    if (*ndxslur < 10) {
/* Writing concatenation */
	i__1[0] = lnote, a__1[0] = notexq;
	i__2 = *ndxslur + 48;
	chax_(ch__1, (ftnlen)1, &i__2);
	i__1[1] = 1, a__1[1] = ch__1;
	s_cat(notexq, a__1, i__1, &c__2, (ftnlen)79);
	++lnote;
    } else {
/* Writing concatenation */
	i__3[0] = lnote, a__2[0] = notexq;
	i__3[1] = 2, a__2[1] = "{1";
	i__2 = *ndxslur + 38;
	chax_(ch__1, (ftnlen)1, &i__2);
	i__3[2] = 1, a__2[2] = ch__1;
	i__3[3] = 1, a__2[3] = "}";
	s_cat(notexq, a__2, i__3, &c__4, (ftnlen)79);
	lnote += 4;
    }
    i__2 = *nolev + *iupdn + *ivoff;
    notefq_(noteq, &lnoten, &i__2, ncm, (ftnlen)8);
/* Writing concatenation */
    i__1[0] = lnote, a__1[0] = notexq;
    i__1[1] = lnoten, a__1[1] = noteq;
    s_cat(notexq, a__1, i__1, &c__2, (ftnlen)79);
    lnote += lnoten;
    if (shift) {
/* Writing concatenation */
	i__1[0] = lnote, a__1[0] = notexq;
	i__1[1] = 5, a__1[1] = "{-.6}";
	s_cat(notexq, a__1, i__1, &c__2, (ftnlen)79);
	lnote += 5;
    }
    addstr_(notexq, &lnote, soutq, lsout, (ftnlen)79, (ftnlen)80);
    return 0;
} /* endslur_ */

/* Subroutine */ int getfig_(itoff, charq, lineq, iccount, isfig, itfig, 
	itsofar, nodur, figq, ivx, nfigs, charq_len, lineq_len, figq_len)
integer *itoff;
char *charq, *lineq;
integer *iccount;
logical *isfig;
integer *itfig, *itsofar, *nodur;
char *figq;
integer *ivx, *nfigs;
ftnlen charq_len;
ftnlen lineq_len;
ftnlen figq_len;
{
    /* System generated locals */
    address a__1[2];
    integer i__1[2];
    icilist ici__1;

    /* Builtin functions */
    integer s_rsfi(), do_fio(), e_rsfi();
    /* Subroutine */ int s_copy(), s_cat();

    /* Local variables */
    static integer lfig, loff, noff;
    extern /* Subroutine */ int getchar_();
    extern integer ifnodur_();

    if (*ivx != 1) {

/*  Read past the figure */

L6:
	getchar_(lineq, iccount, charq, (ftnlen)128, (ftnlen)1);
	if (*(unsigned char *)charq != ' ') {
	    goto L6;
	}
	return 0;
    }
    ++(*nfigs);
    *itoff = 0;
    if (*(unsigned char *)charq == 'x') {

/*  Floating figure. */

	getchar_(lineq, iccount, charq, (ftnlen)128, (ftnlen)1);
	ici__1.icierr = 0;
	ici__1.iciend = 0;
	ici__1.icirnum = 1;
	ici__1.icirlen = 1;
	ici__1.iciunit = charq;
	ici__1.icifmt = "(i1)";
	s_rsfi(&ici__1);
	do_fio(&c__1, (char *)&noff, (ftnlen)sizeof(integer));
	e_rsfi();
	getchar_(lineq, iccount, charq, (ftnlen)128, (ftnlen)1);
	ici__1.icierr = 0;
	ici__1.iciend = 0;
	ici__1.icirnum = 1;
	ici__1.icirlen = 1;
	ici__1.iciunit = charq;
	ici__1.icifmt = "(i1)";
	s_rsfi(&ici__1);
	do_fio(&c__1, (char *)&loff, (ftnlen)sizeof(integer));
	e_rsfi();
	*itoff = noff * ifnodur_(&loff, "x", (ftnlen)1);
	getchar_(lineq, iccount, charq, (ftnlen)128, (ftnlen)1);
    } else {

/*  Figure on a note */

	*isfig = TRUE_;
    }
    *itfig = *itsofar + *itoff - *nodur;
    lfig = 1;
    s_copy(figq, charq, (ftnlen)6, (ftnlen)1);
L5:
    getchar_(lineq, iccount, charq, (ftnlen)128, (ftnlen)1);
    if (*(unsigned char *)charq != ' ') {
/* Writing concatenation */
	i__1[0] = lfig, a__1[0] = figq;
	i__1[1] = 1, a__1[1] = charq;
	s_cat(figq, a__1, i__1, &c__2, (ftnlen)6);
	++lfig;
	goto L5;
    }
    return 0;
} /* getfig_ */

/* Subroutine */ int eskb4_(ip, ivx, in, ib, space, tstart, fbar, itrpt, esk)
integer *ip, *ivx, *in, *ib;
real *space, *tstart, *fbar;
integer *itrpt;
real *esk;
{
    /* System generated locals */
    real r__1;

    /* Builtin functions */
    integer i_nint(), s_wsle(), do_lio(), e_wsle();
    /* Subroutine */ int s_stop();

    /* Local variables */
    static integer iib;
    extern doublereal feon_();
    static integer itnd, nnsk, itprev;

    /* Fortran I/O blocks */
    static cilist io___1138 = { 0, 6, 0, 0, 0 };



/*  Get elemskips to previous note.  Called only for graces, no xtups involved. */

    /* Parameter adjustments */
    --tstart;
    --space;

    /* Function Body */
    itnd = i_nint(&all_1.to[*in - 1]);
    if (*ip == 1 || itnd == *itrpt) {

/*  Start of bar or after rpt. */

	*esk = *fbar;
	return 0;
    } else {
	*esk = (float)0.;
	itprev = itnd - all_1.nodur[*ivx + (*ip - 1) * 15 - 16];
	for (iib = *ib; iib >= 1; --iib) {
	    if (tstart[iib] < itprev + comtol_1.tol) {

/*  This is the block */

		r__1 = (real) (itnd - itprev) / space[iib];
		nnsk = i_nint(&r__1);
		*esk += nnsk * feon_(&space[iib]);
		return 0;
	    } else {
		r__1 = (itnd - tstart[iib]) / space[iib];
		nnsk = i_nint(&r__1);
		*esk += nnsk * feon_(&space[iib]);
		itnd = i_nint(&tstart[iib]);
	    }
/* L1: */
	}
    }
    s_wsle(&io___1138);
    do_lio(&c__9, &c__1, "Problem in eskb4.  Send files to Dr. Don", (ftnlen)
	    40);
    e_wsle();
    s_stop("", (ftnlen)0);
} /* eskb4_ */

/* Subroutine */ int putorn_(iornq, nolev, nolevm, nodur, nornb, ulq, ibmcnt, 
	ivx, ncm, islur, nvmx, nv, ihornb, stemlin, outq, lout, ip, islhgt, 
	beamon, iscrd, ulq_len, outq_len)
integer *iornq, *nolev, *nolevm, *nodur, *nornb;
char *ulq;
integer *ibmcnt, *ivx, *ncm, *islur, *nvmx, *nv, *ihornb;
real *stemlin;
char *outq;
integer *lout, *ip, *islhgt;
logical *beamon, *iscrd;
ftnlen ulq_len;
ftnlen outq_len;
{
    /* System generated locals */
    address a__1[2], a__2[3];
    integer i__1, i__2, i__3[2], i__4[3];
    real r__1, r__2;
    char ch__1[1];

    /* Builtin functions */
    integer pow_ii(), i_nint();
    /* Subroutine */ int s_cat();
    integer lbit_shift(), i_dim();
    /* Subroutine */ int s_copy();

    /* Local variables */
    static char sq[1];
    extern integer log2_();
    extern /* Character */ VOID chax_();
    static integer ioff, ibit;
    extern /* Character */ VOID udqq_();
    static integer ihorn, lnote;
    static char noteq[8];
    static integer iornt;
    static char ulpzq[1];
    extern /* Subroutine */ int notefq_();
    static integer lnoten, iudorn;
    static char notexq[79];
    static integer ioffinc;
    static real stemlen;
    extern /* Subroutine */ int dotrill_(), addblank_();
    static logical usehornb;


/*  All args are individual array element *values* except nornb,ihornb,ulq. */
/*  notcrd = .true. if ornament is on main note. */
/*    nolevm is level of main note (for chords) */

    /* Parameter adjustments */
    ihornb -= 16;
    ulq -= 16;
    --nornb;

    /* Function Body */
    chax_(ch__1, (ftnlen)1, &c__92);
    *(unsigned char *)sq = *(unsigned char *)&ch__1[0];
    *lout = 0;
    usehornb = FALSE_;
    if (*nodur < 64) {
	stemlen = *stemlin;
    } else {
	stemlen = (float)0.;
    }

/*  Get up-downness. ulpzq is opposite from stem direction for both beams and */
/*    non beams.  Can use in name of ornament [ . or _ ] */

    if (*beamon) {
	if (*(unsigned char *)&ulq[*ivx + *ibmcnt * 15] == 'u') {
	    *(unsigned char *)ulpzq = 'l';
	} else {
	    *(unsigned char *)ulpzq = 'u';
	}
    } else {
	udqq_(ch__1, (ftnlen)1, nolevm, ncm, islur, nvmx, ivx, nv);
	if (*(unsigned char *)&ch__1[0] == 'l') {
	    *(unsigned char *)ulpzq = 'u';
	} else {
	    *(unsigned char *)ulpzq = 'l';
	}
    }

/*  To enable >1 ornament on a note, next line is top of manual loop. */

L2:

/*  Bit # of last ornament (last of bits 0-21) */

    i__1 = *iornq & 4194303;
    ibit = log2_(&i__1);
    iornt = pow_ii(&c__2, &ibit);

/*  Begin routine to set height.  Bits 0-13: (stmgx+Tupf._) */
/*  14: Down fermata, was F  15: Trill w/o "tr", was U, 16-18: edit. s,f,n */
/*  19-20: >^, 21: ? (with or w/o 16-18) */

/*  Do not use beam height for . or _ */

    if (bit_test(*iornq,22) && (iornt & 6144) == 0) {

/*  Height is set by special beam stuff. */
/* c  Following block leaves ihorn set for later orns on same note. */
/*  No! Do not leave ihorn set, do separately for every ornament */

/*        if (.not.usebmht) then */
	ihorn = ihornb[*ivx + nornb[*ivx] * 15];
/*          if (iand(iornt,6144).gt.0) then */
/* c */
/* c  Fine-tune for _ or .  Note flaw: for later normal orn here, ht. is wrong. */
/* c */
/*            ihorn = ihorn+1-2*index('l',ulpzq) */
/*            ulpzq = chax(225-ichar(ulpzq)) */
/*          else if (ulpzq .eq. 'u') then */
/*          else if (ulpzq .eq. 'u') then */
/*            ihorn = ihorn-2 */
/*          end if */
	if (*(unsigned char *)ulpzq == 'u') {
	    ihorn += -2;
	}
/*        nornb(ivx) = nornb(ivx)+1 */

/*  Following flag tells whether to increment nornb when exiting the subroutine. */

	usehornb = TRUE_;
/*        end if */
    } else if (ibit == 14) {

/*  Down fermata.  Don't worry about upper chord notes. */

	if (*(unsigned char *)ulpzq == 'l') {
/* Computing MIN */
	    i__1 = *nolev, i__2 = *ncm - 3;
	    ihorn = min(i__1,i__2);
	} else {
/* Computing MIN */
	    r__1 = *nolev - stemlen, r__2 = *ncm - (float)3.;
	    ihorn = dmin(r__1,r__2);
	}
    } else if (bit_test(iornt,13) || bit_test(iornt,0)) {

/*  ( or ) */

	ihorn = *nolev;
    } else if ((iornt & 6144) > 0) {

/* c  Staccato . or tenuto _ , but not special beam stuff.  Need up-down info */
/*  NOTE: removed .&_ from special beam treatment. */
/*  Staccato . or tenuto _  Need up-down info */

	if (! (*iscrd) || comtrill_1.maxlev != *nolev && *(unsigned char *)
		ulpzq == 'l' || comtrill_1.minlev != *nolev && *(unsigned 
		char *)ulpzq == 'u') {
	    ihorn = *nolev;
	} else if (comtrill_1.maxlev == *nolev) {
	    *(unsigned char *)ulpzq = 'u';
/* Computing MAX */
	    r__1 = *nolev + stemlen, r__2 = *ncm + (float)3.;
	    ihorn = dmax(r__1,r__2);
	} else {
	    *(unsigned char *)ulpzq = 'l';
/* Computing MIN */
	    r__1 = *nolev - stemlen, r__2 = *ncm - (float)3.;
	    ihorn = dmin(r__1,r__2);
	}
    } else if (*iscrd && *nolev == comtrill_1.minlev) {
	if (*(unsigned char *)ulpzq == 'l') {
/* Computing MIN */
	    i__1 = *nolev - 3, i__2 = *ncm - 6;
	    ihorn = min(i__1,i__2);
	} else {
/* Computing MIN */
	    i__1 = *nolev - i_nint(&stemlen) - 3, i__2 = *ncm - 6;
	    ihorn = min(i__1,i__2);
	}
    } else if (*(unsigned char *)ulpzq == 'l') {

/*  (iscrd and nolev=maxlev) or (.not.iscrd) */

/* Computing MAX */
	r__1 = *nolev + stemlen + 2, r__2 = *ncm + (float)5.;
	ihorn = dmax(r__1,r__2);
    } else {
/* Computing MAX */
	i__1 = *nolev + 2, i__2 = *ncm + 5;
	ihorn = max(i__1,i__2);
    }
    ioff = 0;

/*  Begin routine to set name.  Bits 0-13: (stmgx+Tupf._) */
/*  14: Down fermata, was F  15: Trill w/o "tr", was U, 16-18: edit. s,f,n */

    if (bit_test(iornt,2)) {
/* Writing concatenation */
	i__3[0] = 1, a__1[0] = sq;
	i__3[1] = 5, a__1[1] = "shake";
	s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	lnote = 6;
    } else if (bit_test(iornt,3)) {
/* Writing concatenation */
	i__3[0] = 1, a__1[0] = sq;
	i__3[1] = 7, a__1[1] = "mordent";
	s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	lnote = 8;
    } else if (bit_test(iornt,1)) {
/* Writing concatenation */
	i__3[0] = 1, a__1[0] = sq;
	i__3[1] = 3, a__1[1] = "mtr";
	s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	lnote = 4;
    } else if (bit_test(iornt,5)) {
/* Writing concatenation */
	i__3[0] = 1, a__1[0] = sq;
	i__3[1] = 3, a__1[1] = "xtr";
	s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	lnote = 4;
    } else if (bit_test(iornt,6)) {
/* Writing concatenation */
	i__3[0] = 1, a__1[0] = sq;
	i__3[1] = 3, a__1[1] = "ptr";
	s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	lnote = 4;
    } else if (bit_test(iornt,13)) {
/* Writing concatenation */
	i__3[0] = 1, a__1[0] = sq;
	i__3[1] = 3, a__1[1] = "rpn";
	s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	lnote = 4;
    } else if (bit_test(iornt,0)) {
/* Writing concatenation */
	i__3[0] = 1, a__1[0] = sq;
	i__3[1] = 3, a__1[1] = "lpn";
	s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	lnote = 4;
    } else if (bit_test(iornt,12)) {
/* Writing concatenation */
	i__4[0] = 1, a__2[0] = sq;
	i__4[1] = 1, a__2[1] = ulpzq;
	i__4[2] = 2, a__2[2] = "st";
	s_cat(notexq, a__2, i__4, &c__3, (ftnlen)79);
	lnote = 4;
    } else if (bit_test(iornt,11)) {
/* Writing concatenation */
	i__4[0] = 1, a__2[0] = sq;
	i__4[1] = 1, a__2[1] = ulpzq;
	i__4[2] = 2, a__2[2] = "pz";
	s_cat(notexq, a__2, i__4, &c__3, (ftnlen)79);
	lnote = 4;
    } else if (bit_test(iornt,8)) {
/* Writing concatenation */
	i__3[0] = 1, a__1[0] = sq;
	i__3[1] = 3, a__1[1] = "upz";
	s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	lnote = 4;
	ioff = -2;
    } else if (bit_test(iornt,9)) {
/* Writing concatenation */
	i__3[0] = 1, a__1[0] = sq;
	i__3[1] = 4, a__1[1] = "uppz";
	s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	lnote = 5;
	ioff = -2;
    } else if (bit_test(iornt,10)) {
	if (*nodur < 48) {
/* Writing concatenation */
	    i__3[0] = 1, a__1[0] = sq;
	    i__3[1] = 9, a__1[1] = "fermataup";
	    s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	} else {
/* Writing concatenation */
	    i__3[0] = 1, a__1[0] = sq;
	    i__3[1] = 9, a__1[1] = "Fermataup";
	    s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	}
	lnote = 10;
	ioff = -2;
    } else if (bit_test(iornt,14)) {
	if (*nodur < 48) {
/* Writing concatenation */
	    i__3[0] = 1, a__1[0] = sq;
	    i__3[1] = 11, a__1[1] = "fermatadown";
	    s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	} else {
/* Writing concatenation */
	    i__3[0] = 1, a__1[0] = sq;
	    i__3[1] = 11, a__1[1] = "Fermatadown";
	    s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	}
	lnote = 12;
    } else if (bit_test(iornt,21)) {

/*  "?" in editorial ornament.  Clear bit 16-18 after use, since ibit=21 */

	if (bit_test(*iornq,16)) {
/* Writing concatenation */
	    i__3[0] = 1, a__1[0] = sq;
	    i__3[1] = 6, a__1[1] = "qsharp";
	    s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	    lnote = 7;
	    ioff = 2;
	    *iornq = bit_clear(*iornq,16);
	} else if (bit_test(*iornq,17)) {
/* Writing concatenation */
	    i__3[0] = 1, a__1[0] = sq;
	    i__3[1] = 5, a__1[1] = "qflat";
	    s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	    lnote = 6;
	    ioff = 1;
	    *iornq = bit_clear(*iornq,17);
	} else if (bit_test(*iornq,18)) {
/* Writing concatenation */
	    i__3[0] = 1, a__1[0] = sq;
	    i__3[1] = 4, a__1[1] = "qnat";
	    s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	    lnote = 5;
	    ioff = 2;
	    *iornq = bit_clear(*iornq,18);
	} else {
/* Writing concatenation */
	    i__3[0] = 1, a__1[0] = sq;
	    i__3[1] = 5, a__1[1] = "qedit";
	    s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	    lnote = 6;
	    ioff = 0;
	}
    } else if (bit_test(iornt,16)) {
/* Writing concatenation */
	i__3[0] = 1, a__1[0] = sq;
	i__3[1] = 6, a__1[1] = "esharp";
	s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	lnote = 7;
	ioff = 2;
    } else if (bit_test(iornt,17)) {
/* Writing concatenation */
	i__3[0] = 1, a__1[0] = sq;
	i__3[1] = 5, a__1[1] = "eflat";
	s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	lnote = 6;
	ioff = 1;
    } else if (bit_test(iornt,18)) {
/* Writing concatenation */
	i__3[0] = 1, a__1[0] = sq;
	i__3[1] = 4, a__1[1] = "enat";
	s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	lnote = 5;
	ioff = 2;
    } else if (bit_test(iornt,19)) {
/* Writing concatenation */
	i__3[0] = 1, a__1[0] = sq;
	i__3[1] = 3, a__1[1] = "usf";
	s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	lnote = 4;
	ioff = -2;
    } else if (bit_test(iornt,20)) {
/* Writing concatenation */
	i__3[0] = 1, a__1[0] = sq;
	i__3[1] = 4, a__1[1] = "usfz";
	s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	lnote = 5;
	ioff = -2;
    }

/*  User-defined level shift of ornament from default? */

    if (bit_test(*iornq,25)) {

/*  Find which (if any) element of kudorn has the shift. */

	i__1 = comtrill_1.nudorn;
	for (iudorn = 1; iudorn <= i__1; ++iudorn) {
	    if (*ip + (*ivx << 8) + (*nolev << 12) + (ibit << 19) == (
		    33554431 & comtrill_1.kudorn[iudorn - 1])) {
		goto L4;
	    }
/* L3: */
	}

/*  Nothing shifted on this note; exit this loop */

	goto L5;
L4:
	ioffinc = (63 & lbit_shift(comtrill_1.kudorn[iudorn - 1], (ftnlen)-25)
		) - 32;
	if (ibit == 19 && ioffinc < -7) {

/*  Convert usf to lsf.  The reason has to do with positioning being impossile */
/*  for some mysterious reason when you drop \usf below the staff */

/* Writing concatenation */
	    i__3[0] = 1, a__1[0] = sq;
	    i__3[1] = 3, a__1[1] = "lsf";
	    s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	    ioffinc += 6;
	}
	ioff += ioffinc;
    }
L5:

/*  Shift level to avoid slur.  Conditions are */
/*   1.  There is a slur */
/*   2.  No user-defined orn height shift (btest(iornq,25)) */
/*   3.  upslur (islhgt>0) */
/*   4.  ornament is not segno(4), ._)(11-13), down ferm(14) or "(" (0) Bin=30737 */
/*   5.  islhgt+3 >=  height already computed. */

    if (! bit_test(*iornq,25) && *islhgt > 0 && (iornt & 30737) == 0) {
	i__1 = *islhgt + 3;
	ioff += i_dim(&i__1, &ihorn);
    }
    i__1 = ihorn + ioff;
    notefq_(noteq, &lnoten, &i__1, ncm, (ftnlen)8);
    if (lnoten == 1) {
	addblank_(noteq, &lnoten, (ftnlen)8);
    }
    if ((iornt & 32896) > 0) {

/*  T-trill or trill w/o "tr" */

	dotrill_(ivx, ip, &iornt, noteq, &lnoten, notexq, &lnote, (ftnlen)8, (
		ftnlen)79);
    } else {
/* Writing concatenation */
	i__3[0] = lnote, a__1[0] = notexq;
	i__3[1] = lnoten, a__1[1] = noteq;
	s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	lnote += lnoten;
    }

/*  Zero out the bit for ornament just dealt with. */

    *iornq = bit_clear(*iornq,ibit);
    if (*lout == 0) {
	s_copy(outq, notexq, (ftnlen)79, lnote);
    } else {
/* Writing concatenation */
	i__3[0] = *lout, a__1[0] = outq;
	i__3[1] = lnote, a__1[1] = notexq;
	s_cat(outq, a__1, i__3, &c__2, (ftnlen)79);
    }
    *lout += lnote;

/*  Check bits 0-21, go back if any are still set */

    if ((*iornq & 4194303) > 0) {
	goto L2;
    }
    if (usehornb) {
	++nornb[*ivx];
    }
    return 0;
} /* putorn_ */

/* Subroutine */ int putxtn_(ntupv, iflop, multb, iud, wheadpt, poenom, 
	nolev1, islope, slfac, xnlmid, islur, lnote, notexq, ncmid, nlnum, 
	eloff, iup, irest, notexq_len)
integer *ntupv, *iflop, *multb, *iud;
real *wheadpt, *poenom;
integer *nolev1, *islope;
real *slfac, *xnlmid;
integer *islur, *lnote;
char *notexq;
integer *ncmid, *nlnum;
real *eloff;
integer *iup, *irest;
ftnlen notexq_len;
{
    /* System generated locals */
    address a__1[2], a__2[3];
    integer i__1[2], i__2[3], i__3;
    real r__1;
    char ch__1[1];
    icilist ici__1;

    /* Builtin functions */
    integer i_nint(), lbit_shift();
    /* Subroutine */ int s_cat();
    integer s_wsfi(), do_fio(), e_wsfi();

    /* Local variables */
    extern /* Character */ VOID chax_();
    static char noteq[8];
    extern /* Subroutine */ int notefq_();
    static integer lnoten;


/*  Places digit for xtuplet. */

    if (*iflop != 0 && *multb > 0) {

/* Number goes on beam side, move R/L by .5 wheadpt for upper/lower */

	*eloff -= *iud * (float).5 * *wheadpt / *poenom;

/*  Number goes on beam side, must use beam parameters to set pos'n */

	*nlnum = *nolev1 + *islope / *slfac * *eloff + *iup * (*multb + 8);
	if (*multb >= 2) {
	    *nlnum += *iup;
	}
    } else {
	r__1 = *xnlmid - 1 + *iud * 3 + *iflop * 11;
	*nlnum = i_nint(&r__1);
    }
    if (! bit_test(*islur,31)) {

/*  Only print number when wanted.  First check vert, horiz offset */

	if (bit_test(*irest,1)) {
	    *nlnum = *nlnum + (31 & lbit_shift(*irest, (ftnlen)-2)) - 16;
	}
	if (bit_test(*irest,7)) {
	    *eloff += ((31 & lbit_shift(*irest, (ftnlen)-9)) * (float).1 - (
		    float)1.6) * *wheadpt / *poenom;
	}
/* Writing concatenation */
	chax_(ch__1, (ftnlen)1, &c__92);
	i__1[0] = 1, a__1[0] = ch__1;
	i__1[1] = 5, a__1[1] = "xnum{";
	s_cat(notexq, a__1, i__1, &c__2, (ftnlen)79);
	*lnote = 10;
	if (*eloff < (float).995) {
	    ici__1.icierr = 0;
	    ici__1.icirnum = 1;
	    ici__1.icirlen = 4;
	    ici__1.iciunit = notexq + 6;
	    ici__1.icifmt = "(i1,f3.2)";
	    s_wsfi(&ici__1);
	    do_fio(&c__1, (char *)&c__0, (ftnlen)sizeof(integer));
	    do_fio(&c__1, (char *)&(*eloff), (ftnlen)sizeof(real));
	    e_wsfi();
	} else if (*eloff < (float)9.995) {
	    ici__1.icierr = 0;
	    ici__1.icirnum = 1;
	    ici__1.icirlen = 4;
	    ici__1.iciunit = notexq + 6;
	    ici__1.icifmt = "(f4.2)";
	    s_wsfi(&ici__1);
	    do_fio(&c__1, (char *)&(*eloff), (ftnlen)sizeof(real));
	    e_wsfi();
	} else {
	    ici__1.icierr = 0;
	    ici__1.icirnum = 1;
	    ici__1.icirlen = 5;
	    ici__1.iciunit = notexq + 6;
	    ici__1.icifmt = "(f5.2)";
	    s_wsfi(&ici__1);
	    do_fio(&c__1, (char *)&(*eloff), (ftnlen)sizeof(real));
	    e_wsfi();
	    *lnote = 11;
	}
	notefq_(noteq, &lnoten, nlnum, ncmid, (ftnlen)8);
/* Writing concatenation */
	i__2[0] = *lnote, a__2[0] = notexq;
	i__2[1] = 1, a__2[1] = "}";
	i__2[2] = lnoten, a__2[2] = noteq;
	s_cat(notexq, a__2, i__2, &c__3, (ftnlen)79);
	*lnote = *lnote + 1 + lnoten;
	if (*ntupv < 10) {
	    i__3 = *lnote;
	    ici__1.icierr = 0;
	    ici__1.icirnum = 1;
	    ici__1.icirlen = *lnote + 1 - i__3;
	    ici__1.iciunit = notexq + i__3;
	    ici__1.icifmt = "(i1)";
	    s_wsfi(&ici__1);
	    do_fio(&c__1, (char *)&(*ntupv), (ftnlen)sizeof(integer));
	    e_wsfi();
	    ++(*lnote);
	} else {
/* Writing concatenation */
	    i__1[0] = *lnote, a__1[0] = notexq;
	    i__1[1] = 1, a__1[1] = "{";
	    s_cat(notexq, a__1, i__1, &c__2, (ftnlen)79);
	    i__3 = *lnote + 1;
	    ici__1.icierr = 0;
	    ici__1.icirnum = 1;
	    ici__1.icirlen = *lnote + 3 - i__3;
	    ici__1.iciunit = notexq + i__3;
	    ici__1.icifmt = "(i2)";
	    s_wsfi(&ici__1);
	    do_fio(&c__1, (char *)&(*ntupv), (ftnlen)sizeof(integer));
	    e_wsfi();
/* Writing concatenation */
	    i__1[0] = *lnote + 3, a__1[0] = notexq;
	    i__1[1] = 1, a__1[1] = "}";
	    s_cat(notexq, a__1, i__1, &c__2, (ftnlen)79);
	    *lnote += 4;
	}
    }
    return 0;
} /* putxtn_ */

/* Subroutine */ int mrec1_(lineq, iccount, ndxm, lineq_len)
char *lineq;
integer *iccount, *ndxm;
ftnlen lineq_len;
{
    /* System generated locals */
    integer i__1, i__2;

    /* Builtin functions */
    integer i_indx();

    /* Local variables */
    extern integer ntindex_();


/*  This is called when (a) macro recording is just starting and */
/*  (b) at the start of a new line, if recording is on */

    if (! commac_1.mrecord) {

/*  Starting the macro */

	c1ommac_1.ip1mac[commac_1.macnum - 1] = inbuff_1.ipbuf - 
		inbuff_1.lbuf[inbuff_1.ilbuf - 2] + *iccount;
	c1ommac_1.il1mac[commac_1.macnum - 1] = inbuff_1.ilbuf - 1;
	c1ommac_1.ic1mac[commac_1.macnum - 1] = *iccount;
	commac_1.mrecord = TRUE_;
    }
    if (*iccount < 128) {
	i__1 = *iccount;
	*ndxm = i_indx(lineq + i__1, "M", 128 - i__1, (ftnlen)1);
	if (*ndxm > 0) {
	    i__1 = *iccount;
	    i__2 = 128 - *iccount;
	    *ndxm = ntindex_(lineq + i__1, "M", &i__2, 128 - i__1, (ftnlen)1);
	}
	if (*ndxm > 0) {

/*  This line ends the macro. */

	    c1ommac_1.ip2mac[commac_1.macnum - 1] = inbuff_1.ipbuf - 
		    inbuff_1.lbuf[inbuff_1.ilbuf - 2] + *iccount + *ndxm;
	    c1ommac_1.il2mac[commac_1.macnum - 1] = inbuff_1.ilbuf - 1;
	    commac_1.mrecord = FALSE_;
	}
    }
    return 0;
} /* mrec1_ */

/* Subroutine */ int read10_(string, lastchar, string_len)
char *string;
logical *lastchar;
ftnlen string_len;
{
    /* Builtin functions */
    /* Subroutine */ int s_copy();

    /* Local variables */
    static integer ip1, ip2;
    extern /* Subroutine */ int getbuf_();

    if (! commac_1.mplay) {
	if (inbuff_1.ilbuf > inbuff_1.nlbuf) {
	    goto L999;
	}
	getbuf_(string, string_len);
	return 0;
L999:
	*lastchar = TRUE_;
	return 0;
    } else {

/*  Play a macro.  Set pointer to first character needed in buffer */

	if (c1ommac_1.ilmac == c1ommac_1.il1mac[commac_1.macnum - 1]) {

/*  Getting first line of macro */

	    ip1 = c1ommac_1.ip1mac[commac_1.macnum - 1];
	    c1ommac_1.iplmac = ip1 - c1ommac_1.ic1mac[commac_1.macnum - 1];
	} else if (c1ommac_1.ilmac <= c1ommac_1.il2mac[commac_1.macnum - 1]) {

/*  Beyond first line of macro.  Advance line-start pointer. */

	    c1ommac_1.iplmac += inbuff_1.lbuf[c1ommac_1.ilmac - 2];
	    ip1 = c1ommac_1.iplmac + 1;
	} else {

/*  Beyond last line of macro.  Terminate it! */

	    commac_1.mplay = FALSE_;
	    commac_1.endmac = TRUE_;
	    return 0;
	}
	if (c1ommac_1.ilmac == c1ommac_1.il2mac[commac_1.macnum - 1]) {

/*  Getting last line of macro. */

	    ip2 = c1ommac_1.ip2mac[commac_1.macnum - 1];
	} else {

/*  Getting line before last line of macro. */

	    ip2 = c1ommac_1.iplmac + inbuff_1.lbuf[c1ommac_1.ilmac - 1];
	}
	if (ip2 >= ip1) {
	    s_copy(string, inbuff_1.bufq + (ip1 - 1), string_len, ip2 - (ip1 
		    - 1));
	} else {

/*  Kluge for when macro start is on a line by itself */

	    s_copy(string, " ", string_len, (ftnlen)1);
	}
	++c1ommac_1.ilmac;
	return 0;
    }
} /* read10_ */

/* Subroutine */ int getset_(nv, noinst, mtrnuml, mtrdenl, mtrnmp, mtrdnp, 
	xmtrnum0, npages, nsyst, musicsize, fracindent, istype0, inameq, 
	clefq, sepsymq, pathnameq, lpath, isig0, inameq_len, clefq_len, 
	sepsymq_len, pathnameq_len)
integer *nv, *noinst, *mtrnuml, *mtrdenl, *mtrnmp, *mtrdnp;
real *xmtrnum0;
integer *npages, *nsyst, *musicsize;
real *fracindent;
logical *istype0;
char *inameq, *clefq, *sepsymq, *pathnameq;
integer *lpath, *isig0;
ftnlen inameq_len;
ftnlen clefq_len;
ftnlen sepsymq_len;
ftnlen pathnameq_len;
{
    /* System generated locals */
    integer i__1, i__2;
    real r__1;
    olist o__1;

    /* Builtin functions */
    integer s_cmp(), f_open(), s_wsfe(), do_fio(), e_wsfe(), i_nint(), i_indx(
	    );

    /* Local variables */
    static integer i__, iv, ivi, nline;
    static char lineq[128];
    static integer iinst, jinst;
    extern doublereal readin_();
    extern /* Subroutine */ int getbuf_();
    static logical newway;
    static integer iccount, nvsofar;

    /* Fortran I/O blocks */
    static cilist io___1159 = { 0, 17, 0, "(a)", 0 };



/*  Get the first line */

    /* Parameter adjustments */
    --sepsymq;
    --clefq;
    inameq -= 79;

    /* Function Body */
    iccount = 0;
L9:
    getbuf_(lineq, (ftnlen)128);
    if (*(unsigned char *)lineq == '%') {
	goto L9;
    }
    *istype0 = s_cmp(lineq, "---", (ftnlen)3, (ftnlen)3) == 0;
    if (*istype0) {

/*  Have TeX input until next line that starts with '---'.  Save in scratch. */

	o__1.oerr = 0;
	o__1.ounit = 17;
	o__1.ofnm = 0;
	o__1.orl = 0;
	o__1.osta = "SCRATCH";
	o__1.oacc = 0;
	o__1.ofm = 0;
	o__1.oblnk = 0;
	f_open(&o__1);
L3:
	getbuf_(lineq, (ftnlen)128);
	if (s_cmp(lineq, "---", (ftnlen)3, (ftnlen)3) != 0) {
	    s_wsfe(&io___1159);
	    do_fio(&c__1, lineq, (ftnlen)128);
	    e_wsfe();
	    goto L3;
	}

/*  Force a new line read on first call to readin */

	iccount = 128;
    }

/*  Here, lineq is first line w/ numerical setup data. */

    r__1 = readin_(lineq, &iccount, &nline, (ftnlen)128);
    *nv = i_nint(&r__1);
    r__1 = readin_(lineq, &iccount, &nline, (ftnlen)128);
    *noinst = i_nint(&r__1);
    newway = *noinst <= 0;
    if (newway) {
	*noinst = -(*noinst);
    }
    i__1 = *noinst;
    for (iinst = 1; iinst <= i__1; ++iinst) {

/*  Seve # of staves per inst in case later drop some inst's. */

	if (newway) {

/*  Read in nvi for each instrument */

	    r__1 = readin_(lineq, &iccount, &nline, (ftnlen)128);
	    comnvi_1.nsperi[iinst - 1] = i_nint(&r__1);
	} else if (iinst > 1) {
	    comnvi_1.nsperi[iinst - 1] = 1;
	} else {
	    comnvi_1.nsperi[iinst - 1] = *nv - *noinst + 1;
	}
	comnvi_1.iiorig[iinst - 1] = iinst;
	comnvi_1.nspern[iinst - 1] = comnvi_1.nsperi[iinst - 1];
/* L2: */
    }
    r__1 = readin_(lineq, &iccount, &nline, (ftnlen)128);
    *mtrnuml = i_nint(&r__1);
    r__1 = readin_(lineq, &iccount, &nline, (ftnlen)128);
    *mtrdenl = i_nint(&r__1);
/* c */
/* c  Kluge to make mtrdenl work */
/* c */
/*      if (mtrdenl .eq. 1) then */
/*        mtrdenl = 2 */
/*        mtrnuml = mtrnuml*2 */
/*      end if */
    r__1 = readin_(lineq, &iccount, &nline, (ftnlen)128);
    *mtrnmp = i_nint(&r__1);
    r__1 = readin_(lineq, &iccount, &nline, (ftnlen)128);
    *mtrdnp = i_nint(&r__1);
    *xmtrnum0 = readin_(lineq, &iccount, &nline, (ftnlen)128);

/*  Original key sig (before any trnasposition) in next position.  Transposed */
/*  sig for topfile was transferred thru pmxtex.dat.  Need isig0 for key */
/*  changes if transposed. */

    r__1 = readin_(lineq, &iccount, &nline, (ftnlen)128);
    *isig0 = i_nint(&r__1);
    r__1 = readin_(lineq, &iccount, &nline, (ftnlen)128);
    *npages = i_nint(&r__1);
    r__1 = readin_(lineq, &iccount, &nline, (ftnlen)128);
    *nsyst = i_nint(&r__1);
    r__1 = readin_(lineq, &iccount, &nline, (ftnlen)128);
    *musicsize = i_nint(&r__1);
    *fracindent = readin_(lineq, &iccount, &nline, (ftnlen)128);

/*  Next noinst non-comment lines are names of instruments. */

    i__1 = *noinst;
    for (i__ = 1; i__ <= i__1; ++i__) {
L5:
	getbuf_(inameq + i__ * 79, (ftnlen)79);
	if (*(unsigned char *)&inameq[i__ * 79] == '%') {
	    goto L5;
	}
/* L4: */
    }

/*  Mext non-comment line has nv clef names */

L6:
    getbuf_(lineq, (ftnlen)128);
    if (*(unsigned char *)lineq == '%') {
	goto L6;
    }
    iv = 0;
    nvsofar = 0;
    i__1 = *noinst;
    for (jinst = 1; jinst <= i__1; ++jinst) {
	nvsofar += comnvi_1.nsperi[jinst - 1];
	i__2 = comnvi_1.nsperi[jinst - 1];
	for (ivi = 1; ivi <= i__2; ++ivi) {
	    ++iv;
	    *(unsigned char *)&clefq[iv] = *(unsigned char *)&lineq[iv - 1];
	    if (iv == nvsofar) {
		*(unsigned char *)&sepsymq[iv] = '&';
	    } else {
		*(unsigned char *)&sepsymq[iv] = '|';
	    }
/* L10: */
	}
/* L1: */
    }

/*  Mext non-comment line has path name */

L8:
    getbuf_(pathnameq, (ftnlen)40);
    if (*(unsigned char *)pathnameq == '%') {
	goto L8;
    }
    *lpath = i_indx(pathnameq, " ", (ftnlen)40, (ftnlen)1) - 1;
    return 0;
} /* getset_ */

doublereal readin_(lineq, iccount, nline, lineq_len)
char *lineq;
integer *iccount, *nline;
ftnlen lineq_len;
{
    /* System generated locals */
    address a__1[3];
    integer i__1[3];
    real ret_val;
    char ch__1[27], ch__2[6], ch__3[1];
    icilist ici__1;

    /* Builtin functions */
    integer i_indx(), s_wsle();
    /* Subroutine */ int s_cat();
    integer do_lio(), e_wsle();
    /* Subroutine */ int s_stop();
    integer s_rsfi(), do_fio(), e_rsfi();

    /* Local variables */
    static integer i1, i2, icf;
    extern /* Character */ VOID chax_();
    static char durq[1];
    extern /* Subroutine */ int getbuf_(), getchar_();

    /* Fortran I/O blocks */
    static cilist io___1171 = { 0, 6, 0, 0, 0 };



/*  Reads a piece of setup data from file lineq, gets a new lineq from */
/*  file 10 (jobname.pmx) and increments nline if needed,  passes over */
/*  comment lines */

L4:
    if (*iccount == 128) {
L1:
	getbuf_(lineq, (ftnlen)128);
	++(*nline);
	if (*(unsigned char *)lineq == '%') {
	    goto L1;
	}
	*iccount = 0;
    }
    ++(*iccount);

/*  Find next non-blank or end of line */

    for (*iccount = *iccount; *iccount <= 127; ++(*iccount)) {
	if (*(unsigned char *)&lineq[*iccount - 1] != ' ') {
	    goto L3;
	}
/* L2: */
    }

/*  If here, need to get a new line */

    *iccount = 128;
    goto L4;
L3:

/*  iccount now points to start of number to read */

    i1 = *iccount;
L5:
    getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);

/*  Remember that getchar increments iccount, then reads a character. */

    if (i_indx("0123456789.-", durq, (ftnlen)12, (ftnlen)1) > 0) {
	goto L5;
    }
    i2 = *iccount - 1;
    if (i2 < i1) {
	s_wsle(&io___1171);
/* Writing concatenation */
	i__1[0] = 7, a__1[0] = "Found \"";
	i__1[1] = 1, a__1[1] = durq;
	i__1[2] = 19, a__1[2] = "\" instead of number";
	s_cat(ch__1, a__1, i__1, &c__3, (ftnlen)27);
	do_lio(&c__9, &c__1, ch__1, (ftnlen)27);
	e_wsle();
	s_stop("1", (ftnlen)1);
    }
    icf = i2 - i1 + 49;
    ici__1.icierr = 0;
    ici__1.iciend = 0;
    ici__1.icirnum = 1;
    ici__1.icirlen = i2 - (i1 - 1);
    ici__1.iciunit = lineq + (i1 - 1);
/* Writing concatenation */
    i__1[0] = 2, a__1[0] = "(f";
    chax_(ch__3, (ftnlen)1, &icf);
    i__1[1] = 1, a__1[1] = ch__3;
    i__1[2] = 3, a__1[2] = ".0)";
    ici__1.icifmt = (s_cat(ch__2, a__1, i__1, &c__3, (ftnlen)6), ch__2);
    s_rsfi(&ici__1);
    do_fio(&c__1, (char *)&ret_val, (ftnlen)sizeof(real));
    e_rsfi();
    return ret_val;
} /* readin_ */

/* Subroutine */ int moveln_(iuin, iuout, done)
integer *iuin, *iuout;
logical *done;
{
    /* System generated locals */
    integer i__1;

    /* Builtin functions */
    integer s_rsfe(), do_fio(), e_rsfe(), s_wsfe(), e_wsfe();

    /* Local variables */
    extern integer llen_();
    static char outq[129];
    static integer lenout;

    /* Fortran I/O blocks */
    static cilist io___1173 = { 0, 0, 1, "(a)", 0 };
    static cilist io___1176 = { 0, 0, 0, "(a)", 0 };


    *done = FALSE_;
    io___1173.ciunit = *iuin;
    i__1 = s_rsfe(&io___1173);
    if (i__1 != 0) {
	goto L1;
    }
    i__1 = do_fio(&c__1, outq, (ftnlen)129);
    if (i__1 != 0) {
	goto L1;
    }
    i__1 = e_rsfe();
    if (i__1 != 0) {
	goto L1;
    }
    lenout = llen_(outq, &c__129, (ftnlen)129);
    io___1176.ciunit = *iuout;
    s_wsfe(&io___1176);
    do_fio(&c__1, outq, lenout);
    e_wsfe();
    return 0;
L1:
    *done = TRUE_;
    return 0;
} /* moveln_ */

/* Subroutine */ int putarp_(tnow, iv, nolev, ncm, soutq, lsout, soutq_len)
real *tnow;
integer *iv, *nolev, *ncm;
char *soutq;
integer *lsout;
ftnlen soutq_len;
{
    /* Initialized data */

    static char symq[8*2+1] = "raisearparpeggio";

    /* System generated locals */
    address a__1[3], a__2[2];
    integer i__1, i__2[3], i__3[2], i__4;
    real r__1;
    char ch__1[1], ch__2[1], ch__3[80];
    icilist ici__1;

    /* Builtin functions */
    integer i_nint(), s_wsle(), do_lio(), e_wsle(), s_wsfe(), do_fio(), 
	    e_wsfe();
    /* Subroutine */ int s_cat();
    integer s_wsfi(), e_wsfi();

    /* Local variables */
    extern /* Character */ VOID chax_();
    static integer iarp, isym, lnote;
    extern /* Subroutine */ int addstr_();
    static integer levbot, ilvert, invert;
    static char notexq[79];

    /* Fortran I/O blocks */
    static cilist io___1181 = { 0, 6, 0, 0, 0 };
    static cilist io___1182 = { 0, 6, 0, "(f5.1,5i5)", 0 };
    static icilist io___1187 = { 0, notexq+10, 0, "(i2,a1)", 3, 1 };
    static icilist io___1188 = { 0, notexq+10, 0, "(i3,a1)", 4, 1 };



/*  Find which iarp, if any */

    i__1 = comarp_1.narp;
    for (iarp = 1; iarp <= i__1; ++iarp) {
	if ((r__1 = *tnow - comarp_1.itar[iarp - 1], dabs(r__1)) < 
		comtol_1.tol) {
	    goto L2;
	}
/* L1: */
    }

/*  If here, this is the *first* call for this arp. */

    ++comarp_1.narp;
    comarp_1.itar[comarp_1.narp - 1] = *tnow + comtol_1.tol;
    comarp_1.ivar1[comarp_1.narp - 1] = *iv;
    comarp_1.levar1[comarp_1.narp - 1] = *nolev;
    comarp_1.ncmar1[comarp_1.narp - 1] = *ncm;
    return 0;
L2:

/*  If here, this is second call at this time, iarp points to values from 1st. */

    if (*iv == comarp_1.ivar1[iarp - 1]) {

/*  Arp is in a single staff. */

/* Computing MIN */
	i__1 = comarp_1.levar1[iarp - 1];
	levbot = min(i__1,*nolev) - *ncm + 3;
	invert = (i__1 = comarp_1.levar1[iarp - 1] - *nolev, abs(i__1)) + 1;
    } else {

/*  Arp covers >1 staff.  Lower staff has to be the first, upper is current and */
/*  is where the symbol will be written. */

/*        levbot = -ni(2*xinsnow)+3+levar1(iarp)-ncmar1(iarp) */
	r__1 = comarp_1.xinsnow * 2;
	levbot = -i_nint(&r__1) + 3 + comarp_1.levar1[iarp - 1] - 
		comarp_1.ncmar1[iarp - 1];
	invert = -levbot + 4 + *nolev - *ncm;
	s_wsle(&io___1181);
	do_lio(&c__9, &c__1, "xinsnow,levar1,ncmar1,levbot,nolev,ncm:", (
		ftnlen)39);
	e_wsle();
	s_wsfe(&io___1182);
	do_fio(&c__1, (char *)&comarp_1.xinsnow, (ftnlen)sizeof(real));
	do_fio(&c__1, (char *)&comarp_1.levar1[iarp - 1], (ftnlen)sizeof(
		integer));
	do_fio(&c__1, (char *)&comarp_1.ncmar1[iarp - 1], (ftnlen)sizeof(
		integer));
	do_fio(&c__1, (char *)&levbot, (ftnlen)sizeof(integer));
	do_fio(&c__1, (char *)&(*nolev), (ftnlen)sizeof(integer));
	do_fio(&c__1, (char *)&(*ncm), (ftnlen)sizeof(integer));
	e_wsfe();
    }

/*  isym will be (1,2) if invert is (even,odd).  If even, raise .5\internote */

    isym = invert % 2 + 1;
    ilvert = (invert + 1) / 2;
    if (levbot >= 0 && levbot <= 9) {

/*  Single digit */

/* Writing concatenation */
	chax_(ch__1, (ftnlen)1, &c__92);
	i__2[0] = 1, a__1[0] = ch__1;
	i__2[1] = 8, a__1[1] = symq + (isym - 1 << 3);
	i__1 = levbot + 48;
	chax_(ch__2, (ftnlen)1, &i__1);
	i__2[2] = 1, a__1[2] = ch__2;
	s_cat(notexq, a__1, i__2, &c__3, (ftnlen)79);
	lnote = 10;
    } else {
/* Writing concatenation */
	chax_(ch__1, (ftnlen)1, &c__92);
	i__2[0] = 1, a__1[0] = ch__1;
	i__2[1] = 8, a__1[1] = symq + (isym - 1 << 3);
	i__2[2] = 1, a__1[2] = "{";
	s_cat(notexq, a__1, i__2, &c__3, (ftnlen)79);
	if (levbot >= -9) {

/*  Need two spaces for number */

	    s_wsfi(&io___1187);
	    do_fio(&c__1, (char *)&levbot, (ftnlen)sizeof(integer));
	    do_fio(&c__1, "}", (ftnlen)1);
	    e_wsfi();
	    lnote = 13;
	} else {
	    s_wsfi(&io___1188);
	    do_fio(&c__1, (char *)&levbot, (ftnlen)sizeof(integer));
	    do_fio(&c__1, "}", (ftnlen)1);
	    e_wsfi();
	    lnote = 14;
	}
    }
    if (ilvert <= 9) {
/* Writing concatenation */
	i__3[0] = lnote, a__2[0] = notexq;
	i__1 = ilvert + 48;
	chax_(ch__1, (ftnlen)1, &i__1);
	i__3[1] = 1, a__2[1] = ch__1;
	s_cat(ch__3, a__2, i__3, &c__2, (ftnlen)80);
	i__4 = lnote + 1;
	addstr_(ch__3, &i__4, soutq, lsout, lnote + 1, (ftnlen)80);
    } else {
	i__1 = lnote;
	ici__1.icierr = 0;
	ici__1.icirnum = 1;
	ici__1.icirlen = lnote + 4 - i__1;
	ici__1.iciunit = notexq + i__1;
	ici__1.icifmt = "(a1,i2,a1)";
	s_wsfi(&ici__1);
	do_fio(&c__1, "{", (ftnlen)1);
	do_fio(&c__1, (char *)&ilvert, (ftnlen)sizeof(integer));
	do_fio(&c__1, "}", (ftnlen)1);
	e_wsfi();
	i__1 = lnote + 4;
	addstr_(notexq, &i__1, soutq, lsout, lnote + 4, (ftnlen)80);
    }

/*  cancel out the stored time, to permit two arps at same time! */

    comarp_1.itar[iarp - 1] = -1;
    return 0;
} /* putarp_ */

/* Subroutine */ int chkarp_(found1, ncrd, icrdat, icrdot, ivx, ip, isacc, 
	isarp, icashft)
logical *found1;
integer *ncrd, *icrdat, *icrdot, *ivx, *ip;
logical *isacc, *isarp;
integer *icashft;
{
    /* System generated locals */
    integer i__1, i__2, i__3;

    /* Builtin functions */
    integer lbit_shift();

    /* Local variables */
    static integer icrd, irshft;
    extern integer igetbits_();

    /* Parameter adjustments */
    --icrdot;
    --icrdat;

    /* Function Body */
    *found1 = FALSE_;

/*  icashft will be max left shift of accid's in chord notes. */
/*  Used only for spacing checks. */
/*  Will include left shift of chord note itself. */
/*  Rezero after use. */

    i__1 = *ncrd;
    for (icrd = 1; icrd <= i__1; ++icrd) {

/*  This if block cycles thru all chord notes on ivx,ip; then returns. */

	if ((255 & icrdat[icrd]) == *ip && (15 & lbit_shift(icrdat[icrd], (
		ftnlen)-8)) == *ivx) {
	    *found1 = TRUE_;
/*          isacc = isacc .or. btest(icrdat(icrd),19) */
	    if (bit_test(icrdat[icrd],19)) {

/*  Accid on this chord note */

		*isacc = TRUE_;
		irshft = igetbits_(&icrdot[icrd], &c__7, &c__20);

/*  Include increment for notehead shift */

		if (bit_test(icrdat[icrd],23)) {
		    if (irshft == 0) {
			irshft = 44;
		    } else {
			irshft += -20;
		    }
		}
		if (irshft != 0) {

/*  Accid on chord note is shifted.  Include only left shift, in 20ths. */

		    if (irshft < 64) {
/* Computing MAX */
			i__2 = *icashft, i__3 = 64 - irshft;
			*icashft = max(i__2,i__3);
		    }
		}
	    }
	    *isarp = *isarp || bit_test(icrdat[icrd],25);
	} else if (*found1) {
	    return 0;
	}
/* L18: */
    }
    return 0;
} /* chkarp_ */

/* Subroutine */ int putshft_(ivx, onoff, soutq, lsout, soutq_len)
integer *ivx;
logical *onoff;
char *soutq;
integer *lsout;
ftnlen soutq_len;
{
    /* System generated locals */
    address a__1[3], a__2[4];
    integer i__1[3], i__2, i__3[4];
    real r__1;
    char ch__1[1], ch__2[6], ch__3[88];
    icilist ici__1;

    /* Builtin functions */
    double r_sign();
    /* Subroutine */ int s_cat();
    integer s_wsfi(), do_fio(), e_wsfi();

    /* Local variables */
    static char sq[1];
    extern /* Character */ VOID chax_();
    static integer ifmt;
    static real xoff;
    extern /* Subroutine */ int addstr_();
    static char notexq[80];

    chax_(ch__1, (ftnlen)1, &c__92);
    *(unsigned char *)sq = *(unsigned char *)&ch__1[0];

/*  Start user-defined offsets X(...): or X(...)S */

    if (*onoff) {
	++comudsp_1.nudoff[*ivx - 1];
    }

/*  Xoff is in pts.  Round off to nearest .1.  Will use at end of shift. */

    xoff = comudsp_1.udoff[*ivx + comudsp_1.nudoff[*ivx - 1] * 15 - 16];
    r__1 = (integer) (dabs(xoff) * (float)10. + (float).5) / (float)10.;
    xoff = r_sign(&r__1, &xoff);
    if (! (*onoff)) {
	xoff = -xoff;
    }
    if (xoff < (float)-9.95) {
	ifmt = 5;
    } else if (xoff < (float)-.95 || xoff > (float)9.95) {
	ifmt = 4;
    } else {
	ifmt = 3;
    }
    ici__1.icierr = 0;
    ici__1.icirnum = 1;
    ici__1.icirlen = 80;
    ici__1.iciunit = notexq;
/* Writing concatenation */
    i__1[0] = 2, a__1[0] = "(f";
    i__2 = ifmt + 48;
    chax_(ch__1, (ftnlen)1, &i__2);
    i__1[1] = 1, a__1[1] = ch__1;
    i__1[2] = 3, a__1[2] = ".1)";
    ici__1.icifmt = (s_cat(ch__2, a__1, i__1, &c__3, (ftnlen)6), ch__2);
    s_wsfi(&ici__1);
    do_fio(&c__1, (char *)&xoff, (ftnlen)sizeof(real));
    e_wsfi();
/* Writing concatenation */
    i__3[0] = 1, a__2[0] = sq;
    i__3[1] = 4, a__2[1] = "off{";
    i__3[2] = ifmt, a__2[2] = notexq;
    i__3[3] = 3, a__2[3] = "pt}";
    s_cat(ch__3, a__2, i__3, &c__4, (ftnlen)88);
    i__2 = ifmt + 8;
    addstr_(ch__3, &i__2, soutq, lsout, ifmt + 8, (ftnlen)80);
    return 0;
} /* putshft_ */

/* Subroutine */ int outbar_(i__, jlast)
integer *i__, *jlast;
{
    /* System generated locals */
    address a__1[3];
    integer i__1[3], i__2;
    real r__1;
    char ch__1[9], ch__2[1], ch__3[11];
    cilist ci__1;

    /* Builtin functions */
    double r_lg10();
    /* Subroutine */ int s_cat();
    integer s_wsfe(), do_fio(), e_wsfe();

    /* Local variables */
    extern /* Character */ VOID chax_();
    static integer nfmt;

    r__1 = *i__ + (float).5;
    nfmt = r_lg10(&r__1) + 2;
    if (*jlast + 5 + nfmt < 80) {
	ci__1.cierr = 0;
	ci__1.ciunit = 6;
/* Writing concatenation */
	i__1[0] = 5, a__1[0] = "(a5,i";
	i__2 = nfmt + 48;
	chax_(ch__2, (ftnlen)1, &i__2);
	i__1[1] = 1, a__1[1] = ch__2;
	i__1[2] = 3, a__1[2] = ",$)";
	ci__1.cifmt = (s_cat(ch__1, a__1, i__1, &c__3, (ftnlen)9), ch__1);
	s_wsfe(&ci__1);
	do_fio(&c__1, "  Bar", (ftnlen)5);
	do_fio(&c__1, (char *)&(*i__), (ftnlen)sizeof(integer));
	e_wsfe();
	ci__1.cierr = 0;
	ci__1.ciunit = 15;
/* Writing concatenation */
	i__1[0] = 5, a__1[0] = "(a5,i";
	i__2 = nfmt + 48;
	chax_(ch__2, (ftnlen)1, &i__2);
	i__1[1] = 1, a__1[1] = ch__2;
	i__1[2] = 3, a__1[2] = ",$)";
	ci__1.cifmt = (s_cat(ch__1, a__1, i__1, &c__3, (ftnlen)9), ch__1);
	s_wsfe(&ci__1);
	do_fio(&c__1, "  Bar", (ftnlen)5);
	do_fio(&c__1, (char *)&(*i__), (ftnlen)sizeof(integer));
	e_wsfe();
	*jlast = *jlast + 5 + nfmt;
    } else {
	ci__1.cierr = 0;
	ci__1.ciunit = 6;
/* Writing concatenation */
	i__1[0] = 7, a__1[0] = "(/,a5,i";
	i__2 = nfmt + 48;
	chax_(ch__2, (ftnlen)1, &i__2);
	i__1[1] = 1, a__1[1] = ch__2;
	i__1[2] = 3, a__1[2] = ",$)";
	ci__1.cifmt = (s_cat(ch__3, a__1, i__1, &c__3, (ftnlen)11), ch__3);
	s_wsfe(&ci__1);
	do_fio(&c__1, "  Bar", (ftnlen)5);
	do_fio(&c__1, (char *)&(*i__), (ftnlen)sizeof(integer));
	e_wsfe();
	ci__1.cierr = 0;
	ci__1.ciunit = 15;
/* Writing concatenation */
	i__1[0] = 7, a__1[0] = "(/,a5,i";
	i__2 = nfmt + 48;
	chax_(ch__2, (ftnlen)1, &i__2);
	i__1[1] = 1, a__1[1] = ch__2;
	i__1[2] = 3, a__1[2] = ",$)";
	ci__1.cifmt = (s_cat(ch__3, a__1, i__1, &c__3, (ftnlen)11), ch__3);
	s_wsfe(&ci__1);
	do_fio(&c__1, "  Bar", (ftnlen)5);
	do_fio(&c__1, (char *)&(*i__), (ftnlen)sizeof(integer));
	e_wsfe();
	*jlast = nfmt + 5;
    }
    return 0;
} /* outbar_ */

/* Subroutine */ int dotmov_(updot, rtdot, soutq, lsout, iddot, soutq_len)
real *updot, *rtdot;
char *soutq;
integer *lsout, *iddot;
ftnlen soutq_len;
{
    /* System generated locals */
    address a__1[5], a__2[8], a__3[5];
    integer i__1[5], i__2, i__3, i__4[8], i__5[5], i__6;
    char ch__1[1], ch__2[22], ch__3[1], ch__4[37], ch__5[15], ch__6[1];
    icilist ici__1;

    /* Builtin functions */
    /* Subroutine */ int s_cat();
    integer s_wsfi(), do_fio(), e_wsfi();

    /* Local variables */
    static char sq[1];
    extern /* Character */ VOID chax_();
    extern integer lfmt1_();
    static integer lnote;
    extern /* Subroutine */ int addstr_();
    static integer lfmtup, lfmtrt;
    static char notexq[80];


/*  iddot = 0 for single dot, 1 for double */

    chax_(ch__1, (ftnlen)1, &c__92);
    *(unsigned char *)sq = *(unsigned char *)&ch__1[0];
    lfmtup = lfmt1_(updot);
    lfmtrt = lfmt1_(rtdot);
    ici__1.icierr = 0;
    ici__1.icirnum = 1;
    ici__1.icirlen = 80;
    ici__1.iciunit = notexq;
/* Writing concatenation */
    i__1[0] = 6, a__1[0] = "(a37,f";
    i__2 = lfmtup + 48;
    chax_(ch__1, (ftnlen)1, &i__2);
    i__1[1] = 1, a__1[1] = ch__1;
    i__1[2] = 7, a__1[2] = ".1,a2,f";
    i__3 = lfmtrt + 48;
    chax_(ch__3, (ftnlen)1, &i__3);
    i__1[3] = 1, a__1[3] = ch__3;
    i__1[4] = 7, a__1[4] = ".1,a15)";
    ici__1.icifmt = (s_cat(ch__2, a__1, i__1, &c__5, (ftnlen)22), ch__2);
    s_wsfi(&ici__1);
/* Writing concatenation */
    i__4[0] = 1, a__2[0] = sq;
    i__4[1] = 12, a__2[1] = "makeatletter";
    i__4[2] = 1, a__2[2] = sq;
    i__4[3] = 3, a__2[3] = "def";
    i__4[4] = 1, a__2[4] = sq;
    i__4[5] = 12, a__2[5] = "C@Point#1#2{";
    i__4[6] = 1, a__2[6] = sq;
    i__4[7] = 6, a__2[7] = "PMXpt{";
    s_cat(ch__4, a__2, i__4, &c__8, (ftnlen)37);
    do_fio(&c__1, ch__4, (ftnlen)37);
    do_fio(&c__1, (char *)&(*updot), (ftnlen)sizeof(real));
    do_fio(&c__1, "}{", (ftnlen)2);
    do_fio(&c__1, (char *)&(*rtdot), (ftnlen)sizeof(real));
/* Writing concatenation */
    i__5[0] = 1, a__3[0] = "}";
    i__6 = *iddot + 48;
    chax_(ch__6, (ftnlen)1, &i__6);
    i__5[1] = 1, a__3[1] = ch__6;
    i__5[2] = 1, a__3[2] = "}";
    i__5[3] = 1, a__3[3] = sq;
    i__5[4] = 11, a__3[4] = "makeatother";
    s_cat(ch__5, a__3, i__5, &c__5, (ftnlen)15);
    do_fio(&c__1, ch__5, (ftnlen)15);
    e_wsfi();

/*   Example of string just created: */
/*   \makeatletter\def\C@Point#1#2{\PMXpt{.5}{.5}}\makeatother\ */

    lnote = lfmtup + 54 + lfmtrt;
    addstr_(notexq, &lnote, soutq, lsout, lnote, (ftnlen)80);
    return 0;
} /* dotmov_ */

integer lfmt1_(x)
real *x;
{
    /* System generated locals */
    integer ret_val;
    real r__1;

    /* Builtin functions */
    double r_sign(), r_lg10();

    /* Local variables */
    static real y;


/*  Computes total length of an "f" format with one decimal place. */
/*  First round to nearest 0.1 */

    if (dabs(*x) < (float).001) {
	ret_val = 2;
    } else {
	r__1 = (integer) (dabs(*x) * 10 + (float).5) * (float).1;
	y = r_sign(&r__1, x);
	r__1 = dabs(y) * 1000 + (float).001;
	ret_val = (integer) r_lg10(&r__1);
	if (y < (float)0.) {
	    ++ret_val;
	}
    }
    return ret_val;
} /* lfmt1_ */

/* Subroutine */ int getorn_(lineq, iccount, iornq, iornq0, ornrpt, noffseg, 
	ip, ivx, noxtup, notcrd, nole, lineq_len)
char *lineq;
integer *iccount, *iornq, *iornq0;
logical *ornrpt;
integer *noffseg, *ip, *ivx;
logical *noxtup, *notcrd;
integer *nole;
ftnlen lineq_len;
{
    /* System generated locals */
    real r__1;

    /* Builtin functions */
    integer i_indx(), s_wsle(), do_lio(), e_wsle();
    /* Subroutine */ int s_stop();
    integer i_nint();

    /* Local variables */
    static real fnum;
    static integer korn;
    static char durq[1], charq[1];
    static integer iorni;
    static logical negseg;
    extern /* Subroutine */ int getchar_(), readnum_();
    static integer iofforn;
    static real xofforn;

    /* Fortran I/O blocks */
    static cilist io___1208 = { 0, 6, 0, 0, 0 };



/*  iornq: Main note.  Do not alter if chord note, except turn on bit 23 */
/*  iornq0: Store iorni + bit 23, in case of repeated ornaments */
/*  iorni: Internal use, 1st 21 bits of iornq or icrdorn, dep. on notcrd. */
/*  noffseg: horiz. offset for segno */
/*  nole: level of note w/ orn, used to ID the note/orn if there's a level shift. */


/*  Bits 0-13: (stmgx+Tupf._), 14: Down fermata, was F, 15: Trill w/o "tr", was U */
/*  16-18 Editorial sharp, flat, natural "oes,f,n"; 19-20: >^, 21 TBD */

/*  Set signal on main note that some note at this time has ornament.  ONLY used */
/*  in beamstrt to activate further tests for whether ihornb is needed. */

    *iornq = bit_set(*iornq,23);

/*  Isolate 21 bits defining exisiting ornaments */

    if (*notcrd) {
	iorni = 4194303 & *iornq;
    } else {
	iorni = 4194303 & comtrill_1.icrdorn[comtrill_1.ncrd - 1];
    }
    getchar_(lineq, iccount, charq, (ftnlen)128, (ftnlen)1);
    korn = i_indx("stmgx+Tupf._)e:XXX>^", charq, (ftnlen)20, (ftnlen)1);
    if (korn != 15) {
	iorni = bit_set(iorni,korn);
    }

/*  Note that korn=0 => charq='(', and we set bit 0.  if "e" (14), alter later */
/*    as follows: korn=16-18 for sfn, and or 21 for bare ?. */
/*  When this if-block is done, korn will = bit# of actual ornament (unless "?"). */

    if (korn == 15) {

/* c  Turn off repeated ornament ('o:'), Replicate bits 0-3,5-15,19-20 prev iornq */
/*  Turn off repeated ornament ('o:'), Replicate bits 0-3,5-15,19-21 prev iornq */

/*        iorni = ior(iorni,iand(iornq0,1638383)) */
	iorni |= *iornq0 & 3735535;
	*ornrpt = FALSE_;
	getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);

/*  durq will be ' ' */

    } else if (korn == 14) {

/*  Editorial accidental */

	getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
/*        korn = 15+index('sfn',durq) */
	korn = i_indx("sfn?", durq, (ftnlen)4, (ftnlen)1) + 15;
	if (korn == 19) {
	    korn = 21;
	}
	iorni = bit_set(bit_clear(iorni,14),korn);
	getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	if (*(unsigned char *)durq == '?') {

/*  This is "oe[s|f|n]".  Set 21st bit also. */

	    iorni = bit_set(iorni,21);
	    korn += 6;
	    getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	}
/*        iorni = ibset(ibclr(iorni,14),korn) */
    } else if (korn == 4 && *noxtup) {

/*  segno. Check in pmxa for just 1/block & notcrd.  Get horiz. offset in points */

	*noffseg = 0;
	negseg = FALSE_;
	getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	if (*(unsigned char *)durq != ' ') {

/*  Segno shift is specified */

	    if (*(unsigned char *)durq == '-') {
		negseg = TRUE_;
		getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	    }
	    readnum_(lineq, iccount, durq, &fnum, (ftnlen)128, (ftnlen)1);
	    *noffseg = (integer) fnum;
	    if (negseg) {
		*noffseg = -(*noffseg);
	    }
	}
    } else if (korn == 7) {

/*  Trill.  Check in pmxa for notcrd.  Default is 1 noteskip long, with "tr" */

	++comtrill_1.ntrill;
	comtrill_1.ivtrill[comtrill_1.ntrill - 1] = *ivx;
	comtrill_1.iptrill[comtrill_1.ntrill - 1] = *ip;
	comtrill_1.xnsktr[comtrill_1.ntrill - 1] = (float)1.;
	getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	if (*(unsigned char *)durq == 't') {

/*  Convert to new internal symbol for non-'"tr" trill */

	    korn = 15;
	    iorni = bit_set(bit_clear(iorni,7),15);
	    getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	}
	if (i_indx("0123456789.", durq, (ftnlen)11, (ftnlen)1) > 0) {

/*  We have a number for the length */

	    readnum_(lineq, iccount, durq, &comtrill_1.xnsktr[
		    comtrill_1.ntrill - 1], (ftnlen)128, (ftnlen)1);
	}
    } else if (korn == 10 && *noxtup) {

/*  Fermata */

	getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	if (*(unsigned char *)durq == 'd') {
	    korn = 14;
	    iorni = bit_set(bit_clear(iorni,10),14);
	    getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	}
    } else {
	getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
    }
    if (i_indx("+- :", durq, (ftnlen)4, (ftnlen)1) == 0) {
	s_wsle(&io___1208);
	do_lio(&c__9, &c__1, "Unexpected character at end of ornament: ", (
		ftnlen)41);
	do_lio(&c__9, &c__1, durq, (ftnlen)1);
	e_wsle();
	s_stop("1", (ftnlen)1);
    }
    if (i_indx("+-", durq, (ftnlen)2, (ftnlen)1) > 0) {

/*  Shift ornament up or down */

	++comtrill_1.nudorn;

/*  Set bit 25 in iorni as a signal.  This may not really be necessary. */

	iorni = bit_set(iorni,25);

/*  Assemble info to put in kudorn(nudorn) Bits 0-7:ip, 8-11:ivx, 12-18:nolev, */
/*     19-24: type of ornament to be shifted, 25-30: shift+32 */

	xofforn = (real) (44 - *(unsigned char *)durq);
	++(*iccount);
	readnum_(lineq, iccount, durq, &fnum, (ftnlen)128, (ftnlen)1);
	r__1 = xofforn * fnum;
	iofforn = i_nint(&r__1);
	comtrill_1.kudorn[comtrill_1.nudorn - 1] = *ip + (*ivx << 8) + (*nole 
		<< 12) + (korn << 19) + (iofforn + 32 << 25);
    } else if (*(unsigned char *)durq == ':') {

/*  Turn on repeated ornaments */

	*ornrpt = TRUE_;

/*  Save the ornament value just set */

	*iornq0 = iorni;
    }
    if (*notcrd) {
	*iornq |= iorni;
    } else {
	comtrill_1.icrdorn[comtrill_1.ncrd - 1] |= iorni;
    }
    return 0;
} /* getorn_ */

/*      subroutine report(nsdat,isdat1,isdat2) */
/*      integer*4 isdat1(202),isdat2(202) */
/*      write(*,'(a)') */
/*     *  ' isd on? iv  kv   ip  id ud1 ud2 ndx ivo iho lev crd lhd rhd' */
/*      do 1 isdat = 1 , nsdat */
/*        isdata = isdat1(isdat) */
/*        ionoff = igetbits(isdata,1,11) */
/* c        iv = iand(7,isdata) */
/*        iv = igetbits(isdata,5,13) */
/*        kv = igetbits(isdata,1,12)+1 */
/*        ip = igetbits(isdata,8,3) */
/*        idcode = igetbits(isdata,7,19) */
/*        iud1 = igetbits(isdata,1,26) */
/*        iud2 = igetbits(isdata,1,27) */
/*        ndxslur = igetbits(isdata,4,28) */
/*        isdatb = isdat2(isdat) */
/*        ivo = igetbits(isdatb,6,6)-32 */
/*        iho = igetbits(isdatb,7,12)-64 */
/*        lev = igetbits(isdatb,7,19) */
/*        icrd = igetbits(isdatb,1,0) */
/*        lhd = igetbits(isdatb,1,1) */
/*        irhd = igetbits(isdatb,7,2) */
/*        write(*,'(17i4)')isdat,ionoff,iv,kv,ip,idcode,iud1,iud2,ndxslur, */
/*     *                     ivo,iho,lev,icrd,lhd,irhd */
/* 1     continue */
/*      print* */
/*      return */
/*      end */
integer igetbits_(isdata, iwidbit, ishift)
integer *isdata, *iwidbit, *ishift;
{
    /* System generated locals */
    integer ret_val;

    /* Builtin functions */
    integer pow_ii(), lbit_shift();


/*  Extracts integer given by iwidbit bits of isdata, shifted by ishift, and */
/*  then added to ioff */

    ret_val = pow_ii(&c__2, iwidbit) - 1 & lbit_shift(*isdata, -(*ishift));
    return ret_val;
} /* igetbits_ */

/* Subroutine */ int setbits_(isdata, iwidbit, ishift, ivalue)
integer *isdata, *iwidbit, *ishift, *ivalue;
{
    /* Builtin functions */
    integer pow_ii(), s_wsle(), e_wsle(), do_lio(), s_wsfe(), do_fio(), 
	    e_wsfe(), lbit_shift();

    /* Local variables */
    static integer ibase;

    /* Fortran I/O blocks */
    static cilist io___1212 = { 0, 6, 0, 0, 0 };
    static cilist io___1213 = { 0, 6, 0, 0, 0 };
    static cilist io___1214 = { 0, 15, 0, "(/,a)", 0 };



/*  Sets iwidbits of isdata, shifted by ishift, to ivalue */

    ibase = pow_ii(&c__2, iwidbit) - 1;
    if (*ivalue > ibase) {
	s_wsle(&io___1212);
	e_wsle();
	s_wsle(&io___1213);
	do_lio(&c__9, &c__1, "WARNING in setbits: ivalue > ibase", (ftnlen)34)
		;
	e_wsle();
	s_wsfe(&io___1214);
	do_fio(&c__1, "WARNING in setbits: ivalue > ibase", (ftnlen)34);
	e_wsfe();
    }
    *isdata = ~ lbit_shift(ibase, *ishift) & *isdata;
    *isdata |= lbit_shift(*ivalue, *ishift);
    return 0;
} /* setbits_ */

/* Subroutine */ int precrd_(ivx, ip, nolevm)
integer *ivx, *ip, *nolevm;
{
    /* System generated locals */
    integer i__1;

    /* Builtin functions */
    integer lbit_shift(), s_wsle(), e_wsle(), do_lio();
    /* Subroutine */ int s_stop();

    /* Local variables */
    static integer nolev;
    extern integer igetbits_();

    /* Fortran I/O blocks */
    static cilist io___1215 = { 0, 6, 0, 0, 0 };
    static cilist io___1216 = { 0, 6, 0, 0, 0 };
    static cilist io___1218 = { 0, 6, 0, 0, 0 };
    static cilist io___1219 = { 0, 6, 0, 0, 0 };



/*  Analyzes chords, data to be used with slurs on chords and plain chords. */

    i__1 = comtrill_1.ncrd;
    for (comtrill_1.icrd1 = 1; comtrill_1.icrd1 <= i__1; ++comtrill_1.icrd1) {
	if ((255 & comtrill_1.icrdat[comtrill_1.icrd1 - 1]) == *ip && (15 & 
		lbit_shift(comtrill_1.icrdat[comtrill_1.icrd1 - 1], (ftnlen)
		-8)) == *ivx) {
	    goto L2;
	}
/* L1: */
    }
    s_wsle(&io___1215);
    e_wsle();
    s_wsle(&io___1216);
    do_lio(&c__9, &c__1, "Failed to find first chord note!", (ftnlen)32);
    e_wsle();
    s_stop("", (ftnlen)0);
L2:
    comtrill_1.maxlev = *nolevm;
    comtrill_1.minlev = *nolevm;
    i__1 = comtrill_1.ncrd;
    for (comtrill_1.icrd2 = comtrill_1.icrd1; comtrill_1.icrd2 <= i__1; 
	    ++comtrill_1.icrd2) {

/*  Exit loop if last note in this chord */

	nolev = igetbits_(&comtrill_1.icrdat[comtrill_1.icrd2 - 1], &c__7, &
		c__12);
	comtrill_1.maxlev = max(comtrill_1.maxlev,nolev);
	comtrill_1.minlev = min(comtrill_1.minlev,nolev);
	if (comtrill_1.icrd2 == comtrill_1.ncrd) {
	    goto L4;
	}
	if (igetbits_(&comtrill_1.icrdat[comtrill_1.icrd2], &c__8, &c__0) != *
		ip || igetbits_(&comtrill_1.icrdat[comtrill_1.icrd2], &c__4, &
		c__8) != *ivx) {
	    goto L4;
	}
/* L3: */
    }
    s_wsle(&io___1218);
    e_wsle();
    s_wsle(&io___1219);
    do_lio(&c__9, &c__1, "Failed to find last chord note!", (ftnlen)31);
    e_wsle();
    s_stop("", (ftnlen)0);
L4:

/*  Now icrd1, icrd2 define range of icrd for this chord. */

    return 0;
} /* precrd_ */

integer lenstr_(string, n, string_len)
char *string;
integer *n;
ftnlen string_len;
{
    /* System generated locals */
    integer ret_val;

    for (ret_val = *n; ret_val >= 1; --ret_val) {
	if (*(unsigned char *)&string[ret_val - 1] != ' ') {
	    return ret_val;
	}
/* L1: */
    }
    ret_val = 0;
    return ret_val;
} /* lenstr_ */

/* Subroutine */ int newvoice_(jv, clefq, change, clefq_len)
integer *jv;
char *clefq;
logical *change;
ftnlen clefq_len;
{
    static integer j;
    extern integer ncmidf_();

    commvl_1.nvmx[*jv - 1] = 1;
    commvl_1.ivmx[*jv - 1] = *jv;
    all_1.itsofar[*jv - 1] = 0;
    all_1.nnl[*jv - 1] = 0;
    comfb_1.nfb[*jv - 1] = 0;
    if (all_1.firstgulp || *change) {
	comcc_1.ncmidcc[*jv - 1] = ncmidf_(clefq, (ftnlen)1);
    } else {
	comcc_1.ncmidcc[*jv - 1] = comcc_1.ncmidcc[*jv + comcc_1.ncc[*jv - 1] 
		* 15 - 16];
    }
    comcc_1.tcc[*jv - 1] = (float)0.;
    comcc_1.ncc[*jv - 1] = 1;
    comudsp_1.nudoff[*jv - 1] = 0;
    comcc_1.ndotmv[*jv - 1] = 0;
    for (j = 1; j <= 200; ++j) {
	all_1.irest[*jv + j * 15 - 16] = 0;
	all_1.islur[*jv + j * 15 - 16] = 0;
	all_1.ipl[*jv + j * 15 - 16] = 0;
	all_1.nacc[*jv + j * 15 - 16] = 0;
	all_1.iornq[*jv + j * 15 - 1] = 0;
	if (*jv == 1) {
	    all_1.isfig[j - 1] = FALSE_;
	}
/* L5: */
    }
    return 0;
} /* newvoice_ */

/* Subroutine */ int chkpm4ac_(lineq, iccount, nacc, moved, lineq_len)
char *lineq;
integer *iccount, *nacc;
logical *moved;
ftnlen lineq_len;
{
    /* System generated locals */
    integer i__1, i__2;

    /* Builtin functions */
    integer i_indx(), s_cmp();

    /* Local variables */
    static integer ipm;
    static real fnum;
    static char durq[1];
    static integer icsav;
    static logical ishorz;
    extern /* Subroutine */ int readnum_(), setbits_();


/*  Called after getting +/-/</> in a note (not rest).  iccount is on the +-<>. */
/*  Sets moved=.true. and sets move parameters in nacc if necc: horiz only (bits */
/*    10-16) if < or >,  horiz and vert (bits 4-9) if two consecutive signed */
/*    numbers.  If moved=.true., iccount on exit is on end of last number. */
/*    If moved=.false., iccount still on +/- */

    i__1 = *iccount - 2;
    i__2 = *iccount;
    if (i_indx("sfn", lineq + i__1, (ftnlen)3, *iccount - 1 - i__1) > 0 && 
	    i_indx("0123456789.", lineq + i__2, (ftnlen)11, *iccount + 1 - 
	    i__2) > 0) {

/*  Prior char was accid & next is #; this may be start of accidental shift. */
/*  Must test for "." above in case we get "<" or ">" */

	ipm = i_indx("- +< >", lineq + (*iccount - 1), (ftnlen)6, (ftnlen)1) 
		- 2;
	i__1 = *iccount + 1;
	i__2 = *iccount;
	if (s_cmp(lineq + i__2, ".", *iccount + 1 - i__2, (ftnlen)1) == 0 && 
		i_indx("0123456789", lineq + i__1, (ftnlen)10, *iccount + 2 - 
		i__1) == 0) {

/*  Rare case of [accid][+/-].[letter].  Bail out */

	    *moved = FALSE_;
	    return 0;
	}
	ishorz = ipm > 1;

/*  Save iccount in case it's not accid shift and we have to reset. */

	icsav = *iccount;
	++(*iccount);
	readnum_(lineq, iccount, durq, &fnum, (ftnlen)128, (ftnlen)1);
	if (ishorz || i_indx("+-", durq, (ftnlen)2, (ftnlen)1) > 0) {

/*  This has to be accidental shift.  Set vert. shift. */

	    if (! ishorz) {

/*  +/- syntax, both shifts set, vertical first */

		i__1 = (integer) (ipm * fnum + (float)32.5);
		setbits_(nacc, &c__6, &c__4, &i__1);
		ipm = i_indx("- +", durq, (ftnlen)3, (ftnlen)1) - 2;
		++(*iccount);
		readnum_(lineq, iccount, durq, &fnum, (ftnlen)128, (ftnlen)1);
	    } else {

/*  </> syntax, only horiz set */

		ipm += -3;
	    }

/*  Set horiz. shift */

	    i__1 = (integer) ((ipm * fnum + (float)3.22) * 20);
	    setbits_(nacc, &c__7, &c__10, &i__1);
	    --(*iccount);
	    *moved = TRUE_;
	} else {

/*  False alarm.  Reset everything and flow onward */

	    *moved = FALSE_;
	    *iccount = icsav;
	}
    } else {

/* Either prior char was not 'sfn' or next was not digit, so take no action */

	*moved = FALSE_;
    }
    return 0;
} /* chkpm4ac_ */

/* Subroutine */ int doacc_(ihshft, ivshft, lshft, notexq, lnote, nacc, nolev,
	 ncm, notexq_len)
integer *ihshft, *ivshft;
logical *lshft;
char *notexq;
integer *lnote, *nacc, *nolev, *ncm;
ftnlen notexq_len;
{
    /* System generated locals */
    address a__1[2], a__2[3];
    integer i__1[2], i__2[3];
    char ch__1[1];
    icilist ici__1;

    /* Builtin functions */
    /* Subroutine */ int s_cat();
    integer s_wsfi(), do_fio(), e_wsfi();
    /* Subroutine */ int s_copy();

    /* Local variables */
    static char sq[1];
    static integer lacc;
    extern /* Character */ VOID chax_();
    static real hshft;
    static char noteq[8];
    extern /* Subroutine */ int accsym_();
    static integer noleva;
    extern /* Subroutine */ int notefq_();
    static char acsymq[3];
    static integer lnoten;
    extern /* Subroutine */ int addblank_();

    chax_(ch__1, (ftnlen)1, &c__92);
    *(unsigned char *)sq = *(unsigned char *)&ch__1[0];
    if (*ihshft == -64) {
	*ihshft = 0;
    }

/*  If main note shifted left, so shift accid.  Terminate below, when acc. is don */

    if (*lshft) {
	*ihshft += -20;
    }
    if (*ihshft != 0) {

/*  Accid must be shifted horizontally */

	if (*ihshft < 0) {
/* Writing concatenation */
	    i__1[0] = 1, a__1[0] = sq;
	    i__1[1] = 8, a__1[1] = "loffset{";
	    s_cat(notexq, a__1, i__1, &c__2, (ftnlen)79);
	    *ihshft = -(*ihshft);
	} else {
/* Writing concatenation */
	    i__1[0] = 1, a__1[0] = sq;
	    i__1[1] = 8, a__1[1] = "roffset{";
	    s_cat(notexq, a__1, i__1, &c__2, (ftnlen)79);
	}
	hshft = *ihshft * (float).05;
	if (hshft < (float)1.) {
	    ici__1.icierr = 0;
	    ici__1.icirnum = 1;
	    ici__1.icirlen = 3;
	    ici__1.iciunit = notexq + 9;
	    ici__1.icifmt = "(f3.2)";
	    s_wsfi(&ici__1);
	    do_fio(&c__1, (char *)&hshft, (ftnlen)sizeof(real));
	    e_wsfi();
	    *lnote = 12;
	} else {
	    ici__1.icierr = 0;
	    ici__1.icirnum = 1;
	    ici__1.icirlen = 4;
	    ici__1.iciunit = notexq + 9;
	    ici__1.icifmt = "(f4.2)";
	    s_wsfi(&ici__1);
	    do_fio(&c__1, (char *)&hshft, (ftnlen)sizeof(real));
	    e_wsfi();
	    *lnote = 13;
	}
/* Writing concatenation */
	i__2[0] = *lnote, a__2[0] = notexq;
	i__2[1] = 2, a__2[1] = "}{";
	i__2[2] = 1, a__2[2] = sq;
	s_cat(notexq, a__2, i__2, &c__3, (ftnlen)79);
	*lnote += 3;
    } else {
	s_copy(notexq, sq, (ftnlen)79, (ftnlen)1);
	*lnote = 1;
    }
    if (bit_test(*nacc,3)) {
/* Writing concatenation */
	i__1[0] = *lnote, a__1[0] = notexq;
	i__1[1] = 3, a__1[1] = "big";
	s_cat(notexq, a__1, i__1, &c__2, (ftnlen)79);
	*lnote += 3;
    }
    accsym_(nacc, acsymq, &lacc, (ftnlen)3);
/* Writing concatenation */
    i__1[0] = *lnote, a__1[0] = notexq;
    i__1[1] = lacc, a__1[1] = acsymq;
    s_cat(notexq, a__1, i__1, &c__2, (ftnlen)79);
    *lnote += lacc;
    noleva = *nolev;
    if (*ivshft != 0) {
	noleva = noleva + *ivshft - 32;
    }
    notefq_(noteq, &lnoten, &noleva, ncm, (ftnlen)8);
    if (lnoten == 1) {
	addblank_(noteq, &lnoten, (ftnlen)8);
    }
/* Writing concatenation */
    i__1[0] = *lnote, a__1[0] = notexq;
    i__1[1] = lnoten, a__1[1] = noteq;
    s_cat(notexq, a__1, i__1, &c__2, (ftnlen)79);
    *lnote += lnoten;
    if (*ihshft != 0) {

/*  Terminate horizontal shift */

/* Writing concatenation */
	i__1[0] = *lnote, a__1[0] = notexq;
	i__1[1] = 1, a__1[1] = "}";
	s_cat(notexq, a__1, i__1, &c__2, (ftnlen)79);
	++(*lnote);
    }
    return 0;
} /* doacc_ */

/* Subroutine */ int getdyn_(ivx, ip, irest, lineq, iccount, lineq_len)
integer *ivx, *ip, *irest;
char *lineq;
integer *iccount;
ftnlen lineq_len;
{
    /* System generated locals */
    address a__1[3];
    integer i__1, i__2[3], i__3;
    real r__1;
    char ch__1[4], ch__2[1];
    icilist ici__1;

    /* Builtin functions */
    integer i_indx();
    /* Subroutine */ int s_cat();
    integer s_rsfi(), do_fio(), e_rsfi(), i_nint();

    /* Local variables */
    static integer ipm, iend;
    extern /* Character */ VOID chax_();
    static integer idno, idyn;
    static real fnum;
    static char durq[1];
    extern /* Subroutine */ int readnum_(), setbits_();
    static char dynsymq[4];


/*  Get info for dynamic mark.  Enter after getting "D", iccount sits on "D" */
/*  Bits in idyndat are as follows */
/*    00-03 ivx */
/*    04-11 ip */
/*    12-15 code for type of mark */
/*      1-12 => pppp,ppp,pp,p,mp,mf,f,fp,sf,ff,fff,ffff */
/*    16    flag for vertical offset */
/*    17-22 vertical offset + 32 , \internote */
/*    23    flag for horizontal offset */
/*    24-30 (horizontal offset)/10 + 6.4 notehead widths */

    *irest = bit_set(*irest,26);
    ++comdyn_1.ndyn;
    idyn = *ivx;
    setbits_(&idyn, &c__8, &c__4, ip);
    for (iend = *iccount + 2; iend <= 128; ++iend) {
	ipm = i_indx("- +", lineq + (iend - 1), (ftnlen)3, (ftnlen)1);
	if (ipm > 0) {
	    goto L2;
	}
/* L1: */
    }
L2:
    i__1 = *iccount;
    ici__1.icierr = 0;
    ici__1.iciend = 0;
    ici__1.icirnum = 1;
    ici__1.icirlen = iend - 1 - i__1;
    ici__1.iciunit = lineq + i__1;
/* Writing concatenation */
    i__2[0] = 2, a__1[0] = "(a";
    i__3 = iend + 47 - *iccount;
    chax_(ch__2, (ftnlen)1, &i__3);
    i__2[1] = 1, a__1[1] = ch__2;
    i__2[2] = 1, a__1[2] = ")";
    ici__1.icifmt = (s_cat(ch__1, a__1, i__2, &c__3, (ftnlen)4), ch__1);
    s_rsfi(&ici__1);
    do_fio(&c__1, dynsymq, (ftnlen)4);
    e_rsfi();
    idno = (i_indx("ppppppp pp  p   mp  mf  f   fp  sf  ff  fff ffff", 
	    dynsymq, (ftnlen)48, (ftnlen)4) + 3) / 4;
    setbits_(&idyn, &c__4, &c__12, &idno);
    *iccount = iend;
    if (ipm != 2) {

/*  There is a vertical shift */

	idyn = bit_set(idyn,16);
	++(*iccount);
	readnum_(lineq, iccount, durq, &fnum, (ftnlen)128, (ftnlen)1);
	idno = i_nint(&fnum);
	i__1 = (ipm - 2) * idno + 32;
	setbits_(&idyn, &c__6, &c__17, &i__1);
	ipm = i_indx("- +", durq, (ftnlen)3, (ftnlen)1);
	if (ipm != 2) {

/*  There is a horizontal shift */

	    idyn = bit_set(idyn,23);
	    ++(*iccount);
	    readnum_(lineq, iccount, durq, &fnum, (ftnlen)128, (ftnlen)1);
	    r__1 = fnum * 10;
	    idno = i_nint(&r__1);
	    i__1 = (ipm - 2) * idno + 64;
	    setbits_(&idyn, &c__7, &c__24, &i__1);
	}

/*  iccount should be on the blank at the end of the entire symbol */

    }
    comdyn_1.idyndat[comdyn_1.ndyn - 1] = idyn;
    return 0;
} /* getdyn_ */

/* Subroutine */ int dodyn_(ivx, ip, nolev, ncm, ipl, islur, nvmx, nv, beamon,
	 soutq, lsout, soutq_len)
integer *ivx, *ip, *nolev, *ncm, *ipl, *islur, *nvmx, *nv;
logical *beamon;
char *soutq;
integer *lsout;
ftnlen soutq_len;
{
    /* Initialized data */

    static char dyntablq[48+1] = "ppppppp pp  p   mp  mf  f   fp  sf  ff  ff\
f ffff";

    /* System generated locals */
    address a__1[2], a__2[3], a__3[4];
    integer i__1, i__2, i__3[2], i__4[3], i__5[4];
    char ch__1[1], ch__2[6], ch__3[81], ch__4[10], ch__5[7];
    icilist ici__1;

    /* Builtin functions */
    integer s_wsle(), do_lio(), e_wsle();
    /* Subroutine */ int s_stop(), s_cat();
    integer s_wsfi(), do_fio(), e_wsfi();
    /* Subroutine */ int s_copy();

    /* Local variables */
    static integer id;
    static real hoff;
    extern /* Character */ VOID chax_();
    static integer lbot, idyn;
    extern /* Character */ VOID udqq_();
    extern integer lfmt1_();
    static integer idynd, lform;
    static char noteq[8];
    extern /* Subroutine */ int addstr_(), notefq_();
    static integer lnoten;
    extern integer lenstr_();
    static char notexq[79], dynstrq[4];
    extern integer igetbits_();

    /* Fortran I/O blocks */
    static cilist io___1242 = { 0, 6, 0, 0, 0 };



/*  Inputs are array *elements* */


/*  Find in list */

    i__1 = comdyn_1.ndyn;
    for (idyn = 1; idyn <= i__1; ++idyn) {
	if ((comdyn_1.idyndat[idyn - 1] & 15) == *ivx) {
	    if (igetbits_(&comdyn_1.idyndat[idyn - 1], &c__8, &c__4) == *ip) {
		goto L2;
	    }
	}
/* L1: */
    }
    s_wsle(&io___1242);
    do_lio(&c__9, &c__1, "problem finding idyndat", (ftnlen)23);
    e_wsle();
    s_stop("1", (ftnlen)1);
L2:
    idynd = comdyn_1.idyndat[idyn - 1];
    *ivx = 15 & idynd;
    if (! (*beamon)) {
	udqq_(ch__1, (ftnlen)1, nolev, ncm, islur, nvmx, ivx, nv);
	if (*(unsigned char *)&ch__1[0] == 'u') {
	    if (! bit_test(*ipl,10)) {
/* Computing MIN */
		i__1 = *nolev - 1, i__2 = *ncm - 4;
		lbot = min(i__1,i__2);
	    } else {
/* Computing MIN */
		i__1 = comtrill_1.minlev - 1, i__2 = *ncm - 4;
		lbot = min(i__1,i__2);
	    }
	} else {
	    if (! bit_test(*ipl,10)) {
/* Computing MIN */
		i__1 = *nolev - 7, i__2 = *ncm - 4;
		lbot = min(i__1,i__2);
	    } else {
/* Computing MIN */
		i__1 = comtrill_1.minlev - 7, i__2 = *ncm - 4;
		lbot = min(i__1,i__2);
	    }
	}
    } else {
/*       if ulq = 'u' then */
	if (! bit_test(*ipl,10)) {
/* Computing MIN */
	    i__1 = *nolev - 1, i__2 = *ncm - 4;
	    lbot = min(i__1,i__2);
	} else {
/* Computing MIN */
	    i__1 = comtrill_1.minlev - 1, i__2 = *ncm - 4;
	    lbot = min(i__1,i__2);
	}
/*       else */
/*         down beam stuff */
/*       end if */
    }
    lbot += -5;

/*  Check for vertical offset */

    if (bit_test(idynd,16)) {
	lbot = lbot - 32 + igetbits_(&idynd, &c__6, &c__17);
    }
    if (bit_test(idynd,23)) {

/*  Horizontal offset */

	hoff = (igetbits_(&idynd, &c__7, &c__24) - 64) * (float).1;
	lform = lfmt1_(&hoff);
/* Writing concatenation */
	chax_(ch__1, (ftnlen)1, &c__92);
	i__3[0] = 1, a__1[0] = ch__1;
	i__3[1] = 8, a__1[1] = "roffset{";
	s_cat(notexq, a__1, i__3, &c__2, (ftnlen)79);
	ici__1.icierr = 0;
	ici__1.icirnum = 1;
	ici__1.icirlen = lform;
	ici__1.iciunit = notexq + 9;
/* Writing concatenation */
	i__4[0] = 2, a__2[0] = "(f";
	i__1 = lform + 48;
	chax_(ch__1, (ftnlen)1, &i__1);
	i__4[1] = 1, a__2[1] = ch__1;
	i__4[2] = 3, a__2[2] = ".1)";
	ici__1.icifmt = (s_cat(ch__2, a__2, i__4, &c__3, (ftnlen)6), ch__2);
	s_wsfi(&ici__1);
	do_fio(&c__1, (char *)&hoff, (ftnlen)sizeof(real));
	e_wsfi();
/* Writing concatenation */
	i__3[0] = lform + 9, a__1[0] = notexq;
	i__3[1] = 2, a__1[1] = "}{";
	s_cat(ch__3, a__1, i__3, &c__2, (ftnlen)81);
	i__1 = lform + 11;
	addstr_(ch__3, &i__1, soutq, lsout, lform + 11, (ftnlen)80);
    }
/* Writing concatenation */
    chax_(ch__1, (ftnlen)1, &c__92);
    i__3[0] = 1, a__1[0] = ch__1;
    i__3[1] = 9, a__1[1] = "zcharnote";
    s_cat(ch__4, a__1, i__3, &c__2, (ftnlen)10);
    addstr_(ch__4, &c__10, soutq, lsout, (ftnlen)10, (ftnlen)80);
    notefq_(noteq, &lnoten, &lbot, ncm, (ftnlen)8);
    if (lnoten == 1) {
/* Writing concatenation */
	i__4[0] = 1, a__2[0] = "{";
	i__4[1] = 1, a__2[1] = noteq;
	i__4[2] = 1, a__2[2] = "}";
	s_cat(noteq, a__2, i__4, &c__3, (ftnlen)8);
	lnoten = 3;
    }
    addstr_(noteq, &lnoten, soutq, lsout, lnoten, (ftnlen)80);
    id = igetbits_(&idynd, &c__4, &c__12) << 2;
    i__1 = id - 4;
    s_copy(dynstrq, dyntablq + i__1, (ftnlen)4, id - i__1);
    id = lenstr_(dynstrq, &c__4, (ftnlen)4);
/* Writing concatenation */
    i__5[0] = 1, a__3[0] = "{";
    chax_(ch__1, (ftnlen)1, &c__92);
    i__5[1] = 1, a__3[1] = ch__1;
    i__5[2] = id, a__3[2] = dynstrq;
    i__5[3] = 1, a__3[3] = "}";
    s_cat(ch__5, a__3, i__5, &c__4, (ftnlen)7);
    i__1 = id + 3;
    addstr_(ch__5, &i__1, soutq, lsout, id + 3, (ftnlen)80);
    if (bit_test(idynd,23)) {
	addstr_("}", &c__1, soutq, lsout, (ftnlen)1, (ftnlen)80);
    }
    return 0;
} /* dodyn_ */

integer levrn_(nolev, irest, iud, ncm, mult)
integer *nolev, *irest, *iud, *ncm, *mult;
{
    /* System generated locals */
    integer ret_val;

    /* Local variables */
    static integer ioff;


/*  Used for placing numbers in xtups.  Returns note level if not a rest, */
/*  else level of top or bottom of rest symbol opposite beam.  iud=-1 for upstm. */

    if (! bit_test(*irest,0)) {
	ret_val = *nolev;
    } else {

/*  Restlevel is -4, 0, 2 or 100+offset.  First get offset from 1-voice default. */

	if (*mult > 0) {
	    if (*mult == 2) {
		ioff = (*iud << 1) - 1;
	    } else if (*mult != 4) {
		ioff = *iud * *mult;
	    } else {
		ioff = (*iud << 2) + 1;
	    }
	} else {

/*  May need to futz with this later for non-beamed xtups (quarter, half rests) */

	    ioff = *iud << 1;
	}
	ret_val = (*nolev + 20) % 100 - 20 + *ncm + ioff;
    }
    return ret_val;
} /* levrn_ */

/* Subroutine */ int getx_(lineq, iccount, irest, shifton, wheadpt, iornq1, 
	ivx, irest1, itsofar, ntup, itup, nnodur, dotq, lineq_len, dotq_len)
char *lineq;
integer *iccount, *irest;
logical *shifton;
real *wheadpt;
integer *iornq1, *ivx, *irest1, *itsofar, *ntup, *itup, *nnodur;
char *dotq;
ftnlen lineq_len;
ftnlen dotq_len;
{
    /* Builtin functions */
    integer i_indx();

    /* Local variables */
    static logical ess;
    static real fnum;
    static char durq[1], charq[1];
    static logical colon, number;
    static integer nextbl;
    extern /* Subroutine */ int getchar_(), readnum_();
    extern integer ifnodur_();


/*  Parse "X" commands.  Ignore all "B"; "P" means to ignore whole symbol. */
/*  In scor2prt, must strip out "P", copy only "B" and "P"-type "X"-symbols. */
/*  Since during getnote phase time is integer itsofar, which is not updated */
/*    during xtups, we use itup and ntup to get actual time.  On entry, ntup=0 if */
/*    not in xtup. */

    colon = FALSE_;
    ess = FALSE_;
    number = FALSE_;
    nextbl = *iccount + i_indx(lineq + (*iccount - 1), " ", 128 - (*iccount - 
	    1), (ftnlen)1) - 1;
    if (i_indx(lineq + (*iccount - 1), "P", nextbl - (*iccount - 1), (ftnlen)
	    1) > 0) {

/*  "Parts only", ignore entire symbol */

	*iccount = nextbl;
	return 0;
    }
L1:
    getchar_(lineq, iccount, charq, (ftnlen)128, (ftnlen)1);
    if (*(unsigned char *)charq == 'B') {

/*  "Both parts and score," ignore character */

	goto L1;
    } else if (*(unsigned char *)charq == ':') {
	colon = TRUE_;
	goto L1;
    } else if (*(unsigned char *)charq == 'S') {
	ess = TRUE_;
	goto L1;
    } else if (i_indx("+-.0123456789", charq, (ftnlen)13, (ftnlen)1) > 0) {
	number = TRUE_;
	if (*(unsigned char *)charq == '-') {
	    ++(*iccount);
	}
	readnum_(lineq, iccount, durq, &fnum, (ftnlen)128, (ftnlen)1);
	if (*(unsigned char *)charq == '-') {
	    fnum = -fnum;
	}
	if (*(unsigned char *)durq != 'p') {
	    fnum *= *wheadpt;
	    --(*iccount);
	}
	goto L1;
    }

/*  charq must be blank, so done parsing */

    if (! ess && ! colon) {

/*  Ordinary hardspace.  Goes before next note. */
/*   (Later, at "|" or "/", check for presence and switch to udoff if there!) */

	++comudsp_1.nudsp;
	*iornq1 = bit_set(*iornq1,26);
	comudsp_1.udsp[comudsp_1.nudsp - 1] = fnum;
	comudsp_1.tudsp[comudsp_1.nudsp - 1] = (real) (*itsofar);
	if (*ntup > 0) {
	    comudsp_1.tudsp[comudsp_1.nudsp - 1] += (real) (*itup - 1) / *
		    ntup * ifnodur_(nnodur, dotq, (ftnlen)1);
	}
    } else if (! number) {

/*  Must be "X:"  End a group offset. */

	*irest = bit_set(*irest,17);
	*shifton = FALSE_;
	return 0;
    } else {

/*  Only other possibility is start offset, "S" for single, ':' for multiple */

	++comudsp_1.nudoff[*ivx - 1];
	comudsp_1.udoff[*ivx + comudsp_1.nudoff[*ivx - 1] * 15 - 16] = fnum;
	if (ess) {
	    *irest1 = bit_set(*irest1,15);
	} else {
	    *irest1 = bit_set(*irest1,16);
	    *shifton = TRUE_;
	}
    }
    return 0;
} /* getx_ */

integer ntindex_(line, s2q, lenline, line_len, s2q_len)
char *line, *s2q;
integer *lenline;
ftnlen line_len;
ftnlen s2q_len;
{
    /* System generated locals */
    address a__1[2];
    integer ret_val, i__1, i__2, i__3[2];
    char ch__1[1], ch__2[2];

    /* Builtin functions */
    integer i_indx(), s_cmp();
    /* Subroutine */ int s_cat();

    /* Local variables */
    static integer ic, len;
    extern /* Character */ VOID chax_();
    static integer ndxs2, ndxbs;
    static logical intex;
    extern integer lenstr_();


/*  Returns index(line,s2q) if NOT in TeX string, 0 otherwise */

    ndxs2 = i_indx(line, s2q, line_len, s2q_len);
    chax_(ch__1, (ftnlen)1, &c__92);
    ndxbs = i_indx(line, ch__1, line_len, (ftnlen)1);
    if (ndxbs == 0 || ndxs2 < ndxbs) {
	ret_val = ndxs2;
    } else {

/*  There are both bs and s2q, and bs is to the left of sq2. So check bs's to */
/*  right of first: End is '\ ', start is ' \' */

	len = lenstr_(line, lenline, line_len);
	intex = TRUE_;
	i__1 = len;
	for (ic = ndxbs + 1; ic <= i__1; ++ic) {
	    if (ic == ndxs2) {
		if (intex) {
		    ret_val = 0;
		    i__2 = ic;
		    ndxs2 = i_indx(line + i__2, s2q, len - i__2, s2q_len) + 
			    ic;
		} else {
		    ret_val = ndxs2;
		    return ret_val;
		}
	    } else /* if(complicated condition) */ {
		i__2 = ic;
/* Writing concatenation */
		chax_(ch__1, (ftnlen)1, &c__92);
		i__3[0] = 1, a__1[0] = ch__1;
		i__3[1] = 1, a__1[1] = " ";
		s_cat(ch__2, a__1, i__3, &c__2, (ftnlen)2);
		if (intex && s_cmp(line + i__2, ch__2, ic + 2 - i__2, (ftnlen)
			2) == 0) {
		    intex = FALSE_;
		} else /* if(complicated condition) */ {
		    i__2 = ic;
/* Writing concatenation */
		    i__3[0] = 1, a__1[0] = " ";
		    chax_(ch__1, (ftnlen)1, &c__92);
		    i__3[1] = 1, a__1[1] = ch__1;
		    s_cat(ch__2, a__1, i__3, &c__2, (ftnlen)2);
		    if (! intex && s_cmp(line + i__2, ch__2, ic + 2 - i__2, (
			    ftnlen)2) == 0) {
			intex = TRUE_;
		    }
		}
	    }
/* L1: */
	}
    }
    return ret_val;
} /* ntindex_ */

/*      integer*4 function mytime() */
/*      CHARACTER(10) tq */
/*      CALL DATE_AND_TIME(TIME=tq) */
/*      read(tq,'(2i2,f6.3)')ih,im,ts */
/*      mytime = 1000*(ts+60*(im+60*ih)) */
/*      return */
/*      end */
/* Subroutine */ int getbuf_(lineq, lineq_len)
char *lineq;
ftnlen lineq_len;
{
    /* System generated locals */
    integer i__1;

    /* Builtin functions */
    /* Subroutine */ int s_copy();

    i__1 = inbuff_1.ipbuf;
    s_copy(lineq, inbuff_1.bufq + i__1, lineq_len, inbuff_1.ipbuf + 
	    inbuff_1.lbuf[inbuff_1.ilbuf - 1] - i__1);
    inbuff_1.ipbuf += inbuff_1.lbuf[inbuff_1.ilbuf - 1];
    ++inbuff_1.ilbuf;
    return 0;
} /* getbuf_ */

/* Subroutine */ int printl_(string, string_len)
char *string;
ftnlen string_len;
{
    /* Builtin functions */
    integer s_wsle(), do_lio(), e_wsle(), s_wsfe(), do_fio(), e_wsfe();

    /* Fortran I/O blocks */
    static cilist io___1265 = { 0, 6, 0, 0, 0 };
    static cilist io___1266 = { 0, 15, 0, "(a)", 0 };



/*  Send string to console and to log file */

    s_wsle(&io___1265);
    do_lio(&c__9, &c__1, string, string_len);
    e_wsle();
    s_wsfe(&io___1266);
    do_fio(&c__1, string, string_len);
    e_wsfe();
    return 0;
} /* printl_ */

/* Character */ VOID chax_(ret_val, ret_val_len, n)
char *ret_val;
ftnlen ret_val_len;
integer *n;
{

/* The only reason for this seemingly do-nothing function is to get around an */
/*  apparent bug in the Visual Fortran Standard Edition 5.0.A compiler! */

    *(unsigned char *)ret_val = (char) (*n);
    return ;
} /* chax_ */

doublereal fnote_(nodur, ivx, ip)
integer *nodur, *ivx, *ip;
{
    /* System generated locals */
    real ret_val;

    /* Builtin functions */
    integer s_wsle(), do_lio(), e_wsle();
    /* Subroutine */ int s_stop();

    /* Local variables */
    static integer iz, kkk, iip, ip1m1, ipback;

    /* Fortran I/O blocks */
    static cilist io___1270 = { 0, 6, 0, 0, 0 };



/*  This return the real duration of a note */

    /* Parameter adjustments */
    nodur -= 16;

    /* Function Body */
    ipback = *ip;
    if (nodur[*ivx + *ip * 15] > 0) {
	if (*ip > 1) {

/*  Check if this is last note of xtup */

	    if (nodur[*ivx + (*ip - 1) * 15] == 0) {
		ipback = *ip - 1;
		goto L2;
	    }
	}
	ret_val = (real) nodur[*ivx + *ip * 15];
	return ret_val;
    }
L2:

/*  Count back to prior non zero note. Start at ip to avoid neg index if ip=1 */

    for (ip1m1 = ipback; ip1m1 >= 1; --ip1m1) {
	if (nodur[*ivx + ip1m1 * 15] > 0) {
	    goto L4;
	}
/* L1: */
    }
L4:

/*  count forward to next non-0 nodur. Start at ip in case last note of xtup. */

    for (iip = *ip; iip <= 200; ++iip) {
	if (nodur[*ivx + iip * 15] > 0) {
	    ret_val = nodur[*ivx + iip * 15] / (real) (iip - ip1m1);
	    return ret_val;
	}
/* L3: */
    }
    s_wsle(&io___1270);
    do_lio(&c__9, &c__1, "Bad error in fnote", (ftnlen)18);
    e_wsle();
    iz = 0;
    kkk = nodur[iz + iz * 15];
    s_stop("", (ftnlen)0);
    return ret_val;
} /* fnote_ */

doublereal getsquez_(n, ntot, space, tnote, to)
integer *n, *ntot;
real *space, *tnote, *to;
{
    /* System generated locals */
    integer i__1;
    real ret_val, r__1, r__2;

    /* Local variables */
    static integer in;
    static real tend, tgovern;


/*  Get the squez factor by checking space against tgovern=minimum duration */
/*    of all notes sounding at time of n-th note in the list. */
/*  The starting time of base increment is to(n) and ending time is to(n)+space */
/*  Sounding notes are those that start at or before to(n) .and. end at or */
/*    after tend=to(n)+space */
/*  Since notes are ordered by increasing start times, as soon as we find one */
/*    that starts too late, we are done checking. */

    /* Parameter adjustments */
    --to;
    --tnote;

    /* Function Body */
    tgovern = (float)1e3;
    tend = to[*n] + *space;
    i__1 = *ntot;
    for (in = 1; in <= i__1; ++in) {

/*  Since to() is ordered by start times, exit loop after first note that */
/*    starts later than note of interest. */

	if (to[in] > to[*n] + comtol_1.tol) {
	    goto L2;
	}
	if (to[in] + tnote[in] > tend - comtol_1.tol) {

/*  If here, this note overlaps and must be tested. */

/* Computing MIN */
	    r__1 = tgovern, r__2 = tnote[in];
	    tgovern = dmin(r__1,r__2);
	}
/* L1: */
    }
L2:
    ret_val = *space / tgovern;
    return ret_val;
} /* getsquez_ */

logical isdotted_(nodur, ivx, ip)
integer *nodur, *ivx, *ip;
{
    /* System generated locals */
    real r__1;
    logical ret_val;

    /* Builtin functions */
    double log(), r_mod();


/*  Function returns true if note is dotted or double-dotted. */
/*    Return false for any xtuplet. */

    /* Parameter adjustments */
    nodur -= 16;

    /* Function Body */
    if (nodur[*ivx + *ip * 15] == 0) {
	ret_val = FALSE_;
	return ret_val;
    } else if (*ip > 1) {
	if (nodur[*ivx + (*ip - 1) * 15] == 0) {
	    ret_val = FALSE_;
	    return ret_val;
	}
    }

/*  Ruled out all xtups, so is dotted or double-dotted if not a power of 2. */

    r__1 = log((real) nodur[*ivx + *ip * 15]) / (float).69314718 + 
	    comtol_1.tol * (float).5;
    ret_val = r_mod(&r__1, &c_b1232) > comtol_1.tol;
    return ret_val;
} /* isdotted_ */

/* Subroutine */ int topfile_(basenameq, lbase, nv, clefq, noinst, musicsize, 
	xinstf1, mtrnmp, mtrdnp, vshrink, fbar, basenameq_len, clefq_len)
char *basenameq;
integer *lbase, *nv;
char *clefq;
integer *noinst, *musicsize;
real *xinstf1;
integer *mtrnmp, *mtrdnp;
logical *vshrink;
real *fbar;
ftnlen basenameq_len;
ftnlen clefq_len;
{
    /* System generated locals */
    address a__1[3], a__2[2], a__3[4], a__4[6], a__5[2], a__6[10], a__7[8];
    integer i__1[3], i__2[2], i__3[4], i__4, i__5, i__6[6], i__7, i__8[2], 
	    i__9[10], i__10[8];
    real r__1;
    char ch__1[1], ch__2[30], ch__3[15], ch__4[10], ch__5[17], ch__6[16], 
	    ch__7[14], ch__8[21], ch__9[7], ch__10[6], ch__11[19], ch__12[12],
	     ch__13[1], ch__14[11], ch__15[2], ch__16[33], ch__17[9], ch__18[
	    25], ch__19[8], ch__20[81], ch__21[82], ch__22[18], ch__23[57], 
	    ch__24[44], ch__25[62], ch__26[34], ch__27[47];
    cilist ci__1;

    /* Builtin functions */
    integer s_wsfe(), do_fio(), e_wsfe();
    /* Subroutine */ int s_cat();
    integer s_wsfi(), e_wsfi(), i_nint();
    double r_lg10();
    /* Subroutine */ int s_copy();

    /* Local variables */
    static integer k, iv;
    static char sq[1];
    static integer ipi;
    extern /* Character */ VOID chax_();
    static char fmtq[24], fbarq[5];
    static integer lname, lfmtq, iinst;
    extern integer numclef_();
    extern /* Subroutine */ int wgmeter_();
    static integer nstaves;

    /* Fortran I/O blocks */
    static cilist io___1277 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1278 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1279 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1280 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1281 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1282 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1283 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1284 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1285 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1286 = { 0, 11, 0, "(a)", 0 };
    static icilist io___1288 = { 0, fbarq, 0, "(f5.3)", 5, 1 };
    static cilist io___1289 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1290 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1291 = { 0, 11, 0, "(a7,i3,a2)", 0 };
    static cilist io___1292 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1293 = { 0, 11, 0, "(a19,i1,a1)", 0 };
    static cilist io___1294 = { 0, 11, 0, "(a19,i2,a1)", 0 };
    static cilist io___1298 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1299 = { 0, 11, 0, "(a11,i2,a)", 0 };
    static cilist io___1303 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1304 = { 0, 11, 0, "(a9,i2,a)", 0 };
    static cilist io___1306 = { 0, 11, 0, "(a8,i1,a)", 0 };
    static cilist io___1307 = { 0, 11, 0, "(a9,i2,a)", 0 };
    static cilist io___1308 = { 0, 11, 0, "(a18,i2,a2)", 0 };
    static cilist io___1310 = { 0, 11, 0, "(a11,i1,a2)", 0 };
    static cilist io___1311 = { 0, 11, 0, "(a11,i2,a2)", 0 };
    static cilist io___1312 = { 0, 11, 0, "(a11,i3,a2)", 0 };
    static cilist io___1313 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1314 = { 0, 11, 0, fmtq, 0 };
    static cilist io___1315 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1316 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1317 = { 0, 11, 0, "(a)", 0 };
    static cilist io___1318 = { 0, 11, 0, "(a)", 0 };


    /* Parameter adjustments */
    --clefq;

    /* Function Body */
    chax_(ch__1, (ftnlen)1, &c__92);
    *(unsigned char *)sq = *(unsigned char *)&ch__1[0];
    *vshrink = *xinstf1 > (float)20.;
    if (*vshrink) {
	comarp_1.xinsnow = (float)10.;
    } else {
	comarp_1.xinsnow = *xinstf1;
    }
    if (! comlast_1.islast) {
	return 0;
    }
    s_wsfe(&io___1277);
    do_fio(&c__1, "%%%%%%%%%%%%%%%%%", (ftnlen)17);
    e_wsfe();
    s_wsfe(&io___1278);
    do_fio(&c__1, "%", (ftnlen)1);
    e_wsfe();
    s_wsfe(&io___1279);
/* Writing concatenation */
    i__1[0] = 2, a__1[0] = "% ";
    i__1[1] = *lbase, a__1[1] = basenameq;
    i__1[2] = 4, a__1[2] = ".tex";
    s_cat(ch__2, a__1, i__1, &c__3, (ftnlen)30);
    do_fio(&c__1, ch__2, *lbase + 6);
    e_wsfe();
    s_wsfe(&io___1280);
    do_fio(&c__1, "%", (ftnlen)1);
    e_wsfe();
    s_wsfe(&io___1281);
    do_fio(&c__1, "%%%%%%%%%%%%%%%%", (ftnlen)16);
    e_wsfe();
    s_wsfe(&io___1282);
/* Writing concatenation */
    i__2[0] = 1, a__2[0] = sq;
    i__2[1] = 14, a__2[1] = "input musixtex";
    s_cat(ch__3, a__2, i__2, &c__2, (ftnlen)15);
    do_fio(&c__1, ch__3, (ftnlen)15);
    e_wsfe();
    s_wsfe(&io___1283);
/* Writing concatenation */
    i__2[0] = 1, a__2[0] = sq;
    i__2[1] = 9, a__2[1] = "input pmx";
    s_cat(ch__4, a__2, i__2, &c__2, (ftnlen)10);
    do_fio(&c__1, ch__4, (ftnlen)10);
    e_wsfe();
    s_wsfe(&io___1284);
/* Writing concatenation */
    i__2[0] = 1, a__2[0] = sq;
    i__2[1] = 14, a__2[1] = "input musixmad";
    s_cat(ch__3, a__2, i__2, &c__2, (ftnlen)15);
    do_fio(&c__1, ch__3, (ftnlen)15);
    e_wsfe();

/* Need to input musixmad to permit more slurs. */

    if (*musicsize == 20) {
	s_wsfe(&io___1285);
/* Writing concatenation */
	i__2[0] = 1, a__2[0] = sq;
	i__2[1] = 16, a__2[1] = "normalmusicsize%";
	s_cat(ch__5, a__2, i__2, &c__2, (ftnlen)17);
	do_fio(&c__1, ch__5, (ftnlen)17);
	e_wsfe();
    } else {
	s_wsfe(&io___1286);
/* Writing concatenation */
	i__2[0] = 1, a__2[0] = sq;
	i__2[1] = 15, a__2[1] = "smallmusicsize%";
	s_cat(ch__6, a__2, i__2, &c__2, (ftnlen)16);
	do_fio(&c__1, ch__6, (ftnlen)16);
	e_wsfe();
    }
    s_wsfi(&io___1288);
    do_fio(&c__1, (char *)&(*fbar), (ftnlen)sizeof(real));
    e_wsfi();
    s_wsfe(&io___1289);
/* Writing concatenation */
    i__2[0] = 1, a__2[0] = sq;
    i__2[1] = 13, a__2[1] = "nopagenumbers";
    s_cat(ch__7, a__2, i__2, &c__2, (ftnlen)14);
    do_fio(&c__1, ch__7, (ftnlen)14);
    e_wsfe();
    s_wsfe(&io___1290);
/* Writing concatenation */
    i__3[0] = 1, a__3[0] = sq;
    i__3[1] = 14, a__3[1] = "tracingstats=2";
    i__3[2] = 1, a__3[2] = sq;
    i__3[3] = 5, a__3[3] = "relax";
    s_cat(ch__8, a__3, i__3, &c__4, (ftnlen)21);
    do_fio(&c__1, ch__8, (ftnlen)21);
    e_wsfe();
    s_wsfe(&io___1291);
/* Writing concatenation */
    i__2[0] = 1, a__2[0] = sq;
    i__2[1] = 6, a__2[1] = "hsize=";
    s_cat(ch__9, a__2, i__2, &c__2, (ftnlen)7);
    do_fio(&c__1, ch__9, (ftnlen)7);
    i__4 = i_nint(&comtop_1.widthpt);
    do_fio(&c__1, (char *)&i__4, (ftnlen)sizeof(integer));
    do_fio(&c__1, "pt", (ftnlen)2);
    e_wsfe();
    ci__1.cierr = 0;
    ci__1.ciunit = 11;
/* Writing concatenation */
    i__1[0] = 5, a__1[0] = "(a6,i";
    r__1 = comtop_1.height + (float).1;
    i__4 = (integer) r_lg10(&r__1) + 49;
    chax_(ch__1, (ftnlen)1, &i__4);
    i__1[1] = 1, a__1[1] = ch__1;
    i__1[2] = 4, a__1[2] = ",a2)";
    ci__1.cifmt = (s_cat(ch__4, a__1, i__1, &c__3, (ftnlen)10), ch__4);
    s_wsfe(&ci__1);
/* Writing concatenation */
    i__2[0] = 1, a__2[0] = sq;
    i__2[1] = 5, a__2[1] = "vsize";
    s_cat(ch__10, a__2, i__2, &c__2, (ftnlen)6);
    do_fio(&c__1, ch__10, (ftnlen)6);
    i__5 = (integer) (comtop_1.height + (float).1);
    do_fio(&c__1, (char *)&i__5, (ftnlen)sizeof(integer));
    do_fio(&c__1, "pt", (ftnlen)2);
    e_wsfe();

/*  The default  raisebarno=3.5 internote, set in pmx.tex.  Increase to 4.5 if */
/*  3 sharps and treble clef, to avoid vertical clash with top space g# */

    if (comtop_1.isig == 3 && *(unsigned char *)&clefq[*nv] == 't') {
	s_wsfe(&io___1292);
/* Writing concatenation */
	i__6[0] = 1, a__4[0] = sq;
	i__6[1] = 3, a__4[1] = "def";
	i__6[2] = 1, a__4[2] = sq;
	i__6[3] = 14, a__4[3] = "raisebarno{4.5";
	i__6[4] = 1, a__4[4] = sq;
	i__6[5] = 10, a__4[5] = "internote}";
	s_cat(ch__2, a__4, i__6, &c__6, (ftnlen)30);
	do_fio(&c__1, ch__2, (ftnlen)30);
	e_wsfe();
    }
    if (*noinst < 10) {
	s_wsfe(&io___1293);
/* Writing concatenation */
	i__3[0] = 1, a__3[0] = sq;
	i__3[1] = 3, a__3[1] = "def";
	i__3[2] = 1, a__3[2] = sq;
	i__3[3] = 14, a__3[3] = "nbinstruments{";
	s_cat(ch__11, a__3, i__3, &c__4, (ftnlen)19);
	do_fio(&c__1, ch__11, (ftnlen)19);
	do_fio(&c__1, (char *)&(*noinst), (ftnlen)sizeof(integer));
	do_fio(&c__1, "}", (ftnlen)1);
	e_wsfe();
    } else {
	s_wsfe(&io___1294);
/* Writing concatenation */
	i__3[0] = 1, a__3[0] = sq;
	i__3[1] = 3, a__3[1] = "def";
	i__3[2] = 1, a__3[2] = sq;
	i__3[3] = 14, a__3[3] = "nbinstruments{";
	s_cat(ch__11, a__3, i__3, &c__4, (ftnlen)19);
	do_fio(&c__1, ch__11, (ftnlen)19);
	do_fio(&c__1, (char *)&(*noinst), (ftnlen)sizeof(integer));
	do_fio(&c__1, "}", (ftnlen)1);
	e_wsfe();
    }
    iv = 0;
    i__4 = *noinst;
    for (iinst = 1; iinst <= i__4; ++iinst) {
	nstaves = comnvi_1.nsperi[iinst - 1];
	if (iinst < 10) {
	    s_wsfe(&io___1298);
/* Writing concatenation */
	    i__3[0] = 1, a__3[0] = sq;
	    i__3[1] = 9, a__3[1] = "setstaffs";
	    i__5 = iinst + 48;
	    chax_(ch__1, (ftnlen)1, &i__5);
	    i__3[2] = 1, a__3[2] = ch__1;
	    i__7 = nstaves + 48;
	    chax_(ch__13, (ftnlen)1, &i__7);
	    i__3[3] = 1, a__3[3] = ch__13;
	    s_cat(ch__12, a__3, i__3, &c__4, (ftnlen)12);
	    do_fio(&c__1, ch__12, (ftnlen)12);
	    e_wsfe();
	} else {
	    s_wsfe(&io___1299);
/* Writing concatenation */
	    i__2[0] = 1, a__2[0] = sq;
	    i__2[1] = 10, a__2[1] = "setstaffs{";
	    s_cat(ch__14, a__2, i__2, &c__2, (ftnlen)11);
	    do_fio(&c__1, ch__14, (ftnlen)11);
	    do_fio(&c__1, (char *)&iinst, (ftnlen)sizeof(integer));
/* Writing concatenation */
	    i__8[0] = 1, a__5[0] = "}";
	    i__5 = nstaves + 48;
	    chax_(ch__1, (ftnlen)1, &i__5);
	    i__8[1] = 1, a__5[1] = ch__1;
	    s_cat(ch__15, a__5, i__8, &c__2, (ftnlen)2);
	    do_fio(&c__1, ch__15, (ftnlen)2);
	    e_wsfe();
	}
	++iv;
	if (nstaves == 1) {
	    i__5 = numclef_(clefq + iv, (ftnlen)1) + 48;
	    chax_(ch__1, (ftnlen)1, &i__5);
	    s_copy(fmtq, ch__1, (ftnlen)24, (ftnlen)1);
	    lfmtq = 1;
	} else {
/* Writing concatenation */
	    i__2[0] = 1, a__2[0] = "{";
	    i__5 = numclef_(clefq + iv, (ftnlen)1) + 48;
	    chax_(ch__1, (ftnlen)1, &i__5);
	    i__2[1] = 1, a__2[1] = ch__1;
	    s_cat(fmtq, a__2, i__2, &c__2, (ftnlen)24);
	    lfmtq = 2;
	    i__5 = nstaves;
	    for (k = 2; k <= i__5; ++k) {
		++iv;
/* Writing concatenation */
		i__2[0] = lfmtq, a__2[0] = fmtq;
		i__7 = numclef_(clefq + iv, (ftnlen)1) + 48;
		chax_(ch__1, (ftnlen)1, &i__7);
		i__2[1] = 1, a__2[1] = ch__1;
		s_cat(fmtq, a__2, i__2, &c__2, (ftnlen)24);
		++lfmtq;
/* L2: */
	    }
/* Writing concatenation */
	    i__2[0] = lfmtq, a__2[0] = fmtq;
	    i__2[1] = 1, a__2[1] = "}";
	    s_cat(fmtq, a__2, i__2, &c__2, (ftnlen)24);
	    ++lfmtq;
	}
	if (iinst < 10) {
	    s_wsfe(&io___1303);
/* Writing concatenation */
	    i__3[0] = 1, a__3[0] = sq;
	    i__3[1] = 7, a__3[1] = "setclef";
	    i__5 = iinst + 48;
	    chax_(ch__1, (ftnlen)1, &i__5);
	    i__3[2] = 1, a__3[2] = ch__1;
	    i__3[3] = lfmtq, a__3[3] = fmtq;
	    s_cat(ch__16, a__3, i__3, &c__4, (ftnlen)33);
	    do_fio(&c__1, ch__16, lfmtq + 9);
	    e_wsfe();
	} else {
	    s_wsfe(&io___1304);
/* Writing concatenation */
	    i__2[0] = 1, a__2[0] = sq;
	    i__2[1] = 8, a__2[1] = "setclef{";
	    s_cat(ch__17, a__2, i__2, &c__2, (ftnlen)9);
	    do_fio(&c__1, ch__17, (ftnlen)9);
	    do_fio(&c__1, (char *)&iinst, (ftnlen)sizeof(integer));
/* Writing concatenation */
	    i__8[0] = 1, a__5[0] = "}";
	    i__8[1] = lfmtq, a__5[1] = fmtq;
	    s_cat(ch__18, a__5, i__8, &c__2, (ftnlen)25);
	    do_fio(&c__1, ch__18, lfmtq + 1);
	    e_wsfe();
	}
	for (lname = 79; lname >= 2; --lname) {
	    if (*(unsigned char *)&comtop_1.inameq[(iinst - 1) * 79 + (lname 
		    - 1)] != ' ') {
		goto L4;
	    }
/* L3: */
	}
L4:
	comtop_1.lnam[iinst - 1] = lname;
	if (iinst < 10) {
	    s_wsfe(&io___1306);
/* Writing concatenation */
	    i__2[0] = 1, a__2[0] = sq;
	    i__2[1] = 7, a__2[1] = "setname";
	    s_cat(ch__19, a__2, i__2, &c__2, (ftnlen)8);
	    do_fio(&c__1, ch__19, (ftnlen)8);
	    do_fio(&c__1, (char *)&iinst, (ftnlen)sizeof(integer));
/* Writing concatenation */
	    i__1[0] = 1, a__1[0] = "{";
	    i__1[1] = lname, a__1[1] = comtop_1.inameq + (iinst - 1) * 79;
	    i__1[2] = 1, a__1[2] = "}";
	    s_cat(ch__20, a__1, i__1, &c__3, (ftnlen)81);
	    do_fio(&c__1, ch__20, lname + 2);
	    e_wsfe();
	} else {
	    s_wsfe(&io___1307);
/* Writing concatenation */
	    i__2[0] = 1, a__2[0] = sq;
	    i__2[1] = 8, a__2[1] = "setname{";
	    s_cat(ch__17, a__2, i__2, &c__2, (ftnlen)9);
	    do_fio(&c__1, ch__17, (ftnlen)9);
	    do_fio(&c__1, (char *)&iinst, (ftnlen)sizeof(integer));
/* Writing concatenation */
	    i__1[0] = 2, a__1[0] = "}{";
	    i__1[1] = lname, a__1[1] = comtop_1.inameq + (iinst - 1) * 79;
	    i__1[2] = 1, a__1[2] = "}";
	    s_cat(ch__21, a__1, i__1, &c__3, (ftnlen)82);
	    do_fio(&c__1, ch__21, lname + 3);
	    e_wsfe();
	}
/* L1: */
    }
    s_wsfe(&io___1308);
/* Writing concatenation */
    i__2[0] = 1, a__2[0] = sq;
    i__2[1] = 17, a__2[1] = "generalsignature{";
    s_cat(ch__22, a__2, i__2, &c__2, (ftnlen)18);
    do_fio(&c__1, ch__22, (ftnlen)18);
    do_fio(&c__1, (char *)&comtop_1.isig, (ftnlen)sizeof(integer));
    do_fio(&c__1, "}%", (ftnlen)2);
    e_wsfe();
    wgmeter_(mtrnmp, mtrdnp);
    r__1 = comtop_1.fracindent * comtop_1.widthpt;
    ipi = i_nint(&r__1);
    if (ipi < 10) {
	s_wsfe(&io___1310);
/* Writing concatenation */
	i__2[0] = 1, a__2[0] = sq;
	i__2[1] = 10, a__2[1] = "parindent ";
	s_cat(ch__14, a__2, i__2, &c__2, (ftnlen)11);
	do_fio(&c__1, ch__14, (ftnlen)11);
	do_fio(&c__1, (char *)&ipi, (ftnlen)sizeof(integer));
	do_fio(&c__1, "pt", (ftnlen)2);
	e_wsfe();
    } else if (ipi < 100) {
	s_wsfe(&io___1311);
/* Writing concatenation */
	i__2[0] = 1, a__2[0] = sq;
	i__2[1] = 10, a__2[1] = "parindent ";
	s_cat(ch__14, a__2, i__2, &c__2, (ftnlen)11);
	do_fio(&c__1, ch__14, (ftnlen)11);
	do_fio(&c__1, (char *)&ipi, (ftnlen)sizeof(integer));
	do_fio(&c__1, "pt", (ftnlen)2);
	e_wsfe();
    } else {
	s_wsfe(&io___1312);
/* Writing concatenation */
	i__2[0] = 1, a__2[0] = sq;
	i__2[1] = 10, a__2[1] = "parindent ";
	s_cat(ch__14, a__2, i__2, &c__2, (ftnlen)11);
	do_fio(&c__1, ch__14, (ftnlen)11);
	do_fio(&c__1, (char *)&ipi, (ftnlen)sizeof(integer));
	do_fio(&c__1, "pt", (ftnlen)2);
	e_wsfe();
    }
    s_wsfe(&io___1313);
/* Writing concatenation */
    i__9[0] = 1, a__6[0] = sq;
    i__9[1] = 11, a__6[1] = "elemskip1pt";
    i__9[2] = 1, a__6[2] = sq;
    i__9[3] = 13, a__6[3] = "afterruleskip";
    i__9[4] = 5, a__6[4] = fbarq;
    i__9[5] = 2, a__6[5] = "pt";
    i__9[6] = 1, a__6[6] = sq;
    i__9[7] = 17, a__6[7] = "beforeruleskip0pt";
    i__9[8] = 1, a__6[8] = sq;
    i__9[9] = 5, a__6[9] = "relax";
    s_cat(ch__23, a__6, i__9, &c__10, (ftnlen)57);
    do_fio(&c__1, ch__23, (ftnlen)57);
    e_wsfe();
    if (! (*vshrink)) {
	if (*xinstf1 < (float)9.95) {
	    s_copy(fmtq, "(a,f3.1,a)", (ftnlen)24, (ftnlen)10);
	} else {
	    s_copy(fmtq, "(a,f4.1,a)", (ftnlen)24, (ftnlen)10);
	}
	s_wsfe(&io___1314);
/* Writing concatenation */
	i__6[0] = 1, a__4[0] = sq;
	i__6[1] = 15, a__4[1] = "stafftopmarg0pt";
	i__6[2] = 1, a__4[2] = sq;
	i__6[3] = 15, a__4[3] = "staffbotmarg0pt";
	i__6[4] = 1, a__4[4] = sq;
	i__6[5] = 11, a__4[5] = "interstaff{";
	s_cat(ch__24, a__4, i__6, &c__6, (ftnlen)44);
	do_fio(&c__1, ch__24, (ftnlen)44);
	do_fio(&c__1, (char *)&(*xinstf1), (ftnlen)sizeof(real));
/* Writing concatenation */
	i__1[0] = 1, a__1[0] = "}";
	i__1[1] = 1, a__1[1] = sq;
	i__1[2] = 5, a__1[2] = "relax";
	s_cat(ch__9, a__1, i__1, &c__3, (ftnlen)7);
	do_fio(&c__1, ch__9, (ftnlen)7);
	e_wsfe();
    } else {
	s_wsfe(&io___1315);
/* Writing concatenation */
	i__9[0] = 1, a__6[0] = sq;
	i__9[1] = 15, a__6[1] = "stafftopmarg0pt";
	i__9[2] = 1, a__6[2] = sq;
	i__9[3] = 13, a__6[3] = "staffbotmarg5";
	i__9[4] = 1, a__6[4] = sq;
	i__9[5] = 10, a__6[5] = "Interligne";
	i__9[6] = 1, a__6[6] = sq;
	i__9[7] = 14, a__6[7] = "interstaff{10}";
	i__9[8] = 1, a__6[8] = sq;
	i__9[9] = 5, a__6[9] = "relax";
	s_cat(ch__25, a__6, i__9, &c__10, (ftnlen)62);
	do_fio(&c__1, ch__25, (ftnlen)62);
	e_wsfe();
    }
    if (*nv == 1) {
	s_wsfe(&io___1316);
/* Writing concatenation */
	i__2[0] = 1, a__2[0] = sq;
	i__2[1] = 11, a__2[1] = "nostartrule";
	s_cat(ch__12, a__2, i__2, &c__2, (ftnlen)12);
	do_fio(&c__1, ch__12, (ftnlen)12);
	e_wsfe();
    }
    s_wsfe(&io___1317);
/* Writing concatenation */
    i__3[0] = 1, a__3[0] = sq;
    i__3[1] = 8, a__3[1] = "readmod{";
    i__3[2] = *lbase, a__3[2] = basenameq;
    i__3[3] = 1, a__3[3] = "}";
    s_cat(ch__26, a__3, i__3, &c__4, (ftnlen)34);
    do_fio(&c__1, ch__26, *lbase + 10);
    e_wsfe();
    s_wsfe(&io___1318);
/* Writing concatenation */
    i__10[0] = 1, a__7[0] = sq;
    i__10[1] = 11, a__7[1] = "startmuflex";
    i__10[2] = 1, a__7[2] = sq;
    i__10[3] = 10, a__7[3] = "startpiece";
    i__10[4] = 1, a__7[4] = sq;
    i__10[5] = 8, a__7[5] = "addspace";
    i__10[6] = 1, a__7[6] = sq;
    i__10[7] = 14, a__7[7] = "afterruleskip%";
    s_cat(ch__27, a__7, i__10, &c__8, (ftnlen)47);
    do_fio(&c__1, ch__27, (ftnlen)47);
    e_wsfe();
    return 0;
} /* topfile_ */

/* Subroutine */ int findeonk_(nptr1, nptr2, wovera, xelsk, dtmin, dtmax, 
	eonk0)
integer *nptr1, *nptr2;
real *wovera, *xelsk, *dtmin, *dtmax, *eonk0;
{
    /* System generated locals */
    integer i__1;
    real r__1;
    doublereal d__1, d__2;

    /* Builtin functions */
    double pow_dd(), sqrt(), log();

    /* Local variables */
    static real f, fp;
    extern doublereal feon_();
    static real targ, esum;
    static integer iptr;
    extern doublereal f1eon_();
    static real desum, dsoln;
    static integer niter;
    static real detarg;
    extern /* Subroutine */ int printl_();


/*  Compute an exponent eonk for use in the "flattened" formula for elemskips */
/*   vs time.  We must solve the eqution f = 0.  Initial quess is eonk0. */

    comeon_1.eonk = *eonk0;
    niter = 0;
L1:
    d__1 = (doublereal) f1eon_(dtmax);
    d__2 = (doublereal) comeon_1.eonk;
    comeon_1.ewmxk = pow_dd(&d__1, &d__2);
    ++niter;
    esum = (float)0.;
    desum = (float)0.;
    i__1 = *nptr2;
    for (iptr = *nptr1; iptr <= i__1; ++iptr) {
	targ = c1omnotes_1.durb[iptr - 1] / c1omnotes_1.sqzb[iptr - 1];
	esum += c1omnotes_1.nnpd[iptr - 1] * c1omnotes_1.sqzb[iptr - 1] * 
		feon_(&targ);
	d__1 = (doublereal) (*dtmax / targ);
	d__2 = (doublereal) comeon_1.eonk;
	detarg = sqrt(targ / 2 * pow_dd(&d__1, &d__2)) * log(*dtmax / targ);
	desum += c1omnotes_1.nnpd[iptr - 1] * c1omnotes_1.sqzb[iptr - 1] * 
		detarg;
/* L2: */
    }
    f = *wovera * feon_(dtmin) - *xelsk - esum;
    d__1 = (doublereal) (*dtmax / *dtmin);
    d__2 = (doublereal) comeon_1.eonk;
    fp = *wovera * sqrt(*dtmin / 2 * pow_dd(&d__1, &d__2)) * log(*dtmax / *
	    dtmin) - desum;
    if (dabs(fp) < comtol_1.tol || (r__1 = comeon_1.eonk - (float).5, dabs(
	    r__1)) > (float).5 || niter > 100) {
	printl_("Error in findeonk.  Please send source to Dr. Don", (ftnlen)
		49);
	comeon_1.eonk = (float)0.;
	comeon_1.ewmxk = (float)1.;
	return 0;
    }
    dsoln = -f / fp;
    if (dabs(dsoln) < comtol_1.tol * (float).1) {
	return 0;
    }

/*  Not converged yet, try again */

    comeon_1.eonk += dsoln;
    goto L1;
} /* findeonk_ */

/* Subroutine */ int istring_(i__, string, len, string_len)
integer *i__;
char *string;
integer *len;
ftnlen string_len;
{
    /* System generated locals */
    address a__1[3], a__2[2];
    integer i__1[3], i__2[2];
    real r__1;
    char ch__1[1], ch__2[4];
    icilist ici__1;

    /* Builtin functions */
    double r_lg10();
    /* Subroutine */ int s_copy(), s_cat();
    integer s_wsfi(), do_fio(), e_wsfi();


/*  Returns string with integer only if length is 1, otherwise enclosed in */
/*   brackets. */

    if (*i__ != 0) {
	r__1 = abs(*i__) * (float)1.0001;
	*len = r_lg10(&r__1) + 1;
	if (*i__ < 0) {
	    ++(*len);
	}
    } else {
	s_copy(string, "0", string_len, (ftnlen)1);
	*len = 1;
	return 0;
    }
    if (*len == 1) {
	*(unsigned char *)&ch__1[0] = *i__ + 48;
	s_copy(string, ch__1, string_len, (ftnlen)1);
    } else {
	s_copy(string, "{", string_len, (ftnlen)1);
	ici__1.icierr = 0;
	ici__1.icirnum = 1;
	ici__1.icirlen = *len;
	ici__1.iciunit = string + 1;
/* Writing concatenation */
	i__1[0] = 2, a__1[0] = "(i";
	*(unsigned char *)&ch__1[0] = *len + 48;
	i__1[1] = 1, a__1[1] = ch__1;
	i__1[2] = 1, a__1[2] = ")";
	ici__1.icifmt = (s_cat(ch__2, a__1, i__1, &c__3, (ftnlen)4), ch__2);
	s_wsfi(&ici__1);
	do_fio(&c__1, (char *)&(*i__), (ftnlen)sizeof(integer));
	e_wsfi();
/* Writing concatenation */
	i__2[0] = *len + 1, a__2[0] = string;
	i__2[1] = 1, a__2[1] = "}";
	s_cat(string, a__2, i__2, &c__2, string_len);
	*len += 2;
    }
    return 0;
} /* istring_ */



/* Subroutine */ int addmidi_(icm, nolev, iacc, isig, time, rest, endrest)
integer *icm, *nolev, *iacc, *isig;
real *time;
logical *rest, *endrest;
{
    /* System generated locals */
    integer i__1, i__2, i__3;
    real r__1;

    /* Builtin functions */
    integer i_nint(), s_wsle(), do_lio(), e_wsle();
    /* Subroutine */ int s_stop();
    integer i_indx();

    /* Local variables */
    static integer i__, j, it1, it2, ion;
    static shortint itk[25];
    static integer jacc, kacc, macc, ioff, isav, idur, jsav, idur1, imidt, 
	    ipsav, ipsav0, nby2on;
    extern integer iashft_();
    static integer nbytes, nby2off;
    static logical eximacc;
    static integer itiesav[500]	/* was [5][100] */, idurvar;
    static logical it1found;
    static integer nsav4tie;
    extern /* Subroutine */ int chkimidi_();
    static char notenumq[1];
    extern integer igetvarlen_(), isetvarlen_();

    /* Fortran I/O blocks */
    static cilist io___1332 = { 0, 6, 0, 0, 0 };
    static cilist io___1344 = { 0, 6, 0, 0, 0 };
    static cilist io___1353 = { 0, 6, 0, 0, 0 };



/*  Following variables are local but must be saved.  I hope they are. */
/*  (3/18/00) With g77 they are not, so add a common block here. */


/*  Cancel out barline accidentals if there's a rest. */

    if (*rest) {
	comslm_1.naccbl[*icm] = 0;
    }

/*  Special path to insert dummy rest at end of a section */

    if (*endrest) {
	goto L20;
    }

    i__1 = commidi_1.nmidcrd;
    for (ion = 0; ion <= i__1; ++ion) {

/*  check if this is only to get pitch of a chord note */

	if (commidi_1.notmain) {
	    goto L6;
	}

/*  check for rest */

	if (*rest) {

/*  Will not put in a note, but must update timing */

	    if (! commidi_1.restpend[*icm]) {

/*  First rest in sequence, save the time */

		commidi_1.restpend[*icm] = TRUE_;
		commidi_1.trest[*icm] = *time;
	    } else {
		commidi_1.trest[*icm] += *time;
	    }

/*  Note: code checkers don't like the above due to calling addmidi(trest(icm)) */
/*    but this only happens if rest at end of section (endrest=.true.) (called */
/*    from getmidi(), in which case these above lines are bypassed. */

	    return 0;
	}

/*  time tics */

	if (commidi_1.imidi[*icm] > 0 && ion == 0) {
	    idur = commidi_1.mgap;
	} else {
	    idur = 0;
	}
	if (commidi_1.restpend[*icm]) {
	    commidi_1.restpend[*icm] = FALSE_;
	    r__1 = commidi_1.trest[*icm] * 15;
	    idur += i_nint(&r__1);
	}

/*  time to start of note */

	idurvar = isetvarlen_(&idur, &nby2on);
	if (nby2on > 4) {
	    s_wsle(&io___1332);
	    do_lio(&c__9, &c__1, "You got >4 bytes, something is bogus.", (
		    ftnlen)37);
	    e_wsle();
	    s_stop("1", (ftnlen)1);
	}
	++commidi_1.imidi[*icm];
	i__2 = nby2on;
	for (i__ = 1; i__ <= i__2; ++i__) {

/*  imidi points to cell before highest (leftmost) byte.  Start with lowest byte */
/*    at far right, fill in backwards */

	    commidi_1.mmidi[*icm + (commidi_1.imidi[*icm] + nby2on - i__ << 4)
		     - 16] = (shortint) (idurvar % 256);
	    if (nby2on > 1) {
		idurvar /= 256;
	    }
/* L2: */
	}
	commidi_1.imidi[*icm] = commidi_1.imidi[*icm] + nby2on - 1;

/*  Note-on signal */

	++commidi_1.imidi[*icm];
	commidi_1.mmidi[*icm + (commidi_1.imidi[*icm] << 4) - 16] = (shortint)
		 (*icm + 144);

/*  Entry point for chord note pitch determination */

L6:

/*  Get midi pitch.  On chord iteration, only do this first time (main note), */
/*  since pitch was already computed for nonmain chord notes. */

	if (ion == 0) {
	    ipsav = *nolev * (float)12. / 7 + 11;
	    ipsav0 = ipsav;
	    if (*isig != 0) {

/*  Adjust for signature */

		*(unsigned char *)notenumq = (char) (*nolev % 7 + 48);
		if (*isig >= i_indx("4152630", notenumq, (ftnlen)7, (ftnlen)1)
			) {
		    ++ipsav;
		} else if (-(*isig) >= i_indx("0362514", notenumq, (ftnlen)7, 
			(ftnlen)1)) {
		    --ipsav;
		}
	    }

/*  Deal with accidentals. */

/*  iacc   0   1   2   3   4   5   6   7 */
/* effect  X   fl  sh  na  X  dfl dsh  X */
/* iashft  X   -1  1   0   X  -2   2   X */

	    jacc = 0;
	    eximacc = FALSE_;
	    if (*iacc > 0) {

/*  Adjust key-sig-adjusted pitch for explicit accidental (and exit) */

		jacc = iashft_(iacc);
		eximacc = TRUE_;
		if (! commidi_1.relacc) {
		    jacc = jacc + ipsav0 - ipsav;
		}

/*  (Above) Shift applies to diatonic pitch but will be added to adjusted one */

	    } else if (commidi_1.naccim[*icm] > 0) {

/*  Possible implicit accidental from earlier in the bar */
/*    Check for prior accid in this bar at this note level */

		i__2 = commidi_1.naccim[*icm];
		for (kacc = 1; kacc <= i__2; ++kacc) {
		    if (commidi_1.laccim[*icm + (kacc << 4) - 16] == *nolev) {
			jacc = commidi_1.jaccim[*icm + (kacc << 4) - 16];
			eximacc = TRUE_;
			if (! commidi_1.relacc) {
			    jacc = jacc + ipsav0 - ipsav;
			}
			goto L4;
		    }
/* L3: */
		}
L4:
		;
	    }

/*  Must split off the following if block from those above because chord */
/*  notes can cause naccim>0, forcing us to miss other chord note's */
/*  accross-bar-line accidental */

	    if (comslm_1.naccbl[*icm] > 0 && ! eximacc) {

/*  Possible carryover accid from prior bar (or prior same-pitch note). */

		i__2 = comslm_1.naccbl[*icm];
		for (kacc = 1; kacc <= i__2; ++kacc) {
		    if (comslm_1.laccbl[*icm + (kacc << 4) - 16] == *nolev) {
			jacc = comslm_1.jaccbl[*icm + (kacc << 4) - 16];

/*  Since we are *using* the bar-line accid, must flag it to be saved for next. */

			++comslm_1.nusebl;
			comips_1.jusebl[comslm_1.nusebl - 1] = (shortint) 
				jacc;
			comips_1.lusebl[comslm_1.nusebl - 1] = (shortint) (*
				nolev);
			if (! commidi_1.relacc) {
			    jacc = jacc + ipsav0 - ipsav;
			}
			goto L22;
		    }
/* L21: */
		}
L22:
		;
	    }
	    ipsav += jacc;
	}
	if (commidi_1.notmain) {
	    commidi_1.mcpitch[commidi_1.nmidcrd - 1] = ipsav;

/*  Save pitch for tie checks */

	    if (comslm_1.levson[*icm] == *nolev && ! comslm_1.slmon[*icm]) {
		comips_1.ipslon[*icm] = (shortint) ipsav;
	    }
	} else {
	    ++commidi_1.imidi[*icm];
	    if (ion == 0) {
		commidi_1.mmidi[*icm + (commidi_1.imidi[*icm] << 4) - 16] = (
			shortint) ipsav;
		if (comslm_1.levson[*icm] == *nolev && ! comslm_1.slmon[*icm])
			 {
		    comips_1.ipslon[*icm] = (shortint) ipsav;
		}
	    } else {
		commidi_1.mmidi[*icm + (commidi_1.imidi[*icm] << 4) - 16] = (
			shortint) commidi_1.mcpitch[ion - 1];
	    }
	}
	if (ion == 0) {

/*  Only record accids for non-chords, main chord note during chord iteration */
/*    and chordnotes on first call but not during iteration */

	    if (*iacc > 0) {

/*  Set marker for accidental for possible continuations later this bar */
/*    but first check and clear earlier ones on same note. */

		i__2 = commidi_1.naccim[*icm];
		for (kacc = 1; kacc <= i__2; ++kacc) {
		    if (commidi_1.laccim[*icm + (kacc << 4) - 16] == *nolev) {
			i__3 = commidi_1.naccim[*icm] - 1;
			for (macc = kacc; macc <= i__3; ++macc) {
			    commidi_1.laccim[*icm + (macc << 4) - 16] = 
				    commidi_1.laccim[*icm + (macc + 1 << 4) - 
				    16];
			    commidi_1.jaccim[*icm + (macc << 4) - 16] = 
				    commidi_1.jaccim[*icm + (macc + 1 << 4) - 
				    16];
/* L24: */
			}
			goto L25;
		    }
/* L23: */
		}
		goto L26;
L25:
		--commidi_1.naccim[*icm];
L26:

/*  Flag new accidental */

		++commidi_1.naccim[*icm];
		commidi_1.laccim[*icm + (commidi_1.naccim[*icm] << 4) - 16] = 
			*nolev;
		commidi_1.jaccim[*icm + (commidi_1.naccim[*icm] << 4) - 16] = 
			iashft_(iacc);
	    }

/*  Bail if this is a chord note on the first call (from docrd) */

	    if (commidi_1.notmain) {
		return 0;
	    }
	}

/*  Vel */

	++commidi_1.imidi[*icm];
	commidi_1.mmidi[*icm + (commidi_1.imidi[*icm] << 4) - 16] = 127;
	chkimidi_(icm);
/* L7: */
    }

/*  For tie checks */

    if (comslm_1.levson[*icm] > 0 && ! comslm_1.slmon[*icm]) {
	comslm_1.imidso[*icm] = commidi_1.imidi[*icm];
    }

/*  Entry point for special rests at section ends (endrest=T) */

L20:

/*  Now insert all the ends */

    i__1 = commidi_1.nmidcrd;
    for (ioff = 0; ioff <= i__1; ++ioff) {
	if (ioff == 0) {

/*  time to end */

	    r__1 = *time * 15;
	    idur1 = i_nint(&r__1);
	    r__1 = commidi_1.trest[*icm] * 15;
	    if (! (*endrest) || comevent_1.miditime == i_nint(&r__1)) {
		idur = idur1 - commidi_1.mgap;
	    } else {
		idur = idur1;
	    }
	    if (idur1 == 69) {

/*  Deal with roundoff problem with 7-tuplets */

		++comdiag_1.n69[*icm];
		if ((comdiag_1.n69[*icm] + 6) % 7 > 3) {
		    idur = 58;
		}
	    }
	    idurvar = isetvarlen_(&idur, &nby2off);
	    if (nby2off > 4) {
		s_wsle(&io___1344);
		do_lio(&c__9, &c__1, "You got >4 bytes, something is bogus.", 
			(ftnlen)37);
		e_wsle();
		s_stop("1", (ftnlen)1);
	    }
	    ++commidi_1.imidi[*icm];
	    chkimidi_(icm);
	    i__2 = nby2off;
	    for (i__ = 1; i__ <= i__2; ++i__) {
		commidi_1.mmidi[*icm + (commidi_1.imidi[*icm] + nby2off - i__ 
			<< 4) - 16] = (shortint) (idurvar % 256);
		if (nby2off > 1) {
		    idurvar /= 256;
		}
/* L1: */
	    }
	    commidi_1.imidi[*icm] = commidi_1.imidi[*icm] + nby2off - 1;
	} else {

/*  Inserting end of chord note, delta time is 0 */

	    ++commidi_1.imidi[*icm];
	    commidi_1.mmidi[*icm + (commidi_1.imidi[*icm] << 4) - 16] = 0;
	}

/*  Note off */

	++commidi_1.imidi[*icm];
	commidi_1.mmidi[*icm + (commidi_1.imidi[*icm] << 4) - 16] = (shortint)
		 (*icm + 128);

/*  Pitch */

	++commidi_1.imidi[*icm];
	if (ioff == 0) {
	    commidi_1.mmidi[*icm + (commidi_1.imidi[*icm] << 4) - 16] = (
		    shortint) ipsav;
	} else {
	    commidi_1.mmidi[*icm + (commidi_1.imidi[*icm] << 4) - 16] = (
		    shortint) commidi_1.mcpitch[ioff - 1];
	}

/*  Vel */

	++commidi_1.imidi[*icm];
	commidi_1.mmidi[*icm + (commidi_1.imidi[*icm] << 4) - 16] = 0;
	chkimidi_(icm);
	if (*endrest) {
	    return 0;
	}

/*      print*,'Off, icm,imidi,ipsav,idur:',icm,imidi(icm),ipsav,time */

/* L8: */
    }
    comslm_1.naccbl[*icm] = comslm_1.nusebl;
    if (comslm_1.nusebl > 0) {

/*  Fix tables of "bar-line" accids that are saved due to consecutive notes. */

	i__1 = comslm_1.nusebl;
	for (kacc = 1; kacc <= i__1; ++kacc) {
	    comslm_1.laccbl[*icm + (kacc << 4) - 16] = comips_1.lusebl[kacc - 
		    1];
	    comslm_1.jaccbl[*icm + (kacc << 4) - 16] = comips_1.jusebl[kacc - 
		    1];
/* L30: */
	}
	comslm_1.nusebl = 0;
    }

/*  Begin tie checks */

    if (comslm_1.slmon[*icm]) {

/*  Prior note had a slur start */

	if (comslm_1.levson[*icm] == comslm_1.levsoff[*icm] && *iacc == 0) {

/*  We have a tie! (Assumed there would be no accidental on tie-ending note) */
/*  Make a list of times of all events back to the one starting at imidso+1, */
/*    which is at or before where the tie started.  Ident tie start and stop by */
/*    comparing pitches.  Save the 4 pieces of data in itiesav(1...4,nsav4tie) */
/*    Store actual time in itiesav(5,nsav4tie), using itiesav(1,1) as initial */
/*    time. */
	    nsav4tie = 0;
	    imidt = comslm_1.imidso[*icm];
L10:
	    ++nsav4tie;
	    itiesav[nsav4tie * 5 - 5] = igetvarlen_(commidi_1.mmidi, icm, &
		    imidt, &nbytes);
	    imidt += nbytes;
	    for (j = 1; j <= 3; ++j) {
		itiesav[j + 1 + nsav4tie * 5 - 6] = commidi_1.mmidi[*icm + (
			imidt + j << 4) - 16];
/* L11: */
	    }
	    imidt += 3;
	    if (nsav4tie == 1) {
		itiesav[4] = itiesav[0];
	    } else {
		itiesav[nsav4tie * 5 - 1] = itiesav[nsav4tie * 5 - 5] + 
			itiesav[(nsav4tie - 1) * 5 - 1];
	    }
	    if (imidt != commidi_1.imidi[*icm]) {
		goto L10;
	    }

/*  Find which two pitches agree with saved slur pitch. */

	    it1found = FALSE_;
	    i__1 = nsav4tie;
	    for (it2 = 1; it2 <= i__1; ++it2) {
		if (itiesav[it2 * 5 - 3] == comips_1.ipslon[*icm]) {
		    if (it1found) {
			goto L13;
		    }
		    it1 = it2;
		    it1found = TRUE_;
		}
/* L12: */
	    }
	    s_wsle(&io___1353);
	    do_lio(&c__9, &c__1, "Failed to find tied notes; kluging", (
		    ftnlen)34);
	    e_wsle();
/*          stop 1 */
	    it1 = nsav4tie + 1;
	    it2 = nsav4tie + 1;
L13:

/*  List the positions we want to keep */

	    jsav = 0;
	    i__1 = nsav4tie;
	    for (isav = 1; isav <= i__1; ++isav) {
		if (isav == it1 || isav == it2) {
		    goto L14;
		}
		++jsav;
		itk[jsav - 1] = (shortint) isav;
L14:
		;
	    }
	    nsav4tie += -2;

/*  Now dump events it1 & it2, recompute times, restack mmidi. */

	    commidi_1.imidi[*icm] = comslm_1.imidso[*icm];
	    i__1 = nsav4tie;
	    for (isav = 1; isav <= i__1; ++isav) {
		if (isav == 1) {
		    idurvar = isetvarlen_(&itiesav[itk[isav - 1] * 5 - 1], &
			    nbytes);
		} else {
		    i__2 = itiesav[itk[isav - 1] * 5 - 1] - itiesav[itk[isav 
			    - 2] * 5 - 1];
		    idurvar = isetvarlen_(&i__2, &nbytes);
		}
		++commidi_1.imidi[*icm];
		i__2 = nbytes;
		for (i__ = 1; i__ <= i__2; ++i__) {
		    commidi_1.mmidi[*icm + (commidi_1.imidi[*icm] + nbytes - 
			    i__ << 4) - 16] = (shortint) (idurvar % 256);
		    if (nbytes > 1) {
			idurvar /= 256;
		    }
/* L16: */
		}
		commidi_1.imidi[*icm] = commidi_1.imidi[*icm] + nbytes - 1;
		for (i__ = 2; i__ <= 4; ++i__) {
		    ++commidi_1.imidi[*icm];
		    commidi_1.mmidi[*icm + (commidi_1.imidi[*icm] << 4) - 16] 
			    = (shortint) itiesav[i__ + itk[isav - 1] * 5 - 6];
/* L17: */
		}
/* L15: */
	    }
	}
	comslm_1.slmon[*icm] = FALSE_;
	comslm_1.levsoff[*icm] = 0;
	if (! comslm_1.dbltie) {
	    comslm_1.levson[*icm] = 0;
	}
    }
    if (comslm_1.levson[*icm] > 0) {
	comslm_1.slmon[*icm] = TRUE_;
    }
    if (commidi_1.nmidcrd > 0) {
	commidi_1.nmidcrd = 0;
    }
    return 0;
} /* addmidi_ */

integer igetvarlen_(mmidi, icm, imidi, nbytes)
shortint *mmidi;
integer *icm, *imidi, *nbytes;
{
    /* System generated locals */
    integer ret_val;

    /* Builtin functions */
    integer s_wsle(), do_lio(), e_wsle();
    /* Subroutine */ int s_stop();

    /* Fortran I/O blocks */
    static cilist io___1357 = { 0, 6, 0, 0, 0 };



/*  Gets variable-length integer starting in mmidi at imidi+1. Returns nbytes. */

    /* Parameter adjustments */
    mmidi -= 16;

    /* Function Body */
    ret_val = 0;
    for (*nbytes = 1; *nbytes <= 4; ++(*nbytes)) {
	ret_val = (ret_val << 7) + (127 & mmidi[*icm + (*imidi + *nbytes << 4)
		]);
/*     *               +iand(127,longi(mmidi(icm,imidi+nbytes))) */
	if (! bit_test(mmidi[*icm + (*imidi + *nbytes << 4)],7)) {
	    return ret_val;
	}
/*        if (.not.btest(longi(mmidi(icm,imidi+nbytes)),7)) return */
/* L1: */
    }
    s_wsle(&io___1357);
    do_lio(&c__9, &c__1, "Messup in igetvarlen", (ftnlen)20);
    e_wsle();
    s_stop("1", (ftnlen)1);
    return ret_val;
} /* igetvarlen_ */

integer isetvarlen_(idur, nbytes)
integer *idur, *nbytes;
{
    /* System generated locals */
    integer ret_val, i__1;

    /* Builtin functions */
    integer pow_ii(), lbit_shift(), s_wsle(), do_lio(), e_wsle();
    /* Subroutine */ int s_stop();

    /* Local variables */
    static integer itemp;

    /* Fortran I/O blocks */
    static cilist io___1359 = { 0, 6, 0, 0, 0 };


    ret_val = 0;
    itemp = *idur;
    for (*nbytes = 1; *nbytes <= 4; ++(*nbytes)) {
	i__1 = *nbytes - 1;
	ret_val += (itemp & 127) * pow_ii(&c__256, &i__1);
	itemp = lbit_shift(itemp, (ftnlen)-7);
	if (itemp > 0) {
	    i__1 = (*nbytes << 3) + 7;
	    ret_val += pow_ii(&c__2, &i__1);
	} else {
	    return ret_val;
	}
/* L1: */
    }
    s_wsle(&io___1359);
    do_lio(&c__9, &c__1, "Problem in function isetvarlen", (ftnlen)30);
    e_wsle();
    s_stop("1", (ftnlen)1);
    return ret_val;
} /* isetvarlen_ */



/* Subroutine */ int writemidi_(jobname, ljob, jobname_len)
char *jobname;
integer *ljob;
ftnlen jobname_len;
{
    /* System generated locals */
    address a__1[4], a__2[7], a__3[8], a__4[2];
    integer i__1[4], i__2, i__3[7], i__4, i__5[8], i__6[2], i__7;
    char ch__1[14], ch__2[1], ch__3[12], ch__4[1], ch__5[1], ch__6[11], ch__7[
	    4], ch__8[25];
    cllist cl__1;

    /* Builtin functions */
    integer s_wsfe();
    /* Subroutine */ int s_cat();
    integer do_fio(), e_wsfe(), s_wsle(), do_lio(), e_wsle();
    /* Subroutine */ int s_stop();
    integer lbit_shift(), s_wsfi(), e_wsfi(), f_clos();

    /* Local variables */
    static integer i__, kv, ib0, ib1, icm, ivt;
    extern /* Character */ VOID chax_();
    static integer isec, mend, ivtt, ndata, ibyte;
    static char byteq[1*4];
    static integer iinst;
    static char instq[10];
    static shortint iinsiv[15];
    static char tempoq[10];
    extern /* Subroutine */ int printl_();
    static integer nstaves;

    /* Fortran I/O blocks */
    static cilist io___1360 = { 0, 51, 0, "(a,$)", 0 };
    static cilist io___1365 = { 0, 51, 0, "(a,$)", 0 };
    static cilist io___1366 = { 0, 51, 0, "(a,$)", 0 };
    static cilist io___1367 = { 0, 51, 0, "(a,$)", 0 };
    static cilist io___1370 = { 0, 51, 0, "(a,$)", 0 };
    static cilist io___1371 = { 0, 51, 0, "(a,$)", 0 };
    static cilist io___1378 = { 0, 6, 0, 0, 0 };
    static cilist io___1382 = { 0, 51, 0, "(a,$)", 0 };
    static cilist io___1383 = { 0, 51, 0, "(a,$)", 0 };
    static cilist io___1384 = { 0, 51, 0, "(a,$)", 0 };
    static icilist io___1386 = { 0, tempoq, 0, "(i2)", 10, 1 };
    static icilist io___1388 = { 0, instq, 0, "(i3)", 10, 1 };
    static cilist io___1389 = { 0, 51, 0, "(a,$)", 0 };
    static cilist io___1390 = { 0, 51, 0, "(a,$)", 0 };
    static cilist io___1391 = { 0, 6, 0, "(1x,a12,12i6)", 0 };
    static cilist io___1392 = { 0, 15, 0, "(1x,a12,12i6)", 0 };



/*  Write Header */

    s_wsfe(&io___1360);
/* Writing concatenation */
    i__1[0] = 11, a__1[0] = "MThd\000\000\000\006\000\001\000";
    *(unsigned char *)&ch__2[0] = commidi_1.numchan + 1;
    i__1[1] = 1, a__1[1] = ch__2;
    i__1[2] = 1, a__1[2] = "\000";
    i__1[3] = 1, a__1[3] = "\360";
    s_cat(ch__1, a__1, i__1, &c__4, (ftnlen)14);
    do_fio(&c__1, ch__1, (ftnlen)14);
    e_wsfe();
/* c */
/* c  Setup for tempos, in case none was given.  This may not be adequate */
/* c */
/*      if (imidi(numchan) .eq. 0) call midievent('t',96,0) */

/*  Write the "conductor" track, for keys, meter, and tempos */
/*  Get the number of bytes in the conductor event stream */

    ndata = commidi_1.imidi[commidi_1.numchan] + 1 - commmac_1.msecstrt[
	    commidi_1.numchan + (commmac_1.nmidsec << 4) - 16];
    i__2 = commmac_1.nmidsec - 1;
    for (isec = 1; isec <= i__2; ++isec) {
	ndata = ndata + 1 + commmac_1.msecend[commidi_1.numchan + (isec << 4) 
		- 16] - commmac_1.msecstrt[commidi_1.numchan + (isec << 4) - 
		16];
/* L15: */
    }
    ib1 = (*ljob + 30 + ndata + 4) / 256;
    ib0 = *ljob + 30 + ndata + 4 - (ib1 << 8);
    s_wsfe(&io___1365);
/* Writing concatenation */
    i__3[0] = 6, a__2[0] = "MTrk\000\000";
    *(unsigned char *)&ch__2[0] = ib1;
    i__3[1] = 1, a__2[1] = ch__2;
    *(unsigned char *)&ch__4[0] = ib0;
    i__3[2] = 1, a__2[2] = ch__4;
    i__3[3] = 1, a__2[3] = "\000";
    i__3[4] = 1, a__2[4] = "\377";
    i__3[5] = 1, a__2[5] = "\001";
    *(unsigned char *)&ch__5[0] = *ljob + 26;
    i__3[6] = 1, a__2[6] = ch__5;
    s_cat(ch__3, a__2, i__3, &c__7, (ftnlen)12);
    do_fio(&c__1, ch__3, (ftnlen)12);
    e_wsfe();

/*  Text header */

    s_wsfe(&io___1366);
    do_fio(&c__1, jobname, (*ljob));
    e_wsfe();

/*  (separate writes are needed to defeat compiler BUG!!!) */

    s_wsfe(&io___1367);
    do_fio(&c__1, ".mid, produced by PMX 2.19", (ftnlen)26);
    e_wsfe();

/*  Conductor event data: Loop over sections. */

    i__2 = commmac_1.nmidsec;
    for (isec = 1; isec <= i__2; ++isec) {
	if (isec < commmac_1.nmidsec) {
	    mend = commmac_1.msecend[commidi_1.numchan + (isec << 4) - 16];
	} else {
	    mend = commidi_1.imidi[commidi_1.numchan];
	}
	i__4 = mend;
	for (i__ = commmac_1.msecstrt[commidi_1.numchan + (isec << 4) - 16]; 
		i__ <= i__4; ++i__) {
	    s_wsfe(&io___1370);
	    *(unsigned char *)&ch__2[0] = (char) commidi_1.mmidi[
		    commidi_1.numchan + (i__ << 4) - 16];
	    do_fio(&c__1, ch__2, (ftnlen)1);
	    e_wsfe();
/* L17: */
	}
/* L16: */
    }

/*  And close out the time sig / tempo track. */

    s_wsfe(&io___1371);
    do_fio(&c__1, "\000\377/\000", (ftnlen)4);
    e_wsfe();

/*  Loop over track for each voice:  The following sets up iv. */

    all_1.iv = all_1.nv;
    if (commidi_1.twoline[all_1.nv - 1]) {
	kv = 2;
    } else {
	kv = 1;
    }

/*  Count up staves(iv,nv) vs instruments.  Store instr# for iv in iinsiv(iv) */

    nstaves = 0;
    ivt = 0;
    for (iinst = 1; iinst <= 15; ++iinst) {
	nstaves += comnvi_1.nsperi[iinst - 1];
	i__2 = comnvi_1.nsperi[iinst - 1];
	for (ivtt = 1; ivtt <= i__2; ++ivtt) {
	    ++ivt;
	    iinsiv[ivt - 1] = (shortint) iinst;
/* L13: */
	}
	if (nstaves == all_1.nv) {
	    goto L14;
	}
/* L12: */
    }
    s_wsle(&io___1378);
    do_lio(&c__9, &c__1, "Screwup!", (ftnlen)8);
    e_wsle();
    s_stop("1", (ftnlen)1);
L14:

    i__2 = commidi_1.numchan - 1;
    for (icm = 0; icm <= i__2; ++icm) {

/*  Get the number of bytes in the data stream */

	ndata = commidi_1.imidi[icm] + 1 - commmac_1.msecstrt[icm + (
		commmac_1.nmidsec << 4) - 16];
	i__4 = commmac_1.nmidsec - 1;
	for (isec = 1; isec <= i__4; ++isec) {
	    ndata = ndata + 1 + commmac_1.msecend[icm + (isec << 4) - 16] - 
		    commmac_1.msecstrt[icm + (isec << 4) - 16];
/* L11: */
	}

/*  Add 3 (for instrum) plus 4 (for closing) to byte count, */

	ndata += 7;

/*  Add 4+lnam(iinsiv(iv)) if lnam>0 , */

	if (comtop_1.lnam[iinsiv[all_1.iv - 1] - 1] > 0) {
	    ndata = ndata + 4 + comtop_1.lnam[iinsiv[all_1.iv - 1] - 1];
	}

/*  Separate total byte counts into 4 bytes */

	for (ibyte = 1; ibyte <= 4; ++ibyte) {
	    if (ndata > 0) {
		*(unsigned char *)&byteq[ibyte - 1] = (char) (ndata % 256);
		ndata = lbit_shift(ndata, (ftnlen)-8);
	    } else {
		*(unsigned char *)&byteq[ibyte - 1] = '\0';
	    }
/* L2: */
	}

/*  Now write front stuff for this track */

	s_wsfe(&io___1382);
/* Writing concatenation */
	i__5[0] = 4, a__3[0] = "MTrk";
	i__5[1] = 1, a__3[1] = byteq + 3;
	i__5[2] = 1, a__3[2] = byteq + 2;
	i__5[3] = 1, a__3[3] = byteq + 1;
	i__5[4] = 1, a__3[4] = byteq;
	i__5[5] = 1, a__3[5] = "\000";
	*(unsigned char *)&ch__2[0] = icm + 192;
	i__5[6] = 1, a__3[6] = ch__2;
	*(unsigned char *)&ch__4[0] = commidi_1.midinst[all_1.iv - 1];
	i__5[7] = 1, a__3[7] = ch__4;
	s_cat(ch__6, a__3, i__5, &c__8, (ftnlen)11);
	do_fio(&c__1, ch__6, (ftnlen)11);
	e_wsfe();
	if (comtop_1.lnam[iinsiv[all_1.iv - 1] - 1] > 0) {

/*  Add instrument name as sequence name */

	    s_wsfe(&io___1383);
/* Writing concatenation */
	    i__6[0] = 3, a__4[0] = "\000\377\003";
	    *(unsigned char *)&ch__2[0] = comtop_1.lnam[iinsiv[all_1.iv - 1] 
		    - 1];
	    i__6[1] = 1, a__4[1] = ch__2;
	    s_cat(ch__7, a__4, i__6, &c__2, (ftnlen)4);
	    do_fio(&c__1, ch__7, (ftnlen)4);
	    e_wsfe();
	    s_wsfe(&io___1384);
	    do_fio(&c__1, comtop_1.inameq + (iinsiv[all_1.iv - 1] - 1) * 79, 
		    comtop_1.lnam[iinsiv[all_1.iv - 1] - 1]);
	    e_wsfe();
	}
	s_wsfi(&io___1386);
	do_fio(&c__1, (char *)&icm, (ftnlen)sizeof(integer));
	e_wsfi();
	s_wsfi(&io___1388);
	do_fio(&c__1, (char *)&commidi_1.midinst[all_1.iv - 1], (ftnlen)
		sizeof(integer));
	e_wsfi();
/* Writing concatenation */
	i__1[0] = 16, a__1[0] = "MIDI instrument ";
	i__1[1] = 2, a__1[1] = tempoq;
	i__1[2] = 4, a__1[2] = " is ";
	i__1[3] = 3, a__1[3] = instq;
	s_cat(ch__8, a__1, i__1, &c__4, (ftnlen)25);
	printl_(ch__8, (ftnlen)25);

/*  Notes: Loop over sections. */

	i__4 = commmac_1.nmidsec;
	for (isec = 1; isec <= i__4; ++isec) {
	    if (isec < commmac_1.nmidsec) {
		mend = commmac_1.msecend[icm + (isec << 4) - 16];
	    } else {
		mend = commidi_1.imidi[icm];
	    }
	    i__7 = mend;
	    for (i__ = commmac_1.msecstrt[icm + (isec << 4) - 16]; i__ <= 
		    i__7; ++i__) {
		s_wsfe(&io___1389);
		*(unsigned char *)&ch__2[0] = (char) commidi_1.mmidi[icm + (
			i__ << 4) - 16];
		do_fio(&c__1, ch__2, (ftnlen)1);
		e_wsfe();
/* L10: */
	    }
/* L9: */
	}

/*  Closing 4 bytes */

	s_wsfe(&io___1390);
/* Writing concatenation */
	chax_(ch__2, (ftnlen)1, &c__0);
	i__1[0] = 1, a__1[0] = ch__2;
	i__1[1] = 1, a__1[1] = "\377";
	i__1[2] = 1, a__1[2] = "/";
	i__1[3] = 1, a__1[3] = "\000";
	s_cat(ch__7, a__1, i__1, &c__4, (ftnlen)4);
	do_fio(&c__1, ch__7, (ftnlen)4);
	e_wsfe();
	if (kv == 2) {
	    kv = 1;
	} else if (all_1.iv == 1) {
	    goto L5;
	} else {
	    --all_1.iv;
	    if (commidi_1.twoline[all_1.iv - 1]) {
		kv = 2;
	    }
	}
L5:
	;
    }
    s_wsfe(&io___1391);
    do_fio(&c__1, "Bytes used:", (ftnlen)11);
    i__2 = commidi_1.numchan;
    for (icm = 0; icm <= i__2; ++icm) {
	do_fio(&c__1, (char *)&commidi_1.imidi[icm], (ftnlen)sizeof(integer));
    }
    e_wsfe();
    s_wsfe(&io___1392);
    do_fio(&c__1, "Bytes used:", (ftnlen)11);
    i__2 = commidi_1.numchan;
    for (icm = 0; icm <= i__2; ++icm) {
	do_fio(&c__1, (char *)&commidi_1.imidi[icm], (ftnlen)sizeof(integer));
    }
    e_wsfe();
    cl__1.cerr = 0;
    cl__1.cunit = 51;
    cl__1.csta = 0;
    f_clos(&cl__1);
    return 0;
} /* writemidi_ */

/* Subroutine */ int getmidi_(nv, lineq, iccount, ibarcnt, ibaroff, nbars, 
	lenbar, mtrdenl, first, lineq_len)
integer *nv;
char *lineq;
integer *iccount, *ibarcnt, *ibaroff, *nbars, *lenbar, *mtrdenl;
logical *first;
ftnlen lineq_len;
{
    /* Initialized data */

    static shortint midinum[26] = { 1,5,7,13,20,25,33,41,42,43,44,57,58,59,61,
	    65,66,67,68,69,71,72,74,75,8,55 };

    /* System generated locals */
    address a__1[2];
    integer i__1, i__2[2], i__3, i__4;
    real r__1;

    /* Builtin functions */
    integer i_indx();
    /* Subroutine */ int s_stop();
    integer i_nint();
    /* Subroutine */ int s_cat();

    /* Local variables */
    static integer icm;
    static real qpm;
    static integer ivx;
    static real fnum;
    static char durq[1];
    static integer iname, numb16;
    static char instq[2];
    extern /* Subroutine */ int errmsg_(), addmidi_(), getchar_(), readnum_();
    static real pausemid;
    extern /* Subroutine */ int midievent_();


/*  Use this from both pmxa and pmxb to input and check midi data. "first" tells */
/*  whether pmxa or pmxb.  If .not.first, then tempo and pause commands cause */
/*  things to be written immediately into the midi storage buffers. */


/*  immac(i) is the index of i-th macro, i=1,nmac.  Also make a list containing */
/*   nmidsec  section starts and stops based on PLAYING macros (not recording). */


/*      Instrument codes */

/*         XXpiXrhXhaXmaXorXguXabXvlXvaXvcXcbXtrXtbXtuXfrXsoXalXteX */

/*           bsXobXbaXclXflXreXctXvo */

L1:
    getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
    if (*(unsigned char *)durq == 't') {

/*  Tempo in beats ber minute */

	getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	if (i_indx("0123456789", durq, (ftnlen)10, (ftnlen)1) == 0) {
	    i__1 = *ibarcnt - *ibaroff + *nbars + 1;
	    errmsg_(lineq, iccount, &i__1, "Expected an integer here for the\
 pause!", (ftnlen)128, (ftnlen)39);
	    s_stop("1", (ftnlen)1);
	} else if (commmac_1.mmacrec) {
	    i__1 = *ibarcnt - *ibaroff + *nbars + 1;
	    errmsg_(lineq, iccount, &i__1, "Cannot change MIDI tempo while r\
ecording a MidiMacro!", (ftnlen)128, (ftnlen)53);
	    s_stop("1", (ftnlen)1);
	}
	readnum_(lineq, iccount, durq, &qpm, (ftnlen)128, (ftnlen)1);
	--(*iccount);
	if (! (*first)) {
	    i__1 = i_nint(&qpm);
	    midievent_("t", &i__1, &c__0, (ftnlen)1);
	    commmac_1.gottempo = TRUE_;
	}
	goto L1;
    } else if (*(unsigned char *)durq == 'p') {

/*  Insert a pause.  pausemid = pause in 1/4's */

	getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	if (i_indx("0123456789.", durq, (ftnlen)11, (ftnlen)1) == 0) {
	    i__1 = *ibarcnt - *ibaroff + *nbars + 1;
	    errmsg_(lineq, iccount, &i__1, "Expected a number here for the p\
ause!", (ftnlen)128, (ftnlen)37);
	    s_stop("1", (ftnlen)1);
	}
	readnum_(lineq, iccount, durq, &pausemid, (ftnlen)128, (ftnlen)1);
	--(*iccount);
	if (! (*first)) {

/*  Compute a meter for the pause.  This is only to keep MidiNotate on track. */
/*  Round pause to nearest 16th.  Let denominator always be 16. */

	    r__1 = pausemid * 4;
	    numb16 = i_nint(&r__1);
	    midievent_("m", &numb16, &c__16, (ftnlen)1);

/*  Put in pausemid beats of rest */

	    i__1 = commidi_1.numchan - 1;
	    for (icm = 0; icm <= i__1; ++icm) {
		r__1 = numb16 * (float)4.;
		addmidi_(&icm, &c__0, &c__0, &c__0, &r__1, &c_true, &c_false);
/* L3: */
	    }
	    r__1 = pausemid * 240;
	    comevent_1.miditime += i_nint(&r__1);

/*  Restore meter */

	    i__1 = *mtrdenl * *lenbar / 64;
	    midievent_("m", &i__1, mtrdenl, (ftnlen)1);
	}
	goto L1;
    } else if (*(unsigned char *)durq == 'i') {

/*  Instrument numbers or letters.  Expect nv of them. */

	i__1 = *nv;
	for (ivx = 1; ivx <= i__1; ++ivx) {
	    getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (*(unsigned char *)durq > 96) {

/*  It's a lowercase letter.  Get another, find corr. instrument #. */

		*(unsigned char *)instq = *(unsigned char *)durq;
		getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
/* Writing concatenation */
		i__2[0] = 1, a__1[0] = instq;
		i__2[1] = 1, a__1[1] = durq;
		s_cat(instq, a__1, i__2, &c__2, (ftnlen)2);
		iname = i_indx("XXpiXrhXhaXmaXorXguXabXvlXvaXvcXcbXtrXtbXtuX\
frXsoXalXteXbsXobXbaXclXflXreXctXvo", instq, (ftnlen)79, (ftnlen)2) / 3;
		if (iname == 0) {
		    i__3 = *ibarcnt - *ibaroff + *nbars + 1;
		    errmsg_(lineq, iccount, &i__3, "Unrecognized 2-letter mi\
di instrument name!", (ftnlen)128, (ftnlen)43);
		    s_stop("1", (ftnlen)1);
		}
		commidi_1.midinst[ivx - 1] = midinum[iname - 1] - 1;
	    } else {

/*  Expect a number, followed by ":" if that is followed by another number. */
/*  I.e., if after call to readnum, durq is not ":", it must be either blank */
/*  or next instrument letter. */

		if (i_indx("123456789", durq, (ftnlen)9, (ftnlen)1) == 0) {
		    i__3 = *ibarcnt - *ibaroff + *nbars + 1;
		    errmsg_(lineq, iccount, &i__3, "Expected a midi instrume\
nt number here!", (ftnlen)128, (ftnlen)39);
		    s_stop("1", (ftnlen)1);
		}
		readnum_(lineq, iccount, durq, &fnum, (ftnlen)128, (ftnlen)1);
		commidi_1.midinst[ivx - 1] = i_nint(&fnum) - 1;
		if (commidi_1.midinst[ivx - 1] < 0 || commidi_1.midinst[ivx - 
			1] > 255) {
		    i__3 = *iccount - 1;
		    i__4 = *ibarcnt - *ibaroff + *nbars + 1;
		    errmsg_(lineq, &i__3, &i__4, "Midi instrument number mus\
t be in range 1-128!", (ftnlen)128, (ftnlen)46);
		    s_stop("1", (ftnlen)1);
		}
		if (*(unsigned char *)durq != ':') {
		    --(*iccount);
		}
	    }
/* L2: */
	}
	goto L1;
    } else if (*(unsigned char *)durq == 'g') {
	getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	if (i_indx("0123456789", durq, (ftnlen)10, (ftnlen)1) == 0) {
	    i__1 = *ibarcnt - *ibaroff + *nbars + 1;
	    errmsg_(lineq, iccount, &i__1, "Expected an integer here for the\
 midi gap!", (ftnlen)128, (ftnlen)42);
	    s_stop("1", (ftnlen)1);
	}
	readnum_(lineq, iccount, durq, &fnum, (ftnlen)128, (ftnlen)1);
	commidi_1.mgap = i_nint(&fnum);
	--(*iccount);
	goto L1;
    } else if (*(unsigned char *)durq == 'M') {

/*  MidiMacros */

	getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	if (*(unsigned char *)durq == 'R') {

/*  Start recording */

	    if (commmac_1.mmacrec) {
		i__1 = *ibarcnt - *ibaroff + *nbars + 1;
		errmsg_(lineq, iccount, &i__1, "You tried to record a MidiMa\
cro while already recording!", (ftnlen)128, (ftnlen)56);
		s_stop("1", (ftnlen)1);
	    }
	    commmac_1.mmacrec = TRUE_;
	    getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (i_indx("123456789", durq, (ftnlen)9, (ftnlen)1) == 0) {
		i__1 = *ibarcnt - *ibaroff + *nbars + 1;
		errmsg_(lineq, iccount, &i__1, "Expected MidiMacro ID number\
 here!", (ftnlen)128, (ftnlen)34);
		s_stop("1", (ftnlen)1);
	    }
	    readnum_(lineq, iccount, durq, &fnum, (ftnlen)128, (ftnlen)1);
	    --(*iccount);
	    if (! (*first)) {
		commmac_1.immac = i_nint(&fnum);
		if (commmac_1.immac > 20) {
		    i__1 = *ibarcnt - *ibaroff + *nbars + 1;
		    errmsg_(lineq, iccount, &i__1, "MidiMacro ID cannot exce\
ed 20!", (ftnlen)128, (ftnlen)30);
		    s_stop("1", (ftnlen)1);
		}

/*  Save the start time */

		commmac_1.mmactime[commmac_1.immac - 1] = comevent_1.miditime;
		i__1 = commidi_1.numchan;
		for (icm = 0; icm <= i__1; ++icm) {
		    if (icm < commidi_1.numchan) {
			if (commidi_1.restpend[icm]) {

/*  Adjust if there's a rest at end of prior section.  Insert dummy turnoff. */
/*    (This causes two turn-offs in a row, which testmidi sees as an error). */

/*  Before:    section1  ------rest-------  section2(to be recorded) */
/*  After:     section1  rest1  now  rest2  section2(recorded) */

			    addmidi_(&icm, &c__30, &c__0, &c__0, &
				    commidi_1.trest[icm], &c_false, &c_true);
			    commidi_1.trest[icm] = (float)0.;
			    commidi_1.restpend[icm] = FALSE_;
			}
		    } else {
			if (comevent_1.miditime > comevent_1.lasttime) {

/*  Insert a dummy turnoff in conductor track */

			    r__1 = (comevent_1.miditime - comevent_1.lasttime)
				     / (float)15.;
			    addmidi_(&icm, &c__30, &c__0, &c__0, &r__1, &
				    c_false, &c_true);
			    comevent_1.lasttime = comevent_1.miditime;
			}
		    }
		    commmac_1.mmacstrt[icm + (commmac_1.immac << 4) - 16] = 
			    commidi_1.imidi[icm] + 1;
/* L4: */
		}
	    }
	    goto L1;
	} else if (i_indx("123456789P", durq, (ftnlen)10, (ftnlen)1) == 0) {

/*  End recording; close the open macro.  Get immac from common. */

	    if (! commmac_1.mmacrec) {
		i__1 = *iccount - 1;
		i__3 = *ibarcnt - *ibaroff + *nbars + 1;
		errmsg_(lineq, &i__1, &i__3, "You tried to end a MidiMacro b\
efore starting one!", (ftnlen)128, (ftnlen)49);
		s_stop("1", (ftnlen)1);
	    }
	    commmac_1.mmacrec = FALSE_;
	    --(*iccount);
	    if (! (*first)) {

/*  Save the macro duration */

		commmac_1.mmactime[commmac_1.immac - 1] = comevent_1.miditime 
			- commmac_1.mmactime[commmac_1.immac - 1];
		i__1 = commidi_1.numchan;
		for (icm = 0; icm <= i__1; ++icm) {
		    if (icm < commidi_1.numchan) {
			if (commidi_1.restpend[icm]) {
			    addmidi_(&icm, &c__30, &c__0, &c__0, &
				    commidi_1.trest[icm], &c_false, &c_true);
			    commidi_1.trest[icm] = (float)0.;
			    commidi_1.restpend[icm] = FALSE_;
			}
		    } else {
			if (comevent_1.miditime > comevent_1.lasttime) {

/*  Insert a dummy turnoff in conductor track if needed. */

			    r__1 = (comevent_1.miditime - comevent_1.lasttime)
				     / (float)15.;
			    addmidi_(&icm, &c__30, &c__0, &c__0, &r__1, &
				    c_false, &c_true);
			    comevent_1.lasttime = comevent_1.miditime;
			}
		    }
		    commmac_1.mmacend[icm + (commmac_1.immac << 4) - 16] = 
			    commidi_1.imidi[icm];
/* L5: */
		}
	    }
	    if (*(unsigned char *)durq != ' ') {
		goto L1;
	    }
	} else if (*(unsigned char *)durq == 'P') {

/*  Play Back a Macro */

	    getchar_(lineq, iccount, durq, (ftnlen)128, (ftnlen)1);
	    if (i_indx("123456789", durq, (ftnlen)9, (ftnlen)1) == 0) {
		i__1 = *ibarcnt - *ibaroff + *nbars + 1;
		errmsg_(lineq, iccount, &i__1, "Expected MidiMacro ID number\
 here!", (ftnlen)128, (ftnlen)34);
		s_stop("1", (ftnlen)1);
	    }
	    if (commmac_1.mmacrec) {
		i__1 = *ibarcnt - *ibaroff + *nbars + 1;
		errmsg_(lineq, iccount, &i__1, "You tried to play a MidiMacr\
o before ending recording!", (ftnlen)128, (ftnlen)54);
		s_stop("1", (ftnlen)1);
	    }
	    readnum_(lineq, iccount, durq, &fnum, (ftnlen)128, (ftnlen)1);
	    --(*iccount);
	    if (! (*first)) {
		commmac_1.immac = i_nint(&fnum);
		if (commmac_1.mmactime[commmac_1.immac - 1] == 0) {
		    i__1 = *ibarcnt - *ibaroff + *nbars + 1;
		    errmsg_(lineq, iccount, &i__1, "Cannot play a MIDI macro\
 before recording it!", (ftnlen)128, (ftnlen)45);
		    s_stop("1", (ftnlen)1);
		}
		i__1 = commidi_1.numchan;
		for (icm = 0; icm <= i__1; ++icm) {
		    if (icm < commidi_1.numchan) {
			if (commidi_1.restpend[icm]) {
			    addmidi_(&icm, &c__30, &c__0, &c__0, &
				    commidi_1.trest[icm], &c_false, &c_true);
			    commidi_1.trest[icm] = (float)0.;
			    commidi_1.restpend[icm] = FALSE_;
			}
		    } else {
			if (comevent_1.miditime > comevent_1.lasttime) {

/*  Insert a dummy turnoff in conductor track */

			    r__1 = (comevent_1.miditime - comevent_1.lasttime)
				     / (float)15.;
			    addmidi_(&icm, &c__30, &c__0, &c__0, &r__1, &
				    c_false, &c_true);
			}
		    }
		    commmac_1.msecend[icm + (commmac_1.nmidsec << 4) - 16] = 
			    commidi_1.imidi[icm];
		    commmac_1.msecstrt[icm + (commmac_1.nmidsec + 1 << 4) - 
			    16] = commmac_1.mmacstrt[icm + (commmac_1.immac <<
			     4) - 16];
		    commmac_1.msecend[icm + (commmac_1.nmidsec + 1 << 4) - 16]
			     = commmac_1.mmacend[icm + (commmac_1.immac << 4) 
			    - 16];
		    commmac_1.msecstrt[icm + (commmac_1.nmidsec + 2 << 4) - 
			    16] = commidi_1.imidi[icm] + 1;
/* L6: */
		}
		commmac_1.nmidsec += 2;

/*  Update running time */

		comevent_1.miditime += commmac_1.mmactime[commmac_1.immac - 1]
			;
		comevent_1.lasttime = comevent_1.miditime;
	    }
	    goto L1;
	} else {
	    i__1 = *ibarcnt - *ibaroff + *nbars + 1;
	    errmsg_(lineq, iccount, &i__1, "Illegal character in MidiMacro s\
ub-command!", (ftnlen)128, (ftnlen)43);
	    s_stop("1", (ftnlen)1);
	}
    } else if (*(unsigned char *)durq != ' ') {
	i__1 = *ibarcnt - *ibaroff + *nbars + 1;
	errmsg_(lineq, iccount, &i__1, "Illegal character in MIDI input data!"
		, (ftnlen)128, (ftnlen)37);
	s_stop("1", (ftnlen)1);
    }
    if (! commmac_1.gottempo && ! (*first)) {

/*  If no tempo is set on first call on the pmxb pass, then set it */

	midievent_("t", &c__96, &c__0, (ftnlen)1);
	commmac_1.gottempo = TRUE_;
    }
    return 0;
} /* getmidi_ */

/* Subroutine */ int chkimidi_(icm)
integer *icm;
{
    /* Builtin functions */
    integer s_wsle(), e_wsle(), do_lio(), s_wsfe(), do_fio(), e_wsfe();

    /* Fortran I/O blocks */
    static cilist io___1403 = { 0, 6, 0, 0, 0 };
    static cilist io___1404 = { 0, 6, 0, 0, 0 };
    static cilist io___1405 = { 0, 6, 0, "(a6,2x,4i8)", 0 };


    if (commidi_1.imidi[*icm] >= 24576) {
	s_wsle(&io___1403);
	e_wsle();
	s_wsle(&io___1404);
	do_lio(&c__9, &c__1, "Midi file is too long! It will be corrupted or\
 worse", (ftnlen)52);
	e_wsle();
	s_wsfe(&io___1405);
	do_fio(&c__1, "imidi:", (ftnlen)6);
	do_fio(&c__1, (char *)&commidi_1.imidi[0], (ftnlen)sizeof(integer));
	do_fio(&c__1, (char *)&commidi_1.imidi[1], (ftnlen)sizeof(integer));
	do_fio(&c__1, (char *)&commidi_1.imidi[2], (ftnlen)sizeof(integer));
	do_fio(&c__1, (char *)&commidi_1.imidi[3], (ftnlen)sizeof(integer));
	e_wsfe();
    }
    return 0;
} /* chkimidi_ */

/* Subroutine */ int midievent_(typeq, in1, in2, typeq_len)
char *typeq;
integer *in1, *in2;
ftnlen typeq_len;
{
    /* System generated locals */
    integer i__1;
    real r__1;

    /* Builtin functions */
    integer lbit_shift(), i_nint(), s_wsle(), do_lio(), e_wsle();
    /* Subroutine */ int s_stop();

    /* Local variables */
    static integer i__;
    extern integer log2_();
    static integer idur, nbytes, misperq;
    extern integer isetvarlen_();

    /* Fortran I/O blocks */
    static cilist io___1410 = { 0, 6, 0, 0, 0 };



/*  We now store "conductor" events in mmidi(numchan,.), and count bytes */
/*    with imidi(numchan) */

    i__1 = comevent_1.miditime - comevent_1.lasttime;
    idur = isetvarlen_(&i__1, &nbytes);
    commidi_1.imidi[commidi_1.numchan] = commidi_1.imidi[commidi_1.numchan] + 
	    nbytes + 1;
    i__1 = nbytes;
    for (i__ = 1; i__ <= i__1; ++i__) {
	commidi_1.mmidi[commidi_1.numchan + (commidi_1.imidi[
		commidi_1.numchan] - i__ << 4) - 16] = (shortint) (idur % 256)
		;
	idur = lbit_shift(idur, (ftnlen)-8);
/* L1: */
    }
    commidi_1.mmidi[commidi_1.numchan + (commidi_1.imidi[commidi_1.numchan] <<
	     4) - 16] = 255;
    if (*(unsigned char *)typeq == 't') {

/*  Tempo event.  in1 = quarters per minute (integer) */

	commidi_1.mmidi[commidi_1.numchan + (commidi_1.imidi[
		commidi_1.numchan] + 1 << 4) - 16] = 81;
	commidi_1.mmidi[commidi_1.numchan + (commidi_1.imidi[
		commidi_1.numchan] + 2 << 4) - 16] = 3;
	r__1 = (float)6e7 / *in1;
	misperq = i_nint(&r__1);
	for (i__ = 1; i__ <= 3; ++i__) {
	    commidi_1.mmidi[commidi_1.numchan + (commidi_1.imidi[
		    commidi_1.numchan] + 6 - i__ << 4) - 16] = (shortint) (
		    misperq % 256);
	    misperq = lbit_shift(misperq, (ftnlen)-8);
/* L2: */
	}
	commidi_1.imidi[commidi_1.numchan] += 5;
    } else if (*(unsigned char *)typeq == 'm') {

/*  Meter event.  in1=numerator, in2=denom (power of 2) */

	commidi_1.mmidi[commidi_1.numchan + (commidi_1.imidi[
		commidi_1.numchan] + 1 << 4) - 16] = 88;
	commidi_1.mmidi[commidi_1.numchan + (commidi_1.imidi[
		commidi_1.numchan] + 2 << 4) - 16] = 4;
	commidi_1.mmidi[commidi_1.numchan + (commidi_1.imidi[
		commidi_1.numchan] + 3 << 4) - 16] = (shortint) (*in1);
	if (*in2 > 0) {
	    commidi_1.mmidi[commidi_1.numchan + (commidi_1.imidi[
		    commidi_1.numchan] + 4 << 4) - 16] = (shortint) log2_(in2)
		    ;
	} else {
	    commidi_1.mmidi[commidi_1.numchan + (commidi_1.imidi[
		    commidi_1.numchan] + 4 << 4) - 16] = 0;
	}
	commidi_1.mmidi[commidi_1.numchan + (commidi_1.imidi[
		commidi_1.numchan] + 5 << 4) - 16] = 24;
	commidi_1.mmidi[commidi_1.numchan + (commidi_1.imidi[
		commidi_1.numchan] + 6 << 4) - 16] = 8;
	commidi_1.imidi[commidi_1.numchan] += 6;
    } else if (*(unsigned char *)typeq == 'k') {

/*  Keychange event.  in1 = isig */

	commidi_1.mmidi[commidi_1.numchan + (commidi_1.imidi[
		commidi_1.numchan] + 1 << 4) - 16] = 89;
	commidi_1.mmidi[commidi_1.numchan + (commidi_1.imidi[
		commidi_1.numchan] + 2 << 4) - 16] = 2;
	commidi_1.mmidi[commidi_1.numchan + (commidi_1.imidi[
		commidi_1.numchan] + 3 << 4) - 16] = (shortint) ((*in1 + 256) 
		% 256);
	commidi_1.mmidi[commidi_1.numchan + (commidi_1.imidi[
		commidi_1.numchan] + 4 << 4) - 16] = 0;
	commidi_1.imidi[commidi_1.numchan] += 4;
    } else {
	s_wsle(&io___1410);
	do_lio(&c__9, &c__1, "Program flameout in midievent", (ftnlen)29);
	e_wsle();
	s_stop("1", (ftnlen)1);
    }
    comevent_1.lasttime = comevent_1.miditime;
    return 0;
} /* midievent_ */

/*      integer*4 function longi(ishort) */
/*      integer*2 ishort */
/*      longi = ishort */
/*      return */
/*      end */
integer iashft_(nacc)
integer *nacc;
{
    /* Initialized data */

    static integer ias[6] = { -1,1,0,0,-2,2 };

    /* System generated locals */
    integer ret_val;

    ret_val = ias[(0 + (0 + (*nacc - 1 << 2))) / 4];
    return ret_val;
} /* iashft_ */

/* Main program alias */ int pmxab_ () { MAIN__ (); }
