예제 #1
0
파일: trxio.c 프로젝트: andersx/gmx-debug
static int pdb_first_x(t_trxstatus *status, FILE *fp, t_trxframe *fr)
{
  initcount(status);
  
  fprintf(stderr,"Reading frames from pdb file");
  frewind(fp);
  get_pdb_coordnum(fp, &fr->natoms);
  if (fr->natoms==0)
    gmx_fatal(FARGS,"\nNo coordinates in pdb file\n");
  frewind(fp);
  snew(fr->x,fr->natoms);
  pdb_next_x(status, fp, fr);

  return fr->natoms;
}
예제 #2
0
파일: gmxfio.c 프로젝트: yhalcyon/Gromacs
void gmx_fio_rewind(t_fileio* fio)
{
    gmx_fio_lock(fio);

    if (fio->xdr)
    {
        xdr_destroy(fio->xdr);
        frewind(fio->fp);
        xdrstdio_create(fio->xdr, fio->fp, fio->xdrmode);
    }
    else
    {
        frewind(fio->fp);
    }
    gmx_fio_unlock(fio);
}
예제 #3
0
파일: game.c 프로젝트: AlexLiuyuren/myos
int fs_test(){
	printg("game start\n");	
	int fp1=open("poem1.txt",0);
	printg("fp1=%d\n",fp1);
	char poem[10][30];
	int i;
	for(i=0;i<4;i++){
		read(fp1,(void*)poem[i],30);
		printg("%s\n",poem[i]);
	}
	close(fp1);
	int fp2=open("poem2.txt",0);
	printg("fp2\n");
	for(i=0;i<4;i++){
		 write(fp2,(void*)poem[i],30);
		 printg("%s\n",poem[i]);
	}
	memset(poem,0,sizeof(poem));
	frewind(fp2);
	for(i=0;i<4;i++){
		read(fp2,(void*)poem[i],30);
		printg("%s\n",poem[i]);
	}
	close(fp2);
	printg("game over nice job");
	while(1);
	return 0;
 }
예제 #4
0
파일: gmxfio.c 프로젝트: aar2163/GROMACS
void gmx_fio_rewind(int fio)
{
    gmx_fio_check(fio);
    if (FIO[fio].xdr) {
        xdrclose(FIO[fio].xdr);
        /* File is always opened as binary by xdropen */
        xdropen(FIO[fio].xdr,FIO[fio].fn,FIO[fio].bRead ? "r" : "w");
    }
    else
        frewind(FIO[fio].fp);
}
예제 #5
0
int gro_first_x_or_v(FILE *status,t_trxframe *fr)
{
  char title[STRLEN];
  
  frewind(status);
  fprintf(stderr,"Reading frames from gro file");
  get_coordnum_fp(status, title, &fr->natoms);
  frewind(status);
  fprintf(stderr," '%s', %d atoms.\n",title, fr->natoms);
  fr->bTitle = TRUE;
  fr->title = title;
  if (fr->natoms==0)
    gmx_file("No coordinates in gro file");
  
  snew(fr->x,fr->natoms);
  snew(fr->v,fr->natoms);
  gro_next_x_or_v(status, fr);
  
  return fr->natoms;
}
예제 #6
0
void MStdFile::rewind(void)
{
	if(m_file)
		frewind(m_file);
}
예제 #7
0
err_t
oafh_find_item_loc(
	file_hashmap_t 	*hash_map,
	ion_key_t		key,
	int				*location
)
{

	hash_t hash 				= hash_map->compute_hash(hash_map, key,
	        						hash_map->super.record.key_size);
													//compute hash value for given key

	int loc 					= oafh_get_location(hash, hash_map->map_size);
													//determine bucket based on hash

	int count 					= 0;

	hash_bucket_t *item;

	int record_size = hash_map->super.record.key_size + hash_map->super.record.value_size
			+ SIZEOF(STATUS);

	item = (hash_bucket_t *)malloc(record_size);

	//set file position
	fseek(hash_map->file, loc * record_size, SEEK_SET);

	//needs to traverse file again
	while (count != hash_map->map_size)
	{

		fread(item,record_size,1,hash_map->file);

		if (item->status == EMPTY)
		{
			free(item);
			return err_item_not_found;		//if you hit an empty cell, exit
		}
		else //calculate if there is a match
		{
			if (item->status != DELETED)
			{
				/** @todo correct compare to use proper return type*/
				int key_is_equal 	= hash_map->super.compare(item->data, key, hash_map->super.record.key_size);

				if (IS_EQUAL == key_is_equal)
				{
					(*location) = loc;
					free(item);
					return err_ok;
				}
			}
			loc++;
			count++;
			if (loc >= hash_map->map_size)	// Perform wrapping
			{
				loc = 0;
				frewind(hash_map->file);
			}
		}

	}
	free(item);
	return err_item_not_found; 				//key have not been found
}
예제 #8
0
err_t
oafh_insert(
	file_hashmap_t 		*hash_map,
	ion_key_t 		key,
	ion_value_t 	value
)
{




	hash_t hash 	= hash_map->compute_hash(hash_map, key,
							hash_map->super.record.key_size);			//compute hash value for given key



	int loc			= oafh_get_location(hash, hash_map->map_size);

	// Scan until find an empty location - oah_insert if found
	int count 		= 0;

	hash_bucket_t *item;

	int record_size = hash_map->super.record.key_size + hash_map->super.record.value_size
			+ SIZEOF(STATUS);

	item = (hash_bucket_t *)malloc(record_size);

	//set file position
	fseek(hash_map->file, loc * record_size, SEEK_SET);

	while (count != hash_map->map_size)
	{
		fread(item,record_size,1,hash_map->file);
#if DEBUG
		DUMP((int)ftell(hash_map->file),"%i");
#endif
		if (item->status == IN_USE) 	//if a cell is in use, need to key to
		{
			if (hash_map->super.compare(item->data, key, hash_map->super.record.key_size) == IS_EQUAL)
			{
				if (hash_map->write_concern == wc_insert_unique)//allow unique entries only
				{
					free(item);
					return err_duplicate_key;
				}
				else if (hash_map->write_concern == wc_update)//allows for values to be updated											//
				{
					//backup and write
					fseek(hash_map->file, SIZEOF(STATUS) + hash_map->super.record.key_size -record_size, SEEK_CUR);
#if DEBUG
					DUMP((int)ftell(hash_map->file),"%i");
					DUMP(value,"%s");
#endif
					fwrite(value, hash_map->super.record.value_size, 1, hash_map->file);
					free(item);
					return err_ok;
				}
				else
				{
					free(item);
					return err_write_concern;// there is a configuration issue with write concern
				}
			}

		}
		else if (item->status == EMPTY || item->status == DELETED)
		{
			//problem is here with base types as it is just an array of data.  Need better way
			//printf("empty\n");
			fseek(hash_map->file,-record_size,SEEK_CUR);
#if DEBUG
			DUMP((int)ftell(hash_map->file),"%i");
#endif
			item->status = IN_USE;
			memcpy(item->data, key, (hash_map->super.record.key_size));
			memcpy(item->data + hash_map->super.record.key_size, value,
			        (hash_map->super.record.value_size));
			fwrite(item, record_size, 1, hash_map->file);
			free(item);

			return err_ok;
		}

		loc++;
		if (loc >= hash_map->map_size)	// Perform wrapping
		{
			loc = 0;
			//rewind the file
			frewind(hash_map->file);
		}

#if DEBUG
		io_printf("checking location %i\n", loc);
#endif
		count++;
	}

#if DEBUG
	io_printf("Hash table full.  Insert not done");
#endif
	free(item);
	return err_max_capacity;
}