REM Converts mCad HP-plotter files for Wanatabe plotter
rem This is offered as an example only. If you have some non-HP plotter
rem this will probably still give some ideas how to convert the plotfile.
rem Aegis draw plotfiles need a similar but not quite the same translation.
rem The conversion takes 5-10 minutes for a middle sized drawing, about
rem 40 minutes for the biggest plotfile mCad handles (voltage-to-frequency)

rem The names of the files can/should include full pathname details.

rem The plotfile is scaled as well as converted. This is needed because your
rem plotter might not have the same table size as the HP plotter.

rem The main parts of the HP plotfiles that are of interest are the commands
rem PU (=Pen Up) and PD (=Pen Down), and the coordinates that follow these.
rem The usual plotfile coordinates are in 0.001" steps, and if your plotter
rem (like the Wanatabe) uses 0.01mm steps then this requires a scaling
rem conversion of itself.


start:
INPUT "Enter name of mCad file to convert";mCad$
INPUT "Enter name of Wanatabe file to write";Wan$
INPUT "enter scaling factors a,b (scale=a/b) (eg 1,2.54)";a,b
scale=a/b
ch$=CHR$(10)

OPEN mCad$ FOR INPUT AS #1 LEN=1000
OPEN Wan$ FOR APPEND AS #2 LEN =1000


newfile:
WHILE NOT EOF(1)
LINE INPUT #1,a$
REM PRINT a$
IF LEN(a$)=0 GOTO windup 
status =0 : oldstatus=-1

newfile1:
 CALL LINP(a$,x$,x,status)
REM  PRINT "next item="; x$
  IF status > 0 THEN 
   x=x*scale
    IF oldstatus > 0 THEN PRINT #2, ","; :PRINT "," ;
   PRINT #2, STR$(INT(x)); : PRINT STR$(INT(x)) ;
  END IF
  
  IF MID$(x$,1,2) = "PU" THEN
   PRINT #2, ch$ ; "M";  : PRINT : PRINT "M" ;
   x=scale*VAL(MID$(x$,3,10))
   PRINT #2, STR$(INT(x)); ","; :PRINT STR$(INT(x)) ; ",";
  END IF

  IF MID$(x$,1,2) = "PD" THEN
   PRINT #2, ch$ ; "D"; :PRINT : PRINT "D" ;
   x=scale*VAL(MID$(x$,3,10))
   PRINT #2, STR$(INT(x)); "," ; : PRINT STR$(INT(x)) ; ",";
  END IF

IF oldstatus=status GOTO newfile
oldstatus=status
IF status <> 0 GOTO newfile1

WEND
REM GOTO newfile
  
windup:
 CLOSE #1
 CLOSE #2
 PRINT "mCad convert done"

END
 
SUB LINP(a$,x$,x,status) STATIC
 x$=""
 IF status=0 THEN c=1 : f1=0 : p=1 : i1=LEN(a$) 
 numfl=1 : reed=1
 WHILE  (reed=1 AND p<=i1)
  x$=MID$(a$,p,1) : reed=0
  IF (x$=" " OR x$="," OR x$=";") THEN reed=1 : p=p+1 
 WEND
  p0=p : reed=1 
 WHILE  (reed=1 AND p<=i1)
  x$=MID$(a$,p,1) : reed=0
  IF x$<>" " AND x$<>"," AND x$<>";" THEN reed=1 :  p=p+1
 WEND
 status=(i1-p+2)
 IF status<1 THEN status=0 : x$="" : x=0 : GOTO done
  x$=MID$(a$,p0,p-p0) :   Y$=x$
  FOR i=1 TO p-p0 : IF MID$(Y$,i,1)="0" THEN MID$(Y$,i,1)="1" : NEXT i
  x=VAL(x$) : Y=VAL(Y$) 
 IF Y=0 THEN status=-status
done:
END SUB
   
  
fin:

END
