with: Erik Oosterwal
Selected Range Copy
This routine will parse an input string for a set of numbers in the form
of any number followed by more numbers separated by commas or pairs of numbers
separated by dashes.
Back in 1988 I was working on a contract programming project that was supposed
to interface a PC with a Chessell model 4001 Data recorder for doing a specific
type of test at a local corporation. In those days, Windows hadn't
been invented yet and if you wanted to have on screen editing capability
you had to program all the keyboard input and screen output stuff yourself.
One of the requests for this particular project was the ability to
copy setup configuration data from one channel to some number of other channels.
For instance, if you had set up channel 3 to accept voltage input from
between 0 and 150 V and you wanted to use the same configuration on channels
5, 6, 9, 10, 11, 12, 24, 25, 26, and 30, you could do it manually, which
took time and was difficult due to the weird pressure sensitive push buttons
on the front of the Chessell data recorders, or you could use this routine
from the PC to do the same thing in about 5 seconds.
Using the scenario from the previous paragraph, you could copy channel 3
configuration to channels 5, 6, 9, 10, 11, 12, 24, 25, 26, and 30 by entering
in each of those channel numbers separated by commas, or you could group
adjacent channel numbers with a dash in between them like this: 5,
6, 9-12, 24-26, 30. This seemed much more intuitive and saved a number
of keystrokes.
The original code appears below:
C * FIND NUMBER OF SUBSTRINGS WITHIN THE STRING
65 SUBLEN=0
C
STRING(LEN+1)='.'
DO 20 I = 1,LEN
IF(STRING(I).EQ.' ')THEN
DO 10 J = I,LEN-1
STRING(J)=STRING(J+1)
10 CONTINUE
STRING(LEN)='.'
SUBLEN=SUBLEN+1
ENDIF
20 CONTINUE
C
LEN=LEN-SUBLEN
SUBLEN=0
C
DO 40 I = 1,LEN-1
IF((STRING(I).EQ.',').AND.(STRING(I+1).EQ.','))THEN
DO 30 J = I,LEN-1
STRING(J)=STRING(J+1)
30 CONTINUE
STRING(LEN)='.'
SUBLEN=SUBLEN+1
ENDIF
40 CONTINUE
C
LEN=LEN-SUBLEN
SUBLEN=0
C
COMMA=1
DO 50 I = 1,LEN
IF(STRING(I).EQ.',')COMMA=COMMA+1
50 CONTINUE
STRING(LEN+1)=','
C
C COPY THE VALUE TO THE SPECIFIED CHANNELS
COUNTER=0
DO 90 I = 1,COMMA
START=0
STOP=0
60 COUNTER=COUNTER+1
IF((STRING(COUNTER).GE.'0').AND.
* (STRING(COUNTER).LE.'9'))THEN
STOP=STOP*10+ICHAR(STRING(COUNTER))-48
IF(STOP.GT.30)STOP=30
GOTO 60
ENDIF
IF(STRING(COUNTER).EQ.'-')THEN
START=STOP
STOP=0
GOTO 60
ENDIF
IF(STRING(COUNTER).EQ.',')THEN
IF(START.EQ.0)START=STOP
DO 80 J = START,STOP
DO 70 K = BEGIN,END
DATAVAR(CHESNUM,(J-1)*43+K)=
* DATAVAR(CHESNUM,(CHAN-1)*43+K)
70 CONTINUE
80 CONTINUE
ENDIF
90 CONTINUE
C
95 CALL XYPOSN(22,3)
WRITE(6,110)
C
CALL COLOR(44,37,1,0,0)
C
DO 96 I = 1,30
STRING(I) = ' '
DATAVAR(CHESNUM,(I-1)*43+1) = CHAR(INT(I/10)+48)
96 DATAVAR(CHESNUM,(I-1)*43+2) = CHAR(MOD(I,10)+48)
C
As time permits, I'll translate the code to be more easily read and describe
the function of each portion. In the mean time, if you have a need
to write a routine that copies or moves data from one location to some set
of other locations and you want to keep the input short and sweet, feel free
to parse through the routine your self.
Discuss computer algorithms and other computer science topics at the Computer Algorithms blog page.
All code and original algorithms are © Erik Oosterwal - 1987-2008
Computer Science 101
Dressing for Success