00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <stdio.h>
00017 #include <ctype.h>
00018 #include <string.h>
00019 #include <fcntl.h>
00020 #include <sys/types.h>
00021 #include "f_radware.h"
00022 #include "typedefs.h"
00023
00024 #ifdef GSI__WINNT
00025 #include <errno.h>
00026 #else
00027 #include <sys/errno.h>
00028 #include <unistd.h>
00029 #endif
00030
00031 #define HIS__BASPERM 0774
00032
00033 int f_radware_out1d(char *pc_file, char *pc_name, float *pr_data, int l_chan, int l_over)
00034 {
00035 char c_retmsg[128];
00036 int i32_fd, i32_bytes, i32_hislen;
00037 int l_status,ll,l_head[6],l_bytes;
00038 char *pc,c_str[128];
00039
00040 if(l_over)
00041 {
00042 strcpy(c_str,"rm ");
00043 strcat(c_str,pc_file);
00044 system(c_str);
00045 }
00046 i32_fd = open(pc_file, O_WRONLY | O_CREAT | O_EXCL, HIS__BASPERM);
00047 if (i32_fd < 0)
00048 {
00049 printf("Error %d opening file %s, already exists?\n",errno, pc_file);
00050 return(1);
00051 }
00052
00053 strcpy(c_str,pc_name);
00054 strcat(c_str," ");
00055 l_head[0]=24;
00056 l_head[1]=1;
00057 l_head[2]=1;
00058 l_head[3]=1;
00059 l_head[4]=24;
00060 l_head[5]=l_chan*4;
00061
00062 i32_bytes = write(i32_fd, (char *) l_head, 4);
00063 i32_bytes += write(i32_fd, c_str, 8);
00064 l_head[0] = l_chan;
00065 i32_bytes += write(i32_fd, (char *) l_head, 24);
00066
00067 i32_bytes += write(i32_fd, (char *) pr_data, l_chan*4);
00068 l_head[0] = l_chan*4;
00069 i32_bytes += write(i32_fd, (char *) l_head, 4);
00070
00071 i32_hislen = l_chan*4 + 40;
00072 if (i32_bytes == i32_hislen)
00073 {
00074
00075
00076 }
00077 else
00078 {
00079 printf("Error %d. Dumping histogram:%s, %d bytes written to %s\n",
00080 errno,pc_name,i32_bytes,pc_file);
00081 }
00082 l_status = close(i32_fd);
00083 if (l_status != 0)
00084 {
00085 printf("Error %d. Close %s failed!\n",errno,pc_file);
00086 return(1);
00087 }
00088 return(0);
00089 }
00090
00091 int f_radware_out2d(char *pc_file, char *pc_name, int *pl_data, int l_chan, int l_over)
00092 {
00093 int i32_fd, i32_bytes, i32_hislen;
00094 int l_status,ll,l_head[6],l_bytes;
00095 char *pc,c_str[128];
00096
00097 if(l_over)
00098 {
00099 strcpy(c_str,"rm ");
00100 strcat(c_str,pc_file);
00101 system(c_str);
00102 }
00103 i32_fd = open(pc_file, O_WRONLY | O_CREAT | O_EXCL, HIS__BASPERM);
00104 if (i32_fd < 0)
00105 {
00106 printf("Error %d opening file %s, already exists?\n",errno, pc_file);
00107 return(1);
00108 }
00109 i32_bytes = write(i32_fd, (char *) pl_data, l_chan*4);
00110 if (i32_bytes == l_chan*4)
00111 {
00112
00113
00114 }
00115 else
00116 {
00117 printf("Error %d. Dumping histogram:%s, only %d bytes written to %s\n",
00118 errno,pc_name,i32_bytes,pc_file);
00119 }
00120 l_status = close(i32_fd);
00121 if (l_status != 0)
00122 {
00123 printf("Error %d. Close %s failed!\n",errno,pc_file);
00124 return(1);
00125 }
00126 return(0);
00127 }
00128
00129