/** * @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; }
//===============================================================// QList<QVector<QVariant > > cdfDataReader::getZVariableAttribute(const int64_t Attribute, const int64_t Variable) { CDFstatus status; QList<QVector<QVariant> > returnVal; long scope; long maxgEntry; long maxzEntry; long maxrEntry; char attName[CDF_ATTR_NAME_LEN256 + 1]; long numElements; long dataType; //verify scope status = CDFinquireAttr(this->fileId, Attribute, attName, &scope, &maxgEntry, &maxrEntry, &maxzEntry); if(this->CDFstatusOK(status)) { //ensure tha the scope is global if(scope == VARIABLE_SCOPE) { long x = Variable; status = CDFinquireAttrzEntry(this->fileId, Attribute, x, &dataType, &numElements); //if the attribute is valid, get the data if(this->CDFstatusOK(status)) { switch(dataType) { case CDF_FLOAT: { //Data is in Float Values float * dataF = new float[numElements]; QVector<QVariant> DataRecord; status = CDFgetAttrzEntry(this->fileId, Attribute, x, dataF); if(this->CDFstatusOK(status)) { for(int y = 0; y < numElements; y++) { //add to the Data Record DataRecord.push_back(QVariant(dataF[y])); } //add to the return values returnVal.push_back(DataRecord); } break; } case CDF_DOUBLE: { //Data is in Double Values double * data = new double[numElements]; QVector<QVariant> DataRecord; status = CDFgetAttrzEntry(this->fileId, Attribute, x, data); if(this->CDFstatusOK(status)) { for(int y = 0; y < numElements; y++) { //add to the Data Record DataRecord.push_back(QVariant(data[y])); } //add to the return values returnVal.push_back(DataRecord); } break; } case CDF_INT1: { int8_t *data = new int8_t[numElements]; QVector<QVariant> DataRecord; //Data is in byte form status = CDFgetAttrzEntry(this->fileId, Attribute, x, data); if(this->CDFstatusOK(status)) { for(int y = 0; y < numElements; y++) { //add to the Data Record DataRecord.push_back(QVariant(data[y])); } //add to the return values returnVal.push_back(DataRecord); } break; } case CDF_INT2: { int16_t *data = new int16_t[numElements]; QVector<QVariant> DataRecord; //Data is 16 bits status = CDFgetAttrzEntry(this->fileId, Attribute, x, data); if(this->CDFstatusOK(status)) { for(int y = 0; y < numElements; y++) { //add to the Data Record DataRecord.push_back(QVariant(data[y])); } //add to the return values returnVal.push_back(DataRecord); } break; } case CDF_INT4: { int32_t *data = new int32_t[numElements]; QVector<QVariant> DataRecord; //Data is 32 bits status = CDFgetAttrzEntry(this->fileId, Attribute, x, data); if(this->CDFstatusOK(status)) { for(int y = 0; y < numElements; y++) { //add to the Data Record DataRecord.push_back(QVariant(data[y])); } //add to the return values returnVal.push_back(DataRecord); } break; } case CDF_INT8: { int64_t *data = new int64_t[numElements]; QVector<QVariant> DataRecord; //Data is 64 bits status = CDFgetAttrzEntry(this->fileId, Attribute, x, data); if(this->CDFstatusOK(status)) { for(int y = 0; y < numElements; y++) { //add to the Data Record DataRecord.push_back(QVariant(data[y])); } //add to the return values returnVal.push_back(DataRecord); } break; } case CDF_CHAR: { //Data is a stirng char * data = new char[numElements + 1]; QVector<QVariant> DataRecord; status = CDFgetAttrzEntry(this->fileId, Attribute, x, data); if(this->CDFstatusOK(status)) { data[numElements] = '\0'; //add to record QString attr(data); DataRecord.push_back(attr); returnVal.push_back(DataRecord); } break; } default: break; } } } else { std::cerr << "No global attribute of this type" << std::endl; } } return returnVal; }