function FileSignalAsComponents( realOut, imagOut, signal, intFlg, polFlg ) % Files the the 2-dim array represented in f % .. as complex components in 2 separate files. % h, w are the height, width of the signal array. % intFlg: 0 => output values are floats, comma-delimited % 1 => output values are signed integers, comma-delimited % 2 => output values are unsigned bytes, comma-delimited % 3 => output is a binary stream % polFlg: 0 => normal operation; % 1 => If 2 output files, then they receive angle, magnitude. % If 1 output file, then it receives magnitude (same as Real). % (This maintains consistency with Matlab's syntax.) % % 31 Dec 2008 - D.Bozarth, SSU Engineering Science % 12 Jan 2009 - Allow empty second parameter. % 13 Jan 2009 - Add flag for polar components. % 17 Jan 2009 - Add value '2' to intFlg semantics. % 27 Jan 2009 - Enable binary file output, remove 2 arguments - use size() instead. % imFlg = ~isequal(imagOut, ''); switch intFlg case 0 format0 = '%.9E,'; format1 = '%.9E\n'; mode = 'wt'; case 1 format0 = '%d,'; format1 = '%d\n'; mode = 'wt'; case 2 format0 = '%03u,'; format1 = '%03u\n'; mode = 'wt'; case 3 format0 = 'single'; format1 = 'single'; mode = 'wb'; %tmp = signal; %signal = MatrixToVector( signal ); %signal = signal'; otherwise intFlg return end fre = fopen( realOut, mode ); if imFlg fim = fopen( imagOut, mode ); else polFlg = 0; % In this case, treat the one file as Real. end [h, w] = size( signal ); for j = 1:h if polFlg if intFlg ~= 3 fprintf(fre, format0, angle( signal(j, 1:(w-1)) )); fprintf(fre, format1, angle( signal(j, w) )); else count = fwrite( fre, angle( signal(j, :) ), format0 ); end else if intFlg ~= 3 fprintf(fre, format0, real( signal(j, 1:(w-1)) )); fprintf(fre, format1, real( signal(j, w) )); else count = fwrite( fre, real( signal(j, :) ), format0 ); end end if imFlg if polFlg if intFlg ~= 3 fprintf(fim, format0, abs( signal(j, 1:(w-1)) )); fprintf(fim, format1, abs( signal(j, w) )); else count = fwrite( fim, abs( signal(j, :) ), format0 ); end else if intFlg ~= 3 fprintf(fim, format0, imag(signal(j, 1:(w-1)) )); fprintf(fim, format1, imag(signal(j, w) )); else count = fwrite( fim, imag(signal(j, :) ), format0 ); end end end end fclose(fre); if imFlg fclose(fim); end % % end script