Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %Gets the processed spectrum of a ProcSpec file.
- files=ls('*.ProcSpec'); %Lists every *.ProcSpec file
- if size(files,1) == 0
- error('No *.ProcSpec file found!')
- end
- numOfFiles=size(files,1);
- specx=cell(numOfFiles,1); %Cells array with the x/y data for every file.
- specy=cell(numOfFiles,1);
- for fnum = 1:numOfFiles
- % ####################################################################################
- % Unzipping, converting and reading files:
- unzip(files(fnum,:),'temp'); %Unzips the ProcSpec file.
- oldEncoding=slCharacterEncoding(); %Converting the file to UTF-8.
- slCharacterEncoding('UTF-8');
- fname_raw=ls('temp\ps_*.xml');
- fid=fopen(['temp\' fname_raw]);
- nfid=fopen('temp\rawxml.xml','a','n','UTF-8');
- rawXML=fscanf(fid,'%c');
- fprintf(nfid,'%c',rawXML);
- fclose(fid);
- fclose(nfid);
- slCharacterEncoding(oldEncoding);
- xfile=xmlread('temp\rawxml.xml'); %Loads the XML file.
- try %Deletes temporary files, remove the folder if possible.
- delete('temp\OOIVersion.txt','temp\OOISignatures.xml',['temp\' fname_raw],'temp\rawxml.xml');
- rmdir('temp');
- end
- % ####################################################################################
- %Obtaining the spectrum channels (X axis):
- x_xmlval=xfile.getElementsByTagName('channelWavelengths');
- for n = 0:x_xmlval.getLength-1 %Detecting corrrect element for channelWavelenths
- if x_xmlval.item(n).getLength/2-1/2 > 100
- specx{fnum}=zeros(1,x_xmlval.item(n).getLength/2-1/2);
- break
- end
- end
- if x_xmlval.item(n).getLength/2-1/2 < 100
- error('XML File doesn''t seems ok... channelWavelengths size doesn''t fits!')
- end
- specx{fnum}=str2num(x_xmlval.item(n).getTextContent)'; %Gets the data
- % ####################################################################################
- %Obtaining the absorvance data (Y axis):
- y_xmlval=xfile.getElementsByTagName('processedPixels');
- for n = 0:y_xmlval.getLength-1 %Detecting corrrect item for processedPixels
- if y_xmlval.item(n).getLength/2-1/2 > 100
- specy{fnum}=zeros(1,y_xmlval.item(n).getLength/2-1/2);
- break
- end
- end
- if y_xmlval.item(n).getLength/2-1/2 < 100
- error('XML File doesn''t seems ok... processedPixels size doesn''t fits!')
- end
- if size(specy{fnum},2) ~= size(specx{fnum},2) %Checks if both sizes are equal.
- error('channelWavelengths and processedPixels sizes doesn''t match!')
- end
- specy{fnum}=str2num(y_xmlval.item(n).getTextContent)'; %Gets the data
- % ####################################################################################
- disp([ num2str(fnum) '/' num2str(numOfFiles) ' - ' deblank(files(fnum,:)) ' done...' ]);
- end
- clear fid fname_raw fnum i k n nfid numOfFiles rawXML x_xmlval xfile y_xmlval ans oldEncoding
- pHandle=plot(cell2mat(specx)',cell2mat(specy)'); %Plotting
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement