]> hackdaworld.org Git - physik/nlsop.git/commitdiff
added save/load function
authorhackbard <hackbard>
Wed, 14 May 2003 14:35:39 +0000 (14:35 +0000)
committerhackbard <hackbard>
Wed, 14 May 2003 14:35:39 +0000 (14:35 +0000)
nlsop.c

diff --git a/nlsop.c b/nlsop.c
index 4eb641085d8f03b5d6b51d25ac01917dc12bf48a..d646cdf9bc3af78a6c4de752edd12625c051ab45 100644 (file)
--- a/nlsop.c
+++ b/nlsop.c
@@ -164,6 +164,76 @@ int distrib_c(3d_lattice *3d_l,int t_c,double a,double b)
  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;
@@ -272,6 +342,8 @@ int main(int argc,char **argv)
   } else usage();
  }
 
+
+
+
  return 1;
 }