bool RemapWidget::getVolumeInfo(QString volfile, int &skipheaderbytes, uchar &voxelType, int &voxelUnit, float &vx, float &vy, float &vz, QString &description, QList<float> &rawMap, QList<uchar> &pvlMap, int &depth, int &width, int &height) { NcError err(NcError::verbose_nonfatal); NcFile pvlFile(volfile.toAscii().data(), NcFile::ReadOnly); if (!pvlFile.is_valid()) { QMessageBox::information(0, "Error", QString("%1 is not a valid preprocessed volume file").arg(volfile)); return false; } int i; NcAtt *att; char *attval; QString pvalue; att = pvlFile.get_att("description"); if (att) { attval = att->as_string(0); description = attval; delete [] attval; } att = pvlFile.get_att("voxeltype"); if (att) { attval = att->as_string(0); pvalue = attval; if (pvalue == "unsigned char") voxelType = Raw2Pvl::_UChar; if (pvalue == "char") voxelType = Raw2Pvl::_Char; if (pvalue == "unsigned short") voxelType = Raw2Pvl::_UShort; if (pvalue == "short") voxelType = Raw2Pvl::_Short; if (pvalue == "int") voxelType = Raw2Pvl::_Int; if (pvalue == "float") voxelType = Raw2Pvl::_Float; delete [] attval; } att = pvlFile.get_att("voxelunit"); if (att) { attval = att->as_string(0); pvalue = attval; voxelUnit = Raw2Pvl::_Nounit; if (pvalue == "angstrom") voxelUnit = Raw2Pvl::_Angstrom; else if (pvalue == "nanometer") voxelUnit = Raw2Pvl::_Nanometer; else if (pvalue == "micron") voxelUnit = Raw2Pvl::_Micron; else if (pvalue == "millimeter") voxelUnit = Raw2Pvl::_Millimeter; else if (pvalue == "centimeter") voxelUnit = Raw2Pvl::_Centimeter; else if (pvalue == "meter") voxelUnit = Raw2Pvl::_Meter; else if (pvalue == "kilometer") voxelUnit = Raw2Pvl::_Kilometer; else if (pvalue == "parsec") voxelUnit = Raw2Pvl::_Parsec; else if (pvalue == "kiloparsec") voxelUnit = Raw2Pvl::_Kiloparsec; delete [] attval; } att = pvlFile.get_att("gridsize"); if (att) { depth = att->as_int(0); width = att->as_int(1); height = att->as_int(2); } att = pvlFile.get_att("voxelsize"); if (att) { vx = att->as_float(0); vy = att->as_float(1); vz = att->as_float(2); } att = pvlFile.get_att("skipheaderbytes"); if (att) skipheaderbytes = att->as_int(0); att = pvlFile.get_att("mapraw"); if (att) { for(i=0; i<att->num_vals(); i++) rawMap.append(att->as_float(i)); att = pvlFile.get_att("mappvl"); for(i=0; i<att->num_vals(); i++) pvlMap.append(att->as_ncbyte(i)); } pvlFile.close(); return true; }
vtkDataArray * avtS3DFileFormat::GetVar(int timeState, int domain, const char *varname) { debug5 << "avtS3DFileFormat::GetVar( timeState=" << timeState << ", domain=" << domain << ", varname=" << varname << ")" << endl; // Calculate the timestep directory that the data lives in. char *pathcopy = strdup(mainFilename); string dir = parse_dirname(pathcopy); string timestepDir = CreateStringFromDouble(fileTimes[timeState]); debug4 << "Timestep directory is <" << timestepDir << ">" << endl; // Figure out how big this piece is. CalculateSubpiece(domain); // Open up the NetCDF file. char path[256]; SNPRINTF(path,256,"%s%s%s%sfield.%05d",dir.c_str(),VISIT_SLASH_STRING, timestepDir.c_str(), VISIT_SLASH_STRING, domain); debug5 << "avtS3DFileFormat::GetVar: Full path to data file is " << path << endl; NcFile nf(path); if (!nf.is_valid()) { debug1 << nc_strerror(NcError().get_err()) << endl; EXCEPTION1(InvalidFilesException, path); } debug5 << "avtS3DFileFormat::GetVar: Got valid file." << endl; // Pull out the appropriate variable. NcVar *v = nf.get_var(varname); if (!v) { debug1 << nc_strerror(NcError().get_err()) << endl; EXCEPTION1(InvalidVariableException, varname); } // Check if it fits the size of the mesh. Always node-centered, remember. int ntuples = localDims[0] * localDims[1] * localDims[2]; debug5 << "ntuples:" << ntuples << endl; int nvals = v->num_vals(); if (ntuples != nvals) { debug1 << "The variable " << v->name() << " does not conform to its mesh (" << nvals << " != " << ntuples << ")" << endl; EXCEPTION1(InvalidVariableException, v->name()); } // Set up the VTK dataset. vtkFloatArray *rv = vtkFloatArray::New(); rv->SetNumberOfTuples(ntuples); float *p = (float*)rv->GetVoidPointer(0); NcValues *input = v->values(); if (!input) { debug1 << nc_strerror(NcError().get_err()) << endl; EXCEPTION1(InvalidVariableException, v->name()); } // Get the scaling factor. NcAtt *scaling = v->get_att(NcToken("scale_factor")); float scaling_factor = 1; if (scaling) { scaling_factor = scaling->as_float(0); debug5 << "avtS3DFileFormat::GetVar: Set the scaling factor as " << scaling_factor << endl; } // Process the variable into the returned data. float *base = (float*)input->base(); for(int i=0;i<ntuples;i++) { p[i] = *(base + i) * scaling_factor; } return rv; }