display("Writing File");
ID = tic();
fid = fopen("TestWrite","w");
for i = 1:255
  for j = 1:254
    for k = 1:253
      CNT = fwrite(fid,uint8(k),"uint8");
      if (CNT == 0)
        display(sprintf("Index %d Index %d Index %d Write Failure\n",i,j,k));
        error("Write Error");
      endif
    endfor
  endfor
endfor
WRITE_FP = ftell(fid);
display(sprintf("Wrote %d bytes\n",i*j*k));
display(sprintf("File Pointer %d\n",WRITE_FP));
fclose(fid);
elapsed_time = toc(ID);
display(sprintf("Write took %f seconds\n",elapsed_time));
##
## Read back Data
##
display("Reading File");
ID = tic();
fid = fopen("TestWrite","r");
DATA = uint8(fread(fid,"uint8"));
READ_FP = ftell(fid);
fclose(fid);
elapsed_time = toc(ID);
display(sprintf("Read took %f seconds\n",elapsed_time));
display(sprintf("Read %d bytes\n",length(DATA)));
display(sprintf("File Pointer %d\n",READ_FP));
##
## Read Back Data - Method 2
display("Reading File");
ID = tic();
fid = fopen("TestWrite","r");
DATA2=uint8([]);
for i = 1:255
  for j = 1:254
    for k = 1:253
      [VAL, CNT] = fread(fid,1,"uint8");
      if (CNT == 0)
        READ2_FP = ftell(fid);
        display(sprintf("Index %d Index %d Index %d Read Failure\n",i,j,k));
        display(sprintf("File Pointer %d\n",READ2_FP));
        error("Invalid Read");
      endif
      DATA2(i*j+k) = uint8(VAL);
    endfor
  endfor
endfor
fclose(fid);
elapsed_time = toc(ID);
display(sprintf("Read took %f seconds\n",elapsed_time));
display(sprintf("Read %d bytes\n",length(DATA)));

