Changeset 1086 for trunk/src


Ignore:
Timestamp:
Aug 3, 2008, 11:13:04 PM (16 years ago)
Author:
dkearney
Message:

adding RpDXWriter fortran bindings. updates to RpDXWriter and RpSimpleBuffer? objects

Location:
trunk/src/core
Files:
4 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/Makefile.in

    r1082 r1086  
    5555                RpDict.h \
    5656                RpDXWriter.h \
     57                RpDXWriterFInterface.h \
     58                RpDXWriterFStubs.h \
    5759                RpEncode.h \
    5860                RpEntityRef.h \
     
    121123                RpBufferCInterface.o \
    122124                RpDXWriter.o \
     125                RpDXWriterFInterface.o \
    123126                RpEncode.o \
    124127                RpEntityRef.o \
  • trunk/src/core/RpDXWriter.cc

    r1060 r1086  
    2222
    2323DXWriter::DXWriter() :
    24     _dataBuf(SimpleFloatBuffer()),
    25     _posBuf(SimpleFloatBuffer()),
     24    _dataBuf(SimpleDoubleBuffer()),
     25    _posBuf(SimpleDoubleBuffer()),
    2626    _rank(3),
    2727    _shape(0),
     
    3030    _origin(NULL)
    3131{
    32     _delta  = (float*) malloc(_rank * _rank* sizeof(float));
     32    _delta  = (double*) malloc(_rank*_rank*sizeof(double));
    3333    if (_delta == NULL) {
    3434        fprintf(stderr,
    3535            "Error allocating %lu bytes, for _delta, inside DXWriter Constructor\n",
    36                 (unsigned long)(_rank *_rank * sizeof(float)));
     36            (unsigned long)(_rank*_rank*sizeof(double)));
    3737            return;
    3838    }
     
    4949    }
    5050
    51     _origin = (float*) malloc(_rank*sizeof(float));
     51    _origin = (double*) malloc(_rank*sizeof(double));
    5252    if (_origin == NULL) {
    5353        fprintf(stderr,
    5454            "Error allocating %lu bytes, for _origin, inside DXWriter Constructor\n",
    55                 (unsigned long)(_rank * sizeof(float)));
     55            (unsigned long)(_rank*sizeof(double)));
    5656            return;
    5757    }
     
    6161}
    6262
    63 DXWriter::DXWriter(float* data, size_t nmemb, size_t rank, size_t shape) :
    64     _dataBuf(SimpleFloatBuffer(data,nmemb)),
    65     _posBuf(SimpleFloatBuffer()),
     63DXWriter::DXWriter(double* data, size_t nmemb, size_t rank, size_t shape) :
     64    _dataBuf(SimpleDoubleBuffer(data,nmemb)),
     65    _posBuf(SimpleDoubleBuffer()),
    6666    _rank(rank),
    6767    _shape(shape),
     
    7070    _origin(NULL)
    7171{
    72     _delta  = (float*) malloc(_rank*_rank*sizeof(float));
     72    _delta  = (double*) malloc(_rank*_rank*sizeof(double));
    7373    if (_delta == NULL) {
    7474        fprintf(stderr,
    7575            "Error allocating %lu bytes, for _delta, inside DXWriter Constructor\n",
    76                 (unsigned long)(_rank * _rank * sizeof(float)));
     76            (unsigned long)(_rank*_rank*sizeof(double)));
    7777            return;
    7878    }
     
    8989    }
    9090
    91     _origin = (float*) malloc(_rank*sizeof(float));
     91    _origin = (double*) malloc(_rank*sizeof(double));
    9292    if (_origin == NULL) {
    9393        fprintf(stderr,
    9494            "Error allocating %lu bytes, for _origin, inside DXWriter Constructor\n",
    95                 (unsigned long)(_rank*sizeof(float)));
     95            (unsigned long)(_rank*sizeof(double)));
    9696            return;
    9797    }
     
    117117
    118118DXWriter&
    119 DXWriter::origin(float* o)
     119DXWriter::origin(double* o)
    120120{
    121121    if (o == NULL) {
    122122        return *this;
    123123    }
    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);
    126127    if (tmp == NULL) {
    127128        fprintf(stderr,"Unable to malloc %lu bytes inside DXWriter::origin\n",
    128                 (unsigned long)nbytes);
     129            (unsigned long)nbytes);
    129130        return *this;
    130131    }
     
    141142
    142143DXWriter&
    143 DXWriter::delta(float* d)
     144DXWriter::delta(double* d)
    144145{
    145146    if (d == NULL) {
     
    147148    }
    148149
    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);
    151152    if (tmp == NULL) {
    152153        fprintf(stderr,"Unable to malloc %lu bytes inside DXWriter::delta\n",
    153                 (unsigned long)nbytes);
     154            (unsigned long)nbytes);
    154155        return *this;
    155156    }
     
    175176    if (tmp == NULL) {
    176177        fprintf(stderr,"Unable to malloc %lu bytes inside DXWriter::pos\n",
    177                 (unsigned long)nbytes);
     178            (unsigned long)nbytes);
    178179        return *this;
    179180    }
     
    189190
    190191DXWriter&
    191 DXWriter::append(float* value)
     192DXWriter::append(double* value)
    192193{
    193194    _dataBuf.append(value,1);
     
    196197
    197198DXWriter&
    198 DXWriter::data(float *d, size_t nmemb)
     199DXWriter::data(double *d, size_t nmemb)
    199200{
    200201    _dataBuf.append(d,nmemb);
     
    203204
    204205DXWriter&
    205 DXWriter::pos(float *p, size_t nmemb)
     206DXWriter::pos(double *p, size_t nmemb)
    206207{
    207208    _posBuf.append(p,nmemb);
     209    return *this;
     210}
     211
     212DXWriter&
     213DXWriter::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
     232DXWriter&
     233DXWriter::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
     249DXWriter&
     250DXWriter::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
    208265    return *this;
    209266}
     
    217274
    218275DXWriter&
    219 DXWriter::write(FILE *stream)
    220 {
    221     SimpleCharBuffer dxfile;
     276DXWriter::_writeDxToBuffer(SimpleCharBuffer *dxfile)
     277{
    222278    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
    226283    // 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);
    230287    for (size_t i=0; i < _rank; i++) {
    231288        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");
    236293    for (size_t i=0; i < _rank; i++) {
    237294        sprintf(b, " %10g",_origin[i]);
    238         dxfile.append(b,11);
     295        dxfile->append(b,11);
    239296    }
    240297
    241298    for (size_t row=0; row < _rank; row++) {
    242         dxfile.append("\ndelta");
     299        dxfile->append("\ndelta");
    243300        for (size_t col=0; col < _rank; col++) {
    244301            sprintf(b, " %10g",_delta[(_rank*row)+col]);
    245             dxfile.append(b,11);
     302            dxfile->append(b,11);
    246303        }
    247304    }
    248305
    249     dxfile.append("\nobject 2 class gridconnections counts", 38);
     306    dxfile->append("\nobject 2 class gridconnections counts", 38);
    250307    for (size_t i=0; i < _rank; i++) {
    251308        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);
    257314
    258315    sprintf(b,"object 3 class array type float rank 0 items %lu data follows\n",
    259316        (unsigned long)_dataBuf.nmemb());
    260     dxfile.append(b);
     317    dxfile->append(b);
    261318
    262319    _dataBuf.seek(0,SEEK_SET);
    263320    while (!_dataBuf.eof()) {
    264321        _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        }
    265326        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
    276340    return *this;
    277341}
  • trunk/src/core/RpDXWriter.h

    r1051 r1086  
    2424public:
    2525    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);
    2727    DXWriter(const DXWriter& rpdx);
    2828    DXWriter& operator=(const DXWriter& rpdx);
    2929    virtual ~DXWriter();
    3030
    31     virtual DXWriter& origin(float* o);
    32     virtual DXWriter& delta(float* d);
     31    virtual DXWriter& origin(double* o);
     32    virtual DXWriter& delta(double* d);
    3333    virtual DXWriter& counts(size_t *p);
    3434
    35     virtual DXWriter& append(float* value);
     35    virtual DXWriter& append(double* value);
    3636
    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);
    4042    virtual size_t size() const;
    4143
     
    4648private:
    4749
    48     SimpleFloatBuffer _dataBuf;
    49     SimpleFloatBuffer _posBuf;
     50    SimpleDoubleBuffer _dataBuf;
     51    SimpleDoubleBuffer _posBuf;
    5052
    5153    size_t _rank;          // number of dimensions in each item
     
    5355
    5456    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);
    5761};
    5862
  • trunk/src/core/RpFortranCommon.cc

    r1018 r1086  
    1313 * ======================================================================
    1414 */
     15
    1516#include "RpFortranCommon.h"
     17#include <stdlib.h>
     18#include <ctype.h>
     19#include <string.h>
    1620
    1721char* null_terminate(char* inStr, int len) {
     
    8690
    8791    return newStr;
    88 }             
     92}
    8993
    9094
  • trunk/src/core/RpFortranCommon.h

    r1018 r1086  
    1414 */
    1515
    16 #include <stdlib.h>
    17 #include <ctype.h>
    18 #include <string.h>
    1916#include <string>
    2017
  • trunk/src/core/RpLibraryFInterface.cc

    r1018 r1086  
    1515#include "RpBindingsDict.h"
    1616#include "RpLibraryFStubs.c"
     17#include "RpDXWriter.h"
    1718
    1819/**********************************************************************/
     
    6061
    6162    if ((handle) && (*handle != 0)) {
    62         lib = getObject_Lib(*handle);
     63        lib = (RpLibrary*) getObject_Void(*handle);
    6364        if (lib) {
    6465            retObj = lib->element(inPath);
     
    9192    inPath = null_terminate_str(path,path_len);
    9293
    93     lib = getObject_Lib(*handle);
     94    lib = (RpLibrary*) getObject_Void(*handle);
    9495
    9596    if (lib) {
     
    120121    inPath = null_terminate_str(path,path_len);
    121122
    122     lib = getObject_Lib(*handle);
     123    lib = (RpLibrary*) getObject_Void(*handle);
    123124
    124125    if (lib) {
     
    148149    inPath = null_terminate_str(path,path_len);
    149150
    150     lib = getObject_Lib(*handle);
     151    lib = (RpLibrary*) getObject_Void(*handle);
    151152
    152153    if (lib) {
     
    175176
    176177    if (handle && (*handle >= 0) ) {
    177         lib = getObject_Lib(*handle);
     178        lib = (RpLibrary*) getObject_Void(*handle);
    178179        if (lib) {
    179180
    180181            if (*childHandle > 0) {
    181182                // check to see if there were any previously returned children
    182                 childNode = getObject_Lib(*childHandle);
     183                childNode = (RpLibrary*) getObject_Void(*childHandle);
    183184            }
    184185
     
    407408    if (rapptureStarted) {
    408409        if ((handle) && (*handle != 0)) {
    409             lib = getObject_Lib(*handle);
     410            lib = (RpLibrary*) getObject_Void(*handle);
    410411
    411412            if (lib) {
     
    460461
    461462    if ((handle) && (*handle != 0)) {
    462         lib = getObject_Lib(*handle);
     463        lib = (RpLibrary*) getObject_Void(*handle);
    463464
    464465        if (lib) {
     
    493494
    494495    if ((handle) && (*handle != 0)) {
    495         lib = getObject_Lib(*handle);
     496        lib = (RpLibrary*) getObject_Void(*handle);
    496497
    497498        if (lib) {
     
    525526
    526527    if ((handle) && (*handle != 0)) {
    527         lib = getObject_Lib(*handle);
     528        lib = (RpLibrary*) getObject_Void(*handle);
    528529
    529530        if (lib) {
     
    555556
    556557    if ((handle) && (*handle != 0)) {
    557         lib = getObject_Lib(*handle);
     558        lib = (RpLibrary*) getObject_Void(*handle);
    558559
    559560        if (lib) {
     
    586587
    587588    if ((handle) && (*handle != 0)) {
    588         lib = getObject_Lib(*handle);
     589        lib = (RpLibrary*) getObject_Void(*handle);
    589590
    590591        if (lib) {
     
    624625
    625626    if ((handle) && (*handle != 0)) {
    626         lib = getObject_Lib(*handle);
     627        lib = (RpLibrary*) getObject_Void(*handle);
    627628
    628629        if (lib) {
     
    662663
    663664    if ((handle) && (*handle != 0)) {
    664         lib = getObject_Lib(*handle);
     665        lib = (RpLibrary*) getObject_Void(*handle);
    665666
    666667        if (lib) {
     
    700701
    701702    if ((handle) && (*handle != 0)) {
    702         lib = getObject_Lib(*handle);
     703        lib = (RpLibrary*) getObject_Void(*handle);
    703704
    704705        if (lib) {
     
    734735
    735736    if ((handle) && (*handle != 0)) {
    736         lib = getObject_Lib(*handle);
     737        lib = (RpLibrary*) getObject_Void(*handle);
    737738
    738739        if (lib) {
     
    746747
    747748
    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 //}
     749void 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
    786784
    787785/*
     
    806804    if (rapptureStarted) {
    807805        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);
    810808
    811809            if (lib && value) {
     
    844842    if (rapptureStarted) {
    845843        if ((handle) && (*handle != 0)) {
    846             lib = getObject_Lib(*handle);
     844            lib = (RpLibrary*) getObject_Void(*handle);
    847845
    848846            if (lib) {
     
    877875    if (rapptureStarted) {
    878876        if ((handle) && (*handle != 0)) {
    879             lib = getObject_Lib(*handle);
     877            lib = (RpLibrary*) getObject_Void(*handle);
    880878
    881879            if (lib) {
     
    917915    if ( file.is_open() ) {
    918916        if ((handle) && (*handle != 0)) {
    919             lib = getObject_Lib(*handle);
     917            lib = (RpLibrary*) getObject_Void(*handle);
    920918
    921919            if (lib) {
     
    946944
    947945    if ((handle) && (*handle != 0)) {
    948         lib = getObject_Lib(*handle);
     946        lib = (RpLibrary*) getObject_Void(*handle);
    949947
    950948        if (lib) {
     
    968966
    969967    if ((handle) && (*handle != 0)) {
    970         node = getObject_Lib(*handle);
     968        node = (RpLibrary*) getObject_Void(*handle);
    971969
    972970        if (node) {
     
    990988
    991989    if ((handle) && (*handle != 0)) {
    992         node = getObject_Lib(*handle);
     990        node = (RpLibrary*) getObject_Void(*handle);
    993991
    994992        if (node) {
     
    10121010
    10131011    if ((handle) && (*handle != 0)) {
    1014         node = getObject_Lib(*handle);
     1012        node = (RpLibrary*) getObject_Void(*handle);
    10151013
    10161014        if (node) {
     
    10321030
    10331031    if (handle && *handle != 0) {
    1034         lib = getObject_Lib(*handle);
     1032        lib = (RpLibrary*) getObject_Void(*handle);
    10351033        if (lib) {
    10361034            lib->put("tool.version.rappture.language", "fortran");
  • trunk/src/core/RpLibraryFInterface.h

    r1018 r1086  
    114114 * rp_lib_put_obj still needs to be written
    115115 * keep function declaration around
     116*/
    116117void rp_lib_put_obj (       int* handle,
    117118                            char* path,
     
    119120                            int* append,
    120121                            int path_len );
    121 */
    122122
    123123/*
  • trunk/src/core/RpSimpleBuffer.h

    r1065 r1086  
    413413    if (buf == NULL) {
    414414        fprintf(stderr,"Can't allocate %lu bytes of memory\n",
    415                 (long unsigned int)nbytes);
     415            (long unsigned int)nbytes);
    416416        _fileState = false;
    417417        return 0;
     
    446446
    447447    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]);
    449449        curMemb += 1;
    450450    }
Note: See TracChangeset for help on using the changeset viewer.