Ejemplo n.º 1
0
//===============================================================//
QStringList cdfDataReader::getAttributeList()
{
    long numAtts=0;
    char attName[CDF_ATTR_NAME_LEN256 +1];


    QStringList AttNameList;

    //get the number of attributes in the file
    CDFstatus status = CDFgetNumAttributes(this->fileId, &numAtts);

    if(this->CDFstatusOK(status))
    {
        for(long x = 0; x < numAtts; x++)
        {
            //inquire as to what the attribute is
            status = CDFgetAttrName(this->fileId, x, attName);
            if(this->CDFstatusOK(status))
            {
                //add the name to the list of attributes
                AttNameList.push_back(QString(attName));
            }
        }
    }

    //this list will be empty if an error occured
    return AttNameList;
}
Ejemplo n.º 2
0
	/**
	 * @param attribute_id
	 * @return String representing the name of the attribute specified by attribute_id
	 */
	std::string CDFFileReader::getVariableAttributeName(long attribute_id)
	{
		char buffer[256];
		CDFgetAttrName(current_file_id, attribute_id, buffer);
		std::string buffer_string = buffer;
		//cout << "Attribute Name: '" << buffer_string << "'" << endl;
		return buffer_string;
	}
Ejemplo n.º 3
0
	/**
	 * @param i The attribute number
	 * @return
	 */
	Attribute CDFFileReader::getGlobalAttribute(long i)
	{

		boost::unordered_map<long, Attribute>::iterator iter = gAttributeByID.find(i);
		if (iter != gAttributeByID.end())
			return (*iter).second;

		//cout << "after search" << endl;


		long attrNum = i;
		//cout << "i: " << i << " attrNum: " << attrNum << endl;
		long numElements;
		long dataType;

		//std::cout << "dataType: " << dataType << std::endl;


		CDFstatus status =  CDFgetAttrgEntryDataType (current_file_id, attrNum, 0, &dataType);
		status = CDFgetAttrgEntryNumElements (current_file_id, attrNum, 0, &numElements);

		Attribute attribute;
		if (dataType == CDF_CHAR)
		{
			std::string attributeValue = "NULL";
			char attributeBuffer[numElements+1];
			CDFgetAttrgEntry(current_file_id, attrNum, 0, attributeBuffer);
			//std::cout << "attrNum: " << attrNum << " i: " << i << " numElements: " << numElements << std::endl;
			//modelName[numElements] = '\0';
			attributeBuffer[numElements] = '\0';
			//std::cout << "status: " << status << std::endl;
			//if (status == CDF_OK)
			{
				attributeValue = attributeBuffer;
				attributeValue = attributeValue.substr(0, numElements); //only use valid parts of char string
			}

			char attributeNameBuffer[512];

			//char * ctemp = new char[512];
			//strcpy(ctemp, attributeValue.c_str());
			//void * vtemp = (void *)ctemp;
			CDFgetAttrName(current_file_id, attrNum, attributeNameBuffer);
			//std::cout << "attrNum: " << attrNum << " i: " << i << " numElements: " << numElements << std::endl;
			//Attribute attribute;
			attribute.setAttributeName(attributeNameBuffer);
			//std::cout << "attributeBuffer: " << attributeBuffer << endl;
			attribute.setAttributeValue(attributeValue);
			gAttributeByID[i] = attribute;
			gAttributes[attribute.getAttributeName()] = attribute;
			//return attribute;
		} else if (dataType == CDF_INT4)
		{
			//int attributeValue = 0.f;
			int attributeBuffer;// = new int[1];

			CDFgetAttrgEntry(current_file_id, attrNum, 0, (void*) &attributeBuffer);
			//std::cout << "attrNum: " << attrNum << " i: " << i << " numElements: " << numElements << std::endl;
			//std::cout << "numElements: " << numElements << std::endl;
			//modelName[numElements] = '\0';
			//std::cout << "status: " << status << std::endl;
			//if (status == CDF_OK)
			{
				//do nothing.  defaults to zero.
				//attributeValue = (int) attributeBuffer[0];
			}

			char attributeNameBuffer[512];

			CDFgetAttrName(current_file_id, attrNum, attributeNameBuffer);
			//Attribute attribute;
			attribute.setAttributeName(attributeNameBuffer);
			attribute.setAttributeValue(attributeBuffer);
			gAttributeByID[i] = attribute;
			gAttributes[attribute.getAttributeName()] = attribute;
			//return attribute;
		} else if (dataType == CDF_FLOAT)//CDF_FLOAT
		{
			//float attributeValue = 0.f;
			float attributeBuffer;// = new float[1];

			CDFgetAttrgEntry(current_file_id, attrNum, 0, &attributeBuffer);
			//std::cout << "numElements: " << numElements << std::endl;
			//modelName[numElements] = '\0';
			//std::cout << "status: " << status << std::endl;


			char attributeNameBuffer[1024];
			CDFgetAttrName(current_file_id, attrNum, attributeNameBuffer);
			//Attribute attribute;
			attribute.setAttributeName(attributeNameBuffer);
			attribute.setAttributeValue(attributeBuffer);
			gAttributeByID[i] = attribute;
			gAttributes[attribute.getAttributeName()] = attribute;
			//return attribute;
		}

		//cout << "added: " << i << " name: " << attribute.getAttributeName() << endl;
		//std::cout << "Attribute: " << attribute.toString() << std::endl;
		return attribute;

	}