Index: /proiecte/SolarSim/C/Parallel/data/astro.dat
===================================================================
--- /proiecte/SolarSim/C/Parallel/data/astro.dat	(revision 152)
+++ /proiecte/SolarSim/C/Parallel/data/astro.dat	(revision 152)
@@ -0,0 +1,12 @@
+   7
+   0			     0				0			   0			     0			      0			1.9891E30
+   0.039718988356852E12   0.030366785604440E12   0.023168117667570E12 -15.819644993401820E03  40.233248676558141E03 -25.613394663449039E03	3.3022E+023
+  -0.098568144514351E12   0.033356749016186E12   0.026905994589281E12 -11.242902837405447E03 -33.415356416769157E03   0.239187799619533E03	4.8685E+024
+  -0.129426625182282E12  -0.070884654059210E12                   0E12  14.502901794973520E03 -26.480507799411470E03                   0E03	5.9736E+024
+   0.208051264177585E12  -0.001936863781400E12  -0.001936863781400E12   0.258530665135422E03  26.319735594121685E03   0.545055020111751E03	6.4185E+023
+   0.598568406789902E12   0.439603107246420E12  -0.015231294985490E12  -8.089003954667575E03  11.018770541158787E03   0.135481472067609E03	1.8986E+027
+   0.958404810010585E12   0.982839000229841E12  -0.055213235013157E12  -7.175777227784183E03   7.006558089055758E03   0.163350990481469E03	5.6846E+026
+
+   1.599099852341484E12  -2.066691216742713E12   1.212370570567251E12   3.162717831418037E03   4.662650706035524E03   3.776698110992691E03	8.6810E+025
+   3.598260599264261E12   0.006647772527355E12  -2.770476993836326E12   3.184576985353795E03  -1.325068383752312E03   4.132908940950548E03	1.0243E+026
+   6.617128192603119E12   2.257835220151279E12   0.958573939536201E12  -0.322219536847948E03  -0.676751330966366E03   3.818339744970676E03	1.3050E+02
Index: /proiecte/SolarSim/C/Parallel/data/astro_peri.dat
===================================================================
--- /proiecte/SolarSim/C/Parallel/data/astro_peri.dat	(revision 152)
+++ /proiecte/SolarSim/C/Parallel/data/astro_peri.dat	(revision 152)
@@ -0,0 +1,12 @@
+10
+0 0 0 0 0 0 1.9891E30
+46001251767	0	0	0	60264.22	0	3.3022E+023
+107473109276	0	0	0	35260.43	0	4.8685E+024
+147098074037.94	0	0	0	30290.86	0	5.9736E+024
+206668962883.5	0	0	0	26612.76	0	6.4185E+023
+740573560320	0	0	0	13725.56	0	1.8986E+027
+1353572956830.08	0	0	0	10189.79	0	5.6846E+026
+2748938461629.85	0	0	0	7107.82	0	8.6810E+025
+4452940832359.2	0	0	0	5490.11	0	1.0243E+026
+-4436824612684.16	0	0	0	-6310.21		0	1.3050E+022
+
Index: /proiecte/SolarSim/C/Parallel/makef.icc
===================================================================
--- /proiecte/SolarSim/C/Parallel/makef.icc	(revision 152)
+++ /proiecte/SolarSim/C/Parallel/makef.icc	(revision 152)
@@ -0,0 +1,11 @@
+CC=icc
+CFLAGS=-openmp
+SRC=src
+BIN=bin
+OUTFILE=SolarSim.$(CC)
+
+all:
+	$(CC) -o $(BIN)/$(OUTFILE) $(SRC)/*.c $(CFLAGS)
+
+clean:
+	$(RM) $(BIN)/$(OUTFILE)
Index: /proiecte/SolarSim/C/Parallel/makefile.gcc
===================================================================
--- /proiecte/SolarSim/C/Parallel/makefile.gcc	(revision 152)
+++ /proiecte/SolarSim/C/Parallel/makefile.gcc	(revision 152)
@@ -0,0 +1,11 @@
+CC=gcc
+CFLAGS=-fopenmp -lm
+SRC=src
+BIN=bin
+OUTFILE=SolarSim.$(CC)
+
+all:
+	$(CC) -o $(BIN)/$(OUTFILE) $(SRC)/*.c $(CFLAGS)
+
+clean:
+	$(RM) $(BIN)/$(OUTFILE)
Index: /proiecte/SolarSim/C/Parallel/run.sh
===================================================================
--- /proiecte/SolarSim/C/Parallel/run.sh	(revision 152)
+++ /proiecte/SolarSim/C/Parallel/run.sh	(revision 152)
@@ -0,0 +1,4 @@
+setenv OMP_NUM_THREADS $1
+setenv OMP_SCHEDULE static
+$argv[2-]
+
Index: /proiecte/SolarSim/C/Parallel/src/SolarSim.c
===================================================================
--- /proiecte/SolarSim/C/Parallel/src/SolarSim.c	(revision 152)
+++ /proiecte/SolarSim/C/Parallel/src/SolarSim.c	(revision 152)
@@ -0,0 +1,117 @@
+/* SolarSim.c */
+#include "SolarSim.h"
+
+typedef struct task {
+	int i, j;
+} Task, *TaskPtr;
+
+int sock = 0;
+long SIM_STEPS, DT, SAVE;
+
+void
+do_work(AState state) {
+	int i, j, t, ntasks, tid, nthreads;
+	long sim_step;
+	int n = state->particles;
+	vector *r = state->positions;
+	vector *v = state->velocities;
+	vector *a = state->accelerations;
+	vector *ac;
+	real *m = state->masses;
+	TaskPtr tasks;
+
+	tasks = malloc( n*(n-1)/2 * sizeof(Task) );
+	t = 0;
+	for( i = 0; i < n-1; i++ )
+		for( j = i+1; j < n; j++ ) {
+			tasks[t].i = i;
+			tasks[t].j = j;
+			t++;
+		}
+	ntasks = t;
+
+	#pragma omp parallel shared(nthreads)
+	{
+		#pragma omp master
+		nthreads = omp_get_num_threads();
+	}
+	ac = malloc(nthreads * n * sizeof(vector));
+	
+	sim_step = 0;
+	while( sim_step < SIM_STEPS ) {
+		if( (SAVE != 0) && (sim_step % SAVE == 0) ) {
+			write_state(sock, state);
+		}
+		
+		#pragma omp parallel for schedule(runtime) shared(ac,n,nthreads) private(i) default(none)
+		for( i = 0; i < n*nthreads; i++ ) {
+			ac[i].x = 0;
+			ac[i].y = 0;
+			ac[i].z = 0;
+		}
+
+		// compute accelerations. each thread uses ac[tid] vector
+		#pragma omp parallel for schedule(runtime) shared(tasks, ntasks, r, v, ac, m, n) private(i,j,t,tid) default(none)
+		for( t = 0; t < ntasks; t++ ) {
+			i = tasks[t].i;
+			j = tasks[t].j;
+			tid = omp_get_thread_num();
+//			printf("%d computed (%d,%d)\n", tid, i, j);
+			compute_acc(r+i, r+j, v+i, v+j, ac+tid*n+i, ac+tid*n+j, m[i], m[j]);
+		}
+
+		// add up the accelerations computed by each thread
+		#pragma omp parallel for schedule(runtime) shared(a,ac,n,nthreads) private(i,j) default(none)
+		for( i = 0; i < n; i++ ) {
+			v_init(a+i,0,0,0);
+			for( j = 0; j < nthreads; j++ ) {
+				a[i].x += ac[j*n+i].x;
+				a[i].y += ac[j*n+i].y;
+				a[i].z += ac[j*n+i].z;
+			}
+		}
+
+		// update positions and speeds
+		#pragma omp parallel for schedule(runtime) shared(r,v,a,n,DT) private(i) default(none)
+		for( i = 0; i < n; i++ ) {
+			update_pos_vel(r+i, v+i, a+i, DT);
+		}
+		sim_step ++;
+	}
+	if( SAVE != 0 )
+		write_state(sock, state);
+}
+
+int
+main( int argc, char **argv ) {
+	TState state;
+	double before, after;
+	int i;
+
+	SIM_STEPS = atol(argv[3]);
+	DT = atol(argv[4]);
+	SAVE = atol(argv[5]);
+
+	if( SAVE != 0 ) {
+		sock = open( argv[2], O_WRONLY | O_CREAT | O_TRUNC, 644 );
+	}
+
+	read_initial( &state, argv[1] );
+
+	before = omp_get_wtime();
+	do_work(&state);
+	after = omp_get_wtime();
+
+	if( SAVE != 0 ) {
+		i = 0;
+		write( sock, &i, sizeof(int) );
+		close(sock);
+	}
+
+	#pragma omp parallel
+	#pragma omp master
+	printf("%d %lf\n", omp_get_num_threads(), after-before);
+
+	return EXIT_SUCCESS;
+}
+
Index: /proiecte/SolarSim/C/Parallel/src/SolarSim.c3
===================================================================
--- /proiecte/SolarSim/C/Parallel/src/SolarSim.c3	(revision 152)
+++ /proiecte/SolarSim/C/Parallel/src/SolarSim.c3	(revision 152)
@@ -0,0 +1,118 @@
+/* SolarSim.c */
+#include "SolarSim.h"
+
+typedef struct task {
+	int i, j;
+} Task, *TaskPtr;
+
+int sock = 0;
+long SIM_STEPS, DT, SAVE;
+
+void
+do_work(AState state) {
+	int tid, nthreads;
+	long i, j, t, ntasks, sim_step;
+	int n = state->particles;
+	vector *r = state->positions;
+	vector *v = state->velocities;
+	vector *a = state->accelerations;
+	vector *ac;
+	real *m = state->masses;
+	TaskPtr tasks;
+
+	tasks = malloc( n*(n-1)/2 * sizeof(Task) );
+	t = 0;
+	for( i = 0; i < n-1; i++ )
+		for( j = i+1; j < n; j++ ) {
+			tasks[t].i = i;
+			tasks[t].j = j;
+			t++;
+		}
+	ntasks = t;
+
+	#pragma omp parallel shared(nthreads)
+	#pragma omp master
+	nthreads = omp_get_num_threads();
+
+	ac = malloc(nthreads * n * sizeof(vector));
+	
+	#pragma omp parallel shared(r,v,a,ac,m,n,tasks,ntasks,nthreads,DT,sim_step,SIM_STEPS,SAVE) private(i,j,t,tid) default(none)
+	sim_step = 0;
+	while( sim_step < SIM_STEPS ) {
+		if( (SAVE != 0) && (sim_step % SAVE == 0) ) {
+			write_state(sock, state);
+		}
+		
+		#pragma omp for schedule(static,n) //shared(ac,n,nthreads) private(i) default(none) nowait
+		for( i = 0; i < n*nthreads; i++ ) {
+			ac[i].x = 0;
+			ac[i].y = 0;
+			ac[i].z = 0;
+		}
+
+		// compute accelerations. each thread uses ac[tid] vector
+		#pragma omp for schedule(static) //shared(tasks, ntasks, r, v, ac, m, n) private(i,j,t,tid) default(none) nowait
+		for( t = 0; t < ntasks; t++ ) {
+			i = tasks[t].i;
+			j = tasks[t].j;
+			tid = omp_get_thread_num();
+			compute_acc(r+i, r+j, v+i, v+j, ac+tid*n+i, ac+tid*n+j, m[i], m[j]);
+		}
+
+		// add up the accelerations computed by each thread
+		#pragma omp parallel for schedule(static,1) //shared(a,ac,n,nthreads) private(i,j) default(none) nowait
+		for( i = 0; i < n; i++ ) {
+			v_init(a+i,0,0,0);
+			for( j = 0; j < nthreads; j++ ) {
+				a[i].x += ac[j*n+i].x;
+				a[i].y += ac[j*n+i].y;
+				a[i].z += ac[j*n+i].z;
+			}
+		}
+
+		// update positions and speeds
+		#pragma omp parallel for schedule(static,1) //shared(r,v,a,n,DT) private(i) default(none) nowait
+		for( i = 0; i < n; i++ ) {
+			update_pos_vel(r+i, v+i, a+i, DT);
+		}
+
+		#pragma omp master
+		sim_step ++;
+
+		#pragma omp barrier
+	}
+	if( SAVE != 0 )
+		write_state(sock, state);
+}
+
+int
+main( int argc, char **argv ) {
+	TState state;
+	double before, after;
+	int i, n=8;
+
+	SIM_STEPS = atol(argv[3]);
+	DT = atol(argv[4]);
+	SAVE = atol(argv[5]);
+
+	if( SAVE != 0 ) {
+		sock = open( argv[2], O_WRONLY | O_CREAT | O_TRUNC, 644 );
+	}
+
+//	read_initial( &state, argv[1] );
+	rand_data( &state, 100 );
+
+	before = omp_get_wtime();
+	do_work(&state);
+	after = omp_get_wtime();
+
+	if( SAVE != 0 )
+		close(sock);
+
+	#pragma omp parallel
+	#pragma omp master
+	printf("%d %lf\n", omp_get_num_threads(), after-before);
+
+	return EXIT_SUCCESS;
+}
+
Index: /proiecte/SolarSim/C/Parallel/src/SolarSim.h
===================================================================
--- /proiecte/SolarSim/C/Parallel/src/SolarSim.h	(revision 152)
+++ /proiecte/SolarSim/C/Parallel/src/SolarSim.h	(revision 152)
@@ -0,0 +1,56 @@
+/* SolarSim.h */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <fcntl.h>
+#include <omp.h>
+
+#if __INTEL_COMPILER
+#include <pmmintrin.h>
+#endif
+
+#define _SINGLE_PRECISION_
+//#define _DOUBLE_PRECISION_
+
+#if defined _DOUBLE_PRECISION_
+typedef double real;
+#elif defined _SINGLE_PRECISION_
+typedef float real;
+#else
+	#error "Must have either _DOUBLE_PRECISION_ or _SINGLE_PRECISION_ defined."
+#endif
+
+/* simulation constants */
+#define G	6.6743E-11		// m^3 kg^-1 s^-2
+
+typedef struct vector {
+	real x, y, z;
+	real unused;
+} vector;
+
+typedef struct state {
+	int particles;
+	vector * positions;
+	vector * velocities;
+	vector * accelerations;
+	real * masses;
+} TState, *AState;
+
+/* declared in "io.c" */
+void read_initial( AState state, const char *filename );
+void rand_data( AState state, int nParticles );
+
+int connect_to_server( char * servername, int portno, int protocol );
+
+void send_state( int sock, AState state );
+
+void write_state( int fd, AState state );
+
+/* declared in "compute.c" */
+inline void compute_acc( vector *rv1, vector *rv2, vector *vv1, vector *vv2, vector *av1, vector *av2, real m1, real m2 );
+
+inline void update_pos_vel( vector *rv, vector *vv, vector *av, long DT );
+
+inline void v_init( vector *v, real x, real y, real z );
+
Index: /proiecte/SolarSim/C/Parallel/src/compute.c
===================================================================
--- /proiecte/SolarSim/C/Parallel/src/compute.c	(revision 152)
+++ /proiecte/SolarSim/C/Parallel/src/compute.c	(revision 152)
@@ -0,0 +1,204 @@
+/* compute.c */
+#include "SolarSim.h"
+
+inline void
+v_init( vector *v, real x, real y, real z ) {
+	v->x = x;
+	v->y = y;
+	v->z = z;	
+}
+
+#if __INTEL_COMPILER
+#if defined _DOUBLE_PRECISION_
+/* double precision using SSE instructions */
+inline void
+compute_acc( vector *rv1, vector *rv2, vector *vv1, vector *vv2, vector *av1, vector *av2, real m1, real m2 ) {
+	__m128d r11, r12, r21, r22, d1, d2, t1, t2, a11, a12, a21, a22;
+	double tmp;
+
+	// load position vectors into SSE registers
+	r11 = _mm_loadu_pd((double*)rv1);	// (x1, y1)
+	r12 = _mm_load1_pd((double*)rv1+2);	// (z1, z1)
+	r21 = _mm_loadu_pd((double*)rv2);	// (x2, y2)
+	r22 = _mm_load1_pd((double*)rv2+2);	// (z2, z2)
+
+	// load acceleration vectors
+	a11 = _mm_loadu_pd((double*)av1);
+	a12 = _mm_load1_pd((double*)av1+2);
+	a21 = _mm_loadu_pd((double*)av2);
+	a22 = _mm_load1_pd((double*)av2+2);
+	// d = r2 - r1
+	d1= _mm_sub_pd(r21, r11);	// (dx dy)
+	d2= _mm_sub_pd(r22, r12);	// (dz dz)
+
+	t1 = _mm_mul_pd(d1, d1);	// (dx^2, dy^2)
+	t2 = _mm_mul_pd(d2, d2);	// (dz^2, dz^2)
+	t1 = _mm_hadd_pd(t1, t1);	// (dx^2+dy^2, dx^2+dy^2)
+	t1 = _mm_add_pd(t1, t2);	// (dx^2+dy^2+dz^2, dx^2+dy^2+dz^2)
+
+	t2 = _mm_sqrt_pd(t1);		// t2 = (norm(d), norm(d))
+	d1 = _mm_div_pd(d1, t1);	// d = d * (norm(d) ^(-3))
+	d1 = _mm_div_pd(d1, t2);	// d = d * (norm(d) ^(-3))
+	d2 = _mm_div_pd(d2, t1);	// d = d * (norm(d) ^(-3))
+	d2 = _mm_div_pd(d2, t2);	// d = d * (norm(d) ^(-3))
+
+	tmp = G * m2;
+	t1 = _mm_load1_pd(&tmp);
+	t2 = _mm_mul_pd(t1, d1);
+	a11 = _mm_add_pd(a11, t2);
+	t2 = _mm_mul_pd(t1, d2);
+	a12 = _mm_add_pd(a12, t2);
+
+	tmp = - G * m1;
+	t1 = _mm_load1_pd(&tmp);
+	t2 = _mm_mul_pd(t1, d1);
+	a21 = _mm_add_pd(a21, t2);
+	t2 = _mm_mul_pd(t1, d2);
+	a22 = _mm_add_pd(a22, t2);
+
+	_mm_storeu_pd((double*)av1, a11);
+	_mm_store_sd((double*)av1+2, a12);
+	_mm_storeu_pd((double*)av2, a21);
+	_mm_store_sd((double*)av2+2, a22);
+}
+
+inline void
+update_pos_vel( vector *rv, vector *vv, vector *av, long DT ) {
+	__m128d r1, r2, v1, v2, a1, a2, t1, t2;
+	double tmp;
+
+	r1 = _mm_loadu_pd((double*)rv);	
+	r2 = _mm_load1_pd((double*)rv+2);	
+	v1 = _mm_loadu_pd((double*)vv);	
+	v2 = _mm_load1_pd((double*)vv+2);	
+	a1 = _mm_loadu_pd((double*)av);	
+	a2 = _mm_load1_pd((double*)av+2);	
+
+	tmp = DT;
+	t1 = _mm_load1_pd(&tmp);	// t1 = (DT,DT)
+
+	t2 = _mm_mul_pd(v1, t1);	// t2 = (vx*DT,vy*DT)
+	r1 = _mm_add_pd(r1, t2);	// r1 = (rx+vx*DT, ry+vy*DT)
+	t2 = _mm_mul_pd(v2, t1);	// t2 = (vz*DT,vz*DT)
+	r2 = _mm_add_pd(r2, t2);	// r2 = (rz+vz*DT, rz+vz*DT)
+
+	t2 = _mm_mul_pd(a1, t1);	// t2 = (ax*DT, ay*DT)
+	v1 = _mm_add_pd(v1, t2);	// v1 = (vx+ax*DT, vy+ay*DT)
+	t2 = _mm_mul_pd(a2, t1);	// t2 = (az*DT, az*DT)
+	v2 = _mm_add_pd(v2, t2);	// v1 = (vz+az*DT, vz+az*DT)
+
+	tmp = DT*DT/2;
+	t1 = _mm_load1_pd(&tmp);	// t1 = (DT*DT/2, DT*DT/2)
+
+	t2 = _mm_mul_pd(a1, t1);	// t2 = (ax*DT*DT/2,ay*DT*DT/2)
+	r1 = _mm_add_pd(r1, t2);	// r1 = (rx+vx*DT+ax*DT*DT/2, ry+vy*DT+ay*DT*DT/2)
+	t2 = _mm_mul_pd(a2, t1);	// t2 = (az*DT*DT/2,az*DT*DT/2)
+	r2 = _mm_add_pd(r2, t2);	// r2 = (rz+vz*DT+az*DT*DT/2, rz+vz*DT+az*DT*DT/2)
+
+	_mm_storeu_pd((double*)rv, r1);
+	_mm_store_sd((double*)rv+2, r2);
+	_mm_storeu_pd((double*)vv, v1);
+	_mm_store_sd((double*)vv+2, v2);
+}
+
+#elif defined _SINGLE_PRECISION_
+/* single precision using SSE instructions */
+inline void
+compute_acc( vector *rv1, vector *rv2, vector *vv1, vector *vv2, vector *av1, vector *av2, real m1, real m2 ) {
+	__m128 r1, r2, d, t1, t2, a1, a2;
+	float tmp;
+
+	// load position and acceleration vectors into SSE registers
+	r1 = _mm_loadu_ps((float*)rv1);	
+	r2 = _mm_loadu_ps((float*)rv2);
+	a1 = _mm_loadu_ps((float*)av1);
+	a2 = _mm_loadu_ps((float*)av2);
+
+	d = _mm_sub_ps(r2, r1);	// d = r2 - r1
+	t1 = _mm_mul_ps(d, d);
+	t1 = _mm_hadd_ps(t1, t1);
+	t1 = _mm_hadd_ps(t1, t1);	// t1 = norm(d) ^ 2
+	t2 = _mm_rcp_ps(t1);	// t2 = norm(d) ^ (-2)
+	t1 = _mm_rsqrt_ps(t1);	// t1 = norm(d) ^ (-1)
+	d = _mm_mul_ps(d, t1);	// d = d * (norm(d) ^(-1))
+	d = _mm_mul_ps(d, t2);	// d = d * (norm(d) ^(-3))
+
+	tmp = G * m2;
+	t1 = _mm_load1_ps(&tmp);
+	t1 = _mm_mul_ps(t1, d);
+	a1 = _mm_add_ps(a1, t1);
+
+	tmp = - G * m1;
+	t2 = _mm_load1_ps(&tmp);
+	t2 = _mm_mul_ps(t2, d);
+	a2 = _mm_add_ps(a2, t2);
+
+	_mm_storeu_ps((float*)av1, a1);
+	_mm_storeu_ps((float*)av2, a2);
+}
+
+inline void
+update_pos_vel( vector *rv, vector *vv, vector *av, long DT ) {
+	__m128 r, v, a, t1, t2;
+	float tmp;
+
+	r = _mm_loadu_ps((float*)rv);	
+	v = _mm_loadu_ps((float*)vv);
+	a = _mm_loadu_ps((float*)av);
+
+	tmp = DT;
+	t1 = _mm_load1_ps(&tmp);	// t1 = (DT,DT,DT)
+	t2 = _mm_mul_ps(v, t1);		// t2 = v*DT
+	r = _mm_add_ps(r, t2);		// r = r + v*DT
+
+	t2 = _mm_mul_ps(a, t1);		// t2 = a*DT
+	v = _mm_add_ps(v, t2);		// v = v + a*DT
+
+	tmp = DT*DT/2;
+	t1 = _mm_load1_ps(&tmp);
+	t2 = _mm_mul_ps(a, t1);		// t2 = a * (DT*DT/2)
+	r = _mm_add_ps(r, t2);		// r = r + v*DT + a*(DT*DT/2)
+
+	_mm_storeu_ps((float*)rv, r);
+	_mm_storeu_ps((float*)vv, v);
+}
+#else
+	#error "Either _SINGLE_PRECISION_ or _DOUBLE_PRECISION_ must be defined"
+#endif
+
+#else
+/* Compatibility mode without SSE instructions */
+inline void
+compute_acc( vector *rv1, vector *rv2, vector *vv1, vector *vv2, vector *av1, vector *av2, real m1, real m2 ) {
+	// varianta fara SSE
+	vector d;
+	real w, norm3;
+
+	d.x = rv2->x - rv1->x;
+	d.y = rv2->y - rv1->y;
+	d.z = rv2->z - rv1->z;
+
+	w = d.x*d.x + d.y*d.y + d.z*d.z;	// norm^2
+	norm3 = w * sqrt(w);			// norm^3
+
+	av1->x += G * m2 * d.x / norm3;
+	av1->y += G * m2 * d.y / norm3;
+	av1->z += G * m2 * d.z / norm3;
+
+	av2->x -= G * m1 * d.x / norm3;
+	av2->y -= G * m1 * d.y / norm3;
+	av2->z -= G * m1 * d.z / norm3;
+}
+
+inline void
+update_pos_vel( vector *rv, vector *vv, vector *av, long DT ) {
+	rv->x = rv->x + vv->x * DT + av->x * (DT*DT)/2;
+	rv->y = rv->y + vv->y * DT + av->y * (DT*DT)/2;
+	rv->z = rv->z + vv->z * DT + av->z * (DT*DT)/2;
+
+	vv->x = vv->x + av->x * DT;
+	vv->y = vv->y + av->y * DT;
+	vv->z = vv->z + av->z * DT;
+}
+#endif
+
Index: /proiecte/SolarSim/C/Parallel/src/io.c
===================================================================
--- /proiecte/SolarSim/C/Parallel/src/io.c	(revision 152)
+++ /proiecte/SolarSim/C/Parallel/src/io.c	(revision 152)
@@ -0,0 +1,152 @@
+/* io.c */
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <math.h>
+
+#include "SolarSim.h"
+
+void
+read_initial( AState state, const char *filename ) {
+	int i;
+	double rx, ry, rz, vx, vy, vz, mass;
+
+	FILE *f = fopen(filename, "rt");
+	if( !f ) {
+		state->particles = 0;
+		return;
+	}
+
+	fscanf( f, "%d\n", &state->particles );
+	state->masses = malloc( state->particles * sizeof(real) );
+	state->positions = malloc( state->particles * sizeof(vector) );
+	state->velocities = malloc( state->particles * sizeof(vector) );
+	state->accelerations = malloc( state->particles * sizeof(vector) );
+	
+	for( i = 0; i < state->particles; i++ ) {
+		fscanf( f, "%lf %lf %lf %lf %lf %lf %lf\n", &rx, &ry, &rz, &vx, &vy, &vz, &mass );
+		state->masses[i] = mass;
+		v_init(&state->positions[i],(real)rx,(real)ry,(real)rz);
+		v_init(&state->velocities[i],(real)vx,(real)vy,(real)vz);
+	}
+
+	fclose(f);
+}
+
+void
+rand_data( AState state, int nParticles ) {
+	int i;
+	double rx, ry, rz, vx, vy, vz, mass;
+
+	state->particles = nParticles;
+	state->masses = malloc( state->particles * sizeof(real) );
+	state->positions = malloc( state->particles * sizeof(vector) );
+	state->velocities = malloc( state->particles * sizeof(vector) );
+	state->accelerations = malloc( state->particles * sizeof(vector) );
+
+	srand( time(NULL) );
+	for( i = 0; i < nParticles; i++ ) {
+		rx = ((double)rand()) / RAND_MAX * 150E09;
+		ry = ((double)rand()) / RAND_MAX * 150E09;
+		rz = ((double)rand()) / RAND_MAX * 150E09;
+		vx = ((double)rand()) / RAND_MAX * 150E09;
+		vy = ((double)rand()) / RAND_MAX * 150E09;
+		vz = ((double)rand()) / RAND_MAX * 150E09;
+		mass = ((double)rand()) / RAND_MAX * 1E20;
+		
+		state->masses[i] = mass;
+		v_init(&state->positions[i],(real)rx,(real)ry,(real)rz);
+		v_init(&state->velocities[i],(real)vx,(real)vy,(real)vz);
+	}
+}
+
+int
+connect_to_server( char *servername, int portno, int PROTOCOL ){
+	return connect_to_server_tcp(servername, portno);
+}
+
+int
+connect_to_server_tcp( char* servername, int portno ){
+	struct sockaddr_in serv_addr;
+	struct hostent *server;
+	int server_sockfd;
+
+	server_sockfd = socket( AF_INET, SOCK_STREAM, 0 );
+	if ( server_sockfd < 0 ) {
+        	printf ( "ERROR opening socket" );
+		return -1;
+	}
+    
+	server = gethostbyname( servername );
+	if (server == NULL) {
+        	fprintf( stderr, "ERROR, no such host\n" );
+		return -1;
+	}
+    
+	memset( (char *) &serv_addr, 0, sizeof(serv_addr) );
+	serv_addr.sin_family = AF_INET;
+	memcpy( (char *)&serv_addr.sin_addr.s_addr, (char *)server->h_addr, server->h_length );
+	serv_addr.sin_port = htons( portno );
+    
+	if ( connect( server_sockfd, (struct sockaddr*) &serv_addr, sizeof( serv_addr ) ) < 0 ) {
+        	printf( "ERROR connecting" );
+		return -1;
+	}
+
+	return server_sockfd;
+}
+
+
+int
+connect_to_server_udp( char* servername, int portno ){
+	struct sockaddr_in serv_addr, cli_addr;
+	struct hostent *server;
+	int server_sockfd, n;
+
+	server_sockfd = socket( AF_INET, SOCK_DGRAM, 0 );
+	if ( server_sockfd < 0 ) {
+        	printf ( "ERROR opening socket" );
+		return -1;
+	}
+    
+	server = gethostbyname( servername );
+	if (server == NULL) {
+        	fprintf( stderr, "ERROR, no such host\n" );
+		return -1;
+	}
+    
+	memset( (char *) &serv_addr, 0, sizeof(serv_addr) );
+	serv_addr.sin_family = AF_INET;
+	memcpy( (char *)&serv_addr.sin_addr.s_addr, (char *)server->h_addr, server->h_length );
+	serv_addr.sin_port = htons( portno );
+
+	memset( (char *) &cli_addr, 0, sizeof(cli_addr) );
+	cli_addr.sin_family = AF_INET;
+	cli_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+	cli_addr.sin_port = htons(0);
+
+	n = bind(server_sockfd, (struct sockaddr *) &cli_addr, sizeof(cli_addr));
+   	if( n < 0 ) {
+		fprintf(stderr, "%d: cannot bind port\n", portno);
+      		return -1;
+	}
+
+	return server_sockfd;
+}
+
+void
+send_state( int sock, AState state ) {
+	send( sock, &state->particles, sizeof(int), 0 );
+	send( sock, state->masses, state->particles*sizeof(real), 0 );
+	send( sock, state->positions, state->particles*sizeof(vector), 0 );
+	send( sock, state->velocities, state->particles*sizeof(vector), 0 );
+}
+
+void
+write_state( int fd, AState state ) {
+	write( fd, &state->particles, sizeof(int) );
+	write( fd, state->masses, state->particles*sizeof(real) );
+	write( fd, state->positions, state->particles*sizeof(vector) );
+	write( fd, state->velocities, state->particles*sizeof(vector) );
+}
Index: /proiecte/SolarSim/C/Parallel/submit.sh
===================================================================
--- /proiecte/SolarSim/C/Parallel/submit.sh	(revision 152)
+++ /proiecte/SolarSim/C/Parallel/submit.sh	(revision 152)
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+wait_qstat() {
+#astept finalizarea executiei
+	while [ `qstat | wc -l` != 0 ]
+	do
+		sleep 1
+	done
+}
+
+#compilez sursele
+for MAKEFILE in `ls makefile*`
+do
+	make -f $MAKEFILE
+done
+
+for SOLARSIM in `ls bin`
+do
+	for THREADS in 1 2 3 4 5 6 7 8
+	do
+		let "SIM_STEPS = 3075840"
+		qsub -q ibm-quad.q -cwd run.sh $THREADS bin/$SOLARSIM data/astro.dat /dev/null $SIM_STEPS 100 0
+	done
+done
+
+wait_qstat
+
+cat $PWD/run.sh.* | \
+	grep -v "Warning: no access to tty (Bad file descriptor)." | \
+	grep -v "Thus no job control in this shell."
+
+rm run.sh.*
+rm bin/*
+
Index: /proiecte/SolarSim/C/Parallel/submit_single.sh
===================================================================
--- /proiecte/SolarSim/C/Parallel/submit_single.sh	(revision 152)
+++ /proiecte/SolarSim/C/Parallel/submit_single.sh	(revision 152)
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+make -f makefile.gcc
+
+qsub -q ibm-quad.q -cwd run.sh 8 bin/SolarSim.gcc data/astro.dat sim.dat 630720 100 864
+
+while [ `qstat | wc -l` != 0 ]
+do
+	sleep 1
+done
+
+cat run.sh.* | \
+	grep -v "Warning: no access to tty (Bad file descriptor)." | \
+	grep -v "Thus no job control in this shell."
+
+rm run.sh.*
+
Index: /proiecte/SolarSim/C/Serial/data/astro.dat
===================================================================
--- /proiecte/SolarSim/C/Serial/data/astro.dat	(revision 152)
+++ /proiecte/SolarSim/C/Serial/data/astro.dat	(revision 152)
@@ -0,0 +1,12 @@
+7
+	0	0	0	0	0	0	1.9891E30
+   0.039718988356852E12   0.030366785604440E12   0.023168117667570E12 -15.819644993401820E03  40.233248676558141E03 -25.613394663449039E03	3.3022E+023
+  -0.098568144514351E12   0.033356749016186E12   0.026905994589281E12 -11.242902837405447E03 -33.415356416769157E03   0.239187799619533E03	4.8685E+024
+  -0.129426625182282E12  -0.070884654059210E12                   0E12  14.502901794973520E03 -26.480507799411470E03                   0E03	5.9736E+024
+   0.208051264177585E12	 -0.001936863781400E12  -0.001936863781400E12   0.258530665135422E03  26.319735594121685E03   0.545055020111751E03	6.4185E+023
+   0.598568406789902E12   0.439603107246420E12  -0.015231294985490E12  -8.089003954667575E03  11.018770541158787E03   0.135481472067609E03	1.8986E+027
+   0.958404810010585E12   0.982839000229841E12  -0.055213235013157E12  -7.175777227784183E03   7.006558089055758E03   0.163350990481469E03	5.6846E+026
+
+   1.599099852341484E12  -2.066691216742713E12   1.212370570567251E12   3.162717831418037E03   4.662650706035524E03   3.776698110992691E03	8.6810E+025
+   3.598260599264261E12   0.006647772527355E12  -2.770476993836326E12   3.184576985353795E03  -1.325068383752312E03   4.132908940950548E03	1.0243E+026
+   6.617128192603119E12   2.257835220151279E12   0.958573939536201E12  -0.322219536847948E03  -0.676751330966366E03   3.818339744970676E03	1.3050E+02
Index: /proiecte/SolarSim/C/Serial/data/astro_peri.dat
===================================================================
--- /proiecte/SolarSim/C/Serial/data/astro_peri.dat	(revision 152)
+++ /proiecte/SolarSim/C/Serial/data/astro_peri.dat	(revision 152)
@@ -0,0 +1,12 @@
+10
+0 0 0 0 0 0 1.9891E30
+46001251767	0	0	0	60264.22	0	3.3022E+023
+107473109276	0	0	0	35260.43	0	4.8685E+024
+147098074037.94	0	0	0	30290.86	0	5.9736E+024
+206668962883.5	0	0	0	26612.76	0	6.4185E+023
+740573560320	0	0	0	13725.56	0	1.8986E+027
+1353572956830.08	0	0	0	10189.79	0	5.6846E+026
+2748938461629.85	0	0	0	7107.82	0	8.6810E+025
+4452940832359.2	0	0	0	5490.11	0	1.0243E+026
+-4436824612684.16	0	0	0	-6310.21		0	1.3050E+022
+
Index: /proiecte/SolarSim/C/Serial/makef.icc
===================================================================
--- /proiecte/SolarSim/C/Serial/makef.icc	(revision 152)
+++ /proiecte/SolarSim/C/Serial/makef.icc	(revision 152)
@@ -0,0 +1,11 @@
+CC=icc
+CFLAGS=-openmp
+SRC=src
+BIN=bin
+OUTFILE=SolarSim.$(CC)
+
+all:
+	$(CC) -o $(BIN)/$(OUTFILE) $(SRC)/*.c $(CFLAGS)
+
+clean:
+	$(RM) $(BIN)/$(OUTFILE)
Index: /proiecte/SolarSim/C/Serial/makefile.gcc
===================================================================
--- /proiecte/SolarSim/C/Serial/makefile.gcc	(revision 152)
+++ /proiecte/SolarSim/C/Serial/makefile.gcc	(revision 152)
@@ -0,0 +1,11 @@
+CC=gcc
+CFLAGS=-fopenmp -lm
+SRC=src
+BIN=bin
+OUTFILE=SolarSim.$(CC)
+
+all:
+	$(CC) -o $(BIN)/$(OUTFILE) $(SRC)/*.c $(CFLAGS)
+
+clean:
+	$(RM) $(BIN)/$(OUTFILE)
Index: /proiecte/SolarSim/C/Serial/run.sh
===================================================================
--- /proiecte/SolarSim/C/Serial/run.sh	(revision 152)
+++ /proiecte/SolarSim/C/Serial/run.sh	(revision 152)
@@ -0,0 +1,1 @@
+time $*
Index: /proiecte/SolarSim/C/Serial/src/SolarSim.c
===================================================================
--- /proiecte/SolarSim/C/Serial/src/SolarSim.c	(revision 152)
+++ /proiecte/SolarSim/C/Serial/src/SolarSim.c	(revision 152)
@@ -0,0 +1,75 @@
+/* SolarSim.c */
+#include "SolarSim.h"
+
+int sock = 0;
+
+long SIM_STEPS, DT, SAVE;
+
+void
+do_work(AState state) {
+	int i, j;
+	long sim_step;
+	real norm_square, norm;
+	int n = state->particles;
+	vector *r = state->positions;
+	vector *v = state->velocities;
+	vector *a = state->accelerations;
+	real *m = state->masses;
+
+	sim_step = 0;
+	while( sim_step < SIM_STEPS ) {
+		if( (SAVE != 0) && (sim_step % SAVE == 0) ) {
+			write_state(sock, state);
+		}
+
+		// compute accelerations
+		memset( a, 0, n * sizeof(vector) );
+		for( i = 0; i < n-1; i++ ) {
+			for( j = i+1; j < n; j++ ) {
+				compute_acc(r+i, r+j, v+i, v+j, a+i, a+j, m[i], m[j]);
+			}
+		}
+
+		// update positions and speeds
+		for( i = 0; i < n; i++ ) {
+			update_pos_vel(r+i, v+i, a+i, DT);
+		}
+
+		sim_step ++;
+	}
+
+	if( SAVE != 0 )
+		write_state(sock, state);
+}
+
+int
+main( int argc, char **argv ) {
+	TState state;
+	double before, after;
+	int i;
+
+	SIM_STEPS = atol(argv[3]);
+	DT = atol(argv[4]);
+	SAVE = atol(argv[5]);
+
+	if( SAVE != 0 ) {
+		sock = open( argv[2], O_WRONLY | O_CREAT | O_TRUNC, 644 );
+	}
+
+	read_initial( &state, argv[1] );
+
+	before = omp_get_wtime();
+	do_work(&state);
+	after = omp_get_wtime();
+
+	if( SAVE != 0 ) {
+		i = 0;
+		write( sock, &i, sizeof(int) );
+		close(sock);
+	}
+
+	printf("%li s %lf\n", SIM_STEPS, after-before);
+
+	return EXIT_SUCCESS;
+}
+
Index: /proiecte/SolarSim/C/Serial/src/SolarSim.h
===================================================================
--- /proiecte/SolarSim/C/Serial/src/SolarSim.h	(revision 152)
+++ /proiecte/SolarSim/C/Serial/src/SolarSim.h	(revision 152)
@@ -0,0 +1,58 @@
+/* SolarSim.h */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <fcntl.h>
+#include <omp.h>
+
+#if __INTEL_COMPILER
+#include <pmmintrin.h>
+#endif
+
+#define _SINGLE_PRECISION_
+//#define _DOUBLE_PRECISION_
+
+#if defined _DOUBLE_PRECISION_
+typedef double real;
+#elif defined _SINGLE_PRECISION_
+typedef float real;
+#else
+	#error "Must have either _DOUBLE_PRECISION_ or _SINGLE_PRECISION_ defined."
+#endif
+
+/* simulation constants */
+//#define SIM_STEPS (24*365*25)	// 250 years
+#define G	6.6743E-11	// m^3 kg^-1 s^-2
+//#define DT	3600		// one hour
+//#define SAVE	(24)		// 1 day
+
+typedef struct vector {
+	real x, y, z;
+	real unused;
+} vector;
+
+typedef struct state {
+	int particles;
+	vector * positions;
+	vector * velocities;
+	vector * accelerations;
+	real * masses;
+} TState, *AState;
+
+/* declared in "io.c" */
+void read_initial( AState state, const char *filename );
+
+int connect_to_server( char * servername, int portno, int protocol );
+
+void send_state( int sock, AState state );
+
+void write_state( int fd, AState state );
+
+/* declared in "compute.c" */
+inline void compute_acc( vector *rv1, vector *rv2, vector *vv1, vector *vv2, vector *av1, vector *av2, real m1, real m2 );
+
+inline void update_pos_vel( vector *rv, vector *vv, vector *av, long DT );
+
+inline void v_init( vector *v, real x, real y, real z );
+
Index: /proiecte/SolarSim/C/Serial/src/compute.c
===================================================================
--- /proiecte/SolarSim/C/Serial/src/compute.c	(revision 152)
+++ /proiecte/SolarSim/C/Serial/src/compute.c	(revision 152)
@@ -0,0 +1,204 @@
+/* compute.c */
+#include "SolarSim.h"
+
+inline void
+v_init( vector *v, real x, real y, real z ) {
+	v->x = x;
+	v->y = y;
+	v->z = z;	
+}
+
+#if __INTEL_COMPILER
+#if defined _DOUBLE_PRECISION_
+/* double precision using SSE instructions */
+inline void
+compute_acc( vector *rv1, vector *rv2, vector *vv1, vector *vv2, vector *av1, vector *av2, real m1, real m2 ) {
+	__m128d r11, r12, r21, r22, d1, d2, t1, t2, a11, a12, a21, a22;
+	double tmp;
+
+	// load position vectors into SSE registers
+	r11 = _mm_loadu_pd((double*)rv1);	// (x1, y1)
+	r12 = _mm_load1_pd((double*)rv1+2);	// (z1, z1)
+	r21 = _mm_loadu_pd((double*)rv2);	// (x2, y2)
+	r22 = _mm_load1_pd((double*)rv2+2);	// (z2, z2)
+
+	// load acceleration vectors
+	a11 = _mm_loadu_pd((double*)av1);
+	a12 = _mm_load1_pd((double*)av1+2);
+	a21 = _mm_loadu_pd((double*)av2);
+	a22 = _mm_load1_pd((double*)av2+2);
+	// d = r2 - r1
+	d1= _mm_sub_pd(r21, r11);	// (dx dy)
+	d2= _mm_sub_pd(r22, r12);	// (dz dz)
+
+	t1 = _mm_mul_pd(d1, d1);	// (dx^2, dy^2)
+	t2 = _mm_mul_pd(d2, d2);	// (dz^2, dz^2)
+	t1 = _mm_hadd_pd(t1, t1);	// (dx^2+dy^2, dx^2+dy^2)
+	t1 = _mm_add_pd(t1, t2);	// (dx^2+dy^2+dz^2, dx^2+dy^2+dz^2)
+
+	t2 = _mm_sqrt_pd(t1);		// t2 = (norm(d), norm(d))
+	d1 = _mm_div_pd(d1, t1);	// d = d * (norm(d) ^(-3))
+	d1 = _mm_div_pd(d1, t2);	// d = d * (norm(d) ^(-3))
+	d2 = _mm_div_pd(d2, t1);	// d = d * (norm(d) ^(-3))
+	d2 = _mm_div_pd(d2, t2);	// d = d * (norm(d) ^(-3))
+
+	tmp = G * m2;
+	t1 = _mm_load1_pd(&tmp);
+	t2 = _mm_mul_pd(t1, d1);
+	a11 = _mm_add_pd(a11, t2);
+	t2 = _mm_mul_pd(t1, d2);
+	a12 = _mm_add_pd(a12, t2);
+
+	tmp = - G * m1;
+	t1 = _mm_load1_pd(&tmp);
+	t2 = _mm_mul_pd(t1, d1);
+	a21 = _mm_add_pd(a21, t2);
+	t2 = _mm_mul_pd(t1, d2);
+	a22 = _mm_add_pd(a22, t2);
+
+	_mm_storeu_pd((double*)av1, a11);
+	_mm_store_sd((double*)av1+2, a12);
+	_mm_storeu_pd((double*)av2, a21);
+	_mm_store_sd((double*)av2+2, a22);
+}
+
+inline void
+update_pos_vel( vector *rv, vector *vv, vector *av, long DT ) {
+	__m128d r1, r2, v1, v2, a1, a2, t1, t2;
+	double tmp;
+
+	r1 = _mm_loadu_pd((double*)rv);	
+	r2 = _mm_load1_pd((double*)rv+2);	
+	v1 = _mm_loadu_pd((double*)vv);	
+	v2 = _mm_load1_pd((double*)vv+2);	
+	a1 = _mm_loadu_pd((double*)av);	
+	a2 = _mm_load1_pd((double*)av+2);	
+
+	tmp = DT;
+	t1 = _mm_load1_pd(&tmp);	// t1 = (DT,DT)
+
+	t2 = _mm_mul_pd(v1, t1);	// t2 = (vx*DT,vy*DT)
+	r1 = _mm_add_pd(r1, t2);	// r1 = (rx+vx*DT, ry+vy*DT)
+	t2 = _mm_mul_pd(v2, t1);	// t2 = (vz*DT,vz*DT)
+	r2 = _mm_add_pd(r2, t2);	// r2 = (rz+vz*DT, rz+vz*DT)
+
+	t2 = _mm_mul_pd(a1, t1);	// t2 = (ax*DT, ay*DT)
+	v1 = _mm_add_pd(v1, t2);	// v1 = (vx+ax*DT, vy+ay*DT)
+	t2 = _mm_mul_pd(a2, t1);	// t2 = (az*DT, az*DT)
+	v2 = _mm_add_pd(v2, t2);	// v1 = (vz+az*DT, vz+az*DT)
+
+	tmp = DT*DT/2;
+	t1 = _mm_load1_pd(&tmp);	// t1 = (DT*DT/2, DT*DT/2)
+
+	t2 = _mm_mul_pd(a1, t1);	// t2 = (ax*DT*DT/2,ay*DT*DT/2)
+	r1 = _mm_add_pd(r1, t2);	// r1 = (rx+vx*DT+ax*DT*DT/2, ry+vy*DT+ay*DT*DT/2)
+	t2 = _mm_mul_pd(a2, t1);	// t2 = (az*DT*DT/2,az*DT*DT/2)
+	r2 = _mm_add_pd(r2, t2);	// r2 = (rz+vz*DT+az*DT*DT/2, rz+vz*DT+az*DT*DT/2)
+
+	_mm_storeu_pd((double*)rv, r1);
+	_mm_store_sd((double*)rv+2, r2);
+	_mm_storeu_pd((double*)vv, v1);
+	_mm_store_sd((double*)vv+2, v2);
+}
+
+#elif defined _SINGLE_PRECISION_
+/* single precision using SSE instructions */
+inline void
+compute_acc( vector *rv1, vector *rv2, vector *vv1, vector *vv2, vector *av1, vector *av2, real m1, real m2 ) {
+	__m128 r1, r2, d, t1, t2, a1, a2;
+	float tmp;
+
+	// load position and acceleration vectors into SSE registers
+	r1 = _mm_loadu_ps((float*)rv1);	
+	r2 = _mm_loadu_ps((float*)rv2);
+	a1 = _mm_loadu_ps((float*)av1);
+	a2 = _mm_loadu_ps((float*)av2);
+
+	d = _mm_sub_ps(r2, r1);	// d = r2 - r1
+	t1 = _mm_mul_ps(d, d);
+	t1 = _mm_hadd_ps(t1, t1);
+	t1 = _mm_hadd_ps(t1, t1);	// t1 = norm(d) ^ 2
+	t2 = _mm_rcp_ps(t1);	// t2 = norm(d) ^ (-2)
+	t1 = _mm_rsqrt_ps(t1);	// t1 = norm(d) ^ (-1)
+	d = _mm_mul_ps(d, t1);	// d = d * (norm(d) ^(-1))
+	d = _mm_mul_ps(d, t2);	// d = d * (norm(d) ^(-3))
+
+	tmp = G * m2;
+	t1 = _mm_load1_ps(&tmp);
+	t1 = _mm_mul_ps(t1, d);
+	a1 = _mm_add_ps(a1, t1);
+
+	tmp = - G * m1;
+	t2 = _mm_load1_ps(&tmp);
+	t2 = _mm_mul_ps(t2, d);
+	a2 = _mm_add_ps(a2, t2);
+
+	_mm_storeu_ps((float*)av1, a1);
+	_mm_storeu_ps((float*)av2, a2);
+}
+
+inline void
+update_pos_vel( vector *rv, vector *vv, vector *av, long DT ) {
+	__m128 r, v, a, t1, t2;
+	float tmp;
+
+	r = _mm_loadu_ps((float*)rv);	
+	v = _mm_loadu_ps((float*)vv);
+	a = _mm_loadu_ps((float*)av);
+
+	tmp = DT;
+	t1 = _mm_load1_ps(&tmp);	// t1 = (DT,DT,DT)
+	t2 = _mm_mul_ps(v, t1);		// t2 = v*DT
+	r = _mm_add_ps(r, t2);		// r = r + v*DT
+
+	t2 = _mm_mul_ps(a, t1);		// t2 = a*DT
+	v = _mm_add_ps(v, t2);		// v = v + a*DT
+
+	tmp = DT*DT/2;
+	t1 = _mm_load1_ps(&tmp);
+	t2 = _mm_mul_ps(a, t1);		// t2 = a * (DT*DT/2)
+	r = _mm_add_ps(r, t2);		// r = r + v*DT + a*(DT*DT/2)
+
+	_mm_storeu_ps((float*)rv, r);
+	_mm_storeu_ps((float*)vv, v);
+}
+#else
+	#error "Either _SINGLE_PRECISION_ or _DOUBLE_PRECISION_ must be defined"
+#endif
+
+#else
+/* Compatibility mode without SSE instructions */
+inline void
+compute_acc( vector *rv1, vector *rv2, vector *vv1, vector *vv2, vector *av1, vector *av2, real m1, real m2 ) {
+	// varianta fara SSE
+	vector d;
+	real w, norm3;
+
+	d.x = rv2->x - rv1->x;
+	d.y = rv2->y - rv1->y;
+	d.z = rv2->z - rv1->z;
+
+	w = d.x*d.x + d.y*d.y + d.z*d.z;	// norm^2
+	norm3 = w * sqrt(w);			// norm^3
+
+	av1->x += G * m2 * d.x / norm3;
+	av1->y += G * m2 * d.y / norm3;
+	av1->z += G * m2 * d.z / norm3;
+
+	av2->x -= G * m1 * d.x / norm3;
+	av2->y -= G * m1 * d.y / norm3;
+	av2->z -= G * m1 * d.z / norm3;
+}
+
+inline void
+update_pos_vel( vector *rv, vector *vv, vector *av, long DT ) {
+	rv->x = rv->x + vv->x * DT + av->x * (DT*DT)/2;
+	rv->y = rv->y + vv->y * DT + av->y * (DT*DT)/2;
+	rv->z = rv->z + vv->z * DT + av->z * (DT*DT)/2;
+
+	vv->x = vv->x + av->x * DT;
+	vv->y = vv->y + av->y * DT;
+	vv->z = vv->z + av->z * DT;
+}
+#endif
+
Index: /proiecte/SolarSim/C/Serial/src/io.c
===================================================================
--- /proiecte/SolarSim/C/Serial/src/io.c	(revision 152)
+++ /proiecte/SolarSim/C/Serial/src/io.c	(revision 152)
@@ -0,0 +1,124 @@
+/* io.c */
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+
+#include "SolarSim.h"
+
+void
+read_initial( AState state, const char *filename ) {
+	int i;
+	double rx, ry, rz, vx, vy, vz, mass;
+
+	FILE *f = fopen(filename, "rt");
+	if( !f ) {
+		state->particles = 0;
+		return;
+	}
+
+	fscanf( f, "%d\n", &state->particles );
+	state->masses = malloc( state->particles * sizeof(real) );
+	state->positions = malloc( state->particles * sizeof(vector) );
+	state->velocities = malloc( state->particles * sizeof(vector) );
+	state->accelerations = malloc( state->particles * sizeof(vector) );
+	
+	for( i = 0; i < state->particles; i++ ) {
+		fscanf( f, "%lf %lf %lf %lf %lf %lf %lf\n", &rx, &ry, &rz, &vx, &vy, &vz, &mass );
+		state->masses[i] = mass;
+		v_init(&state->positions[i],(real)rx,(real)ry,(real)rz);
+		v_init(&state->velocities[i],(real)vx,(real)vy,(real)vz);
+	}
+
+	fclose(f);
+}
+
+int
+connect_to_server( char *servername, int portno, int PROTOCOL ){
+	return connect_to_server_tcp(servername, portno);
+}
+
+int
+connect_to_server_tcp( char* servername, int portno ){
+	struct sockaddr_in serv_addr;
+	struct hostent *server;
+	int server_sockfd;
+
+	server_sockfd = socket( AF_INET, SOCK_STREAM, 0 );
+	if ( server_sockfd < 0 ) {
+        	printf ( "ERROR opening socket" );
+		return -1;
+	}
+    
+	server = gethostbyname( servername );
+	if (server == NULL) {
+        	fprintf( stderr, "ERROR, no such host\n" );
+		return -1;
+	}
+    
+	memset( (char *) &serv_addr, 0, sizeof(serv_addr) );
+	serv_addr.sin_family = AF_INET;
+	memcpy( (char *)&serv_addr.sin_addr.s_addr, (char *)server->h_addr, server->h_length );
+	serv_addr.sin_port = htons( portno );
+    
+	if ( connect( server_sockfd, (struct sockaddr*) &serv_addr, sizeof( serv_addr ) ) < 0 ) {
+        	printf( "ERROR connecting" );
+		return -1;
+	}
+
+	return server_sockfd;
+}
+
+
+int
+connect_to_server_udp( char* servername, int portno ){
+	struct sockaddr_in serv_addr, cli_addr;
+	struct hostent *server;
+	int server_sockfd, n;
+
+	server_sockfd = socket( AF_INET, SOCK_DGRAM, 0 );
+	if ( server_sockfd < 0 ) {
+        	printf ( "ERROR opening socket" );
+		return -1;
+	}
+    
+	server = gethostbyname( servername );
+	if (server == NULL) {
+        	fprintf( stderr, "ERROR, no such host\n" );
+		return -1;
+	}
+    
+	memset( (char *) &serv_addr, 0, sizeof(serv_addr) );
+	serv_addr.sin_family = AF_INET;
+	memcpy( (char *)&serv_addr.sin_addr.s_addr, (char *)server->h_addr, server->h_length );
+	serv_addr.sin_port = htons( portno );
+
+	memset( (char *) &cli_addr, 0, sizeof(cli_addr) );
+	cli_addr.sin_family = AF_INET;
+	cli_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+	cli_addr.sin_port = htons(0);
+
+	n = bind(server_sockfd, (struct sockaddr *) &cli_addr, sizeof(cli_addr));
+   	if( n < 0 ) {
+		fprintf(stderr, "%d: cannot bind port\n", portno);
+      		return -1;
+	}
+
+	return server_sockfd;
+}
+
+void
+send_state( int sock, AState state ) {
+	send( sock, &state->particles, sizeof(int), 0 );
+	send( sock, state->masses, state->particles*sizeof(real), 0 );
+	send( sock, state->positions, state->particles*sizeof(vector), 0 );
+	send( sock, state->velocities, state->particles*sizeof(vector), 0 );
+}
+
+void
+write_state( int fd, AState state ) {
+	write( fd, &state->particles, sizeof(int) );
+	write( fd, state->masses, state->particles*sizeof(real) );
+	write( fd, state->positions, state->particles*sizeof(vector) );
+	write( fd, state->velocities, state->particles*sizeof(vector) );
+}
Index: /proiecte/SolarSim/C/Serial/src/time.h
===================================================================
--- /proiecte/SolarSim/C/Serial/src/time.h	(revision 152)
+++ /proiecte/SolarSim/C/Serial/src/time.h	(revision 152)
@@ -0,0 +1,420 @@
+/* Copyright (C) 1991-1999,2000,2001,2002,2003,2006
+	Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+/*
+ *	ISO C99 Standard: 7.23 Date and time	<time.h>
+ */
+
+#ifndef	_TIME_H
+
+#if (! defined __need_time_t && !defined __need_clock_t && \
+     ! defined __need_timespec)
+# define _TIME_H	1
+# include <features.h>
+
+__BEGIN_DECLS
+
+#endif
+
+#ifdef	_TIME_H
+/* Get size_t and NULL from <stddef.h>.  */
+# define __need_size_t
+# define __need_NULL
+# include <stddef.h>
+
+/* This defines CLOCKS_PER_SEC, which is the number of processor clock
+   ticks per second.  */
+# include <bits/time.h>
+
+/* This is the obsolete POSIX.1-1988 name for the same constant.  */
+# if !defined __STRICT_ANSI__ && !defined __USE_XOPEN2K
+#  ifndef CLK_TCK
+#   define CLK_TCK	CLOCKS_PER_SEC
+#  endif
+# endif
+
+#endif /* <time.h> included.  */
+
+#if !defined __clock_t_defined && (defined _TIME_H || defined __need_clock_t)
+# define __clock_t_defined	1
+
+# include <bits/types.h>
+
+__BEGIN_NAMESPACE_STD
+/* Returned by `clock'.  */
+typedef __clock_t clock_t;
+__END_NAMESPACE_STD
+#if defined __USE_XOPEN || defined __USE_POSIX || defined __USE_MISC
+__USING_NAMESPACE_STD(clock_t)
+#endif
+
+#endif /* clock_t not defined and <time.h> or need clock_t.  */
+#undef	__need_clock_t
+
+#if !defined __time_t_defined && (defined _TIME_H || defined __need_time_t)
+# define __time_t_defined	1
+
+# include <bits/types.h>
+
+__BEGIN_NAMESPACE_STD
+/* Returned by `time'.  */
+typedef __time_t time_t;
+__END_NAMESPACE_STD
+#if defined __USE_POSIX || defined __USE_MISC || defined __USE_SVID
+__USING_NAMESPACE_STD(time_t)
+#endif
+
+#endif /* time_t not defined and <time.h> or need time_t.  */
+#undef	__need_time_t
+
+#if !defined __clockid_t_defined && \
+   ((defined _TIME_H && defined __USE_POSIX199309) || defined __need_clockid_t)
+# define __clockid_t_defined	1
+
+# include <bits/types.h>
+
+/* Clock ID used in clock and timer functions.  */
+typedef __clockid_t clockid_t;
+
+#endif /* clockid_t not defined and <time.h> or need clockid_t.  */
+#undef	__clockid_time_t
+
+#if !defined __timer_t_defined && \
+    ((defined _TIME_H && defined __USE_POSIX199309) || defined __need_timer_t)
+# define __timer_t_defined	1
+
+# include <bits/types.h>
+
+/* Timer ID returned by `timer_create'.  */
+typedef __timer_t timer_t;
+
+#endif /* timer_t not defined and <time.h> or need timer_t.  */
+#undef	__need_timer_t
+
+
+#if !defined __timespec_defined &&				\
+    ((defined _TIME_H &&					\
+      (defined __USE_POSIX199309 || defined __USE_MISC)) ||	\
+      defined __need_timespec)
+# define __timespec_defined	1
+
+# include <bits/types.h>	/* This defines __time_t for us.  */
+
+/* POSIX.1b structure for a time value.  This is like a `struct timeval' but
+   has nanoseconds instead of microseconds.  */
+struct timespec
+  {
+    __time_t tv_sec;		/* Seconds.  */
+    long int tv_nsec;		/* Nanoseconds.  */
+  };
+
+#endif /* timespec not defined and <time.h> or need timespec.  */
+#undef	__need_timespec
+
+
+#ifdef	_TIME_H
+__BEGIN_NAMESPACE_STD
+/* Used by other time functions.  */
+struct tm
+{
+  int tm_sec;			/* Seconds.	[0-60] (1 leap second) */
+  int tm_min;			/* Minutes.	[0-59] */
+  int tm_hour;			/* Hours.	[0-23] */
+  int tm_mday;			/* Day.		[1-31] */
+  int tm_mon;			/* Month.	[0-11] */
+  int tm_year;			/* Year	- 1900.  */
+  int tm_wday;			/* Day of week.	[0-6] */
+  int tm_yday;			/* Days in year.[0-365]	*/
+  int tm_isdst;			/* DST.		[-1/0/1]*/
+
+#ifdef	__USE_BSD
+  long int tm_gmtoff;		/* Seconds east of UTC.  */
+  __const char *tm_zone;	/* Timezone abbreviation.  */
+#else
+  long int __tm_gmtoff;		/* Seconds east of UTC.  */
+  __const char *__tm_zone;	/* Timezone abbreviation.  */
+#endif
+};
+__END_NAMESPACE_STD
+#if defined __USE_XOPEN || defined __USE_POSIX || defined __USE_MISC
+__USING_NAMESPACE_STD(tm)
+#endif
+
+
+#ifdef __USE_POSIX199309
+/* POSIX.1b structure for timer start values and intervals.  */
+struct itimerspec
+  {
+    struct timespec it_interval;
+    struct timespec it_value;
+  };
+
+/* We can use a simple forward declaration.  */
+struct sigevent;
+
+#endif	/* POSIX.1b */
+
+#ifdef __USE_XOPEN2K
+# ifndef __pid_t_defined
+typedef __pid_t pid_t;
+#  define __pid_t_defined
+# endif
+#endif
+
+
+__BEGIN_NAMESPACE_STD
+/* Time used by the program so far (user time + system time).
+   The result / CLOCKS_PER_SECOND is program time in seconds.  */
+extern clock_t clock (void) __THROW;
+
+/* Return the current time and put it in *TIMER if TIMER is not NULL.  */
+extern time_t time (time_t *__timer) __THROW;
+
+/* Return the difference between TIME1 and TIME0.  */
+extern double difftime (time_t __time1, time_t __time0)
+     __THROW __attribute__ ((__const__));
+
+/* Return the `time_t' representation of TP and normalize TP.  */
+extern time_t mktime (struct tm *__tp) __THROW;
+
+
+/* Format TP into S according to FORMAT.
+   Write no more than MAXSIZE characters and return the number
+   of characters written, or 0 if it would exceed MAXSIZE.  */
+extern size_t strftime (char *__restrict __s, size_t __maxsize,
+			__const char *__restrict __format,
+			__const struct tm *__restrict __tp) __THROW;
+__END_NAMESPACE_STD
+
+# ifdef __USE_XOPEN
+/* Parse S according to FORMAT and store binary time information in TP.
+   The return value is a pointer to the first unparsed character in S.  */
+extern char *strptime (__const char *__restrict __s,
+		       __const char *__restrict __fmt, struct tm *__tp)
+     __THROW;
+# endif
+
+# ifdef __USE_GNU
+/* Similar to the two functions above but take the information from
+   the provided locale and not the global locale.  */
+# include <xlocale.h>
+
+extern size_t strftime_l (char *__restrict __s, size_t __maxsize,
+			  __const char *__restrict __format,
+			  __const struct tm *__restrict __tp,
+			  __locale_t __loc) __THROW;
+
+extern char *strptime_l (__const char *__restrict __s,
+			 __const char *__restrict __fmt, struct tm *__tp,
+			 __locale_t __loc) __THROW;
+# endif
+
+
+__BEGIN_NAMESPACE_STD
+/* Return the `struct tm' representation of *TIMER
+   in Universal Coordinated Time (aka Greenwich Mean Time).  */
+extern struct tm *gmtime (__const time_t *__timer) __THROW;
+
+/* Return the `struct tm' representation
+   of *TIMER in the local timezone.  */
+extern struct tm *localtime (__const time_t *__timer) __THROW;
+__END_NAMESPACE_STD
+
+# if defined __USE_POSIX || defined __USE_MISC
+/* Return the `struct tm' representation of *TIMER in UTC,
+   using *TP to store the result.  */
+extern struct tm *gmtime_r (__const time_t *__restrict __timer,
+			    struct tm *__restrict __tp) __THROW;
+
+/* Return the `struct tm' representation of *TIMER in local time,
+   using *TP to store the result.  */
+extern struct tm *localtime_r (__const time_t *__restrict __timer,
+			       struct tm *__restrict __tp) __THROW;
+# endif	/* POSIX or misc */
+
+__BEGIN_NAMESPACE_STD
+/* Return a string of the form "Day Mon dd hh:mm:ss yyyy\n"
+   that is the representation of TP in this format.  */
+extern char *asctime (__const struct tm *__tp) __THROW;
+
+/* Equivalent to `asctime (localtime (timer))'.  */
+extern char *ctime (__const time_t *__timer) __THROW;
+__END_NAMESPACE_STD
+
+# if defined __USE_POSIX || defined __USE_MISC
+/* Reentrant versions of the above functions.  */
+
+/* Return in BUF a string of the form "Day Mon dd hh:mm:ss yyyy\n"
+   that is the representation of TP in this format.  */
+extern char *asctime_r (__const struct tm *__restrict __tp,
+			char *__restrict __buf) __THROW;
+
+/* Equivalent to `asctime_r (localtime_r (timer, *TMP*), buf)'.  */
+extern char *ctime_r (__const time_t *__restrict __timer,
+		      char *__restrict __buf) __THROW;
+# endif	/* POSIX or misc */
+
+
+/* Defined in localtime.c.  */
+extern char *__tzname[2];	/* Current timezone names.  */
+extern int __daylight;		/* If daylight-saving time is ever in use.  */
+extern long int __timezone;	/* Seconds west of UTC.  */
+
+
+# ifdef	__USE_POSIX
+/* Same as above.  */
+extern char *tzname[2];
+
+/* Set time conversion information from the TZ environment variable.
+   If TZ is not defined, a locale-dependent default is used.  */
+extern void tzset (void) __THROW;
+# endif
+
+# if defined __USE_SVID || defined __USE_XOPEN
+extern int daylight;
+extern long int timezone;
+# endif
+
+# ifdef __USE_SVID
+/* Set the system time to *WHEN.
+   This call is restricted to the superuser.  */
+extern int stime (__const time_t *__when) __THROW;
+# endif
+
+
+/* Nonzero if YEAR is a leap year (every 4 years,
+   except every 100th isn't, and every 400th is).  */
+# define __isleap(year)	\
+  ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
+
+
+# ifdef __USE_MISC
+/* Miscellaneous functions many Unices inherited from the public domain
+   localtime package.  These are included only for compatibility.  */
+
+/* Like `mktime', but for TP represents Universal Time, not local time.  */
+extern time_t timegm (struct tm *__tp) __THROW;
+
+/* Another name for `mktime'.  */
+extern time_t timelocal (struct tm *__tp) __THROW;
+
+/* Return the number of days in YEAR.  */
+extern int dysize (int __year) __THROW  __attribute__ ((__const__));
+# endif
+
+
+# ifdef __USE_POSIX199309
+/* Pause execution for a number of nanoseconds.
+
+   This function is a cancellation point and therefore not marked with
+   __THROW.  */
+extern int nanosleep (__const struct timespec *__requested_time,
+		      struct timespec *__remaining);
+
+
+/* Get resolution of clock CLOCK_ID.  */
+extern int clock_getres (clockid_t __clock_id, struct timespec *__res) __THROW;
+
+/* Get current value of clock CLOCK_ID and store it in TP.  */
+extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) __THROW;
+
+/* Set clock CLOCK_ID to value TP.  */
+extern int clock_settime (clockid_t __clock_id, __const struct timespec *__tp)
+     __THROW;
+
+#  ifdef __USE_XOPEN2K
+/* High-resolution sleep with the specified clock.
+
+   This function is a cancellation point and therefore not marked with
+   __THROW.  */
+extern int clock_nanosleep (clockid_t __clock_id, int __flags,
+			    __const struct timespec *__req,
+			    struct timespec *__rem);
+
+/* Return clock ID for CPU-time clock.  */
+extern int clock_getcpuclockid (pid_t __pid, clockid_t *__clock_id) __THROW;
+#  endif
+
+
+/* Create new per-process timer using CLOCK_ID.  */
+extern int timer_create (clockid_t __clock_id,
+			 struct sigevent *__restrict __evp,
+			 timer_t *__restrict __timerid) __THROW;
+
+/* Delete timer TIMERID.  */
+extern int timer_delete (timer_t __timerid) __THROW;
+
+/* Set timer TIMERID to VALUE, returning old value in OVLAUE.  */
+extern int timer_settime (timer_t __timerid, int __flags,
+			  __const struct itimerspec *__restrict __value,
+			  struct itimerspec *__restrict __ovalue) __THROW;
+
+/* Get current value of timer TIMERID and store it in VLAUE.  */
+extern int timer_gettime (timer_t __timerid, struct itimerspec *__value)
+     __THROW;
+
+/* Get expiration overrun for timer TIMERID.  */
+extern int timer_getoverrun (timer_t __timerid) __THROW;
+# endif
+
+
+# ifdef __USE_XOPEN_EXTENDED
+/* Set to one of the following values to indicate an error.
+     1  the DATEMSK environment variable is null or undefined,
+     2  the template file cannot be opened for reading,
+     3  failed to get file status information,
+     4  the template file is not a regular file,
+     5  an error is encountered while reading the template file,
+     6  memory allication failed (not enough memory available),
+     7  there is no line in the template that matches the input,
+     8  invalid input specification Example: February 31 or a time is
+        specified that can not be represented in a time_t (representing
+	the time in seconds since 00:00:00 UTC, January 1, 1970) */
+extern int getdate_err;
+
+/* Parse the given string as a date specification and return a value
+   representing the value.  The templates from the file identified by
+   the environment variable DATEMSK are used.  In case of an error
+   `getdate_err' is set.
+
+   This function is a possible cancellation points and therefore not
+   marked with __THROW.  */
+extern struct tm *getdate (__const char *__string);
+# endif
+
+# ifdef __USE_GNU
+/* Since `getdate' is not reentrant because of the use of `getdate_err'
+   and the static buffer to return the result in, we provide a thread-safe
+   variant.  The functionality is the same.  The result is returned in
+   the buffer pointed to by RESBUFP and in case of an error the return
+   value is != 0 with the same values as given above for `getdate_err'.
+
+   This function is not part of POSIX and therefore no official
+   cancellation point.  But due to similarity with an POSIX interface
+   or due to the implementation it is a cancellation point and
+   therefore not marked with __THROW.  */
+extern int getdate_r (__const char *__restrict __string,
+		      struct tm *__restrict __resbufp);
+# endif
+
+__END_DECLS
+
+#endif /* <time.h> included.  */
+
+#endif /* <time.h> not already included.  */
Index: /proiecte/SolarSim/C/Serial/submit.sh
===================================================================
--- /proiecte/SolarSim/C/Serial/submit.sh	(revision 152)
+++ /proiecte/SolarSim/C/Serial/submit.sh	(revision 152)
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+wait_qstat() {
+#astept finalizarea executiei
+	while [ `qstat | wc -l` != 0 ]
+	do
+		sleep 1
+	done
+}
+
+#compilez sursele
+for MAKEFILE in `ls makefile*`
+do
+	make -f $MAKEFILE
+done
+
+for SOLARSIM in `ls bin`
+do
+	for YEARS in 10 # 2 3 # 4 5 6 7 8 9 10
+	do
+		let "SIM_STEPS = $YEARS * 307584"
+		qsub -q ibm-quad.q -cwd run.sh bin/$SOLARSIM data/astro.dat /dev/null $SIM_STEPS 100 0
+		#time bin/$SOLARSIM data/astro.dat /dev/null $SIM_STEPS 100 0
+	done
+done
+
+wait_qstat
+
+cat $PWD/run.sh.* | \
+	grep -v "Warning: no access to tty (Bad file descriptor)." | \
+	grep -v "Thus no job control in this shell."
+
+rm run.sh.*
+rm bin/*
+
Index: /proiecte/SolarSim/Java/SolarSim/src/solarsim/common/Particle.java
===================================================================
--- /proiecte/SolarSim/Java/SolarSim/src/solarsim/common/Particle.java	(revision 152)
+++ /proiecte/SolarSim/Java/SolarSim/src/solarsim/common/Particle.java	(revision 152)
@@ -0,0 +1,45 @@
+package solarsim.common;
+
+/**
+ * Clasa care modeleaza o particula. Este caracterizata de masa, vector pozitie si vector viteza.
+ * @author Marius Ion
+ */
+public class Particle {
+
+    double mass;
+    Vector position;
+    Vector velocity;
+
+    public Particle() {
+    }
+
+    public Particle(double mass, Vector position, Vector velocity) {
+        this.mass = mass;
+        this.position = position;
+        this.velocity = velocity;
+    }
+
+    public double getMass() {
+        return mass;
+    }
+
+    public void setMass(double mass) {
+        this.mass = mass;
+    }
+
+    public Vector getPosition() {
+        return position;
+    }
+
+    public void setPosition(Vector position) {
+        this.position = position;
+    }
+
+    public Vector getVelocity() {
+        return velocity;
+    }
+
+    public void setVelocity(Vector velocity) {
+        this.velocity = velocity;
+    }
+}
Index: /proiecte/SolarSim/Java/SolarSim/src/solarsim/common/State.java
===================================================================
--- /proiecte/SolarSim/Java/SolarSim/src/solarsim/common/State.java	(revision 152)
+++ /proiecte/SolarSim/Java/SolarSim/src/solarsim/common/State.java	(revision 152)
@@ -0,0 +1,118 @@
+package solarsim.common;
+
+import java.io.BufferedReader;
+import solarsim.io.MyInputStreamReader;
+import solarsim.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.*;
+
+/**
+ * Clasa care descrie starea sistemului la un moment dat. Contine o lista de obiecte {@link Particle}
+ * care specifica masele, pozitiile si vitezele elementelor sistemului.
+ * @author Marius Ion
+ */
+public class State {
+
+    private enum FP_Precision {
+        FLOAT, DOUBLE;
+    };
+
+    private List<Particle> particles;
+    private static final FP_Precision precision = FP_Precision.FLOAT;
+
+    private State(){}
+
+    public State(List<Particle> particles) {
+        this.particles = particles;
+    }
+
+    /**
+     * Metoda statica ce permite citirea starii dintr-un buffer. Starea a fost
+     * scrisa in buffer de catre programul C.
+     * @param inputStream   streamul din care se citeste
+     * @return  starea sistemului
+     * @throws IOException cand s-a produs o eroare la citirea din InputStream
+     */
+    public static State readStateFromBuffer(byte[] data, int offset, int length)
+    throws IOException {
+        ByteArrayInputStream ins = new ByteArrayInputStream(data, offset, length);
+        return readStateFromInputStream(ins);
+    }
+
+    /**
+     * Metoda statica ce permite citirea starii dintr-un InputStream. Starea a fost
+     * scrisa in stream de catre programul C.
+     * @param inputStream   streamul din care se citeste
+     * @return  starea sistemului
+     * @throws IOException cand s-a produs o eroare la citirea din InputStream
+     */
+    public static State readStateFromInputStream(InputStream inputStream)
+    throws IOException {
+        State state = new State();
+        MyInputStreamReader in = new MyInputStreamReader(inputStream);
+
+        int n = in.readInt();
+        if( n == 0 )
+            return null;
+        state.particles = new ArrayList<Particle>(n);
+        for( int i = 0; i < n; i++ ) {
+            state.particles.add(new Particle());
+        }
+
+        for( int i = 0; i < n; i++ ) {
+            double mass;
+            if( precision == FP_Precision.DOUBLE )
+                mass = in.readDouble();
+            else
+                mass = (double)in.readFloat();
+            state.particles.get(i).mass = mass;
+        }
+        
+        for( int i = 0; i < n; i++ ) {
+            Vector position;
+            if( precision == FP_Precision.DOUBLE )
+                position = in.readVector();
+            else
+                position = in.readFloatVector();
+            state.particles.get(i).position = position;
+        }
+
+        for( int i = 0; i < n; i++ ) {
+            Vector velocity;
+            if( precision == FP_Precision.DOUBLE )
+                velocity = in.readVector();
+            else
+                velocity = in.readFloatVector();
+            state.particles.get(i).velocity = velocity;
+        }
+
+        return state;
+    }
+
+    /**
+     * Getter pentru particule.
+     * @return lista particulelor din sistem.
+     */
+    public List<Particle> getParticles() {
+        return particles;
+    }
+
+    @Override
+    public String toString() {
+        StringBuffer buf = new StringBuffer();
+
+        for( int i = 0; i < particles.size(); i++ ) {
+            buf.append("Particle " + i + ":\n");
+            buf.append("\tmass:" + particles.get(i).mass + "\n");
+            buf.append("\tposition:" + particles.get(i).position + "\n");
+            buf.append("\tvelocity:" + particles.get(i).velocity + "\n");
+            buf.append("\n");
+        }
+
+        return buf.toString();
+    }
+
+}
Index: /proiecte/SolarSim/Java/SolarSim/src/solarsim/common/Vector.java
===================================================================
--- /proiecte/SolarSim/Java/SolarSim/src/solarsim/common/Vector.java	(revision 152)
+++ /proiecte/SolarSim/Java/SolarSim/src/solarsim/common/Vector.java	(revision 152)
@@ -0,0 +1,24 @@
+package solarsim.common;
+
+/**
+ * Clasa ce modeleaza un vector in trei dimensiuni.
+ * @author Marius Ion
+ */
+public class Vector {
+    public double x;
+    public double y;
+    public double z;
+
+    public Vector(){}
+
+    public Vector(double x, double y, double z) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+    }
+
+    @Override
+    public String toString() {
+        return "(" + x + "," + y + "," + z + ")";
+    }
+}
Index: /proiecte/SolarSim/Java/SolarSim/src/solarsim/gl/GameGLEventListener.java
===================================================================
--- /proiecte/SolarSim/Java/SolarSim/src/solarsim/gl/GameGLEventListener.java	(revision 152)
+++ /proiecte/SolarSim/Java/SolarSim/src/solarsim/gl/GameGLEventListener.java	(revision 152)
@@ -0,0 +1,286 @@
+package solarsim.gl;
+
+import solarsim.common.State;
+import solarsim.*;
+import java.awt.event.*;
+import java.io.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+//import net.java.games.jogl.*; // If thise does not work, try net.java.games.jogl.*, or get the newest version of JOGL.
+import java.lang.Math.*;
+import java.util.LinkedList;
+import javax.media.opengl.*;
+import javax.media.opengl.glu.*;
+import com.sun.opengl.util.texture.*;
+
+public class GameGLEventListener implements GLEventListener,MouseListener, MouseMotionListener, KeyListener {
+        static final int MODE_SCALE = 0;
+        static final int MODE_ROTATE = 1;
+        static final int MODE_NOTHING = -1;
+
+        int press_x, press_y;
+        float msX_angle = 0;
+        float msY_angle = 0;
+        int mouseX, mouseY;
+        int mode ;
+        float scale_size = 1;
+
+        float rotate = 0;
+
+        int MoveX = 0;
+        int MoveY = 0;
+
+        float x1[][]= new float[361][2];
+        float x2[][]= new float[361][2];
+        float x3[][]= new float[721][2];
+
+        float Xvalue = 0;
+        float Yvalue = 0;
+        float Angle = 0;
+
+        private LinkedList<State>   states = new LinkedList<State>();
+        public final int MAX_STATES = 10000;
+        private final double SCALE_FACTOR = 150E9F;   // 150 million km
+        private GLU glu = new GLU();
+
+	// Only put stuff here that should happen once, at the beginning of the program
+	public void init(GLAutoDrawable gld) {
+                //states = new LinkedList<State>();
+                int i = 0;
+
+                for(i=0; i <= 360; i++)
+                {
+                    x1[i][0] = (float)(Math.sin(i*3.1416/180)*3);
+                    x1[i][1] = (float)(Math.cos(i*3.1416/180)*3);
+                }
+
+                for(i=0; i <= 360; i++)
+                {
+                    x2[i][0] = (float)(Math.sin(i*3.1416/180)*1);
+                    x2[i][1] = (float)(Math.cos(i*3.1416/180)*1);
+                }
+
+                for(i=0; i <= 720; i++)
+                {
+                  x3[i][0] = (float)(Math.sin(i*3.1416/180)*5);
+                  x3[i][1] = (float)(Math.cos(i*3.1416/180)*5);
+                }
+                
+		GL gl = gld.getGL();		
+		gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+
+		gl.glViewport(0,0,500,300);
+		gl.glMatrixMode(GL.GL_PROJECTION);
+		gl.glLoadIdentity();
+		glu.gluPerspective(45.0f, 800.0f / 600.0f, 1.0f, 500.0f);
+		gl.glMatrixMode(GL.GL_MODELVIEW);
+	}
+
+        void drawState(State s) {
+           // System.out.println("in draw");
+            //if (states != nu)
+            synchronized( states ) {
+                if( states.size() == MAX_STATES ) {
+                    states.removeLast();
+                }
+                states.addFirst(s);
+            }
+            //this.repaint();
+        }
+	// This function will get called repeatedly by the Animator. Think of it as your game loop.
+	public void display(GLAutoDrawable gld) {
+		GL gl = gld.getGL();
+            //    GLU glu = gld.getGLU();
+	
+
+                if (mode == MODE_ROTATE)
+                {
+                    msX_angle += (mouseX - press_x)/5.0;
+                 //  System.out.println("changed "+msX_angle);
+                     if (msX_angle > 180) msX_angle -= 360;
+                     else if (msX_angle <-180) msX_angle += 360;
+                        press_x = mouseX;
+
+                    msY_angle += (mouseY - press_y)/5.0;
+                    if (msY_angle > 180) msY_angle -= 360;
+                    else if (msY_angle <-180) msY_angle += 360;
+                        press_y = mouseY;
+                }
+                else if (mode == MODE_SCALE){
+                    float old_size = scale_size;
+                    scale_size *= (1+ (mouseY - press_y)/60.0);
+                    if (scale_size <0) scale_size = old_size;
+                        press_y = mouseY;
+                }                              
+                
+                gl.glClear (gl.GL_COLOR_BUFFER_BIT);
+                gl.glColor3f ((float)1.0,(float) 1.0,(float) 1.0);
+                           
+                //rotate scale the entire image
+                gl.glRotatef(msX_angle, 0, 1,0);
+                gl.glRotatef(msY_angle, 1,0,0);
+                gl.glScalef(scale_size, scale_size, scale_size);
+
+                GLUquadric qobj=null ;//= new GLUquadric();
+                glu.gluQuadricDrawStyle(qobj, GLU.GLU_FILL);    
+                //sun
+                gl.glPushMatrix();
+                glu.gluLookAt (0.0, 10.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);           
+                gl.glTranslatef(Xvalue, 0.0f, Yvalue);
+                gl.glRotatef(Angle, 0.0f, 0.0f, 1.0f);                       
+                //glu.gluQuadricNormals(qobj, GLU.GLU_SMOOTH);
+                glu.gluSphere (qobj,0.2f, 15, 15);
+                gl.glPopMatrix();
+
+
+                //earth
+               // System.out.println(states.size());
+              /*  for( State s : states ) {
+                 for( Particle p : s.getParticles() ) {
+                    //System.out.println("aici");
+                    p = s.getParticles().get(0);
+                    Vector r = p.getPosition();
+                    int dx = +(int)(r.x/SCALE_FACTOR*300);
+                    int dy = -(int)(r.y/SCALE_FACTOR*300);
+                    gl.glPushMatrix();
+                    glu.gluLookAt (0.0, 10.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
+                    if ( MoveX == 360 )
+                        MoveX = 0;
+                    gl.glTranslatef((float)dx, (float)dy, 0.0f);
+                    gl.glRotatef(Angle, 0.0f, 0.0f, 1.0f);
+                    glu.gluSphere (qobj,0.4f, 10, 10);
+                    //gl.glFfillOval(0, 0, 1, 1);
+                    gl.glTranslatef(-(float)dx, -(float)dy, 0.0f);
+                    gl.glPopMatrix();
+                    //g.translate(dx, dy);
+                    //g.fillOval(0, 0, 1, 1);
+                    //g.translate(-dx, -dy);
+                      gl.glFlush ();
+                }
+                }*/
+
+                gl.glPushMatrix();
+                glu.gluLookAt (0.0, 10.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
+                if ( MoveX == 360 )
+                    MoveX = 0;
+                gl.glTranslatef(x1[MoveX][1], x1[MoveX][0], 0.0f);
+                gl.glRotatef(Angle, 0.0f, 0.0f, 1.0f);
+                glu.gluSphere (qobj,0.3f, 15, 15);
+                gl.glTranslatef(x2[MoveX][0], x2[MoveX][1], 0.0f);
+                glu.gluSphere (qobj ,0.1f, 10, 10);
+                gl.glPopMatrix();
+
+                //saturn
+                gl.glPushMatrix();
+                glu.gluLookAt (0.0, 10.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
+                if( MoveY == 720 )
+                    MoveY = 0;
+                gl.glTranslatef(x3[MoveY/2][1], x3[MoveY/2][0], 0.0f);
+                gl.glRotatef(Angle, 0.0f, 0.0f, 1.0f);
+                glu.gluSphere (qobj ,0.3f, 15, 15);
+                int i = 0;
+                //glBegin(GL_LINE_STRIP);
+                gl.glBegin(gl.GL_QUAD_STRIP);
+                for(i=0; i <= 360; i++)
+                {
+                  gl.glVertex3f((float)(Math.sin(i*3.1416/180)*0.5), (float)(Math.cos(i*3.1416/180)*0.5), 0f );
+                  gl.glVertex3f((float)(Math.sin(i*3.1416/180)*0.7), (float)(Math.cos(i*3.1416/180)*0.7), 0f );
+                }
+                gl.glEnd();
+                gl.glRotatef(Angle, 0.0f, 0.0f, 1.0f);
+                gl.glPopMatrix();
+                gl.glFlush ();
+                Angle += 15.0;
+              //  glu.glutPostRedisplay();
+                MoveX +=1;
+                MoveY +=1;              
+                //glutPostRedisplay();
+                //glu.glutTimerFunc(100, animation, 0);
+	}
+  
+    public void mouseClicked(MouseEvent e) {
+        System.out.println("clicked");
+        //throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void mousePressed(MouseEvent e) {
+    System.out.println("pressed");    
+
+           switch(e.getModifiers()) {
+            case InputEvent.BUTTON1_MASK: {
+                mode = MODE_ROTATE;
+                mouseX=e.getX();
+                mouseY=e.getY();
+                System.out.println("That's the LEFT button");
+                break;
+            }
+            case InputEvent.BUTTON3_MASK: {
+                mode = MODE_SCALE;
+                mouseX=e.getX();
+                mouseY=e.getY();
+                System.out.println("That's the RIGHT button");
+                break;
+            }
+          
+        //throw new UnsupportedOperationException("Not supported yet.");
+    }
+    }
+
+    public void mouseReleased(MouseEvent e) {
+        System.out.println("released");
+        mode = MODE_NOTHING;
+       // throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void mouseEntered(MouseEvent e) {   
+        //throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void mouseExited(MouseEvent e) {     
+        //throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void mouseDragged(MouseEvent e) {
+        System.out.println("dragged");
+        //throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void mouseMoved(MouseEvent e) {             
+      //  throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void keyTyped(KeyEvent e) {
+        System.out.println("pressed");
+        //throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void keyPressed(KeyEvent e) {
+         System.out.println("pressed");
+          switch (e.getKeyCode()) {
+      case KeyEvent.VK_ESCAPE:
+        System.exit(0);
+        break;
+
+      default:
+        break;
+    }
+        //throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void keyReleased(KeyEvent e) {
+         System.out.println("pressed");
+        //throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+   /* public void display(GLAutoDrawable drawable) {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }*/
+
+    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+       // throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
+        //throw new UnsupportedOperationException("Not supported yet.");
+    }
+}
Index: /proiecte/SolarSim/Java/SolarSim/src/solarsim/gl/SolarSim.java
===================================================================
--- /proiecte/SolarSim/Java/SolarSim/src/solarsim/gl/SolarSim.java	(revision 152)
+++ /proiecte/SolarSim/Java/SolarSim/src/solarsim/gl/SolarSim.java	(revision 152)
@@ -0,0 +1,445 @@
+package solarsim.gl;
+
+import solarsim.common.State;
+import solarsim.*;
+import com.sun.opengl.util.Animator;
+import com.sun.opengl.util.texture.Texture;
+import com.sun.opengl.util.texture.TextureCoords;
+import com.sun.opengl.util.texture.TextureIO;
+import java.awt.Frame;
+import java.awt.event.*;
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.media.opengl.GL;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLCanvas;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLException;
+import javax.media.opengl.glu.GLU;
+import javax.media.opengl.glu.GLUquadric;
+
+
+
+/**
+ * SolarSim.java <BR>
+ * author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P>
+ *
+ * This version is equal to Brian Paul's version 1.2 1999/10/21
+ */
+public class SolarSim implements GLEventListener, Runnable, KeyListener, MouseListener {
+
+        float rotate = 0;
+        private final double SCALE_FACTOR = 150E9F;   // 150 million km
+        int MoveX = 0;
+        int MoveY = 0;
+
+        float x1[][]= new float[361][2];
+        float x2[][]= new float[361][2];
+        float x3[][]= new float[721][2];
+
+        float Xvalue = 0;
+        float Yvalue = 0;
+        float Angle = 0;
+
+          static final int MODE_SCALE = 0;
+        static final int MODE_ROTATE = 1;
+        static final int MODE_NOTHING = -1;
+
+        int press_x, press_y;
+        float msX_angle = 0;
+        float msY_angle = 0;
+        int mouseX, mouseY;
+        int mode ;
+        float scale_size = 1;
+        
+        private GLU glu = new GLU();
+
+        //private boolean newTexture;
+        private boolean flushTexture;
+        private File file;
+        private Texture textureEarth, textureSun;
+
+        private LinkedList<State> states;
+        static int count = 0;
+
+        private volatile boolean running;
+        private Thread thread;
+        Iterator<State> it;
+        
+    public SolarSim(){
+         this.states = new LinkedList<State>();        
+    }
+
+    void drawState(State s) {
+        if( count == 0 )
+            System.out.println(s);
+        if( count++ % 1 != 0 )
+            return;
+        if( s == null )
+            return;
+        synchronized( states ) {
+            states.addFirst(s);
+            states.notify();
+        }
+    }
+
+    public void init(GLAutoDrawable drawable) {
+        // Use debug pipeline
+        // drawable.setGL(new DebugGL(drawable.getGL()));
+
+        int i = 0;
+
+        for(i=0; i <= 360; i++)
+        {
+            x1[i][0] = (float)(Math.sin(i*3.1416/180)*3);
+            x1[i][1] = (float)(Math.cos(i*3.1416/180)*3);
+        }
+
+        for(i=0; i <= 360; i++)
+        {
+            x2[i][0] = (float)(Math.sin(i*3.1416/180)*1);
+            x2[i][1] = (float)(Math.cos(i*3.1416/180)*1);
+        }
+
+        for(i=0; i <= 720; i++)
+        {
+          x3[i][0] = (float)(Math.sin(i*3.1416/180)*5);
+          x3[i][1] = (float)(Math.cos(i*3.1416/180)*5);
+        }
+
+        GL gl = drawable.getGL();
+        System.err.println("INIT GL IS: " + gl.getClass().getName());
+
+        // Enable VSync
+        gl.setSwapInterval(1);
+
+        // Setup the drawing area and shading mode
+        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+        gl.glShadeModel(GL.GL_SMOOTH); // try setting this to GL_FLAT and see what happens.       
+
+        it = states.iterator();
+
+      /*  gl.glViewport(0,0,500,300);
+        gl.glMatrixMode(GL.GL_PROJECTION);
+        gl.glLoadIdentity();
+        glu.gluPerspective(45.0f, 800.0f / 600.0f, 1.0f, 500.0f);
+        gl.glMatrixMode(GL.GL_MODELVIEW);*/
+    }
+
+    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+        GL gl = drawable.getGL();
+        //GLU glu = new GLU();
+
+        if (height <= 0) { // avoid a divide by zero error!
+        
+            height = 1;
+        }
+        final float h = (float) width / (float) height;
+        gl.glViewport(0, 0, width, height);
+        gl.glMatrixMode(GL.GL_PROJECTION);
+        gl.glLoadIdentity();
+        glu.gluPerspective(45.0f, h, 1.0, 20.0);
+        gl.glMatrixMode(GL.GL_MODELVIEW);
+        gl.glLoadIdentity();
+    }
+
+    public void display(GLAutoDrawable drawable) {
+     /*  synchronized( states ) {
+                while( states.isEmpty() ) {
+                    try {
+                        states.wait();
+                    } catch (InterruptedException ex) { }
+                }
+       }*/
+       
+        //if (it.hasNext())
+          //  while (it.hasNext())
+           // {
+             //   State s = it.next();
+                try {
+                    GL gl = drawable.getGL();
+                    File file = new File("images/earthS.png");
+                    textureEarth = TextureIO.newTexture(file, true);
+                    file = new File("images/sunS.jpg");
+                    textureSun = TextureIO.newTexture(file, true);
+                    // Clear the drawing area
+                    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+                    // Reset the current matrix to the "identity"
+                    gl.glLoadIdentity();
+                    gl.glTranslatef(0.0f, 0.0f, -6.0f);
+
+                    if (mode == MODE_ROTATE) {
+                        msX_angle += (mouseX - press_x) / 5.0;
+                        //  System.out.println("changed "+msX_angle);
+                        if (msX_angle > 180) {
+                            msX_angle -= 360;
+                        } else if (msX_angle < -180) {
+                            msX_angle += 360;
+                        }
+                        press_x = mouseX;
+                        msY_angle += (mouseY - press_y) / 5.0;
+                        if (msY_angle > 180) {
+                            msY_angle -= 360;
+                        } else if (msY_angle < -180) {
+                            msY_angle += 360;
+                        }
+                        press_y = mouseY;
+                    } else if (mode == MODE_SCALE) {
+                        float old_size = scale_size;
+                        scale_size *= (1 + (mouseY - press_y) / 60.0);
+                        if (scale_size < 0) {
+                            scale_size = old_size;
+                        }
+                        press_y = mouseY;
+                    }
+                    //glu.gluLookAt(0.0, 7.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
+                    glu.gluLookAt(0,7,2, 0,0,0, 0,1,0);
+                    gl.glColor3f((float) 1.0, (float) 1.0, (float) 1.0);
+                    //rotate scale the entire image
+                    gl.glRotatef(msX_angle, 0, 1, 0);
+                    gl.glRotatef(msY_angle, 1, 0, 0);
+                    gl.glScalef(scale_size, scale_size, scale_size);
+
+                    GLUquadric qobj = glu.gluNewQuadric();
+                    glu.gluQuadricDrawStyle(qobj, GLU.GLU_FILL);
+                    glu.gluQuadricNormals(qobj, GLU.GLU_SMOOTH);
+
+
+                 /*  synchronized(states) {
+                  //  for( State s : states ) {
+                            Particle p = s.getParticles().get(0);
+                            Vector r = p.getPosition();
+                            int dx = +(int)(r.x/SCALE_FACTOR*300)/20;
+                            int dy = -(int)(r.y/SCALE_FACTOR*300)/20;
+                            System.out.println(dx + " " + dy);
+                                 //earth
+                              //  glu.gluLookAt (0.0, 10.0, 2.0, 0.0, 0.0, 0.0, 1.0, .0, 0.0);
+                                gl.glPushMatrix();
+
+                                gl.glTranslatef(dx, dy, 0.0f);
+                                gl.glRotatef(Angle, 0.0f, 0.0f, 1.0f);
+                                gl.glColor3f(0f, 0f, 1f);
+
+                                glu.gluSphere(qobj,0.2, 15, 15);
+                                gl.glTranslatef(-dx, -dy, 0.0f);
+
+                                gl.glPopMatrix();
+                    //    }
+                    //}*/
+                      /* gl.glPushMatrix();
+
+                                gl.glTranslatef(Xvalue, 0.0f, Yvalue);
+                                gl.glRotatef(Angle, 0.0f, 0.0f, 1.0f);
+                                gl.glColor3f(0f, 0f, 1f);
+
+                                glu.gluSphere(qobj,0.5, 20, 20);
+                                gl.glTranslatef(Xvalue, 0.0f, Yvalue);
+
+                                gl.glPopMatrix();*/
+                    
+                    if (textureSun != null) {
+                        textureSun.enable();
+                        textureSun.bind();
+                        gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
+                        TextureCoords coords = textureSun.getImageTexCoords();
+                        //sun
+                        gl.glPushMatrix();
+                        //glu.gluLookAt (0.0, 10.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
+                        gl.glTranslatef(Xvalue, 0.0f, Yvalue);
+                        gl.glRotatef(Angle, 0.0f, 0.0f, 1.0f);
+                        //glu.gluQuadricNormals(qobj, GLU.GLU_SMOOTH);
+                       // gl.glColor4f(1f, 1f, 0f, 1f);
+                        gl.glTexCoord2f(coords.left(), coords.bottom());
+                        glu.gluQuadricTexture(qobj, true);
+                        glu.gluSphere(qobj, 0.2f, 15, 15);
+                        textureSun.disable();
+                        glu.gluQuadricTexture(qobj, false);
+                        gl.glPopMatrix();
+                    }
+                 
+                    if (textureEarth != null) {
+                        textureEarth.enable();
+                        textureEarth.bind();
+                        gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
+                        TextureCoords coords = textureEarth.getImageTexCoords();
+                         //earth
+                        //glu.gluLookAt (0.0, 10.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
+                        gl.glPushMatrix();
+                        if (MoveX == 360) {
+                            MoveX = 0;
+                        }
+                        gl.glTranslatef(x1[MoveX][1], x1[MoveX][0], 0.0f);
+                        gl.glRotatef(Angle, 0.0f, 0.0f, 1.0f);
+                        //gl.glColor3f(0f, 0f, 1f);
+                        gl.glTexCoord2f(coords.left(), coords.bottom());
+                        glu.gluQuadricTexture(qobj, true);
+                        glu.gluSphere(qobj, 0.3f, 15, 15);
+                        textureEarth.disable();
+                        glu.gluQuadricTexture(qobj, false);
+
+                        gl.glTranslatef(x2[MoveX][0], x2[MoveX][1], 0.0f);
+                        glu.gluSphere(qobj, 0.1f, 10, 10);
+                        gl.glPopMatrix();
+                    }
+
+                    
+                    //saturn
+                    gl.glPushMatrix();
+                    // glu.gluLookAt (0.0, 10.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
+                    if (MoveY == 720) {
+                        MoveY = 0;
+                    }
+                    gl.glTranslatef(x3[MoveY / 2][1], x3[MoveY / 2][0], 0.0f);
+                    gl.glRotatef(Angle, 0.0f, 0.0f, 1.0f);
+                    glu.gluSphere(qobj, 0.3f, 15, 15);
+                    int i = 0;
+                    //glBegin(GL_LINE_STRIP);
+                    gl.glBegin(gl.GL_QUAD_STRIP);
+                    for (i = 0; i <= 360; i++) {
+                        gl.glVertex3f((float) (Math.sin(i*3.1416/180)*0.5), (float) (Math.cos(i*3.1416/180)*0.5), 0f);
+                        gl.glVertex3f((float) (Math.sin(i*3.1416/180)*0.7), (float) (Math.cos(i*3.1416/180)*0.7), 0f);
+                    }
+                    gl.glEnd();
+                    gl.glRotatef(Angle, 0.0f, 0.0f, 1.0f);
+                    gl.glPopMatrix();
+                    gl.glFlush();
+                    Angle += 15.0;
+                    //  glu.glutPostRedisplay();
+                    MoveX += 1;
+                    MoveY += 1;
+                    // Flush all drawing operations to the graphics card
+                } catch (Exception ex) {
+                    Logger.getLogger(SolarSim.class.getName()).log(Level.SEVERE, null, ex);
+                }
+            //}
+    }
+
+    public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
+    }
+
+    public void run() {
+        this.running = true;
+        this.thread = Thread.currentThread();
+        while( running ) {
+            synchronized( states ) {
+                while( states.isEmpty() ) {
+                    try {
+                        states.wait();
+                    } catch (InterruptedException ex) { }
+                }
+               // State s = states.removeLast();
+               
+            }
+            try {
+                thread.sleep(40);
+            } catch( Exception ex ) {}
+        }
+    }
+
+    public void keyTyped(KeyEvent e) {
+      //  throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void keyPressed(KeyEvent e) {
+       // throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void keyReleased(KeyEvent e) {
+      //  throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void mouseClicked(MouseEvent e) {
+        //throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void mousePressed(MouseEvent e) {
+        System.out.println("pressed");
+
+           switch(e.getModifiers()) {
+            case InputEvent.BUTTON1_MASK: {
+                mode = MODE_ROTATE;
+                mouseX=e.getX();
+                mouseY=e.getY();
+                System.out.println("That's the LEFT button");
+                break;
+            }
+            case InputEvent.BUTTON3_MASK: {
+                mode = MODE_SCALE;
+                mouseX=e.getX();
+                mouseY=e.getY();
+                System.out.println("That's the RIGHT button");
+                break;
+            }
+
+        //throw new UnsupportedOperationException("Not supported yet.");
+    }
+    }
+
+    public void mouseReleased(MouseEvent e) {
+        //throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void mouseEntered(MouseEvent e) {
+      //  throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public void mouseExited(MouseEvent e) {
+        //throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public static void main(String[] args) {
+        try{
+            SolarSim sim = new SolarSim();
+            new Thread(sim).start();
+            Frame frame = new Frame("Simple JOGL Application");
+            GLCanvas canvas = new GLCanvas();
+
+            canvas.requestFocus();
+            canvas.addGLEventListener(sim);
+            canvas.addKeyListener(sim);
+            canvas.addMouseListener(sim);
+
+            frame.add(canvas);
+            frame.setSize(800, 600);
+            final Animator animator = new Animator(canvas);
+            frame.addWindowListener(new WindowAdapter() {
+
+            @Override
+            public void windowClosing(WindowEvent e) {
+                // Run this on another thread than the AWT event queue to
+                // make sure the call to Animator.stop() completes before
+                // exiting
+                new Thread(new Runnable() {
+
+                    public void run() {
+                        animator.stop();
+                        System.exit(0);
+                    }
+                }).start();
+            }
+            });
+            // Center frame
+            frame.setLocationRelativeTo(null);
+            frame.setVisible(true);
+            animator.start();
+
+         /*   InputStream is = new FileInputStream("sim.dat");
+            // TODO must have stop message
+            for( int i = 0; i < 1000000; i++ ) {
+                State s = State.readStateFromInputStream(is);
+               sim.drawState(s);
+            }*/
+
+            System.out.println("Stopping.");
+
+            Thread.currentThread().sleep(1000 * 10);
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+    }
+}
+
Index: /proiecte/SolarSim/Java/SolarSim/src/solarsim/io/MyInputStreamReader.java
===================================================================
--- /proiecte/SolarSim/Java/SolarSim/src/solarsim/io/MyInputStreamReader.java	(revision 152)
+++ /proiecte/SolarSim/Java/SolarSim/src/solarsim/io/MyInputStreamReader.java	(revision 152)
@@ -0,0 +1,146 @@
+package solarsim.io;
+
+import solarsim.common.Vector;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Clasa Wrapper pentru InputStream care permite citirea de valori care au fost scrise de programul in C
+ * @author Marius Ion
+ */
+public class MyInputStreamReader {
+
+    private InputStream in;
+
+    public MyInputStreamReader(InputStream in) {
+        this.in = in;
+    }
+
+    /**
+     * Citeste un double scris in binar (8 octeti) din streamul de intrare
+     * @return numarul citit citit
+     * @throws IOException cand s-a produs o eroare la citirea din InputStream-ul incapsulat
+     */
+    public double readDouble() throws IOException {
+        byte [] buf = new byte[8];
+        while( in.available() < 8 )
+            try {
+                Thread.currentThread().sleep(1000);
+            } catch (InterruptedException ex) {}
+        in.read(buf, 0, 8);
+        return arr2double(buf, 0);
+    }
+
+    /**
+     * Citeste un float scris in binar (4 octeti) din streamul de intrare
+     * @return numarul citit citit
+     * @throws IOException cand s-a produs o eroare la citirea din InputStream-ul incapsulat
+     */
+    public double readFloat() throws IOException {
+        byte [] buf = new byte[4];
+        while( in.available() < 4 )
+            try {
+                Thread.currentThread().sleep(1000);
+            } catch (InterruptedException ex) {}
+        in.read(buf, 0, 4);
+        return arr2float(buf, 0);
+    }
+
+    /**
+     * Citeste un int scris in binar (4 octeti) din streamul de intrare
+     * @return numarul citit
+     * @throws IOException cand s-a produs o eroare la citirea din InputStream-ul incapsulat
+     */
+    public int readInt() throws IOException {
+        byte [] buf = new byte[4];
+        while( in.available() < 4 )
+            try {
+                Thread.currentThread().sleep(1000);
+            } catch (InterruptedException ex) {}
+        in.read(buf, 0, 4);
+        return arr2int(buf);
+    }
+
+    /**
+     * Citeste un Vector scris in binar (3 double) din streamul de intrare
+     * @return Vectorul citit
+     * @throws IOException cand s-a produs o eroare la citirea din InputStream-ul incapsulat
+     */
+    public Vector readVector() throws IOException {
+        Vector v = new Vector();
+        v.x = readDouble();
+        v.y = readDouble();
+        v.z = readDouble();
+        readDouble();
+        return v;
+    }
+
+    /**
+     * Citeste un Vector scris in binar (3 float) din streamul de intrare
+     * @return Vectorul citit
+     * @throws IOException cand s-a produs o eroare la citirea din InputStream-ul incapsulat
+     */
+    public Vector readFloatVector() throws IOException {
+        Vector v = new Vector();
+        v.x = (double)readFloat();
+        v.y = (double)readFloat();
+        v.z = (double)readFloat();
+        readFloat();
+        return v;
+    }
+
+    private int arr2int (byte[] arr) {
+        int i = 0;
+        int len = 4;
+        int cnt = 0;
+        byte[] tmp = new byte[len];
+        for (i = 0; i < len; i++) {
+            tmp[cnt] = arr[i];
+            cnt++;
+        }
+        int accum = 0;
+        i = 0;
+        for ( int shiftBy = 0; shiftBy < 32; shiftBy += 8 ) {
+            accum |= ( (int)( tmp[i] & 0xff ) ) << shiftBy;
+            i++;
+        }
+        return accum;
+    }
+
+    private double arr2float (byte[] arr, int start) {
+        int i = 0;
+        int len = 4;
+        int cnt = 0;
+        byte[] tmp = new byte[len];
+        for (i = start; i < (start + len); i++) {
+            tmp[cnt] = arr[i];
+            cnt++;
+        }
+        int accum = 0;
+        i = 0;
+        for ( int shiftBy = 0; shiftBy < 32; shiftBy += 8 ) {
+            accum |= ( (long)( tmp[i] & 0xff ) ) << shiftBy;
+            i++;
+        }
+        return Float.intBitsToFloat(accum);
+    }
+
+    private double arr2double (byte[] arr, int start) {
+        int i = 0;
+        int len = 8;
+        int cnt = 0;
+        byte[] tmp = new byte[len];
+        for (i = start; i < (start + len); i++) {
+            tmp[cnt] = arr[i];
+            cnt++;
+        }
+        long accum = 0;
+        i = 0;
+        for ( int shiftBy = 0; shiftBy < 64; shiftBy += 8 ) {
+            accum |= ( (long)( tmp[i] & 0xff ) ) << shiftBy;
+            i++;
+        }
+        return Double.longBitsToDouble(accum);
+    }
+
+}
Index: /proiecte/SolarSim/Java/SolarSim/src/solarsim/renderer/MyCanvas.java
===================================================================
--- /proiecte/SolarSim/Java/SolarSim/src/solarsim/renderer/MyCanvas.java	(revision 152)
+++ /proiecte/SolarSim/Java/SolarSim/src/solarsim/renderer/MyCanvas.java	(revision 152)
@@ -0,0 +1,53 @@
+package solarsim.renderer;
+
+import java.awt.Canvas;
+import java.awt.Graphics;
+import java.util.LinkedList;
+import solarsim.common.Particle;
+import solarsim.common.State;
+import solarsim.common.Vector;
+
+class MyCanvas extends Canvas {
+
+    private final LinkedList<State> states;
+    MyCanvas() {
+        super();
+        this.setSize(800, 600);
+        states = new LinkedList<State>();
+    }
+
+    void drawState(State s) {
+        synchronized( states ) {
+            if( states.size() == RenderConstants.MAX_STATES ) {
+                states.removeLast();
+            }
+            states.addFirst(s);
+        }
+        this.repaint();
+    }
+
+    @Override
+    public void paint(Graphics g) {
+        g.translate(400, 300);
+        g.drawLine(-300, -300, 300, 300);
+        g.drawLine(-300, 300, 300, -300);
+        g.drawLine(-300, -300, -300, 300);
+        g.drawLine(300, -300, 300, 300);
+        g.drawLine(-400, 0, 400, 0);
+        g.drawLine(0, -300, 0, 300);
+        synchronized(states) {
+            for( State s : states ) {
+                for( Particle p : s.getParticles() ) {
+                    Vector r = p.getPosition();
+                    int dx = +(int)(r.x/RenderConstants.SCALE_FACTOR*300);
+                    int dy = -(int)(r.y/RenderConstants.SCALE_FACTOR*300);
+                    g.translate(dx, dy);
+                    g.fillOval(-1, -1, 3, 3);
+                    g.translate(-dx, -dy);
+                }
+            }
+        }
+        g.translate(-400, -300);
+    }
+
+}
Index: /proiecte/SolarSim/Java/SolarSim/src/solarsim/renderer/RenderConstants.java
===================================================================
--- /proiecte/SolarSim/Java/SolarSim/src/solarsim/renderer/RenderConstants.java	(revision 152)
+++ /proiecte/SolarSim/Java/SolarSim/src/solarsim/renderer/RenderConstants.java	(revision 152)
@@ -0,0 +1,19 @@
+package solarsim.renderer;
+
+class RenderConstants {
+    /**
+     * how many states to draw. MAX_STATES==1 - draws only current state, 2 - draws current and previous, etc.
+     */
+    public final static int MAX_STATES = 10000;
+    /**
+     * 150 million km - only the first three planets are visible
+     * 250 million km - only the first four planets are visible
+     * 800 million km - only the first five planets are visible
+     * 1500 million km - only the first six planets are visible
+     */
+    public final static double SCALE_FACTOR = 250E9F;
+    /**
+     * DRAW_EVERY=1 - draws every state, DRAW_EVERY=n - draws one in n states.
+     */
+    public final static int DRAW_EVERY = 1;
+}
Index: /proiecte/SolarSim/Java/SolarSim/src/solarsim/renderer/Renderer2D.java
===================================================================
--- /proiecte/SolarSim/Java/SolarSim/src/solarsim/renderer/Renderer2D.java	(revision 152)
+++ /proiecte/SolarSim/Java/SolarSim/src/solarsim/renderer/Renderer2D.java	(revision 152)
@@ -0,0 +1,101 @@
+package solarsim.renderer;
+
+import solarsim.*;
+import solarsim.common.State;
+import java.awt.*;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.*;
+import javax.swing.*;
+
+
+public class Renderer2D extends JFrame implements Runnable {
+
+    private final MyCanvas canvas;
+    private final LinkedList<State> states;
+    private volatile boolean running;
+    private Thread thread;
+    static int count=0;
+
+    public Renderer2D() {
+        super("Solar Sim");
+        this.canvas = new MyCanvas();
+        this.states = new LinkedList<State>();
+
+        this.setLayout(new BorderLayout());
+        this.add(canvas);
+
+        this.pack();
+        this.setVisible(true);
+    }
+
+    public void drawState(State s) {
+        if( count++ % RenderConstants.DRAW_EVERY != 0 )
+            return;
+        if( s == null )
+            return;
+        synchronized( states ) {
+            states.addFirst(s);
+            states.notify();
+        }
+    }
+
+    @Override
+    public void run() {
+        this.running = true;
+        this.thread = Thread.currentThread();
+        while( running ) {          
+            synchronized( states ) {
+                while( states.isEmpty() ) {
+                    try {
+                        states.wait();
+                    } catch (InterruptedException ex) { }
+                }
+                State s = states.removeLast();
+                canvas.drawState(s);
+            }
+            try {
+                thread.sleep(40);
+            } catch( Exception ex ) {}
+        }
+    }
+
+    public void stop() {
+        this.running = false;
+        this.thread.interrupt();
+        // close JFrame
+        this.setVisible(false);
+        this.dispose();
+    }
+
+
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String[] args) {
+        try {
+            Renderer2D renderer = new Renderer2D();
+            new Thread(renderer).start();
+/*
+            ServerSocket ss = new ServerSocket(2200);
+            Socket sock = ss.accept();
+            InputStream is = sock.getInputStream();
+*/
+            InputStream is = new FileInputStream("sim.dat");
+            while(true) {
+                State s = State.readStateFromInputStream(is);
+                if( s == null )
+                    break;
+                renderer.drawState(s);
+            }
+
+            System.out.println("Stopping.");
+
+            Thread.currentThread().sleep(1000 * 60);
+            renderer.stop();
+  //          sock.close();
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+    }
+}
Index: /proiecte/SolarSim/Java/SolarSim/src/solarsim/sochacki/Sochacki.java
===================================================================
--- /proiecte/SolarSim/Java/SolarSim/src/solarsim/sochacki/Sochacki.java	(revision 152)
+++ /proiecte/SolarSim/Java/SolarSim/src/solarsim/sochacki/Sochacki.java	(revision 152)
@@ -0,0 +1,187 @@
+package solarsim.sochacki;
+
+import solarsim.renderer.Renderer2D;
+import solarsim.common.State;
+import solarsim.common.Particle;
+import solarsim.common.Vector;
+import java.util.LinkedList;
+import java.util.List;
+
+public class Sochacki {
+    int nt;
+    int Np;
+    static double AU = 149597870691F;   // Astronomical Unit
+    static double D = 86400;            // Astronomical Day
+    static double K = 0.01720209895;    // Gauss' gravitational constant
+    static double G = K*K;
+    static double S = 1.9891E30;        // Astronomical Unit for mass - the mass of the Sun
+    //static double Gm = 6.6743E-11;
+
+    double [] mass;
+    double [][][] xx;
+    double [][][] vv;
+
+    double [][][] aa;
+    double [][][] u1;
+    double [][][] u2;
+    double [][][] u3;
+
+    public Sochacki(int nt, int Np) {
+        this.nt = nt;
+        this.Np = Np;
+        mass = new double[2];
+        xx = new double[3][Np][nt];
+        vv = new double[3][Np][nt];
+
+        aa = new double[Np][Np][nt];
+        u1 = new double[Np][Np][nt];
+        u2 = new double[Np][Np][nt];
+        u3 = new double[Np][Np][nt];
+    }
+
+    void initState() {
+        // Sun
+        mass[0] = G;
+        xx[0][0][0] = 0;
+        xx[1][0][0] = 0;
+        xx[2][0][0] = 0;
+        vv[0][0][0] = 0;
+        vv[1][0][0] = 0;
+        vv[2][0][0] = 0;
+
+        // Earth
+        mass[1] = G / 332840;//S
+        xx[0][1][0] = 0.98328989;//AU
+        xx[1][1][0] = 0;
+        xx[2][1][0] = 0;
+        vv[0][1][0] = 0;
+        vv[1][1][0] = 30286.7 * D / AU;
+        vv[2][1][0] = 0;
+
+        for( int j = 0; j < Np; j++ ) {
+            for( int k = 0; k < Np; k++ ) {
+                if( j == k )
+                    continue;
+                
+                double s = 0;
+                for( int i = 0; i < 3; i++ ) {
+                    double dx = (xx[i][j][0] - xx[i][k][0]);
+                    s += dx * dx;
+                }
+                u1[j][k][0] = 1 / Math.sqrt(s);
+                u2[j][k][0] = u1[j][k][0] * u1[j][k][0];
+                u3[j][k][0] = u2[j][k][0] * u1[j][k][0];
+
+                s = 0;
+                for( int i = 0; i < 3; i++ ) {
+                    double dx = (xx[i][k][0] - xx[i][j][0]);
+                    double dv = (vv[i][k][0] - vv[i][j][0]);
+                    s += dx * dv;
+                }
+                aa[j][k][0] = s;
+            }
+        }
+    }
+
+    void genPoly() {
+        double a, b;
+        int i, j, k, L, m;
+
+        for( m = 1; m < nt; m++ ) {
+            for( j = 0; j < Np; j++ ) {
+                for( i = 0; i < 3; i++ ) {
+                    xx[i][j][m] = vv[i][j][m-1] / m;
+                    a = 0;
+                    for( k = 0; k < Np; k++ ) {
+                        b = 0;
+                        for( L = 0; L <= m-1; L++ ) {
+                            b = b + (xx[i][k][L] - xx[i][j][L])*u3[j][k][m-1-L];
+                        }
+                        a = a + mass[k] * b;
+                    }
+                    vv[i][j][m] = a / m;
+                }
+                for( k = 0; k <= j-1; k++ ) {
+                    a = 0;
+                    for( L = 0; L <= m-1; L++ ) {
+                        a = a - u3[j][k][L] * aa[j][k][m-1-L];
+                    }
+                    u1[j][k][m] = a / m;
+                    u1[k][j][m] = a / m;
+                    a = 0;
+                    for( L = 0 ; L <= m; L++ ) {
+                        a = a + u1[j][k][L] * u1[j][k][m-L];
+                    }
+                    u2[j][k][m] = a;
+                    u2[k][j][m] = a;
+                    a = 0;
+                    b = 0;
+                    for( L = 0; L <= m; L++ ) {
+                        b = b + u2[j][k][L] * u1[j][k][m-L];
+                        for( i = 0; i < 3; i++ ) {
+                            a = a + (xx[i][j][L]-xx[i][k][L])*(vv[i][j][m-L]-vv[i][k][m-L]);
+                        }
+                    }
+                    aa[j][k][m] = a;
+                    aa[k][j][m] = a;
+                    u3[j][k][m] = b;
+                    u3[k][j][m] = b;
+                }
+                aa[j][j][m] = 0;
+                u1[j][j][m] = 0;
+                u2[j][j][m] = 0;
+                u3[j][j][m] = 0;
+            }
+        }
+    }
+
+    double evalPoly( double t, double [] c ) {
+        double p = 0;
+
+        for( int i = c.length-1; i >= 0; i-- ) {
+            p = p * t + c[i];
+        }
+
+        return p * AU;
+    }
+
+    State getState( double time ) {
+        List<Particle> particles = new LinkedList<Particle>();
+        for( int i = 0; i < Np; i++) {
+            double x = evalPoly(time, xx[0][i]);
+            double y = evalPoly(time, xx[1][i]);
+            double z = evalPoly(time, xx[2][i]);
+            Vector r = new Vector(x, y, z);
+
+            double vx = evalPoly(time, vv[0][i]);
+            double vy = evalPoly(time, vv[1][i]);
+            double vz = evalPoly(time, vv[2][i]);
+            Vector v = new Vector(vx, vy, vz);
+
+            Particle p = new Particle(mass[i], r, v);
+            particles.add(p);
+        }
+
+        return new State(particles);
+    }
+
+    public static void main(String [] args) {
+        Renderer2D renderer = new Renderer2D();
+        new Thread(renderer).start();
+
+        Sochacki sch = new Sochacki(100,2);
+        sch.initState();
+        sch.genPoly();
+        for( double t = -228; t < 229; t += 1 ) {
+            State s = sch.getState(t);
+            //System.out.println(s);
+            renderer.drawState(s);
+        }
+        try {
+            Thread.currentThread().sleep(60 * 1000);
+        } catch( InterruptedException e ) {
+            e.printStackTrace();
+        }
+        renderer.stop();
+    }
+}
Index: /proiecte/SolarSim/Matlab/CalcEA.m
===================================================================
--- /proiecte/SolarSim/Matlab/CalcEA.m	(revision 152)
+++ /proiecte/SolarSim/Matlab/CalcEA.m	(revision 152)
@@ -0,0 +1,52 @@
+% Orbit eccentric anomaly, Kepler's equation keplers equation
+% Richard Rieber
+% 1/23/2005
+% rrieber@gmail.com
+% 
+% Revision 8/21/07: Fixed typo in line 38 if statement
+%                   Added H1 line for lookfor functionality
+%
+% function E = CalcEA(M,ecc,tol)
+% 
+% Purpose: Solves for eccentric anomaly, E, from a given mean anomaly, M,
+%          and eccentricty, ecc.  Performs a simple Newton-Raphson iteration
+%
+% Inputs: o M   - Mean anomaly in radians.
+%         o ecc - Eccentricity of the orbit.
+%         o tol - a tolerance at which to terminate iterations; Default
+%                 is 10^-8 radians. [OPTIONAL]
+%
+% Outputs: o E  - The eccentric anomaly in radians.
+%
+% E = CalcEA(M,ecc) uses default tolerances
+%
+% E = CalcEA(M,ecc,tol) will use a user specified tolerance, tol
+% 
+
+function E = CalcEA(M,ecc,tol)
+
+%Checking for user inputed tolerance
+if nargin == 2
+    %using default value
+    tol = 10^-8;
+elseif nargin > 3
+    error('Too many inputs.  See help CalcEA')
+elseif nargin < 2
+    error('Too few inputs.  See help CalcEA')
+end
+
+if (M > -pi && M < 0) || M > pi
+    E = M - ecc;
+else
+    E = M + ecc;
+end
+
+Etemp  = E + (M - E + ecc*sin(E))/(1-ecc*cos(E));
+Etemp2 = E;
+
+while abs(Etemp - Etemp2) > tol
+    Etemp = Etemp2;
+    Etemp2 = Etemp + (M - Etemp + ecc*sin(Etemp))/(1-ecc*cos(Etemp));
+end
+
+E = Etemp2;
Index: /proiecte/SolarSim/Matlab/keplerToCarthezian.m
===================================================================
--- /proiecte/SolarSim/Matlab/keplerToCarthezian.m	(revision 152)
+++ /proiecte/SolarSim/Matlab/keplerToCarthezian.m	(revision 152)
@@ -0,0 +1,46 @@
+function [R,V,v] = keplerToCarthezian(I,Omega,w,a,ecc,M,tol)
+
+    if nargin < 6 || nargin > 7
+        error('Incorrect number of inputs')
+    elseif nargin == 6
+        tol = 10^-8;
+    end
+    
+    mu_sun = 132712440018; %km^3/s^2
+
+    E = CalcEA(M,ecc);
+    nu = nuFromM(M,ecc,tol);
+    r = a * (1 - ecc*ecc)/(1+ecc*cos(nu));
+    p = a * (1 - ecc*ecc);
+    
+    rx = r * (cos(Omega)*cos(w+nu) - sin(Omega)*cos(I)*sin(w+nu));
+    ry = r * (sin(Omega)*cos(w+nu) + cos(Omega)*cos(I)*sin(w+nu));
+    rz = r * sin(I) * sin(w+nu);
+
+    v = sqrt( mu_sun * (2/r - 1/a) );
+    
+%    vx = -sqrt(mu_sun/p) * (cos(Omega)*(sin(w+nu)+ecc*sin(w))-sin(Omega)*cos(I)*(cos(w+nu)+ecc*cos(w)));
+%    vy = -sqrt(mu_sun/p) * (sin(Omega)*(sin(w+nu)+ecc*sin(w))-cos(Omega)*cos(I)*(cos(w+nu)+ecc*cos(w)));
+%    vz =  sqrt(mu_sun/p) * sin(I)*(cos(w+nu)+ecc*cos(w));
+
+    if (I > 0)
+        A = [ sin(I)*sin(Omega) -sin(I)*cos(Omega) ; rx ry ];
+        B = [ -cos(I) ; -rz ];
+        rez = inv(A) * B;
+        a = rez(1);
+        b = rez(2);
+
+        vz = v / sqrt(1 + a*a + b*b);
+        vx = a * vz;
+        vy = b * vz;
+    else
+        vx = v / sqrt(1+(rx*rx)/(ry*ry));
+        vy = - rx/ry * vx;
+        vz = 0;
+    end
+    
+    R = [rx ry rz];
+    V = [vx vy vz];
+    
+end
+    
Index: /proiecte/SolarSim/Matlab/nuFromM.m
===================================================================
--- /proiecte/SolarSim/Matlab/nuFromM.m	(revision 152)
+++ /proiecte/SolarSim/Matlab/nuFromM.m	(revision 152)
@@ -0,0 +1,34 @@
+%Kepler Orbit Anomaly true mean
+% Richard Rieber
+% September 27, 2006
+% rrieber@gmail.com
+% 
+% Revision 9/25/07 - Fixed a grusome error in the default tolerance.
+%                    Changed from 10^8 radians to 10^-8 radians.  Whoops.
+%
+% function nu = nuFromM(M,ecc,tol)
+% 
+% Purpose:  This function calculates the true anomaly (nu) of a position in an orbit given
+%           the mean anomaly of the position (M) and the eccentricity (ecc) of the orbit.
+%           This uses another function, calcEA.
+%           
+% Inputs:  M   - mean anomaly of position in radians
+%          ecc - eccentricity of orbit
+%          tol - A tolerance for calculating the eccentric anomaly (see help calcEA.m)
+%                Default is 10^-8 radians [OPTIONAL]
+% 
+% Output:  nu  - true anomaly of position in radians
+
+function nu = nuFromM(M,ecc,tol)
+
+if nargin < 2 || nargin > 3
+    error('Incorrect number of inputs, see help nuFromM.m')
+elseif nargin == 2
+    tol = 10^-8;
+end
+
+E = CalcEA(M,ecc,tol);  %Determining eccentric anomaly from mean anomaly
+
+% Since tan(x) = sin(x)/cos(x), we can use atan2 to ensure that the angle for nu
+% is in the correct quadrant since we know both sin(nu) and cos(nu).  [see help atan2]
+nu = atan2((sin(E)*(1-ecc^2)^.5),(cos(E)-ecc));
