24.05.2014 Views

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

A Sample dbx Session <strong>for</strong> an <strong>XL</strong> <strong>Fortran</strong> Program<br />

You can debug <strong>XL</strong> <strong>Fortran</strong> programs with any dbx-compatible symbolic debugger.<br />

For background in<strong>for</strong>mation on dbx, see the <strong>AIX</strong> General Concepts and Procedures<br />

document . For in<strong>for</strong>mation on dbx subcommands, see the <strong>AIX</strong> Commands<br />

Reference.<br />

The following example represents a typical <strong>XL</strong> <strong>Fortran</strong> problem that you may be<br />

able to resolve through dbx. Although it demonstrates only a small subset of dbx<br />

features and uses memory-allocation techniques made obsolete by <strong>Fortran</strong><br />

90/<strong>Fortran</strong> 95 allocatable arrays, it can serve as an introduction if you have not<br />

used this debugger be<strong>for</strong>e.<br />

Problem with Dynamic Memory Allocation<br />

The following program tries to allocate an array at run time by using the <strong>AIX</strong><br />

system subroutine malloc. When you use the following command to compile the<br />

program and then run the program, the program produces a core dump:<br />

xlf95 -qddim testprog.f -o testprog<br />

At this point, you may be wondering whether the C malloc routine is working<br />

correctly or whether this is the right way to allocate an array in a main program<br />

when the dimensions are not known until run time.<br />

program main<br />

pointer(p, array(nvar,nrec))<br />

real*8 array<br />

nvar = 2<br />

nrec = 3<br />

p = malloc(nvar*nrec*8)<br />

call test_sub(array, nvar, nrec)<br />

end<br />

subroutine test_sub(array, nvar, nrec)<br />

dimension array(nvar, nrec)<br />

array(1,1) = 1.<br />

array(2,1) = 2.<br />

array(1,2) = 3.<br />

array(2,2) = 4.<br />

array(1,3) = 5.<br />

array(2,3) = 6.<br />

write(*, 100) array(1,1), array(2,1), array(1,2),<br />

1 array(2,2), array(1,3), array(2,3)<br />

100 <strong>for</strong>mat(//t2,f4.1/t2,f4.1/t2,f4.1/t2,f4.1/<br />

1 t2,f4.1/t2,f4.1)<br />

return<br />

end<br />

You might go through the debugging process as follows:<br />

1. Compile the program with the -g option, to allow debugging under dbx:<br />

Problem Determination and Debugging 377

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!