| | |
| | | #include "initial_distribution.h" |
| | | #include "poly.h" |
| | | |
| | | |
| | | |
| | | #include <getopt.h> |
| | | #include <sys/stat.h> |
| | | #include <sys/types.h> |
| | | #include <dirent.h> |
| | | #include <errno.h> |
| | | /** DUMP STATE TO DISK DRIVE **/ |
| | | |
| | | ts_bool dump_state(ts_vesicle *vesicle){ |
| | |
| | | FILE *fh=fopen("dump.bin","wb"); |
| | | |
| | | /* dump vesicle */ |
| | | fwrite(vesicle, sizeof(vesicle),1,fh); |
| | | fwrite(vesicle, sizeof(ts_vesicle),1,fh); |
| | | /* dump vertex list */ |
| | | fwrite(vesicle->vlist, sizeof(ts_vertex_list),1,fh); |
| | | /* dump bond list */ |
| | |
| | | poly_list->poly->bond |
| | | */ |
| | | |
| | | fwrite(vesicle->clist, sizeof(ts_cell_list),1, fh); |
| | | |
| | | fclose(fh); |
| | | return TS_SUCCESS; |
| | | } |
| | |
| | | /* we restore all the data from the dump */ |
| | | /* restore vesicle */ |
| | | ts_vesicle *vesicle=(ts_vesicle *)calloc(1,sizeof(ts_vesicle)); |
| | | retval=fread(vesicle, sizeof(vesicle),1,fh); |
| | | retval=fread(vesicle, sizeof(ts_vesicle),1,fh); |
| | | // fprintf(stderr,"was here! %e\n",vesicle->dmax); |
| | | |
| | | /* restore vertex list */ |
| | | vesicle->vlist=(ts_vertex_list *)malloc(sizeof(ts_vertex_list)); |
| | | retval=fread(vesicle->vlist, sizeof(ts_vertex_list),1,fh); |
| | |
| | | for(i=0;i<vesicle->tlist->n;i++){ |
| | | vesicle->tlist->tria[i]=(ts_triangle *)malloc(sizeof(ts_triangle)); |
| | | } |
| | | |
| | | /*restore vertices*/ |
| | | /* prerequisity. Vertices must be malloced before vertexes are recreated */ |
| | | vesicle->vlist->vtx=(ts_vertex **)calloc(vesicle->vlist->n,sizeof(ts_vertex *)); |
| | | for(i=0;i<vesicle->vlist->n;i++){ |
| | | for(i=0;i<vesicle->vlist->n;i++){ |
| | | vesicle->vlist->vtx[i]=(ts_vertex *)malloc(sizeof(ts_vertex)); |
| | | } |
| | | /*restore vertices*/ |
| | | for(i=0;i<vesicle->vlist->n;i++){ |
| | | retval=fread(vesicle->vlist->vtx[i],sizeof(ts_vertex),1,fh); |
| | | /*restore neigh, bond, tristar. Ignoring cell */ |
| | | vesicle->vlist->vtx[i]->neigh=(ts_vertex **)calloc(vesicle->vlist->vtx[i]->neigh_no, sizeof(ts_vertex *)); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | // recreating space for cells // |
| | | vesicle->clist=(ts_cell_list *)malloc(sizeof(ts_cell_list)); |
| | | retval=fread(vesicle->clist, sizeof(ts_cell_list), 1,fh); |
| | | vesicle->clist->cell=(ts_cell **)malloc(sizeof(ts_cell *)*vesicle->clist->ncmax[0]*vesicle->clist->ncmax[1]*vesicle->clist->ncmax[2]); |
| | | for(i=0;i<vesicle->clist->ncmax[0]*vesicle->clist->ncmax[1]*vesicle->clist->ncmax[2];i++){ |
| | | vesicle->clist->cell[i]=(ts_cell *)calloc(1,sizeof(ts_cell)); |
| | | vesicle->clist->cell[i]->idx=i+1; // We enumerate cells! Probably never required! |
| | | } |
| | | |
| | | if(retval); |
| | | fclose(fh); |
| | |
| | | |
| | | |
| | | |
| | | ts_bool parse_args(int argc, char **argv){ |
| | | int c, retval; |
| | | DIR *dir; |
| | | path[0]=0; |
| | | while (1) |
| | | { |
| | | static struct option long_options[] = |
| | | { |
| | | {"force-from-tape", no_argument, &force_from_tape, 1}, |
| | | {"tape", no_argument, 0, 't'}, |
| | | {"output-file", required_argument, 0, 'o'}, |
| | | {"directory", required_argument, 0, 'd'}, |
| | | {"dump-file", required_argument,0, 'f'}, |
| | | {0, 0, 0, 0} |
| | | }; |
| | | /* getopt_long stores the option index here. */ |
| | | int option_index = 0; |
| | | |
| | | c = getopt_long (argc, argv, "d:fot", |
| | | long_options, &option_index); |
| | | |
| | | /* Detect the end of the options. */ |
| | | if (c == -1) |
| | | break; |
| | | |
| | | switch (c) |
| | | { |
| | | case 0: |
| | | /* If this option set a flag, do nothing else now. */ |
| | | if (long_options[option_index].flag != 0) |
| | | break; |
| | | printf ("option %s", long_options[option_index].name); |
| | | if (optarg) |
| | | printf (" with arg %s", optarg); |
| | | printf ("\n"); |
| | | break; |
| | | |
| | | case 't': |
| | | //check if tape exists. If not, fail immediately. |
| | | puts ("option -t\n"); |
| | | break; |
| | | |
| | | case 'o': |
| | | //set filename of master output file |
| | | printf ("option -o with value `%s'\n", optarg); |
| | | break; |
| | | |
| | | case 'd': |
| | | //check if directory exists. If not create one. If creation is |
| | | //successful, set directory for output files. |
| | | //printf ("option -d with value `%s'\n", optarg); |
| | | dir = opendir(optarg); |
| | | if (dir) |
| | | { |
| | | /* Directory exists. */ |
| | | closedir(dir); |
| | | } |
| | | else if (ENOENT == errno) |
| | | { |
| | | /* Directory does not exist. */ |
| | | retval=mkdir(optarg, 0700); |
| | | if(retval){ |
| | | fatal("Could not create requested directory. Check if you have permissions",1); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | /* opendir() failed for some other reason. */ |
| | | fatal("Could not check if directory exists. Reason unknown",1); |
| | | } |
| | | ts_fprintf(stdout,"\n*** Using output directory: %s\n\n", optarg); |
| | | // sprintf(path,"%s", optarg); |
| | | strcpy(path, optarg); |
| | | // ts_fprintf(stdout,"ok!\n"); |
| | | |
| | | break; |
| | | |
| | | case 'f': |
| | | //check if dump file specified exists. Defaults to dump.bin |
| | | break; |
| | | |
| | | case '?': |
| | | /* getopt_long already printed an error message. */ |
| | | |
| | | ts_fprintf(stderr,"\n\nhere comes the help.\n\n"); |
| | | fatal("Ooops, read help first",1); |
| | | break; |
| | | |
| | | default: |
| | | exit (1); |
| | | } |
| | | } |
| | | |
| | | return TS_SUCCESS; |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | ts_bool print_vertex_list(ts_vertex_list *vlist){ |
| | | ts_uint i; |
| | | printf("Number of vertices: %u\n",vlist->n); |