source: branches/start/MagicSoft/Simulation/Corsika/Mmcs/jcio.c@ 18752

Last change on this file since 18752 was 286, checked in by harald, 25 years ago
This is the start point for further developments of the Magic Monte Carlo Simulation written by Jose Carlos Gonzales. Now it is under control of one CVS repository for the whole collaboration. Everyone should use this CVS repository for further developments.
File size: 9.5 KB
Line 
1/*----------------------------------------------------------------------
2 jcio.c :
3
4Rutinas para la gestion de ficheros en CORSIKA 5.20 Las posibilidades
5que contempla son:
6
7- Creacion de un fichero de inicio de run: run######
8- Creacion de un fichero de fin de run: end######
9- Creacion de fichero separados para cada cascada, tanto para
10 particulas como para Cherenkov. Ademas, para la salida Cherenkov se
11 genera en ficheros separados en caso de que se reutilice la cascada.
12 Los fichero son por tanto: cer######.# y dat######, donde el indice
13 del fichero cer va de 0 a 9.
14- La grabacion se realiza en C, por lo que no existen marcas de inicio
15 ni final de bloque en los ficheros.
16----------------------------------------------------------------------*/
17
18#include <stdio.h>
19#include <stdlib.h>
20
21#define MAXBUF 273 /*- 39*7 -*/
22#define NSUBBL 21
23#define NPLONG 1041
24
25static int nshow = 0;
26static float timefirst = 0.;
27static float timelast = 0.;
28
29FILE *cetape;
30FILE *patape;
31FILE *sttape;
32FILE *runtape;
33FILE *endtape;
34char tpl[100];
35char certpl[100];
36char dattpl[100];
37char statpl[100];
38char cerfile[100];
39char datfile[100];
40char stafile[100];
41char runfile[100];
42char endfile[100];
43
44/*--------------------------------------------------
45 jcinitio:
46 graba un bloque al fichero de particulas
47--------------------------------------------------*/
48#ifdef JC_UNDERSCORES
49void
50jcinitio_ (char *path, int *runnum)
51#else /* JC_NO_UNDERSCORES */
52void
53jcinitio (char *path, int *runnum)
54#endif /* JC_UNDERSCORES */
55{
56 register int i = 0;
57
58 while (*(path + (++i)) != ' ');
59 strncpy (tpl, path, i);
60 if (*(path + i - 1) != '/')
61 strcat (tpl, "/");
62
63 strcpy (certpl, tpl);
64 strcat (certpl, "cer%06d");
65 strcpy (dattpl, tpl);
66 strcat (dattpl, "dat%06d");
67 strcpy (statpl, tpl);
68 strcat (statpl, "sta%06d");
69
70 sprintf (runfile, "%srun%06d", tpl, *runnum);
71 sprintf (endfile, "%send%06d", tpl, *runnum);
72}
73
74/*--------------------------------------------------
75 jcdatsave:
76 graba un bloque al fichero de particulas
77--------------------------------------------------*/
78#ifdef JC_UNDERSCORES
79void
80jcdatsave_ (float *outbuf)
81#else /* JC_NO_UNDERSCORES */
82void
83jcdatsave (float *outbuf)
84#endif /* JC_UNDERSCORES */
85{
86 /* puts("JCIO:: saving particle buffer..."); */
87 fwrite (outbuf, sizeof (float) * MAXBUF * NSUBBL, 1, patape);
88}
89
90/*--------------------------------------------------
91 jccersave:
92 graba un bloque al fichero de particulas
93--------------------------------------------------*/
94#ifdef JC_UNDERSCORES
95void
96jccersave_ (float *outbuf)
97#else /* JC_NO_UNDERSCORES */
98void
99jccersave (float *outbuf)
100#endif /* JC_UNDERSCORES */
101{
102 /* puts("JCIO:: saving cerenkov buffer..."); */
103 fwrite (outbuf, sizeof (float) * MAXBUF * NSUBBL, 1, cetape);
104}
105
106/*--------------------------------------------------
107 jcstartrun:
108 abre el fichero run###### y graba el contenido
109--------------------------------------------------*/
110#ifdef JC_UNDERSCORES
111void
112jcstartrun_ (float *runh)
113#else /* JC_NO_UNDERSCORES */
114void
115jcstartrun (float *runh)
116#endif /* JC_UNDERSCORES */
117{
118 if ((runtape = fopen (runfile, "wb")) == NULL) {
119 printf ("JCIO:: Cannot open RUN file %s. Exiting.\n", runfile);
120 exit (1);
121 }
122 /* puts("JCIO:: saving runheader buffer..."); */
123 fwrite (runh, sizeof (float) * MAXBUF, 1, runtape);
124}
125
126/*--------------------------------------------------
127 jcendrun:
128 abre el fichero run###### y graba el contenido
129--------------------------------------------------*/
130#ifdef JC_UNDERSCORES
131void
132jcendrun_ (float *rune)
133#else /* JC_NO_UNDERSCORES */
134void
135jcendrun (float *rune)
136#endif /* JC_UNDERSCORES */
137{
138 fwrite (rune, sizeof (float) * MAXBUF, 1, runtape);
139 fclose (runtape);
140}
141
142/*--------------------------------------------------
143 jcnewcerfile:
144 abre un nuevo fichero Cherenkov
145--------------------------------------------------*/
146#ifdef JC_UNDERSCORES
147void
148jcnewcerfile_ ()
149#else /* JC_NO_UNDERSCORES */
150void
151jcnewcerfile ()
152#endif /* JC_UNDERSCORES */
153{
154 sprintf (cerfile, certpl, nshow);
155 if ((cetape = fopen (cerfile, "wb")) == NULL) {
156 printf ("JCIO:: Cannot open CER file %s. Exiting.\n", cerfile);
157 exit (1);
158 }
159 timefirst = 9.0e10;
160 timelast = -9.0e10;
161}
162
163/*--------------------------------------------------
164 jcnewdatfile:
165 abre un nuevo fichero de particulas
166--------------------------------------------------*/
167#ifdef JC_UNDERSCORES
168void
169jcnewdatfile_ (void)
170#else /* JC_NO_UNDERSCORES */
171void
172jcnewdatfile (void)
173#endif /* JC_UNDERSCORES */
174{
175 sprintf (datfile, dattpl, nshow);
176 if ((patape = fopen (datfile, "wb")) == NULL) {
177 printf ("JCIO:: Cannot open DAT file %s. Exiting.\n", datfile);
178 exit (1);
179 }
180}
181
182/*--------------------------------------------------
183 jcnewstafile:
184 abre un nuevo fichero de estadisticas
185--------------------------------------------------*/
186#ifdef JC_UNDERSCORES
187void
188jcnewstafile_ (void)
189#else /* JC_NO_UNDERSCORES */
190void
191jcnewstafile (void)
192#endif /* JC_UNDERSCORES */
193{
194 sprintf (stafile, statpl, nshow);
195 if ((sttape = fopen (stafile, "wb")) == NULL) {
196 printf ("JCIO:: Cannot open STA file %s. Exiting.\n", stafile);
197 exit (1);
198 }
199}
200
201/*--------------------------------------------------
202 jcnewshower:
203 abre nuevos ficheros para la nueva cascada
204--------------------------------------------------*/
205#ifdef JC_UNDERSCORES
206void
207jcnewshower_ (void)
208#else /* JC_NO_UNDERSCORES */
209void
210jcnewshower (void)
211#endif /* JC_UNDERSCORES */
212{
213 if (nshow > 0) {
214 fclose (patape);
215 fclose (cetape);
216 fclose (sttape);
217 }
218
219 nshow++;
220#ifdef JC_UNDERSCORES
221 jcnewdatfile_ ();
222 jcnewcerfile_ ();
223 jcnewstafile_ ();
224#else /* JC_NO_UNDERSCORES */
225 jcnewdatfile ();
226 jcnewcerfile ();
227 jcnewstafile ();
228#endif /* JC_UNDERSCORES */
229}
230
231/*--------------------------------------------------
232 jcenddata:
233 abre el fichero run###### y graba el contenido
234--------------------------------------------------*/
235#ifdef JC_UNDERSCORES
236void
237jcenddata_ (float *runh, float *rune)
238#else /* JC_NO_UNDERSCORES */
239void
240jcenddata (float *runh, float *rune)
241#endif /* JC_UNDERSCORES */
242{
243 if ((endtape = fopen (endfile, "wb")) == NULL) {
244 printf ("JCIO:: Cannot open END file %s. Exiting.\n", endfile);
245 exit (1);
246 }
247 fwrite (runh, sizeof (float) * MAXBUF, 1, endtape);
248 fwrite (rune, sizeof (float) * MAXBUF, 1, endtape);
249 fclose (endtape);
250}
251
252/*--------------------------------------------------
253 jctime:
254 va echando cuentas del tiempo de los fotones
255--------------------------------------------------*/
256#ifdef JC_UNDERSCORES
257void
258jctime_ (float *cartim)
259#else /* JC_NO_UNDERSCORES */
260void
261jctime (float *cartim)
262#endif /* JC_UNDERSCORES */
263{
264 if (*cartim>timelast) timelast = *cartim;
265 if (*cartim<timefirst) timefirst = *cartim;
266}
267
268/*--------------------------------------------------
269 jcstadata:
270 graba las estadisticas de la cascada
271--------------------------------------------------*/
272#ifdef JC_UNDERSCORES
273void
274jcstadata_ (float *evth, float *evte,
275 double *nproto, double *nprotb, double *nneutr,
276 double *nneutb, double *nphoto, double *nelect,
277 double *nposit, double *nnu, double *nmum,
278 double *nmup, double *npi0, double *npim, double *npip,
279 double *nk0l, double *nk0s, double *nkmi, double *nkpl,
280 double *nhyp, double *ndeut, double *ntrit, double *nalpha,
281 double *nother, int *ifinnu, int *ifinpi,
282 int *ifinet, int *ifinka, int *ifinhy,
283 double *cerele, double *cerhad,
284 double *plong, int *lpct1, int *nstep, double *thstep)
285#else /* JC_NO_UNDERSCORES */
286void
287jcstadata (float *evth, float *evte,
288 double *nproto, double *nprotb, double *nneutr,
289 double *nneutb, double *nphoto, double *nelect,
290 double *nposit, double *nnu, double *nmum,
291 double *nmup, double *npi0, double *npim, double *npip,
292 double *nk0l, double *nk0s, double *nkmi, double *nkpl,
293 double *nhyp, double *ndeut, double *ntrit, double *nalpha,
294 double *nother, int *ifinnu, int *ifinpi,
295 int *ifinet, int *ifinka, int *ifinhy,
296 double *cerele, double *cerhad,
297 double *plong, int *lpct1, int *nstep, double *thstep)
298#endif /* JC_UNDERSCORES */
299{
300 register int i, ii, k;
301 int np[22];
302 float f;
303
304 fwrite (evth, sizeof (float) * MAXBUF, 1, sttape);
305 fwrite (evte, sizeof (float) * MAXBUF, 1, sttape);
306
307 fwrite (&timefirst, sizeof (float), 1, sttape);
308 fwrite (&timelast, sizeof (float), 1, sttape);
309
310 for (i = 0; i < 10; i++) {
311 np[0] = (int) (*(nproto + i));
312 np[1] = (int) (*(nprotb + i));
313 np[2] = (int) (*(nneutr + i));
314 np[3] = (int) (*(nneutb + i));
315 np[4] = (int) (*(nphoto + i));
316 np[5] = (int) (*(nelect + i));
317 np[6] = (int) (*(nposit + i));
318 np[7] = (int) (*(nnu + i));
319 np[8] = (int) (*(nmum + i));
320 np[9] = (int) (*(nmup + i));
321 np[10] = (int) (*(npi0 + i));
322 np[11] = (int) (*(npim + i));
323 np[12] = (int) (*(npip + i));
324 np[13] = (int) (*(nk0l + i));
325 np[14] = (int) (*(nk0s + i));
326 np[15] = (int) (*(nkmi + i));
327 np[16] = (int) (*(nkpl + i));
328 np[17] = (int) (*(nhyp + i));
329 np[18] = (int) (*(ndeut + i));
330 np[19] = (int) (*(ntrit + i));
331 np[20] = (int) (*(nalpha + i));
332 np[21] = (int) (*(nother + i));
333 fwrite (np, sizeof (int) * 22, 1, sttape);
334 }
335
336 np[0] = (int) (*ifinnu);
337 np[1] = (int) (*ifinpi);
338 np[2] = (int) (*ifinet);
339 np[3] = (int) (*ifinka);
340 np[4] = (int) (*ifinhy);
341 np[5] = (int) (*cerele);
342 np[6] = (int) (*cerhad);
343 fwrite (np, sizeof (int) * 7, 1, sttape);
344
345 fwrite (lpct1, sizeof (int), 1, sttape);
346 fwrite (nstep, sizeof (int), 1, sttape);
347
348 f = (float) (*thstep);
349 fwrite (&f, sizeof (float), 1, sttape);
350
351 for (k=0;k<9;k++)
352 for (i = 0; i < *nstep; i++) {
353 f = (float)(*(plong + i + k*NPLONG));
354 fwrite (&f, sizeof (float), 1, sttape);
355 }
356
357
358}
Note: See TracBrowser for help on using the repository browser.