<font style="font-family: arial,helvetica,sans-serif;" size="2">From the Petsc-manual</font><span style="font-family: arial,helvetica,sans-serif;">:</span><br><div style="margin-left: 40px;"><font size="1"><br><font style="color: rgb(102, 102, 102);" size="2">The user should check the return codes for all PETSc routines (and possibly user-defined routines as well)<br>
with<br></font></font><div style="margin-left: 40px;"><font size="1"><font style="color: rgb(102, 102, 102);" size="2"><span style="font-family: courier new,monospace;">ierr = PetscRoutine(...);CHKERRQ(PetscErrorCode ierr);</span></font></font><br>
</div><font size="1"><font style="color: rgb(102, 102, 102);" size="2">Likewise, all memory allocations should be checked with<br></font></font><div style="margin-left: 40px;"><font size="1"><font style="color: rgb(102, 102, 102);" size="2"><span style="font-family: courier new,monospace;">ierr = PetscMalloc(n*sizeof(double),&amp;ptr);CHKERRQ(ierr);</span></font></font><br>
</div><font size="1"><font style="color: rgb(102, 102, 102);" size="2">If this procedure is followed throughout all of the user’s libraries and codes, any error will by default generate<br>a clean traceback of the location of the error.<br>
     Note that the macro __FUNCT__ is used to keep track of routine names during error tracebacks. Users<br>need not worry about this macro in their application codes; however, users can take advantage of this feature<br>
if desired by setting this macro before each user-defined routine that may call SETERRQ(), CHKERRQ().<br>A simple example of usage is given below.<br></font></font><div style="margin-left: 40px;"><font size="1"><font style="color: rgb(102, 102, 102);" size="2"><span style="font-family: courier new,monospace;">#undef FUNCT</span></font></font><br style="font-family: courier new,monospace;">
<font size="1"><font style="color: rgb(102, 102, 102);" size="2"><span style="font-family: courier new,monospace;">#define FUNCT ”MyRoutine1”</span></font></font><br style="font-family: courier new,monospace;"><font size="1"><font style="color: rgb(102, 102, 102);" size="2"><span style="font-family: courier new,monospace;">int MyRoutine1() {</span></font></font><br style="font-family: courier new,monospace;">
<font size="1"><font style="color: rgb(102, 102, 102);" size="2"><span style="font-family: courier new,monospace;">/* code here */</span></font></font><br style="font-family: courier new,monospace;"><font size="1"><font style="color: rgb(102, 102, 102);" size="2"><span style="font-family: courier new,monospace;">return 0;</span></font></font><br style="font-family: courier new,monospace;">
<font size="1"><font style="color: rgb(102, 102, 102);" size="2"><span style="font-family: courier new,monospace;">}</span></font></font><font size="1"><font style="color: rgb(102, 102, 102);" size="2"><span style="font-family: courier new,monospace;"><br>
<br></span></font></font></div></div><font style="font-family: arial,helvetica,sans-serif;" size="1"><font style="color: rgb(102, 102, 102);" size="2"><font color="#000000">My question is</font></font></font>, what is the correct way do this in Fortran? I have seen the following variant in an example (ex35f90), but I couldn&#39;t get it to work myself. Also, it&#39;s tedious to copy this macro every time you start a new project. <br>
<br style="font-family: courier new,monospace;"><div style="margin-left: 40px;"><span style="font-family: courier new,monospace; color: rgb(102, 102, 102);">!  Error handler forces traceback of where error occurred</span><span style="font-family: courier new,monospace; color: rgb(102, 102, 102);"></span><br style="font-family: courier new,monospace; color: rgb(102, 102, 102);">
<span style="font-family: courier new,monospace; color: rgb(102, 102, 102);">      subroutine HE2(ierr,line)</span><br style="font-family: courier new,monospace; color: rgb(102, 102, 102);"><span style="font-family: courier new,monospace; color: rgb(102, 102, 102);">      use mex35f90</span><br style="font-family: courier new,monospace; color: rgb(102, 102, 102);">
<span style="font-family: courier new,monospace; color: rgb(102, 102, 102);">      use mex35f90interfaces</span><br style="font-family: courier new,monospace; color: rgb(102, 102, 102);"><br style="font-family: courier new,monospace; color: rgb(102, 102, 102);">
<span style="font-family: courier new,monospace; color: rgb(102, 102, 102);">      call PetscError(ierr,line,0,&#39;&#39;,ierr)</span><br style="font-family: courier new,monospace; color: rgb(102, 102, 102);"><span style="font-family: courier new,monospace; color: rgb(102, 102, 102);">      return</span><br style="font-family: courier new,monospace; color: rgb(102, 102, 102);">
<span style="font-family: courier new,monospace; color: rgb(102, 102, 102);">      end      </span><br style="font-family: courier new,monospace; color: rgb(102, 102, 102);"><span style="font-family: courier new,monospace; color: rgb(102, 102, 102);">#define CHKR(n) if(n .ne. 0)then;call HE2(n,__LINE__);return;endif</span><br>
<br></div>Thanks in advance.<br><br>Leo van Kampenhout<br>