From: hackbard Date: Wed, 14 May 2003 14:35:39 +0000 (+0000) Subject: added save/load function X-Git-Tag: fpb~59 X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=72a665941269353574e0fd9effb31c19cdac68e3;p=physik%2Fnlsop.git added save/load function --- diff --git a/nlsop.c b/nlsop.c index 4eb6410..d646cdf 100644 --- 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))max_x*d3_l->max_y*d3_l->max_z; + if(write(sf_fd,3d_l->status,c*sizeof(unsigned char)extra,c*sizeof(int)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))extra,c*sizeof(int))