function writeSSRL(immigrant) %WRITESSRL save struct data in SSRL binary format and % allow MVIEW, MCALIB, MAVE to read % % The input struct data should contain the following fields % froot: char array (the root name of the data file) % fext: char array (the extension of the data file) % beamline: char array (beamline infomation) % comments: cell array {6x1} (user comments) % recTime: char array (data recording time) % labels: cell array {Ncolx1} (labels for each columns) % offsets: double array [Ncolx1] (offset for each channels) % data: double array [NcolxNpts] (data) % % The converted file has a prefix of 'ssrl_' to the original file name % and can be read by MVIEW, MCALIB, and MAVE. % %************* % SSRL format %************* % 1. 800 bytes = 40 bytes (title MUST start with 'SSRL -') '\n' '0' % + 40 bytes (recording date:time) '\n' '0' % + 40 bytes (scaler_file) '\n' '0' % + 40 bytes (region_file) '\n' '0' % + 80 bytes (mirror_info) '\n' '0' % + 40 bytes (mirror param) '\n' '0' % + 80 bytes x 6 (User comments) '\n' '0' % % 2. NCOL*4 bytes (offsets) % NCOL*4 bytes (weights) % % 3. NCOL*20 bytes (labels for each column) % % 4. 4 bytes integer (npts) % % 5. mysterious 12 bytes starting w/ char(8),char(0), char(1), char(0) % probably it's not important. % % 6. NCOL*NPTS*4 bytes (data) % % % Tsu-Chien Weng, 2002-07-24 % Copyleft(c), by the Penner-Hahn research group % 2004-12-01: add truncateOrFillBlanks() to clean up the codes fname=['ssrl_' immigrant.froot '.' immigrant.fext]; fid=fopen(fname,'w','vaxd'); [numDataColumns,numDataPoints]=size(immigrant.data); % char([10 0])=['\n', '0'] % Hallelujah ... % Tricks: 'SSRL - EXAFS Data Collector 1.3 '; % 1. 800 bytes of char (headers) fwrite(fid,[truncateOrFillBlanks('SSRL - EXAFS Data Collector 1.3 ',38), 10 0],'char'); fwrite(fid,[truncateOrFillBlanks(immigrant.recTime,38), 10 0],'char'); fwrite(fid,[truncateOrFillBlanks(['PTS: ' num2str(numDataPoints) ' COLS: ' num2str(numDataColumns)],38), 10 0],'char'); fwrite(fid,[truncateOrFillBlanks('UNKNOWN.DET',38), 10 0],'char'); fwrite(fid,[truncateOrFillBlanks('UNKNOWN.RGN',38), 10 0],'char'); fwrite(fid,[truncateOrFillBlanks(immigrant.beamline,78), 10 0],'char'); fwrite(fid,[truncateOrFillBlanks(' ',38), 10 0],'char'); for n=1:6, fwrite(fid,[truncateOrFillBlanks(immigrant.comments{n},78), 10 0], 'char'); end % 2. NCOL*8 bytes of float (channel offsets and weightings) fwrite(fid,immigrant.offsets,'float'); fwrite(fid,ones(numDataColumns,1),'float'); % 3. NCOL*20 bytes of char (column labels) for n=1:length(immigrant.labels) fwrite(fid,[truncateOrFillBlanks(immigrant.labels{n},18), 10 0],'char'); end % 4. 4 bytes of integer (numbers of energy points) fwrite(fid,numDataPoints,'int'); % 5. 12 bytes of mysterious char fwrite(fid,[8 0 1 0 33 71 24 40 -117 68 11 0],'char'); % 6. NCOL*NPTS*4 bytes of floats (data) fwrite(fid,immigrant.data,'float'); fclose(fid); return %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function textString=truncateOrFillBlanks(textString,maxLengthOfString) lengthOfString=length(textString); if lengthOfString > maxLengthOfString, textString=textString(1:maxLengthOfString); else textString=[textString repmat(' ',1,maxLengthOfString-lengthOfString)]; end return