added support for starting file, added make_cryst tool
[physik/nlsop.git] / nlsop_make_cryst.c
diff --git a/nlsop_make_cryst.c b/nlsop_make_cryst.c
new file mode 100644 (file)
index 0000000..0587020
--- /dev/null
@@ -0,0 +1,81 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <signal.h>
+
+#include "nlsop.h"
+#include "dfbapi.h"
+
+int check(int ret,int size) {
+  if(ret==size) printf("%d, %d ... ok!\n",ret,size);
+  else printf("%d, %d ... FAILED!\n",ret,size);
+  return 1;
+}
+
+int main(int argc,char **argv) {
+
+  int wfd,rfd;
+  char wfile[128];
+  char rfile[128];
+  int size;
+  d3_lattice d3l;
+  info info;
+  unsigned char *buf;
+  int ret;
+
+  if(argc!=3) {
+    printf("usage: %s <orig file> <new file>\n",
+           argv[0]);
+    return -1;
+  }
+
+  strcpy(rfile,argv[1]);
+  strcpy(wfile,argv[2]);
+  
+  rfd=open(rfile,O_RDONLY);
+  wfd=open(wfile,O_WRONLY|O_CREAT);
+
+  ret=read(rfd,&d3l,sizeof(d3_lattice));
+  check(ret,sizeof(d3_lattice));
+  ret=read(rfd,&info,sizeof(info));
+  check(ret,sizeof(info));
+
+
+  ret=write(wfd,&d3l,sizeof(d3_lattice));
+  check(ret,sizeof(d3_lattice));
+  ret=write(wfd,&info,sizeof(info));
+  check(ret,sizeof(info));
+
+  size=d3l.max_x*d3l.max_y*d3l.max_z;
+
+  buf=(unsigned char *)malloc(size*sizeof(unsigned char));
+  memset(buf,0,size*sizeof(unsigned char));
+
+  ret=write(wfd,buf,size*sizeof(unsigned char));
+  check(ret,size*sizeof(unsigned char));
+
+  free(buf);
+  buf=(unsigned char *)malloc(size*sizeof(int));
+
+  ret=read(rfd,buf,size*sizeof(unsigned char));
+  check(ret,size*sizeof(unsigned char));
+
+  ret=read(rfd,buf,size*sizeof(int));
+  check(ret,size*sizeof(int));
+
+  ret=write(wfd,buf,size*sizeof(int));
+  check(ret,size*sizeof(int));
+
+  free(buf);
+  close(wfd);
+  close(rfd);
+
+  return 1;
+}
+