% Program: DarkCurrentComputation.m
% Author: Greg Wientjes
% Class: EE 362, Applied Vision Systems
% -----------------------------------------
% Description: This program computes the dark current value for the Nikon D70 Digital Camera. 
% We will be using the dark current value for the simulation of the camera using ISET.


% Compute dark current average for the first cd.
average_all_1stCD =[];

for i=1:55
    num = num2str(i);
    if ( i <= 9 )
        name = strcat('first\Dark Current\dc0', num, '.nef');
    else 
        name = strcat('first\Dark Current\dc', num, '.nef');
    end;    
    
    a = nefread(name);
    average_1stCD = sum(sum(sum(a)))/(1007*1520*4);
    average_all_1stCD = [average_all_1stCD average_1stCD];
    if( mod(i, 3) == 0 ) 
        disp(i);
        disp(average_1stCD);
    end;
end;


% Compute dark current average for the second cd.
average_all_2ndCD =[];

for i=1:55
    num = num2str(i);
    if ( i <= 9 )
        name = strcat('second\DSC_000', num, '.nef');
    else 
        name = strcat('second\DSC_00', num, '.nef');
    end;    
    
    a = nefread(name);
    average_2ndCD = sum(sum(sum(a)))/(1007*1520*4);
    average_all_2ndCD = [average_all_2ndCD average_2ndCD];
    if( mod(i, 3) == 0 ) 
        disp(i);
        disp(average_2ndCD);
    end;
end;


% Compute dark current average for the third cd.
average_all_3rdCD =[];

for i=1:55
    num = num2str(i);
    if ( i <= 9 )
        name = strcat('third\dc0', num, '.nef');
    else 
        name = strcat('third\dc', num, '.nef');
    end;    
    
    a = nefread(name);
    average_3rdCD = sum(sum(sum(a)))/(1007*1520*4);
    average_all_3rdCD = [average_all_3rdCD average_3rdCD];
    if( mod(i, 3) == 0 ) 
        disp(i);
        disp(average_3rdCD);
    end;
end;


% Take the average of the 3 cds.
average_3cds = ( average_all_1stCD + average_all_2ndCD + average_all_3rdCD ) / 3;


% Save our dark current workspace variables.
save DarkCurrent_AverageAll average_all_1stCD average_all_2ndCD average_all_3rdCD average_3cds;


% Display 'done' once the program finishes.
disp('done');