return 1;
}
+int save_to_file(char *sf,3d_lattice *3d_l)
+{
+ 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,3d_l,sizeof(3d_lattice))<sizeof(3d_lattice))
+ {
+ puts("failed saving 3d lattice struct");
+ return -1;
+ }
+ c=d3_l->max_x*d3_l->max_y*d3_l->max_z;
+ if(write(sf_fd,3d_l->status,c*sizeof(unsigned char)<c*sizeof(unsigned char))
+ {
+ puts("failed saving status of 3d lattice sites");
+ return -1;
+ }
+ if(write(sf_fd,3d_l->extra,c*sizeof(int)<c*sizeof(int))
+ {
+ puts("failed saving sites concentration");
+ return -1;
+ }
+ close(sf_fd);
+
+ return 1;
+}
+
+int load_from_file(char *lf,3d_lattice *3d_l)
+{
+ int lf_fd,c;
+
+ if((lf_fd=open(lf,O_RDONLY))<0)
+ {
+ puts("cannot open load file");
+ return -1;
+ }
+ if(read(lf_fd,3d_l,sizeof(3d_lattice))<sizeof(3d_lattice))
+ {
+ puts("failed reading d3 lattice struct");
+ return -1;
+ }
+ 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,3d_l->status,c*sizeof(unsigned char))<c*sizeof(unsigned char))
+ {
+ puts("failed reading status of 3d lattice sites");
+ return -1;
+ }
+ if(read(lf_fd,3d_l->extra,c*sizeof(int))<c*sizeof(int))
+ {
+ puts("failed reading sites concentration");
+ return -1;
+ }
+ close(lf_fd);
+
+ return 1;
+}
+
int main(int argc,char **argv)
{
u32 max_x,max_y,max_z,x,y,z,x_c,y_c,z_c;
} else usage();
}
-
+
+
+
return 1;
}