From 7b0c077e18af45b1312c35aa52efb0211d1378c5 Mon Sep 17 00:00:00 2001 From: Samo Penic <samo.penic@fe.uni-lj.si> Date: Thu, 11 Sep 2014 10:57:05 +0000 Subject: [PATCH] Command line tape options, directories and files are parsed correctly. Command line tape works. --- src/io.c | 179 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 131 insertions(+), 48 deletions(-) diff --git a/src/io.c b/src/io.c index 17adda4..d8c1009 100644 --- a/src/io.c +++ b/src/io.c @@ -1,7 +1,6 @@ #include "general.h" #include<stdio.h> #include "io.h" -#include <confuse.h> #include "vertex.h" #include "bond.h" #include<string.h> @@ -10,7 +9,7 @@ #include <dirent.h> #include "initial_distribution.h" #include "poly.h" - +#include "cell.h" #include <getopt.h> #include <sys/stat.h> #include <sys/types.h> @@ -169,8 +168,9 @@ poly_list->poly->bond */ - fwrite(vesicle->clist, sizeof(ts_cell_list),1, fh); - +// fwrite(vesicle->clist, sizeof(ts_cell_list),1, fh); +/* write tape information on vesicle */ +// fwrite(vesicle->tape,sizeof(ts_tape),1,fh); fwrite(&iteration, sizeof(ts_uint),1,fh); fclose(fh); return TS_SUCCESS; @@ -418,16 +418,12 @@ vesicle->filament_list->poly[i]->blist->bond[j]->vtx2=vesicle->filament_list->poly[i]->vlist->vtx[idx]; } } - + vesicle->tape=parsetape("tape"); // 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! - } - + vesicle->clist=init_cell_list(vesicle->tape->ncxmax, vesicle->tape->ncymax, vesicle->tape->nczmax, vesicle->tape->stepsize); + vesicle->clist->max_occupancy=8; +// vesicle->tape=(ts_tape *)malloc(sizeof(ts_tape)); +// retval=fread(vesicle->tape, sizeof(ts_tape),1,fh); retval=fread(iteration,sizeof(ts_uint),1,fh); if(retval); fclose(fh); @@ -440,9 +436,9 @@ int c, retval; struct stat sb; sprintf(command_line_args.path, "./"); //clear string; - sprintf(command_line_args.output_fullfilename,"./output.pvd"); - sprintf(command_line_args.dump_fullfilename,"./dump.bin"); - sprintf(command_line_args.tape_fullfilename,"./tape"); + sprintf(command_line_args.output_fullfilename,"output.pvd"); + sprintf(command_line_args.dump_fullfilename,"dump.bin"); + sprintf(command_line_args.tape_fullfilename,"tape"); FILE *file; while (1) @@ -455,12 +451,13 @@ {"output-file", required_argument, 0, 'o'}, {"directory", required_argument, 0, 'd'}, {"dump-filename", required_argument,0, 'f'}, + {"tape-options",required_argument,0,'c'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long (argc, argv, "d:f:o:t:", + c = getopt_long (argc, argv, "d:f:o:t:c:", long_options, &option_index); /* Detect the end of the options. */ @@ -479,25 +476,14 @@ printf ("\n"); break; - case 't': - //check if tape exists. If not, fail immediately. - if (stat(optarg, &sb) == -1) { - ts_fprintf(stderr,"Tape '%s' does not exist!\n",optarg); - fatal("Please select correct tape",1); - } else { + case 'c': + strcpy(command_line_args.tape_opts,optarg); + break; + case 't': //tape strcpy(command_line_args.tape_fullfilename,optarg); - } break; - case 'o': - //set filename of master output file - if ((file = fopen(optarg, "w")) == NULL) { - fprintf(stderr,"Could not create output file!\n"); - fatal("Please specify correct output file",1); - - } else { - fclose(file); - } + case 'o': //set filename of master pvd output file strcpy(command_line_args.output_fullfilename, optarg); break; @@ -522,14 +508,6 @@ break; case 'f': - //check if dump file specified exists. Defaults to dump.bin - if ((file = fopen(optarg, "w")) == NULL) { - fprintf(stderr,"Could not create dump file!\n"); - fatal("Please specify correct dump file",1); - - } else { - fclose(file); - } strcpy(command_line_args.dump_fullfilename, optarg); break; @@ -545,6 +523,53 @@ } } +//Here we set correct values for full filenames! + char *buffer=(char *)malloc(10000*sizeof(char)); + //correct the path and add trailing / + if(command_line_args.path[strlen(command_line_args.path)-1]!='/') strcat(command_line_args.path,"/"); + +/* master pvd output file */ + strcpy(buffer,command_line_args.path); + strcat(buffer,command_line_args.output_fullfilename); + if ((file = fopen(buffer, "w")) == NULL) { + fprintf(stderr,"Could not create output file %s!\n", buffer); + fatal("Please specify correct output file or check permissions of the file",1); + + } else { + fclose(file); + strcpy(command_line_args.output_fullfilename,buffer); + } + +/* tape file */ + strcpy(buffer,command_line_args.path); + strcat(buffer,command_line_args.tape_fullfilename); + if (stat(buffer, &sb) == -1) { + ts_fprintf(stderr,"Tape '%s' does not exist!\n",buffer); + fatal("Please select correct tape or check permissions of the file",1); + } else { + strcpy(command_line_args.tape_fullfilename,buffer); + } + + +/* dump file */ + strcpy(buffer,command_line_args.path); + strcat(buffer,command_line_args.dump_fullfilename); + //check if dump file exist first. + if (stat(buffer, &sb) == -1) { + //no dump file. check if we can create one. + if ((file = fopen(buffer, "w")) == NULL) { + fprintf(stderr,"Could not create dump file '%s'!\n",buffer); + fatal("Please specify correct dump file or check permissions of the file",1); + } else { + fclose(file); + //good, file is writeable. delete it for now. + remove(buffer); + } + } + strcpy(command_line_args.dump_fullfilename, buffer); + + + free(buffer); return TS_SUCCESS; } @@ -952,15 +977,8 @@ ts_tape *parsetape(char *filename){ - // long int nshell=17,ncxmax=60, ncymax=60, nczmax=60, npoly=10, nmono=20, pswitch=0; // THIS IS DUE TO CONFUSE BUG! ts_tape *tape=(ts_tape *)calloc(1,sizeof(ts_tape)); tape->multiprocessing=calloc(255,sizeof(char)); - /* long int brezveze0=1; - long int brezveze1=1; - long int brezveze2=1; - ts_double xk0=25.0, dmax=1.67,stepsize=0.15,kspring=800.0,pressure=0.0; - long int iter=1000, init=1000, mcsw=1000; -*/ cfg_opt_t opts[] = { CFG_SIMPLE_INT("nshell", &tape->nshell), @@ -970,8 +988,11 @@ CFG_SIMPLE_INT("nfono",&tape->nfono), CFG_SIMPLE_INT("R_nucleus",&tape->R_nucleus), CFG_SIMPLE_FLOAT("dmax", &tape->dmax), + CFG_SIMPLE_FLOAT("dmin_interspecies", &tape->dmin_interspecies), CFG_SIMPLE_FLOAT("xk0",&tape->xk0), CFG_SIMPLE_INT("pswitch",&tape->pswitch), + CFG_SIMPLE_INT("constvolswitch",&tape->constvolswitch), + CFG_SIMPLE_FLOAT("constvolprecision",&tape->constvolprecision), CFG_SIMPLE_FLOAT("pressure",&tape->pressure), CFG_SIMPLE_FLOAT("k_spring",&tape->kspring), CFG_SIMPLE_FLOAT("xi",&tape->xi), @@ -987,6 +1008,7 @@ CFG_SIMPLE_INT("smp_cores",&tape->brezveze0), CFG_SIMPLE_INT("cluster_nodes",&tape->brezveze1), CFG_SIMPLE_INT("distributed_processes",&tape->brezveze2), + CFG_SIMPLE_INT("spherical_harmonics_coefficients",&tape->shc), CFG_END() }; cfg_t *cfg; @@ -1000,6 +1022,8 @@ fatal("Invalid tape!",100); } + /* here we override all values read from tape with values from commandline*/ + getcmdline_tape(cfg,command_line_args.tape_opts); cfg_free(cfg); @@ -1015,6 +1039,65 @@ } + +ts_bool getcmdline_tape(cfg_t *cfg, char *opts){ + + char *commands, *backup, *saveptr, *saveopptr, *command, *operator[2]; + ts_uint i,j; + commands=(char *)malloc(10000*sizeof(char)); + backup=commands; //since the pointer to commands will be lost, we acquire a pointer that will serve as backup. + strcpy(commands,opts); + for(i=0; ;i++, commands=NULL){ + //breaks comma separated list of commands into specific commands. + command=strtok_r(commands,",",&saveptr); + if(command==NULL) break; +// fprintf(stdout,"Command %d: %s\n",i,command); + //extracts name of command and value of command into operator[2] array. + for(j=0; j<2;j++,command=NULL){ + operator[j]=strtok_r(command,"=",&saveopptr); + if(operator[j]==NULL) break; +// fprintf(stdout," ---> Operator %d: %s\n",j,operator[j]); + } + //1. check: must have 2 operators. + if(j!=2) fatal("Error. Command line tape options are not formatted properly",1); + + // cfg_setstr(cfg,operator[0],operator[1]); + cmdline_to_tape(cfg,operator[0],operator[1]); + //2. check: must be named properly. + //3. check: must be of right format (integer, double, string, ...) + + } + free(backup); + return TS_SUCCESS; +} + + +ts_bool cmdline_to_tape(cfg_t *cfg, char *key, char *val){ + + cfg_opt_t *cfg_opt=cfg_getopt(cfg,key); + if(cfg_opt==NULL) fatal("Commandline tape option not recognised",1); //return TS_FAIL; + switch (cfg_opt->type){ + case CFGT_INT: + cfg_setint(cfg,key,atol(val)); + break; + case CFGT_FLOAT: + cfg_setfloat(cfg,key,atof(val)); + break; +/* case CFGT_BOOL: + cfg_setbool(cfg,operator[0],operator[1]); + break; */ + case CFGT_STR: + cfg_setstr(cfg,key,val); + break; + default: + break; + + } + return TS_SUCCESS; +} + + + ts_bool read_geometry_file(char *fname, ts_vesicle *vesicle){ FILE *fh; ts_uint i, nvtx,nedges,ntria; -- Gitblit v1.9.3