%% This generates a binary file and corresponding set of
%% commands for ldcodas.

fid_bin = fopen('test1.bin', 'wb');
fid_cmd = fopen('test1.cmd', 'w');

array1 = 1:6;
array2 = array1 * 2;

access = [1 64 2.73 4.198 0 0 0 0];

fprintf(fid_cmd, 'binary_file: test1.bin\n');
fprintf(fid_cmd, 'new_block\n');

fprintf(fid_cmd, 'dp_mask: 1\n');

fprintf(fid_cmd, 'new_profile: 2000/09/18 00:00:01\n');

fprintf(fid_cmd, 'depth_range: 16 256\n');

offset = ftell(fid_bin);
fwrite(fid_bin, array1, 'float32');
fprintf(fid_cmd, 'binary_data: U FLOAT %d %d\n', ...
                              length(array1), offset);

offset = ftell(fid_bin);
fwrite(fid_bin, access, 'float64');
fprintf(fid_cmd, 'binary_data: ACCESS_VARIABLES DOUBLE %d %d\n', ...
                              length(access), offset);


offset = ftell(fid_bin);
fwrite(fid_bin, array2, 'uint8');
fprintf(fid_cmd, 'binary_data: PERCENT_GOOD UBYTE %d %d\n', ...
                              length(array2), offset);

fprintf(fid_cmd, 'new_profile: 2000/09/18 00:00:02\n');

fprintf(fid_cmd, 'depth_range: 16 512\n');


offset = ftell(fid_bin);
fwrite(fid_bin, array2, 'float32');
fprintf(fid_cmd, 'binary_data: U FLOAT %d %d\n', ...
                              length(array2), offset);

offset = ftell(fid_bin);
fwrite(fid_bin, access, 'float64');
fprintf(fid_cmd, 'binary_data: ACCESS_VARIABLES DOUBLE %d %d\n', ...
                              length(access), offset);


offset = ftell(fid_bin);
fwrite(fid_bin, array1, 'uint8');
fprintf(fid_cmd, 'binary_data: PERCENT_GOOD UBYTE %d %d\n', ...
                              length(array1), offset);


fclose(fid_cmd)
fclose(fid_bin)

