title: Writing To a Binary File
body: <p>I am attempting to write an STL Binary file in Fortran 90. The file has the following format</p>
  
  <blockquote>
    <p>HEADER: An 80 byte ASCII header - TITLE</p>
    
    <p>A 4 byte unsigned long integer, NO. OF FACETS</p>
    
    <p>FORMAT FOR EACH FACET:</p>
    
    <p>Normal vector, 3 floating values of 4 bytes each;</p>
    
    <p>Vertex 1 XYZ coordinates, 3 floating values of 4 bytes each;</p>
    
    <p>Vertex 2 XYZ coordinates, 3 floating values of 4 bytes each;</p>
    
    <p>Vertex 3 XYZ coordinates, 3 floating values of 4 bytes each;</p>
    
    <p>An unsigned integer, of 2 bytes, that should be zero;</p>
  </blockquote>
  
  <p>I am attempting to create an unformatted file for writing the relevant information but am having trouble defining the correct record length. Assuming that I have N facets, I am using the following commands to open and write information</p>
  
  <pre><code>open(unit = 1, status = 'replace', iostat = ioerror, format = 'unformatted', access = 'direct', recl = 84 + N * 50, file = 'c:\temp\test.stl')
  </code></pre>
  
  <p>Can I issue the first write statement to write out the header information followed by the second write statement (within a do loop) to write out the facet information?</p>
  
  <p>If so, what would be the record number I need to have for each of the write statements since I have the header and the facet information with different record lengths.</p>
  
  <pre><code>write(1,rec=?), *header information*
  do,i=1,N,1
     write(1,rec=?), *facet information*
  enddo
  </code></pre>