title: Format statement with unknown columns
body: <p>I am attempting to use fortran to write out a comma-delimited file for import into another commercial package.  The issue is that I have an unknown number of data columns.  My output needs to look like this:</p>
  
  <pre><code>a_string,a_float,a_different_float,float_array_elem1,float_array_elem2,...,float_array_elemn
  </code></pre>
  
  <p>which would result in something that might look like this:</p>
  
  <pre><code>L1080,546876.23,4325678.21,300.2,150.125,...,0.125
  L1090,563245.1,2356345.21,27.1245,...,0.00983
  </code></pre>
  
  <p>I have three issues.  One, I would prefer the elements to be tightly grouped (variable column width), two, I do not know how to define a variable number of array elements in the format statement, and three, the array elements can span a large range--maybe 12 orders of magnitude.  The following code conceptually does what I want, but the variable 'n' and the lack of column-width definition throws an error (of course):</p>
  
  <pre><code>WRITE(50,900) linenames(ii),loc(ii,1:2),recon(ii,1:n)
  900 FORMAT(A,',',F,',',F,n(',',F))
  </code></pre>
  
  <p>(I should note that n is fixed at run-time.)  The write statement does what I want it to when I do WRITE(50,*), except that it's width-delimited.</p>
  
  <p>I think this thread almost answered my question, but I got quite confused: <a href="https://stackoverflow.com/questions/2751453/matlabs-fortrans-format-equivalents/2751615#2751615">SO</a>.  Right now I have a shell script with awk fixing the issue, but that solution is...inelegant.  I could do some manipulation to make the output a string, and then just write it, but I would rather like to avoid that option if at all possible.</p>
  
  <p>I'm doing this in Fortran 90 but I like to try to keep my code as backwards-compatible as possible.</p>