From 201659654a328f84c229d16fe85d8709a4183957 Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Sat, 19 Oct 2019 15:53:42 +0000
Subject: [PATCH] Fixed most problems, some still persists.

---
 src/io.c      |    4 ++--
 src/restore.c |   13 +++++++++----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/io.c b/src/io.c
index 0dd022c..64dc53d 100644
--- a/src/io.c
+++ b/src/io.c
@@ -435,7 +435,7 @@
 
 
 
-	fprintf(fh,"</CellData>\n<Points>\n<DataArray type=\"Float64\" Name=\"Koordinate tock\" NumberOfComponents=\"3\" format=\"binary\">\n");
+	fprintf(fh,"</CellData>\n<Points>\n<DataArray type=\"Float64\" Name=\"Koordinate tock\" NumberOfComponents=\"3\" format=\"binary\">");
 	offset=0;
 	for(i=0;i<vlist->n;i++,offset+=3){
 		//fprintf(fh,"%.17e %.17e %.17e\n",vtx[i]->x,vtx[i]->y, vtx[i]->z);
@@ -539,7 +539,7 @@
 	printout=ts_compress((char *)int_vector,offset*sizeof(long));
 	fprintf(fh,"%s",printout);
 	free(printout);
-    fprintf(fh,"</DataArray>\n<DataArray type=\"UInt8\" Name=\"types\" format=\"binary\">\n");
+    fprintf(fh,"</DataArray>\n<DataArray type=\"UInt8\" Name=\"types\" format=\"binary\">");
 	free(int_vector);
 	free(float_vector);
 	free(float_cell_vector);
diff --git a/src/restore.c b/src/restore.c
index a1211ea..7079960 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -344,6 +344,7 @@
 //				vals=(char *)values;
 				unsigned long data_len=0;
 				ts_double *curv_values=(double *)ts_decompress((unsigned char *)values,strlen((char *)values), &data_len);
+				data_len=data_len/sizeof(ts_double);
 //				token=strtok(vals," ");
 				for(idx=0;idx<data_len;idx++){
 //				while(token!=NULL){
@@ -362,7 +363,9 @@
 					//idx++;
 					//token=strtok(NULL," ");
 				}
+				
 				xmlFree(values);		
+				free(curv_values);
 			}
 			xmlFree(property_name);
 		}
@@ -376,18 +379,19 @@
 	xmlNodePtr child = cur->xmlChildrenNode;
 	xmlChar *points;
 //	char *pts;
-	int idx, polyidx, monoidx, filidx, fonoidx;
+	int i,idx, polyidx, monoidx, filidx, fonoidx;
 //	char *token[3];
 	while (child != NULL) {
 		if ((!xmlStrcmp(child->name, (const xmlChar *)"DataArray"))){
 			points = xmlNodeListGetString(doc, child->xmlChildrenNode, 1);
 			unsigned long data_len=0;
 			ts_double *coords=(double *)ts_decompress((unsigned char *)points,strlen((char *)points), &data_len);
+			data_len=data_len/sizeof(ts_double);
 			//pts=(char *)points;
 			//token[0]=strtok(pts," ");
 			//token[1]=strtok(NULL," ");
 			//token[2]=strtok(NULL,"\n");
-			for(idx=0;idx<data_len;idx+=3){
+			for(i=0,idx=0;i<data_len;i+=3,idx++){
 //			while(token[0]!=NULL){
 				if(idx<vesicle->vlist->n){
 					vesicle->vlist->vtx[idx]->x=coords[idx];//atof(token[0]);
@@ -424,7 +428,7 @@
 	xmlNodePtr child = cur->xmlChildrenNode;
 	xmlChar *bonds, *conname;
 //	char *b;
-	int idx, polyidx;
+	int i,idx, polyidx;
 //	char *token[2];
 //	int temp_cnt=0;
 	while (child != NULL) {
@@ -433,9 +437,10 @@
 			bonds = xmlNodeListGetString(doc, child->xmlChildrenNode, 1);
 			unsigned long data_len=0;
 			unsigned long *conn=(unsigned long *)ts_decompress((unsigned char *)bonds,strlen((char *)bonds), &data_len);
+			data_len=data_len/sizeof(unsigned long);
 			//token[0]=strtok(b," ");
 			//token[1]=strtok(NULL,"\n");
-			for(idx=0;idx<data_len;idx+=2){
+			for(i=0,idx=0;i<data_len;i+=2,idx++){
 //			while(token[0]!=NULL){
 				if(idx<3*(vesicle->vlist->n-2)){
 					bond_add(vesicle->blist, vesicle->vlist->vtx[conn[idx]], vesicle->vlist->vtx[conn[idx+1]]);

--
Gitblit v1.9.3