GLOBAL void swap_xz_free(transform_info_ptr newtinfo) { if (newtinfo!=NULL) { free_pointer((void **)&newtinfo->tsdata); free_pointer((void **)&newtinfo->xdata); free((void *)newtinfo); } }
/*{{{ recode_exit(transform_info_ptr tinfo) {*/ METHODDEF void recode_exit(transform_info_ptr tinfo) { struct recode_storage *local_arg=(struct recode_storage *)tinfo->methods->local_storage; free_pointer((void **)&local_arg->blockdefs); free_pointer((void **)&local_arg->channel_list); tinfo->methods->init_done=FALSE; }
/*{{{ rereference_exit(transform_info_ptr tinfo)*/ METHODDEF void rereference_exit(transform_info_ptr tinfo) { struct rereference_args_struct *rereference_args=(struct rereference_args_struct *)tinfo->methods->local_storage; free_pointer((void **)&rereference_args->refchannel_numbers); free_pointer((void **)&rereference_args->excludechannel_numbers); tinfo->methods->init_done=FALSE; }
/* * static int split_block * * DESCRIPTION: * * When freeing space in a multi-block chunk we have to create new * blocks out of the upper areas being freed. * * RETURNS: * * Success - MPOOL_ERROR_NONE * * Failure - Mpool error code * * ARGUMENTS: * * mp_p <-> Pointer to the memory pool. * * free_addr -> Address that we are freeing. * * size -> Size of the space that we are taking from address. */ static int split_block(mpool_t * mp_p, void *free_addr, const unsigned long size) { mpool_block_t *block_p, *new_block_p; int ret, page_n; void *end_p; /* * 1st we find the block pointer from our free addr. At this point * the pointer must be the 1st one in the block if it is spans * multiple blocks. */ block_p = (mpool_block_t *) ((char *)free_addr - sizeof(mpool_block_t)); if (block_p->mb_magic != BLOCK_MAGIC || block_p->mb_magic2 != BLOCK_MAGIC) { return MPOOL_ERROR_POOL_OVER; } page_n = PAGES_IN_SIZE(mp_p, size); /* we are creating a new block structure for the 2nd ... */ new_block_p = (mpool_block_t *) ((char *)block_p + SIZE_OF_PAGES(mp_p, page_n)); new_block_p->mb_magic = BLOCK_MAGIC; /* New bounds is 1st block bounds. The 1st block's is reset below. */ new_block_p->mb_bounds_p = block_p->mb_bounds_p; /* Continue the linked list. The 1st block will point to us below. */ new_block_p->mb_next_p = block_p->mb_next_p; new_block_p->mb_magic2 = BLOCK_MAGIC; /* bounds for the 1st block are reset to the 1st page only */ block_p->mb_bounds_p = (char *)new_block_p; /* the next block pointer for the 1st block is now the new one */ block_p->mb_next_p = new_block_p; /* only free the space in the 1st block if it is only 1 block in size */ if (page_n == 1) { /* now free the rest of the 1st block block */ end_p = (char *)free_addr + size; ret = free_pointer(mp_p, end_p, (char *)block_p->mb_bounds_p - (char *)end_p); if (ret != MPOOL_ERROR_NONE) { return ret; } } /* now free the rest of the block */ ret = free_pointer(mp_p, FIRST_ADDR_IN_BLOCK(new_block_p), MEMORY_IN_BLOCK(new_block_p)); if (ret != MPOOL_ERROR_NONE) { return ret; } return MPOOL_ERROR_NONE; }
/*{{{ project_exit(transform_info_ptr tinfo)*/ METHODDEF void project_exit(transform_info_ptr tinfo) { struct project_args_struct *project_args=(struct project_args_struct *)tinfo->methods->local_storage; array_free(&project_args->vectors); if (project_args->project_mode==PROJECT_MODE_MULTIPLY) { if (project_args->save_side_tinfo.channelnames!=NULL) { free_pointer((void **)&project_args->save_side_tinfo.channelnames[0]); free_pointer((void **)&project_args->save_side_tinfo.channelnames); } free_pointer((void **)&project_args->save_side_tinfo.probepos); } free_pointer((void **)&project_args->channel_list); tinfo->methods->init_done=FALSE; }
/* This function has all the knowledge about events in the various file types */ LOCAL void read_neurofile_build_trigbuffer(transform_info_ptr tinfo) { struct read_neurofile_storage *local_arg=(struct read_neurofile_storage *)tinfo->methods->local_storage; transform_argument *args=tinfo->methods->arguments; if (local_arg->triggers.buffer_start==NULL) { growing_buf_allocate(&local_arg->triggers, 0); } else { growing_buf_clear(&local_arg->triggers); } if (args[ARGS_TRIGFILE].is_set) { FILE * const triggerfile=(strcmp(args[ARGS_TRIGFILE].arg.s,"stdin")==0 ? stdin : fopen(args[ARGS_TRIGFILE].arg.s, "r")); TRACEMS(tinfo->emethods, 1, "read_neurofile_build_trigbuffer: Reading event file\n"); if (triggerfile==NULL) { ERREXIT1(tinfo->emethods, "read_neurofile_build_trigbuffer: Can't open trigger file >%s<\n", MSGPARM(args[ARGS_TRIGFILE].arg.s)); } while (TRUE) { long trigpoint; char *description; int const code=read_trigger_from_trigfile(triggerfile, tinfo->sfreq, &trigpoint, &description); if (code==0) break; push_trigger(&local_arg->triggers, trigpoint, code, description); free_pointer((void **)&description); } if (triggerfile!=stdin) fclose(triggerfile); } else { TRACEMS(tinfo->emethods, 0, "read_neurofile_build_trigbuffer: No trigger source known.\n"); } }
/** * Frees the whole memory associated to the given list. We free the pointers * using the given 'free_pointer' function, if not NULL. */ void free_list_pointer(struct list_pointer* list,void (*free_pointer)(void*),Abstract_allocator prv_alloc) { struct list_pointer* tmp; while (list!=NULL) { tmp=list; list=list->next; if (free_pointer!=NULL) free_pointer(tmp->pointer); free_cb(tmp,prv_alloc); } }
static void clean_up_inner_problem(struct Struct_FGM *s) { free_pointer(s->c); free_pointer(s->z0); free_pointer(s->zopt); free_pointer(s->z); free_pointer(s->y); free_pointer(s->znew); free_pointer(s->ynew); free_pointer(s->temp1_dim_N); }
/*! ***************************************************************************** * \brief * Read the TIFF file named 'path' into 't'. * ***************************************************************************** */ static int readTiff (Tiff * t, char * path) { assert( t); assert( path); if (readFileIntoMemory( t, path)) goto Error; if (readImageFileHeader( t)) goto Error; if (readImageFileDirectory( t)) goto Error; if (readImageData( t)) goto Error; return 0; Error: free_pointer( t->fileInMemory); free_pointer( t->img); return 1; }
/*{{{ read_freiburg_exit(transform_info_ptr tinfo) {*/ METHODDEF void read_freiburg_exit(transform_info_ptr tinfo) { struct read_freiburg_storage *local_arg=(struct read_freiburg_storage *)tinfo->methods->local_storage; transform_argument *args=tinfo->methods->arguments; if (args[ARGS_CONTINUOUS].is_set) { fclose(local_arg->infile); } freiburg_get_segment_free(tinfo); if (local_arg->channelnames!=NULL) { free_pointer((void **)&local_arg->channelnames[0]); free_pointer((void **)&local_arg->channelnames); } free_pointer((void **)&local_arg->uV_per_bit); growing_buf_free(&local_arg->segment_table); tinfo->methods->init_done=FALSE; }
/*{{{ write_rec_exit(transform_info_ptr tinfo) {*/ METHODDEF void write_rec_exit(transform_info_ptr tinfo) { struct write_rec_storage *local_arg=(struct write_rec_storage *)tinfo->methods->local_storage; transform_argument *args=tinfo->methods->arguments; if (args[ARGS_CLOSE].is_set==FALSE) write_rec_close_file(tinfo); free_pointer((void **)&local_arg->outbuf); local_arg->outfptr=NULL; tinfo->methods->init_done=FALSE; }
void query_params_clean(QUERY_PARAMS *params) { if(params != NULL) { /* Free the sensors from the params */ if(params->sensors != NULL) { int i; /* Free all individual sensors in the double pointer. */ for(i = 0; params->sensors[i] != NULL; i++) free_pointer(params->sensors[i]); /* Free the double pointer */ free(params->sensors); params->sensors = NULL; } /* Free all resources associated to the structure */ free_pointer(params->fromTime); free_pointer(params->toTime); free_pointer(params); } }
/* * static int free_mem * * DESCRIPTION: * * Free an address from a memory pool. * * RETURNS: * * Success - MPOOL_ERROR_NONE * * Failure - Mpool error code * * ARGUMENTS: * * mp_p <-> Pointer to the memory pool. If NULL then it will do a * normal free. * * addr <-> Address to free. * * size -> Size of the address being freed. */ static int free_mem(mpool_t *mp_p, void *addr, const unsigned long size) { unsigned long old_size, fence; int ret; mpool_block_t *block_p; /* * If the size is larger than a block then the allocation must be at * the front of the block. */ if (size > MAX_BLOCK_USER_MEMORY(mp_p)) { block_p = (mpool_block_t *)((char *)addr - sizeof(mpool_block_t)); if (block_p->mb_magic != BLOCK_MAGIC || block_p->mb_magic2 != BLOCK_MAGIC) { return MPOOL_ERROR_POOL_OVER; } } /* make sure we have enough bytes */ if (size < MIN_ALLOCATION) { old_size = MIN_ALLOCATION; } else { old_size = size; } /* if we are packing the pool smaller */ if (BIT_IS_SET(mp_p->mp_flags, MPOOL_FLAG_NO_FREE)) { fence = 0; } else { /* find the user's magic numbers if they were written */ ret = check_magic(addr, old_size); if (ret != MPOOL_ERROR_NONE) { return ret; } fence = FENCE_SIZE; } /* now we free the pointer */ ret = free_pointer(mp_p, addr, old_size + fence); if (ret != MPOOL_ERROR_NONE) { return ret; } mp_p->mp_user_alloc -= old_size; /* adjust our stats */ mp_p->mp_alloc_c--; return MPOOL_ERROR_NONE; }
static void downpour_release(DownpourWrapper *wrapper) { if(wrapper == NULL) return; wrapper->reference_count--; if(wrapper->reference_count == 0) { free_extra_pointer(wrapper); free_pointer(wrapper); downpour_release(wrapper->parent); free(wrapper); } }
/*{{{ append(transform_info_ptr tinfo)*/ METHODDEF DATATYPE * append(transform_info_ptr tinfo) { struct append_local_struct *localp=(struct append_local_struct *)tinfo->methods->local_storage; /* For the very first incoming epoch set, in either case the epochs must just be stored: */ if (localp->type==ADD_LINKEPOCHS || localp->tinfop==NULL) { transform_info_ptr tinfoptr; /* Go to the start: */ for (tinfoptr=tinfo; tinfoptr->previous!=NULL; tinfoptr=tinfoptr->previous); for (; tinfoptr!=NULL; tinfoptr=tinfoptr->next) { if (localp->tinfop==NULL) { deepcopy_tinfo(&localp->tinfo, tinfoptr); localp->tinfop= &localp->tinfo; localp->tinfop->previous=localp->tinfop->next=NULL; } else { transform_info_ptr tinfo_next=(transform_info_ptr)malloc(sizeof(struct transform_info_struct)); if (tinfo_next==NULL) { ERREXIT(tinfo->emethods, "append: Error malloc'ing tinfo struct\n"); } /* This copies everything *except* tsdata: */ deepcopy_tinfo(tinfo_next, tinfoptr); tinfo_next->previous=localp->tinfop; tinfo_next->next=NULL; localp->tinfop->next=tinfo_next; localp->tinfop=tinfo_next; } tinfoptr->tsdata=NULL; } free_tinfo(tinfo); /* Free everything from the old epoch(s) *except* tsdata... */ return tinfo->tsdata; } else { /* !ARGS_LINKEPOCHS */ transform_info_ptr tinfoptr, tinfop; /* Go to the start: */ for (tinfoptr=tinfo; tinfoptr->previous!=NULL; tinfoptr=tinfoptr->previous); for (tinfop= &localp->tinfo; tinfoptr!=NULL; tinfoptr=tinfoptr->next, tinfop=tinfop->next) { if (tinfop==NULL) { ERREXIT(tinfo->emethods, "append: Varying number of linked epochs in input!\n"); } else { DATATYPE * const newtsdata=add_channels_or_points(tinfop, tinfoptr, /* channel_list= */NULL, localp->type, /* zero_newdata= */FALSE); free_pointer((void **)&tinfop->tsdata); tinfop->tsdata=newtsdata; } } } /* !ARGS_LINKEPOCHS */ free_tinfo(tinfo); /* Free everything from the old epoch */ localp->nroffiles++; return localp->tinfo.tsdata; }
/*{{{ swap_ix(transform_info_ptr tinfo) {*/ METHODDEF DATATYPE * swap_ix(transform_info_ptr tinfo) { int const olditemsize=tinfo->itemsize; if (tinfo->data_type==FREQ_DATA) { if (tinfo->nrofshifts>1) { ERREXIT(tinfo->emethods, "swap_ix: FREQ_DATA with nrofshifts>1 not (yet?) implemented.\n"); } tinfo->nr_of_points=tinfo->nroffreq; tinfo->data_type=TIME_DATA; } free_pointer((void **)&tinfo->xdata); tinfo->xchannelname=NULL; nonmultiplexed(tinfo); tinfo->itemsize=tinfo->nr_of_points; tinfo->nr_of_points=olditemsize; tinfo->beforetrig=0; tinfo->aftertrig=tinfo->nr_of_points; return tinfo->tsdata; }
/* * static void *get_space * * DESCRIPTION: * * Moved a pointer into our free lists. * * RETURNS: * * Success - New address that we can use. * * Failure - NULL * * ARGUMENTS: * * mp_p <-> Pointer to the memory pool. * * byte_size -> Size of the address space that we need. * * error_p <- Pointer to integer which, if not NULL, will be set with * a mpool error code. */ static void *get_space(mpool_t *mp_p, const unsigned long byte_size, int *error_p) { mpool_block_t *block_p; mpool_free_t free_pnt; int ret; unsigned long size; unsigned int bit_c, page_n, left; void *free_addr = NULL, *free_end; size = byte_size; while ((size & (sizeof(void *) - 1)) > 0) { size++; } /* * First we check the free lists looking for something with enough * pages. Maybe we should only look X bits higher in the list. * * XXX: this is where we'd do the best fit. We'd look for the * closest match. We then could put the rest of the allocation that * we did not use in a lower free list. Have a define which states * how deep in the free list to go to find the closest match. */ for (bit_c = size_to_bits(size); bit_c <= MAX_BITS; bit_c++) { if (mp_p->mp_free[bit_c] != NULL) { free_addr = mp_p->mp_free[bit_c]; break; } } /* * If we haven't allocated any blocks or if the last block doesn't * have enough memory then we need a new block. */ if (bit_c > MAX_BITS) { /* we need to allocate more space */ page_n = PAGES_IN_SIZE(mp_p, size); /* now we try and get the pages we need/want */ block_p = alloc_pages(mp_p, page_n, error_p); if (block_p == NULL) { /* error_p set in alloc_pages */ return NULL; } /* init the block header */ block_p->mb_magic = BLOCK_MAGIC; block_p->mb_bounds_p = (char *)block_p + SIZE_OF_PAGES(mp_p, page_n); block_p->mb_next_p = mp_p->mp_first_p; block_p->mb_magic2 = BLOCK_MAGIC; /* * We insert it into the front of the queue. We could add it to * the end but there is not much use. */ mp_p->mp_first_p = block_p; if (mp_p->mp_last_p == NULL) { mp_p->mp_last_p = block_p; } free_addr = FIRST_ADDR_IN_BLOCK(block_p); #ifdef DEBUG (void)printf("had to allocate space for %lx of %lu bytes\n", (long)free_addr, size); #endif free_end = (char *)free_addr + size; left = (char *)block_p->mb_bounds_p - (char *)free_end; } else { if (bit_c < min_bit_free_next) { mp_p->mp_free[bit_c] = NULL; /* calculate the number of left over bytes */ left = bits_to_size(bit_c) - size; } else if (bit_c < min_bit_free_next) { /* grab the next pointer from the freed address into our list */ memcpy(mp_p->mp_free + bit_c, free_addr, sizeof(void *)); /* calculate the number of left over bytes */ left = bits_to_size(bit_c) - size; } else { /* grab the free structure from the address */ memcpy(&free_pnt, free_addr, sizeof(free_pnt)); mp_p->mp_free[bit_c] = free_pnt.mf_next_p; /* are we are splitting up a multiblock chunk into fewer blocks? */ if (PAGES_IN_SIZE(mp_p, free_pnt.mf_size) > PAGES_IN_SIZE(mp_p, size)) { ret = split_block(mp_p, free_addr, size); if (ret != MPOOL_ERROR_NONE) { SET_POINTER(error_p, ret); return NULL; } /* left over memory was taken care of in split_block */ left = 0; } else { /* calculate the number of left over bytes */ left = free_pnt.mf_size - size; } } #ifdef DEBUG (void)printf("found a free block at %lx of %lu bytes\n", (long)free_addr, left + size); #endif free_end = (char *)free_addr + size; } /* * If we have memory left over then we free it so someone else can * use it. We do not free the space if we just allocated a * multi-block chunk because we need to have every allocation easily * find the start of the block. Every user address % page-size * should take us to the start of the block. */ if (left > 0 && size <= MAX_BLOCK_USER_MEMORY(mp_p)) { /* free the rest of the block */ ret = free_pointer(mp_p, free_end, left); if (ret != MPOOL_ERROR_NONE) { SET_POINTER(error_p, ret); return NULL; } } /* update our bounds */ if (free_addr > mp_p->mp_bounds_p) { mp_p->mp_bounds_p = free_addr; } else if (free_addr < mp_p->mp_min_p) { mp_p->mp_min_p = free_addr; } return free_addr; }
/*{{{ write_vitaport_exit(transform_info_ptr tinfo) {*/ METHODDEF void write_vitaport_exit(transform_info_ptr tinfo) { struct write_vitaport_storage *local_arg=(struct write_vitaport_storage *)tinfo->methods->local_storage; int channel, NoOfChannels=local_arg->fileheader.knum; long point; long const channellen=local_arg->total_points*sizeof(uint16_t); long const hdlen=local_arg->fileheader.hdlen; uint16_t checksum=0; local_arg->fileheaderII.dlen=hdlen+NoOfChannels*channellen; /*{{{ Write the file headers*/ # ifdef LITTLE_ENDIAN change_byteorder((char *)&local_arg->fileheader, sm_vitaport_fileheader); change_byteorder((char *)&local_arg->fileheaderII, sm_vitaportII_fileheader); change_byteorder((char *)&local_arg->fileext, sm_vitaportII_fileext); # endif write_struct((char *)&local_arg->fileheader, sm_vitaport_fileheader, local_arg->outfile); write_struct((char *)&local_arg->fileheaderII, sm_vitaportII_fileheader, local_arg->outfile); write_struct((char *)&local_arg->fileext, sm_vitaportII_fileext, local_arg->outfile); /*}}} */ for (channel=0; channel<NoOfChannels; channel++) { /*{{{ Write a channel header*/ /* This is the factor as we'd like to have it... */ float factor=((float)(local_arg->channelmax[channel]> -local_arg->channelmin[channel] ? local_arg->channelmax[channel] : -local_arg->channelmin[channel]))/SHRT_MAX; if (strncmp(local_arg->channelheaders[channel].kname, VP_MARKERCHANNEL_NAME, 6)==0) { strcpy(local_arg->channelheaders[channel].kunit, "mrk"); local_arg->channelheaders[channel].datype=VP_DATYPE_MARKER; /* Since the marker channel is read without the conversion factors, * set the conversion to 1.0 for this channel */ local_arg->channelheaders[channel].mulfac=local_arg->channelheaders[channel].divfac=1; local_arg->channelheaders[channel].offset=0; } else { float const logdiff=log(factor)-TARGET_LOG_SHORTVAL; local_arg->channelheaders[channel].offset=0; if (logdiff<0) { /*{{{ Factor is small: Better to fix divfac and calculate mulfac after that*/ double const divfac=exp(-logdiff); if (divfac>SHRT_MAX) { local_arg->channelheaders[channel].divfac=SHRT_MAX; } else { local_arg->channelheaders[channel].divfac=(unsigned short)divfac; } /* The +1 takes care that we never get below the `ideal' factor computed above. */ local_arg->channelheaders[channel].mulfac=(unsigned short)(factor*local_arg->channelheaders[channel].divfac+1); if (local_arg->channelheaders[channel].mulfac==0) { local_arg->channelheaders[channel].mulfac=1; local_arg->channelheaders[channel].divfac=(unsigned short)(1.0/factor-1); } /*}}} */ } else { /*{{{ Factor is large: Better to fix mulfac and calculate divfac after that*/ double const mulfac=exp(logdiff); if (mulfac>SHRT_MAX) { local_arg->channelheaders[channel].mulfac=SHRT_MAX; } else { local_arg->channelheaders[channel].mulfac=(unsigned short)mulfac; } /* The -1 takes care that we never get below the `ideal' factor computed above. */ local_arg->channelheaders[channel].divfac=(unsigned short)(local_arg->channelheaders[channel].mulfac/factor-1); if (local_arg->channelheaders[channel].divfac==0) { local_arg->channelheaders[channel].mulfac=(unsigned short)(factor+1); local_arg->channelheaders[channel].divfac=1; } /*}}} */ } } /* Now see which factor we actually got constructed */ factor=((float)local_arg->channelheaders[channel].mulfac)/local_arg->channelheaders[channel].divfac; local_arg->channelheadersII[channel].doffs=channel*channellen; local_arg->channelheadersII[channel].dlen=channellen; # ifdef LITTLE_ENDIAN change_byteorder((char *)&local_arg->channelheaders[channel], sm_vitaport_channelheader); change_byteorder((char *)&local_arg->channelheadersII[channel], sm_vitaportIIrchannelheader); # endif write_struct((char *)&local_arg->channelheaders[channel], sm_vitaport_channelheader, local_arg->outfile); write_struct((char *)&local_arg->channelheadersII[channel], sm_vitaportIIrchannelheader, local_arg->outfile); # ifdef LITTLE_ENDIAN change_byteorder((char *)&local_arg->channelheaders[channel], sm_vitaport_channelheader); change_byteorder((char *)&local_arg->channelheadersII[channel], sm_vitaportIIrchannelheader); # endif /*}}} */ } fwrite(&checksum, sizeof(checksum), 1, local_arg->outfile); TRACEMS(tinfo->emethods, 1, "write_vitaport_exit: Copying channels to output file...\n"); /* We close and re-open the channel file because buffering is much more * efficient at least with DJGPP if the file is either only read or written */ fclose(local_arg->channelfile); if ((local_arg->channelfile=fopen(local_arg->channelfilename, "rb"))==NULL) { ERREXIT1(tinfo->emethods, "write_vitaport_exit: Can't open temp file %s\n", MSGPARM(local_arg->channelfilename)); } for (channel=0; channel<NoOfChannels; channel++) { /*{{{ Copy a channel to the target file */ float const factor=((float)local_arg->channelheaders[channel].mulfac)/local_arg->channelheaders[channel].divfac; unsigned short const offset=local_arg->channelheaders[channel].offset; for (point=0; point<local_arg->total_points; point++) { DATATYPE dat; int16_t s; fseek(local_arg->channelfile, (point*NoOfChannels+channel)*sizeof(DATATYPE), SEEK_SET); if (fread(&dat, sizeof(DATATYPE), 1, local_arg->channelfile)!=1) { ERREXIT(tinfo->emethods, "write_vitaport_exit: Error reading temp file.\n"); } s= (int16_t)rint(dat/factor)-offset; # ifdef LITTLE_ENDIAN Intel_int16((uint16_t *)&s); # endif if (fwrite(&s, sizeof(s), 1, local_arg->outfile)!=1) { ERREXIT(tinfo->emethods, "write_vitaport_exit: Write error.\n"); } } /*}}} */ } fclose(local_arg->channelfile); unlink(local_arg->channelfilename); if (local_arg->triggers.current_length!=0) { long tagno, n_events; uint32_t length, trigpoint; int const nevents=local_arg->triggers.current_length/sizeof(struct trigger); struct vitaport_idiotic_multiplemarkertablenames *markertable_entry; /* Try to keep a security space of at least 20 free events */ for (markertable_entry=markertable_names; markertable_entry->markertable_name!=NULL && markertable_entry->idiotically_fixed_length<nevents+20; markertable_entry++); if (markertable_entry->markertable_name==NULL) { if ((markertable_entry-1)->idiotically_fixed_length<=nevents) { /* Drop the requirement for at least 20 free events */ markertable_entry--; } else { /* No use... */ ERREXIT1(tinfo->emethods, "write_vitaport_exit: %d events wouldn't fit into the fixed-length VITAGRAPH marker tables!\nBlame the Vitaport people!\n", MSGPARM(nevents)); } } n_events=markertable_entry->idiotically_fixed_length; fwrite(markertable_entry->markertable_name, 1, VP_TABLEVAR_LENGTH, local_arg->outfile); length=n_events*sizeof(length); #ifdef LITTLE_ENDIAN Intel_int32((uint32_t *)&length); #endif fwrite(&length, sizeof(length), 1, local_arg->outfile); for (tagno=0; tagno<n_events; tagno++) { if (tagno<nevents) { struct trigger * const intrig=((struct trigger *)local_arg->triggers.buffer_start)+tagno; /* Trigger positions are given in ms units */ trigpoint=(long)rint(intrig->position*1000.0/local_arg->sfreq); /* Make trigpoint uneven if code%2==1 */ trigpoint=trigpoint-trigpoint%2+(intrig->code-1)%2; } else { trigpoint= -1; } #ifdef LITTLE_ENDIAN Intel_int32((uint32_t *)&trigpoint); #endif fwrite(&trigpoint, sizeof(trigpoint), 1, local_arg->outfile); } for (; tagno<n_events; tagno++) { trigpoint= -1; #ifdef LITTLE_ENDIAN Intel_int32((uint32_t *)&trigpoint); #endif fwrite(&trigpoint, sizeof(trigpoint), 1, local_arg->outfile); } } fclose(local_arg->outfile); /*{{{ Free memory*/ free_pointer((void **)&local_arg->channelfilename); free_pointer((void **)&local_arg->channelmax); free_pointer((void **)&local_arg->channelmin); free_pointer((void **)&local_arg->channelheaders); free_pointer((void **)&local_arg->channelheadersII); if (local_arg->triggers.buffer_start!=NULL) { clear_triggers(&local_arg->triggers); growing_buf_free(&local_arg->triggers); } /*}}} */ tinfo->methods->init_done=FALSE; }
/** * Deallocates array memory. * * @param pointer pointer to the previously allocated memory */ void operator delete[](void* pointer) throw() { free_pointer(pointer, _DEBUG_NEW_CALLER_ADDRESS, true); }
/*! ************************************************************************ * \brief * free allocated memory * ************************************************************************ */ void destructTiff (Tiff * t) { free_pointer( t->fileInMemory); free_pointer( t->img); }
/*! ************************************************************************ * \brief * Read file named 'path' into memory buffer 't->fileInMemory'. * * \return * 0 if successful ************************************************************************ */ static int readFileIntoMemory (Tiff * t, const char * path) { long cnt, result; uint16 byteOrder; int endian = 1, machineLittleEndian = (*( (char *)(&endian) ) == 1) ? 1 : 0, fd; assert( t); assert( path); fd = open( path, OPENFLAGS_READ); if (fd == -1) { fprintf( stderr, "Couldn't open to read: %s\n", path); return 1; } cnt = (long) lseek( fd, 0, SEEK_END); // TIFF files by definition cannot exceed 2^32 if (cnt == -1L) return 1; if (lseek( fd, 0, SEEK_SET) == -1L) // reposition file at beginning return 1; t->fileInMemory = (uint8 *) realloc( t->fileInMemory, cnt); if (t->fileInMemory == 0) { close( fd); return 1; } result = (long) read( fd, t->fileInMemory, cnt); if (result != cnt) { close( fd); return 1; } close( fd); byteOrder = (t->fileInMemory[0] << 8) | t->fileInMemory[1]; switch (byteOrder) { case 0x4949: // little endian file t->le = 1; //printf( "Little endian file\n"); break; case 0x4D4D: // big endian file t->le = 0; //printf( "Big endian file\n"); break; default: fprintf( stderr, "First two bytes indicate: Not a TIFF file\n"); free_pointer( t->fileInMemory); return 1; } if (t->le == machineLittleEndian) // endianness of machine matches file { t->getU16 = getU16; t->getU32 = getU32; } else // endianness of machine does not match file { t->getU16 = getSwappedU16; t->getU32 = getSwappedU32; } t->mp = t->fileInMemory; return 0; }
/*{{{ project(transform_info_ptr tinfo)*/ METHODDEF DATATYPE * project(transform_info_ptr tinfo) { struct project_args_struct *project_args=(struct project_args_struct *)tinfo->methods->local_storage; transform_argument *args=tinfo->methods->arguments; DATATYPE *retvalue=tinfo->tsdata; array indata, scalars, *vectors= &project_args->vectors; int itempart, itemparts=tinfo->itemsize-tinfo->leaveright; if (project_args->project_mode==PROJECT_MODE_MULTIPLY) { if (!(tinfo->nr_of_channels==vectors->nr_of_vectors ||(tinfo->nr_of_channels==1 && tinfo->itemsize==vectors->nr_of_vectors))) { ERREXIT(tinfo->emethods, "project: Number of scalars and maps doesn't match!\n"); } } else { if (vectors->nr_of_elements!=tinfo->nr_of_channels) { ERREXIT2(tinfo->emethods, "project: %d channels in epoch, but %d channels in project file.\n", MSGPARM(tinfo->nr_of_channels), MSGPARM(vectors->nr_of_elements)); } } array_reset(vectors); tinfo_array(tinfo, &indata); array_transpose(&indata); /* Vectors are maps */ /* Be sure that different output items are adjacent... */ scalars.nr_of_elements=vectors->nr_of_vectors; switch (project_args->project_mode) { case PROJECT_MODE_SCALAR: scalars.nr_of_vectors=tinfo->nr_of_points; scalars.element_skip=itemparts; break; case PROJECT_MODE_SSP: case PROJECT_MODE_SSPS: scalars.nr_of_vectors=1; scalars.element_skip=1; break; case PROJECT_MODE_MULTIPLY: scalars=indata; if (tinfo->nr_of_channels!=vectors->nr_of_vectors) { /* Ie, one channel and weights in the items: Convert from 1 element to * itemsize elements */ scalars.element_skip=1; scalars.nr_of_elements=tinfo->itemsize; itemparts=1; } indata.element_skip=itemparts; indata.nr_of_elements=vectors->nr_of_elements; /* New number of channels */ indata.nr_of_vectors=scalars.nr_of_vectors; /* New number of points */ if (array_allocate(&indata)==NULL) { ERREXIT(tinfo->emethods, "project: Can't allocate new indata array\n"); } break; } if (project_args->project_mode==PROJECT_MODE_MULTIPLY) { array_transpose(vectors); /* Now the elements are the subspace dimensions */ for (itempart=0; itempart<itemparts; itempart++) { array_use_item(&indata, itempart); array_use_item(&scalars, itempart); do { /*{{{ Build the signal subspace vector*/ do { array_write(&indata, array_multiply(vectors, &scalars, MULT_SAMESIZE)); } while (indata.message==ARRAY_CONTINUE); /*}}} */ } while (indata.message!=ARRAY_ENDOFSCAN); } array_transpose(vectors); } else { if (array_allocate(&scalars)==NULL) { ERREXIT(tinfo->emethods, "project: Can't allocate scalars array\n"); } for (itempart=0; itempart<itemparts; itempart++) { array_use_item(&indata, itempart); if (project_args->project_mode==PROJECT_MODE_SCALAR) { array_use_item(&scalars, itempart); } do { /*{{{ Calculate the projection scalars*/ do { /* With all vectors in turn: */ DATATYPE product=0.0; do { if (project_args->channel_list!=NULL && !is_in_channellist(vectors->current_element+1, project_args->channel_list)) { array_advance(vectors); array_advance(&indata); } else { product+=array_scan(&indata)*array_scan(vectors); } } while (vectors->message==ARRAY_CONTINUE); array_write(&scalars, product); if (scalars.message==ARRAY_CONTINUE) array_previousvector(&indata); } while (scalars.message==ARRAY_CONTINUE); /*}}} */ switch (project_args->project_mode) { case PROJECT_MODE_SCALAR: break; case PROJECT_MODE_SSP: /*{{{ Build the signal subspace vector*/ array_transpose(vectors); /* Now the elements are the subspace dimensions */ array_previousvector(&indata); do { array_write(&indata, array_multiply(vectors, &scalars, MULT_VECTOR)); } while (indata.message==ARRAY_CONTINUE); array_transpose(vectors); /*}}} */ break; case PROJECT_MODE_SSPS: /*{{{ Subtract the signal subspace vector*/ array_transpose(vectors); /* Now the elements are the subspace dimensions */ array_previousvector(&indata); do { array_write(&indata, READ_ELEMENT(&indata)-array_multiply(vectors, &scalars, MULT_VECTOR)); } while (indata.message==ARRAY_CONTINUE); array_transpose(vectors); /*}}} */ break; default: /* Can't happen, just to keep the compiler happy... */ ERREXIT(tinfo->emethods, "project: This cannot happen!\n"); break; } } while (indata.message!=ARRAY_ENDOFSCAN); } } /*{{{ Prepare tinfo to reflect the data structure returned*/ switch (project_args->project_mode) { case PROJECT_MODE_SCALAR: if (args[ARGS_USE_CHANNELS].is_set) { tinfo->nr_of_channels=vectors->nr_of_vectors; tinfo->itemsize=itemparts; } else { tinfo->nr_of_channels=1; tinfo->itemsize=itemparts*vectors->nr_of_vectors; } tinfo->length_of_output_region=scalars.nr_of_elements*scalars.element_skip*scalars.nr_of_vectors; tinfo->leaveright=0; tinfo->multiplexed=TRUE; if (tinfo->channelnames!=NULL) { free_pointer((void **)&tinfo->channelnames[0]); free_pointer((void **)&tinfo->channelnames); } free_pointer((void **)&tinfo->probepos); create_channelgrid(tinfo); retvalue=scalars.start; break; case PROJECT_MODE_SSP: case PROJECT_MODE_SSPS: array_free(&scalars); retvalue=tinfo->tsdata; break; case PROJECT_MODE_MULTIPLY: /* Note that we don't free `scalars' because it just points to the original tsdata! */ /* Have to set this correctly so that copy_channelinfo works... */ tinfo->nr_of_channels=indata.nr_of_elements; copy_channelinfo(tinfo, project_args->save_side_tinfo.channelnames, project_args->save_side_tinfo.probepos); tinfo->nr_of_points=indata.nr_of_vectors; tinfo->itemsize=indata.element_skip; tinfo->length_of_output_region=tinfo->nr_of_channels*tinfo->nr_of_points*tinfo->itemsize; retvalue=indata.start; tinfo->multiplexed=TRUE; break; } /*}}} */ return retvalue; }
/*! ************************************************************************************** * \brief * free memory of error resilient RDO. ************************************************************************************** */ void free_errdo_mem(VideoParameters *p_Vid) { //for shared memory if (p_Vid->p_decs->res_img) { free_mem3Dint(p_Vid->p_decs->res_img); p_Vid->p_decs->res_img = NULL; } if (p_Vid->p_decs->res_mb_best8x8) { free_mem3Dint(p_Vid->p_decs->res_mb_best8x8); p_Vid->p_decs->res_mb_best8x8 = NULL; } //for RMPC if (p_Vid->p_decs->RCD_bestY_mb) { free_mem2Dint(p_Vid->p_decs->RCD_bestY_mb); p_Vid->p_decs->RCD_bestY_mb = NULL; } if (p_Vid->p_decs->RCD_bestY_b8x8) { free_mem3Dint(p_Vid->p_decs->RCD_bestY_b8x8); p_Vid->p_decs->RCD_bestY_b8x8 = NULL; } if (p_Vid->p_decs->MVCD_bestY_mb) { free_mem2Dint(p_Vid->p_decs->MVCD_bestY_mb); p_Vid->p_decs->MVCD_bestY_mb = NULL; } if (p_Vid->p_decs->MVCD_bestY_b8x8) { free_mem3Dint(p_Vid->p_decs->MVCD_bestY_b8x8); p_Vid->p_decs->MVCD_bestY_b8x8 = NULL; } if (p_Vid->p_decs->flag_bestY_mb) { free_mem2D(p_Vid->p_decs->flag_bestY_mb); p_Vid->p_decs->flag_bestY_mb = NULL; } if (p_Vid->p_decs->flag_bestY_b8x8) { free_mem3D(p_Vid->p_decs->flag_bestY_b8x8); p_Vid->p_decs->flag_bestY_b8x8 = NULL; } if (p_Vid->p_decs->flag_wo_res) { free_mem2D(p_Vid->p_decs->flag_wo_res); p_Vid->p_decs->flag_wo_res = NULL; } if (p_Vid->p_decs->flag_wo_res_bestY_b8x8) { free_mem3D(p_Vid->p_decs->flag_wo_res_bestY_b8x8); p_Vid->p_decs->flag_wo_res_bestY_b8x8 = NULL; } if (p_Vid->p_decs->trans_dist_bestY_mb) { free_mem2Dint(p_Vid->p_decs->trans_dist_bestY_mb); p_Vid->p_decs->trans_dist_bestY_mb = NULL; } if (p_Vid->p_decs->trans_dist_bestY_b8x8) { free_mem3Dint(p_Vid->p_decs->trans_dist_bestY_b8x8); p_Vid->p_decs->trans_dist_bestY_b8x8 = NULL; } if (p_Vid->p_decs->trans_dist_wo_res) { free_mem2Dint(p_Vid->p_decs->trans_dist_wo_res); p_Vid->p_decs->trans_dist_wo_res = NULL; //it is used for P8x8, where residual may be set to 0 } if (p_Vid->p_decs->trans_dist_wo_res_bestY_b8x8) { free_mem3Dint(p_Vid->p_decs->trans_dist_wo_res_bestY_b8x8); p_Vid->p_decs->trans_dist_wo_res_bestY_b8x8 = NULL; //it is used for P8x8, where residual may be set to 0 } if (p_Vid->p_decs->trans_err_bestY_mb) { free_mem2Dint(p_Vid->p_decs->trans_err_bestY_mb); p_Vid->p_decs->trans_err_bestY_mb = NULL; } if (p_Vid->p_decs->trans_err_bestY_b8x8) { free_mem3Dint(p_Vid->p_decs->trans_err_bestY_b8x8); p_Vid->p_decs->trans_err_bestY_b8x8 = NULL; } if (p_Vid->p_decs->trans_err_wo_res) { free_mem2Dint(p_Vid->p_decs->trans_err_wo_res); p_Vid->p_decs->trans_err_wo_res = NULL; //it is used for P8x8, where residual may be set to 0 } if (p_Vid->p_decs->trans_err_wo_res_bestY_b8x8) { free_mem3Dint(p_Vid->p_decs->trans_err_wo_res_bestY_b8x8); p_Vid->p_decs->trans_err_wo_res_bestY_b8x8 = NULL; //it is used for P8x8, where residual may be set to 0 } //for LLN if (p_Vid->p_decs->dec_mb_pred) { free_mem3Dpel(p_Vid->p_decs->dec_mb_pred); p_Vid->p_decs->dec_mb_pred = NULL; } if (p_Vid->p_decs->dec_mbY_best) { free_mem3Dpel(p_Vid->p_decs->dec_mbY_best); p_Vid->p_decs->dec_mbY_best = NULL; } if (p_Vid->p_decs->dec_mbY_best8x8) { free_mem4Dpel(p_Vid->p_decs->dec_mbY_best8x8); p_Vid->p_decs->dec_mb_pred_best8x8 = NULL; } if (p_Vid->p_decs->dec_mb_pred_best8x8) { free_mem4Dpel(p_Vid->p_decs->dec_mb_pred_best8x8); p_Vid->p_decs->dec_mbY_best8x8 = NULL; } //for ROPE if (p_Vid->p_decs->first_moment_bestY_mb) { free_mem2Dpel(p_Vid->p_decs->first_moment_bestY_mb); p_Vid->p_decs->first_moment_bestY_mb = NULL; } if (p_Vid->p_decs->first_moment_bestY_b8x8) { free_mem3Dpel(p_Vid->p_decs->first_moment_bestY_b8x8); p_Vid->p_decs->first_moment_bestY_b8x8 = NULL; } if (p_Vid->p_decs->first_moment_pred_bestY_b8x8) { free_mem3Dpel(p_Vid->p_decs->first_moment_pred_bestY_b8x8); p_Vid->p_decs->first_moment_pred_bestY_b8x8 = NULL; } if (p_Vid->p_decs->first_moment_pred) { free_mem2Dpel(p_Vid->p_decs->first_moment_pred); p_Vid->p_decs->first_moment_pred = NULL; } if (p_Vid->p_decs->second_moment_bestY_mb) { free_mem2Duint16(p_Vid->p_decs->second_moment_bestY_mb); p_Vid->p_decs->second_moment_bestY_mb = NULL; } if (p_Vid->p_decs->second_moment_bestY_b8x8) { free_mem3Duint16(p_Vid->p_decs->second_moment_bestY_b8x8); p_Vid->p_decs->second_moment_bestY_b8x8 = NULL; } if (p_Vid->p_decs->second_moment_pred_bestY_b8x8) { free_mem3Duint16(p_Vid->p_decs->second_moment_pred_bestY_b8x8); p_Vid->p_decs->second_moment_pred_bestY_b8x8 = NULL; } if (p_Vid->p_decs->second_moment_pred) { free_mem2Duint16(p_Vid->p_decs->second_moment_pred); p_Vid->p_decs->second_moment_pred = NULL; } free_pointer( p_Vid->p_decs ); }
/*! ************************************************************************************* * \brief * free storable picture memory for errdo * ************************************************************************************* */ void errdo_free_storable_picture(StorablePicture* s) { int nplane; Dist_Estm *p = s->de_mem; //free memory for RMPC and extended RMPC algorithms if (p->res_con_diff_Y) { free_mem2Dint(p->res_con_diff_Y); p->res_con_diff_Y = NULL; } if (p->res_con_diff_UV) { free_mem3Dint(p->res_con_diff_UV); p->res_con_diff_UV = NULL; } for (nplane = 0; nplane < 3; nplane++) { p->p_res_con_diff[nplane] = NULL; } if (p->MV_con_diff_Y) { free_mem2Dint(p->MV_con_diff_Y); p->MV_con_diff_Y = NULL; } if (p->MV_con_diff_UV) { free_mem3Dint(p->MV_con_diff_UV); p->MV_con_diff_UV = NULL; } for (nplane = 0; nplane < 3; nplane++) { p->p_MV_con_diff[nplane] = NULL; } if (p->error_sign_flag_Y) { free_mem2D(p->error_sign_flag_Y); p->error_sign_flag_Y = NULL; } if (p->error_sign_flag_UV) { free_mem3D(p->error_sign_flag_UV); p->error_sign_flag_UV = NULL; } for (nplane = 0; nplane < 3; nplane++) { p->p_error_sign_flag[nplane] = NULL; } if (p->transmission_dist_Y) { free_mem2Dint(p->transmission_dist_Y); p->transmission_dist_Y = NULL; } if (p->transmission_dist_UV) { free_mem3Dint(p->transmission_dist_UV); p->transmission_dist_UV = NULL; } for (nplane = 0; nplane < 3; nplane++) { p->p_transmission_dist[nplane] = NULL; } if (p->transmission_err_Y) { free_mem2Dint(p->transmission_err_Y); p->transmission_err_Y = NULL; } if (p->transmission_err_UV) { free_mem3Dint(p->transmission_err_UV); p->transmission_err_UV = NULL; } for (nplane = 0; nplane < 3; nplane++) { p->p_transmission_err[nplane] = NULL; } //free memory for LLN and Faster LLN algorithms if (p->dec_imgY) { free_mem3Dpel(p->dec_imgY); p->dec_imgY = NULL; } if (p->dec_imgUV) { free_mem4Dpel(p->dec_imgUV); p->dec_imgUV = NULL; } for (nplane = 0; nplane < 3; nplane++) { free_pointer(p->p_dec_img[nplane]); } if (p->mb_error_map) { free_mem3D(p->mb_error_map); p->mb_error_map = NULL; } //free memory for ROPE and extended ROPE algorithms if (p->first_moment_Y) { free_mem2Dpel(p->first_moment_Y); p->first_moment_Y = NULL; } if (p->first_moment_UV) { free_mem3Dpel(p->first_moment_UV); p->first_moment_UV = NULL; } for (nplane = 0; nplane < 3; nplane++) { p->p_first_moment[nplane] = NULL; } if (p->second_moment_Y) { free_mem2Duint16(p->second_moment_Y); p->second_moment_Y = NULL; } if (p->second_moment_UV) { free_mem3Duint16(p->second_moment_UV); p->second_moment_UV = NULL; } for (nplane = 0; nplane < 3; nplane++) { p->p_second_moment[nplane] = NULL; } free_pointer(s->de_mem); }
/* This function has all the knowledge about events in the various file types */ LOCAL void read_synamps_build_trigbuffer(transform_info_ptr tinfo) { struct read_synamps_storage * const local_arg=(struct read_synamps_storage *)tinfo->methods->local_storage; transform_argument *args=tinfo->methods->arguments; if (local_arg->triggers.buffer_start==NULL) { growing_buf_allocate(&local_arg->triggers, 0); } else { growing_buf_clear(&local_arg->triggers); } if (args[ARGS_TRIGFILE].is_set) { FILE * const triggerfile=(strcmp(args[ARGS_TRIGFILE].arg.s,"stdin")==0 ? stdin : fopen(args[ARGS_TRIGFILE].arg.s, "r")); TRACEMS(tinfo->emethods, 1, "read_synamps_build_trigbuffer: Reading event file\n"); if (triggerfile==NULL) { ERREXIT1(tinfo->emethods, "read_synamps_build_trigbuffer: Can't open trigger file >%s<\n", MSGPARM(args[ARGS_TRIGFILE].arg.s)); } while (TRUE) { long trigpoint; char *description; int const code=read_trigger_from_trigfile(triggerfile, tinfo->sfreq, &trigpoint, &description); if (code==0) break; push_trigger(&local_arg->triggers, trigpoint, code, description); free_pointer((void **)&description); } if (triggerfile!=stdin) fclose(triggerfile); } else { switch(local_arg->SubType) { case NST_CONTINUOUS: case NST_SYNAMPS: { /*{{{ Read the events header and array*/ /* We handle errors through setting errormessage, because we want to continue * with a warning if we are in continuous mode or read from an event file */ TEEG TagType; EVENT2 event; TRACEMS(tinfo->emethods, 1, "read_synamps_build_trigbuffer: Reading event table\n"); fseek(local_arg->SCAN,local_arg->EEG.EventTablePos,SEEK_SET); /* Here we face two evils in one header: Coding enums as chars and * allowing longs at odd addresses. Well... */ if (read_struct((char *)&TagType, sm_TEEG, local_arg->SCAN)==1) { # ifndef LITTLE_ENDIAN change_byteorder((char *)&TagType, sm_TEEG); # endif if (TagType.Teeg==TEEG_EVENT_TAB1 || TagType.Teeg==TEEG_EVENT_TAB2) { /*{{{ Read the event table*/ struct_member * const sm_EVENT=(TagType.Teeg==TEEG_EVENT_TAB1 ? sm_EVENT1 : sm_EVENT2); int ntags, tag; ntags=TagType.Size/sm_EVENT[0].offset; /* sm_EVENT[0].offset is the size of the structure in file. */ for (tag=0; tag<ntags; tag++) { long trigger_position=0; int TrigVal=0, KeyPad=0, KeyBoard=0; enum NEUROSCAN_ACCEPTVALUES Accept=(enum NEUROSCAN_ACCEPTVALUES)0; if (read_struct((char *)&event, sm_EVENT, local_arg->SCAN)==0) { ERREXIT(tinfo->emethods, "read_synamps_build_trigbuffer: Can't read an event table entry.\n"); break; } # ifndef LITTLE_ENDIAN change_byteorder((char *)&event, sm_EVENT); # endif trigger_position=offset2point(tinfo,event.Offset); TrigVal=event.StimType &0xff; KeyBoard=event.KeyBoard&0xf; KeyPad=Event_KeyPad_value(event); Accept=Event_Accept_value(event); if (!args[ARGS_NOREJECTED].is_set || Accept!=NAV_REJECT) { read_synamps_push_keys(tinfo, trigger_position, TrigVal, KeyPad, KeyBoard, Accept); } } /*}}} */ } else { ERREXIT1(tinfo->emethods, "read_synamps_build_trigbuffer: Unknown tag type %d.\n", MSGPARM(TagType.Teeg)); } } else { ERREXIT(tinfo->emethods, "read_synamps_build_trigbuffer: Can't read the event table header.\n"); } /*}}} */ } break; case NST_CONT0: { /*{{{ CONT0: Two trailing marker channels*/ long current_triggerpoint=0; unsigned short *pdata; TRACEMS(tinfo->emethods, 1, "read_synamps_build_trigbuffer: Analyzing CONT0 marker channels\n"); while (current_triggerpoint<local_arg->EEG.NumSamples) { int TrigVal=0, KeyPad=0, KeyBoard=0; enum NEUROSCAN_ACCEPTVALUES Accept=(enum NEUROSCAN_ACCEPTVALUES)0; read_synamps_seek_point(tinfo, current_triggerpoint); pdata=(unsigned short *)local_arg->buffer+current_triggerpoint-local_arg->first_point_in_buffer+local_arg->nchannels; TrigVal =pdata[0]&0xff; KeyBoard=pdata[1]&0xf; if (KeyBoard>13) KeyBoard=0; if (TrigVal!=0 || KeyBoard!=0) { read_synamps_push_keys(tinfo, current_triggerpoint, TrigVal, KeyPad, KeyBoard, Accept); current_triggerpoint++; while (current_triggerpoint<local_arg->EEG.NumSamples) { int This_TrigVal, This_KeyBoard; read_synamps_seek_point(tinfo, current_triggerpoint); pdata=(unsigned short *)local_arg->buffer+current_triggerpoint-local_arg->first_point_in_buffer+local_arg->nchannels; This_TrigVal =pdata[0]&0xff; This_KeyBoard=pdata[1]&0xf; if (This_KeyBoard>13) This_KeyBoard=0; if (This_TrigVal!=TrigVal || This_KeyBoard!=KeyBoard) break; current_triggerpoint++; } } } /*}}} */ } break; case NST_DCMES: { /*{{{ DC-MES: Single, leading marker channel*/ long current_triggerpoint=0; unsigned short *pdata; TRACEMS(tinfo->emethods, 1, "read_synamps_build_trigbuffer: Analyzing DCMES marker channel\n"); while (current_triggerpoint<local_arg->EEG.NumSamples) { int TrigVal=0, KeyPad=0, KeyBoard=0; enum NEUROSCAN_ACCEPTVALUES Accept=(enum NEUROSCAN_ACCEPTVALUES)0; read_synamps_seek_point(tinfo, current_triggerpoint); pdata=(unsigned short *)local_arg->buffer+current_triggerpoint-local_arg->first_point_in_buffer; TrigVal= *pdata&0xff; KeyBoard=(*pdata>>8)&0xf; if (KeyBoard>13) KeyBoard=0; if (TrigVal!=0 || KeyBoard!=0) { read_synamps_push_keys(tinfo, current_triggerpoint, TrigVal, KeyPad, KeyBoard, Accept); current_triggerpoint++; while (current_triggerpoint<local_arg->EEG.NumSamples) { int This_TrigVal, This_KeyBoard; read_synamps_seek_point(tinfo, current_triggerpoint); pdata=(unsigned short *)local_arg->buffer+current_triggerpoint-local_arg->first_point_in_buffer; This_TrigVal= *pdata&0xff; This_KeyBoard=(*pdata>>8)&0xf; if (This_KeyBoard>13) This_KeyBoard=0; if (This_TrigVal!=TrigVal || This_KeyBoard!=KeyBoard) break; current_triggerpoint++; } } } /*}}} */ } break; default: break; } }
/* * mpool_t *mpool_open * * DESCRIPTION: * * Open/allocate a new memory pool. * * RETURNS: * * Success - Pool pointer which must be passed to mpool_close to * deallocate. * * Failure - NULL * * ARGUMENTS: * * flags -> Flags to set attributes of the memory pool. See the top * of mpool.h. * * page_size -> Set the internal memory page-size. This must be a * multiple of the getpagesize() value. Set to 0 for the default. * * start_addr -> Starting address to try and allocate memory pools. * This is ignored if the MPOOL_FLAG_USE_SBRK is enabled. * * error_p <- Pointer to integer which, if not NULL, will be set with * a mpool error code. */ mpool_t *mpool_open(const unsigned int flags, const unsigned int page_size, void *start_addr, int *error_p) { mpool_block_t *block_p; int page_n, ret; mpool_t mp, *mp_p; void *free_addr; if (! enabled_b) { startup(); } /* zero our temp struct */ memset(&mp, 0, sizeof(mp)); mp.mp_magic = MPOOL_MAGIC; mp.mp_flags = flags; mp.mp_alloc_c = 0; mp.mp_user_alloc = 0; mp.mp_max_alloc = 0; mp.mp_page_c = 0; /* mp.mp_page_size set below */ /* mp.mp_blocks_bit_n set below */ /* mp.mp_fd set below */ /* mp.mp_top set below */ /* mp.mp_addr set below */ mp.mp_log_func = NULL; mp.mp_min_p = NULL; mp.mp_bounds_p = NULL; mp.mp_first_p = NULL; mp.mp_last_p = NULL; mp.mp_magic2 = MPOOL_MAGIC; /* get and sanity check our page size */ if (page_size > 0) { mp.mp_page_size = page_size; if (mp.mp_page_size % getpagesize() != 0) { SET_POINTER(error_p, MPOOL_ERROR_ARG_INVALID); return NULL; } } else { mp.mp_page_size = getpagesize() * DEFAULT_PAGE_MULT; if (mp.mp_page_size % 1024 != 0) { SET_POINTER(error_p, MPOOL_ERROR_PAGE_SIZE); return NULL; } } if (BIT_IS_SET(flags, MPOOL_FLAG_USE_SBRK)) { mp.mp_fd = -1; mp.mp_addr = NULL; mp.mp_top = 0; } else { /* open dev-zero for our mmaping */ mp.mp_fd = open("/dev/zero", O_RDWR, 0); if (mp.mp_fd < 0) { SET_POINTER(error_p, MPOOL_ERROR_OPEN_ZERO); return NULL; } mp.mp_addr = start_addr; /* we start at the front of the file */ mp.mp_top = 0; } /* * Find out how many pages we need for our mpool structure. * * NOTE: this adds possibly unneeded space for mpool_block_t which * may not be in this block. */ page_n = PAGES_IN_SIZE(&mp, sizeof(mpool_t)); /* now allocate us space for the actual struct */ mp_p = alloc_pages(&mp, page_n, error_p); if (mp_p == NULL) { if (mp.mp_fd >= 0) { (void)close(mp.mp_fd); mp.mp_fd = -1; } return NULL; } /* * NOTE: we do not normally free the rest of the block here because * we want to lesson the chance of an allocation overwriting the * main structure. */ if (BIT_IS_SET(flags, MPOOL_FLAG_HEAVY_PACKING)) { /* we add a block header to the front of the block */ block_p = (mpool_block_t *)mp_p; /* init the block header */ block_p->mb_magic = BLOCK_MAGIC; block_p->mb_bounds_p = (char *)block_p + SIZE_OF_PAGES(&mp, page_n); block_p->mb_next_p = NULL; block_p->mb_magic2 = BLOCK_MAGIC; /* the mpool pointer is then the 2nd thing in the block */ mp_p = FIRST_ADDR_IN_BLOCK(block_p); free_addr = (char *)mp_p + sizeof(mpool_t); /* free the rest of the block */ ret = free_pointer(&mp, free_addr, (char *)block_p->mb_bounds_p - (char *)free_addr); if (ret != MPOOL_ERROR_NONE) { if (mp.mp_fd >= 0) { (void)close(mp.mp_fd); mp.mp_fd = -1; } /* NOTE: after this line mp_p will be invalid */ (void)free_pages(block_p, SIZE_OF_PAGES(&mp, page_n), BIT_IS_SET(flags, MPOOL_FLAG_USE_SBRK)); SET_POINTER(error_p, ret); return NULL; } /* * NOTE: if we are HEAVY_PACKING then the 1st block with the mpool * header is not on the block linked list. */ /* now copy our tmp structure into our new memory area */ memcpy(mp_p, &mp, sizeof(mpool_t)); /* we setup min/max to our current address which is as good as any */ mp_p->mp_min_p = block_p; mp_p->mp_bounds_p = block_p->mb_bounds_p; } else { /* now copy our tmp structure into our new memory area */ memcpy(mp_p, &mp, sizeof(mpool_t)); /* we setup min/max to our current address which is as good as any */ mp_p->mp_min_p = mp_p; mp_p->mp_bounds_p = (char *)mp_p + SIZE_OF_PAGES(mp_p, page_n); } SET_POINTER(error_p, MPOOL_ERROR_NONE); return mp_p; }
LOCAL void freiburg_get_segment_free(transform_info_ptr tinfo) { struct read_freiburg_storage *local_arg=(struct read_freiburg_storage *)tinfo->methods->local_storage; free_pointer((void **)&local_arg->last_values_buf); }