Trisurf Monte Carlo simulator
Samo Penic
2014-03-08 0fb40c28545e8418469cf7d3600547dfe4083edb
Merged with dump-state. Added some arg switches that need to be inished
5 files modified
444 ■■■■■ changed files
missing 295 ●●●●● patch | view | raw | blame | history
src/io.c 107 ●●●●● patch | view | raw | blame | history
src/io.h 12 ●●●●● patch | view | raw | blame | history
src/main.c 29 ●●●●● patch | view | raw | blame | history
src/timestep.c 1 ●●●● patch | view | raw | blame | history
missing
@@ -1,10 +1,20 @@
#! /bin/sh
<<<<<<< HEAD
# Common wrapper for a few potentially missing GNU programs.
scriptversion=2012-06-26.16; # UTC
# Copyright (C) 1996-2013 Free Software Foundation, Inc.
# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
=======
# Common stub for a few missing GNU programs while installing.
scriptversion=2012-01-06.13; # UTC
# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
# 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
>>>>>>> dump-state
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -25,6 +35,7 @@
# the same distribution terms that you use for the rest of that program.
if test $# -eq 0; then
<<<<<<< HEAD
  echo 1>&2 "Try '$0 --help' for more information"
  exit 1
fi
@@ -41,17 +52,59 @@
    # Back-compat with the calling convention used by older automake.
    shift
    ;;
=======
  echo 1>&2 "Try \`$0 --help' for more information"
  exit 1
fi
run=:
sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
sed_minuso='s/.* -o \([^ ]*\).*/\1/p'
# In the cases where this matters, `missing' is being run in the
# srcdir already.
if test -f configure.ac; then
  configure_ac=configure.ac
else
  configure_ac=configure.in
fi
msg="missing on your system"
case $1 in
--run)
  # Try to run requested program, and just exit if it succeeds.
  run=
  shift
  "$@" && exit 0
  # Exit code 63 means version mismatch.  This often happens
  # when the user try to use an ancient version of a tool on
  # a file that requires a minimum version.  In this case we
  # we should proceed has if the program had been absent, or
  # if --run hadn't been passed.
  if test $? = 63; then
    run=:
    msg="probably too old"
  fi
  ;;
>>>>>>> dump-state
  -h|--h|--he|--hel|--help)
    echo "\
$0 [OPTION]... PROGRAM [ARGUMENT]...
<<<<<<< HEAD
Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
to PROGRAM being missing or too old.
=======
Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
error status if there is no known handling for PROGRAM.
>>>>>>> dump-state
Options:
  -h, --help      display this help and exit
  -v, --version   output version information and exit
<<<<<<< HEAD
Supported PROGRAM values:
  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
@@ -59,6 +112,25 @@
Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
'g' are ignored when checking the name.
=======
  --run           try to run the given command, and emulate it if it fails
Supported PROGRAM values:
  aclocal      touch file \`aclocal.m4'
  autoconf     touch file \`configure'
  autoheader   touch file \`config.h.in'
  autom4te     touch the output file, or create a stub one
  automake     touch all \`Makefile.in' files
  bison        create \`y.tab.[ch]', if possible, from existing .[ch]
  flex         create \`lex.yy.c', if possible, from existing .c
  help2man     touch the output file
  lex          create \`lex.yy.c', if possible, from existing .c
  makeinfo     touch the output file
  yacc         create \`y.tab.[ch]', if possible, from existing .[ch]
Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and
\`g' are ignored when checking the name.
>>>>>>> dump-state
Send bug reports to <bug-automake@gnu.org>."
    exit $?
@@ -70,13 +142,19 @@
    ;;
  -*)
<<<<<<< HEAD
    echo 1>&2 "$0: unknown '$1' option"
    echo 1>&2 "Try '$0 --help' for more information"
=======
    echo 1>&2 "$0: Unknown \`$1' option"
    echo 1>&2 "Try \`$0 --help' for more information"
>>>>>>> dump-state
    exit 1
    ;;
esac
<<<<<<< HEAD
# Run the given program, remember its exit status.
"$@"; st=$?
@@ -205,6 +283,223 @@
# Propagate the correct exit status (expected to be 127 for a program
# not found, 63 for a program that failed due to version mismatch).
exit $st
=======
# normalize program name to check for.
program=`echo "$1" | sed '
  s/^gnu-//; t
  s/^gnu//; t
  s/^g//; t'`
# Now exit if we have it, but it failed.  Also exit now if we
# don't have it and --version was passed (most likely to detect
# the program).  This is about non-GNU programs, so use $1 not
# $program.
case $1 in
  lex*|yacc*)
    # Not GNU programs, they don't have --version.
    ;;
  *)
    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
       # We have it, but it failed.
       exit 1
    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
       # Could not run --version or --help.  This is probably someone
       # running `$TOOL --version' or `$TOOL --help' to check whether
       # $TOOL exists and not knowing $TOOL uses missing.
       exit 1
    fi
    ;;
esac
# If it does not exist, or fails to run (possibly an outdated version),
# try to emulate it.
case $program in
  aclocal*)
    echo 1>&2 "\
WARNING: \`$1' is $msg.  You should only need it if
         you modified \`acinclude.m4' or \`${configure_ac}'.  You might want
         to install the \`Automake' and \`Perl' packages.  Grab them from
         any GNU archive site."
    touch aclocal.m4
    ;;
  autoconf*)
    echo 1>&2 "\
WARNING: \`$1' is $msg.  You should only need it if
         you modified \`${configure_ac}'.  You might want to install the
         \`Autoconf' and \`GNU m4' packages.  Grab them from any GNU
         archive site."
    touch configure
    ;;
  autoheader*)
    echo 1>&2 "\
WARNING: \`$1' is $msg.  You should only need it if
         you modified \`acconfig.h' or \`${configure_ac}'.  You might want
         to install the \`Autoconf' and \`GNU m4' packages.  Grab them
         from any GNU archive site."
    files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
    test -z "$files" && files="config.h"
    touch_files=
    for f in $files; do
      case $f in
      *:*) touch_files="$touch_files "`echo "$f" |
                       sed -e 's/^[^:]*://' -e 's/:.*//'`;;
      *) touch_files="$touch_files $f.in";;
      esac
    done
    touch $touch_files
    ;;
  automake*)
    echo 1>&2 "\
WARNING: \`$1' is $msg.  You should only need it if
         you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
         You might want to install the \`Automake' and \`Perl' packages.
         Grab them from any GNU archive site."
    find . -type f -name Makefile.am -print |
       sed 's/\.am$/.in/' |
       while read f; do touch "$f"; done
    ;;
  autom4te*)
    echo 1>&2 "\
WARNING: \`$1' is needed, but is $msg.
         You might have modified some files without having the
         proper tools for further handling them.
         You can get \`$1' as part of \`Autoconf' from any GNU
         archive site."
    file=`echo "$*" | sed -n "$sed_output"`
    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
    if test -f "$file"; then
    touch $file
    else
    test -z "$file" || exec >$file
    echo "#! /bin/sh"
    echo "# Created by GNU Automake missing as a replacement of"
    echo "#  $ $@"
    echo "exit 0"
    chmod +x $file
    exit 1
    fi
    ;;
  bison*|yacc*)
    echo 1>&2 "\
WARNING: \`$1' $msg.  You should only need it if
         you modified a \`.y' file.  You may need the \`Bison' package
         in order for those modifications to take effect.  You can get
         \`Bison' from any GNU archive site."
    rm -f y.tab.c y.tab.h
    if test $# -ne 1; then
        eval LASTARG=\${$#}
    case $LASTARG in
    *.y)
        SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
        if test -f "$SRCFILE"; then
             cp "$SRCFILE" y.tab.c
        fi
        SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
        if test -f "$SRCFILE"; then
             cp "$SRCFILE" y.tab.h
        fi
      ;;
    esac
    fi
    if test ! -f y.tab.h; then
    echo >y.tab.h
    fi
    if test ! -f y.tab.c; then
    echo 'main() { return 0; }' >y.tab.c
    fi
    ;;
  lex*|flex*)
    echo 1>&2 "\
WARNING: \`$1' is $msg.  You should only need it if
         you modified a \`.l' file.  You may need the \`Flex' package
         in order for those modifications to take effect.  You can get
         \`Flex' from any GNU archive site."
    rm -f lex.yy.c
    if test $# -ne 1; then
        eval LASTARG=\${$#}
    case $LASTARG in
    *.l)
        SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
        if test -f "$SRCFILE"; then
             cp "$SRCFILE" lex.yy.c
        fi
      ;;
    esac
    fi
    if test ! -f lex.yy.c; then
    echo 'main() { return 0; }' >lex.yy.c
    fi
    ;;
  help2man*)
    echo 1>&2 "\
WARNING: \`$1' is $msg.  You should only need it if
     you modified a dependency of a manual page.  You may need the
     \`Help2man' package in order for those modifications to take
     effect.  You can get \`Help2man' from any GNU archive site."
    file=`echo "$*" | sed -n "$sed_output"`
    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
    if test -f "$file"; then
    touch $file
    else
    test -z "$file" || exec >$file
    echo ".ab help2man is required to generate this page"
    exit $?
    fi
    ;;
  makeinfo*)
    echo 1>&2 "\
WARNING: \`$1' is $msg.  You should only need it if
         you modified a \`.texi' or \`.texinfo' file, or any other file
         indirectly affecting the aspect of the manual.  The spurious
         call might also be the consequence of using a buggy \`make' (AIX,
         DU, IRIX).  You might want to install the \`Texinfo' package or
         the \`GNU make' package.  Grab either from any GNU archive site."
    # The file to touch is that specified with -o ...
    file=`echo "$*" | sed -n "$sed_output"`
    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
    if test -z "$file"; then
      # ... or it is the one specified with @setfilename ...
      infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
      file=`sed -n '
    /^@setfilename/{
      s/.* \([^ ]*\) *$/\1/
      p
      q
    }' $infile`
      # ... or it is derived from the source name (dir/f.texi becomes f.info)
      test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
    fi
    # If the file does not exist, the user really needs makeinfo;
    # let's fail without touching anything.
    test -f $file || exit 1
    touch $file
    ;;
  *)
    echo 1>&2 "\
WARNING: \`$1' is needed, and is $msg.
         You might have modified some files without having the
         proper tools for further handling them.  Check the \`README' file,
         it often tells you about the needed prerequisites for installing
         this package.  You may also peek at any GNU archive site, in case
         some other package would contain this missing \`$1' program."
    exit 1
    ;;
esac
exit 0
>>>>>>> dump-state
# Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp)
src/io.c
@@ -11,8 +11,11 @@
#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){
@@ -320,6 +323,106 @@
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);
src/io.h
@@ -1,6 +1,18 @@
#ifndef _IO_H
#define _IO_H
/** @ Global variables for I/O operations like filenames etc. */
/*static char mastername[1024];
static char prefixname[1024];
static ts_bool restore=0;
static char tape[1024]; */
char path[1024];
int force_from_tape;
ts_bool parse_args(int argc, char **argv);
/** @brief Prints the position of vertices for the whole list
 *  
 *  The function is meant more or less as a debug tool, but can be used in production
src/main.c
@@ -21,6 +21,10 @@
int main(int argv, char *argc[]){
ts_uint inititer,mcsweeps, iterations;
ts_vesicle *vesicle, *vesicle1;
parse_args(argv,argc);
/* THIS SHOULD GO INTO UNIT TEST
ts_bool retval;
    ts_vertex_list *vlist=init_vertex_list(5);
@@ -64,19 +68,22 @@
vtx_list_free(vlist1);
printf("Tests complete.\n");
*/
if(force_from_tape){
ts_fprintf(stdout,"****************************************************\n");
ts_fprintf(stdout,"**** Reinitializing initial geometry from tape *****\n");
ts_fprintf(stdout,"****************************************************\n\n");
vesicle=parsetape(&mcsweeps, &inititer, &iterations);
} else {
ts_fprintf(stdout,"**********************************************************************\n");
ts_fprintf(stdout,"**** Recreating vesicle from dump file and continuing simulation *****\n");
ts_fprintf(stdout,"**********************************************************************\n\n");
vesicle1=parsetape(&mcsweeps, &inititer, &iterations);
/*Testing */
//vesicle->poly_list=init_poly_list(1400,20,vesicle->vlist);
//poly_list_free(vesicle->poly_list);
/*End testing*/
dump_state(vesicle1);
vesicle=restore_state();
//vesicle_free(vesicle1);
run_simulation(vesicle1, mcsweeps, inititer, iterations);
vesicle_free(vesicle1);
}
run_simulation(vesicle, mcsweeps, inititer, iterations);
write_master_xml_file("test.pvd");
write_dout_fcompat_file(vesicle,"dout");
vesicle_free(vesicle);
src/timestep.c
@@ -22,6 +22,7 @@
        centermass(vesicle);
        cell_occupation(vesicle);
        ts_fprintf(stdout,"Done %d out of %d iterations (x %d MC sweeps).\n",i+1,inititer+iterations,mcsweeps);
            dump_state(vesicle);
        if(i>inititer){
            write_vertex_xml_file(vesicle,i-inititer);
        }