-----------------------------------------------------------------------
--
-- Copyright (c) 2010 VINAS
-- All rights reserved.
--
-- This sample FVX script is not supported by VINAS and VINAS provides
-- no warranties or assurances about its fitness or merchantability.
-- It is provided at no cost and is for demonstration purposes only.
--
--                                      created on wed. mar. 16, 2011
-----------------------------------------------------------------------


-----------------------------------------------------------------------
--- function  ReadPlotsArray            ---- Streamline の        -----
---                                     ---- 軌跡座標列を配列格納 -----
---      strFileName: Streamline export data file name            -----
-----------------------------------------------------------------------
	function ReadPlotsArray(strFileName)

	Xarray={}
	Yarray={}
	Zarray={}

	fp_tmp=openfile(strFileName, "r")
	for i=1, 7 do                       ---- ヘッダ部の読み飛ばし
		nTmp=read(fp_tmp,"*l")
	end
	nPlots=read(fp_tmp,"*l")
	-- print("nPlots: "..nPlots)

	for i=1, nPlots do                  ---- 点の数だけ 読み込む loop
		Xarray[i]=read(fp_tmp,"*n")
		Yarray[i]=read(fp_tmp,"*n")
		Zarray[i]=read(fp_tmp,"*n")
		Duration=read(fp_tmp,"*n")
		CurScalar=read(fp_tmp,"*n")
	end

	closefile(fp_tmp)

	return nPlots, Xarray, Yarray, Zarray
	end -- function ReadPlotsArray()

-----------------------------------------------------------------------
-----------------------------------------------------------------------

-----------------------------------------------------------------------
---                                                               -----
---                   main  program                               -----
---                                                               -----
-----------------------------------------------------------------------

	---- export filename prefix ------
	strPrefix="SectionalView"

	---- marching increment step ------
	mStep=15

	---- streamline setting ------
	seeds={x = { -0.0150822},
			 y = {0.0350822},
			 z = {-0.0108454}}

	seeding_input_table = {
		seed_coord = "XYZ",
		mode = "add",
		seeds = seeds}


	streamline_table = {vector_func = "U",
						scalar_func = "epsilon",
						dataset = 1,
						visibility = "on",
						seeding = seeding_input_table,
						display_seeds = "on",

						calculation_parameters = {
							direction ="forward",
							step = 3,
						--	time_limit =20,
							release_interval =10,
							duration = 3}}

	---- preparing input dataset 
	data_input_table = {
		data_format = "unstructured",
		input_parameters = {
				name = "./FF055_sample.uns",
				options = {
					input_mode = "replace",
					transient = "off"
				},
		}
	}

	---- read dataset
	SampleTableHandle= read_dataset(data_input_table)

	---- read restart files
	fv_script("RESTART BOUNDARY sample.bnd")
	fv_script("RESTART VIEW sample.vct")

	---- create streamline
	rake_handle=create_streamline(streamline_table)


	---- export streamline location plots
	strFileName="tmp.lne"
	fv_script("EXPORT STREAM "..strFileName)


	----  storing streamline location plots data
	nPlots, Xarray, Yarray, Zarray=ReadPlotsArray(strFileName)



	----  probe current function
	point={Xarray[nPlots-1], Yarray[nPlots-1], Zarray[nPlots-1]}
	probe_cf_result=probe_current_functions(point, 1)
	ScalarName=probe_cf_result.scalar.func
	ScalarValue=probe_cf_result.scalar.value


	-------------------------------------------------------------
	-------   output --------------------------------------------
	-------------------------------------------------------------

	print("\n")
	print("\n")
	print("nPlots: "..nPlots)
	print("----- seed point  -------\n")
	print("X:".." "..Xarray[1])
	print("Y:".." "..Yarray[1])
	print("Z:".." "..Zarray[1])
	print("\n")
	print("----- terminal point  -------\n")
	print("X:".." "..Xarray[nPlots-1])
	print("Y:".." "..Yarray[nPlots-1])
	print("Z:".." "..Zarray[nPlots-1])
	print("\n")
	print("Scalar Name:".." "..ScalarName)
	print("Scalar Value:".." "..ScalarValue)
	print("\n")




