From: hackbard Date: Wed, 20 Jul 2005 10:33:30 +0000 (+0000) Subject: added support for starting file, added make_cryst tool X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=785bcf81e0bf1e0829f7bef13fddf194339bdd1e;p=physik%2Fnlsop.git added support for starting file, added make_cryst tool --- diff --git a/configure b/configure index 056e71a..e1f692c 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #!/bin/sh -name="nlsop_server nlsop_client nlsop_gui" +name="nlsop_server nlsop_client nlsop_gui nlsop_make_cryst" main="nlsop" #defaults diff --git a/nlsop_client.c b/nlsop_client.c index 8a1c81c..ad1c84f 100644 --- a/nlsop_client.c +++ b/nlsop_client.c @@ -59,6 +59,8 @@ char p_file[MAX_CHARS]; char n_e_file[MAX_CHARS]; char r_file[MAX_CHARS]; +char s_file[MAX_CHARS]; +int start_fd; t_net *gnet; d3_lattice *gd3_l; info *gmy_info; @@ -72,7 +74,7 @@ int nop(t_event *event,void *allineed); int usage(char *prog) { puts("usage:"); - printf("%s -i ip -p port -r/P/n random/profile/neloss file\n",prog); + printf("%s -i ip -p port -r/P/n/s random/profile/neloss/start file\n",prog); return 1; } @@ -348,6 +350,8 @@ int main(int argc,char **argv) strcpy(p_file,IMP_PROFILE); strcpy(n_e_file,NEL_PROFILE); strcpy(r_file,""); + strcpy(s_file,""); + start_fd=0; port=1025; /* parse/check argv */ @@ -372,6 +376,9 @@ int main(int argc,char **argv) case 'p': port=atoi(argv[++i]); break; + case 's': + strcpy(s_file,argv[++i]); + break; default: usage(argv[0]); return -1; @@ -383,6 +390,13 @@ int main(int argc,char **argv) return -1; } + /* try a file to start from */ + if(strcmp(s_file,"")) { + start_fd=open(s_file,O_RDONLY); + if(start_fd>0) printf("using %s as a starting file ...\n",s_file); + else printf("errors opening %s!\n",s_file); + } + /* event init */ event_init(&event,1); event_set_timeout(&event,0,0); @@ -406,6 +420,7 @@ int main(int argc,char **argv) event_start(&event,NULL,get_data_and_calc,nop); network_shutdown(&net); + if(start_fd>0) close(start_fd); return 1; } @@ -428,6 +443,7 @@ int get_data_and_calc(t_event *event,void *allineed) { u32 x_c,y_c,z_c; int i,j; int c_step; + unsigned char do_sputter; unsigned char data; t_net *net; @@ -435,6 +451,7 @@ int get_data_and_calc(t_event *event,void *allineed) { c_step=0; ne_max=0; ip_max=0; + do_sputter=1; net=gnet; gd3_l=&d3_l; @@ -481,6 +498,31 @@ int get_data_and_calc(t_event *event,void *allineed) { memset(d3_l.status,0,j*sizeof(unsigned char)); memset(d3_l.extra,0,j*sizeof(int)); } + /* check for file to start from ... */ + if(start_fd>0) { + printf("starting from a save file!\n"); + unsigned char *nullbuf; + nullbuf=(unsigned char *)malloc(sizeof(d3_lattice)); + if(read(start_fd,nullbuf,sizeof(d3_lattice))!=sizeof(d3_lattice)) { + printf("read failed (start file d3l)\n"); + return -1; + } + free(nullbuf); + nullbuf=(unsigned char *)malloc(sizeof(info)); + if(read(start_fd,nullbuf,sizeof(info))!=sizeof(info)) { + printf("read failed (start file info)\n"); + return -1; + } + free(nullbuf); + if(read(start_fd,d3_l.status,j*sizeof(unsigned char))!=j*sizeof(unsigned char)) { + printf("read failed (start file status)\n"); + return -1; + } + if(read(start_fd,d3_l.extra,j*sizeof(int))!=j*sizeof(int)) { + printf("read failed (start file extra)\n"); + return -1; + } + } } else { printf("unknown instruction, restarting ...\n"); @@ -525,7 +567,7 @@ int get_data_and_calc(t_event *event,void *allineed) { /* this should be obsolete - z is high enough - we check now! */ if(c_profile[d3_l.max_z-1]!=0) { printf("max_z (%d) too small - sputtering not possible\n",d3_l.max_z); - return -1; + do_sputter=0; } /* sputtering really possible ?*/ @@ -553,7 +595,7 @@ int get_data_and_calc(t_event *event,void *allineed) { send_data(0); dc=DC_QUIT; } - if(i%my_info.s_rate==0) sputter(&d3_l); + if((do_sputter)&(i%my_info.s_rate==0)) sputter(&d3_l); if(shut_down) { free(d3_l.status); free(d3_l.extra); diff --git a/nlsop_make_cryst.c b/nlsop_make_cryst.c new file mode 100644 index 0000000..0587020 --- /dev/null +++ b/nlsop_make_cryst.c @@ -0,0 +1,81 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include + +#include + +#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 \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; +} +