GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
f_radware.c
Go to the documentation of this file.
1 // $Id: f_radware.c 478 2009-10-29 12:26:09Z linev $
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 für 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 <fcntl.h>
19 #include <sys/types.h>
20 #include "f_radware.h"
21 #include "typedefs.h"
22 
23 #ifdef GSI__WINNT
24 #include <errno.h>
25 #else
26 #include <errno.h>
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  char c_retmsg[128];
35  int i32_fd, i32_bytes, i32_hislen;
36  int l_status,ll,l_head[6],l_bytes;
37  char *pc,c_str[128];
38 
39  if(l_over) // delete old file
40 {
41  strcpy(c_str,"rm ");
42  strcat(c_str,pc_file);
43  system(c_str);
44 }
45 i32_fd = open(pc_file, O_WRONLY | O_CREAT | O_EXCL, HIS__BASPERM);
46 if (i32_fd < 0)
47 {
48  printf("Error %d opening file %s, already exists?\n",errno, pc_file);
49  return(1);
50 }
51 //write file
52 strcpy(c_str,pc_name);
53 strcat(c_str," ");
54 l_head[0]=24;
55 l_head[1]=1;
56 l_head[2]=1;
57 l_head[3]=1;
58 l_head[4]=24;
59 l_head[5]=l_chan*4; /* record size */
60 
61 i32_bytes = write(i32_fd, (char *) l_head, 4);
62 i32_bytes += write(i32_fd, c_str, 8);
63 l_head[0] = l_chan;
64 i32_bytes += write(i32_fd, (char *) l_head, 24); /* includes record size */
65 
66 i32_bytes += write(i32_fd, (char *) pr_data, l_chan*4);
67 l_head[0] = l_chan*4;
68 i32_bytes += write(i32_fd, (char *) l_head, 4);
69 
70 i32_hislen = l_chan*4 + 40;
71 if (i32_bytes == i32_hislen)
72 {
73  // printf("Histogram %32s: %d bytes (data %d) written to %s\n",
74  // pc_name,i32_bytes,l_chan*4,pc_file);
75 }
76 else
77 {
78  printf("Error %d. Dumping histogram:%s, %d bytes written to %s\n",
79  errno,pc_name,i32_bytes,pc_file);
80 }
81 l_status = close(i32_fd);
82 if (l_status != 0)
83 {
84  printf("Error %d. Close %s failed!\n",errno,pc_file);
85  return(1);
86 }
87 return(0);
88 }
89 //*************************************************************
90 int f_radware_out2d(char *pc_file, char *pc_name, int *pl_data, int l_chan, int l_over)
91 {
92  int i32_fd, i32_bytes, i32_hislen;
93  int l_status,ll,l_head[6],l_bytes;
94  char *pc,c_str[128];
95 
96 if(l_over)
97 {
98  strcpy(c_str,"rm ");
99  strcat(c_str,pc_file);
100  system(c_str);
101 }
102 i32_fd = open(pc_file, O_WRONLY | O_CREAT | O_EXCL, HIS__BASPERM);
103 if (i32_fd < 0)
104 {
105  printf("Error %d opening file %s, already exists?\n",errno, pc_file);
106  return(1);
107 }
108 i32_bytes = write(i32_fd, (char *) pl_data, l_chan*4);
109 if (i32_bytes == l_chan*4)
110 {
111  // printf("Histogram %32s: %d bytes written to %s\n",
112  // pc_name,i32_bytes,pc_file);
113 }
114 else
115 {
116  printf("Error %d. Dumping histogram:%s, only %d bytes written to %s\n",
117  errno,pc_name,i32_bytes,pc_file);
118 }
119 l_status = close(i32_fd);
120 if (l_status != 0)
121 {
122  printf("Error %d. Close %s failed!\n",errno,pc_file);
123  return(1);
124 }
125 return(0);
126 }
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:183
int f_radware_out2d(char *pc_file, char *pc_name, int *pl_data, int l_chan, int l_over)
Definition: f_radware.c:90