/** * @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; }
//===============================================================// QList<QVector<QVariant> > cdfDataReader::getGlobalAttribute(int64_t Attribute) { 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 == GLOBAL_SCOPE) { for(int x=0; x < maxgEntry; x++) { status = CDFinquireAttrgEntry(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 = CDFgetAttrgEntry(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 = CDFgetAttrgEntry(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 = CDFgetAttrgEntry(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 = CDFgetAttrgEntry(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 = CDFgetAttrgEntry(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 = CDFgetAttrgEntry(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 = CDFgetAttrgEntry(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; }