function[ count ] = freaddata( filename, initial )
%Version 4/3/09
%Called by fupdate to read in the data (from initial.txt, culled.txt,
%inspected.txt and final.txt) to update the black progress bar in the
%FretScal window. Gets called when returning to a previous analysis in an output directory, to
% load the previous settings and results from initial.txt.
global AOIshape CFPspill YFPspill frettype cfptype yfptype active
global biggestring side AOIring limit1 limit2
global intensitylimit bringthick bringincr separation inputdirectory outputdirectory dirsep
global YFPFWHM FRETFWHM CFPFWHM YFPmono FRETmono CFPmono YFPs2b FRETs2b CFPs2b
global YFPFWHMcull FRETFWHMcull CFPFWHMcull YFPmonocull FRETmonocull CFPmonocull YFPs2bcull FRETs2bcull CFPs2bcull
global context toobright bpfilter patchpixel maxmovement primary
fin = fopen( strcat( inputdirectory, dirsep, outputdirectory, dirsep, filename ), 'r' );
if( fin ~= -1 ) %% opened and needs updating
count = 0;
[ scrap, count ] = fscanf( fin, '%s', 1 );
while( count > 0 )
if (strcmp(scrap, 'ExptType'))
Etype = fscanf(fin,'%s',1);
if strcmp(Etype,'FRET')
frettype = 1; cfptype = 0; yfptype = 0;
active(1:4) = 1;
elseif strcmp(Etype,'calcCFPspill')
frettype = 0; cfptype = 1; yfptype = 0;
active (1) = 0; active(2:4) =1;
elseif strcmp(Etype,'calcYFPspill')
frettype = 0; cfptype = 0; yfptype = 1;
active(1:2) =1; active(3) = 0; active(4)=1;
else
fprintf(1,'Expt type not recognized');
end;
end
if( strcmp( scrap, 'CFPspillfactor' ) )
CFPspill = fscanf( fin, '%f', 1 );
end;
if( strcmp( scrap, 'YFPspillfactor' ) )
YFPspill = fscanf( fin, '%f', 1 );
end;
if( strcmp( scrap, 'PrimaryChannel' ) )
primary = fscanf( fin, '%d', 1 );
end;
if( strcmp( scrap, 'YFPtargetFWHM' ) )
YFWHM = fscanf( fin, '%f', 1 );
end;
if( strcmp( scrap, 'YFPtargetmono' ) )
Ymono = fscanf( fin, '%f', 1 );
end;
if( strcmp( scrap, 'YFPsignal2noise' ) )
Ys2b = fscanf( fin, '%f', 1 );
end;
if( strcmp( scrap, 'FRETtargetFWHM' ) )
FFWHM = fscanf( fin, '%f', 1 );
end;
if( strcmp( scrap, 'FRETtargetmono' ) )
Fmono = fscanf( fin, '%f', 1 );
end;
if( strcmp( scrap, 'FRETsignal2noise' ) )
Fs2b = fscanf( fin, '%f', 1 );
end;
if( strcmp( scrap, 'CFPtargetFWHM' ) )
CFWHM = fscanf( fin, '%f', 1 );
end;
if( strcmp( scrap, 'CFPtargetmono' ) )
Cmono = fscanf( fin, '%f', 1 );
end;
if( strcmp( scrap, 'CFPsignal2noise' ) )
Cs2b = fscanf( fin, '%f', 1 );
end;
if( strcmp( scrap, 'Bkg_incr' ) )
bringincr = fscanf( fin, '%d', 1 );
end;
if( strcmp( scrap, 'Bkg_thick' ) )
bringthick = fscanf( fin, '%d', 1 );
end;
if( strcmp( scrap, 'AOIshape' ) )
AOIshape = fscanf( fin, '%d', 1 );
side = AOIshape;
AOIring = (side +1)/2;
rindex = AOIring-1;
biggestring = rindex + bringincr + bringthick -1;
end;
if( strcmp( scrap, 'spotlimit' ) )
intensitylimit = fscanf( fin, '%f', 1 );
% fprintf( 1, 'in readdata intensitylimit = %f\n', intensitylimit );
end;
if( strcmp( scrap, 'separation' ) )
separation = fscanf( fin, '%d', 1 );
end;
if( strcmp( scrap, 'context' ) )
context = fscanf( fin, '%d', 1 );
end;
if( strcmp( scrap, 'toobright' ) )
toobright = fscanf( fin, '%f', 1 );
end;
if( strcmp( scrap, 'bpfilter' ) )
bpfilter = fscanf( fin, '%d', 1 );
end;
if( strcmp( scrap, 'patchpixel' ) )
patchpixel = fscanf( fin, '%d', 1 );
end;
if( strcmp( scrap, 'maxmovement' ) )
maxmovement = fscanf( fin, '%d', 1 );
end;
if( strcmp( scrap, 'searchlimited' ) )
limit1 = fscanf( fin, '%d', 1 );
end;
if( strcmp( scrap, 'culllimited' ) )
limit2 = fscanf( fin, '%d', 1 );
end;
[ scrap, count ] = fscanf( fin, '%s', 1 );
end;
fseek( fin, 0, -1 ); % rewind
while( feof( fin ) ~= 1 )
tline = fgetl( fin );
count = count + 1;
end;
count = count - 2;
fclose( fin );
if initial == 1 % if reading from initial.txt
YFPs2b = Ys2b;
CFPs2b = Cs2b;
FRETs2b = Fs2b;
YFPFWHM = YFWHM;
CFPFWHM = CFWHM;
FRETFWHM = FFWHM;
YFPmono = Ymono;
CFPmono = Cmono;
FRETmono = Fmono;
end;
if initial == 2 % if reading from culled.txt
YFPs2bcull = Ys2b;
CFPs2bcull = Cs2b;
FRETs2bcull = Fs2b;
YFPFWHMcull = YFWHM;
CFPFWHMcull = CFWHM;
FRETFWHMcull = FFWHM;
YFPmonocull = Ymono;
CFPmonocull = Cmono;
FRETmonocull = Fmono;
end;
else
count = 0;
end;