c-conc and p-val colour table output added
[physik/nlsop.git] / nlsop_make_cryst.c
1 #define _GNU_SOURCE
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8 #include <unistd.h>
9
10 #include <signal.h>
11
12 #include "nlsop.h"
13 #include "dfbapi.h"
14
15 int check(int ret,int size) {
16   if(ret==size) printf("%d, %d ... ok!\n",ret,size);
17   else printf("%d, %d ... FAILED!\n",ret,size);
18   return 1;
19 }
20
21 int main(int argc,char **argv) {
22
23   int wfd,rfd;
24   char wfile[128];
25   char rfile[128];
26   int size;
27   d3_lattice d3l;
28   info info;
29   unsigned char *buf;
30   int ret;
31
32   if(argc!=3) {
33     printf("usage: %s <orig file> <new file>\n",
34            argv[0]);
35     return -1;
36   }
37
38   strcpy(rfile,argv[1]);
39   strcpy(wfile,argv[2]);
40   
41   rfd=open(rfile,O_RDONLY);
42   wfd=open(wfile,O_WRONLY|O_CREAT);
43
44   ret=read(rfd,&d3l,sizeof(d3_lattice));
45   check(ret,sizeof(d3_lattice));
46   ret=read(rfd,&info,sizeof(info));
47   check(ret,sizeof(info));
48
49
50   ret=write(wfd,&d3l,sizeof(d3_lattice));
51   check(ret,sizeof(d3_lattice));
52   ret=write(wfd,&info,sizeof(info));
53   check(ret,sizeof(info));
54
55   size=d3l.max_x*d3l.max_y*d3l.max_z;
56
57   buf=(unsigned char *)malloc(size*sizeof(unsigned char));
58   memset(buf,0,size*sizeof(unsigned char));
59
60   ret=write(wfd,buf,size*sizeof(unsigned char));
61   check(ret,size*sizeof(unsigned char));
62
63   free(buf);
64   buf=(unsigned char *)malloc(size*sizeof(int));
65
66   ret=read(rfd,buf,size*sizeof(unsigned char));
67   check(ret,size*sizeof(unsigned char));
68
69   ret=read(rfd,buf,size*sizeof(int));
70   check(ret,size*sizeof(int));
71
72   ret=write(wfd,buf,size*sizeof(int));
73   check(ret,size*sizeof(int));
74
75   free(buf);
76   close(wfd);
77   close(rfd);
78
79   return 1;
80 }
81