Advertisement
Francoo

Ocean Optics *.ProcSpec Spectrum Extrator/Plotter Script

Nov 27th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.78 KB | None | 0 0
  1. %Gets the processed spectrum of a ProcSpec file.
  2.  
  3. files=ls('*.ProcSpec'); %Lists every *.ProcSpec file
  4.  
  5. if size(files,1) == 0
  6.     error('No *.ProcSpec file found!')
  7. end
  8.  
  9. numOfFiles=size(files,1);
  10.  
  11. specx=cell(numOfFiles,1); %Cells array with the x/y data for every file.
  12. specy=cell(numOfFiles,1);
  13.  
  14. for fnum = 1:numOfFiles
  15.  
  16. % ####################################################################################
  17. % Unzipping, converting and reading files:
  18.  
  19. unzip(files(fnum,:),'temp'); %Unzips the ProcSpec file.
  20.  
  21. oldEncoding=slCharacterEncoding(); %Converting the file to UTF-8.
  22. slCharacterEncoding('UTF-8');
  23. fname_raw=ls('temp\ps_*.xml');
  24. fid=fopen(['temp\' fname_raw]);
  25. nfid=fopen('temp\rawxml.xml','a','n','UTF-8');
  26. rawXML=fscanf(fid,'%c');
  27. fprintf(nfid,'%c',rawXML);
  28. fclose(fid);
  29. fclose(nfid);
  30. slCharacterEncoding(oldEncoding);
  31.  
  32. xfile=xmlread('temp\rawxml.xml'); %Loads the XML file.
  33.  
  34. try %Deletes temporary files, remove the folder if possible.
  35.     delete('temp\OOIVersion.txt','temp\OOISignatures.xml',['temp\' fname_raw],'temp\rawxml.xml');
  36.     rmdir('temp');
  37. end
  38.  
  39.  
  40. % ####################################################################################
  41. %Obtaining the spectrum channels (X axis):
  42.  
  43. x_xmlval=xfile.getElementsByTagName('channelWavelengths');
  44.  
  45. for n = 0:x_xmlval.getLength-1 %Detecting corrrect element for channelWavelenths
  46.     if x_xmlval.item(n).getLength/2-1/2 > 100
  47.         specx{fnum}=zeros(1,x_xmlval.item(n).getLength/2-1/2);
  48.         break
  49.     end
  50. end
  51. if x_xmlval.item(n).getLength/2-1/2 < 100
  52.     error('XML File doesn''t seems ok... channelWavelengths size doesn''t fits!')
  53. end
  54.  
  55. specx{fnum}=str2num(x_xmlval.item(n).getTextContent)'; %Gets the data
  56.  
  57. % ####################################################################################
  58. %Obtaining the absorvance data (Y axis):
  59.  
  60. y_xmlval=xfile.getElementsByTagName('processedPixels');
  61.  
  62. for n = 0:y_xmlval.getLength-1 %Detecting corrrect item for processedPixels
  63.     if y_xmlval.item(n).getLength/2-1/2 > 100
  64.         specy{fnum}=zeros(1,y_xmlval.item(n).getLength/2-1/2);
  65.         break
  66.     end
  67. end
  68. if y_xmlval.item(n).getLength/2-1/2 < 100
  69.     error('XML File doesn''t seems ok... processedPixels size doesn''t fits!')
  70. end
  71.  
  72. if size(specy{fnum},2) ~= size(specx{fnum},2) %Checks if both sizes are equal.
  73.     error('channelWavelengths and processedPixels sizes doesn''t match!')
  74. end
  75.  
  76. specy{fnum}=str2num(y_xmlval.item(n).getTextContent)'; %Gets the data
  77.  
  78. % ####################################################################################
  79.  
  80. disp([ num2str(fnum) '/' num2str(numOfFiles) ' - ' deblank(files(fnum,:)) ' done...' ]);
  81.  
  82. end
  83.  
  84. clear fid fname_raw fnum i k n nfid numOfFiles rawXML x_xmlval xfile y_xmlval ans oldEncoding
  85.  
  86. pHandle=plot(cell2mat(specx)',cell2mat(specy)'); %Plotting
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement