%
% mkbod.m -- generate test data for the N-body project
%
% The N-body data is saved in a file that begins with two 32-bit
% integers specifying the number of rows (this value is always 7) and
% the number of columns, equal to N.  The remainder of the values are
% 32-bit floats, organized as follows:
% 
%                        objects
%                   1   2   3  ...  N 
%                 +----------- ... ---+
%        mass     |                   |
%     x position  |                   |
%     y position  |                   |
%     z position  |                   |
%     x velocity  |                   |
%     y velocity  |                   |
%     z velocity  |                   |
%                 +----------- ... ---+
% 
% The N-body data generated by this script saved in nbod_init.dat
%

wtype = 'ieee-be';   % for IBM Power PC
% wtype = 'ieee-le';     % for Intel/AMD

N = input('number of bodies > ');

% seed random number generator
% rand('seed',sum(100*clock));

% generate masses
M  =  100 * (abs(randn(N,1)) + 1);

% generate positions
Px  = 20 * randn(N,1);
Py  = 20 * randn(N,1);
Pz  = 20 * randn(N,1);
% Pz  = 20 * zeros(N,1);  % TEMPORARY 2-D TEST

% generate veolcities
Vx = randn(N,1) * 2;
Vy = randn(N,1) * 2;
Vz = randn(N,1) * 2;
% Vz = zeros(N,1) * 2;    % TEMPORARY 2-D TEST	

% concatenate data
tmp = [M,Px,Py,Pz,Vx,Vy,Vz];
tmp = tmp';

% write the dataset
fp = fopen('nbod_init.dat', 'w', wtype);
fwrite(fp, 7, 'int32');
fwrite(fp, N, 'int32');
fwrite(fp, tmp, 'float32');
fclose(fp);

% clean up
clear N M Px Py Pz Vz Vy Vz tmp fp

