From 698ae18f535c3e388b6ebcdca1582005a29ff2f2 Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@fe.uni-lj.si>
Date: Mon, 29 Feb 2016 11:52:16 +0000
Subject: [PATCH] Tape is in the dump and successfully restored.

---
 src/snapshot.c             |    6 +-
 src/initial_distribution.h |    2 
 src/io.c                   |   16 +++++++
 src/initial_distribution.c |   12 ++++-
 src/restore.h              |    1 
 src/restore.c              |   21 +++++++++-
 src/io.h                   |    3 +
 7 files changed, 49 insertions(+), 12 deletions(-)

diff --git a/src/initial_distribution.c b/src/initial_distribution.c
index 35d533d..3af821d 100644
--- a/src/initial_distribution.c
+++ b/src/initial_distribution.c
@@ -39,11 +39,17 @@
 
 ts_vesicle *create_vesicle_from_tape(ts_tape *tape){
 	ts_vesicle *vesicle;
-	ts_vertex *vtx;
 
 	vesicle=initial_distribution_dipyramid(tape->nshell,tape->ncxmax,tape->ncymax,tape->nczmax,tape->stepsize);
-    vesicle->tape=tape;
+    	vesicle->tape=tape;
+	set_vesicle_values_from_tape(vesicle);
+	return vesicle;
+}
+
+ts_bool set_vesicle_values_from_tape(ts_vesicle *vesicle){
 	// Nucleus:
+	ts_vertex *vtx;
+	ts_tape *tape=vesicle->tape;
 	vesicle->R_nucleus=tape->R_nucleus*tape->R_nucleus;
 
 	vesicle->clist->dmin_interspecies = tape->dmin_interspecies*tape->dmin_interspecies;
@@ -101,7 +107,7 @@
     else {
         vesicle->sphHarmonics=NULL;
     }
-    return vesicle;
+    return TS_SUCCESS;
 
 }
 
diff --git a/src/initial_distribution.h b/src/initial_distribution.h
index 20bbf18..39815d9 100644
--- a/src/initial_distribution.h
+++ b/src/initial_distribution.h
@@ -13,7 +13,7 @@
 ts_vesicle *initial_distribution_dipyramid(ts_uint nshell, ts_uint ncmax1, ts_uint ncmax2, ts_uint ncmax3, ts_double stepsize);
 
 ts_vesicle *create_vesicle_from_tape(ts_tape *tape);
-
+ts_bool set_vesicle_values_from_tape(ts_vesicle *vesicle);
 /** Sets the initial position of the vertexes to dipyramid
  *
  *      @param *vlist is a pointer to list of vertices
diff --git a/src/io.c b/src/io.c
index e7461d6..0a6cd57 100644
--- a/src/io.c
+++ b/src/io.c
@@ -1000,6 +1000,20 @@
 
 
 ts_tape *parsetape(char *filename){
+	FILE *fd = fopen (filename, "r");
+	long length;
+	size_t size;
+	fseek (fd, 0, SEEK_END);
+  	length = ftell (fd);
+	fseek (fd, 0, SEEK_SET);
+	size=fread (tapetxt, 1, length, fd);
+	fclose(fd);
+	if(size);
+	ts_tape *tape=parsetapebuffer(tapetxt);
+	return tape;
+}
+
+ts_tape *parsetapebuffer(char *buffer){
     ts_tape *tape=(ts_tape *)calloc(1,sizeof(ts_tape));
     tape->multiprocessing=calloc(255,sizeof(char));
 
@@ -1038,7 +1052,7 @@
     cfg_t *cfg;    
     ts_uint retval;
     cfg = cfg_init(opts, 0);
-    retval=cfg_parse(cfg, filename);
+    retval=cfg_parse_buf(cfg, buffer);
     if(retval==CFG_FILE_ERROR){
 	fatal("No tape file.",100);
 	}
diff --git a/src/io.h b/src/io.h
index 69de4e9..6c1e18a 100644
--- a/src/io.h
+++ b/src/io.h
@@ -7,7 +7,7 @@
 static ts_bool restore=0;
 static char tape[1024]; */
 int force_from_tape;
-
+char tapetxt[128000]; //stores text file of the tape
 typedef struct{
 	ts_int force_from_tape;
 	ts_int reset_iteration_count;
@@ -76,6 +76,7 @@
 ts_bool write_pov_file(ts_vesicle *vesicle, char *filename);
 
 ts_tape *parsetape(char *filename);
+ts_tape *parsetapebuffer(char *buffer);
 ts_bool tape_free(ts_tape *tape);
 ts_bool getcmdline_tape(cfg_t *cfg, char *opts);
 ts_bool cmdline_to_tape(cfg_t *cfg, char *key, char *val);
diff --git a/src/restore.c b/src/restore.c
index aae6cb0..5db794e 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -14,12 +14,12 @@
 #include "energy.h"
 #include "poly.h"
 #include "initial_distribution.h"
+#include "io.h"
 
 ts_bool parseDump(char *dumpfname) {
 	xmlDocPtr doc;
 	xmlNodePtr cur, cur1,cur2;
 	ts_vesicle *vesicle=NULL;
-
 	doc = xmlParseFile(dumpfname);
 	
 	if (doc == NULL ) {
@@ -38,6 +38,11 @@
 	
 	cur = cur->xmlChildrenNode;
 	while (cur != NULL) {
+
+		if ((!xmlStrcmp(cur->name, (const xmlChar *)"tape"))){
+			setGlobalTapeTXTfromTapeTag(doc, cur);
+		}
+
 		if ((!xmlStrcmp(cur->name, (const xmlChar *)"trisurf"))){
 			vesicle=parseTrisurfTag(doc, cur);
 		}
@@ -84,6 +89,12 @@
 	return TS_SUCCESS;
 }
 
+ts_bool setGlobalTapeTXTfromTapeTag(xmlDocPtr doc, xmlNodePtr cur){
+	xmlChar *tape = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+	strcpy(tapetxt,(char *)tape);
+	xmlFree(tape);
+	return TS_SUCCESS;
+}
 
 
 /* this is a parser of additional data in xml */
@@ -129,8 +140,10 @@
 	nvtx = xmlGetProp(cur, (xmlChar *)"nvtx");
 	npoly=xmlGetProp(cur, (xmlChar *)"npoly");
 	nfono=xmlGetProp(cur, (xmlChar *)"nfono");
-	fprintf(stderr,"nvtx=%u\n",atoi((char *)nvtx));
-	ts_vesicle *vesicle=init_vesicle(atoi((char *)nvtx),10,10,10,0.1);
+	ts_tape *tape=parsetapebuffer(tapetxt);
+	//fprintf(stderr,"nvtx=%u\n",atoi((char *)nvtx));
+	//TODO: check if nvtx is in agreement with nshell from tape
+	ts_vesicle *vesicle=init_vesicle(atoi((char *)nvtx),tape->ncxmax,tape->ncymax,tape->nczmax,tape->stepsize);
 	//vesicle->poly_list=init_poly_list(atoi((char *)npoly),atoi((char *)nmono), vesicle->vlist, vesicle);
 	xmlFree(nvtx);
 	xmlFree(npoly);
@@ -155,6 +168,8 @@
 	}
 
 
+	vesicle->tape=tape;
+	set_vesicle_values_from_tape(vesicle);
 
 	return vesicle;
 }
diff --git a/src/restore.h b/src/restore.h
index 16efff2..4c97a09 100644
--- a/src/restore.h
+++ b/src/restore.h
@@ -3,6 +3,7 @@
 
 ts_bool parseDump(char *dumpfname);
 ts_vesicle *parseTrisurfTag(xmlDocPtr doc, xmlNodePtr cur);
+ts_bool setGlobalTapeTXTfromTapeTag(xmlDocPtr doc, xmlNodePtr cur);
 ts_bool parseTrisurfVtxn(ts_vertex_list *vlist, xmlDocPtr doc, xmlNodePtr cur);
 ts_bool parseTrisurfTria(ts_vesicle *vesicle, xmlDocPtr doc, xmlNodePtr cur);
 ts_bool parseTrisurfTriaNeigh(ts_vesicle *vesicle, xmlDocPtr doc, xmlNodePtr cur);
diff --git a/src/snapshot.c b/src/snapshot.c
index 12bb19a..177557d 100644
--- a/src/snapshot.c
+++ b/src/snapshot.c
@@ -7,7 +7,7 @@
 #include<inttypes.h>
 #include<config.h>
 #include <time.h>
-
+#include "io.h"
 /* a helper function that utilizes ts_string data structure and performs same as sprintf */
 ts_uint ts_sprintf(ts_string *str, char *fmt, ...){
 	va_list ap;
@@ -56,7 +56,7 @@
 	fprintf(fh, "<dumpdate>%s</dumpdate>\n", c_time_string);
 
 	fprintf(fh, "<tape>\n");
-	
+		fprintf(fh,"%s",tapetxt);	
 	fprintf(fh, "</tape>\n");
 	if(vesicle->poly_list!=NULL){
 		npoly=vesicle->poly_list->n;
@@ -69,7 +69,7 @@
 		npoly=0;
 		nfono=0;
 	}
-	fprintf(fh, "<trisurf nvtx=\"%u\" npoly=\"%u\" nfono=\"%u\">\n", vesicle->vlist->n, npoly, nfono);
+	fprintf(fh, "<trisurf nvtx=\"%u\" npoly=\"%u\" nfono=\"%u\" compressed=\"false\">\n", vesicle->vlist->n, npoly, nfono);
 	return TS_SUCCESS;
 }
 

--
Gitblit v1.9.3