! script name: backplotmill
! topic: Convert NC code to geometry
!A	
!A	NAME:  Backplot NC Code for mill
!A	
!A	DESCRIPTION:
!A	
!A	The source NC code file can be in either decimal or trailing zero format.
!A	The converted tape is in decimal format.
!A	The convert function will sense the input format based on finding a
!A	decimal point in X, Y or Z axis numbers in the first 100 blocks.
!A	
!A	The input file name determines the optional offset filename by finding 
!A	the extension ( i.e .nc ) and replacing it with .oft for the offset name.
!A	The X,Y,Z,I,J,K words are converted to decimal if necessary.
!A	

stat=ChangeLabelStr("ScriptNameStatus","Function: backplot mill ")

DIM Inputname$[256]
DIM Output_file$[256]
DIM Answer$[256]
DIM Destination$[256]
DIM Fileline$[2048]
DIM Fileline1$[2048]
DIM Filename$[256]
DIM Offset_file$[256]
DIM Tempdata$[256]
DIM Tapeline$[512]
DIM Dir$[512]
DIM Dir1$[512]
DIM D_label$[256]
DIM Sub_label$[256]
DIM F_label$[256]
DIM Choice$[256]
DIM Mask$[32]
DIM A$[256],B$[256],C$[256]
DIM Comments$[512]
DEG

StdWorkplane

Input_name:!
Stat= NamedVarStr("retrieve dir",WsSystemVars,"/usr/weber/ST/",Dir$)
IF (OSystemId=0) THEN      ! NT
        Stat= ReplaceString(Dir$,"/","\\",Dir1$)
        Stat= DisplayMessage("CHOOSE SOURCE TAPE FILE FROM FILE BOX")
        LOOP
            Stat= StartProcess("/mksnt/filebox -a -d "&Dir1$&" >/tmp/filename")
            IF Stat THEN Leave
	    Stat= GetFileLine("/tmp/filename",1,Inputname$)
            IF NOT Stat THEN 
            	Stat= DisplayMessage("ERROR ACCESSING FILE ")
            	Leave_loop= 0
	    ELSE
        	Stat= ReplaceString(Inputname$,CHR$(13),"",Answer$)
            	Leave_loop= 1
	    END IF
            EXIT IF Leave_loop
        END LOOP
        Stat= ReplaceString(Dir1$,"\\","/",Dir$)
	Inputname$= Answer$
ELSE                    !HP
        D_label$="DIRECTORY"
        Sub_label$="SUB DIRECTORIES"
        F_label$="FILES"
        Choice$="FILE TO OPEN"
        Mask$="[A-Za-z0-9]*"

   	Stat=UserFileBox(Dir$,Mask$,D_label$,Sub_label$,F_label$,Choice$,"Synergy")
        Stat=SetInputFormat("a99","")
        Stat=GetValue("SELECT SOURCE TAPE FILE",Answer$)
        IF (ExitScript(Destination$)) THEN Leave
        IF Answer$= "CANCEL" THEN Leave
        LowerFileBox
	Inputname$= Answer$
END IF

Offset_name:!
P=POS(Inputname$,".")
IF P>1 THEN
Offset_file$=Inputname$[1,P-1]&".oft"
ELSE
Offset_file$=Inputname$&".oft"
END IF

! Format of ConvertNCFile is (inputfile, LatheInput)
LatheInput=0
Stat=ConvertNCFile(Inputname$,LatheInput)

Leave:!

IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
