Ignore:
Timestamp:
Mar 14, 2009 4:20:03 PM (15 years ago)
Author:
gah
Message:

Clean up of warnings, outcomes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanovis/dxReader.cpp

    r1312 r1325  
    4747 * Load a 3D vector field from a dx-format file
    4848 */
    49 void
    50 load_vector_stream2(int volindex, std::istream& fin)
     49bool
     50load_vector_stream2(Rappture::Outcome &result, int volindex, std::istream& fin)
    5151{
    5252    int dummy, nx, ny, nz, npts;
     
    5959        fin.getline(line, sizeof(line) - 1);
    6060        if (fin.fail()) {
    61             //return result.error("error in data stream");
    62             return;
     61            result.addError("error in data stream");
     62            return false;
    6363        }
    6464        for (start=&line[0]; *start == ' ' || *start == '\t'; start++)
     
    8383                printf("point %d\n", npts);
    8484                if (npts != nx*ny*nz) {
    85                     std::cerr << "inconsistent data: expected " << nx*ny*nz << " points but found " << npts << " points" << std::endl;
    86                     return;
     85                    result.addError("inconsistent data: expected %d points"
     86                                    " but found %d points", nx*ny*nz, npts);
     87                    return false;
    8788                }
    8889                break;
    8990            } else if (sscanf(start, "object %d class array type %s rank 0 times %d data follows", &dummy, type, &npts) == 3) {
    9091                if (npts != nx*ny*nz) {
    91                     std::cerr << "inconsistent data: expected " << nx*ny*nz << " points but found " << npts << " points" << std::endl;
    92                     return;
     92                    result.addError("inconsistent data: expected %d points"
     93                                    " but found %d points", nx*ny*nz, npts);
     94                    return false;
    9395                }
    9496                break;
     
    101103    if (!fin.eof()) {
    102104        double vx, vy, vz, vm;
     105#ifdef notdef
    103106        double max_x = -1e21, min_x = 1e21;
    104107        double max_y = -1e21, min_y = 1e21;
    105108        double max_z = -1e21, min_z = 1e21;
     109#endif
    106110        double max_mag = -1e21, min_mag = 1e21;
    107111        int nread = 0;
     
    145149        // make sure that we read all of the expected points
    146150        if (nread != nx*ny*nz) {
    147             std::cerr << "inconsistent data: expected " << nx*ny*nz << " points but found " << nread << " points" << std::endl;
    148             return;
     151            result.addError("inconsistent data: expected %d points"
     152                            " but found %d points", nx*ny*nz, npts);
     153            return false;
    149154        }
    150155
     
    155160
    156161        // generate the uniformly sampled data that we need for a volume
     162#ifdef notdef
    157163        double nzero_min = 0.0;
     164#endif
    158165        int ngen = 0;
    159166        int nindex = 0;
     
    178185
    179186        Volume *volPtr;
    180         volPtr = NanoVis::load_volume(volindex, nx, ny, nz, 4, data, min_mag, max_mag,
    181                     0);
     187        volPtr = NanoVis::load_volume(volindex, nx, ny, nz, 4, data,
     188                min_mag, max_mag, 0);
    182189
    183190        volPtr->xAxis.SetRange(x0, x0 + nx);
     
    190197        std::cerr << "WARNING: data not found in stream" << std::endl;
    191198    }
     199    return true;
    192200}
    193 void
    194 load_vector_stream(int index, std::istream& fin)
     201
     202bool
     203load_vector_stream(Rappture::Outcome result, int index, std::istream& fin)
    195204{
    196205    int dummy, nx, ny, nz, npts;
     
    203212        fin.getline(line, sizeof(line) - 1);
    204213        if (fin.fail()) {
    205             //return result.error("error in data stream");
    206             return;
     214            result.addError("error in data stream");
     215            return false;
    207216        }
    208217        for (start=&line[0]; *start == ' ' || *start == '\t'; start++)
     
    227236                printf("point %d\n", npts);
    228237                if (npts != nx*ny*nz) {
    229                     std::cerr << "inconsistent data: expected " << nx*ny*nz << " points but found " << npts << " points" << std::endl;
    230                     return;
     238                    result.addError("inconsistent data: expected %d points"
     239                                    " but found %d points", nx*ny*nz, npts);
     240                    return false;
    231241                }
    232242                break;
    233243            } else if (sscanf(start, "object %d class array type %s rank 0 times %d data follows", &dummy, type, &npts) == 3) {
    234244                if (npts != nx*ny*nz) {
    235                     std::cerr << "inconsistent data: expected " << nx*ny*nz << " points but found " << npts << " points" << std::endl;
    236                     return;
     245                    result.addError("inconsistent data: expected %d points"
     246                                    " but found %d points", nx*ny*nz, npts);
     247                    return false;
    237248                }
    238249                break;
     
    272283        // make sure that we read all of the expected points
    273284        if (nread != nx*ny*nz) {
    274             std::cerr << "inconsistent data: expected " << nx*ny*nz << " points but found " << nread << " points" << std::endl;
    275             return;
     285            result.addError("inconsistent data: expected %d points"
     286                            " but found %d points", nx*ny*nz, npts);
     287            return false;
    276288        }
    277289
     
    355367        delete [] data;
    356368    } else {
    357         std::cerr << "WARNING: data not found in stream" << std::endl;
     369        result.addError("WARNING: data not found in stream");
     370        return false;
    358371    }
     372    return true;
    359373}
    360 
    361374
    362375/* Load a 3D volume from a dx-format file
    363376 */
    364 Rappture::Outcome
    365 load_volume_stream2(int index, std::iostream& fin)
     377bool
     378load_volume_stream2(Rappture::Outcome &result, int index, std::iostream& fin)
    366379{
    367380    printf("load_volume_stream2\n");
    368     Rappture::Outcome result;
    369 
    370381    Rappture::MeshTri2D xymesh;
    371382    int dummy, nx, ny, nz, nxy, npts;
     
    382393
    383394        if (*start != '#') {  // skip comment lines
    384             if (sscanf(start, "object %d class gridpositions counts %d %d %d", &dummy, &nx, &ny, &nz) == 4) {
     395            if (sscanf(start, "object %d class gridpositions counts %d %d %d",
     396                       &dummy, &nx, &ny, &nz) == 4) {
    385397                // found grid size
    386398                isrect = 1;
     
    432444                    ftri.close();
    433445                } else {
    434                     return result.error("triangularization failed");
    435                 }
    436 
    437                 sprintf(cmdstr, "rm -f %s %s", fpts, fcells);
    438                 system(cmdstr);
     446                    result.error("triangularization failed");
     447                    return false;
     448                }
     449                unlink(fpts), unlink(fcells);
    439450            } else if (sscanf(start, "object %d class regulararray count %d", &dummy, &nz) == 2) {
    440451                // found z-grid
     
    457468        }
    458469        if (count > 1) {
    459             return result.error(
    460             "don't know how to handle multiple non-zero delta values");
     470            result.addError("don't know how to handle multiple non-zero"
     471                            " delta values");
     472            return false;
    461473        }
    462474            } else if (sscanf(start, "object %d class array type %s rank 0 items %d data follows", &dummy, type, &npts) == 3) {
    463475                if (isrect && (npts != nx*ny*nz)) {
    464                     char mesg[256];
    465                     sprintf(mesg,"inconsistent data: expected %d points but found %d points", nx*ny*nz, npts);
    466                     return result.error(mesg);
     476                    result.addError("inconsistent data: expected %d points "
     477                                    " but found %d points", nx*ny*nz, npts);
     478                    return false;
    467479                } else if (!isrect && (npts != nxy*nz)) {
    468                     char mesg[256];
    469                     sprintf(mesg,"inconsistent data: expected %d points but found %d points", nxy*nz, npts);
    470                     return result.error(mesg);
     480                    result.addError("inconsistent data: expected %d points "
     481                                    " but found %d points", nxy*nz, npts);
     482                    return false;
    471483                }
    472484                break;
    473485            } else if (sscanf(start, "object %d class array type %s rank 0 times %d data follows", &dummy, type, &npts) == 3) {
    474486                if (npts != nx*ny*nz) {
    475                     char mesg[256];
    476                     sprintf(mesg,"inconsistent data: expected %d points but found %d points", nx*ny*nz, npts);
    477                     return result.error(mesg);
     487                    result.addError("inconsistent data: expected %d points "
     488                                    " but found %d points", nx*ny*nz, npts);
     489                    return false;
    478490                }
    479491                break;
     
    527539            // make sure that we read all of the expected points
    528540            if (nread != nx*ny*nz) {
    529                 char mesg[256];
    530                 sprintf(mesg,"inconsistent data: expected %d points but found %d points", nx*ny*nz, nread);
    531                 result.error(mesg);
    532                 return result;
     541                result.addError("inconsistent data: expected %d points "
     542                                " but found %d points", nx*ny*nz, nread);
     543                return false;
    533544            }
    534545
     
    578589                fin >> dval;
    579590                if (fin.fail()) {
    580                     char mesg[256];
    581                     sprintf(mesg,"after %d of %d points: can't read number",
    582                             nread, npts);
    583                     return result.error(mesg);
     591                    result.addError("after %d of %d points: can't read number",
     592                                    nread, npts);
     593                    return false;
    584594                } else {
    585595                    int nid = nxy*iz + ixy;
     
    596606            // make sure that we read all of the expected points
    597607            if (nread != nxy*nz) {
    598                 char mesg[256];
    599                 sprintf(mesg,"inconsistent data: expected %d points but found %d points", nxy*nz, nread);
    600                 return result.error(mesg);
     608                result.addError("inconsistent data: expected %d points "
     609                                "but found %d points", nxy*nz, nread);
     610                return false;
    601611            }
    602612
     
    714724        }
    715725    } else {
    716         return result.error("data not found in stream");
     726        result.addError("data not found in stream");
     727        return false;
    717728    }
    718729
     
    724735    float dz0 = -0.5*dz/dx;
    725736    NanoVis::volume[index]->move(Vector3(dx0, dy0, dz0));
    726 
    727     return result;
     737    return true;
    728738}
    729739
     
    806816                    return result.error("triangularization failed");
    807817                }
    808 
    809                 sprintf(cmdstr, "rm -f %s %s", fpts, fcells);
    810                 system(cmdstr);
     818                unlink(fpts);
     819                unlink(fcells);
    811820            } else if (sscanf(start, "object %d class regulararray count %d", &dummy, &nz) == 2) {
    812821                // found z-grid
     
    820829            } else if (sscanf(start, "object %d class array type %s rank 0 items %d data follows", &dummy, type, &npts) == 3) {
    821830                if (isrect && (npts != nx*ny*nz)) {
    822                     char mesg[256];
    823                     sprintf(mesg,"inconsistent data: expected %d points but found %d points", nx*ny*nz, npts);
    824                     return result.error(mesg);
     831                    result.addError("inconsistent data: expected %d points"
     832                                    " but found %d points", nx*ny*nz, npts);
     833                    return false;
    825834                } else if (!isrect && (npts != nxy*nz)) {
    826                     char mesg[256];
    827                     sprintf(mesg,"inconsistent data: expected %d points but found %d points", nxy*nz, npts);
    828                     return result.error(mesg);
     835                    result.addError("inconsistent data: expected %d points"
     836                                    " but found %d points", nx*ny*nz, npts);
     837                    return false;
    829838                }
    830839                break;
    831840            } else if (sscanf(start, "object %d class array type %s rank 0 times %d data follows", &dummy, type, &npts) == 3) {
    832841                if (npts != nx*ny*nz) {
    833                     char mesg[256];
    834                     sprintf(mesg,"inconsistent data: expected %d points but found %d points", nx*ny*nz, npts);
    835                     return result.error(mesg);
     842                    result.addError("inconsistent data: expected %d points"
     843                                    " but found %d points", nx*ny*nz, npts);
     844                    return false;
    836845                }
    837846                break;
     
    879888            // make sure that we read all of the expected points
    880889            if (nread != nx*ny*nz) {
    881                 char mesg[256];
    882                 sprintf(mesg,"inconsistent data: expected %d points but found %d points", nx*ny*nz, nread);
    883                 result.error(mesg);
    884                 return result;
     890                result.addError("inconsistent data: expected %d points"
     891                                " but found %d points", nx*ny*nz, npts);
     892                return false;
    885893            }
    886894
     
    10251033            // make sure that we read all of the expected points
    10261034            if (nread != nxy*nz) {
    1027                 char mesg[256];
    1028                 sprintf(mesg,"inconsistent data: expected %d points but found %d points", nxy*nz, nread);
    1029                 return result.error(mesg);
     1035                result.addError("inconsistent data: expected %d points"
     1036                                " but found %d points", nx*ny*nz, npts);
     1037                return false;
    10301038            }
    10311039
     
    12371245                    return result.error("triangularization failed");
    12381246                }
    1239 
    1240                 sprintf(cmdstr, "rm -f %s %s", fpts, fcells);
    1241                 system(cmdstr);
     1247                unlink(fpts), unlink(fcells);
    12421248            } else if (sscanf(start, "object %d class regulararray count %d", &dummy, &nz) == 2) {
    12431249                // found z-grid
     
    12511257            } else if (sscanf(start, "object %d class array type %s rank 0 items %d data follows", &dummy, type, &npts) == 3) {
    12521258                if (isrect && (npts != nx*ny*nz)) {
    1253                     char mesg[256];
    1254                     sprintf(mesg,"inconsistent data: expected %d points but found %d points", nx*ny*nz, npts);
    1255                     return result.error(mesg);
     1259                    result.addError("inconsistent data: expected %d points"
     1260                                    " but found %d points", nx*ny*nz, npts);
     1261                    return false;
    12561262                } else if (!isrect && (npts != nxy*nz)) {
    1257                     char mesg[256];
    1258                     sprintf(mesg,"inconsistent data: expected %d points but found %d points", nxy*nz, npts);
    1259                     return result.error(mesg);
     1263                    result.addError("inconsistent data: expected %d points"
     1264                                    " but found %d points", nx*ny*nz, npts);
     1265                    return false;
    12601266                }
    12611267                break;
    12621268            } else if (sscanf(start, "object %d class array type %s rank 0 times %d data follows", &dummy, type, &npts) == 3) {
    12631269                if (npts != nx*ny*nz) {
    1264                     char mesg[256];
    1265                     sprintf(mesg,"inconsistent data: expected %d points but found %d points", nx*ny*nz, npts);
    1266                     return result.error(mesg);
     1270                    result.addError("inconsistent data: expected %d points"
     1271                                    " but found %d points", nx*ny*nz, npts);
     1272                    return false;
    12671273                }
    12681274                break;
     
    13101316            // make sure that we read all of the expected points
    13111317            if (nread != nx*ny*nz) {
    1312                 char mesg[256];
    1313                 sprintf(mesg,"inconsistent data: expected %d points but found %d points", nx*ny*nz, nread);
    1314                 result.error(mesg);
    1315                 return result;
     1318                result.addError("inconsistent data: expected %d points"
     1319                                " but found %d points", nx*ny*nz, npts);
     1320                return false;
    13161321            }
    13171322
     
    14971502            // make sure that we read all of the expected points
    14981503            if (nread != nxy*nz) {
    1499                 char mesg[256];
    1500                 sprintf(mesg,"inconsistent data: expected %d points but found %d points", nxy*nz, nread);
    1501                 return result.error(mesg);
     1504                result.addError("inconsistent data: expected %d points"
     1505                                " but found %d points", nx*ny*nz, npts);
     1506                return false;
    15021507            }
    15031508
Note: See TracChangeset for help on using the changeset viewer.