Fork me on GitHub

source: svn/trunk/Utilities/stdhep/mcf_stdcm1_xdr.c@ 260

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

first commit

File size: 5.7 KB
RevLine 
[3]1/*******************************************************************************
2* *
3* mcf_stdcm1_xdr.c -- XDR Utility routines for the Block stdcm1 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/stdcm1.h"
41#include "Utilities/stdhep/stdver.h"
42#ifndef FALSE
43#define FALSE 0
44#endif
45#ifndef TRUE
46#define TRUE 1
47#endif
48
49extern struct stdver stdver_;
50extern struct stdcm1 stdcm1_;
51extern struct stdcm2 stdcm2_;
52
53bool_t xdr_stdhep_cm1_(XDR *xdrs, int *blockid,
54 int *ntot, char** version)
55
56{
57/* Translate the STDCM1 COMMON block from the STDHEP package to/from
58 an XDR stream. Note that we do not allocate memory, because we fill
59 directly the COMMON. Also, mcfio will allocate the space for the
60 string version. */
61
62 unsigned int nn, nn1, nn2;
63 char *vers;
64 char *cdat;
65
66 if ((xdrs->x_op == XDR_ENCODE) || (xdrs->x_op == XDR_MCFIOCODE)) {
67 if (( *blockid != MCFIO_STDHEPEND)&&( *blockid != MCFIO_STDHEPBEG)) {
68 fprintf (stderr, "mcf_Stdhep_cm1_xdr: Inconsistent Blockid %d \n ",
69 (*blockid));
70 return FALSE;
71 }
72 nn = sizeof(int) * stdcm1_.nevtreq;
73 nn1 = sizeof(float) * stdcm1_.nevtreq;
74 nn2 = sizeof(double) * stdcm1_.nevtreq;
75 *ntot = 3 * sizeof(int) + 3 * nn + 2 * nn1 + 2 * nn2
76 + 2 * sizeof(char) * ( MCF_XDR_STDCM2_LENGTH + 1 );
77 if (xdrs->x_op == XDR_MCFIOCODE) return TRUE;
78 strncpy(version[0],stdver_.stdhep_ver, 4);
79 }
80
81 if ( (xdr_int(xdrs, blockid) &&
82 xdr_int(xdrs, ntot) &&
83 xdr_string(xdrs, version, MCF_XDR_VERSION_LENGTH) )
84 == FALSE) return FALSE;
85
86 if ((xdrs->x_op == XDR_DECODE) &&
87 (( *blockid != MCFIO_STDHEPEND)&&( *blockid != MCFIO_STDHEPBEG))) {
88 fprintf (stderr, "mcf_Stdhep_cm1_xdr: Inconsistent Blockid %d \n ",
89 (*blockid));
90 return FALSE;
91 }
92 if ( xdr_int(xdrs, &(stdcm1_.nevtreq) ) == FALSE) return FALSE;
93 if ( xdr_int(xdrs, &(stdcm1_.nevtgen) ) == FALSE) return FALSE;
94 if ( xdr_int(xdrs, &(stdcm1_.nevtwrt) ) == FALSE) return FALSE;
95 if ( xdr_float(xdrs, &(stdcm1_.stdecom) ) == FALSE) return FALSE;
96 if ( xdr_float(xdrs, &(stdcm1_.stdxsec) ) == FALSE) return FALSE;
97 if ( xdr_double(xdrs, &(stdcm1_.stdseed1) ) == FALSE) return FALSE;
98 if ( xdr_double(xdrs, &(stdcm1_.stdseed2) ) == FALSE) return FALSE;
99 /*
100 ** V5.01 Upgrade : adding stdcm2
101 */
102 vers = *version;
103 if (((strcmp(vers,"1.") == 0) || (strcmp(vers,"2.") == 0) ||
104 (strcmp(vers,"3.") == 0) || (strcmp(vers,"4.") == 0) ||
105 (strcmp(vers,"5.00") == 0) ) && (xdrs->x_op == XDR_DECODE)) {
106 strncpy(stdcm2_.generatorname, " ", MCF_XDR_STDCM2_LENGTH);
107 strncpy(stdcm2_.pdfname, " ", MCF_XDR_STDCM2_LENGTH);
108 return TRUE;
109 }
110/*
111 allocate memory and deal with encoding and decoding separately
112*/
113 cdat = malloc(MCF_XDR_STDCM2_LENGTH+1);
114 if( (xdrs->x_op == XDR_DECODE) ) {
115 strncpy(stdcm2_.generatorname, " ", MCF_XDR_STDCM2_LENGTH);
116 strncpy(stdcm2_.pdfname, " ", MCF_XDR_STDCM2_LENGTH);
117 cdat = NULL;
118 if ( xdr_string(xdrs, &cdat, MCF_XDR_STDCM2_LENGTH+1 ) == FALSE) return FALSE;
119 strncpy(stdcm2_.generatorname,cdat,MCF_XDR_STDCM2_LENGTH);
120 cdat = NULL;
121 if ( xdr_string(xdrs, &cdat, MCF_XDR_STDCM2_LENGTH+1 ) == FALSE) return FALSE;
122 strncpy(stdcm2_.pdfname,cdat,MCF_XDR_STDCM2_LENGTH);
123 } else {
124 strncpy(cdat, stdcm2_.generatorname, MCF_XDR_STDCM2_LENGTH);
125 /* some compilers do not properly append the null terminator */
126 cdat[MCF_XDR_STDCM2_LENGTH]='\0';
127 if ( xdr_string(xdrs, &cdat, MCF_XDR_STDCM2_LENGTH+1 ) == FALSE) return FALSE;
128 strncpy(cdat, stdcm2_.pdfname, MCF_XDR_STDCM2_LENGTH);
129 cdat[MCF_XDR_STDCM2_LENGTH]='\0';
130 if ( xdr_string(xdrs, &cdat, MCF_XDR_STDCM2_LENGTH+1 ) == FALSE) return FALSE;
131 }
132 free(cdat);
133
134 /*
135 ** V5.02 Upgrade : add nevtlh to stdcm1
136 ** note that we cannot get here unless the version is 5.00 or greater
137 */
138 if (((strcmp(vers,"5.00") == 0) || (strcmp(vers,"5.01") == 0))
139 && (xdrs->x_op == XDR_DECODE)) {
140 stdcm1_.nevtlh = 0;
141 return TRUE;
142 }
143 if ( xdr_int(xdrs, &(stdcm1_.nevtlh) ) == FALSE) return FALSE;
144
145 return TRUE;
146}
147
Note: See TracBrowser for help on using the repository browser.