Fork me on GitHub

source: svn/trunk/Utilities/stdhep/mcf_Stdhep_xdr.c@ 161

Last change on this file since 161 was 3, checked in by Xavier Rouby, 16 years ago

first commit

File size: 9.6 KB
RevLine 
[3]1/*******************************************************************************
2* *
3* mcf_Stdhep_xdr.c -- XDR Utility routines for the Block Stdhep filters *
4* *
5* Copyright (c) 1994 Universities Research Association, Inc. *
6* All rights reserved. *
7* *
8* This material resulted from work developed under a Government Contract and *
9* is subject to the following license: The Government retains a paid-up, *
10* nonexclusive, irrevocable worldwide license to reproduce, prepare derivative *
11* works, perform publicly and display publicly by or for the Government, *
12* including the right to distribute to other Government contractors. Neither *
13* the United States nor the United States Department of Energy, nor any of *
14* their employees, makes any warranty, express or implied, or assumes any *
15* legal liability or responsibility for the accuracy, completeness, or *
16* usefulness of any information, apparatus, product, or process disclosed, or *
17* represents that its use would not infringe privately owned rights. *
18* *
19* *
20* Written by Paul Lebrun, Lynn Garren *
21* *
22* *
23*******************************************************************************/
24#include <stdio.h>
25#include <string.h>
26#include <sys/param.h>
27#include <rpc/types.h>
28#include <sys/types.h>
29#include <rpc/xdr.h>
30#include <limits.h>
31#ifdef SUNOS
32#include <floatingpoint.h>
33#else /* SUNOS */
34#include <float.h>
35#endif /* SUNOS */
36#include <stdlib.h>
37#include <time.h>
38#include "Utilities/mcfio/mcfio_Dict.h"
39#include "Utilities/mcfio/mcf_xdr.h"
40#include "Utilities/stdhep/stdhep.h"
41#include "Utilities/stdhep/stdtmp.h"
42#include "Utilities/stdhep/stdver.h"
43#ifndef FALSE
44#define FALSE 0
45#endif
46#ifndef TRUE
47#define TRUE 1
48#endif
49
50extern struct stdver stdver_;
51extern struct hepevt myhepevt;
52extern struct hepev2 hepev2_;
53extern struct hepev3 hepev3_;
54extern struct stdtmp stdtmp_;
55
56bool_t xdr_stdhep_(XDR *xdrs, int *blockid,
57 int *ntot, char** version)
58
59{
60/* Translate the HEPEVT temporary COMMON block from the STDHEP package to/from
61 an XDR stream. Note that we do not allocate memory, because we fill
62 directly the COMMON. Also, mcfio will allocate the space for the
63 string version. */
64
65 unsigned int nn, nn2, nn4, nn5, nnw, nnw2, nnw4, nnw5;
66 int *idat;
67 double *dat;
68
69 if ((xdrs->x_op == XDR_ENCODE) || (xdrs->x_op == XDR_MCFIOCODE)) {
70 if (*blockid != MCFIO_STDHEP) {
71 fprintf (stderr, "mcf_Stdhep_xdr: Inconsistent Blockid %d \n ",
72 (*blockid));
73 return FALSE;
74 }
75
76 nn = (unsigned int) stdtmp_.nhept; /* Number of elements in isthep or idhep */
77 nn2 = 2*(unsigned int) stdtmp_.nhept; /* Number of elements in jmohep or jdahep */
78 nn4 = 4*(unsigned int) stdtmp_.nhept; /* Number of elements in vhep */
79 nn5 = 5*(unsigned int) stdtmp_.nhept; /* Number of elements in phep */
80 nnw = (unsigned int) stdtmp_.nhept;
81 nnw2 = 2 * nnw;
82 nnw4 = 4 * nnw;
83 nnw5 = 5 * nnw;
84
85 /* Total length in bytes include blockid, ntot, version, nevhept and nhept as well
86 as the arrays remembering doubles are longer than ints. */
87 *ntot = 5*sizeof(int) + sizeof(int)*(2*nn + 2*nn2) + sizeof(double)*(nn4 + nn5);
88
89 if (xdrs->x_op == XDR_MCFIOCODE) return TRUE;
90 strncpy(version[0],stdver_.stdhep_ver, 4);
91 }
92
93 if ( (xdr_int(xdrs, blockid) &&
94 xdr_int(xdrs, ntot) &&
95 xdr_string(xdrs, version, MCF_XDR_VERSION_LENGTH) &&
96 xdr_int(xdrs, &(stdtmp_.nevhept)) &&
97 xdr_int(xdrs, &(stdtmp_.nhept))) == FALSE) return FALSE;
98
99 if ((xdrs->x_op == XDR_DECODE) && ( *blockid != MCFIO_STDHEP) ) {
100 fprintf (stderr, "mcf_Stdhep_xdr: Inconsistent Blockid %d \n ",
101 (*blockid));
102 return FALSE;
103 }
104 idat = stdtmp_.isthept;
105 if ( xdr_array(xdrs, (char **) &idat,
106 &nnw, NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
107 idat = stdtmp_.idhept;
108 if ( xdr_array(xdrs, (char **) &idat,
109 &nnw, NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
110 idat = (int *) stdtmp_.jmohept;
111 if ( xdr_array(xdrs, (char **) &idat,
112 &nnw2, 2*NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
113 idat = (int *) stdtmp_.jdahept;
114 if ( xdr_array(xdrs, (char **) &idat,
115 &nnw2, 2*NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
116 dat = (double *) stdtmp_.phept;
117 if ( xdr_array(xdrs, (char **) &dat,
118 &nnw5, 5*NMXHEP, sizeof(double), (void *) xdr_double) == FALSE) return FALSE;
119 dat = (double *) stdtmp_.vhept;
120 if ( xdr_array(xdrs, (char **) &dat,
121 &nnw4, 4*NMXHEP, sizeof(double), (void *) xdr_double) == FALSE) return FALSE;
122 return TRUE;
123}
124
125bool_t xdr_stdhep_multi_(XDR *xdrs, int *blockid,
126 int *ntot, char** version)
127
128{
129/* Translate the HEPEVT COMMON block from the STDHEP package to/from
130 an XDR stream. Note that we do not allocate memory, because we fill
131 directly the COMMON. Also, mcfio will allocate the space for the
132 string version.
133 Also translate the HEPEV2 COMMON block from the STDHEP package to/from
134 an XDR stream. HEPEV2 contains multiple interaction information */
135
136 unsigned int nn, nn2, nn4, nn5, nnw, nnw2, nnw4, nnw5, nmlt, nnmlt;
137 int i;
138 int *idat;
139 char *vers;
140 double *dat;
141
142 if ((xdrs->x_op == XDR_ENCODE) || (xdrs->x_op == XDR_MCFIOCODE)) {
143 if (*blockid != MCFIO_STDHEPM) {
144 fprintf (stderr, "mcf_Stdhep_xdr: Inconsistent Blockid %d \n ",
145 (*blockid));
146 return FALSE;
147 }
148 nn = sizeof(int) * myhepevt.nhep;
149 nn2 = 2 * sizeof(int) * myhepevt.nhep;
150 nn4 = 4 * sizeof(double) * myhepevt.nhep;
151 nn5 = 5 * sizeof(double) * myhepevt.nhep;
152 nmlt = sizeof(int) * hepev2_.nmulti;
153 nnw = (unsigned int) myhepevt.nhep;
154 nnw2 = 2 * nnw;
155 nnw4 = 4 * nnw;
156 nnw5 = 5 * nnw;
157 nnmlt = (unsigned int) hepev2_.nmulti;
158 *ntot = 6 * sizeof(int) + 3 * nn + 2 * nn2 + nn4 + nn5 + 3 * nmlt;
159 if (xdrs->x_op == XDR_MCFIOCODE) return TRUE;
160 strncpy(version[0],stdver_.stdhep_ver, 4);
161 }
162
163 if ( (xdr_int(xdrs, blockid) &&
164 xdr_int(xdrs, ntot) &&
165 xdr_string(xdrs, version, MCF_XDR_VERSION_LENGTH) &&
166 xdr_int(xdrs, &(myhepevt.nevhep)) &&
167 xdr_int(xdrs, &(myhepevt.nhep))) == FALSE) return FALSE;
168
169 if ((xdrs->x_op == XDR_DECODE) && ( *blockid != MCFIO_STDHEPM) ) {
170 fprintf (stderr, "mcf_Stdhep_xdr: Inconsistent Blockid %d \n ",
171 (*blockid));
172 return FALSE;
173 }
174 idat = myhepevt.isthep;
175 if ( xdr_array(xdrs, (char **) &idat,
176 &nnw, NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
177 idat = myhepevt.idhep;
178 if ( xdr_array(xdrs, (char **) &idat,
179 &nnw, NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
180 idat = (int *) myhepevt.jmohep;
181 if ( xdr_array(xdrs, (char **) &idat,
182 &nnw2, 2*NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
183 idat = (int *) myhepevt.jdahep;
184 if ( xdr_array(xdrs, (char **) &idat,
185 &nnw2, 2*NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
186 dat = (double *) myhepevt.phep;
187 if ( xdr_array(xdrs, (char **) &dat,
188 &nnw5, 5*NMXHEP, sizeof(double), (void *) xdr_double) == FALSE) return FALSE;
189 dat = (double *) myhepevt.vhep;
190 if ( xdr_array(xdrs, (char **) &dat,
191 &nnw4, 4*NMXHEP, sizeof(double), (void *) xdr_double) == FALSE) return FALSE;
192 /*
193 ** V2.02 Upgrade : adding Multiple interactions.
194 */
195 vers = *version;
196 if ((strcmp(vers,"1.05") == 0) && (xdrs->x_op == XDR_DECODE)) {
197 hepev2_.nmulti = -1;
198 return TRUE;
199 }
200 if ( xdr_int(xdrs, &(hepev2_.nmulti)) == FALSE) return FALSE;
201 idat = hepev2_.jmulti;
202 if ( xdr_array(xdrs, (char **) &idat,
203 &nnw, NMXHEP, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
204 /*
205 ** V4.04 Upgrade : adding more Multiple interaction information
206 */
207 if (((strcmp(vers,"2.") > 0) || (strcmp(vers,"3.") > 0))
208 && (xdrs->x_op == XDR_DECODE)) {
209 for (i = 0; i <= NMXMLT; i++) {
210 hepev3_.nevmulti[i] = 0;
211 hepev3_.itrkmulti[i] = 0;
212 hepev3_.mltstr[i] = 0;
213 }
214 return TRUE;
215 }
216 if (((strcmp(vers,"4.00") == 0) || (strcmp(vers,"4.01") == 0) ||
217 (strcmp(vers,"4.02") == 0) || (strcmp(vers,"4.03") == 0) )
218 && (xdrs->x_op == XDR_DECODE)) {
219 for (i = 0; i <= NMXMLT; i++) {
220 hepev3_.nevmulti[i] = 0;
221 hepev3_.itrkmulti[i] = 0;
222 hepev3_.mltstr[i] = 0;
223 }
224 return TRUE;
225 }
226 idat = hepev3_.nevmulti;
227 if ( xdr_array(xdrs, (char **) &idat,
228 &nnmlt, NMXMLT, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
229 idat = hepev3_.itrkmulti;
230 if ( xdr_array(xdrs, (char **) &idat,
231 &nnmlt, NMXMLT, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
232 idat = hepev3_.mltstr;
233 if ( xdr_array(xdrs, (char **) &idat,
234 &nnmlt, NMXMLT, sizeof(int), (void *) xdr_int) == FALSE) return FALSE;
235 return TRUE;
236}
237
238
Note: See TracBrowser for help on using the repository browser.