next up previous contents
Next: Summary of FORTRAN routines Up: ndf access routines Previous: Example of FORTRAN usage   Contents

Example of C usage

The following C example demonstrates how to open a file and loop through all the targets to print out their ZA, mass and the total cross-section for each reaction type.

#include <stdio.h>
#include <ndf.h> 

main( ) {

    int yi = 1, iZA, nZAs, *ZAs, i;
    int ncg, gid = 93, fid = 0, iC, nC, C, *CList;
    double cgb[250], cs[250], Q;         /* 250 should be large enough. */
    char name[5], Path[256];
    CorrectionTypes tcType = endf_LLNL;  /* LLNL transport correction. */

    printf( "\nOpening ndf file ndf%d with date = %d\n", 
             yi, ndfcopen( yi, name ) );
    ndfcinfo( Path, sizeof( Path ) );
    printf( "Path = %s\n", Path );
    ndfctrcorr( tc_Type );               /* Set the transport correction method. */
    ncg = ndfcidog( gid, cgb );          /* Get group from bdfls file. */
    ndfcgroup( ncg, cgb, fid );          /* Set collapsing. */

    nZAs = ndfcistab( &ZAs );            /* Get list of targets. */
    for( iZA = 0; iZA < nZAs; iZA++ ) {  /* Loop over target list. */
        ndfciso( ZAs[iZA] );             /* Select next target. */
        printf( "\nProcessing ZA = %d.  Mass = %e AMU.\n", 
                ZAs[iZA], ndfcatw( ) );
        nC = ndfcreact( &CList ); /* Get list of reactions for current target. */
        C = -1;
        for( iC = 0; iC < nC; iC++ ) {   /* Loop over reactions. */
           if( C != CList[iC] ) {        /* Do only if different C-value. */
              C = CList[iC];
              Q = ndfcrxs( C, 0, cs );   /* Total cross-section for reaction C. */
              printf( "C = %2d  Q = %e\n", C, Q );
              for( i = 0; i < ncg; i++ ) {
                  printf( "%18.10e\n", cs[i] );
              }
           }
        }
    }
    ndfcclose( );                        /* Close the ndf file. */
}