home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / GRAPHICS.DI$ / SWAPPREV.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  1.9 KB  |  83 lines

  1. function swapprev( filename, filenamei )
  2. %SWAPPREV Merge EPSI and EPS files.
  3. %    Used to extract the preview bitmap from an EPSI file and
  4. %    mate it with the Setup and script from an EPS file. Needed to
  5. %    fix a bug with MATLAB v4.0 and v4.0a.
  6. %
  7. %    See also 8 Febuary 93 version of PRINT
  8.  
  9. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  10.  
  11. if nargin < 2
  12.     error('Filenames required.')
  13. end
  14.  
  15. % Need to read information from the EPSI version.
  16. fepsi = fopen( filenamei, 'r' );
  17.  
  18. %
  19. % Read till beginning of preview, keep track of how many lines read.
  20. %
  21. s = [];
  22. lineNo = 0;
  23.  
  24. while ~strcmp( s, '%%EndComments' ) & s ~= -1
  25.     s = fgetl( fepsi );
  26.     lineNo = lineNo + 1;
  27. end    
  28.  
  29. %
  30. % If reached end of file, error out.
  31. %
  32. if s == -1
  33.     fclose( fepsi );
  34.     error(['Unexpected End of File condition, line ' int2str( lineNo )])
  35. end
  36.  
  37. %
  38. % Every MATLAB EPS file, with or without preview, has the same size header.
  39. %
  40. headCount = lineNo;
  41.  
  42. %
  43. % Get the BeginPreview line, find out how many lines of 
  44. % preview data there are.
  45. %
  46. s = fgetl( fepsi );
  47. lineNo = lineNo + 1;
  48. blanks = find( s == ' ' );
  49. numDataLines = str2num( s( blanks(length(blanks)) : length(s) ) );
  50.  
  51. %
  52. % Total lines we want from EPSI file includes header, Preview comments,
  53. % and data.
  54. %
  55. linesFromI = lineNo + numDataLines + 1;
  56.  
  57. %
  58. % Put header and preview in temporary file
  59. %
  60. headerFile = tempname;
  61. fclose( fepsi );
  62. [s,r] = unix(['head -' int2str(linesFromI) ' ' filenamei ' > ' headerFile]);
  63. if s ~= 0
  64.     error('Problem with head command.')
  65. end
  66.  
  67. %
  68. % Skip the header and store just the script from the EPS file temporarily.
  69. %
  70. [s,r] = unix( [ '\tail +' int2str(headCount+1) ' ' filename ' >> ' headerFile ] );
  71. if s ~= 0
  72.     error('Problem with tail command.')
  73. end
  74.  
  75. %
  76. % Finally, move it back to the original filename.
  77. %
  78. [s,r] = unix( [ '\mv ' headerFile ' ' filename ] );
  79. if s ~= 0
  80.     error('Problem with mv command.')
  81. end
  82.  
  83.