void CopyNcVarAttributes( NcVar * varIn, NcVar * varOut ) { for (int a = 0; a < varIn->num_atts(); a++) { NcAtt * att = varIn->get_att(a); long num_vals = att->num_vals(); NcValues * pValues = att->values(); if (att->type() == ncByte) { varOut->add_att(att->name(), num_vals, (const ncbyte*)(pValues->base())); } else if (att->type() == ncChar) { varOut->add_att(att->name(), num_vals, (const char*)(pValues->base())); } else if (att->type() == ncShort) { varOut->add_att(att->name(), num_vals, (const short*)(pValues->base())); } else if (att->type() == ncInt) { varOut->add_att(att->name(), num_vals, (const int*)(pValues->base())); } else if (att->type() == ncFloat) { varOut->add_att(att->name(), num_vals, (const float*)(pValues->base())); } else if (att->type() == ncDouble) { varOut->add_att(att->name(), num_vals, (const double*)(pValues->base())); } else { _EXCEPTIONT("Invalid attribute type"); } delete pValues; } }
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; }
eavlNetCDFImporter::eavlNetCDFImporter(const string &filename) { file = new NcFile(filename.c_str(), NcFile::ReadOnly); if (!file->is_valid()) { THROW(eavlException,"Couldn't open file!\n"); } if (debugoutput) cerr << "num_dims="<<file->num_dims()<<endl; if (debugoutput) cerr << "num_vars="<<file->num_vars()<<endl; if (debugoutput) cerr << "num_atts="<<file->num_atts()<<endl; for (int i=0; i<file->num_dims(); i++) { NcDim *d = file->get_dim(i); if (debugoutput) cerr << " dim["<<i<<"]: name="<<d->name()<<" size="<<d->size()<<endl; } for (int i=0; i<file->num_atts(); i++) { NcAtt *a = file->get_att(i); if (debugoutput) cerr << " att["<<i<<"]: name="<<a->name()<<" numvals="<<a->num_vals()<<endl; } bool found_grid = false; for (int i=0; i<file->num_vars(); i++) { NcVar *v = file->get_var(i); if (debugoutput) { cerr << " var["<<i<<"]: name="<<v->name(); cerr << " ndims="<<v->num_dims(); cerr << " dims = "; for (int j=0; j<v->num_dims(); j++) { cerr << v->get_dim(j)->name(); if (j<v->num_dims()-1) cerr << "*"; } cerr << endl; } // Here's the condition for what we're going to use; // we only support one mesh for the moment, so we're picking one. // Also, the netcdf files we have have the time dim size as "1" if (v->num_dims() == 4 && string(v->get_dim(0)->name())=="time") { if (!found_grid) { dims.push_back(v->get_dim(1)); dims.push_back(v->get_dim(2)); dims.push_back(v->get_dim(3)); found_grid = true; vars.push_back(v); if (debugoutput) cerr << " * using as first real var\n"; } else { if (string(v->get_dim(1)->name()) == dims[0]->name() && string(v->get_dim(2)->name()) == dims[1]->name() && string(v->get_dim(3)->name()) == dims[2]->name()) { vars.push_back(v); if (debugoutput) cerr << " * using as another var; matches the first real one's dims\n"; } } } } }
void avtS3DFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md, int timeState) { debug5 << "avtS3DFileFormat::PopulateDatabaseMetaData" << endl; // Get the metadata from the log file first. OpenLogFile(); // Mesh avtMeshMetaData *mesh = new avtMeshMetaData; mesh->name = "mesh"; mesh->meshType = AVT_RECTILINEAR_MESH; mesh->numBlocks = procs[0] * procs[1] * procs[2]; mesh->blockOrigin = 1; mesh->cellOrigin = 0; mesh->spatialDimension = 3; mesh->topologicalDimension = 3; mesh->blockTitle = "blocks"; mesh->blockPieceName = "block"; mesh->hasSpatialExtents = false; mesh->xUnits = "mm"; mesh->yUnits = "mm"; mesh->zUnits = "mm"; md->Add(mesh); // // Look in the NetCDF file for the first block for the list of variables. // // Calculate the timestep directory that the data lives in. char *pathcopy = strdup(mainFilename); string dir = parse_dirname(pathcopy); string timestepDir = CreateStringFromDouble(fileTimes[timeState]); char path[256]; SNPRINTF(path,256,"%s%s%s%sfield.00000",dir.c_str(),VISIT_SLASH_STRING, timestepDir.c_str(), VISIT_SLASH_STRING); NcError err(NcError::verbose_nonfatal); NcFile nf(path); if (!nf.is_valid()) { EXCEPTION1(InvalidFilesException, path); } debug5 << "avtS3DFileFormat::PopulateDatabaseMetaData: Got valid file" << endl; int nvars = nf.num_vars(); debug5 << "avtS3DFileFormat::PopulateDatabaseMetaData: Found " << nvars << " variables" << endl; for (int i=0 ; i<nvars; i++) { NcVar *v = nf.get_var(i); if (!v) continue; debug4 << "Found variable " << v->name() << endl; // Check dimensionality int nvals = v->num_vals(); if (nvals != 1) // Single scalars are useless. { avtScalarMetaData *scalar = new avtScalarMetaData(); scalar->name = v->name(); scalar->meshName = "mesh"; scalar->centering = AVT_NODECENT; scalar->hasDataExtents = false; scalar->treatAsASCII = false; NcAtt *units = v->get_att(NcToken("units")); if (units) { long nv = units->num_vals(); if (nv == 0) { scalar->hasUnits = false; } else { char *unitString = units->as_string(0); scalar->units = unitString; scalar->hasUnits = true; } } else scalar->hasUnits = false; md->Add(scalar); } else { debug4 << "Unable to process variable " << v->name() << " since it is a single scalar" << endl; } } #if 0 // Expressions Expression tempGradient_expr; tempGradient_expr.SetName("Temperature_gradient"); tempGradient_expr.SetDefinition("gradient(Temperature)"); tempGradient_expr.SetType(Expression::VectorMeshVar); tempGradient_expr.SetHidden(true); md->AddExpression(&tempGradient_expr); Expression tempUnit_expr; tempUnit_expr.SetName("Temperature_grad_unit"); //tempUnit_expr.SetDefinition("(Temperature_gradient + {1e-6,0,0})/(magnitude(Temperature_gradient) + 1e-6)"); //tempUnit_expr.SetDefinition("Temperature_gradient/(magnitude(Temperature_gradient) + 1e-6)"); tempUnit_expr.SetDefinition("normalize(Temperature_gradient)"); tempUnit_expr.SetType(Expression::VectorMeshVar); tempUnit_expr.SetHidden(true); md->AddExpression(&tempUnit_expr); Expression tempCurv_expr; tempCurv_expr.SetName("Temperature_curvature"); tempCurv_expr.SetDefinition("divergence(Temperature_grad_unit)"); tempCurv_expr.SetType(Expression::ScalarMeshVar); tempUnit_expr.SetHidden(false); md->AddExpression(&tempCurv_expr); #endif }