title: Compile-time defined storage order in Fortran using C++ preprocessor
body: <p>I would like get a flexible (compile time defined) storage order in Fortran 90. For this I'm trying to use a C++ preprocessor including some boost pp headers. </p>
  
  <p>So, for example, instead of accessing a 3D-array like this: </p>
  
  <pre><code>myArray(k,i,j)
  </code></pre>
  
  <p>I'd like to have this: </p>
  
  <pre><code>myArray(POINT3D(i,j,k))
  </code></pre>
  
  <p>and determine the order of accesses at compile time. </p>
  
  <p>Now what I've tried: </p>
  
  <pre><code>#include "boost_pp_cat.hpp"
  #include "boost_pp_comma.hpp"
  
  ! ------ Define storage orders here --------- !
  !Forward lookup {i,j,k} &lt;- {1,2,3}
  #define KIJ_ORDER_ARG1 k
  #define KIJ_ORDER_ARG2 i
  #define KIJ_ORDER_ARG3 j
  
  ! ------ Switch between storage orders ------ !
  #define CURR_ORDER KIJ_ORDER
  
  ! ------ Generate all required macros ------- !
  #define STOR_ORDER_ARG(storOrder, argNum) BOOST_PP_CAT(BOOST_PP_CAT(storOrder, _ARG), argNum)
  
  #define CHOOSE_PARAM(storOrder, argNum) BOOST_PP_CAT(STOR_ORDER_ARG(storOrder, argNum), Param)
  
  #define POINT3D(iParam, jParam, kParam) POINT3D_WITH_STORORDER(CURR_ORDER, iParam, jParam, kParam)
  
  #define POINT3D_WITH_STORORDER(storOrder, iParam, jParam, kParam)     POINT3D_WITH_STORORDER_PRE(storOrder) 
  #define POINT3D_WITH_STORORDER_PRE(storOrder) CHOOSE_PARAM(storOrder, 1), CHOOSE_PARAM(storOrder, 2), CHOOSE_PARAM(storOrder, 3)
  </code></pre>
  
  <p>This will expand</p>
  
  <pre><code>myArray(POINT3D(i,j,k))
  </code></pre>
  
  <p>to</p>
  
  <pre><code>myArray(kParam, iParam, jParam)
  </code></pre>
  
  <p>.</p>
  
  <p>Almost there! Now my question: </p>
  
  <ol>
  <li>Is it possible to do what I want using a C preprocessor?</li>
  <li>If not - what technique would you use? (I'm thinking about making my own specialized "preprocessor" python script, but do you have another suggestion?)</li>
  </ol>