title: Fortran equivalent of the MATLAB meshgrid function?
body: <p>Is there a <code>meshgrid</code> equivalent in Fortran? </p>
  
  <p>This is the Matlab code which I am trying to re-write in Fortran: </p>
  
  <pre><code>n = a;  %same in fortran
  m = n*(n-1)/2; %same in fortran 
  offdiags = dec2bin(0:2^m-1,m)-48; % found a subroutine online
  A = zeros(n,n,2^m); %multi-dimensional array same concept in fortran
  
  [ind_i,ind_j,ind_k] = meshgrid(1:n,1:n,1:2^m); % ?
  A(ind_i&gt;ind_j) = offdiags.'; 
  
  A = A + permute(A,[2 1 3]); 
  </code></pre>
  
  <p>This code is intended to generate all the possible adjacency matrices (or graph configurations with undirected edges) with $n$ vertices. The number of such configurations is exactly $2^{n(n-1)/2}$. They can be generated by "hand" in a loop or simply by using the above code kindly suggested on stackoverflow. </p>
  
  <p>For n=3, meshgrid is used in this code to generate 3D coordinate arrays ind_i, ind_j and ind_z which have 3 lines (length(1:3)) , 3 columns (length(1:3)) and 8 pages (length(1:1:2^m)) and they contain copies of the vectors specified in the grid. In my case, let $L=[1,2,3]$. Then I get for i from 1 to 8, $ind_i(:,:,i)=[L;L;L]$, $ind_j(:,:,i)=[ones(1,3);2*ones(1,3);3*ones(1,3)]$ and $ind_k(:,:,i)=i*ones(3)$.</p>
  
  <blockquote>
    <p>Matlab description copied from their site: [X,Y,Z] = meshgrid(xgv,ygv,zgv) produces three-dimensional coordinate arrays. The output coordinate arrays X, Y, and Z contain copies of the grid vectors xgv, ygv, and zgv respectively. The sizes of the output arrays are determined by the length of the grid vectors. For grid vectors xgv, ygv, and zgv of length M, N, and P respectively, X, Y, and Z will have N rows, M columns, and P pages.</p>
  </blockquote>