<div dir="ltr"><div>Hi,<br></div><div>I managed to write a macro to determine the largest available Fortran integer kind so that it can be #defined at compile time where needed--via compiler supplied preprocessors or the cpp. The macro I wrote needs some more refinement/abstraction, but the basic technique is there. I am sharing it here in the event that someone might find it useful. Others' suggestions proved very helpful in implementing this, particularly <span name="Yngve Inntjore Levinsen" class="">Yngve Inntjore Levinsen's suggestions. My solution relies on more guarantees by the standard, and I feel it is more portable, so long as one has an F95 conforming compiler. (Virtually all compilers released in the past decade are F95 conforming.) Here is my macro:<br>
<br></span><span name="Yngve Inntjore Levinsen" class="">macro(Fortran_biggest_int)<br> message(STATUS "Checking for the largest available Fortran integer..")<br> set(filename ${CMAKE_BINARY_DIR}/getbigint.f90)<br>
file(WRITE ${filename} "program getbigint\n")<br> file(APPEND ${filename} " implicit none\n")<br> file(APPEND ${filename} " integer ,parameter :: DEFAULT = kind(1) , DEF_RANGE = range(kind(1))\n")<br>
file(APPEND ${filename} " integer :: r, ktmp, k\n")<br> file(APPEND ${filename} " r = DEF_RANGE\n")<br> file(APPEND ${filename} " k = DEFAULT\n")<br> file(APPEND ${filename} " do\n")<br>
file(APPEND ${filename} " r = r + 1\n")<br> file(APPEND ${filename} " ktmp = selected_int_kind(r)\n")<br> file(APPEND ${filename} " if ( ktmp == -1 ) exit\n")<br> file(APPEND ${filename} " k = ktmp\n")<br>
file(APPEND ${filename} " end do\n")<br> file(APPEND ${filename} " write(*,'(i0)') k\n")<br> file(APPEND ${filename} "end program\n")<br> try_run(BIG_INT_COMPILES BIG_INT_RUNS<br>
${CMAKE_BINARY_DIR} ${filename}<br> RUN_OUTPUT_VARIABLE FBIGINT)<br> message(STATUS "Fortran big integer kind: ${FBIGINT}")<br>endmacro()<br><br><br></span></div><div><div><div>Izaak Beekman<br>===================================<br>
(301)244-9367<br>Princeton University Doctoral Candidate<br>Mechanical and Aerospace Engineering<br><a href="mailto:ibeekman@princeton.edu" target="_blank">ibeekman@princeton.edu</a><br><br>UMD-CP Visiting Graduate Student<br>
Aerospace Engineering<br><a href="mailto:ibeekman@umiacs.umd.edu" target="_blank">ibeekman@umiacs.umd.edu</a><br><a href="mailto:ibeekman@umd.edu" target="_blank">ibeekman@umd.edu</a></div>
</div></div></div>