File: rawexample_readmcpl.c

package info (click to toggle)
mcpl 1.3.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,336 kB
  • sloc: ansic: 69,469; python: 2,689; cpp: 408; makefile: 40
file content (51 lines) | stat: -rw-r--r-- 1,863 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

///////////////////////////////////////////////////////////////////////////////////
//                                                                               //
// A small standalone example of how to one might read particles from an MCPL    //
// file into a given programme.                                                  //
//                                                                               //
// This file can be freely used as per the terms in the LICENSE file.            //
//                                                                               //
// Written 2015-2016 by Thomas.Kittelmann@esss.se                                //
//                                                                               //
///////////////////////////////////////////////////////////////////////////////////

#include "mcpl.h"
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

int main(int argc,char**argv) {

  if (argc!=2) {
    printf("Please supply input filename\n");
    return 1;
  }

  const char * filename = argv[1];

  //Open the file:
  mcpl_file_t f = mcpl_open_file(filename);

  //For fun, access and print a bit of the info found in the header (see mcpl.h for more):

  printf("Opened MCPL file produced with %s\n",mcpl_hdr_srcname(f));
  unsigned i;
  for (i = 0; i < mcpl_hdr_ncomments(f); ++i)
    printf("file had comment: '%s'\n",mcpl_hdr_comment(f,i));
  printf("File contains %llu particles\n",(unsigned long long)mcpl_hdr_nparticles(f));

  //Now, loop over particles and print some info:

  const mcpl_particle_t* p;
  while ( ( p = mcpl_read(f) ) ) {

    //print some info (see the mcpl_particle_t struct in mcpl.h for more fields):
    printf("  found particle with pdgcode %i and time-stamp %g ms with weight %g\n",
           p->pdgcode, p->time, p->weight);


  }

  mcpl_close_file(f);
}