Beispiel #1
0
char *getCurrentList(ListItem *list) {
	char *ret;
	char buffer[READ_LENGTH+1];
	int fileHandle;
	char *cursor;
	int attempt, goodPass;
	const int MAX_ATTEMPTS = 3;
	
	buffer[READ_LENGTH] = '\0';
	if (list->currentFilePosition == -1) {
		list->currentFilePosition = 0;		
		for (attempt=0,goodPass=0;attempt < MAX_ATTEMPTS;attempt++) {
			fileHandle = openList(list,NULL);
			readBuffer(fileHandle,buffer,READ_LENGTH);
			if (goodString(buffer,1)) {
				goodPass = 1;
				break;
			}
			close(fileHandle);
			logException(30,0,0); // log failed attempt
		}
		if (!goodPass)
			logException(30,0,RESET);
		buffer[READ_LENGTH] = '\0'; //prevents readLine from searching for \n past buffer
		for (cursor = buffer;*cursor != 0x0a && *cursor != 0x0d && *cursor != 0x00;cursor++);
		*cursor = 0x00;
		close(fileHandle);
		strcpy(list->currentString,buffer);
	}
	ret = list->currentString;
	return ret;
}
static bool export_list(int _iH5File, int *_piVar, char* _pstName, int _iVarType)
{
    int iRet        = 0;
    bool bReturn    = false;
    int iItemNumber = 0;
    SciErr sciErr   = getListItemNumber(pvApiCtx, _piVar, &iItemNumber);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return false;
    }


    //create groupe name
    char* pstGroupName	= createGroupName(_pstName);

    char pstMsg[256];
    sprintf(pstMsg, "list (%d)", iItemNumber);
    print_type(pstMsg);

    iLevel++;
    //open list
    void *pvList = openList(_iH5File, pstGroupName, iItemNumber);
    for (int i = 0 ; i < iItemNumber ; i++)
    {
        int *piNewVar = NULL;
        getListItemAddress(pvApiCtx, _piVar, i + 1, &piNewVar);//1 indexed
        char* pstPathName   = createPathName(pstGroupName, i);

        if (piNewVar == NULL)
        {
            //undefined item
            bReturn = export_undefined(_iH5File, piNewVar, pstPathName);
        }
        else
        {
            bReturn = export_data(_iH5File, piNewVar, pstPathName);
        }

        iRet = addItemInList(_iH5File, pvList, i, pstPathName);
        FREE(pstPathName);
        if (bReturn == false || iRet)
        {
            return false;
        }
    }
    iLevel--;
    closeList(_iH5File, pvList, _pstName, iItemNumber, _iVarType);
    FREE(pstGroupName);
    //close list
    return true;
}
Beispiel #3
0
DbManager::DbManager()
    : QObject() {
    closingAll = false;
    nconn = 0;
    m_driverModel = new QStandardItemModel(this);
    m_model = new QStandardItemModel(this);

    lastUsedDbIndex = 0;

    setupConnections();
    setupModels();
    openList();
}
Beispiel #4
0
char *getPreviousList(ListItem *list) {
	char *ret;
	char buffer[READ_LENGTH+1];
	int fileHandle;
	char *line, *tempCursor;
	int attempt,goodPass;
	const int MAX_ATTEMPTS = 3;
	
	if (list->currentFilePosition == -1)
		ret = getCurrentList(list); 
	else {
		for (attempt=0,goodPass=0;attempt < MAX_ATTEMPTS && !goodPass;attempt++) {
			fileHandle = openList(list,NULL);
			lseek(fileHandle,list->currentFilePosition,SEEK_SET);
			buffer[READ_LENGTH] = '\0'; //prevents readLine from searching for \n past buffer
			getLine(-1,0); // resets DONE
			line = getLine(fileHandle,buffer);
			if (!line)
				line[0] = 0; //empty list
			else {
				do {
					line = getLine(fileHandle,buffer);
				} while (line && strspn(line," \x0a\x0d\x00"));
				if (!line) {
					// end of file -- move to start
					line = getLine(fileHandle,0); // to reset DONE and move to BOF
					list->currentFilePosition = 0;
					line = getLine(fileHandle,buffer);
					if (!line)
						logException(9,0,RESET); //todo: format problem with list
				}
				list->currentFilePosition += getFilePosition();
			}
			close(fileHandle);
			for (tempCursor = line;*tempCursor != 0x0a && *tempCursor != 0x0d && *tempCursor != 0x00;tempCursor++);
			*tempCursor = 0x00;
			strcpy(list->currentString,line);
			ret = list->currentString;
			if ((goodPass = goodString(ret,1)))
				break;
			else 
				logException(30,0,0);
		}
		if (!goodPass)
			logException(30,0,RESET);
	}
	return ret;
} 
Beispiel #5
0
int insertIntoList(ListItem *list, long posInsert, char * string) {
	//todo: create a version without a roundtrip between single/dbl-byte chars	
	int rHandle, wHandle, ret, i, bytesToWrite;
	char wFilepath[PATH_LENGTH],rFilepath[PATH_LENGTH];
	char buffer[READ_LENGTH+1];
	char tempLine[LIST_ITEM_LENGTH];
	int MAX_BYTES = 2 * READ_LENGTH;

	strcpy(rFilepath,LIST_PATH);
	strcpy(wFilepath,LIST_PATH);
	strcat(wFilepath,"temp.txt");  
	rHandle = openList(list,rFilepath+strlen(rFilepath));
	wHandle = tbOpen((LPSTR)wFilepath,O_CREAT|O_TRUNC|O_WRONLY);
	ret = -1;
	if (rHandle != -1 && wHandle != -1) {
		buffer[READ_LENGTH] = '\0';
		ret = strcspn(string,"\x0a\x0d");
		if (ret > 0) 
			*(string + ret) = '\0';
		if (posInsert) {
			bytesToWrite = read(rHandle,(unsigned long)buffer << 1,posInsert % MAX_BYTES);
			ret = write(wHandle,(unsigned long)buffer << 1,bytesToWrite);
			for (i=bytesToWrite; i < posInsert; i+= MAX_BYTES) {
				bytesToWrite = read(rHandle,(unsigned long)buffer << 1,MAX_BYTES);
				ret = write(wHandle,(unsigned long)buffer << 1,bytesToWrite);
			}
		}
		bytesToWrite = convertDoubleToSingleChar(tempLine,string,TRUE);
		ret = write(wHandle,(unsigned long)tempLine<<1,bytesToWrite);		
		do {
			bytesToWrite = read(rHandle,(unsigned long)buffer << 1,MAX_BYTES);
			ret = write(wHandle,(unsigned long)buffer << 1,bytesToWrite);
		} while (bytesToWrite == MAX_BYTES);
		close(wHandle);
		close(rHandle);
		i = unlink((LPSTR)rFilepath);
		if (i != -1) {
			//todo: change this to rename instead of copy and unlink
			i = _copy((LPSTR)wFilepath,(LPSTR)rFilepath);
			if (i != -1)
				i = unlink((LPSTR)wFilepath);
		}
		ret = i;
	}
	return ret;
}
Beispiel #6
0
char *getCurrentList(ListItem *list) {
	char *ret;
	char buffer[READ_LENGTH+1];
	int fileHandle;
	char *cursor, *cp;
	int attempt, goodPass;
	ListItem *masterlist;
	const int MAX_ATTEMPTS = 3;
	
	buffer[READ_LENGTH] = '\0';
	if (list->currentFilePosition == -1) {
		list->currentFilePosition = 0;		
		for (attempt=0,goodPass=0;attempt < MAX_ATTEMPTS;attempt++) {
			fileHandle = openList(list,NULL);
			readBuffer(fileHandle,buffer,READ_LENGTH);
			if (goodString(buffer,1)) {
				goodPass = 1;
				break;
			}
			close(fileHandle);
			logException(30,0,0); // log failed attempt
		}
		if (!goodPass)
			logException(30,0,RESET);
		buffer[READ_LENGTH] = '\0'; //prevents readLine from searching for \n past buffer
		for (cursor = buffer;*cursor != 0x0a && *cursor != 0x0d && *cursor != 0x00;cursor++);
		*cursor = 0x00;
		close(fileHandle);
		
		//device-58
		masterlist = &pkgSystem.lists[context.package->idxMasterList];
		list->isLocked = 0;
		cp = buffer;
		if(list == masterlist) {
			if(*buffer == '!') { // catagory locked, no writing allowed
				list->isLocked = 1;
				cp++;
			}
		}
		//device-58
		strcpy(list->currentString,cp);		
	}
	ret = list->currentString;
	return ret;
}
Beispiel #7
0
void Search::doSearch(char* words) {
    struct timeval start, end;
    
    gettimeofday(&start, NULL);
    
	cout<<"do searching...."<<endl<<" key words:"<<words<<endl;
	//for(int i =0; i< key_words.size();i++)
	//	cout<<key_words[i]<<" ";
	result_count = 0;
	int request_count = 0;
	string word="";
	int pos=0;
    int N = (int)docMap.size();
	vector<string> request_list;
//	while(get_one_word(words,pos,word))
//	{
//		cout<<"new:"<<word<<endl;
//		request_list.push_back(word);
//		request_count++;
//		word="";
//        
//	}
    stringstream ss;
    ss << words;
    string temp;
    while (ss >> temp) {
        request_list.push_back(temp);
        request_count ++;
    }
	if(request_count == 0)
		return;
    
	vector<LP*> p;
    //	_result.print();
	for(int i = 0 ; i < request_list.size();i++)
	{
		int word_id=lexMap[request_list[i]];
		cout<<"word: "<<request_list[i]<<" word_id:"<<word_id<<endl;
		if(word_id == 0)
			continue;
		LP* tmp = openList(word_id);
		if(tmp == NULL)
			continue;
		p.push_back(tmp);
	}
	if(p.size() == 0)
		return;
	cout<<"p.size:"<<p.size()<<endl;
	cout<<"doc_map_size: "<<docMap.size()<<endl;
	int did = 0;
	while(did < N)
	{
		int d = 0;
	 	did = nextGEQ(p[0],did);
//	 	if( did == 0)
// 		{
// 			cout<<"did = 0"<<endl;
// 			continue;
// 		}
	 	for(int i = 1; (i< p.size())&& ((d=nextGEQ(p[i],did))==did);i++);
	 	if(did> N)
	 		break;
		if(d > did) did = d-1;
		else
		{
			float bm25_all = 0.0;
			STRU_DOC one_doc = docMap[did];
			//cout<<"doc_id:"<<did<<"url:"<<one_doc.doc_name<<" file: "<<one_doc.file_id<<" offset:"<<one_doc.offset<<" len:"<<one_doc.len<<endl;
			//int target_pos = getPos(p[0]);
			for( int k = 0 ; k<p.size(); k++)
			{
			 	int freq= getFreq(p[k]);
                
			 	int ft=p[k]->doc_num;
                
			 	if(one_doc.doc_name == "")
			 		continue;
			 	//cout<<"doc_id:"<<did<<"url:"<<one_doc.doc_name<<" file: "<<one_doc.file_id<<" offset:"<<one_doc.offset<<" len:"<<one_doc.len<<endl;
			 	//cout<<"req:"<<freq<<" ft:"<<ft<<endl;
			 	//comput bm25
			 	float K = (float)k1 * (float)((1-b) + b* ((float)one_doc.len / (float)d_agv ) );
			 	float bm25 = log ( (float)(N-ft+0.5)/(float)(ft+0.5) ) * ((k1 + 1)*(float)freq)/(float)(K + freq);
			 	//cout<<"bm25:"<<bm25<<endl;
			 	bm25_all+=bm25;
	 		}
		 	if(result_count < 10)
		 	{
                STRU_RESULT temp;
				temp._url =one_doc.doc_name;
				temp._bm25=bm25_all;
				temp._doc_id = did;
				//temp._pos = target_pos;
                result_array.push(temp);
		 		result_count++;
		 	}
		 	else if(bm25_all > result_array.top()._bm25)
		 	{
                STRU_RESULT temp;
				temp._url =one_doc.doc_name;
				temp._bm25=bm25_all;
				temp._doc_id = did;
				//temp._pos = target_pos;
                result_array.pop();
                result_array.push(temp);
                
		 	}
            
	 		//sort(result_array,0,result_count-1);
	 	}
	 	//cout<<"list:";
	 	//for(int j =0; j < result_count; j++)
	 	//	cout<<"["<<j<<"] "<<result_array[j]._bm25<<endl;
        
		did++;
	}
    gettimeofday(&end, NULL);
	_searching_time  = (end.tv_sec  - start.tv_sec)*1000+ (end.tv_usec - start.tv_usec)/1000.0;
    
}
Beispiel #8
0
char *getNextList(ListItem *list, BOOL shouldAdvance) {
	char *ret;
	char buffer[READ_LENGTH+1];
	int fileHandle;
	char *line, *tempCursor;
	int cursor;
	long position, bytesToRead;
	int attempt, goodPass;
	ListItem *masterlist;
	const int MAX_ATTEMPTS = 3;
	
	for (attempt=0,goodPass=0;attempt < MAX_ATTEMPTS && !goodPass;attempt++) {
		position = list->currentFilePosition;
		if (position == -1 || position == 0) {
			fileHandle = openList(list,NULL);			
			position = 0;
			// find last entry in file
			while (readBuffer(fileHandle,buffer,READ_LENGTH))
				position += READ_LENGTH;
			if (buffer[0]) { //check not empty list 
				//move before any empty last line, although this file should be machine-written
				for (line=strchr(buffer,0)-1;isspace(*line) && line > buffer;line--); 
				cursor = line - buffer;
			}
		}
		else if (shouldAdvance) {
			fileHandle = openList(list,NULL);			
			bytesToRead = 80;
			if (position < bytesToRead) {  //todo: move this to #define and make sure it is < READ_LENGTH
				bytesToRead = position;
				position = 0;
			}
			else {
				position -= bytesToRead;
				lseek(fileHandle,position,SEEK_SET);
			}
			readBuffer(fileHandle, buffer, bytesToRead);
			for (cursor = bytesToRead-1;buffer[cursor]==0x0a || buffer[cursor]==0x0d  || isspace(buffer[cursor]);cursor--);
			buffer[cursor+1] = '\0'; 
		}		
		if (buffer[0] && (shouldAdvance || (position == -1 || position == 0))) {
			for (;cursor > 0 && buffer[cursor-1] != 0x0a && buffer[cursor-1] != 0x0d; cursor--);		
			for (tempCursor = &buffer[cursor];*tempCursor != 0x0a && *tempCursor != 0x0d && *tempCursor != 0x00;tempCursor++);
			*tempCursor = 0x00;
			position += cursor;
			list->currentFilePosition = position;	
			
			//device-58
			masterlist = &pkgSystem.lists[context.package->idxMasterList];
			list->isLocked = 0;
			if(list == masterlist) {
				if(*(buffer+cursor) == '!') { // catagory locked, no writing allowed
					list->isLocked = 1;
					cursor++;
				}
			}
			//device-58

			strcpy(list->currentString,&buffer[cursor]);
			goodString(list->currentString,1);
			close(fileHandle);
		}
		if (!buffer[0]) 
			list->currentString[0] = 0;
		ret = list->currentString;
		if ((goodPass = goodString(ret,1)))
			break;
		else
			logException(30,0,0);
	}
	if (!goodPass)
		logException(30,0,RESET);

	return ret;
} 	
Beispiel #9
0
AViz::AViz() 
    : QMainWindow()
{
    // Make menus in menubar
    QMenu *file = menuBar()->addMenu("&File");
    QMenu *elements = menuBar()->addMenu( "&Elements");
    QMenu *view = menuBar()->addMenu( "&View");
    QMenu *settings = menuBar()->addMenu( "&Settings");
    QMenu *data = menuBar()->addMenu("&Data");
    menuBar()->addSeparator();
    QMenu *help = menuBar()->addMenu("&Help");

    // Make a cascade menu to read files
    QMenu *openfile = file->addMenu("&Open");
    openfile->addAction("Open XYZ File...", this, SLOT(openXYZ()));
    openfile->addAction("Open File List...", this, SLOT(openList()));
    openfile->addAction("Open ViewParam File...", this, SLOT(openViewParam()));



    file->addAction( "Save ViewParam File...", this, SLOT(saveViewParam()) );
    file->addSeparator();
    file->addAction( "File List...", this, SLOT(launchFileList()) );
    file->addAction( "Animation...", this, SLOT(launchAnimation()) );
    file->addSeparator();
    m_inOutWatchModelAction = file->addAction( "Watch XYZ File", this, SLOT(watchFile()) );
    file->addSeparator();
    file->addAction( "Snap PNG File...", this, SLOT(savePNGFile()) );
    file->addSeparator();
    file->addAction( "Set Default View Param", this, SLOT(setDefaultView()));
    file->addSeparator();
    file->addAction( "E&xit", qApp, SLOT(quit()), Qt::CTRL+Qt::Key_Q );

    // Make a general view menu
    QMenu *viewpoint = view->addMenu("Set &Viewpoint");
    view->addAction( "Clipping...", this, SLOT(launchClip()) );
    view->addAction( "Slicing...", this, SLOT(launchSlice()) );

    // Make a cascade menu to set standard view points
    viewpoint->addAction( "Explicit...", this, SLOT(launchExplicit()) );
    viewpoint->addSeparator();
    viewpoint->addAction( "Default View", this, SLOT(setDefaults()) );
    viewpoint->addSeparator();
    viewpoint->addAction( "View XY +", this, SLOT(viewXYPlus()) );
    viewpoint->addAction( "View XY -", this, SLOT(viewXYMinus()) );
    viewpoint->addSeparator();
    viewpoint->addAction( "View XZ +", this, SLOT(viewXZPlus()) );
    viewpoint->addAction( "View XZ -", this, SLOT(viewXZMinus()) );
    viewpoint->addSeparator();
    viewpoint->addAction( "View YZ +", this, SLOT(viewYZPlus()) );
    viewpoint->addAction( "View YZ -", this, SLOT(viewYZMinus()) );


    // Fill a general elements menu
    m_atomsMenu = elements->addMenu("Atoms...");

    // Make a submenu for atom specifications
    m_atomsMenu->addAction( "Atoms/Molecules...", this, SLOT(launchAtoms()) );
    m_atomsMenu->addAction( "Bonds...", this, SLOT(launchBonds()) );

    m_spinsAction = elements->addAction( "Spins...", this, SLOT(launchSpins()) );
    m_liquidCrystalsAction = elements->addAction( "Liquid Crystals...", this, SLOT(launchLiquidCrystals()) );
    m_polymersMenu = elements->addMenu( "Polymers...");
    m_poresAction = elements->addAction( "Pores ...", this, SLOT(launchPores()) );
    elements->addAction( "Lights...", this, SLOT(launchLights()) );
    elements->addAction( "Annotation...", this, SLOT(launchAnnotation()) );

    // fill submenu for polymer specifications
    m_polymersMenu->addAction( "Polymers...", this, SLOT(launchPolymers()) );
    m_polymersMenu->addAction( "Bonds...", this, SLOT(launchBonds()) );


    // fill a general settings menu
    m_showHideAxesAction = settings->addAction( "Hide Axes", this, SLOT(showHideAxesCB()) );
    m_showHideContourAction = settings->addAction( "Hide Contour", this, SLOT(showHideContourCB()) );
    m_onlyContourAction = settings->addAction( "Only Contour", this, SLOT(onlyContourCB()) );

    // fill a general data menu
    data->addAction( "&Translate...", this, SLOT(launchTranslation()) );
    data->addSeparator();
    data->addAction( "Swap XY", this, SLOT(swapXY()) );
    data->addAction( "Swap XZ", this, SLOT(swapXZ()) );
    data->addAction( "Swap YZ", this, SLOT(swapYZ()) );
    data->addSeparator();
    data->addAction( "Mirror X", this, SLOT(mirrorX()) );
    data->addAction( "Mirror Y", this, SLOT(mirrorY()) );
    data->addAction( "Mirror Z", this, SLOT(mirrorZ()) );
    data->addSeparator();
    data->addAction( "Stretch XYZ...", this, SLOT(launchStretch()) );

    // fill a general help menu
    help->addAction( "&About", this, SLOT(about()), Qt::CTRL+Qt::Key_H );
    help->addAction( "License", this, SLOT(license()) );
    help->addAction( "Distribution", this, SLOT(distribute()) );

    // Now construct the main form
    // (Note having aviz as paramter for MainForm ctor
    // is "This is an ugly hack, intended to propagate the
    // address of the calling class")
    m_mainForm = new MainForm(this/*parent*/, this /*aviz*/);
    setCentralWidget(m_mainForm);

    // Construct a timer
    m_watchTimer = new QTimer(this);

    // Set initial settings
    setAtomMenus();
}
Beispiel #10
0
path* 
FlexibleAStar::search(node* start, node* goal)
{
	nodesExpanded=0;
	nodesTouched=0;
	searchTime =0;
	nodesGenerated = 0;

	if(verbose) 
	{
		std::cout << "getPath() mapLevel: ";
		std::cout <<start->getLabelL(kAbstractionLevel)<<std::endl;
	}

	if(!checkParameters(start, goal))
		return NULL;

	start->setLabelF(kTemporaryLabel, heuristic->h(start, goal));
	start->backpointer = 0;
	
	altheap openList(heuristic, goal, 30);
	std::map<int, node*> closedList;
	
	openList.add(start);
	path *p = NULL;
	
	Timer t;
	t.startTimer();
	while(1) 
	{
		node* current = ((node*)openList.remove()); 

		// check if the current node is the goal (early termination)
		if(current == goal)
		{
			closeNode(current, &closedList);
			p = extractBestPath(current);
			if(verbose)
				debug->printNode(std::string("goal found! "), current);
			break;
		}
		
		// expand current node
		expand(current, goal, &openList, &closedList);
		closeNode(current, &closedList);
				
		// terminate when the open list is empty
		if(openList.empty())
		{
			if(verbose) std::cout << "search failed. ";
			break;
		}
	}
	searchTime = t.endTimer();
	closedList.clear();

	start->drawColor = 3;
	goal->drawColor = 3;

	if(verbose)
	{
		std::cout << "\n";
		debug->printPath(p); 
	}

	return p;	
}