// // Writes the data to given Silo file under the virtual path provided. // The corresponding mesh must have been written already. // bool DataVar::writeToSilo(DBfile* dbfile, const string& siloPath, const string& units) { #ifdef ESYS_HAVE_SILO if (!initialized) return false; if (numSamples == 0) return true; int ret; if (siloPath != "") { ret = DBSetDir(dbfile, siloPath.c_str()); if (ret != 0) return false; } char* siloMesh = const_cast<char*>(siloMeshName.c_str()); int dcenter = (centering == NODE_CENTERED ? DB_NODECENT : DB_ZONECENT); DBoptlist* optList = DBMakeOptlist(2); if (units.length()>0) { DBAddOption(optList, DBOPT_UNITS, (void*)units.c_str()); } if (rank == 0) { ret = DBPutUcdvar1(dbfile, varName.c_str(), siloMesh, dataArray[0], numSamples, NULL, 0, DB_FLOAT, dcenter, optList); } else if (rank == 1) { const string comps[3] = { varName+string("_x"), varName+string("_y"), varName+string("_z") }; const char* varnames[3] = { comps[0].c_str(), comps[1].c_str(), comps[2].c_str() }; ret = DBPutUcdvar(dbfile, varName.c_str(), siloMesh, shape[0], (char**)varnames, &dataArray[0], numSamples, NULL, 0, DB_FLOAT, dcenter, optList); } else { string tensorDir = varName+string("_comps/"); ret = DBMkdir(dbfile, tensorDir.c_str()); if (ret == 0) { int one = 1; DBAddOption(optList, DBOPT_HIDE_FROM_GUI, &one); for (int i=0; i<shape[1]; i++) { for (int j=0; j<shape[0]; j++) { ostringstream varname; varname << tensorDir << "a_" << i << j; ret = DBPutUcdvar1(dbfile, varname.str().c_str(), siloMesh, dataArray[i*shape[0]+j], numSamples, NULL, 0, DB_FLOAT, dcenter, optList); if (ret != 0) break; } if (ret != 0) break; } } // ret==0 } // rank DBFreeOptlist(optList); DBSetDir(dbfile, "/"); return (ret == 0); #else // !ESYS_HAVE_SILO return false; #endif }
/*------------------------------------------------------------------------- * Function: test_dirs * * Purpose: Test directory operations * * Return: Success: 0 * * Failure: number of errors * * Programmer: Robb Matzke * Wednesday, February 10, 1999 * * Modifications: * Robb Matzke, 2000-01-12 * Changed hyphens to underscores in object names because silo * now fails when underscores are present in the name. *------------------------------------------------------------------------- */ static int test_dirs(DBfile *dbfile) { int nerrors=0; char curdir[1024]; static int in[1]={911}, value[1]={0}; static int dims[1]={1}; puts("=== Directories ==="); /* Make some directories */ if (DBMkDir(dbfile, "dir1")<0) { puts("DBMkDir(dir1) failed"); nerrors++; } if (DBMkDir(dbfile, "dir1/d1a")<0) { puts("DBMkDir(dir1/d1a) failed"); nerrors++; } if (DBMkDir(dbfile, "/dir1/d1b")<0) { puts("DBMkDir(dir1/d1b) failed"); nerrors++; } if (DBMkDir(dbfile, "/dir1/d1c/")<0) { puts("DBMkDir(dir1/d1c) failed"); nerrors++; } if (DBMkdir(dbfile, "//dir2//")<0) { puts("DBMkDir(dir2) failed"); nerrors++; } /* Set the CWD to /dir1/d1c and write a variable */ if (DBSetDir(dbfile, "//dir1//d1c//")<0) { puts("DBSetDir(/dir1/d1c) failed"); nerrors++; } if (DBWrite(dbfile, "d1c_A", value, dims, 1, DB_INT)<0) { puts("DBWrite(d1c_A) failed"); nerrors++; } if (DBGetDir(dbfile, curdir)<0 || strcmp(curdir, "/dir1/d1c")) { puts("DBGetDir() failed"); nerrors++; } if (DBReadVar(dbfile, "../d1c/..//..////dir1/d1c//d1c_A", in)<0 || in[0]!=value[0]) { puts("DBReadVar(d1c_A) failed"); nerrors++; } /* Test table of contents */ if (NULL==DBGetToc(dbfile)) { puts("DBGetToc() failed"); nerrors++; } /* Set CWD to top */ if (DBSetDir(dbfile, "/")<0) { puts("DBSetDir(/) failed"); nerrors++; } if (DBGetDir(dbfile, curdir)<0 || strcmp(curdir, "/")) { puts("DBetDir() failed"); nerrors++; } return nerrors; }