Debian Codegraph @

utils/pmx/pmx-src/scor2prt.for

raw
1 cccccccccccccccccccccccccc
2 cc
3 cc scor2prt 2/19/16 for PMX 2.74
4 cccccccccccccccccccccccccc
5 c This program, developed by Don Simons ([email protected]), is
6 c part of the PMX distribution, PMX is a preprocessor for MusiXTeX. In concert
7 c with MusiXTeX and TeX, the purpose of PMX is to allow the user to create
8 c high-quality typeset musical scores by including a sequence of PMX commands
9 c in an ASCII input file. Scor2prt is an auxiliary program that creates PMX
10 c input files for individual parts from the PMX input file for the score.
11 c
12 c This program is free software: you can redistribute it and/or modify
13 c it under the terms of the GNU General Public License as published by
14 c the Free Software Foundation, either version 3 of the License, or
15 c (at your option) any later version.
16 c
17 c This program is distributed in the hope that it will be useful,
18 c but WITHOUT ANY WARRANTY; without even the implied warranty of
19 c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 c GNU General Public License for more details.
21 c
22 c You should have received a copy of the GNU General Public License
23 c along with this program. If not, see <http://www.gnu.org/licenses/>.
24 c
25 c 2/19/16
26 c Exit gracefully when last input line is comment, with mods in
27 c subroutine chkcom, adding logical argument goto999
28 c which is set to .true. in that case, causing input file to
29 c be closed after exiting.
30 c 4/9/12
31 c Add logical declarations to subroutine dosetup
32 c 8/8/11
33 c Copy & mod Ki into parts when after beginning.
34 c 7/18/11
35 c Start to fix up for AS..., also Ki was done a little earlier.
36 c 7/5/10
37 c Modify Manual to explain extended hex numbering for part-specific comments
38 c 5/16/10
39 c Extend part-specific comments for up to 24 parts (subroutine chkcom)
40 c Allow files 11-34 for parts
41 c Change file 30 to 40
42 c 6/1/08 es2p
43 c noimax = 24
44 c
45 c To do
46 c Override fracindent, musicsize?
47 c Deal with midbar R?
48 c 2/29/04
49 c Check for special character being in quoted string.
50 c 10/20/02 PMX 2.407
51 c Interpret AN[n]"[used-defined-part-file-name]"
52 c 1/21/02
53 c Deals with rm in multiple parts.
54 c s2p15
55 c Get right non-tex index even if there's "\" inside D"..."
56 c s2p14
57 c 10/29/00 fix transfer to parts of negative mtrdnp
58 c 4/29/00 screen for "%%" followed by "T"
59 c Restore change from "Version 2.1a, 21 Dec"
60 c s2p13
61 c Allow whole-bar double-whole rests.
62 c Bypass MIDI commands "I..." achar(10)="I"
63 c s2p12
64 c Let %ablabla ... %cblabla represent pmx input for parts 10-12. But %?blabla
65 c only taken as such if ? represents a hex digit .le. noinst, otherwise it's
66 c a simple comment. This lessens incompatibility.
67 c In subroutine mbrest, properly open parts 10-12 if needed
68 c s2p11
69 c Ignore leading blanks
70 c Fix undefined linelength in mbrest at very end of comments.
71 c s2p10
72 c Fix non-transfer of P..c" "
73 c Allow "%%" and "%"n anywhere
74 c Version 1.43
75 c Fix bug with P in TeX string.
76 c Ignore shifted whole-bar rests when consolidating whole-bar rests
77 c Copy type 4 TeX into all parts.
78 c Deal with XB and XP.
79 c Permit transfer of blank line into parts
80 c Change staves/inst in 'M' command.
81 c Arbitrary staves/inst.
82 c Recognize m1/2/3/4 syntax.
83 c Enable comment and one-voice syntax in instrument names
84 c
85 c Changes since 1.1
86 c Deal with saved macros.
87 c Revise setup readin, to admit comments.
88 c Do not copy 'X' into parts
89 c
90 cccccccccccccccccccccccccccccccccccccccccccccccc
91 parameter (noimax=24)
92 common /all/ noinow,iorig(noimax),noinst,insetup,replacing,
93 * instnum(noimax),botv(noimax),nvi(noimax),nsyst,nvnow
94 integer*4 ludpfn(noimax)
95 character*1 sq,achar(10)
96 character*2 termsym
97 character*27 jobname,infileq
98 character*128 instrum(noimax),udpfnq(noimax)
99 character*128 line,holdln,templine
100 logical termrpt,isachar,frstln,oneof2,botv,clefpend,fexist,
101 * insetup,replacing,gotname,yesodd,goto999
102 character*1 dumq
103 data achar /'P','m','V','R','A','h','w','K','M','I'/
104 clefpend = .false.
105 insetup = .true.
106 replacing = .false.
107 frstln = .true.
108 lenhold = 0
109 sq = char(92)
110 print*,'This is scor2prt for PMX 2.74, 19 February 2016'
111 numargs = iargc()
112 if (numargs .eq. 0) then
113 print*,'You could have entered a jobname on the command line,'
114 print*,' but you may enter one now:'
115 read(*,'(a)')jobname
116 numargs = 1
117 else
118 c call getarg(1,jobname,idum) ! May need to replace this w/ next line
119 call getarg(1,jobname)
120 end if
121 ljob = lenstr(jobname,27)
122 if (ljob .eq. 0) then
123 print*,'No was jobname entered. Restart and try again.'
124 stop
125 end if
126 c
127 c Strip ".pmx" if necessary
128 c
129 ndxpmx = max(index(jobname,'.pmx'),index(jobname,'.PMX'))
130 if (ndxpmx .gt. 0) then
131 jobname = jobname(1:ndxpmx-1)
132 ljob = ljob-4
133 end if
134 c
135 c Check for existence of input file
136 c
137 infileq = jobname(1:ljob)//'.pmx'
138 inquire(file=infileq,EXIST=fexist)
139 if (.not.fexist) then
140 print*,'Cannot find file '//infileq
141 stop
142 end if
143 open(10,file=jobname(1:ljob)//'.pmx')
144 c
145 c Open all instrument files now for allparts stuff. Later disgard those >nv
146 c
147 do 19 iv = 1 , noimax
148 iorig(iv) = iv
149 open(10+iv,status='SCRATCH')
150 ludpfn(iv) = 0
151 19 continue
152 read(10,'(a)')line
153 call chkcom(line,goto999)
154 if (line(1:3) .eq. '---') then
155 call allparts(line,128)
156 31 read(10,'(a)')line
157 if (line(1:3) .ne. '---') then
158 call allparts(line,128)
159 go to 31
160 end if
161 call allparts(line,128)
162 read(10,'(a)')line
163 call chkcom(line,goto999)
164 end if
165 iccount = 0
166 nv = readin(line,iccount,1)+.1
167 noinst = readin(line,iccount,2)+.1
168 if (noinst .gt. 0) then
169 nvi(1) = nv-noinst+1
170 else
171 noinst = 1-noinst
172 do 21 iinst = 1 , noinst
173 nvi(iinst) = readin(line,iccount,-1)+.1
174 21 continue
175 end if
176 noinow = noinst
177 insnow = 1
178 c
179 c ivlast is last iv in current inst. instnum(iv) is iinst for current voice.
180 c
181 ivlast = nvi(1)
182 do 22 iv = 1 , nv
183 instnum(iv) = insnow
184 if (iv .eq. ivlast) then
185 if (iv .lt. nv) botv(iv+1) = .true.
186 c
187 c The previous stmt will set botv true only for bot voice of iinst>1. It is
188 c used when writing termrpts, but the one in voice one is handled differently,
189 c so botv(1) is left .false.
190 c
191 if (insnow .lt. noinst) then
192 insnow = insnow+1
193 ivlast = ivlast+nvi(insnow)
194 end if
195 end if
196 22 continue
197 mtrnuml = readin(line,iccount,0)+.1
198 mtrdenl = readin(line,iccount,0)+.1
199 mtrnmp = readin(line,iccount,0)+.1
200 mtrdnp = readin(line,iccount,0)+.1
201 xmtrnum0 = readin(line,iccount,0)
202 isig = readin(line,iccount,0)+.1
203 npages = readin(line,iccount,3)+.1
204 nsyst = readin(line,iccount,0)+.1
205 musicsize = readin(line,iccount,4)+.1
206 fracindent = readin(line,iccount,5)
207 if (npages .eq. 0) then
208 print*,
209 *'You entered npages=0, which means nsyst is not the total number'
210 print*,
211 *'of systems. Scor2prt has to know the total number of systems.'
212 print*,
213 *'Please set npages and nsyst to their real values.'
214 stop
215 end if
216 c
217 c Must leave insetup=.true. else could bypass ALL instrument names.
218 c
219 read(10,'(a)')line
220 call chkcom(line,goto999)
221 backspace(10)
222 c
223 c Normally this puts pointer at start of line with 1st inst name
224 c Check if prior line was "%%"
225 c
226 backspace(10)
227 read(10,'(a)')line
228 if (line(1:2) .eq. '%%') backspace(10)
229 do 14 iv = 1 , noinst
230 gotname = .false.
231 16 read(10,'(a)') instrum(iv)
232 if (instrum(iv)(1:2) .eq. '%%') then
233 read(10,'(a)')line
234 go to 16
235 else if (instrum(iv)(1:1) .eq. '%') then
236 ivq = ichar(instrum(iv)(2:2))-48
237 if (ivq.ne.iv) then
238 c
239 c It's really a comment. Copy to parts, then get another trial name.
240 c
241 call allparts(instrum(iv),128)
242 go to 16
243 else
244 line = instrum(iv)(3:)
245 instrum(iv) = line
246 gotname = .true.
247 end if
248 else
249 gotname = .true.
250 end if
251 cc
252 cc The following checks for macro that write original C-clef as part of
253 cc instrument name. See pmx.tex
254 cc
255 c if (index(instrum(iv),'namewpc') .eq. 0) then
256 c write(10+iv,'(a)')' '
257 c else
258 c inm1 = index(instrum(iv),'{')+1
259 c inm2 = index(instrum(iv),'}')-1
260 c read(instrum(iv)(inm2+2:inm2+8),'(i1,4x,2i1)')ilev,iy1,iy2
261 c write(10+iv,'(a)')sq//'namewpc{}'//char(ilev+48)//'{20}'//
262 c * char(iy1+49)//char(iy2+49)
263 c instrum(iv) = instrum(iv)(inm1:inm2)
264 c end if
265 if (.not.gotname) then
266 print*,'You must provide a replacement instrument name'
267 stop
268 end if
269 write(10+iv,'(a)')' '
270 14 continue
271 replacing = .false.
272 nvnow = nv
273 c
274 c Clef string: Note insetup is still T, so "%%" will be treated specially
275 c
276 read(10,'(a)')line
277 call chkcom(line,goto999)
278 if (replacing) then
279 c
280 c If here, we have next line after "%%", containing score's clef string
281 c Assume all clefs are handled with instrument comments.
282 c
283 read(10,'(a)')line
284 call chkcom(line,goto999)
285 backspace(10)
286 else
287 c
288 c If here, line has the clef string in it. Handle the old way
289 c
290 kvstart = 1
291 kvend = nvi(1)
292 do 2 inst = 1 , noinst
293 write(10+inst,'(a'//char(48+nvi(inst))//')')
294 * line(kvstart:kvend)
295 if (inst .lt. noinst) then
296 kvstart = kvend+1
297 kvend = kvstart+nvi(inst+1)-1
298 end if
299 2 continue
300 end if
301 replacing = .false.
302 insetup = .false.
303 c
304 c *****NOTE*****This comment applies to stuff done earlier!
305 c Before starting the big loop, copy initial instnum and staffnum stuff
306 c into working values. Latter may change if noinst changes. Also make
307 c list of current inst nums relative to original ones. In addition to those
308 c below, must redo instnum(iv) and botv(iv) when we change noinst.
309 c
310 c Path string: ASSUME THIS WILL NEVER BE ALTERED IN PARTS!
311 c
312 18 read(10,'(a)') line
313 if (line(1:1) .eq. '%') then
314 call allparts(line,128)
315 go to 18
316 end if
317 call allparts(line,128)
318 c
319 c Write instrument names. Will be blank if later part of a score.
320 c
321 if (instrum(1)(1:1) .ne. ' ') then
322 do 3 iv = 1 , noinst
323 len = lenstr(instrum(iv),79)
324 write(10+iv,'(a2/a)')'Ti',instrum(iv)(1:len)
325 3 continue
326 end if
327 c
328 c The big loop. Except for '%%', put all comment lines in all parts.
329 c Unless preceeded by '%%', put all type 2 or 3 TeX Strings in all parts
330 c If a line starts with %!, put the rest of it in each part.
331 c If a line starts with %[n], put the rest of it in part [n].
332 c Check for Tt, Tc, Voltas, Repeats, headers, lower texts, meter changes.
333 c Assume they only come at top of block, except terminal repeat needs
334 c special handling.
335 c Check for "P"; ignore in parts.
336 c Check for consecutive full-bar rests; if found, replace with rm[nn]
337 c
338 iv = 1
339 iinst = 1
340 termrpt = .false.
341 4 continue
342 read(10,'(a)',end=999)line
343 lenline = lenstr(line,128)
344 if (lenline .eq. 0) go to 4
345 call zapbl(line,128)
346 call chkcom(line,goto999)
347 if (goto999) go to 999
348 lenline = lenstr(line,128)
349 if (lenline .eq. 0) go to 4
350 if (line(1:1) .eq. 'T') then
351 call allparts(line,128)
352 read(10,'(a)')line
353 call allparts(line,128)
354 go to 4
355 else if (line(1:2) .eq. sq//sq) then
356 call allparts(line,128)
357 go to 4
358 else if (index('hl',line(1:1)).gt.0 .and.
359 * index(' +-',line(2:2)) .gt. 0) then
360 call allparts(line,128)
361 read(10,'(a)')line
362 call allparts(line,128)
363 go to 4
364 else if (iv .eq. 1) then
365 do 5 ia = 1 , 10
366 24 continue
367 idxa = ntindex(line,achar(ia))
368 isachar = idxa .gt. 0
369 if (idxa.gt.1) isachar = line(idxa-1:idxa-1).eq.' '
370 c
371 c 1 2 3 4 5 6 7 8 9 10
372 c data achar /'P','m','V','R','A','h','w','K','M','I'/
373 c
374 if (ia .eq. 9) isachar =
375 * isachar .and. line(idxa+1:idxa+1).eq.'S'
376 if (isachar) then
377 c
378 c Check whether character is inside a quoted string by counting
379 c how many quotes precede it in the line
380 c
381
382 call OddQuotesBefore(line,idxa,yesodd)
383 if (yesodd) isachar=.false.
384 end if
385 if (isachar) then
386 c
387 c Find next blank
388 c
389 do 6 ib = idxa+1 , 128
390 if (line(ib:ib) .eq. ' ') go to 7
391 6 continue
392 print*,'Problem with "V,R,m,P,A,h,MS, or w"'
393 print*,
394 * 'Send files to Dr. Don at dsimons at roadrunner dot com'
395 stop 1
396 7 continue
397 c
398 c Next blank is at position ib. Later, if ia=1, must check for Pc" " ;
399 c i.e., look for '"' between P and blank
400 c
401 if (ia .eq. 4) then
402 c
403 c Check for terminal repeat. Note if there's a term rpt, there can't be any
404 c others. Also, must process repeats LAST, after m's and 'V's
405 c
406 do 8 ic = ib+1 , 128
407 c
408 c If any subsequent character on this line is neither blank nor "/", get out
409 c
410 if (index(' /',line(ic:ic)) .eq. 0) go to 9
411 if (line(ic:ic) .eq. '/') then
412 termrpt = .true.
413 termsym = line(ib-2:ib-1)
414 c
415 c Process the line as if there were no "R"
416 c
417 go to 10
418 end if
419 8 continue
420 c
421 c +++ 060812
422 c If here, all chars after "R" symbol are blanks, so process the line normally,
423 c but only IF next line is not the M-Tx line " /"
424 c
425 read(10,'(a)')templine
426 if (templine(1:2) .ne. ' /') then
427 backspace(10) ! and flow out
428 else
429 c
430 c We have the M-Tx case where one line ends with R? and next is " /". Add / to the line,
431 c and proceed as above
432 c
433 line = line(1:ib)//'/'
434 lenline = lenline+2
435 termrpt = .true.
436 termsym = line(ib-2:ib-1)
437 go to 10
438 end if
439 c +++ 060812
440 c
441 else if (ia .eq. 1) then
442 idxq = ntindex(line,'"')
443 if (idxq.gt.idxa .and. idxq.lt.ib) then
444 c
445 c Quote is between P and next blank. Find 2nd quote, starting at the blank.
446 c
447 idxq2 = ib-1+ntindex(line,'"')
448 if (idxq.eq.0 .or. line(idxq2+1:idxq2+1).ne.' ') then
449 print*
450 print*,'Error copying P with quotes, idxq2:',idxq2
451 print*,line(1:60)
452 stop 1
453 end if
454 ib = idxq2+1
455 end if
456 c
457 c Do not transfer P into parts.
458 c
459 go to 12
460 else if (ia .eq. 9) then
461 c
462 c Start Saving a macro. After leaving here, a symbol will be sent to all parts,
463 c If all on this line, set ib to end and exit normally.
464 c
465 ndxm = index(line(ib+1:128),'M')
466 if (ndxm.gt.0 .and. line(ib+ndxm-1:ib+ndxm-1).eq.' ') then
467 c
468 c Macro ends on this line
469 c
470 ib = ib+ndxm+1
471 else
472 c
473 c Save leading part of current line
474 c
475 lenhold = idxa-1
476 if (lenhold .gt. 0) holdln = line(1:lenhold)
477 c
478 c Transfer rest of line
479 c
480 call allparts(line(idxa:128),129-idxa)
481 c
482 c Read next line
483 c
484 20 read(10,'(a)')line
485 c
486 c Check for comment, transfer and loop if so
487 c
488 c if (line(1:1) .eq.'%') then
489 23 if (line(1:1) .eq.'%') then
490 c call allparts(line,128)
491 c go to 20
492 call chkcom(line,goto999)
493 go to 23
494 end if
495 c
496 c Look for terminal ' M'
497 c
498 if (line(1:1) .eq. 'M') then
499 ndxm = 1
500 else
501 ndxm = index(line,' M')
502 if (ndxm .gt. 0) ndxm = ndxm+1
503 end if
504 if (ndxm .gt. 0) then
505 c
506 c Set parameters, exit normally (but later check for leading part of 1st line
507 c
508 idxa = 1
509 ib = ndxm+1
510 else
511 c
512 c No "M", transfer entire line, loop
513 c
514 call allparts(line,128)
515 go to 20
516 end if
517 end if
518 else if (ia .eq. 10) then
519 c
520 c Do not transfer MIDI command into parts
521 c
522 go to 12
523 else if (ia .eq. 5) then
524 c
525 c First check for "AS", but S may come after other "A" options
526 c
527 idxS = index(line(idxa+1:ib),'S')
528 if (idxS .gt. 0) then
529 c
530 c Get rid of the string. First check if that's all there is in A.
531 c
532 if (ib-idxa .eq. nv+2) go to 12
533 line = line(1:idxa+idxS-1)//line(idxa+idxS+nv+1:ib)
534 end if
535 c
536 c Check for user-defined part file name. Must start in column 1 and have
537 c AN[n]"userfilename".
538 c idxa is position of "A"
539 c ib is position of the next blank after "A"
540 c Don't allow any blanks in user
541 c
542 if (line(idxa+1:idxa+1) .ne. 'N') go to 9 ! bail out
543 if (idxa .ne. 1) then
544 print*
545 print*,
546 * 'You entered "AN..." somewhere beyond first column; stopping.'
547 stop 1
548 end if
549 c
550 c pmxa already checked for valid one- or 2-digit number, so get it
551 c
552 if (line(4:4) .eq. '"') then
553 c
554 c Single digit instrument number
555 c
556 read(line(3:3),'(i1)')iudpfn
557 idxstartname = 5
558 else
559 read(line(3:4),'(i2)')iudpfn
560 idxstartname = 6
561 end if
562 ludpfn(iudpfn) = index(line(idxstartname:128),'"')-1
563 if (ludpfn(iudpfn) .lt. 0) then
564 print*
565 print*,'User-defined part file name must be in quotes'
566 stop 1
567 end if
568 idxendname = idxstartname+ludpfn(iudpfn)-1
569 udpfnq(iudpfn) = line(idxstartname:idxendname)
570 c
571 c Get a new line!
572 c
573 go to 4
574 else if (ia .eq. 8) then
575 c
576 c Key change/transposition.
577 c If not instrument specific, copy to all parts
578 c
579 if (line(idxa+1:idxa+1).ne.'i') go to 9
580 c
581 c Instrument-wise key/transposition(s): Ki[nn][+/-][dd}[+/-][dd]...
582 c
583 ibb = idxa+2 ! Starts on digit after 'i'
584 40 continue
585 read(line(ibb:ibb),'(i1)')iiinst ! 1st digit of iinst
586 itemp = (index('01234567890',line(ibb+1:ibb+1)))
587 if (itemp.gt.0) then
588 ibb = ibb+1
589 iiinst = 10*iiinst+itemp-1
590 end if
591 ibb = ibb+1 ! now at first +/-. Need end of 2nd number
592 itemp = index(line(ibb+1:ib),'i') ! Rel pos'n of next 'i' or 0
593 if (itemp .gt. 0) then
594 iend = ibb+itemp-1
595 else
596 iend = ib-1
597 end if
598 write(10+iorig(iiinst),'(a)')'Ki1'//line(ibb:iend)
599 if (itemp .gt. 0) then
600 ibb = iend+2
601 go to 40
602 end if
603 go to 12 ! Remove K command from string, go to next ia
604 end if
605 9 continue
606 call allparts(line(idxa:ib-1),ib-idxa)
607 12 continue
608 c
609 c Remove the string from line
610 c
611 if (idxa .eq. 1) then
612 line = line(ib:128)
613 else
614 line = line(1:idxa-1)//line(ib:128)
615 end if
616 lenline = lenstr(line,128)
617 c
618 c Loop if only blanks are left
619 c
620 if (lenline .eq. 0) go to 4
621 c
622 c Must check for multiple "I" commands, so go to just after start of ia loop
623 c
624 if (ia .eq. 10) go to 24
625 c
626 c Tack on front part from 1st line of saved macro
627 c
628 if (lenhold .gt. 0) then
629 line = holdln(1:lenhold)//' '//line(1:lenline)
630 lenhold = 0
631 end if
632 end if
633 5 continue
634 end if
635 c
636 c Now a special loop to deal with 'X'. If it was %[n]X..., will have been
637 c copied into part [n] already. If no "B" or "P", remove. If "P", just
638 c remove the "P" so pmxa/b will process. If "B". do nothing.
639 c
640 10 continue
641 nchk = 1
642 13 ntinx = nchk-1+ntindex(line(nchk:),'X')
643 if (ntinx .gt. nchk-1) then
644 c
645 c There is a non-TeX 'X' at ntinx. Loop if neither 1st nor after a blank.
646 c
647 if (ntinx.gt.1) then
648 if (line(ntinx-1:ntinx-1).ne.' ') then
649 c
650 c The X is not 1st char of PMX command. Advance starting point, loop.
651 c
652 nchk = ntinx+1
653 go to 13
654 end if
655 end if
656 c
657 c We now know the X at ntinx starts a PMX command. Find next blank
658 c
659 ib = ntinx+index(line(ntinx+1:),' ')
660 c
661 c There must be a blank to right of "X", so ib>ntinx
662 c
663 c locp = nchk-1+index(line(nchk:ib),'P')
664 locp = ntinx+index(line(ntinx+1:ib),'P')
665 c
666 c Did not need to use ntindex because we already know bounds of PMX command.
667 c
668 c if (locp .gt. nchk-1) then
669 if (locp .gt. ntinx) then
670 c
671 c Strip out the 'P'
672 c
673 templine = line(1:locp-1)
674 line = templine(1:locp-1)//line(locp+1:lenline)
675 lenline = lenline-1
676 ib = ib-1
677 end if
678 if (index(line(ntinx:ib),':').gt.0 .or.
679 * index(line(ntinx:ib),'S').gt.0 .or.
680 * index(line(ntinx:ib),'B').gt.0 .or. locp.gt.ntinx) then
681 c
682 c The X command is a shift, "Both", or "Part". Do not remove.
683 c
684 nchk = ib+1
685 go to 13
686 end if
687 c
688 c Remove the X command.
689 c
690 if (ntinx .eq. 1) then
691 if (ib .lt. lenline) then
692 line = line(ib+1:lenline)
693 else
694 c
695 c line contains ONLY the "X" command, so get a new line
696 c
697 go to 4
698 end if
699 else
700 templine = line(1:ntinx-1)
701 if (ib .lt. lenline) then
702 line = templine(1:ntinx-1)//line(ib+1:lenline)
703 else
704 line = templine(1:ntinx-1)
705 end if
706 end if
707 c
708 c Recompute lenline
709 c
710 lenline = lenstr(line,128)
711 c
712 c Resume checking after location of removed command.
713 c
714 nchk = ntinx
715 go to 13
716 end if
717 c
718 c End of loop for X-checks
719 c
720 oneof2 = ntindex(line,'//') .gt. 0
721 if (termrpt .and. botv(iv) .and. frstln .and.
722 * line(lenline:lenline).eq.'/') then
723 c
724 c Must add a terminal repeat before the slash
725 c
726 if (oneof2) lenline = lenline-1
727 if (lenline.gt.1) write(10+iorig(iinst),'(a)')line(1:lenline-1)
728 if (.not. oneof2) then
729 line = termsym//' /'
730 lenline = 4
731 else
732 line = termsym//' //'
733 lenline = 5
734 end if
735 end if
736 if (termrpt .and. frstln .and. line(lenline:lenline).eq.'/' .and.
737 * iv.eq.nvnow) termrpt = .false.
738 write(10+iorig(iinst),'(a)')line(1:lenline)
739 if (oneof2) then
740 frstln = .false.
741 else if (.not.frstln) then
742 frstln = .true.
743 end if
744 c if (ntindex(line,'/').gt.0 .and. index(line,'//').eq.0) then
745 if (ntindex(line,'/').gt.0 .and. ntindex(line,'//').eq.0) then
746 iv = 1+mod(iv,nvnow)
747 iinst = instnum(iv)
748 end if
749 go to 4
750 999 continue
751 close(10)
752 c
753 c In the mbrest checks, must run through ALL noinst files (not just noinow)
754 c
755 do 11 iinst = 1 , noinst
756 ccc+++
757 cc
758 cc Temporarily transfer entire scratch file to real file
759 cc
760 c rewind(10+iinst)
761 c open(40,file='s2pout'//char(48+iinst)//'.pmx')
762 c do 50 m = 1 , 10000
763 c read(10+iinst,'(a)',end=51)line
764 c lenline = lenstr(line,128)
765 c if (lenline .ge. 1) then
766 c write(40,'(a)')line(1:lenline)
767 c else
768 c write(40,'(a)')' '
769 c end if
770 c50 continue
771 c51 continue
772 c close(40)
773 ccc+++
774 if (nvi(iinst) .eq. 1) then
775 call mbrests(iinst,jobname,ljob,ludpfn(iinst),udpfnq(iinst))
776 else
777 c
778 c Send a signal with ljob to bypass most mbrest processing
779 c
780 call mbrests(iinst,jobname,-ljob,ludpfn(iinst),udpfnq(iinst))
781 end if
782 11 continue
783 end
784 function lenstr(string,n)
785 character*(*) string
786 do 1 lenstr = n , 1 , -1
787 if (string(lenstr:lenstr) .ne. ' ') return
788 1 continue
789 lenstr = 0
790 return
791 end
792 subroutine allparts(string,n)
793 parameter (noimax=24)
794 character*(*) string
795 common /all/ noinow,iorig(noimax),noinst,insetup,replacing,
796 * instnum(noimax),botv(noimax),nvi(noimax),nsyst,nvnow
797 logical insetup,replacing,botv
798 len = lenstr(string,n)
799 if (len .eq. 0) then
800 len = 1
801 string = ' '
802 end if
803 do 1 iinst = 1 , noinow
804 write(10+iorig(iinst),'(a)')string(1:len)
805 1 continue
806 return
807 end
808 subroutine mbrests(iv,jobname,ljob,ludpfn,udpfnq)
809 character*128 line(50),line1,udpfnq
810 character*80 sym
811 character*12 jobname
812 character*3 wbrsym(2)
813 character*2 partq
814 character*1 sq
815 logical wbrest,alldone,rpfirst,newmtr,type4
816 type4 = .false.
817 sq = char(92)
818 alldone = .false.
819 rewind(10+iv)
820 if (iv .lt. 10) then
821 partq(1:1) = char(48+iv)
822 lpart = 1
823 else
824 lpart = 2
825 if (iv .lt. 20) then
826 partq = '1'//char(38+iv)
827 else
828 partq = '2'//char(28+iv)
829 end if
830 end if
831 c 130327
832 c open(40,file=jobname(1:abs(ljob))//partq(1:lpart)//'.pmx')
833 if (ludpfn .eq. 0) then
834 open(40,file=jobname(1:abs(ljob))//partq(1:lpart)//'.pmx')
835 else
836 open(40,file=udpfnq(1:ludpfn)//'.pmx')
837 end if
838 do 10 i = 1 , 10000
839 read(10+iv,'(a)')line(1)
840 if (line(1)(1:1).eq.'%' .or. line(1)(1:3).eq.'---'
841 * .or. type4) then
842 len = lenstr(line(1),128)
843 if (len .gt. 0) then
844 write(40,'(a)')line(1)(1:len)
845 else
846 write(40,'(a)')' '
847 end if
848 if (line(1)(1:3).eq.'---') type4 = .not.type4
849 else
850 go to 11
851 end if
852 10 continue
853 print*,'You should not be here in scor2prt. Call Dr. Don'
854 stop
855 11 continue
856 c
857 c Finished reading opening type4 TeX and comments. Next line to be read
858 c will contain the first of the input numbers
859 c
860 call dosetup(iv,line(1),mtrnum,mtrden)
861 do 1 i = 1 , 10000
862 13 read(10+iv,'(a)',end=999)line(1)
863 7 len = lenstr(line(1),128)
864 c
865 c Pass-through (and copy into part file) if instrumnet has >1 voice.
866 c
867 if (ljob .lt. 0) go to 2
868 if (index('TtTiTch+h-h l ',line(1)(1:2)) .gt. 0) then
869 c
870 c Traps titles, instruments, composers, headers, lower strings. Read 2 lines.
871 c
872 write(40,'(a)')line(1)(1:len)
873 read(10+iv,'(a)')line(1)
874 len = lenstr(line(1),128)
875 go to 2
876 end if
877 if (i.eq.1 .or. (i.gt.5.and.line(1)(1:1).eq.'m')) then
878 c
879 c Either just starting, or a new meter is defined.
880 c NOTE! The above test may be bogus.
881 c
882 if (line(1)(1:1) .eq. '%') then
883 write(40,'(a)')line(1)(1:len)
884 go to 13
885 end if
886 if (i .ne. 1) then
887 c
888 c New meter. Check for slashes (new meter change syntax)
889 c
890 idxs = index(line(1),'/')
891 idxb = index(line(1),' ')
892 newmtr = idxs.gt.0 .and. (idxb.eq.0 .or. idxs.lt.idxb)
893 if (.not.newmtr) then
894 c
895 c Old way, no slashes, uses 'o' for lonesome '1'
896 c
897 icden = 3
898 if (line(1)(2:2) .eq. 'o') then
899 mtrnum = 1
900 else
901 mtrnum = ichar(line(1)(2:2))-48
902 if (mtrnum .eq. 1) then
903 icden = 4
904 mtrnum = 10+ichar(line(1)(3:3))-48
905 end if
906 end if
907 mtrden = ichar(line(1)(icden:icden))-48
908 else
909 c
910 c New way with slashes: idxs is index of 1st slash!
911 c
912 read(line(1)(2:idxs-1),'(i'//char(48+idxs-2)//')')mtrnum
913 idxb = index(line(1)(idxs+1:),'/')
914 read(line(1)(idxs+1:idxs+idxb-1),
915 * '(i'//char(48+idxb-1)//')')mtrden
916 end if
917 end if
918 lenbeat = ifnodur(mtrden,'x')
919 lenmult = 1
920 if (mtrden .eq. 2) then
921 lenbeat = 16
922 lenmult = 2
923 end if
924 lenbar = lenmult*mtrnum*lenbeat
925 call fwbrsym(lenbar,nwbrs,wbrsym,lwbrs)
926 end if
927 c
928 c Finished setting up meter stuff and defining whole-bar rest symbols
929 c
930 ip1 = 0
931 line1 = line(1)
932 do 3 iw = 0 , nwbrs
933 if (iw .gt. 0) then
934 idx = ntindex(line1,wbrsym(iw)(1:lwbrs))
935 if (idx .gt. 0) then
936 c
937 c Check for blank or shifted rest, discount it if it's there
938 c
939 if (line1(idx+lwbrs:idx+lwbrs).ne.' ') idx = 0
940 end if
941 else
942 idx = ntindex(line1,'rp')
943 c
944 c Check for raised rest
945 c
946 if (idx.gt.0) then
947 if (line1(idx+2:idx+2).ne.' ') idx = 0
948 end if
949 end if
950 if (idx .gt. 0) then
951 if (ip1 .eq. 0) then
952 ip1 = idx
953 else
954 ip1 = min(ip1,idx) ! Maybe allows e.g. r0 rp ...
955 end if
956 end if
957 3 continue
958 if (i.lt.5 .or. line(1)(1:1).eq.'%' .or. line(1)(1:2).eq.sq//sq
959 * .or. ip1.eq.0) go to 2
960 c
961 c Switch to multibar rest search mode!!! Start forward in line(1)
962 c
963 rpfirst = line1(ip1:ip1+1) .eq. 'rp'
964 iline = 1
965 nmbr = 1
966 if (rpfirst) then
967 lwbrsx = 2
968 else
969 lwbrsx = lwbrs
970 end if
971 ipe = ip1+lwbrsx-1 ! ip at end of 1st wbrsym
972 4 if (ipe .eq. len) then
973 c
974 c Need a new line
975 c
976 iline = iline+1
977 6 read(10+iv,'(a)',end=998)line(iline)
978 len = lenstr(line(iline),128)
979 if (line(iline)(1:1).eq.'%' ) then
980 write(40,'(a)')'% Following comment has been moved forward'
981 write(40,'(a)')line(iline)(1:len)
982 go to 6
983 end if
984 ipe = 0
985 go to 4
986 998 continue
987 c
988 c No more input left
989 c
990 print*,'All done!'
991 alldone = .true.
992 ipe = 0
993 iline = iline-1
994 len = lenstr(line(iline),128)
995 go to 4
996 else
997 if (alldone) then
998 sym(1:1) = ' '
999 else
1000 c
1001 c ipe<len here, so it's ok to get a symbol
1002 c
1003 call nextsym(line(iline),len,ipe,ipenew,sym,lsym)
1004 end if
1005 c
1006 c Check for end of block or bar line symbol
1007 c
1008 if (index('/|',sym(1:1)) .gt. 0) then
1009 ipe = ipenew
1010 go to 4
1011 else
1012 wbrest = .false.
1013 if (alldone) go to 12
1014 do 5 iw = 1 , nwbrs
1015 wbrest = wbrest .or. sym(1:lsym).eq.wbrsym(iw)(1:lwbrs)
1016 5 continue
1017 wbrest = wbrest .or. (sym(1:lsym).eq.'r'.and.lwbrs.eq.2)
1018 * .or. (sym(1:lsym).eq.'rd'.and.lwbrs.eq.3)
1019 * .or. (sym(1:lsym).eq.'rp')
1020 * .or. (sym(1:lsym).eq.'r' .and. rpfirst)
1021 12 if (wbrest) then
1022 ipe = ipenew
1023 nmbr = nmbr+1
1024 go to 4
1025 else
1026 c
1027 c AHA! Failed prev. test, so last symbol was *not* mbr.
1028 c It must be saved, and its starting position is ipenew-lsym+1
1029 c
1030 if (nmbr .gt. 1) then
1031 c
1032 c Write stuff up to start of mbr
1033 c
1034 if (ip1 .gt. 1) write(40,'(a)')line(1)(1:ip1-1)
1035 c
1036 c Insert mbr symbol. Always end with a slash just in case next sym must be
1037 c at start of block. May think this causes undefined octaves, but
1038 c probably not since it's a single voice.
1039 c
1040 ndig = int(alog10(nmbr+.01))+1
1041 print*,'Inserting rm, iv,nmbr:',iv,nmbr
1042 write(40,'(a2,i'//char(48+ndig)//',a2)')'rm',nmbr,' /'
1043 if (alldone) go to 999
1044 ipc = ipenew-lsym+1
1045 line(1) = line(iline)(ipc:len)
1046 else
1047 c
1048 c Write old stuff up to end of original lonesome wbr, save the rest.
1049 c 4 cases: (wbr /) , (wbr line-end) , (wbr followed by other non-/ symbols) ,
1050 c alldone.
1051 c In 1st 2 will have gotten some other lines, so write all up to one b4 last
1052 c non-comment line; then revert to normal mode on that. In 3rd case must
1053 c split line.
1054 c
1055 if (alldone) then
1056 write(40,'(a)')line(1)(1:len)
1057 go to 999
1058 else if (iline .gt. 1) then
1059 do 9 il = 1 , iline-1
1060 len = lenstr(line(il),128)
1061 write(40,'(a)')line(il)(1:len)
1062 9 continue
1063 line(1) = line(iline)
1064 else
1065 c
1066 c Since iline = 1 the wbr is not the last sym, so must split
1067 c
1068 write(40,'(a)')line(1)(1:ip1+lwbrsx-1)
1069 line(1) = line(1)(ip1+lwbrsx+1:len)
1070 end if
1071 end if
1072 c
1073 c Exit multibar mode
1074 c
1075 go to 7
1076 end if
1077 end if
1078 end if
1079 2 continue
1080 if (len .gt. 0) then
1081 write(40,'(a)')line(1)(1:len)
1082 else
1083 write(40,'(a)')' '
1084 end if
1085 1 continue
1086 999 continue
1087 close(10+iv)
1088 close(40)
1089 return
1090 end
1091 function ifnodur(idur,dotq)
1092 character*1 dotq
1093 if (idur .eq. 6) then
1094 ifnodur=1
1095 else if (idur .eq. 3) then
1096 ifnodur=2
1097 else if (idur.eq.1 .or. idur.eq.16) then
1098 ifnodur=4
1099 else if (idur .eq. 8) then
1100 ifnodur=8
1101 else if (idur .eq. 4) then
1102 ifnodur=16
1103 else if (idur .eq. 2) then
1104 ifnodur=32
1105 else if (idur .eq. 0) then
1106 ifnodur=64
1107 else
1108 print*,'You entered an invalid note-length value'
1109 stop
1110 end if
1111 if (dotq .eq. 'd') ifnodur = ifnodur*3/2
1112 return
1113 end
1114 subroutine fwbrsym(lenbar,nwbrs,wbrsym,lwbrs)
1115 character*3 wbrsym(2)
1116 nwbrs = 1
1117 lwbrs = 2
1118 if (lenbar .eq. 16) then
1119 wbrsym(1) = 'r4'
1120 else if (lenbar .eq. 32) then
1121 wbrsym(1) = 'r2'
1122 else if (lenbar .eq. 64) then
1123 wbrsym(1) = 'r0'
1124 else if (lenbar .eq. 8) then
1125 wbrsym(1) = 'r8'
1126 else if (lenbar .eq. 128) then
1127 wbrsym(1) = 'r9'
1128 else
1129 nwbrs = 2
1130 lwbrs = 3
1131 if (lenbar .eq. 24) then
1132 wbrsym(1) = 'rd4'
1133 wbrsym(2) = 'r4d'
1134 else if (lenbar .eq. 48) then
1135 wbrsym(1) = 'rd2'
1136 wbrsym(2) = 'r2d'
1137 else if (lenbar .eq. 96) then
1138 wbrsym(1) = 'rd0'
1139 wbrsym(2) = 'r0d'
1140 else
1141 write(*,'(33H Any whole-bar rests of duration ,i3,
1142 * 26H/64 will not be recognized)') lenbar
1143 end if
1144 end if
1145 return
1146 end
1147 subroutine nextsym(line,len,ipeold,ipenew,sym,lsym)
1148 c
1149 c Know its the last symbol if on return ipenew = len!. So should never
1150 c be called when ipstart=len.
1151 c
1152 character*128 line
1153 character*80 sym
1154 if (ipeold .ge. len) then
1155 print*,'Called nextsym with ipstart>=len '
1156 print*,'Send files to Dr. Don at [email protected]'
1157 stop
1158 end if
1159 do 1 ip = ipeold+1 , len
1160 if (line(ip:ip) .ne. ' ') then
1161 c
1162 c symbol starts here (ip). We're committed to exit the loop.
1163 c
1164 if (ip .lt. len) then
1165 do 2 iip = ip+1 , len
1166 if (line(iip:iip) .ne. ' ') go to 2
1167 c
1168 c iip is the space after the symbol
1169 c
1170 ipenew = iip-1
1171 lsym = ipenew-ip+1
1172 sym = line(ip:ipenew)
1173 return
1174 2 continue
1175 c
1176 c Have len>=2 and ends on len
1177 c
1178 ipenew = len
1179 lsym = ipenew-ip+1
1180 sym = line(ip:ipenew)
1181 return
1182 else
1183 c
1184 c ip = len
1185 c
1186 ipenew = len
1187 lsym = 1
1188 sym = line(ip:ip)
1189 return
1190 end if
1191 end if
1192 1 continue
1193 print*,'Error #3. Send files to Dr. Don at [email protected]'
1194 end
1195 function ntindex(line,s2q)
1196 c
1197 c Returns index(line,s2q) if NOT in TeX string, 0 otherwise
1198 c
1199 character*(*) s2q
1200 character*128 line,tline
1201 logical intex
1202 c
1203 c print*,'Starting ntindex. s2q:',s2q,', line(1:79) is below'
1204 c print*,line(1:79)
1205 c
1206 c
1207 c Use a temporary string to store the input and test, so can zap D"..."
1208 c
1209 tline = line
1210 ndxs2 = index(tline,s2q)
1211 c
1212 c Return point below for rechecks after zapping D" "
1213 c
1214 2 continue
1215 ndxbs = index(tline,char(92))
1216 if (ndxbs .gt. 0) then
1217 c
1218 c Special check in case \ is inside D"..."
1219 c
1220 ndxDq1 = index(tline,'D"')
1221 c
1222 c If the following test fails, flow out of if block; else loop up to 2.
1223 c
1224 if (ndxDq1 .gt. 0) then
1225 c
1226 c Find end of D"..."
1227 c
1228 ndxDq2 = ndxDq1+1+index(tline(ndxDq1+2:128),'"')
1229 if (ndxDq2 .eq. ndxDq1+1) then
1230 print*,'Something is really wierd here'
1231 stop
1232 end if
1233 tline = tline(1:ndxDq1-1)
1234 do 3 ic = ndxDq1 , ndxDq2
1235 tline = tline(1:ic-1)//' '
1236 3 continue
1237 tline = tline(1:ndxDq2)//line(ndxDq2+1:128)
1238 go to 2
1239 end if
1240 end if
1241 if (ndxbs.eq.0 .or. ndxs2.lt.ndxbs) then
1242 ntindex = ndxs2
1243 c print*,'No bs, or char is left of 1st bs, ntindex:',ntindex
1244 else
1245 c
1246 c There are both bs and s2q, and bs is to the left of sq2. So check bs's to
1247 c right of first: End is '\ ', start is ' \'
1248 c
1249 len = lenstr(tline,128)
1250 intex = .true.
1251 c print*,'intex+>',intex
1252 do 1 ic = ndxbs+1 , len
1253 if (ic .eq. ndxs2) then
1254 if (intex) then
1255 ntindex = 0
1256 ndxs2 = index(tline(ic+1:len),s2q)+ic
1257 c print*,'ndxs2 =>',ndxs2
1258 else
1259 ntindex = ndxs2
1260 return
1261 end if
1262 c print*,'Internal exit, intex, ntindex:',intex,ntindex
1263 else if (intex .and. tline(ic+1:ic+2).eq.char(92)//' ') then
1264 intex = .false.
1265 c print*,'intex+>',intex
1266 else if (.not.intex .and. tline(ic+1:ic+2).eq.' '//char(92))
1267 * then
1268 intex = .true.
1269 c print*,'intex+>',intex
1270 end if
1271 1 continue
1272 c print*,'Out end of loop 1'
1273 end if
1274 c print*,'Exiting ntindex at the end???'
1275 return
1276 end
1277 subroutine getchar(line,iccount,charq)
1278 c
1279 c Gets the next character out of line*128. If pointer iccount=128 on entry,
1280 c then reads in a new line. Resets iccount to position of the new character.
1281 c
1282 character*1 charq
1283 character*128 line
1284 if (iccount .eq. 128) then
1285 read(10,'(a)')line
1286 iccount = 0
1287 end if
1288 iccount = iccount+1
1289 charq = line(iccount:iccount)
1290 return
1291 end
1292 function readin(line,iccount,iread)
1293 parameter (noimax=24)
1294 common /all/ noinow,iorig(noimax),noinst,insetup,replacing,
1295 * instnum(noimax),botv(noimax),nvi(noimax),nsyst,nvnow
1296 logical insetup,replacing,botv,goto999
1297 c
1298 c Reads a piece of setup data from line, gets a new line from
1299 c file 10 (jobname.pmx) if needed, Transfers comment lines into all parts.
1300 c
1301 c iread controls copying of values into scratch files for parts, but only
1302 c if not replacing.
1303 c
1304 c iread input value written
1305 c -1 nvi nothing (only used when noinst<0 initially)
1306 c 0 various value read
1307 c 1 nv -1 , replace later with nvi(i)
1308 c 2 noinst 1
1309 c 3 np -2 , replace later with (nsyst-1)/12+1
1310 c 4 musicsize 20
1311 c 5 fracondent 0.05
1312 c
1313 character*128 line
1314 character*1 durq
1315 4 if (iccount .eq. 128) then
1316 read(10,'(a)')line
1317 if (replacing) replacing = .false.
1318 call chkcom(line,goto999)
1319 iccount = 0
1320 end if
1321 iccount = iccount+1
1322 c
1323 c Find next non-blank or end of line
1324 c
1325 do 2 iccount = iccount , 127
1326 if (line(iccount:iccount) .ne. ' ') go to 3
1327 2 continue
1328 c
1329 c If here, need to get a new line
1330 c
1331 iccount = 128
1332 go to 4
1333 3 continue
1334 c
1335 c iccount now points to start of number to read
1336 c
1337 i1 = iccount
1338 5 call getchar(line,iccount,durq)
1339 c
1340 c Remember that getchar first increments iccount, *then* reads a character.
1341 c
1342 if (index('0123456789.-',durq) .gt. 0) go to 5
1343 i2 = iccount-1
1344 if (i2 .lt. i1) then
1345 print*,'Found "'//durq//'" instead of number'
1346 stop 1
1347 end if
1348 icf = i2-i1+49
1349 read(line(i1:i2),'(f'//char(icf)//'.0)')readin
1350 if (.not.replacing) then
1351 if (iread .eq. 0) then
1352 call allparts(line(i1:i2),i2-i1+1)
1353 else if (iread .eq. 1) then
1354 call allparts('-999',4)
1355 else if (iread .eq. 2) then
1356 call allparts('1',1)
1357 else if (iread .eq. 3) then
1358 call allparts('-998',4)
1359 else if (iread .eq. 4) then
1360 call allparts('20',2)
1361 else if (iread .eq. 5) then
1362 call allparts('.05',3)
1363 else if (iread .ne. -1) then
1364 print*,'Error with iread in readin'
1365 stop
1366 end if
1367 end if
1368 return
1369 end
1370 subroutine chkcom(line,goto999)
1371 parameter (noimax=24)
1372 common /all/ noinow,iorig(noimax),noinst,insetup,replacing,
1373 * instnum(noimax),botv(noimax),nvi(noimax),nsyst,nvnow
1374 logical insetup,replacing,clefpend,botv,goto999
1375 character*128 line
1376 c
1377 c Assume that line has just been read. No need to change iccount since we only
1378 c process full lines.
1379 c
1380 goto999 = .false.
1381 1 if (line(1:1) .ne. '%') return
1382 c
1383 c If here, line has some sort of comment
1384 c
1385 if (line(2:2) .eq. '%') then
1386 if (.not. insetup) then
1387 c
1388 c Suck up a line, then flow out of "if" block to get another and loop
1389 c
1390 read(10,'(a)')line
1391
1392 c++VV
1393 c
1394 c UNLESS (a) it has a score-only "M" and changes # of inst's.
1395 c
1396 if (index(line,'M') .gt. 0) then
1397 idxL = index(line,'L')
1398 idxM = index(line,'M')
1399 idxn = index(line,'n')
1400 idxb = index(line,' ')
1401 if (idxL.lt.idxM .and. idxM.lt.idxn .and.
1402 * (idxb.eq.0 .or. idxn.lt.idxb)) then
1403 noinow = ichar(line(idxn+1:idxn+1))-48
1404 clefpend = .true.
1405 c
1406 c Next noinow digits are original inst. #'s of new inst. set. Next noinow
1407 c char's after that are clefs
1408 c
1409 nvnow = 0
1410 do 24 j = 1 , noinow
1411 iorig(j) = ichar(line(idxn+1+j:idxn+1+j))-48
1412 iposc0 = idxn+1+noinow
1413 do 25 k = 1 , nvi(iorig(j))
1414 nvnow = nvnow+1
1415 c clefq(nvnow) = line(iposc0+nvnow:iposc0+nvnow)
1416 instnum(nvnow) = j
1417 botv(nvnow) = k.eq.1 .and. j.ne.1
1418 25 continue
1419 24 continue
1420 end if
1421 end if
1422 c
1423 c or if it's "h" or "l", need to suck up one more line
1424 c
1425 if ((line(1:1).eq.'h'.and.index('+- ',line(2:2)).gt.0) .or.
1426 c
1427 c 4/29/00 check for T string also
1428 c
1429 * line(1:1).eq.'T' .or.
1430 * line(1:2).eq.'l ') read(10,'(a)')line
1431 else
1432 c
1433 c In setup mode. Set flag, flow out and do use following line
1434 c
1435 replacing = .true.
1436 end if
1437 else if (line(2:2) .eq. '!') then
1438 c
1439 c Copy to all parts
1440 c
1441 call allparts(line(3:128),125)
1442 else
1443 c
1444 c Get value of hex integer 1,2,...,9,a,b,c in 2nd position, zero otherwise
1445 cc Get value of extended hex integer 1,2,...,9,a,b,c,...,o in 2nd position, zero otherwise
1446 c
1447 ivq = index('123456789abcdefghijklmno',line(2:2))
1448 c
1449 c Only treat as part-specific pmx line if number .le. noinst
1450 c
1451 if (ivq.lt.1 .or. ivq.gt.noinst) then
1452 c
1453 c Simple comment.
1454 c
1455 call allparts(line,128)
1456 else
1457 c
1458 c Instrument comment, copy only to part
1459 c
1460 lenline = lenstr(line,128)
1461 if (lenline .gt. 2) then
1462 write(10+ivq,'(a)')line(3:lenline)
1463 else
1464 c
1465 c Transferring blank line
1466 c
1467 write(10+ivq,'(a)')' '
1468 end if
1469 end if
1470 end if
1471 read(10,'(a)',end=2)line
1472 call zapbl(line,128)
1473 go to 1
1474 2 continue
1475 goto999 = .true.
1476 return
1477 end
1478 subroutine dosetup(iv,line,mtrnum,mtrden)
1479 parameter (noimax=24)
1480 c
1481 c Transfers setup data from scratch file to real one for one instrument
1482 c Data may be mixed with comments, but on entry 1st item is a number.
1483 c Write a comment when encountered, as it comes.
1484 c Write numbers one per line.
1485 c Three input data require special handling:
1486 c If not already replaced, i.e., if negative, then
1487 c iset(1) (nv) will be replaced with nvi(i)
1488 c iset(9) (npages) will be replaced with (nsyst-1)/12+1
1489 c iset(2), if negative, will be followed by extra numbers to be transf.
1490 c
1491 common /all/ noinow,iorig(noimax),noinst,insetup,replacing,
1492 * instnum(noimax),botv(noimax),nvi(noimax),nsyst,nvnow
1493 character*128 line
1494 logical insetup,replacing,botv
1495 iccount = 0
1496 do 1 iset = 1 , 12
1497 call partnum(iv,iccount,line,xdata)
1498 if (iset .eq. 2) then
1499 if (xdata .gt. 0) then
1500 write(40,'(i5)')int(xdata+.1)
1501 else
1502 noi = -xdata+.1
1503 write(40,'(i5)')noi
1504 do 2 ioi = 1 , noi
1505 call partnum(iv,iccount,line,xdata)
1506 write(40,'(i5)')int(xdata+.1)
1507 2 continue
1508 end if
1509 c else if (iset.ne.8 .and. xdata.lt.0) then
1510 else if (iset.ne.8 .and. iset.ne.5 .and. xdata.lt.0) then
1511 c
1512 c Must be either nv or npages
1513 c
1514 if (int(-xdata+.1) .eq. 999) then
1515 c
1516 c It's nv
1517 c
1518 write(40,'(i5)')nvi(iv)
1519 else
1520 c
1521 c npages must be computed
1522 c
1523 write(40,'(i5)')(nsyst-1)/12+1
1524 end if
1525 else if (iset.ne.7 .and. iset.ne.12) then
1526 c
1527 c write integer
1528 c
1529 write(40,'(i5)')nint(xdata)
1530 else
1531 c
1532 c write floating number
1533 c
1534 write(40,'(f5.2)')xdata
1535 end if
1536 if (iset .eq. 3) then
1537 mtrnum = nint(xdata)
1538 else if (iset .eq. 4) then
1539 mtrden = nint(xdata)
1540 end if
1541 1 continue
1542 return
1543 end
1544 subroutine partnum(iv,iccount,line,xdata)
1545 c
1546 c Simplified number parsing. Only looks for comment lines and numbers.
1547 c
1548 character*128 line
1549 character*1 durq
1550 2 if (iccount .eq. 128) then
1551 read(10+iv,'(a)')line
1552 if (line(1:1) .eq. '%') then
1553 len = lenstr(line,128)
1554 write(40,'(a)')line(1:len)
1555 go to 2
1556 end if
1557 iccount = 0
1558 end if
1559 iccount = iccount+1
1560 c
1561 c Find next non-blank or end of line
1562 c
1563 do 4 iccount = iccount , 127
1564 if (line(iccount:iccount) .ne. ' ') go to 3
1565 4 continue
1566 c
1567 c If here, iccount=128 and need to get a new line
1568 c
1569 go to 2
1570 3 continue
1571 c
1572 c iccount now points to start of number to read
1573 c
1574 i1 = iccount
1575 5 call getchar(line,iccount,durq)
1576 c
1577 c Remember that getchar first increments iccount, *then* reads a character.
1578 c
1579 if (index('0123456789.-',durq) .gt. 0) go to 5
1580 i2 = iccount-1
1581 if (i2 .lt. i1) then
1582 print*,'Found "'//durq//'" instead of number'
1583 stop 1
1584 end if
1585 icf = i2-i1+49
1586 read(line(i1:i2),'(f'//char(icf)//'.0)')xdata
1587 return
1588 end
1589 block data
1590 parameter (noimax=24)
1591 common /all/ noinow,iorig(noimax),noinst,insetup,replacing,
1592 * instnum(noimax),botv(noimax),nvi(noimax),nsyst,nvnow
1593 logical insetup,replacing,botv
1594 data nvi /noimax*1/, noinst,noinow /2*noimax/
1595 data botv /noimax*.false./
1596 end
1597 subroutine zapbl(string,len)
1598 character*(*) string
1599 do 1 i = 1 , len
1600 if (string(i:i) .eq. ' ')go to 1
1601 if (i .eq. 1) return
1602 go to 2
1603 1 continue
1604 c
1605 c If line is all blank, leave it alone
1606 c
1607 return
1608 2 continue
1609 string = string(i:len)
1610 return
1611 end
1612 subroutine OddQuotesBefore(lineq,indx,yesodd)
1613 c
1614 c This counts number of double quotes in lineq up to position indx-1, then
1615 c sets yesodd according to whether number is odd or even
1616 c
1617 logical yesodd
1618 character*(*) lineq
1619 numdqs = 0
1620 do 1 i = 1 , indx-1
1621 if (lineq(i:i) .eq. '"') numdqs = numdqs+1
1622 1 continue
1623 yesodd = mod(numdqs,2) .eq. 1
1624 return
1625 end
1626
1627
1628
1629
1630