Commit ab52cada authored by hrchilds's avatar hrchilds
Browse files

Update from May 9, 2004

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@238 18c085ea-50e0-402c-830e-de6fd14e8384
parent 0161bc5f
......@@ -319,6 +319,9 @@ $0 = shift @ARGV;
# Brad Whitlock, Tue Apr 27 09:49:57 PDT 2004
# I removed some obsolete MacOS X coding and I updated the GDB directories.
#
# Hank Childs, Sun May 9 11:48:58 PDT 2004
# Add a line to the usage regarding "default_format".
#
###############################################################################
......@@ -456,6 +459,8 @@ USAGE: visit [arguments]
-gui or -movie.
-verbose Prints status information during pipeline
execution.
-default_format Sets the database plugin format to use as a default
if the file type cannot be resolved by using extensions.
Debugging arguments:
-debug <level> Run with <level> levels of output logging.
......
......@@ -39,11 +39,45 @@ using std::string;
using std::vector;
//
// Function Prototypes
// Static data members
//
char *avtDatabaseFactory::defaultFormat = "Silo";
//
// Function Prototypes
//
void CheckPermissions(const char *);
// ****************************************************************************
// Method: avtDatabaseFactory::SetDefaultFormat
//
// Purpose:
// Sets the default format to use if the file type cannot be determined
// by looking at extensions.
//
// Arguments:
// format The name of the format to use (example: "Silo")
// Programmer: Hank Childs
// Creation: May 9, 2004
//
// ****************************************************************************
void
avtDatabaseFactory::SetDefaultFormat(const char *f)
{
//
// It's quite possible that the current format string is pointing to
// something on the heap (in which case we should free it). However, it
// might be pointing to something in the program portion of memory, which
// would be a bad thing to delete. So just leak it. It's only a few
// bytes.
defaultFormat = new char[strlen(f)+1];
strcpy(defaultFormat, f);
}
// ****************************************************************************
// Method: avtDatabaseFactory::FileList
//
......@@ -91,6 +125,9 @@ void CheckPermissions(const char *);
// Brad Whitlock, Fri Apr 30 16:05:42 PST 2004
// I made extension comparison be case insensitive on Windows.
//
// Hank Childs, Sun May 9 11:41:45 PDT 2004
// Use the user-settable default format, rather than a hard-coded "Silo".
//
// ****************************************************************************
avtDatabase *
......@@ -239,7 +276,7 @@ avtDatabaseFactory::FileList(const char * const * filelist, int filelistN,
//
// If no file extension match, then we default to the given database type
//
string defaultDatabaseType("Silo");
string defaultDatabaseType(defaultFormat);
if (rv == NULL)
{
int defaultindex = dbmgr->GetAllIndexFromName(defaultDatabaseType);
......
......@@ -36,6 +36,9 @@ class CommonDatabasePluginInfo;
// Added string specifying format type. Also removed outdated comments
// from the era when the DB factory knew about specific formats.
//
// Hank Childs, Sun May 9 11:41:45 PDT 2004
// Allow for default file format type to be set.
//
// ****************************************************************************
class DATABASE_API avtDatabaseFactory
......@@ -45,11 +48,14 @@ class DATABASE_API avtDatabaseFactory
const char * = NULL);
static avtDatabase *VisitFile(const char *, int,
const char * = NULL);
static void SetDefaultFormat(const char *);
protected:
static avtDatabase *SetupDatabase(CommonDatabasePluginInfo *,
const char * const *, int,
int, int, int);
static char *defaultFormat;
};
......
......@@ -35,6 +35,10 @@ static int FormatLine(char *line);
// Hank Childs, Mon Sep 15 09:21:29 PDT 2003
// Initialized nodalCentering.
//
// Hank Childs, Sun May 9 07:56:42 PDT 2004
// Allow for the format not to be broken up into bricklets. Also add
// support for byte data.
//
// ****************************************************************************
avtBOVFileFormat::avtBOVFileFormat(const char *fname)
......@@ -80,7 +84,7 @@ avtBOVFileFormat::avtBOVFileFormat(const char *fname)
varname = new char[strlen("var") + 1];
strcpy(varname, "var");
min = 0.;
max = 0.;
max = 1.;
origin[0] = 0.;
origin[1] = 0.;
origin[2] = 0.;
......@@ -89,9 +93,11 @@ avtBOVFileFormat::avtBOVFileFormat(const char *fname)
dimensions[2] = 1.;
var_brick_min = NULL;
var_brick_max = NULL;
declaredEndianess = false;
littleEndian = false;
hasBoundaries = false;
nodalCentering = true;
byteData = true;
ReadTOC();
......@@ -107,8 +113,9 @@ avtBOVFileFormat::avtBOVFileFormat(const char *fname)
}
if (bricklet_size[0] <= 0 || bricklet_size[1] <= 0 || bricklet_size[2] <= 0)
{
debug1 << "Was not able to determine \"DATA_BRICKLETS\"" << endl;
EXCEPTION1(InvalidFilesException, fname);
bricklet_size[0] = full_size[0];
bricklet_size[1] = full_size[1];
bricklet_size[2] = full_size[2];
}
if (dimensions[0] <= 0. || dimensions[1] <= 0. || dimensions[2] <= 0.)
{
......@@ -311,6 +318,14 @@ avtBOVFileFormat::GetMesh(int dom, const char *meshname)
// Programmer: Hank Childs
// Creation: May 12, 2003
//
// Modifications:
//
// Hank Childs, Sun May 9 07:56:42 PDT 2004
// Better support for non-bricklet format. Also better support for fully
// qualified pathnames. Also add support for bytes vs floats. Also
// add support for gzipped vs non-gzipped. Also do a better job of closing
// file descriptors and freeing memory.
//
// ****************************************************************************
// FROM FConvert.C
......@@ -354,10 +369,28 @@ avtBOVFileFormat::GetVar(int dom, const char *var)
char filename[1024];
sprintf(filename, file_pattern, dom);
char qual_filename[1024];
sprintf(qual_filename, "%s%s", path, filename);
if (filename[0] != '/')
sprintf(qual_filename, "%s%s", path, filename);
else
strcpy(qual_filename, filename);
void *f_handle = gzopen(qual_filename, "r");
if (f_handle == NULL)
void *gz_handle = NULL;
FILE *file_handle = NULL;
bool gzipped = false;
if (strstr(qual_filename, ".gz") != NULL)
{
gz_handle = gzopen(qual_filename, "r");
gzipped = true;
}
else
{
file_handle = fopen(qual_filename, "r");
gzipped = false;
}
int unit_size = (byteData == true ? sizeof(unsigned char) : sizeof(float));
if (file_handle == NULL && gz_handle == NULL)
{
EXCEPTION1(InvalidFilesException, qual_filename);
}
......@@ -379,38 +412,113 @@ avtBOVFileFormat::GetVar(int dom, const char *var)
rv->SetNumberOfTuples(n_real_vals);
float *buff = (float *) rv->GetVoidPointer(0);
//
// How much we should allocate depends on whether we have floats or
// unsigned chars.
//
int total_vals = (dx*dy*dz);
float *buff2 = new float[total_vals];
gzread(f_handle, buff2, total_vals*sizeof(float));
unsigned char *uc_buff = NULL;
float *f_buff = NULL;
if (byteData)
uc_buff = new unsigned char[total_vals];
else
f_buff = new float[total_vals];
void *buff2 = (byteData ? (void *) uc_buff : (void *) f_buff);
//
// Read in based on whether or not we have a gzipped file.
//
if (gzipped)
gzread(gz_handle, buff2, total_vals*unit_size);
else
fread(buff2, unit_size, total_vals, file_handle);
int ptId = 0;
for (int i = z_start ; i < z_stop ; i++)
for (int j = y_start ; j < y_stop ; j++)
for (int k = x_start ; k < x_stop ; k++)
{
int index = i*dx*dy + j*dx + k;
buff[ptId++] = buff2[index];
if (byteData)
buff[ptId++] = min + (max-min)*(uc_buff[index]/255.);
else
buff[ptId++] = f_buff[index];
}
if (uc_buff != NULL)
delete [] uc_buff;
if (f_buff != NULL)
delete [] f_buff;
}
else
{
int nvals = bricklet_size[0] * bricklet_size[1] * bricklet_size[2];
rv->SetNumberOfTuples(nvals);
float *buff = (float *) rv->GetVoidPointer(0);
gzread(f_handle, buff, nvals*sizeof(float));
//
// If we have unsigned chars, then we have to create temporary buffer to
// read into. If we have floats, we can just use the buffer directly.
//
unsigned char *uc_buff = NULL;
float *f_buff = NULL;
if (byteData)
uc_buff = new unsigned char[nvals];
else
f_buff = (float *) rv->GetVoidPointer(0);
void *buff = (byteData ? (void *) uc_buff : (void *) f_buff);
//
// Read in based on whether or not we have a gzipped file.
//
if (gzipped)
gzread(gz_handle, buff, nvals*unit_size);
else
fread(buff, unit_size, nvals, file_handle);
if (byteData)
{
float *tmp = (float *) rv->GetVoidPointer(0);
for (int i = 0 ; i < nvals ; i++)
tmp[i] = min + (max-min)*(uc_buff[i]/255.);
delete [] uc_buff;
}
}
if (littleEndian)
//
// If the endian is opposite of this platform, then reverse it...
//
if (declaredEndianess)
{
int nvals = rv->GetNumberOfTuples();
float *buff = (float *) rv->GetVoidPointer(0);
for (int i = 0 ; i < nvals ; i++)
bool machineEndianIsLittle = true;
#ifdef WORDS_BIGENDIAN
machineEndianIsLittle = false;
#else
machineEndianIsLittle = true;
#endif
if (littleEndian != machineEndianIsLittle)
{
float tmp;
float32_Reverse_Endian(buff[i], (unsigned char *) &tmp);
buff[i] = tmp;
if (!byteData)
{
int nvals = rv->GetNumberOfTuples();
float *buff = (float *) rv->GetVoidPointer(0);
for (int i = 0 ; i < nvals ; i++)
{
float tmp;
float32_Reverse_Endian(buff[i], (unsigned char *) &tmp);
buff[i] = tmp;
}
}
}
}
//
// Close the file descriptors.
//
if (gzipped)
gzclose(gz_handle);
else
fclose(file_handle);
return rv;
}
......@@ -424,6 +532,11 @@ avtBOVFileFormat::GetVar(int dom, const char *var)
// Programmer: Hank Childs
// Creation: May 12, 2003
//
// Modifications:
//
// Hank Childs, Sun May 9 08:43:33 PDT 2004
// Do not assume that we have valid data extents.
//
// ****************************************************************************
void *
......@@ -444,16 +557,19 @@ avtBOVFileFormat::GetAuxiliaryData(const char *var, int domain,
{
EXCEPTION1(InvalidVariableException, var);
}
avtIntervalTree *itree = new avtIntervalTree(nbricks, 1);
for (int i = 0 ; i < nbricks ; i++)
if (var_brick_min != NULL && var_brick_max != NULL)
{
float range[2] = { var_brick_min[i], var_brick_max[i] };
itree->AddDomain(i, range);
}
itree->Calculate(true);
avtIntervalTree *itree = new avtIntervalTree(nbricks, 1);
for (int i = 0 ; i < nbricks ; i++)
{
float range[2] = { var_brick_min[i], var_brick_max[i] };
itree->AddDomain(i, range);
}
itree->Calculate(true);
rv = (void *) itree;
df = avtIntervalTree::Destruct;
rv = (void *) itree;
df = avtIntervalTree::Destruct;
}
}
else if (strcmp(type, AUXILIARY_DATA_SPATIAL_EXTENTS) == 0)
{
......@@ -550,6 +666,10 @@ avtBOVFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md)
// Hank Childs, Mon Sep 15 11:12:32 PDT 2003
// Allow for centering to be specified.
//
// Hank Childs, Sun May 9 08:51:38 PDT 2004
// Add support for byte data. Also interpret palette min/max as variable
// min/max as well.
//
// ****************************************************************************
void
......@@ -597,6 +717,17 @@ avtBOVFileFormat::ReadTOC(void)
line += strlen(line)+1;
full_size[2] = atoi(line);
}
else if (strcmp(line, "DATA_FORMAT:") == 0)
{
line += strlen("DATA_FORMAT:") + 1;
if (strncmp(line, "FLOAT", strlen("FLOAT")) == 0)
byteData = false;
else if (strncmp(line, "BYTE", strlen("BYTE")) == 0)
byteData = true;
else
debug1 << "Unknown keyword for BOV byte data: "
<< line << endl;
}
else if (strcmp(line, "DATA_BRICKLETS:") == 0)
{
line += strlen("DATA_BRICKLETS:") + 1;
......@@ -628,6 +759,19 @@ avtBOVFileFormat::ReadTOC(void)
line += strlen("DATA_ENDIAN:") + 1;
if (strcmp(line, "LITTLE") == 0)
littleEndian = true;
else
littleEndian = false;
declaredEndianess = true;
}
else if (strcmp(line, "VARIABLE_PALETTE_MIN:") == 0)
{
line += strlen("VARIABLE_PALETTE_MIN:") + 1;
min = atof(line);
}
else if (strcmp(line, "VARIABLE_PALETTE_MAX:") == 0)
{
line += strlen("VARIABLE_PALETTE_MAX:") + 1;
max = atof(line);
}
else if (strcmp(line, "VARIABLE_MIN:") == 0)
{
......@@ -705,6 +849,11 @@ avtBOVFileFormat::ReadTOC(void)
// Programmer: Hank Childs
// Creation: May 12, 2003
//
// Modifications:
//
// Hank Childs, Sun May 9 07:56:42 PDT 2004
// Combine words before the first colon using underscores.
//
// ****************************************************************************
static int
......@@ -717,13 +866,15 @@ FormatLine(char *line)
bool inQuotes = false;
int buffOffset = 0;
int nchar = strlen(line);
bool hasColon = (strstr(line, ":") != NULL);
bool foundColon = false;
int i;
for (i = 0 ; i < nchar ; i++)
{
if (line[i] == '\"')
{
inQuotes = (inQuotes ? false : true);
}
if (line[i] == ':')
foundColon = true;
bool is_space = isspace(line[i]);
if (inQuotes)
......@@ -733,8 +884,13 @@ FormatLine(char *line)
{
if (is_space)
{
buff[buffOffset++] = '\0';
inWord = false;
if (hasColon && !foundColon)
buff[buffOffset++] = '_';
else
{
buff[buffOffset++] = '\0';
inWord = false;
}
}
else
{
......
......@@ -47,8 +47,10 @@ class avtBOVFileFormat : public avtSTMDFileFormat
int bricklet_size[3];
char *varname;
bool hasBoundaries;
bool declaredEndianess;
bool littleEndian;
bool nodalCentering;
bool byteData;
float min, max;
float origin[3];
float dimensions[3];
......
......@@ -5,6 +5,8 @@
#include <Init.h>
#include <InitVTKNoGraphics.h>
#include <avtDatabase.h>
#include <avtDatabaseFactory.h>
// Prototypes.
bool ProcessCommandLine(int argc, char *argv[]);
......@@ -136,6 +138,9 @@ main(int argc, char *argv[])
// I made it return a flag that tells whether we should connect back to
// the calling program.
//
// Hank Childs, Sun May 9 11:52:45 PDT 2004
// Added the default_format argument.
//
// ****************************************************************************
bool
......@@ -157,6 +162,14 @@ ProcessCommandLine(int argc, char *argv[])
{
runApp = false;
}
else if (strcmp(argv[i], "-default_format") == 0)
{
if ((i+1) < argc)
{
avtDatabaseFactory::SetDefaultFormat(argv[i+1]);
i++;
}
}
}
return runApp;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment