- Timestamp:
- Mar 9, 2006, 1:12:05 PM (19 years ago)
- Location:
- trunk/src/mesh
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/mesh/grid2d.cc
r279 r302 81 81 82 82 // total length = tagEncode + tagCompress + num + data 83 char * buf = (char*) malloc(numVals*sizeof(DataValType) + sizeof(int) + 2);83 char * buf = (char*) new char[numVals*sizeof(DataValType) + sizeof(int) + 2]; 84 84 if (buf == NULL) { 85 85 RpAppendErr("RpGrid2d::serialize: malloc failed"); -
trunk/src/mesh/test_grid1d.cc
r298 r302 1 1 #include <stdio.h> 2 #include "serializer.h" 2 3 #include "grid1d.h" 3 4 … … 27 28 }; 28 29 30 void writeToFile(char* buf, int len, const char* filename) 31 { 32 if (buf != NULL) { 33 FILE* fp = fopen(filename, "w"); 34 fwrite(buf, 1, len, fp); 35 fclose(fp); 36 } 37 } 38 29 39 int main() 30 40 { 31 int i, j, err ;41 int i, j, err, nbytes; 32 42 33 43 printf("Testing RpGrid1d\n"); 34 44 35 printf("Testing constructor\n");36 RpGrid1d grid1("output.grid(g1d)", 20);45 RpGrid1d* grid1 = new RpGrid1d("output.grid(g1d)", 20); 46 grid1->addAllPoints(&(points[0]), 20); 37 47 38 printf("vector size: %d\n", grid1.size());39 printf("capacity: %d\n", grid1.capacity());48 char* buf = grid1->serialize(nbytes); 49 writeToFile(buf, nbytes, "out.grid1"); 40 50 41 printf("Testing addAllPoints\n");42 grid1.addAllPoints(&(points[0]), 20);51 delete [] buf; 52 //buf = NULL; 43 53 44 printf(" vector size: %d\n", grid1.size());54 printf("Testing serializer\n"); 45 55 46 printf("Testing print\n"); 47 grid1.print(); 56 RpSerializer myvis; 48 57 49 printf("Testing serialize\n");58 myvis.addObject(grid1); 50 59 51 int nbytes; 52 char* buf = grid1.serialize(nbytes); 53 printf("nbytes=%d\n", nbytes); 60 RpGrid1d* ptr = (RpGrid1d*) myvis.getObject(grid1->objectName()); 54 61 55 FILE* fp = fopen("out.grid", "w"); 56 fwrite(buf, 1, nbytes, fp); 57 fclose(fp); 62 if (ptr == NULL) 63 printf("%s not found\n", grid1->objectName()); 58 64 59 printf("Testing print\n"); 60 grid1.print(); 65 myvis.print(); 61 66 62 printf("Testing deserialize\n");67 buf = myvis.serialize(); 63 68 64 RpGrid1d * grid2 = new RpGrid1d("test.path"); 65 grid2->deserialize(buf); 66 67 printf("Testing getData\n"); 68 69 // double* ptr = grid2->getDataCopy(); 70 double* ptr = grid2->getData(); 71 for (i=0; i<grid2->size(); i++) { 72 printf("%.12f\n", ptr[i]); 73 } 74 69 nbytes = myvis.numBytes(); 70 writeToFile(buf, nbytes, "out.g1"); 75 71 76 72
Note: See TracChangeset
for help on using the changeset viewer.