HPS-MC
 
Loading...
Searching...
No Matches
split.cc
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3#include <stdhep_mcfio.h>
4#include <stdhep.h>
5#include <string.h>
6
10int main(int argc, char** argv)
11{
12 char outputname[200];
13 if (argc != 4)
14 {
15 printf("<input stdhep filename> <output stdhep basename> <number of events per file>\n");
16 return 1;
17 }
18 int n_events = atoi(argv[3]);
19 printf("Reading %d events from %s\n", n_events, argv[1]);
20 int istream = 0;
21 int ostream = 1;
22 int ilbl;
23 StdHepXdrReadInit(argv[1], n_events, istream);
24 int j = 1;
25
26 while (true) {
27 sprintf(outputname, "%s_%d.stdhep", argv[2], j);
28 printf("Writing to %s\n", outputname);
29 StdHepXdrWriteOpen(outputname, outputname, n_events, ostream);
30 StdHepXdrWrite(100, ostream);
31
32 for (int i = 0; i < n_events; i++)
33 {
34 do {
35 if (StdHepXdrRead(&ilbl, istream) != 0) {
36 printf("End of file\n");
37 printf("Last output file contains %d events\n", n_events);
38 StdHepXdrEnd(istream);
39 StdHepXdrWrite(200, ostream);
40 StdHepXdrEnd(ostream);
41 return(0);
42 }
43 if (ilbl != 1)
44 printf("ilbl = %d\n", ilbl);
45 } while (ilbl != 1);
46 StdHepXdrWrite(ilbl ,ostream);
47 }
48 StdHepXdrWrite(200, ostream);
49 StdHepXdrEnd(ostream);
50 j++;
51 }
52}
int main(int argc, char **argv)
Definition split.cc:10
int StdHepXdrReadInit(char *filename, int ntries, int ist)
int StdHepXdrWrite(int ilbl, int ist)
int StdHepXdrRead(int *ilbl, int ist)
void StdHepXdrEnd(int ist)
int StdHepXdrWriteOpen(char *filename, char *title, int ntries, int ist)