void wpa_supplicantClient_proxyIntrospectable_Start (wpa_supplicantClient_ProxyIntrospectable *proxy, GDBusConnection *connection) { ENTER(); if (!proxy) { NULL_POINTER("proxy"); EXIT_WITH_ERROR(); return; } if (!connection) { NULL_POINTER("connection"); EXIT_WITH_ERROR(); return; } if (proxy->m_xmlDescription) { WARN("XML Description is already there, no need to query for it again...No action is performed"); } else { query4XmlDescription(proxy, connection); } INFO("XML Description: %s", proxy->m_xmlDescription); EXIT(); return; }
void wpa_supplicantClient_bssManager_AddBss(wpa_supplicantClient_bssManager* mgr, char* pathName) { ENTER(); bssList *bssRec = (bssList *)&(mgr->m_bssGroup); while (bssRec->m_next) { bssRec = bssRec->m_next; } //Create a new Record; bssRec->m_next = (bssList *)malloc(sizeof(bssList)); if(!bssRec) { ALLOC_FAIL("bssRec"); EXIT_WITH_ERROR(); return; } bssRec = bssRec->m_next; memset(bssRec, 0, sizeof(bssList)); //Now initializing the BSS bssRec->m_bss = wpa_supplicantClient_bss_Init(mgr->m_busName, pathName, mgr->m_dbusConnection); if (!bssRec->m_bss) { ERROR("Failed to initialize the BSS Record .. exit"); EXIT_WITH_ERROR(); return; } //Now starting the BSS wpa_supplicantClient_bss_Start(bssRec->m_bss); EXIT(); return; }
int main( int argc, char **argv ) { struct thread_args *net = malloc(sizeof(struct thread_args)); pthread_cond_t *cv = NULL; pthread_mutex_t *mut = NULL; cv = malloc(sizeof(pthread_cond_t)); if( !cv ) return 1; pthread_cond_init(cv, NULL); net->core_cond = cv; mut = malloc(sizeof(pthread_mutex_t)); if( !mut ) return 1; pthread_mutex_init(mut, NULL); net->core_mut = mut; if( create_network_thread( net ) != 0 ) EXIT_WITH_ERROR("Failed to create network thread in main.\n"); for(;;) { /* wait for signal */ //pthread_mutex_lock(mut); pthread_cond_wait( cv, mut ); /* FIXME: memory leak. This means you, Bryan! */ pthread_t *proc_thread = malloc(sizeof(pthread_t)); if( !proc_thread ) return 1; if( pthread_create( proc_thread, NULL, process_work, net ) != 0 ) return 1; } return 0; }
//main function int main (int argc, char* argv[]) { ENTER(); PROGRESS("Create the wpa_supplicant mgr"); wpaHandle mgrHandle = wpa_supplicant_mgr_Init(); if (!mgrHandle){ ALLOC_FAIL("mgrHandle"); EXIT_WITH_ERROR(); return -1; } PROGRESS("Start the Manager Operation"); wpa_supplicant_mgr_Start(mgrHandle); //This function will not return until operation is complete //Perform needed Cleanup //The program enters here before it exits PROGRESS("Cleanup: Stop and Destroy the Mgr"); wpa_supplicant_mgr_Stop(mgrHandle); wpa_supplicant_mgr_Destroy (mgrHandle); EXIT(); return 0; }
void wpa_supplicantClient_bssManager_Stop (wpa_supplicantClient_bssManager *manager) { ENTER(); if (!manager){ NULL_POINTER("manager"); EXIT_WITH_ERROR(); return; } EXIT(); return; }
int main( int argc, char **argv ) { char c0 = 0, c1 = 0; FILE *hex_fp = NULL; FILE *obj_fp = NULL; if( argc != 3 ) EXIT_WITH_ERROR("Usage: hex_to_obj infile.hex outfile.obj\n"); hex_fp = fopen( argv[1], "r" ); obj_fp = fopen( argv[2], "w+"); if( !hex_fp || ! obj_fp ) EXIT_WITH_ERROR("Error: fopen failed in main.\n"); c0 = getc( hex_fp ); while( c0 != EOF ) { /* Skip white space and comments */ if( c0 == '#' ) { while( (c0 = getc( hex_fp )) != '\n' ); continue; } if( isspace(c0) ) { while( isspace( (c0 = getc( hex_fp )) )); continue; } c1 = getc( hex_fp ); fwrite( &bytes[ b_to_i(c0)*16+b_to_i(c1)], 1, 1, obj_fp ); c0 = getc( hex_fp ); } fclose( hex_fp ); fclose( obj_fp ); return 0; }
void wpa_supplicantClient_proxyIntrospectable_Destroy(wpa_supplicantClient_ProxyIntrospectable *proxy) { ENTER(); if (!proxy) { NULL_POINTER("proxy"); EXIT_WITH_ERROR(); } //finally free the object free(proxy); EXIT(); return; }
void wpa_supplicantClient_bssManager_Destroy (wpa_supplicantClient_bssManager *manager) { ENTER(); if (!manager){ NULL_POINTER("Passing NULL to the function ...Exiting"); EXIT_WITH_ERROR(); return; } //Free the manager free(manager); EXIT(); return; }
void wpa_supplicantClient_ifManager_AddIf(wpa_supplicantClient_ifManager* mgr, char* ifPathName) { ENTER(); interfaceList *ifRec = (interfaceList *)&(mgr->m_interfaceGroup); while (ifRec->m_next) { ifRec = ifRec->m_next; } //Create a new Record; ifRec->m_next = (interfaceList *)malloc(sizeof(interfaceList)); if(!ifRec) { ALLOC_FAIL("ifRec"); EXIT_WITH_ERROR(); return; } ifRec = ifRec->m_next; memset(ifRec, 0, sizeof(interfaceList)); //Now initializing the Interface ifRec->m_interface = wpa_supplicantClient_if_Init(mgr->m_busName, ifPathName, mgr->m_dbusConnection); if (!ifRec->m_interface) { ERROR("Failed to initialize the Interface Record .. exit"); EXIT_WITH_ERROR(); return; } //Now starting the interface wpa_supplicantClient_if_Start(ifRec->m_interface); EXIT(); return; }
void wpa_supplicantClient_ifManager_Destroy (wpa_supplicantClient_ifManager *manager) { ENTER(); if (!manager){ NULL_POINTER("manager"); EXIT_WITH_ERROR(); return; } //Finally free the object free(manager); EXIT(); return; }
void wpa_supplicantClient_ifManager_Start (wpa_supplicantClient_ifManager *manager, void *connection) { ENTER(); if (!manager){ NULL_POINTER("manager"); EXIT_WITH_ERROR(); return; } manager->m_dbusConnection = connection; EXIT(); return; }
wpa_supplicantClient_bssManager *wpa_supplicantClient_bssManager_Init (char *busName, void* connection) { ENTER(); wpa_supplicantClient_bssManager *manager = malloc(sizeof(wpa_supplicantClient_bssManager)); if (!manager) { ALLOC_FAIL("manager"); EXIT_WITH_ERROR(); return NULL; } memset(manager, 0, sizeof(wpa_supplicantClient_bssManager)); strcpy(manager->m_busName, busName); manager->m_dbusConnection = connection; EXIT(); return manager; }
wpa_supplicantClient_ProxyIntrospectable *wpa_supplicantClient_proxyIntrospectable_Init(char *busName, char *objectPath) { ENTER(); //First Create the object wpa_supplicantClient_ProxyIntrospectable *proxy = malloc(sizeof(wpa_supplicantClient_ProxyIntrospectable)); if (!proxy){ ALLOC_FAIL("Can not allocate a wpa_supplicantClient_ProxyIntrospectable Object ...Exiting"); EXIT_WITH_ERROR(); return NULL; } memset(proxy, 0, sizeof(wpa_supplicantClient_ProxyIntrospectable)); strcpy(proxy->m_busName, busName); strcpy(proxy->m_objectPath, objectPath); EXIT(); return proxy; }
void wpa_supplicantClient_ifManager_RemIf(wpa_supplicantClient_ifManager* mgr, char* ifPathName) { ENTER(); interfaceList *ifRec = mgr->m_interfaceGroup.m_next; interfaceList *prevRec = NULL; while (ifRec) { if (!strcmp (wpa_supplicantClient_if_GetIfPathName(ifRec->m_interface), ifPathName)) { //Found the Interface to delete break; } prevRec = ifRec; ifRec = ifRec->m_next; } if (!ifRec) { ERROR("Can not find the interface with PathName %s to delete", ifPathName); EXIT_WITH_ERROR(); return; } //First Stop the Interface wpa_supplicantClient_if_Stop(ifRec->m_interface); //Then Destroy the Interface wpa_supplicantClient_if_Destroy(ifRec->m_interface); //Then remove the ifRec from the list if (!prevRec) { //The removed interface is the first interface in the list mgr->m_interfaceGroup.m_next = ifRec->m_next; } else { prevRec->m_next = ifRec->m_next; } //Now we can delete the ifRec free(ifRec); EXIT(); return; }
void wpa_supplicantClient_proxyIntrospectable_Stop (wpa_supplicantClient_ProxyIntrospectable *proxy) { ENTER(); if (!proxy) { NULL_POINTER("proxy"); EXIT_WITH_ERROR(); return; } //Free the XML Description string if it is allocated g_free(proxy->m_xmlDescription); proxy->m_xmlDescription = NULL; //Free the dbus proxy Object g_object_unref(proxy->m_introspectionProxy); proxy->m_introspectionProxy = NULL; EXIT(); return; }
void wpa_supplicantClient_bssManager_RemBss(wpa_supplicantClient_bssManager* mgr, char* pathName) { ENTER(); bssList *bssRec = mgr->m_bssGroup.m_next; bssList *prevRec = NULL; while (bssRec) { if (!strcmp (wpa_supplicantClient_bss_GetPathName(bssRec->m_bss), pathName)) { //Found the bss to delete break; } prevRec = bssRec; bssRec = bssRec->m_next; } if (!bssRec) { ERROR("Can not find the BSS with PathName %s to delete", pathName); EXIT_WITH_ERROR(); return; } //First Stop the BSS wpa_supplicantClient_bss_Stop(bssRec->m_bss); //Then Destroy the BSS wpa_supplicantClient_bss_Destroy(bssRec->m_bss); //Then remove the bssRec from the list if (!prevRec) { //The removed BSS is the first BSS in the list mgr->m_bssGroup.m_next = bssRec->m_next; } else { prevRec->m_next = bssRec->m_next; } //Now we can delete the bssRec free(bssRec); EXIT(); return; }
int b_to_i( uint8_t c ) { switch( c ) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; case 'a': return 10; case 'b': return 11; case 'c': return 12; case 'd': return 13; case 'e': return 14; case 'f': return 15; default: /* Should never happen */ EXIT_WITH_ERROR("Error: bad byte in b_to_i: %d\n", c ); } }
Mesh::DataSets Crayfish::loadAsciiDataSet(const QString& fileName, const Mesh* mesh, LoadStatus* status) { QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) EXIT_WITH_ERROR(LoadStatus::Err_FileNotFound); // Couldn't open the file QTextStream stream(&file); QString firstLine = stream.readLine(); // http://www.xmswiki.com/xms/SMS:ASCII_Dataset_Files_*.dat // Apart from the format specified above, there is an older supported format used in BASEMENT (and SMS?) // which is simpler (has only one dataset in one file, no status flags etc) bool oldFormat; bool isVector = false; QScopedPointer<DataSet> ds; if (firstLine.trimmed() == "DATASET") oldFormat = false; else if (firstLine == "SCALAR" || firstLine == "VECTOR") { oldFormat = true; isVector = (firstLine == "VECTOR"); ds.reset(new DataSet(fileName)); ds->setIsTimeVarying(true); ds->setType(isVector ? DataSet::Vector : DataSet::Scalar); ds->setName(QFileInfo(fileName).baseName()); } else EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); // see if it contains element-centered results - supported by BASEMENT bool elementCentered = false; if (!oldFormat && QFileInfo(fileName).baseName().contains("_els_")) elementCentered = true; int nodeCount = mesh->nodes().count(); int elemCount = mesh->elements().count(); QVector<int> nodeIDToIndex = _mapIDToIndex(mesh->nodes()); QVector<int> elemIDToIndex = _mapIDToIndex(mesh->elements()); QRegExp reSpaces("\\s+"); Mesh::DataSets datasets; while (!stream.atEnd()) { QString line = stream.readLine(); QStringList items = line.split(reSpaces, QString::SkipEmptyParts); if (items.count() < 1) continue; // empty line?? let's skip it QString cardType = items[0]; if (cardType == "ND" && items.count() >= 2) { int fileNodeCount = items[1].toInt(); if (nodeIDToIndex.count() != fileNodeCount) EXIT_WITH_ERROR(LoadStatus::Err_IncompatibleMesh); } else if (!oldFormat && cardType == "NC" && items.count() >= 2) { int fileElemCount = items[1].toInt(); if (elemIDToIndex.count() != fileElemCount) EXIT_WITH_ERROR(LoadStatus::Err_IncompatibleMesh); } else if (!oldFormat && cardType == "OBJTYPE") { if (items[1] != "mesh2d" && items[1] != "\"mesh2d\"") EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); } else if (!oldFormat && (cardType == "BEGSCL" || cardType == "BEGVEC")) { if (ds) { qDebug("Crayfish: New dataset while previous one is still active!"); EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); } isVector = cardType == "BEGVEC"; ds.reset(new DataSet(fileName)); ds->setIsTimeVarying(true); ds->setType(isVector ? DataSet::Vector : DataSet::Scalar); } else if (!oldFormat && cardType == "ENDDS") { if (!ds) { qDebug("Crayfish: ENDDS card for no active dataset!"); EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); } ds->updateZRange(); datasets << ds.take(); } else if (!oldFormat && cardType == "NAME" && items.count() >= 2) { if (!ds) { qDebug("Crayfish: NAME card for no active dataset!"); EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); } int quoteIdx1 = line.indexOf('\"'); int quoteIdx2 = line.indexOf('\"', quoteIdx1+1); if (quoteIdx1 > 0 && quoteIdx2 > 0) ds->setName(line.mid(quoteIdx1+1, quoteIdx2-quoteIdx1-1)); } else if (oldFormat && (cardType == "SCALAR" || cardType == "VECTOR")) { // just ignore - we know the type from earlier... } else if (cardType == "TS" && items.count() >= (oldFormat ? 2 : 3)) { bool hasStatus = (oldFormat ? false : items[1].toInt()); float t = items[oldFormat ? 1 : 2].toFloat(); if (elementCentered) { ElementOutput* o = _readTimestampElementCentered(t, isVector, hasStatus, stream, elemCount); ds->addOutput(o); } else { NodeOutput* o = _readTimestep(t, isVector, hasStatus, stream, nodeCount, elemCount, nodeIDToIndex); ds->addOutput(o); } } else { qDebug("Crafish: Unknown card: %s", items.join(" ").toAscii().data()); } } if (oldFormat) { if (ds->outputCount() == 0) EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); ds->updateZRange(); datasets << ds.take(); } return datasets; }
/** * The DAT format contains "datasets" and each dataset has N-outputs. One output * represents data for all vertices/faces for one timestep * * In MDAL we convert one output to one MDAL dataset; * */ void MDAL::LoaderAsciiDat::load( MDAL::Mesh *mesh, MDAL_Status *status ) { if ( status ) *status = MDAL_Status::None; if ( !MDAL::fileExists( mDatFile ) ) { if ( status ) *status = MDAL_Status::Err_FileNotFound; return; } std::ifstream in( mDatFile, std::ifstream::in ); std::string line; if ( !std::getline( in, line ) ) { if ( status ) *status = MDAL_Status::Err_UnknownFormat; return; } line = trim( line ); // http://www.xmswiki.com/xms/SMS:ASCII_Dataset_Files_*.dat // Apart from the format specified above, there is an older supported format used in BASEMENT (and SMS?) // which is simpler (has only one dataset in one file, no status flags etc) bool oldFormat; bool isVector = false; std::shared_ptr<DatasetGroup> group; // DAT outputs data std::string name( MDAL::baseName( mDatFile ) ); if ( line == "DATASET" ) oldFormat = false; else if ( line == "SCALAR" || line == "VECTOR" ) { oldFormat = true; isVector = ( line == "VECTOR" ); group.reset( new DatasetGroup() ); group->uri = mDatFile; group->setName( name ); group->isScalar = !isVector; } else EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); // see if it contains face-centered results - supported by BASEMENT bool faceCentered = false; if ( !oldFormat && contains( name, "_els_" ) ) faceCentered = true; if ( group ) group->isOnVertices = !faceCentered; while ( std::getline( in, line ) ) { std::vector<std::string> items = split( line, " ", SplitBehaviour::SkipEmptyParts ); if ( items.size() < 1 ) continue; // empty line?? let's skip it std::string cardType = items[0]; if ( cardType == "ND" && items.size() >= 2 ) { size_t fileNodeCount = toSizeT( items[1] ); if ( mesh->vertexIDtoIndex.size() != fileNodeCount ) EXIT_WITH_ERROR( MDAL_Status::Err_IncompatibleMesh ); } else if ( !oldFormat && cardType == "NC" && items.size() >= 2 ) { size_t fileElemCount = toSizeT( items[1] ); if ( mesh->faceIDtoIndex.size() != fileElemCount ) EXIT_WITH_ERROR( MDAL_Status::Err_IncompatibleMesh ); } else if ( !oldFormat && cardType == "OBJTYPE" ) { if ( items[1] != "mesh2d" && items[1] != "\"mesh2d\"" ) EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); } else if ( !oldFormat && ( cardType == "BEGSCL" || cardType == "BEGVEC" ) ) { if ( group ) { debug( "New dataset while previous one is still active!" ); EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); } isVector = cardType == "BEGVEC"; group.reset( new DatasetGroup() ); group->uri = mDatFile; group->setName( name ); group->isScalar = !isVector; group->isOnVertices = !faceCentered; } else if ( !oldFormat && cardType == "ENDDS" ) { if ( !group ) { debug( "ENDDS card for no active dataset!" ); EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); } mesh->datasetGroups.push_back( group ); group.reset(); } else if ( !oldFormat && cardType == "NAME" && items.size() >= 2 ) { if ( !group ) { debug( "NAME card for no active dataset!" ); EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); } size_t quoteIdx1 = line.find( '\"' ); size_t quoteIdx2 = line.find( '\"', quoteIdx1 + 1 ); if ( quoteIdx1 != std::string::npos && quoteIdx2 != std::string::npos ) group->setName( line.substr( quoteIdx1 + 1, quoteIdx2 - quoteIdx1 - 1 ) ); } else if ( oldFormat && ( cardType == "SCALAR" || cardType == "VECTOR" ) ) { // just ignore - we know the type from earlier... } else if ( cardType == "TS" && items.size() >= ( oldFormat ? 2 : 3 ) ) { double t = toDouble( items[oldFormat ? 1 : 2] ); if ( faceCentered ) { readFaceTimestep( mesh, group, t, isVector, in ); } else { bool hasStatus = ( oldFormat ? false : toBool( items[1] ) ); readVertexTimestep( mesh, group, t, isVector, hasStatus, in ); } } else { std::stringstream str; str << " Unknown card:" << line; debug( str.str() ); } } if ( oldFormat ) { if ( !group || group->datasets.size() == 0 ) EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); mesh->datasetGroups.push_back( group ); group.reset(); } }
//Private Functions /////////////////// static void query4XmlDescription (wpa_supplicantClient_ProxyIntrospectable *proxy, GDBusConnection *connection) { ENTER(); GError * error = NULL; #if SYNC_API proxy->m_introspectionProxy = g_dbus_proxy_new_sync (connection, G_DBUS_PROXY_FLAGS_NONE, NULL, proxy->m_busName, proxy->m_objectPath, WPA_SUPPLICANT_INTROSPECTABLE_INTERFACE, NULL, &error); if (!proxy->m_introspectionProxy){ ERROR("Can not create the Introspection proxy"); ERROR("Error Message: %s", error->message); EXIT_WITH_ERROR(); return; } else { PROGRESS("Created the Introspection Proxy Interface successfully"); } GVariant *v = g_dbus_proxy_call_sync (proxy->m_introspectionProxy, "Introspect", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (!v){ ERROR("Failed to Introspect wpa_supplicant"); ERROR("Error Message: %s", error->message); //Free the proxy g_object_unref(proxy->m_introspectionProxy); proxy->m_introspectionProxy = NULL; EXIT_WITH_ERROR(); return; } else { PROGRESS("Performed the Introspection Successfully"); } #endif g_variant_get(v, "(s)", &proxy->m_xmlDescription); if (!proxy->m_xmlDescription) { ERROR("Failed to allocate the string for XML Description"); g_variant_unref(v); //Free the proxy g_object_unref(proxy->m_introspectionProxy); proxy->m_introspectionProxy = NULL; EXIT_WITH_ERROR(); return; } //Now we free the GVariant g_variant_unref(v); EXIT(); return; }
/** * The DAT format contains "datasets" and each dataset has N-outputs. One output * represents data for all vertices/faces for one timestep * * in TUFLOW results there could be also a special timestep (99999) with maximums * we will put it into a separate dataset with name suffixed with "/Maximums" * * In MDAL we convert one output to one MDAL dataset; * */ void MDAL::DriverBinaryDat::load( const std::string &datFile, MDAL::Mesh *mesh, MDAL_Status *status ) { mDatFile = datFile; if ( status ) *status = MDAL_Status::None; if ( !MDAL::fileExists( mDatFile ) ) { if ( status ) *status = MDAL_Status::Err_FileNotFound; return; } std::ifstream in( mDatFile, std::ifstream::in | std::ifstream::binary ); // implementation based on information from: // http://www.xmswiki.com/wiki/SMS:Binary_Dataset_Files_*.dat if ( !in ) EXIT_WITH_ERROR( MDAL_Status::Err_FileNotFound ); // Couldn't open the file size_t vertexCount = mesh->verticesCount(); size_t elemCount = mesh->facesCount(); int card = 0; int version; int objecttype; int sflt; int sflg = 0; int vectype; int objid; int numdata; int numcells; char name[40]; char istat; float time; if ( read( in, reinterpret_cast< char * >( &version ), 4 ) ) EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); if ( version != CT_VERSION ) // Version should be 3000 EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); std::shared_ptr<DatasetGroup> group = std::make_shared< DatasetGroup >( mesh, mDatFile ); // DAT datasets group->setIsOnVertices( true ); // in TUFLOW results there could be also a special timestep (99999) with maximums // we will put it into a separate dataset std::shared_ptr<DatasetGroup> groupMax = std::make_shared< DatasetGroup >( mesh, mDatFile ); groupMax->setIsOnVertices( true ); while ( card != CT_ENDDS ) { if ( read( in, reinterpret_cast< char * >( &card ), 4 ) ) { // We've reached the end of the file and there was no ends card break; } switch ( card ) { case CT_OBJTYPE: // Object type if ( read( in, reinterpret_cast< char * >( &objecttype ), 4 ) || objecttype != CT_2D_MESHES ) EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); break; case CT_SFLT: // Float size if ( read( in, reinterpret_cast< char * >( &sflt ), 4 ) || sflt != CT_FLOAT_SIZE ) EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); break; case CT_SFLG: // Flag size if ( read( in, reinterpret_cast< char * >( &sflg ), 4 ) ) if ( sflg != CF_FLAG_SIZE && sflg != CF_FLAG_INT_SIZE ) EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); break; case CT_BEGSCL: group->setIsScalar( true ); groupMax->setIsScalar( true ); break; case CT_BEGVEC: group->setIsScalar( false ); groupMax->setIsScalar( false ); break; case CT_VECTYPE: // Vector type if ( read( in, reinterpret_cast< char * >( &vectype ), 4 ) || vectype != 0 ) EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); break; case CT_OBJID: // Object id if ( read( in, reinterpret_cast< char * >( &objid ), 4 ) ) EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); break; case CT_NUMDATA: // Num data if ( read( in, reinterpret_cast< char * >( &numdata ), 4 ) ) EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); if ( numdata != static_cast< int >( vertexCount ) ) EXIT_WITH_ERROR( MDAL_Status::Err_IncompatibleMesh ); break; case CT_NUMCELLS: // Num data if ( read( in, reinterpret_cast< char * >( &numcells ), 4 ) ) EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); if ( numcells != static_cast< int >( elemCount ) ) EXIT_WITH_ERROR( MDAL_Status::Err_IncompatibleMesh ); break; case CT_NAME: // Name if ( read( in, reinterpret_cast< char * >( &name ), 40 ) ) EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); if ( name[39] != 0 ) name[39] = 0; group->setName( trim( std::string( name ) ) ); groupMax->setName( group->name() + "/Maximums" ); break; case CT_TS: // Time step! if ( readIStat( in, sflg, &istat ) ) EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); if ( read( in, reinterpret_cast< char * >( &time ), 4 ) ) EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); double t = static_cast<double>( time ); if ( readVertexTimestep( mesh, group, groupMax, t, istat, sflg, in ) ) EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); break; } } if ( !group || group->datasets.size() == 0 ) EXIT_WITH_ERROR( MDAL_Status::Err_UnknownFormat ); group->setStatistics( MDAL::calculateStatistics( group ) ); mesh->datasetGroups.push_back( group ); if ( groupMax && groupMax->datasets.size() > 0 ) { groupMax->setStatistics( MDAL::calculateStatistics( groupMax ) ); mesh->datasetGroups.push_back( groupMax ); } }
Mesh::DataSets Crayfish::loadBinaryDataSet(const QString& datFileName, const Mesh* mesh, LoadStatus* status) { // implementation based on information from: // http://www.xmswiki.com/wiki/SMS:Binary_Dataset_Files_*.dat QFile file(datFileName); if (!file.open(QIODevice::ReadOnly)) EXIT_WITH_ERROR(LoadStatus::Err_FileNotFound); // Couldn't open the file int nodeCount = mesh->nodes().count(); int elemCount = mesh->elements().count(); int card = 0; int version; int objecttype; int sflt; int sflg; int vectype; int objid; int numdata; int numcells; char name[40]; char istat; float time; QDataStream in(&file); if( in.readRawData( (char*)&version, 4) != 4 ) EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); if( version != CT_VERSION ) // Version should be 3000 EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); QScopedPointer<DataSet> ds(new DataSet(datFileName)); ds->setIsTimeVarying(true); // in TUFLOW results there could be also a special timestep (99999) with maximums // we will put it into a separate dataset QScopedPointer<DataSet> dsMax(new DataSet(datFileName)); dsMax->setIsTimeVarying(false); while (card != CT_ENDDS) { if( in.readRawData( (char*)&card, 4) != 4 ) { // We've reached the end of the file and there was no ends card break; } switch (card) { case CT_OBJTYPE: // Object type if( in.readRawData( (char*)&objecttype, 4) != 4 || objecttype != 3 ) EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); break; case CT_SFLT: // Float size if( in.readRawData( (char*)&sflt, 4) != 4 || sflt != 4 ) EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); break; case CT_SFLG: // Flag size if( in.readRawData( (char*)&sflg, 4) != 4 || sflg != 1 ) EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); break; case CT_BEGSCL: ds->setType(DataSet::Scalar); dsMax->setType(DataSet::Scalar); break; case CT_BEGVEC: ds->setType(DataSet::Vector); dsMax->setType(DataSet::Vector); break; case CT_VECTYPE: // Vector type if( in.readRawData( (char*)&vectype, 4) != 4 || vectype != 0 ) EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); break; case CT_OBJID: // Object id if( in.readRawData( (char*)&objid, 4) != 4 ) EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); break; case CT_NUMDATA: // Num data if ( in.readRawData( (char*)&numdata, 4) != 4 ) EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); if (numdata != nodeCount) EXIT_WITH_ERROR(LoadStatus::Err_IncompatibleMesh); break; case CT_NUMCELLS: // Num data if( in.readRawData( (char*)&numcells, 4) != 4 ) EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); if(numcells != elemCount) EXIT_WITH_ERROR(LoadStatus::Err_IncompatibleMesh); break; case CT_NAME: // Name if( in.readRawData( (char*)&name, 40) != 40 ) EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); if(name[39] != 0) name[39] = 0; ds->setName(QString(name).trimmed()); dsMax->setName(ds->name() + "/Maximums"); break; case CT_TS: // Time step! if( in.readRawData( (char*)&istat, 1) != 1 ) EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); if( in.readRawData( (char*)&time, 4) != 4 ) EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); QScopedPointer<NodeOutput> o(new NodeOutput); o->time = time; try { o->init(nodeCount, elemCount, ds->type() == DataSet::Vector); } catch (const std::bad_alloc &) { EXIT_WITH_ERROR(LoadStatus::Err_NotEnoughMemory); } if (istat) { // Read status flags char* active = o->active.data(); for (int i=0; i < elemCount; i++) { if( in.readRawData( active+i, 1) != 1 ) EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); } } float* values = o->values.data(); NodeOutput::float2D* valuesV = o->valuesV.data(); for (int i=0; i<nodeCount; i++) { // Read values flags if (ds->type() == DataSet::Vector) { NodeOutput::float2D v; if( in.readRawData( (char*)&v.x, 4) != 4 ) EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); if( in.readRawData( (char*)&v.y, 4) != 4 ) EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); valuesV[i] = v; values[i] = v.length(); // Determine the magnitude } else { if( in.readRawData( (char*)&values[i], 4) != 4 ) EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); } } if (o->time == 99999) dsMax->addOutput(o.take()); // special timestep (in TUFLOW) with maximums else ds->addOutput(o.take()); // ordinary timestep break; } } if (ds->outputCount() == 0) EXIT_WITH_ERROR(LoadStatus::Err_UnknownFormat); ds->updateZRange(); Mesh::DataSets datasets; datasets << ds.take(); if (dsMax->outputCount() != 0) { dsMax->updateZRange(); datasets << dsMax.take(); } return datasets; }