1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
|
// ************************************************************************* //
// avtFVCOM_STSDFileFormat.C //
// ************************************************************************* //
#include <avtFVCOM_STSDFileFormat.h>
#include <string>
#include <vtkFloatArray.h>
#include <vtkRectilinearGrid.h>
#include <vtkUnstructuredGrid.h>
#include <avtDatabaseMetaData.h>
#include <Expression.h>
#include <InvalidVariableException.h>
#include <DebugStream.h>
#include <NETCDFFileObject.h>
#include <avtFVCOMReader.h>
#include <avtMaterial.h>
#include "vtk_netcdf.h"
using std::string;
// ****************************************************************************
// Method: avtFVCOMFileFormat::Identify
//
// Purpose:
// This method checks to see if the file is an FVCOM file.
//
// Arguments:
// fileObject : The file to check.
//
// Returns: True if the file is a particle file; False otherwise.
//
// Note:
//
// Programmer: David Stuebe
// Creation: Thu May 4 16:18:57 PST 2006
//
// Modifications:
//
// ****************************************************************************
bool
avtFVCOM_STSDFileFormat::Identify(NETCDFFileObject *fileObject)
{
bool isFVCOM = false;
//
// Use the fileObject to look for something in the file that will make us
// believe that it is a FVCOM file. The check can be as complex as you want
// but it should not return true unless this really is an FVCOM file.
//
std::string source;
if(fileObject->ReadStringAttribute("source", source))
{
isFVCOM = strncmp("FVCOM",source.c_str(),5)==0;
}
// Make sure it is STSD.
if(isFVCOM)
{
size_t ntimesteps;
int status, time_id, ncid;
ncid=fileObject->GetFileHandle();
status = nc_inq_dimid(ncid, "time", &time_id);
if (status != NC_NOERR) fileObject-> HandleError(status);
status = nc_inq_dimlen(ncid, time_id, &ntimesteps);
if (status != NC_NOERR) fileObject-> HandleError(status);
if(ntimesteps==1)
{
isFVCOM= true;
}
else
{
isFVCOM=false;
}
}
return isFVCOM;
}
// ****************************************************************************
// Method: avtFVCOMFileFormat::CreateInterface
//
// Purpose:
// Creates the file format interface for this reader.
//
// Programmer: David Stuebe
// Creation: Thu May 4 16:18:57 PST 2006
//
// Modifications:
//
// ****************************************************************************
avtFileFormatInterface *
avtFVCOM_STSDFileFormat::CreateInterface(NETCDFFileObject *f,
const char *const *list, int nList, int nBlock)
{
avtSTSDFileFormat ***ffl = new avtSTSDFileFormat**[nList];
int nTimestep = nList / nBlock;
for (int i = 0 ; i < nTimestep ; i++)
{
ffl[i] = new avtSTSDFileFormat*[nBlock];
for (int j = 0 ; j < nBlock ; j++)
{
if(f != 0)
{
ffl[i][j] = new avtFVCOM_STSDFileFormat(list[i*nBlock + j], f);
f = 0;
}
else
ffl[i][j] = new avtFVCOM_STSDFileFormat(list[i*nBlock + j]);
}
}
return new avtSTSDFileFormatInterface(ffl, nTimestep, nBlock);
}
// ****************************************************************************
// Method: avtFVCOM_STSD constructor
//
// Programmer: David Stuebe
// Creation: Wed May 31 15:50:45 PST 2006
//
// ****************************************************************************
avtFVCOM_STSDFileFormat::avtFVCOM_STSDFileFormat(const char *filename)
: avtSTSDFileFormat(filename)
{
// debug4 << "avtFVCOM_STSDFileFormat::avtFVCOM_STSDFileFormat" << endl;
reader = new avtFVCOMReader(filename);
reader->SetKeySuffixForCaching(filename);
// debug4 << "avtFVCOM_STSDFileFormat::avtFVCOM_STSDFileFormat: end" << endl;
}
avtFVCOM_STSDFileFormat::avtFVCOM_STSDFileFormat(const char *filename,
NETCDFFileObject *f) : avtSTSDFileFormat(filename)
{
// debug4 << "avtFVCOM_STSDFileFormat::avtFVCOM_STSDFileFormat(name f)" << endl;
reader = new avtFVCOMReader(filename,f);
reader->SetKeySuffixForCaching(filename);
// debug4 << "avtFVCOM_STSDFileFormat::avtFVCOM_STSDFileFormat(name f): end" << endl;
}
// ****************************************************************************
// Method: avtFVCOM_STSD destructor
//
// Programmer: David Stuebe
// Creation: Wed May 31 15:50:45 PST 2006
//
// ****************************************************************************
avtFVCOM_STSDFileFormat::~avtFVCOM_STSDFileFormat()
{
debug4 << "avtFVCOM_STSDFileFormat::~avtFVCOM_STSDFileFormat" << endl;
// debug4 << "reader: " << reader << endl;
delete reader;
debug4 << "avtFVCOM_STSDFileFormat::~avtFVCOM_STSDFileFormat: end" << endl;
}
// ****************************************************************************
// Method: avtFVCOM_STSDFileFormat::FreeUpResources
//
// Purpose:
// When VisIt is done focusing on a particular timestep, it asks that
// timestep to free up any resources (memory, file descriptors) that
// it has associated with it. This method is the mechanism for doing
// that.
//
// Programmer: David Stuebe
// Creation: Wed May 31 15:50:45 PST 2006
//
// ****************************************************************************
void
avtFVCOM_STSDFileFormat::FreeUpResources(void)
{
debug4 << "avtFVCOM_STSDFileFormat::FreeUpResources" << endl;
reader->FreeUpResources();
debug4 << "avtFVCOM_STSDFileFormat::FreeUpResources: end" << endl;
}
// ****************************************************************************
// Method: avtFVCOMReader::GetCycles
//
// Purpose:
// Returns the time cycle in the file.
//
// Arguments:
// cyc : The times cycle to be returned.
//
// Programmer: David Stuebe
// Creation: Thu May 18 08:39:01 PDT 2006
//
// Modifications: Ref to FVCOM Reader class!
//
// ****************************************************************************
int
avtFVCOM_STSDFileFormat::GetCycle(void)
{
// reader->GetNTimesteps();
std::vector<int> cycles;
reader->GetCycles(cycles);
debug4 << "Cycle size=" << cycles.size() << endl;
debug4 << "Cycles=" << cycles[0] << endl;
return (cycles.size() > 0) ? cycles[0] : 0;
}
// ****************************************************************************
// Method: avtFVCOM_STSDFileFormat::GetTime
//
// Purpose:
// Returns the time for the dataset.
//
// Programmer: David Stuebe
// Creation: Wed May 31 15:50:45 PST 2006
//
// Modifications:
//
// ****************************************************************************
double
avtFVCOM_STSDFileFormat::GetTime(void)
{
std::vector<double> time;
reader->GetTimes(time);
debug4 << "Time size=" << time.size() << endl;
debug4 << "TIME=" << time[0] << endl;
return (time.size() > 0) ? time[0] : 0;
}
// ****************************************************************************
// Method: avtFVCOM_STSDFileFormat::PopulateDatabaseMetaData
//
// Purpose:
// This database meta-data object is like a table of contents for the
// file. By populating it, you are telling the rest of VisIt what
// information it can request from you.
//
// Programmer: David Stuebe
// Creation: Wed May 31 15:50:45 PST 2006
//
// ****************************************************************************
void
avtFVCOM_STSDFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md)
{
debug4<< "Should run GetCycle" << endl;
reader->PopulateDatabaseMetaData(md, 0, GetType());
}
// ****************************************************************************
// Method: avtFVCOM_STSDFileFormat::GetMesh
//
// Purpose:
// Gets the mesh associated with this file. The mesh is returned as a
// derived type of vtkDataSet (ie vtkRectilinearGrid, vtkStructuredGrid,
// vtkUnstructuredGrid, etc).
//
// Arguments:
// meshname The name of the mesh of interest. This can be ignored if
// there is only one mesh.
//
// Programmer: David Stuebe
// Creation: Wed May 31 15:50:45 PST 2006
//
// ****************************************************************************
vtkDataSet *
avtFVCOM_STSDFileFormat::GetMesh(const char *meshname)
{
reader->SetDomainIndexForCaching(0);
return reader->GetMesh(0, meshname, cache);
}
// ****************************************************************************
// Method: avtFVCOM_STSDFileFormat::GetAuxiliaryData
//
// Purpose:
// Gets the material object for the particles.
//
// Arguments:
//
// Returns:
//
// Note:
//
// Programmer: David Stuebe
// Creation: Mon Jul 17 2006
//
// Modifications:
//
// ****************************************************************************
void *
avtFVCOM_STSDFileFormat::GetAuxiliaryData(const char *var,
const char *type, void *args, DestructorFunction &df)
{
return reader->GetAuxiliaryData(var, 0, type, args, df);
}
// ****************************************************************************
// Method: avtFVCOM_STSDFileFormat::GetVar
//
// Purpose:
// Gets a scalar variable associated with this file. Although VTK has
// support for many different types, the best bet is vtkFloatArray, since
// that is supported everywhere through VisIt.
//
// Arguments:
// varname The name of the variable requested.
//
// Programmer: David Stuebe
// Creation: Wed May 31 15:50:45 PST 2006
//
// ****************************************************************************
vtkDataArray *
avtFVCOM_STSDFileFormat::GetVar(const char *varname)
{
reader->SetDomainIndexForCaching(0);
return reader->GetVar(0, varname, cache);
}
// ****************************************************************************
// Method: avtFVCOM_STSDFileFormat::GetVectorVar
//
// Purpose:
// Gets a vector variable associated with this file. Although VTK has
// support for many different types, the best bet is vtkFloatArray, since
// that is supported everywhere through VisIt.
//
// Arguments:
// varname The name of the variable requested.
//
// Programmer: David Stuebe
// Creation: Wed May 31 15:50:45 PST 2006
//
// ****************************************************************************
vtkDataArray *
avtFVCOM_STSDFileFormat::GetVectorVar(const char *varname)
{
reader->SetDomainIndexForCaching(0);
return reader->GetVectorVar(0, varname, cache);
}
|