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