- Timestamp:
- Aug 3, 2008, 11:13:04 PM (16 years ago)
- Location:
- trunk/src/core
- Files:
-
- 4 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/Makefile.in
r1082 r1086 55 55 RpDict.h \ 56 56 RpDXWriter.h \ 57 RpDXWriterFInterface.h \ 58 RpDXWriterFStubs.h \ 57 59 RpEncode.h \ 58 60 RpEntityRef.h \ … … 121 123 RpBufferCInterface.o \ 122 124 RpDXWriter.o \ 125 RpDXWriterFInterface.o \ 123 126 RpEncode.o \ 124 127 RpEntityRef.o \ -
trunk/src/core/RpDXWriter.cc
r1060 r1086 22 22 23 23 DXWriter::DXWriter() : 24 _dataBuf(Simple FloatBuffer()),25 _posBuf(Simple FloatBuffer()),24 _dataBuf(SimpleDoubleBuffer()), 25 _posBuf(SimpleDoubleBuffer()), 26 26 _rank(3), 27 27 _shape(0), … … 30 30 _origin(NULL) 31 31 { 32 _delta = ( float*) malloc(_rank * _rank* sizeof(float));32 _delta = (double*) malloc(_rank*_rank*sizeof(double)); 33 33 if (_delta == NULL) { 34 34 fprintf(stderr, 35 35 "Error allocating %lu bytes, for _delta, inside DXWriter Constructor\n", 36 (unsigned long)(_rank *_rank * sizeof(float)));36 (unsigned long)(_rank*_rank*sizeof(double))); 37 37 return; 38 38 } … … 49 49 } 50 50 51 _origin = ( float*) malloc(_rank*sizeof(float));51 _origin = (double*) malloc(_rank*sizeof(double)); 52 52 if (_origin == NULL) { 53 53 fprintf(stderr, 54 54 "Error allocating %lu bytes, for _origin, inside DXWriter Constructor\n", 55 (unsigned long)(_rank * sizeof(float)));55 (unsigned long)(_rank*sizeof(double))); 56 56 return; 57 57 } … … 61 61 } 62 62 63 DXWriter::DXWriter( float* data, size_t nmemb, size_t rank, size_t shape) :64 _dataBuf(Simple FloatBuffer(data,nmemb)),65 _posBuf(Simple FloatBuffer()),63 DXWriter::DXWriter(double* data, size_t nmemb, size_t rank, size_t shape) : 64 _dataBuf(SimpleDoubleBuffer(data,nmemb)), 65 _posBuf(SimpleDoubleBuffer()), 66 66 _rank(rank), 67 67 _shape(shape), … … 70 70 _origin(NULL) 71 71 { 72 _delta = ( float*) malloc(_rank*_rank*sizeof(float));72 _delta = (double*) malloc(_rank*_rank*sizeof(double)); 73 73 if (_delta == NULL) { 74 74 fprintf(stderr, 75 75 "Error allocating %lu bytes, for _delta, inside DXWriter Constructor\n", 76 (unsigned long)(_rank * _rank * sizeof(float)));76 (unsigned long)(_rank*_rank*sizeof(double))); 77 77 return; 78 78 } … … 89 89 } 90 90 91 _origin = ( float*) malloc(_rank*sizeof(float));91 _origin = (double*) malloc(_rank*sizeof(double)); 92 92 if (_origin == NULL) { 93 93 fprintf(stderr, 94 94 "Error allocating %lu bytes, for _origin, inside DXWriter Constructor\n", 95 (unsigned long)(_rank*sizeof(float)));95 (unsigned long)(_rank*sizeof(double))); 96 96 return; 97 97 } … … 117 117 118 118 DXWriter& 119 DXWriter::origin( float* o)119 DXWriter::origin(double* o) 120 120 { 121 121 if (o == NULL) { 122 122 return *this; 123 123 } 124 size_t nbytes = _rank * sizeof(float); 125 float *tmp = (float*) malloc(nbytes); 124 125 size_t nbytes = _rank * sizeof(double); 126 double *tmp = (double*) malloc(nbytes); 126 127 if (tmp == NULL) { 127 128 fprintf(stderr,"Unable to malloc %lu bytes inside DXWriter::origin\n", 128 129 (unsigned long)nbytes); 129 130 return *this; 130 131 } … … 141 142 142 143 DXWriter& 143 DXWriter::delta( float* d)144 DXWriter::delta(double* d) 144 145 { 145 146 if (d == NULL) { … … 147 148 } 148 149 149 size_t nbytes = _rank * _rank * sizeof( float);150 float *tmp = (float*)malloc(nbytes);150 size_t nbytes = _rank * _rank * sizeof(double); 151 double *tmp = (double*)malloc(nbytes); 151 152 if (tmp == NULL) { 152 153 fprintf(stderr,"Unable to malloc %lu bytes inside DXWriter::delta\n", 153 154 (unsigned long)nbytes); 154 155 return *this; 155 156 } … … 175 176 if (tmp == NULL) { 176 177 fprintf(stderr,"Unable to malloc %lu bytes inside DXWriter::pos\n", 177 178 (unsigned long)nbytes); 178 179 return *this; 179 180 } … … 189 190 190 191 DXWriter& 191 DXWriter::append( float* value)192 DXWriter::append(double* value) 192 193 { 193 194 _dataBuf.append(value,1); … … 196 197 197 198 DXWriter& 198 DXWriter::data( float*d, size_t nmemb)199 DXWriter::data(double *d, size_t nmemb) 199 200 { 200 201 _dataBuf.append(d,nmemb); … … 203 204 204 205 DXWriter& 205 DXWriter::pos( float*p, size_t nmemb)206 DXWriter::pos(double *p, size_t nmemb) 206 207 { 207 208 _posBuf.append(p,nmemb); 209 return *this; 210 } 211 212 DXWriter& 213 DXWriter::write(FILE *stream) 214 { 215 SimpleCharBuffer *dxfile = NULL; 216 217 if (stream == NULL) { 218 fprintf(stderr,"stream is NULL, cannot write to NULL file inside DXWriter::write\n"); 219 return *this; 220 } 221 222 dxfile = new SimpleCharBuffer(); 223 224 _writeDxToBuffer(dxfile); 225 fwrite((const void*)(dxfile->bytes()),1,dxfile->size(),stream); 226 227 delete dxfile; 228 229 return *this; 230 } 231 232 DXWriter& 233 DXWriter::write(const char* fname) 234 { 235 FILE *fp = NULL; 236 237 if (fname == NULL) { 238 fprintf(stderr,"filename is NULL, cannot write to NULL file inside DXWriter::write\n"); 239 return *this; 240 } 241 242 fp = fopen(fname,"wb"); 243 write(fp); 244 fclose(fp); 245 246 return *this; 247 } 248 249 DXWriter& 250 DXWriter::write(char *str) 251 { 252 SimpleCharBuffer *dxfile = NULL; 253 int sz = 0; 254 255 dxfile = new SimpleCharBuffer(); 256 257 _writeDxToBuffer(dxfile); 258 sz = dxfile->size(); 259 str = new char[sz+1]; 260 memcpy(str,dxfile->bytes(),sz); 261 str[sz] = '\0'; 262 263 delete dxfile; 264 208 265 return *this; 209 266 } … … 217 274 218 275 DXWriter& 219 DXWriter::write(FILE *stream) 220 { 221 SimpleCharBuffer dxfile; 276 DXWriter::_writeDxToBuffer(SimpleCharBuffer *dxfile) 277 { 222 278 char b[80]; 223 float f = 0.0; 224 225 // expand our original buffer to because we know there are at least 279 double f = 0.0; 280 281 // expand our original buffer to 512 characters 282 // because we know there are at least 226 283 // 400 characters in even our smallest dx file. 227 dxfile .set(512);228 229 dxfile .append("object 1 class gridpositions counts",35);284 dxfile->set(512); 285 286 dxfile->append("<ODX>object 1 class gridpositions counts",40); 230 287 for (size_t i=0; i < _rank; i++) { 231 288 sprintf(b, " %10lu", (unsigned long)_positions[i]); 232 dxfile .append(b,11);233 } 234 235 dxfile .append("\norigin");289 dxfile->append(b,11); 290 } 291 292 dxfile->append("\norigin"); 236 293 for (size_t i=0; i < _rank; i++) { 237 294 sprintf(b, " %10g",_origin[i]); 238 dxfile .append(b,11);295 dxfile->append(b,11); 239 296 } 240 297 241 298 for (size_t row=0; row < _rank; row++) { 242 dxfile .append("\ndelta");299 dxfile->append("\ndelta"); 243 300 for (size_t col=0; col < _rank; col++) { 244 301 sprintf(b, " %10g",_delta[(_rank*row)+col]); 245 dxfile .append(b,11);302 dxfile->append(b,11); 246 303 } 247 304 } 248 305 249 dxfile .append("\nobject 2 class gridconnections counts", 38);306 dxfile->append("\nobject 2 class gridconnections counts", 38); 250 307 for (size_t i=0; i < _rank; i++) { 251 308 sprintf(b, " %10lu",(unsigned long)_positions[i]); 252 dxfile .append(b,11);253 } 254 255 dxfile .append("\nattribute \"element type\" string \"cubes\"\n",41);256 dxfile .append("attribute \"ref\" string \"positions\"\n",35);309 dxfile->append(b,11); 310 } 311 312 dxfile->append("\nattribute \"element type\" string \"cubes\"\n",41); 313 dxfile->append("attribute \"ref\" string \"positions\"\n",35); 257 314 258 315 sprintf(b,"object 3 class array type float rank 0 items %lu data follows\n", 259 316 (unsigned long)_dataBuf.nmemb()); 260 dxfile .append(b);317 dxfile->append(b); 261 318 262 319 _dataBuf.seek(0,SEEK_SET); 263 320 while (!_dataBuf.eof()) { 264 321 _dataBuf.read(&f,1); 322 // nanovis and many other progs fail when you send it inf data 323 if (isinf(f)) { 324 f = 0.0; 325 } 265 326 sprintf(b," %10g\n",f); 266 dxfile.append(b,15); 267 } 268 269 dxfile.append("attribute \"dep\" string \"positions\"\n",35); 270 dxfile.append("object \"density\" class field\n",29); 271 dxfile.append("component \"positions\" value 1\n",30); 272 dxfile.append("component \"connections\" value 2\n",32); 273 dxfile.append("component \"data\" value 3\n",25); 274 275 fwrite((const void*)dxfile.bytes(),1,dxfile.size(),stream); 327 // we do not know the length of the string 328 // only that it has 10 sigdigs, so we cannot tell 329 // append the size of the data 330 // dxfile->append(b,15); 331 dxfile->append(b); 332 } 333 334 dxfile->append("attribute \"dep\" string \"positions\"\n",35); 335 dxfile->append("object \"density\" class field\n",29); 336 dxfile->append("component \"positions\" value 1\n",30); 337 dxfile->append("component \"connections\" value 2\n",32); 338 dxfile->append("component \"data\" value 3\n",25); 339 276 340 return *this; 277 341 } -
trunk/src/core/RpDXWriter.h
r1051 r1086 24 24 public: 25 25 DXWriter(); 26 DXWriter( float* data, size_t nmemb, size_t rank, size_t shape);26 DXWriter(double* data, size_t nmemb, size_t rank, size_t shape); 27 27 DXWriter(const DXWriter& rpdx); 28 28 DXWriter& operator=(const DXWriter& rpdx); 29 29 virtual ~DXWriter(); 30 30 31 virtual DXWriter& origin( float* o);32 virtual DXWriter& delta( float* d);31 virtual DXWriter& origin(double* o); 32 virtual DXWriter& delta(double* d); 33 33 virtual DXWriter& counts(size_t *p); 34 34 35 virtual DXWriter& append( float* value);35 virtual DXWriter& append(double* value); 36 36 37 virtual DXWriter& data(float *d, size_t nmemb=1); 38 virtual DXWriter& pos(float *p, size_t nmemb=1); 39 virtual DXWriter& write(FILE *stream=NULL); 37 virtual DXWriter& data(double *d, size_t nmemb=1); 38 virtual DXWriter& pos(double *p, size_t nmemb=1); 39 virtual DXWriter& write(FILE *stream); 40 virtual DXWriter& write(const char* fname); 41 virtual DXWriter& write(char *str); 40 42 virtual size_t size() const; 41 43 … … 46 48 private: 47 49 48 Simple FloatBuffer _dataBuf;49 Simple FloatBuffer _posBuf;50 SimpleDoubleBuffer _dataBuf; 51 SimpleDoubleBuffer _posBuf; 50 52 51 53 size_t _rank; // number of dimensions in each item … … 53 55 54 56 size_t* _positions; // array holding the number of x,y,z points 55 float* _delta; // array holding deltas of the uniform mesh 56 float* _origin; // array holding coord of origin 57 double* _delta; // array holding deltas of the uniform mesh 58 double* _origin; // array holding coord of origin 59 60 DXWriter& _writeDxToBuffer(SimpleCharBuffer *dxfile); 57 61 }; 58 62 -
trunk/src/core/RpFortranCommon.cc
r1018 r1086 13 13 * ====================================================================== 14 14 */ 15 15 16 #include "RpFortranCommon.h" 17 #include <stdlib.h> 18 #include <ctype.h> 19 #include <string.h> 16 20 17 21 char* null_terminate(char* inStr, int len) { … … 86 90 87 91 return newStr; 88 } 92 } 89 93 90 94 -
trunk/src/core/RpFortranCommon.h
r1018 r1086 14 14 */ 15 15 16 #include <stdlib.h>17 #include <ctype.h>18 #include <string.h>19 16 #include <string> 20 17 -
trunk/src/core/RpLibraryFInterface.cc
r1018 r1086 15 15 #include "RpBindingsDict.h" 16 16 #include "RpLibraryFStubs.c" 17 #include "RpDXWriter.h" 17 18 18 19 /**********************************************************************/ … … 60 61 61 62 if ((handle) && (*handle != 0)) { 62 lib = getObject_Lib(*handle);63 lib = (RpLibrary*) getObject_Void(*handle); 63 64 if (lib) { 64 65 retObj = lib->element(inPath); … … 91 92 inPath = null_terminate_str(path,path_len); 92 93 93 lib = getObject_Lib(*handle);94 lib = (RpLibrary*) getObject_Void(*handle); 94 95 95 96 if (lib) { … … 120 121 inPath = null_terminate_str(path,path_len); 121 122 122 lib = getObject_Lib(*handle);123 lib = (RpLibrary*) getObject_Void(*handle); 123 124 124 125 if (lib) { … … 148 149 inPath = null_terminate_str(path,path_len); 149 150 150 lib = getObject_Lib(*handle);151 lib = (RpLibrary*) getObject_Void(*handle); 151 152 152 153 if (lib) { … … 175 176 176 177 if (handle && (*handle >= 0) ) { 177 lib = getObject_Lib(*handle);178 lib = (RpLibrary*) getObject_Void(*handle); 178 179 if (lib) { 179 180 180 181 if (*childHandle > 0) { 181 182 // check to see if there were any previously returned children 182 childNode = getObject_Lib(*childHandle);183 childNode = (RpLibrary*) getObject_Void(*childHandle); 183 184 } 184 185 … … 407 408 if (rapptureStarted) { 408 409 if ((handle) && (*handle != 0)) { 409 lib = getObject_Lib(*handle);410 lib = (RpLibrary*) getObject_Void(*handle); 410 411 411 412 if (lib) { … … 460 461 461 462 if ((handle) && (*handle != 0)) { 462 lib = getObject_Lib(*handle);463 lib = (RpLibrary*) getObject_Void(*handle); 463 464 464 465 if (lib) { … … 493 494 494 495 if ((handle) && (*handle != 0)) { 495 lib = getObject_Lib(*handle);496 lib = (RpLibrary*) getObject_Void(*handle); 496 497 497 498 if (lib) { … … 525 526 526 527 if ((handle) && (*handle != 0)) { 527 lib = getObject_Lib(*handle);528 lib = (RpLibrary*) getObject_Void(*handle); 528 529 529 530 if (lib) { … … 555 556 556 557 if ((handle) && (*handle != 0)) { 557 lib = getObject_Lib(*handle);558 lib = (RpLibrary*) getObject_Void(*handle); 558 559 559 560 if (lib) { … … 586 587 587 588 if ((handle) && (*handle != 0)) { 588 lib = getObject_Lib(*handle);589 lib = (RpLibrary*) getObject_Void(*handle); 589 590 590 591 if (lib) { … … 624 625 625 626 if ((handle) && (*handle != 0)) { 626 lib = getObject_Lib(*handle);627 lib = (RpLibrary*) getObject_Void(*handle); 627 628 628 629 if (lib) { … … 662 663 663 664 if ((handle) && (*handle != 0)) { 664 lib = getObject_Lib(*handle);665 lib = (RpLibrary*) getObject_Void(*handle); 665 666 666 667 if (lib) { … … 700 701 701 702 if ((handle) && (*handle != 0)) { 702 lib = getObject_Lib(*handle);703 lib = (RpLibrary*) getObject_Void(*handle); 703 704 704 705 if (lib) { … … 734 735 735 736 if ((handle) && (*handle != 0)) { 736 lib = getObject_Lib(*handle);737 lib = (RpLibrary*) getObject_Void(*handle); 737 738 738 739 if (lib) { … … 746 747 747 748 748 //void rp_lib_put_obj( int* handle, 749 // char* path, 750 // int* valHandle, 751 // int* append, 752 // int path_len 753 // ) 754 //{ 755 // std::string inPath = ""; 756 // RpLibrary* lib = NULL; 757 // 758 // // inPath = null_terminate(path,path_len); 759 // inPath = std::string(path,path_len); 760 // 761 // /* 762 // if (inPath) { 763 // path_len = strlen(inPath) + 1; 764 // } 765 // */ 766 // 767 // if ((handle) && (*handle != 0)) { 768 // lib = getObject_Lib(*handle); 769 // 770 // if (lib) { 771 // // rpPut(lib, inPath, inValue, inId, *append); 772 // lib->put(inPath,inValue,"",*append); 773 // } 774 // } 775 // 776 // /* 777 // rp_lib_put_id_obj(handle,inPath,valHandle,NULL,append,path_len,0); 778 // 779 // if (inPath) { 780 // free(inPath); 781 // inPath = NULL; 782 // } 783 // */ 784 // 785 //} 749 void rp_lib_put_obj( int* handle, 750 char* path, 751 int* valHandle, 752 int* append, 753 int path_len 754 ) 755 { 756 std::string inPath = ""; 757 RpLibrary* lib = NULL; 758 // Rp_Obj does not currently exist 759 Rappture::DXWriter* obj = NULL; 760 char* objStr = NULL; 761 762 763 inPath = null_terminate_str(path,path_len); 764 765 if ((handle) && (*handle != 0)) { 766 lib = (RpLibrary*) getObject_Void(*handle); 767 if (!lib) { 768 // return error, lib was not found 769 } 770 771 obj = (Rappture::DXWriter*) getObject_Void(*valHandle); 772 if (!obj) { 773 // return error, obj was not found 774 } 775 776 // textsize function does not currently exist 777 objStr = (char*) malloc(obj->size()*sizeof(char)); 778 obj->write(objStr); 779 lib->put(inPath,objStr,"",*append); 780 free(objStr); 781 } 782 } 783 786 784 787 785 /* … … 806 804 if (rapptureStarted) { 807 805 if ((handle) && (*handle != 0)) { 808 lib = getObject_Lib(*handle);809 value = getObject_Lib(*valHandle);806 lib = (RpLibrary*) getObject_Void(*handle); 807 value = (RpLibrary*) getObject_Void(*valHandle); 810 808 811 809 if (lib && value) { … … 844 842 if (rapptureStarted) { 845 843 if ((handle) && (*handle != 0)) { 846 lib = getObject_Lib(*handle);844 lib = (RpLibrary*) getObject_Void(*handle); 847 845 848 846 if (lib) { … … 877 875 if (rapptureStarted) { 878 876 if ((handle) && (*handle != 0)) { 879 lib = getObject_Lib(*handle);877 lib = (RpLibrary*) getObject_Void(*handle); 880 878 881 879 if (lib) { … … 917 915 if ( file.is_open() ) { 918 916 if ((handle) && (*handle != 0)) { 919 lib = getObject_Lib(*handle);917 lib = (RpLibrary*) getObject_Void(*handle); 920 918 921 919 if (lib) { … … 946 944 947 945 if ((handle) && (*handle != 0)) { 948 lib = getObject_Lib(*handle);946 lib = (RpLibrary*) getObject_Void(*handle); 949 947 950 948 if (lib) { … … 968 966 969 967 if ((handle) && (*handle != 0)) { 970 node = getObject_Lib(*handle);968 node = (RpLibrary*) getObject_Void(*handle); 971 969 972 970 if (node) { … … 990 988 991 989 if ((handle) && (*handle != 0)) { 992 node = getObject_Lib(*handle);990 node = (RpLibrary*) getObject_Void(*handle); 993 991 994 992 if (node) { … … 1012 1010 1013 1011 if ((handle) && (*handle != 0)) { 1014 node = getObject_Lib(*handle);1012 node = (RpLibrary*) getObject_Void(*handle); 1015 1013 1016 1014 if (node) { … … 1032 1030 1033 1031 if (handle && *handle != 0) { 1034 lib = getObject_Lib(*handle);1032 lib = (RpLibrary*) getObject_Void(*handle); 1035 1033 if (lib) { 1036 1034 lib->put("tool.version.rappture.language", "fortran"); -
trunk/src/core/RpLibraryFInterface.h
r1018 r1086 114 114 * rp_lib_put_obj still needs to be written 115 115 * keep function declaration around 116 */ 116 117 void rp_lib_put_obj ( int* handle, 117 118 char* path, … … 119 120 int* append, 120 121 int path_len ); 121 */122 122 123 123 /* -
trunk/src/core/RpSimpleBuffer.h
r1065 r1086 413 413 if (buf == NULL) { 414 414 fprintf(stderr,"Can't allocate %lu bytes of memory\n", 415 415 (long unsigned int)nbytes); 416 416 _fileState = false; 417 417 return 0; … … 446 446 447 447 while (curMemb != _nMembStored) { 448 fprintf(stdout,"_buf[%d] = :% g:\n",curMemb,(double)_buf[curMemb]);448 fprintf(stdout,"_buf[%d] = :%#x:\n",curMemb,(unsigned long)_buf[curMemb]); 449 449 curMemb += 1; 450 450 }
Note: See TracChangeset
for help on using the changeset viewer.