
! script name: vthread.d/storevarfile
! var_topic: store an automatic variational program

!A
!A NAME:
!A
!A 	Automatic Variational  Store
!A
!A DESCRIPTION:
!A
!A	Stores the result of an execute of a variational file.
!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

DIM Answer$[256],Header$[4096],A$[256]
DIM Descr$[256],Datestr$[256],Output_file$[256]
DIM Tmp$[256],Space$[25],Jobs$[25],Unit$[256]
DIM Dir$[256],Mask$[256],Namelist$[5000],Filelist$(100)[100]

DeActivateUndo
Stat= NamedVarStr("var output file",WsSystemVars,"",Output_file$)
IF NOT LEN(Output_file$) THEN Leave
Stat= CurrentHeader(Header$)
IF LEN(Header$) THEN Head=ReadUserData(WsGeneralString,"HEADER",Header$)
Stat= DisplayMessage("SAFETY STORING FILE ")
DeleteAll

IF ValidGeometry(Head) THEN
	Stat= DateString(Datestr$)
	Stat= PutUserString(Head,"Revision date:",Datestr$)
        Units= CurrentUnits
        Unit$= RPT$("METRIC",Units= WsMetric)&RPT$("INCHES",Units=WsInch)
        Stat=PutUserString(Head,"Units:",Unit$)
	AccTime = TIMEDATE-NamedVarVal("job start time",WsSystemVars,0.0)
	AccTimer = NamedVarVal("accumulated time",WsSystemVars,0.0)
	AccTime=AccTime/60+AccTimer
	Stat=PutUserString(Head,"Accumulated Time:"," "&VAL$(PROUND(AccTime,-2))&" minutes")
END IF
UnSelectAll

IF ValidGeometry(Head) THEN
	Stat= PutUserString(Head,"Component files 1:","Geometry")
	I= 2
	WHILE CheckUserField(Head,"Component files "&VAL$(I)&":",1)
		Stat= PutUserString(Head,"Component files "&VAL$(I)&":","EMPTY")
		I= I+1
	END WHILE
	Enti= UserDataString(Head,Header$)
	Stat= FileHeader(Header$)
	Stat= DeleteEntity(Head)
END IF

Stat=StoreFile(Output_file$,1.0)

Leave:!
Stat=SendSlaveComplete
V1= CreateVariable("thread finished",WsSystemVars,1)
V1= CreateVariable("job time",WsSystemVars,TIMEDATE)
IF ValidGeometry(Head) THEN Stat= DeleteEntity(Head)
Stat=SetInputFormat("n4","")
LOAD "typecontrol"
END
