12 int byte_switch(void *data,int bytes) {
18 d=(unsigned char *)data;
20 for(i=0;i<bytes/2;i++) {
29 int main(int argc,char **argv) {
37 printf("just a short test ...\n");
46 byte_switch(&i,sizeof(int));
52 if((rfd=open(argv[1],O_RDONLY))<0) {
53 printf("failed opening file %s\n",argv[1]);
57 if((wfd=open(argv[2],O_WRONLY|O_CREAT))<0) {
58 printf("failed opening file %s\n",argv[2]);
62 size=sizeof(d3_lattice);
63 if(read(rfd,&l,size)<size) {
64 printf("failed reading %d bytes\n",size);
68 byte_switch(&(l.max_x),sizeof(int));
69 byte_switch(&(l.max_y),sizeof(int));
70 byte_switch(&(l.max_z),sizeof(int));
73 byte_switch(&(l.fakt_x),sizeof(int));
74 byte_switch(&(l.fakt_y),sizeof(int));
75 byte_switch(&(l.info_x),sizeof(int));
76 byte_switch(&(l.info_y),sizeof(int));
77 byte_switch(&(l.o_x),sizeof(int));
78 byte_switch(&(l.info_w),sizeof(int));
79 byte_switch(&(l.info_h),sizeof(int));
80 byte_switch(&(l.font_h),sizeof(int));
84 if(read(rfd,&info,size)<size) {
85 printf("failed reading %d bytes\n",size);
89 byte_switch(&(info.cc),sizeof(int));
90 byte_switch(&(info.steps),sizeof(int));
91 byte_switch(&(info.range),sizeof(int));
92 byte_switch(&(info.diff_rate),sizeof(int));
93 byte_switch(&(info.cpi),sizeof(int));
94 byte_switch(&(info.c_sat),sizeof(int));
95 byte_switch(&(info.s),sizeof(double));
96 byte_switch(&(info.b),sizeof(double));
97 byte_switch(&(info.c),sizeof(double));
98 byte_switch(&(info.dr_ac),sizeof(double));
99 byte_switch(&(info.dr_cc),sizeof(double));
101 /* write lattice and info struct */
102 size=sizeof(d3_lattice);
103 if(write(wfd,&l,size)<size) {
104 printf("failed writing %d bytes\n",size);
109 if(write(wfd,&info,size)<size) {
110 printf("failed writing %d bytes\n",size);
114 /* read & write data */
115 /* status info - just chars */
116 size=l.max_x*l.max_y*l.max_z;
117 if((buf=(unsigned char *)malloc(size))==NULL) {
118 printf("unable to malloc %d bytes\n",size);
121 if(read(rfd,buf,size)<size) {
122 printf("failed reading %d data bytes\n",size);
125 if(write(wfd,buf,size)<size) {
126 printf("failed writing %d data bytes\n",size);
129 /* c conc - integers */
130 for(i=0;i<size;i++) {
131 if(read(rfd,buf,sizeof(int))<sizeof(int)) {
132 printf("unable to read c conc nr. %d\n",i);
135 byte_switch(buf,sizeof(int));
136 if(write(wfd,buf,sizeof(int))<sizeof(int)) {
137 printf("unable to write c conc nr. %d\n",i);
142 printf("done ... (never tell the endian police!)\n");