GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
f_radware.c
Go to the documentation of this file.
1 // $Id$
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <ctype.h>
17 #include <string.h>
18 #include <errno.h>
19 #include <fcntl.h>
20 #include <sys/types.h>
21 #include "f_radware.h"
22 #include "typedefs.h"
23 
24 #ifdef GSI__WINNT
25 #include <io.h>
26 #else
27 #include <unistd.h>
28 #endif
29 
30 #define HIS__BASPERM 0774
31 //*************************************************************
32 int f_radware_out1d(char *pc_file, char *pc_name, float *pr_data, int l_chan, int l_over)
33 {
34  int i32_fd, i32_bytes, i32_hislen;
35  int l_status,l_head[6];
36  char c_str[128];
37 
38  if(l_over) // delete old file
39 {
40  strcpy(c_str,"rm ");
41  strncat(c_str, pc_file, sizeof(c_str)-1);
42  system(c_str);
43 }
44 i32_fd = open(pc_file, O_WRONLY | O_CREAT | O_EXCL, HIS__BASPERM);
45 if (i32_fd < 0)
46 {
47  printf("Error %d opening file %s, already exists?\n",errno, pc_file);
48  return(1);
49 }
50 //write file
51 strncpy(c_str,pc_name, sizeof(c_str));
52 strncat(c_str," ", sizeof(c_str)-1);
53 l_head[0]=24;
54 l_head[1]=1;
55 l_head[2]=1;
56 l_head[3]=1;
57 l_head[4]=24;
58 l_head[5]=l_chan*4; /* record size */
59 
60 i32_bytes = write(i32_fd, (char *) l_head, 4);
61 i32_bytes += write(i32_fd, c_str, 8);
62 l_head[0] = l_chan;
63 i32_bytes += write(i32_fd, (char *) l_head, 24); /* includes record size */
64 
65 i32_bytes += write(i32_fd, (char *) pr_data, l_chan*4);
66 l_head[0] = l_chan*4;
67 i32_bytes += write(i32_fd, (char *) l_head, 4);
68 
69 i32_hislen = l_chan*4 + 40;
70 if (i32_bytes == i32_hislen)
71 {
72  // printf("Histogram %32s: %d bytes (data %d) written to %s\n",
73  // pc_name,i32_bytes,l_chan*4,pc_file);
74 }
75 else
76 {
77  printf("Error %d. Dumping histogram:%s, %d bytes written to %s\n",
78  errno,pc_name,i32_bytes,pc_file);
79 }
80 l_status = close(i32_fd);
81 if (l_status != 0)
82 {
83  printf("Error %d. Close %s failed!\n",errno,pc_file);
84  return(1);
85 }
86 return(0);
87 }
88 //*************************************************************
89 int f_radware_out2d(char *pc_file, char *pc_name, int *pl_data, int l_chan, int l_over)
90 {
91  int i32_fd, i32_bytes;
92  int l_status;
93  char c_str[128];
94 
95 if(l_over)
96 {
97  strcpy(c_str,"rm ");
98  strncat(c_str,pc_file, sizeof(c_str)-1);
99  system(c_str);
100 }
101 i32_fd = open(pc_file, O_WRONLY | O_CREAT | O_EXCL, HIS__BASPERM);
102 if (i32_fd < 0)
103 {
104  printf("Error %d opening file %s, already exists?\n",errno, pc_file);
105  return(1);
106 }
107 i32_bytes = write(i32_fd, (char *) pl_data, l_chan*4);
108 if (i32_bytes == l_chan*4)
109 {
110  // printf("Histogram %32s: %d bytes written to %s\n",
111  // pc_name,i32_bytes,pc_file);
112 }
113 else
114 {
115  printf("Error %d. Dumping histogram:%s, only %d bytes written to %s\n",
116  errno,pc_name,i32_bytes,pc_file);
117 }
118 l_status = close(i32_fd);
119 if (l_status != 0)
120 {
121  printf("Error %d. Close %s failed!\n",errno,pc_file);
122  return(1);
123 }
124 return(0);
125 }
int f_radware_out1d(char *pc_file, char *pc_name, float *pr_data, int l_chan, int l_over)
Definition: f_radware.c:32
#define HIS__BASPERM
Definition: f_radware.c:30
int l_status
Definition: f_evcli.c:169
int f_radware_out2d(char *pc_file, char *pc_name, int *pl_data, int l_chan, int l_over)
Definition: f_radware.c:89