Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use the preprocessor to print out the file name and line number. You might want take advantage of the predefined preprocessor symbols <code>__LINE__</code> and <code>__FILE__</code>. Here's an example:</p> <p>A preprocessor macro is defined in header file (so that it can be used in multiple locations), call it <strong>errormsg.h</strong>:</p> <pre><code>#define ERRORMSG(msg) write(0,'("There was an error at ",I4," in file ",/,A,/,"Error message: ",A)') __LINE__,__FILE__,msg </code></pre> <p>Then you can include this header file in your program, library or module files, for example:</p> <pre><code>#include "errormsg.h" program main ERRORMSG("not really an error...") call foo() end program subroutine foo() ERRORMSG("not an error too!") end subroutine </code></pre> <p>The <code>ERRORMSG("not really an error...")</code> seems like weird syntax for fortran code, but it get's replaced by the c-preprocessor using the macro definition. So when this is compiled, it looks like:</p> <pre><code>write(0,'("There was an error at ",I4," in file ",/,A,/,"Error message: ",A)') __LINE__,__FILE__,"not really an error" </code></pre> <p>For my <code>ERRORMSG</code> macro, I chose to use the 0 file unit to print to stderr. You obviously have the freedom to write the message how ever you like, as long as it results in syntactical correct FORTRAN code. </p> <p>Getting this to compile requires you to pass flags to the compiler, and they differ slightly from compiler to compiler. This worked for me, for example:</p> <pre><code>gfortran -cpp -o errorTest errorTest.f90 </code></pre> <p>That is, for gfortran, <code>-cpp</code> invokes the c-preprocessor before compiling. The output from the above program looks like this: </p> <pre><code>There was an error at 5 in file errorTest.f90 Error message: not really an error... There was an error at 13 in file errorTest.f90 Error message: not an error too! </code></pre> <p>This might have the effect you are looking for, especially if you write only one subroutine per file. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload