Changeset 2408


Ignore:
Timestamp:
Aug 24, 2011, 7:01:44 PM (13 years ago)
Author:
dkearney
Message:

adding a getFile function for rappture library and fortran bindings so fortran users no longer need to know the length of a string a user provides them as input, before compile time. they can now just dump the string into a file, and read the file as they are probably already used to doing. also fixed a bug in teh Rappture::Buffer dump function where it would correctly open a file pointer, but failed the check to see if the file pointer was opened.

Location:
trunk/src/core
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/RpBuffer.cc

    r1527 r2408  
    172172    FILE *f;
    173173    f = fopen(filePath, "wb");
    174     if (f != NULL) {
     174    if (f == NULL) {
    175175        status.addError("can't open \"%s\": %s\n", filePath, strerror(errno));
    176176        return false;
  • trunk/src/core/RpLibrary.cc

    r1707 r2408  
    17351735
    17361736/**********************************************************************/
     1737// METHOD: getFile()
     1738/// Get the value at path and write it to the file at fileName
     1739/**
     1740 * Return the number of bytes written
     1741 */
     1742
     1743size_t
     1744RpLibrary::getFile (std::string path, std::string fileName) const
     1745{
     1746    Rappture::Buffer buf;
     1747
     1748    buf = getData(path);
     1749
     1750    if (buf.bad()) {
     1751        status.addContext("RpLibrary::getFile()");
     1752        return 0;
     1753    }
     1754
     1755    if (!buf.dump(status, fileName.c_str())) {
     1756        status.addContext("RpLibrary::getFile()");
     1757        return 0;
     1758    }
     1759
     1760    return buf.size();
     1761}
     1762
     1763
     1764/**********************************************************************/
    17371765// METHOD: put()
    17381766/// Put a string value into the xml.
     
    18131841        // library doesn't exist, do nothing;
    18141842        status.error("invalid library object");
    1815         status.addContext("RpLibrary::put()");
     1843        status.addContext("RpLibrary::put() - putDouble");
    18161844        return *this;
    18171845    }
     
    18201848
    18211849    put(path,valStr.str(),id,append);
    1822     status.addContext("RpLibrary::put() - putDouble");
    18231850    return *this;
    18241851}
     
    20072034    Rappture::Buffer buf;
    20082035    Rappture::Buffer fileBuf;
    2009     Rappture::Outcome err;
    20102036
    20112037    if (!this->root) {
     
    20142040    }
    20152041
    2016     if (!fileBuf.load(err, fileName.c_str())) {
    2017         fprintf(stderr, "error loading file: %s\n", err.remark());
     2042    if (!fileBuf.load(status, fileName.c_str())) {
     2043        fprintf(stderr, "error loading file: %s\n", status.remark());
     2044        status.addContext("RpLibrary::putFile()");
    20182045        return *this;
    20192046    }
     
    20252052        put(path, fileBuf.bytes(), "", append, RPLIB_TRANSLATE);
    20262053    }
    2027     status.addContext("RpLibrary::putFile()");
    20282054    return *this;
    20292055}
  • trunk/src/core/RpLibrary.h

    r1041 r2408  
    8181        bool        getBool   ( std::string path = "") const;
    8282        Rappture::Buffer getData ( std::string path = "") const;
     83        size_t      getFile   ( std::string path,
     84                                std::string fileName) const;
    8385
    8486        /*
  • trunk/src/core/RpLibraryFInterface.cc

    r1105 r2408  
    605605
    606606/**********************************************************************/
     607// FUNCTION: rp_lib_get_file()
     608/// Get data located at 'path' and write it to the file 'fileName'.
     609/**
     610 * Returns if any bytes were written to the file
     611 */
     612int rp_lib_get_file (   int* handle,     /* integer handle of library */
     613                        char* path,      /* null terminated path */
     614                        char* fileName,  /* name of file to write data to */
     615                        int path_len,    /* length of the path variable */
     616                        int fileName_len /* length of the fileName variable */
     617                     )
     618{
     619    size_t nbytes = 0;
     620    int ret = 0;
     621
     622    RpLibrary* lib = NULL;
     623
     624    std::string inPath = "";
     625    std::string filePath = "";
     626
     627    inPath = null_terminate_str(path,path_len);
     628    filePath = null_terminate_str(fileName,fileName_len);
     629
     630    if ((handle) && (*handle != 0)) {
     631        lib = (RpLibrary*) getObject_Void(*handle);
     632
     633        if (lib) {
     634            nbytes = lib->getFile(inPath, filePath);
     635        }
     636    }
     637
     638    if (nbytes > 0) {
     639        ret = 1;
     640    }
     641
     642    return ret;
     643}
     644
     645
     646
     647/**********************************************************************/
    607648// FUNCTION: rp_lib_put_str()
    608649/// Put string into Rappture Library Object at location 'path'.
  • trunk/src/core/RpLibraryFInterface.h

    r1086 r2408  
    7878                            char* path,
    7979                            int path_len);
     80
     81int rp_lib_get_file (       int* handle,
     82                            char* path,
     83                            char* fileName,
     84                            int path_len,
     85                            int fileName_len);
    8086
    8187void rp_lib_put_str (       int* handle,
  • trunk/src/core/RpLibraryFStubs.c

    r1018 r2408  
    340340}
    341341
     342int rp_lib_get_file_ (  int* handle,
     343                        char* path,
     344                        char* fileName,
     345                        int path_len,
     346                        int fileName_len) {
     347
     348    return rp_lib_get_file(handle,path,fileName,path_len,fileName_len);
     349}
     350
     351int rp_lib_get_file__ ( int* handle,
     352                        char* path,
     353                        char* fileName,
     354                        int path_len,
     355                        int fileName_len) {
     356
     357    return rp_lib_get_file(handle,path,fileName,path_len,fileName_len);
     358}
     359
     360int RP_LIB_GET_FILE (   int* handle,
     361                        char* path,
     362                        char* fileName,
     363                        int path_len,
     364                        int fileName_len) {
     365
     366    return rp_lib_get_file(handle,path,fileName,path_len,fileName_len);
     367}
     368
    342369void
    343370rp_lib_put_str_ (       int* handle,
     
    353380
    354381void
    355 rp_lib_put_str__ (       int* handle,
     382rp_lib_put_str__ (      int* handle,
    356383                        char* path,
    357384                        char* value,
  • trunk/src/core/RpLibraryFStubs.h

    r1018 r2408  
    8282                            int path_len);
    8383
     84int rp_lib_get_file_ (      int* handle,
     85                            char* path,
     86                            char* fileName,
     87                            int path_len,
     88                            int fileName_len);
     89
    8490void rp_lib_put_str_ (      int* handle,
    8591                            char* path,
     
    223229                            int path_len);
    224230
     231int rp_lib_get_file__ (     int* handle,
     232                            char* path,
     233                            char* fileName,
     234                            int path_len,
     235                            int fileName_len);
     236
    225237void rp_lib_put_str__ (     int* handle,
    226238                            char* path,
     
    365377                            int path_len);
    366378
     379int RP_LIB_GET_FILE (       int* handle,
     380                            char* path,
     381                            char* fileName,
     382                            int path_len,
     383                            int fileName_len);
     384
    367385void RP_LIB_PUT_STR (       int* handle,
    368386                            char* path,
Note: See TracChangeset for help on using the changeset viewer.