
! script name: vthread.d/readvarfile
! var_topic: read a file for remote execution

!A
!A NAME:
!A
!A 	Read a variational file for remote execution.
!A
!A DESCRIPTION:
!A
!A	This script is used for remote execution of webmon by a thread.
!A
!B INSTRUCTIONS:
!B
!B	THIS PROGRAM DOES NOT INTERACT WITH THE USER.
!B	IT IS CALLED AUTOMATICALLY IN A VARIATIONAL THREAD.
!B
!# see also - vthread.d/thread.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: read variational file ")

DIM Answer$[256]
DIM Destination$[256]
DIM Header$[4096]
DIM Ac$[256]
DIM Filename$[256]
DIM Input_file$[256]
DIM Output_file$[256]
DIM Name$[256]
DIM Value$[256]
DIM Startup$[256]
DIM Setconstants$[256]
DIM Store_dir$[255],Retrieve_dir$[255]

stat= NamedVarStr("startup script",WsSystemVars,"startup",Startup$)
stat= NamedVarStr("startup constants",WsSystemVars,"setconstants",SetConstants$)
Stat= NamedVarStr("storage dir",WsSystemVars,"/usr/weber/ST/",Store_dir$)
Stat= NamedVarStr("retrieve dir",WsSystemVars,"/usr/weber/ST/",Retrieve_dir$)
Time_check= NamedVarVal("time check",WsSystemVars,720.0)

Stat= NamedVarStr("execute file",WsSystemVars,"",Filename$)
Stat= NamedVarStr("var input file",WsSystemVars,"",Input_file$)
Stat= NamedVarStr("var output file",WsSystemVars,"",Output_file$)
Done_thread= NamedVarVal("thread finished",WsSystemVars,0.0)

DeActivateUndo
IF NOT LEN(Filename$) THEN Leave
Op_mode=1
DeleteAll
Stat=ReadStoredFile(Filename$,Op_mode)

V1=CreateVariable("startup script",WsSystemVars,Startup$)
V1=CreateVariable("startup constants",WsSystemVars,SetConstants$)
V1=CreateVariable("storage dir",WsSystemVars,Store_dir$)
V1=CreateVariable("retrieve dir",WsSystemVars,Retrieve_dir$)
V1=CreateVariable("time check",WsSystemVars,Time_check)

Stat= CurrentHeader(Header$)
IF LEN(Header$) THEN
        Head=ReadUserData(WsGeneralString,"HEADER",Header$)
        IF ValidGeometry(Head) THEN
		Stat=GetUserString(Head,"Accumulated Time:",Ac$)
		Stat= PutUserString(Head,"File name:",Answer$)
		AccTime = VAL("0"&TRIM$(Ac$))
		V1=CreateVariable("accumulated time",WsSystemVars,AccTime)
		V1=CreateVariable("job start time",WsSystemVars,TIMEDATE)
		Enti= UserDataString(Head,Header$)
		Stat= FileHeader(Header$)
		Stat= DeleteEntity(Head)
        END IF
END IF
ResizeAll

V1=CreateVariable("execute file",WsSystemVars,Execute_file$)
V1=CreateVariable("var input file",WsSystemVars,Input_file$)
V1=CreateVariable("var output file",WsSystemVars,Output_file$)
V1=CreateVariable("thread finished",WsSystemVars,Done_thread)
Destination$= SetConstants$&":/vthread.d/execfromdata"


Leave:!
Stat=SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD SetConstants$
ELSE
	 LOAD Destination$
END IF
END

