示例#1
0
//===============================================================//
// this provides all entries and all elements in a given global attribute
QList<QVector<QVariant> > cdfDataReader::getGlobalAttribute(QString Attribute)
{
    QList<QVector<QVariant> > returnVal;

    returnVal = this->getGlobalAttribute(CDFgetAttrNum(this->fileId, Attribute.toAscii().data()));

    return returnVal;
}
示例#2
0
//===============================================================//
QList<QVector<QVariant > > cdfDataReader::getZVariableAttribute(const QString Attribute, const QString Variable)
{

    long attNum = CDFgetAttrNum(this->fileId, Attribute.toAscii().data());
    long varNum = CDFgetVarNum(this->fileId, Variable.toAscii().data());

    //convert the names to values, and call other version of the call
    return  this->getZVariableAttribute(attNum, varNum);
}
示例#3
0
//===============================================================//
QMap<QString, QList<QVector< QVariant > > > cdfDataReader::getZVaraibleAttributes(QStringList Attributes, int64_t Variable)
{
    QMap< QString, QList<QVector <QVariant > > > returnVal;
    QStringList::Iterator iter;
    long varN =  Variable;

    //for each Attribute in the list, get the attributes for the given variable
    for(iter = Attributes.begin(); iter != Attributes.end(); ++iter)
    {
        long attN =  CDFgetAttrNum(this->fileId, (*iter).toAscii().data());

        returnVal[*iter] = this->getZVariableAttribute(attN, varN);
    }

    return returnVal;
}
示例#4
0
int main (int argc, char * argv[])
{

    if (argc < 2)
    {
        std::cout << "Usage: cdfreader path\n";
        return 1;
    }
    ccmc::CDFFileReader fileReader;
    int status = fileReader.open(argv[1]);
    //std::vector<int> * intmat = fileReader.getVariableInt("intmat");
    //std::vector<float> * coord = fileReader.getVariable("coord");
    //std::vector<float> * x = fileReader.getVariable("x");
    //std::vector<float> * y = fileReader.getVariable("y");
    if (status != ccmc::CDFFileReader::OK)
    {
        std::cout << argv[1] << " was not a valid CDF file" << std::endl;
        exit(1);
    }

    fileReader.close();
    CDFid current_file_id;
    status = CDFopenCDF(argv[1], &current_file_id);
    CDFsetReadOnlyMode(current_file_id, READONLYoff);
    std::string r_body = "r_body";
    std::string new_value = "2.5";
    long attrNum = CDFgetAttrNum(current_file_id, (char *)r_body.c_str());
    CDFputAttrgEntry(current_file_id, attrNum, 0,  CDF_CHAR, new_value.length(), (char *)new_value.c_str());
    CDFcloseCDF(current_file_id);
//	boost::filesystem::path path = argv[1];
//
//
//
//	try {
//		if (boost::filesystem::exists(path)) // does p actually exist?
//		{
//			if (boost::filesystem::is_regular_file(path)) // is p a regular file?
//				std::cout << path << " size is " << boost::filesystem::file_size(path) << '\n';
//
//			else if (boost::filesystem::is_directory(path)) // is p a directory?
//			{
//				std::cout << path << " is a directory containing:\n";
//
//				typedef std::vector<boost::filesystem::path> vec; // store paths,
//				vec v; // so we can sort them later
//
//				std::copy(boost::filesystem::directory_iterator(path), boost::filesystem::directory_iterator(),
//						std::back_inserter(v));
//
//				std::sort(v.begin(), v.end()); // sort, since directory iteration
//				// is not ordered on some file systems
//
//				for (vec::const_iterator it(v.begin()), it_end(v.end());
//						it != it_end; ++it) {
//					std::cout << "   " << *it << '\n';
//				}
//			} else
//				std::cout << path
//				<< " exists, but is neither a regular file nor a directory\n";
//		} else
//			std::cout << path << " does not exist\n";
//	}
//
//	catch (const boost::filesystem::filesystem_error& ex) {
//		std::cout << ex.what() << '\n';
//	}
//




    return 0;
}
	/**
	 * @param variable
	 * @param vattribute
	 * @return
	 */
	Attribute CDFFileReader::getVariableAttribute(const std::string& variable, const std::string& vattribute)
	{


		//first, check the vAttributes map
		boost::unordered_map<std::string, boost::unordered_map< std::string, Attribute> >::iterator iter =
				vAttributes.find(variable);
		if (iter != vAttributes.end())
		{
			boost::unordered_map< std::string, Attribute>::iterator iter2 = vAttributes[variable].find(vattribute);
			if (iter2 != vAttributes[variable].end())
			{
				return (*iter2).second;
			}
		}
		long variableNumber = CDFgetVarNum(current_file_id, (char *) variable.c_str());
		long attributeNumber = CDFgetAttrNum(current_file_id, (char *) vattribute.c_str());
		long dataType;
		CDFstatus status = CDFgetAttrzEntryDataType(current_file_id, attributeNumber, variableNumber, &dataType);
		Attribute attribute;
		//	std::cout << "CDFFileReader::getVariableAttribute - datatype: " << dataType << " CDF_CHAR: " << CDF_CHAR << std::endl;
		if (dataType == CDF_CHAR)
		{
			char value[1024];
			long status = CDFgetAttrzEntry(current_file_id, attributeNumber, variableNumber, value);
			long numElements;
			status = CDFgetAttrzEntryNumElements(current_file_id, attributeNumber, variableNumber, &numElements);

			value[numElements] = '\0';
			//std::cout << "C: attributeValue (" << vattribute << "): " << value << std::endl;
			std::string valueString = value;

			attribute.setAttributeName(vattribute);
			attribute.setAttributeValue(valueString);


		} else if (dataType == CDF_INT4)
		{

			int value;
			long status = CDFgetAttrzEntry(current_file_id, attributeNumber, variableNumber, &value);
			//std::cout << "I: attributeValue (" << vattribute << "): " << value << std::endl;

			attribute.setAttributeName(vattribute);
			attribute.setAttributeValue(value);


		} else if (dataType == CDF_FLOAT) //CDF_FLOAT
		{
			float value;
			long status = CDFgetAttrzEntry(current_file_id, attributeNumber, variableNumber, &value);
			//std::cout << "F: attributeValue (" << vattribute << "): " << value << std::endl;

			attribute.setAttributeName(vattribute);
			attribute.setAttributeValue(value);

		}

		(vAttributes[variable])[vattribute] = attribute;
		return attribute;

	}
	/**
	 * @param attribute
	 * @return
	 */
	long CDFFileReader::getGlobalAttributeID(const std::string& attribute)
	{
		long attrNum = CDFgetAttrNum(current_file_id, (char *) attribute.c_str());
		return attrNum;
	}
示例#7
0
//===============================================================//
cdfDataSet cdfDataReader::getZVariableRecord(int64_t variable, int64_t record)
{
    //    std::cout << __FUNCTION__ << std::endl;

    CDFstatus status;
    cdfDataSet returnVal;
    QVector<QVariant> Qdata;

    cdfVarInfo VarInfo = this->getZVariableInformation(variable);

    QList<QVector<QVariant> > badData  = this->getZVariableAttribute(CDFgetAttrNum(this->fileId, (char*)"FILLVAL"), variable );

    void *data = NULL;
    long numValues = 1;


    // proceed only if the record number exists
    if(VarInfo.numRecords > record)
    {
        if(VarInfo.numDims > 0)
        {
            for(int s = 0; s < VarInfo.numDims; s++)
            {
                numValues *= VarInfo.dimSizes[s];
            }
        }

        cdfAllocateMemory(VarInfo.dataType, data, numValues);

        //get data record
        status = CDFgetzVarRecordData(this->fileId, variable, record, data);

        //process the data
        if(CDFstatusOK(status))
        {
            if(VarInfo.dataType == CDF_CHAR)
            {
                char* temp = (char*)data;
                temp[numValues] = '\0';
            }

            this->cToQVector(data, numValues, VarInfo.dataType, Qdata);

            //setup the returnvalues
            returnVal.setVector(Qdata);
            returnVal.setVarInfo(VarInfo);
            returnVal.setInvalidData(badData[0][0]);
            returnVal.setMajority(majority);
        }

        //deallocate the data
        //TODO: add remainder of cases for freeing memory
        if(data)
        {
                 if(VarInfo.dataType == CDF_FLOAT)       delete [] (float*)data;
            else if(VarInfo.dataType == CDF_DOUBLE)      delete [] (double*)data;
            else if(VarInfo.dataType == CDF_INT1)        delete [] (int8_t*)data;
            else if(VarInfo.dataType == CDF_UINT1)       delete [] (u_int8_t*)data;
            else if(VarInfo.dataType == CDF_BYTE)        delete [] (int8_t*)data;
            else if(VarInfo.dataType == CDF_INT2)        delete [] (int16_t*)data;
            else if(VarInfo.dataType == CDF_UINT2)       delete [] (u_int16_t*)data;
            else if(VarInfo.dataType == CDF_INT4)        delete [] (int32_t*)data;
            else if(VarInfo.dataType == CDF_UINT4)       delete [] (u_int32_t*)data;
            else if(VarInfo.dataType == CDF_INT8)        delete [] (int64_t*)data;
            else if(VarInfo.dataType == CDF_FLOAT)       delete [] (char*)data;
            else if(VarInfo.dataType == CDF_REAL4)       delete [] (float*)data;
            else if(VarInfo.dataType == CDF_REAL8)       delete [] (float*)data;
            else if(VarInfo.dataType == CDF_EPOCH)       delete [] (double*)data;
            else if(VarInfo.dataType == CDF_EPOCH16)     delete [] (double*)data;
        }
    }

    return returnVal;
}