-/* save to file --> send to server :) --> T O D O <-- */
-int send_data( ) {
-
- return 1;
-}
-
-int save_to_file(char *sf,d3_lattice *d3_l,info *my_inf)
-{
- int sf_fd,c;
-
- if((sf_fd=open(sf,O_WRONLY|O_CREAT))<0)
- {
- puts("cannot open save file");
- return -1;
- }
- if(write(sf_fd,d3_l,sizeof(d3_lattice))<sizeof(d3_lattice))
- {
- puts("failed saving d3 lattice struct");
- return -1;
- }
- if(write(sf_fd,my_inf,sizeof(info))<sizeof(info))
- {
- puts("failed saving info struct");
- return-1;
- }
- c=d3_l->max_x*d3_l->max_y*d3_l->max_z;
- if(write(sf_fd,d3_l->status,c*sizeof(unsigned char))<c*sizeof(unsigned char))
- {
- puts("failed saving status of d3 lattice sites");
- return -1;
- }
- if(write(sf_fd,d3_l->extra,c*sizeof(int))<c*sizeof(int))
- {
- puts("failed saving sites concentration");
- return -1;
- }
- close(sf_fd);
-
- return 1;
-}
-
-/* load from file --> receive from server :) --> T O D O <-- */
-int receive_data( ) {
-
- return 1;
-}
-
-int load_from_file(char *lf,d3_lattice *d3_l,info *my_inf)
-{
-
- int lf_fd,c,pos,end,data,data_len,strip;
-
- if((lf_fd=open(lf,O_RDONLY))<0)
- {
- puts("cannot open load file");
- return -1;
- }
- if(read(lf_fd,d3_l,sizeof(d3_lattice))<sizeof(d3_lattice))
- {
- puts("failed reading d3 lattice struct");
- return -1;
- }
- pos=lseek(lf_fd,0,SEEK_CUR);
- printf("psition: %d (%d)\n",pos,sizeof(d3_lattice));
- data=d3_l->max_x*d3_l->max_y*d3_l->max_z;
- data_len=data*(sizeof(int)+sizeof(unsigned char));
- printf("there are %d volumes so we need %d of bytes\n",data,data_len);
- end=lseek(lf_fd,0,SEEK_END);
- c=end-pos-data_len;
- printf("end: %d => length: %d => guessed info size: %d bytes\n",end,end-pos,c);
- strip=sizeof(info)-c;
- printf("as real programs info size is %d, we strip %d bytes\n",sizeof(info),strip);
- lseek(lf_fd,pos,SEEK_SET);
- c=sizeof(info);
- if(strip>0) c-=strip;
- if(c<0)
- {
- puts("info smaller then strip size");
- return -1;
- }
- if(read(lf_fd,my_inf,c)<c)
- {
- puts("failed reading info struct");
- return-1;
- }
- if(strip>0) memset(my_inf+c,0,strip);
- if(strip<0) lseek(lf_fd,(-1*strip),SEEK_CUR);
- c=d3_l->max_x*d3_l->max_y*d3_l->max_z;
- if((d3_l->status=(unsigned char*)malloc(c*sizeof(unsigned char)))==NULL)
- {
- puts("cannot allocate status buffer");
- return -1;
- }
- if((d3_l->extra=(int *)malloc(c*sizeof(int)))==NULL)
- {
- puts("cannot allocate concentration buffer");
- return -1;
- }
- if(read(lf_fd,d3_l->status,c*sizeof(unsigned char))<c*sizeof(unsigned char))
- {
- puts("failed reading status of d3 lattice sites");
- return -1;
- }
- if(read(lf_fd,d3_l->extra,c*sizeof(int))<c*sizeof(int))
- {
- puts("failed reading sites concentration");
- return -1;
- }
- close(lf_fd);
-
- return 1;
-}
-