!!!
Spline version is faster than Legendre method, due to precalculated functions in folder DUMP. 
If you dont have this floder, create it and run program. First time it will write down all precalculated functions,
so the first run is not fast.
!!!

-------INPUT DATA
-points in sgems format, BUT first line is NUMBER OF POINTS
	Example:
	30
	3		
	x		
	y		
	v		
	16	32	0.035235
	2	83	0.37638
	83	81	0.75348
	.....

	Rows in file:
	1 row is number of points
	2 row is number of variables (3 for 2D and 4 for 3D)
	then variables names
	then points, each column is for variables described before

-Training image in sgems format, regular grid.
	Example:
	ti		
	3		
	x		
	y		
	v		
	0	0	0.00057052
	1	0	0.0036513
	2	0	0.010134
	3	0	0.015649
	.....

	Rows in file:
	1 row is just name, doesn't matter
	2 row is number of variables (3 for 2D and 4 for 3D)
	then variables names
	then points, each column is for variables described before. 
	first change x index, then y index, then z index


-Mask grid in sgems format, regular grid.
	Example:
	mask		
	3		
	x		
	y		
	v		
	0	0	0
	1	0	1
	2	0	1
	3	0	0
	.....

	Rows in file:
	1 row is just name, doesn't matter
	2 row is number of variables, algorithm takes the last column
	and use inexing from grid info provided
	then variables names
	then points, each column is for variables described before. 
	nodes with the values of last column bigger than 0 will be simulated, others will be assinged as -999;


-Parameters file
Example

2		                      	# DIMENSION OF THE PROBLEM: 2D or 3D
1                            	# NUMBER OF REALIZATIONS > 0
1                             	# NUMBER OF GRID LEVEL > 0
3                           	# METHOD: 1 LEGENDRE TI,2 LEGENDRE Data-driven, 3 SPLINE TI,4 SPLINE data driven
4664	                      	# SEED NUMBER > 0, for control of randomization
=======================================================
poro_data_500.txt  			# DATA FILE: SAMPLES . In file make sure you put number of samples in first row
poro_TI.txt                		# TRAINING IMAGE FILE
poro_spline.out                  	# OUTPUT FILE: REALIZATIONS  
poro.dbg	                	# DEBUG5GING FILE: CONTROL THE AMOUNT OF INFO USING THE VERBOSITY LEVEL CONYTOL BELOW.
=======================================================
0 100 1  		              	# GRID DIMENSION: (XMIN,NX,DX)
0 100 1			              	# GRID DIMENSION: (YMIN,NY,DY)
0 1   1			              	# GRID DIMENSION: (ZMIN,NZ,DZ)
poro_mask.txt				# MASK GRID: 0-all nodes to be simulated, 1 - name of mask grid
=======================================================
0 100 1  		              	# TRAINNG IMAGE DIMENSION: (XMIN,NX,DX)
0 100 1			              	# TRAINNG IMAGE DIMENSION: (YMIN,NY,DY)
0 1   1			              	# TRAINNG IMAGE DIMENSION: (ZMIN,NZ,DZ)
1000                           	# NUMBER OF RANDOM LOCATIONS USED TO ESTIMATE STATISTICS FROM TI.
=======================================================
17 17 5			              	# LOCAL SEARCHING NEIGHBORS: (NX,NY,NZ)
1 1 1			              	# not used in code, do not change. LOCAL SEARCHING NEIGHBORS: (DX,DY,DZ) 
0                             	# not used in code, do not change. DYNAMIC SEARCHING: 0 NO, 1 YES. IF YES, THEN SPECIFY NUMBER OF LEVELS
2 2 1                       	# not used in code, do not change. NUMBER OF LEVELS IN X,Y,Z DIRECTIONS ADDED TO FIND MIN NUMBER OF SAMPLES WHEN NEDEED ONLY. 
=======================================================
2 7  	                  		# MINIMUM & MAXIMUM NUMBER OF SAMPLES in LOCAL SEARCHING NEIGHBORS:   
3                           	# ORDER OF THE SERIES
=======================================================
1                             	# Keep 1 for speed. VERBOSITY LEVEL =
								# 1: THE ORDER THE POINTS ARE SIMULATED i.e RANDOM PATH.
								# 2: IN ADDITION to 1, THE SAMPLES USED TO SIMULATE EACH POINT.
								# 3: IN ADDITION to 2, THE CPDF and CCDF CALCULATED.
								# 4: IN ADDITION to 3, THE STATISTICS USED AND THEIR VALUES



If you dont need simulate all grid nodes, please provide mask grid file name in row 15.

----RUNINIG
run hosim.exe and print name of parameter file. All input files should be in folder.

-----OUTPUT:
There are two output, ASCII format for small cases and also binary *.sgems fromat, which can be uploaded to SGEMS software very fast.


!!!
For large data you can export TI and MASK-grid in binary format from SGEMS, it should have name extention *.sgems. 
The  values will be taken form first variable (names are taken in alphabetic order).
!!!


