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