source: trunk/MagicSoft/Simulation/Corsika/Mmcs/jcio.c@ 770

Last change on this file since 770 was 687, checked in by harald, 24 years ago
Changes of Ciro and Dennis to write all events of one run in only one file. Be careful, from now on you need also a new reflector.
File size: 8.2 KB
Line 
1/*----------------------------------------------------------------------
2 jcio.c :
3
4Rutinas para la gestion de ficheros en CORSIKA 5.20
5Author J.C.Gonzalez
6
7Las posibilidades que contempla son:
8
9- Creacion de un fichero de inicio de run: run######
10- Creacion de un fichero de fin de run: end######
11- Creacion de fichero separados para cada cascada, tanto para
12 particulas como para Cherenkov. Ademas, para la salida Cherenkov se
13 genera en ficheros separados en caso de que se reutilice la cascada.
14 Los fichero son por tanto: cer######.# y dat######, donde el indice
15 del fichero cer va de 0 a 9.
16- La grabacion se realiza en C, por lo que no existen marcas de inicio
17 ni final de bloque en los ficheros.
18
19Modified by C.Bigongiari 2000 Dec 19.
20No more RUN###### and END###### files created.
21Three files, CER######, DAT###### and STA###### files, per run instead
22of three files per shower.
23Now ###### is the RUN NUMBER not the shower number !!!
24----------------------------------------------------------------------*/
25
26#include <stdio.h>
27#include <stdlib.h>
28
29#define MAXBUF 273 /*- 39*7 -*/
30#define NSUBBL 21
31#define NPLONG 1041
32
33static int nshow = 0;
34static float timefirst = 0.;
35static float timelast = 0.;
36
37FILE *cetape;
38FILE *patape;
39FILE *sttape;
40/* CBC
41FILE *runtape;
42FILE *endtape;
43CBC*/
44char tpl[100];
45char certpl[100];
46char dattpl[100];
47/* CBC char statpl[100]; */
48char cerfile[100];
49char datfile[100];
50/* CBC
51char stafile[100];
52char runfile[100];
53char endfile[100];
54CBC */
55
56/*--------------------------------------------------
57 jcinitio:
58
59Define file names
60--------------------------------------------------*/
61#ifdef JC_UNDERSCORES
62void
63jcinitio_ (char *path, int *runnum)
64#else /* JC_NO_UNDERSCORES */
65void
66jcinitio (char *path, int *runnum)
67#endif /* JC_UNDERSCORES */
68{
69 register int i = 0;
70
71 while (*(path + (++i)) != ' ');
72 strncpy (tpl, path, i);
73 if (*(path + i - 1) != '/')
74 strcat (tpl, "/");
75
76 strcpy (certpl, tpl);
77 strcat (certpl, "cer%06d");
78 strcpy (dattpl, tpl);
79 strcat (dattpl, "dat%06d");
80 /* CBC
81 strcpy (statpl, tpl);
82 strcat (statpl, "sta%06d");
83 */
84 /* CBC
85 sprintf (runfile, "%srun%06d", tpl, *runnum);
86 sprintf (endfile, "%send%06d", tpl, *runnum);
87 CBC */
88
89 sprintf (cerfile, certpl, *runnum); /* Added by CB */
90 sprintf (datfile, dattpl, *runnum); /* Added by CB */
91}
92
93/*--------------------------------------------------
94 jcdatsave:
95 graba un bloque al fichero de particulas
96--------------------------------------------------*/
97#ifdef JC_UNDERSCORES
98void
99jcdatsave_ (float *outbuf)
100#else /* JC_NO_UNDERSCORES */
101void
102jcdatsave (float *outbuf)
103#endif /* JC_UNDERSCORES */
104{
105 /* puts("JCIO:: saving particle buffer..."); */
106 fwrite (outbuf, sizeof (float) * MAXBUF * NSUBBL, 1, patape);
107}
108
109/*--------------------------------------------------
110 jccersave:
111 graba un bloque al fichero de particulas
112--------------------------------------------------*/
113#ifdef JC_UNDERSCORES
114void
115jccersave_ (float *outbuf)
116#else /* JC_NO_UNDERSCORES */
117void
118jccersave (float *outbuf)
119#endif /* JC_UNDERSCORES */
120{
121 /* puts("JCIO:: saving cerenkov buffer..."); */
122 fwrite (outbuf, sizeof (float) * MAXBUF * NSUBBL, 1, cetape);
123}
124
125/*--------------------------------------------------
126 jcstartrun:
127 abre el fichero run###### y graba el contenido
128
129NOW open CER and DAT files
130--------------------------------------------------*/
131#ifdef JC_UNDERSCORES
132void
133jcstartrun_ (void)
134#else /* JC_NO_UNDERSCORES */
135void
136jcstartrun (void)
137#endif /* JC_UNDERSCORES */
138{
139 /* CBC
140
141 if ((runtape = fopen (runfile, "wb")) == NULL) {
142 printf ("JCIO:: Cannot open RUN file %s. Exiting.\n", runfile);
143 exit (1);
144 }
145 CBC */
146
147 /* puts("JCIO:: saving runheader buffer..."); */
148
149 /* CBC
150 fwrite (runh, sizeof (float) * MAXBUF, 1, runtape);
151
152 CBC */
153
154 /* Following lines up to CBC added by CB */
155
156
157 if ((cetape = fopen (cerfile, "wb")) == NULL) {
158 printf ("JCIO:: Cannot open CER file %s. Exiting.\n", cerfile);
159 exit (1);
160 }
161 if ((patape = fopen (datfile, "wb")) == NULL) {
162 printf ("JCIO:: Cannot open DAT file %s. Exiting.\n", datfile);
163 exit (1);
164 }
165
166 /* CBC */
167}
168
169/* WHAT FOLLOWS IS NO MORE USED !!!!!! CB */
170
171/*--------------------------------------------------
172 jcstartshower:
173
174Function added by CB
175Sets timefirst and timelast variables to their initial value at the beginnng
176of new shower
177--------------------------------------------------*/
178#ifdef JC_UNDERSCORES
179void
180jcstartshower_ (float *evth)
181#else /* JC_NO_UNDERSCORES */
182void
183jcstartshower (float *evth)
184#endif /* JC_UNDERSCORES */
185{
186 timefirst = 9.0e10;
187 timelast = -9.0e10;
188}
189
190
191/*--------------------------------------------------
192 jctime:
193 va echando cuentas del tiempo de los fotones
194--------------------------------------------------*/
195#ifdef JC_UNDERSCORES
196void
197jctime_ (float *cartim)
198#else /* JC_NO_UNDERSCORES */
199void
200jctime (float *cartim)
201#endif /* JC_UNDERSCORES */
202{
203 if (*cartim>timelast) timelast = *cartim;
204 if (*cartim<timefirst) timefirst = *cartim;
205}
206
207/*--------------------------------------------------
208 jcstadata:
209 graba las estadisticas de la cascada
210--------------------------------------------------*/
211#ifdef JC_UNDERSCORES
212void
213jcstadata_ (float *evth, float *evte,
214 double *nproto, double *nprotb, double *nneutr,
215 double *nneutb, double *nphoto, double *nelect,
216 double *nposit, double *nnu, double *nmum,
217 double *nmup, double *npi0, double *npim, double *npip,
218 double *nk0l, double *nk0s, double *nkmi, double *nkpl,
219 double *nhyp, double *ndeut, double *ntrit, double *nalpha,
220 double *nother, int *ifinnu, int *ifinpi,
221 int *ifinet, int *ifinka, int *ifinhy,
222 double *cerele, double *cerhad,
223 double *plong, int *lpct1, int *nstep, double *thstep)
224#else /* JC_NO_UNDERSCORES */
225void
226jcstadata (float *evth, float *evte,
227 double *nproto, double *nprotb, double *nneutr,
228 double *nneutb, double *nphoto, double *nelect,
229 double *nposit, double *nnu, double *nmum,
230 double *nmup, double *npi0, double *npim, double *npip,
231 double *nk0l, double *nk0s, double *nkmi, double *nkpl,
232 double *nhyp, double *ndeut, double *ntrit, double *nalpha,
233 double *nother, int *ifinnu, int *ifinpi,
234 int *ifinet, int *ifinka, int *ifinhy,
235 double *cerele, double *cerhad,
236 double *plong, int *lpct1, int *nstep, double *thstep)
237#endif /* JC_UNDERSCORES */
238{
239 register int i, ii, k;
240 int np[22];
241 float f;
242
243 fwrite (evth, sizeof (float) * MAXBUF, 1, sttape);
244 fwrite (evte, sizeof (float) * MAXBUF, 1, sttape);
245
246 fwrite (&timefirst, sizeof (float), 1, sttape);
247 fwrite (&timelast, sizeof (float), 1, sttape);
248
249 for (i = 0; i < 10; i++) {
250 np[0] = (int) (*(nproto + i));
251 np[1] = (int) (*(nprotb + i));
252 np[2] = (int) (*(nneutr + i));
253 np[3] = (int) (*(nneutb + i));
254 np[4] = (int) (*(nphoto + i));
255 np[5] = (int) (*(nelect + i));
256 np[6] = (int) (*(nposit + i));
257 np[7] = (int) (*(nnu + i));
258 np[8] = (int) (*(nmum + i));
259 np[9] = (int) (*(nmup + i));
260 np[10] = (int) (*(npi0 + i));
261 np[11] = (int) (*(npim + i));
262 np[12] = (int) (*(npip + i));
263 np[13] = (int) (*(nk0l + i));
264 np[14] = (int) (*(nk0s + i));
265 np[15] = (int) (*(nkmi + i));
266 np[16] = (int) (*(nkpl + i));
267 np[17] = (int) (*(nhyp + i));
268 np[18] = (int) (*(ndeut + i));
269 np[19] = (int) (*(ntrit + i));
270 np[20] = (int) (*(nalpha + i));
271 np[21] = (int) (*(nother + i));
272 fwrite (np, sizeof (int) * 22, 1, sttape);
273 }
274
275 np[0] = (int) (*ifinnu);
276 np[1] = (int) (*ifinpi);
277 np[2] = (int) (*ifinet);
278 np[3] = (int) (*ifinka);
279 np[4] = (int) (*ifinhy);
280 np[5] = (int) (*cerele);
281 np[6] = (int) (*cerhad);
282 fwrite (np, sizeof (int) * 7, 1, sttape);
283
284 fwrite (lpct1, sizeof (int), 1, sttape);
285 fwrite (nstep, sizeof (int), 1, sttape);
286
287 f = (float) (*thstep);
288 fwrite (&f, sizeof (float), 1, sttape);
289
290 for (k=0;k<9;k++)
291 for (i = 0; i < *nstep; i++) {
292 f = (float)(*(plong + i + k*NPLONG));
293 fwrite (&f, sizeof (float), 1, sttape);
294 }
295
296
297}
298
299/*--------------------------------------------------
300 jcendrun:
301
302 Closes STA file
303--------------------------------------------------*/
304#ifdef JC_UNDERSCORES
305void
306jcendrun_ (float *rune)
307#else /* JC_NO_UNDERSCORES */
308void
309jcendrun (float *rune)
310#endif /* JC_UNDERSCORES */
311{
312 /* fwrite (rune, sizeof (float) * MAXBUF, 1, sttape); */
313 fclose (sttape);
314}
Note: See TracBrowser for help on using the repository browser.