コード例 #1
0
ファイル: startup.c プロジェクト: tkorhon1/FDS-SMVgit
void copy_args(int *argc, char **aargv, char ***argv_sv){
#ifdef WIN32
  char *filename=NULL;
  char **argv=NULL;
  int filelength=1024,openfile;
  int i;

  if(NewMemory((void **)&argv,(*argc+1)*sizeof(char **))!=0){
    *argv_sv=argv;
    for(i=0;i<*argc;i++){
      argv[i]=aargv[i];
    }
    if(*argc==1){
      if(NewMemory((void **)&filename,(unsigned int)(filelength+1))!=0){
        openfile=0;
        OpenSMVFile(filename,filelength,&openfile);
        if(openfile==1&&ResizeMemory((void **)&filename,strlen(filename)+1)!=0){
          *argc=2;
          argv[1]=filename;
        }
        else{
          FREEMEMORY(filename);
        }
      }
    }
  }
  else{
    *argc=0;
  }
#else
  *argv_sv=aargv;
#endif
}
コード例 #2
0
ファイル: AddressBook.c プロジェクト: X-Band/SegaOS
static long AddressBookSetup( ScreenParams *params )
{
DITLItem		addressItem[kMaxAddressBookEntries];
DITLItem *		aItem;
AddressItemDesc	*addressDesc;
AddressItemDesc *aDesc;
DITLItemList 	*addressItemDitlList;
ControlTable 	*addressItemControlTable;
ControlTable 	*textButtControlTable;
DITLItemList 	*textButtDitlList;
AddressBookRefCon	*addressGlobals;
segaCharRect 	myRect;
short			ypos;
short			xpos;
short			count;
short			iii;
long			patternStart;
PlayerInfo		*theAddress;
char			*theCString;

	DisableDefDialogs();

	addressGlobals = (AddressBookRefCon	*) NewMemory( kTemp, sizeof(AddressBookRefCon) );
	addressDesc = (AddressItemDesc*) NewMemory( kTemp, sizeof(AddressItemDesc) * kMaxAddressBookEntries );
	addressGlobals->disposeAddressDesc = addressDesc;
	
	EraseGDevice ( kScrollA );
	SetBackdropIDAndAuxBackgroundGraphic( kBlackBackground,
コード例 #3
0
ファイル: IOshooter.c プロジェクト: tkorhon1/FDS-SMVgit
int  allocate_shooter(void){
  int mem_points, mem_frames;

  FREEMEMORY(shootpointinfo);
  FREEMEMORY(shoottimeinfo);

  mem_points=max_shooter_points*sizeof(shootpointdata);
  mem_frames=nshooter_frames*sizeof(shoottimedata);

  PRINTF("shooter point memory requirements\n");
  PRINTF("max_shooter_points=%i mem=%i\n",max_shooter_points,mem_points);
  PRINTF("nshooter_frames=%i mem=%i\n",nshooter_frames,mem_frames);

  if(  mem_points<=0||mem_frames<=0||
#ifdef _DEBUG
       mem_points>=2000000000||mem_frames>2000000000||
#endif
    NewMemory((void **)&shootpointinfo,mem_points)==0||
    NewMemory((void **)&shoottimeinfo,mem_frames)==0){
    FREEMEMORY(shootpointinfo);
    FREEMEMORY(shoottimeinfo);
    shooter_active=0;
    PRINTF("shooter point memory allocation failed\n");
    return 1;
  }
  return 0;

}
コード例 #4
0
bool ResizeMemory(void *block, size_t new_size) {
	byte **pp_block = (byte **)block;
	byte *p_block;
	size_t old_size;
	byte *p_newblock;
	bool ok_new;

	ASSERT(NULL != pp_block && 0 != new_size);
	p_block = *pp_block;
	old_size = MEMINFO_GETSIZE(p_block);

	if (old_size > new_size)
		MEMSET(p_block + new_size, GARBAGE_FLAG, old_size - new_size);
	else if (old_size < new_size) {
		ok_new = NewMemory(&p_newblock, new_size);
		if (!ok_new)
			return false;
		else {
			memcpy(p_newblock, p_block, old_size);
			FreeMemory(p_block);
			*pp_block = p_newblock;
			//MEMINFO_UPDATE(p_block, p_newblock, new_size);
			return true;
		}
	}
	else
		return true;
}
コード例 #5
0
int main(void) {
	char str_1[256] = "123456789";
	char str_2[256] = "abcdefg";
	char str_3[256] = "ABCDEFGHIJKLMN";
	char *p_memory_1 = NULL;
	char *p_memory_2 = NULL;
	bool ok_new;

	p_memory_1 = (char *)malloc(64);
	if (NULL == p_memory_1) {
		printf("malloc() failure! [%p]\n", p_memory_1);
	}
	else {
		printf("malloc() success! [%p]\n", p_memory_1);
		memcpy(p_memory_1, str_1, strlen(str_1));
		free(p_memory_1);
	}

	ok_new = NewMemory(&p_memory_2, 64);
	if (false == ok_new) {
		printf("NewMemory() failure! [%d,%p]\n", ok_new, p_memory_2);
	}
	else {
		printf("NewMemory() success! [%d,%p]\n", ok_new, p_memory_2);
		memcpy(p_memory_2, str_1, strlen(str_1));
		ResizeMemory(&p_memory_2, 128);
		memcpy(p_memory_2 + strlen(str_1), str_2, strlen(str_2));
		ResizeMemory(&p_memory_2, 32);
		FreeMemory(p_memory_2);
	}

	return 0;
}
コード例 #6
0
ファイル: renderfile.c プロジェクト: tkorhon1/FDS-SMVgit
unsigned char *readpng(const char *filename,int *width, int *height){

  FILE *file;
  gdImagePtr image;
  unsigned char *dataptr,*dptr;
  int i,j;
  unsigned int intrgb;

  file = fopen(filename, "rb");
  if(file == NULL)return NULL;
  image = gdImageCreateFromPng(file);
  fclose(file);
  *width=gdImageSX(image);
  *height=gdImageSY(image);
  if( NewMemory((void **)&dataptr,(unsigned int)(4*(*width)*(*height)) )==0){
    gdImageDestroy(image);
    return NULL;
  }
  dptr=dataptr;
  for (i = 0; i<*height; i++){
    for(j=0;j<*width;j++){
      intrgb=(unsigned int)gdImageGetPixel(image,j,(unsigned int)(*height-(1+i)));
      *dptr++ = (intrgb>>16)&255;
      *dptr++ = (intrgb>>8)&255;
      *dptr++ = intrgb&255;
      *dptr++ = 0xff;
    }
  }
  gdImageDestroy(image);
  return dataptr;

}
コード例 #7
0
ファイル: scontour2d.c プロジェクト: tkorhon1/FDS-SMVgit
void initcontours(contour **ci_ptr, float **rgbptr, int ncontours,float constval, int idir, float level_min, float level_max, int nlevels){
  int i;

  contour *cont;
  float dval;

  dval = 0.0;

  if(nlevels>1){
    dval = (level_max-level_min)/(float)(nlevels);
  }

  NewMemory((void **)&cont,ncontours*sizeof(contour));
  *ci_ptr=cont;
  for(i=0;i<ncontours;i++){
    contour *ci;
    int j;

    ci = cont+i;
    initcontour(ci,rgbptr,nlevels);
    ci->xyzval=constval;
    ci->idir=idir;
    for(j=0;j<nlevels+1;j++){
      ci->levels[j]=level_min+j*dval;
    }
  }

}
コード例 #8
0
ファイル: event.c プロジェクト: assassinGG/PTP
static int
dbg_str_to_memory(char ***args, int *nargs, List **lst)
{
	int			i;
	int			count;
	memory *	m;

	if (dbg_str_to_int(args, nargs, &count) < 0) {
	}

	*lst = NewList();

	for (i = 0; i < count; i++) {
		m = NewMemory();
		if (dbg_copy_str(args, nargs, &m->addr) < 0 ||
			dbg_copy_str(args, nargs, &m->ascii) < 0 ||
			dbg_str_to_memory_data(args, nargs, &m->data) < 0) {
				DestroyList(*lst, FreeMemory);
				return -1;
		}
		AddToList(*lst, (void *)m);
	}

	return 0;
}
コード例 #9
0
ファイル: CLUTDataAnimation.c プロジェクト: X-Band/SegaOS
Ptr
GetCLUTDataAnimatorProc ( void )
{
long	size;
Ptr		data;
long	srcFunction;

	srcFunction = (*(long *) ((Ptr) CLUTDataAnimatorProc + 2));

	size = (*(long *) ((Ptr) GetCLUTDataAnimatorProc + 2)) - srcFunction;
	data = NewMemory ( kTemp,  size );
	ASSERT_MESG( data, "Cannot allocate memory for table animator proc" );
	
	if ( data )
		{
#ifdef SIMULATOR
		*(short *)data = kJmpLongOpcode;
		*(long *)((long)data+2) = (long) CLUTDataAnimatorProc;
#else
		CheckCodeForJTRefs((void *)CLUTDataAnimatorProc, size);
		BlockMove ( (Ptr) srcFunction, data, size );
#endif
		}
	
	return data;
}
コード例 #10
0
ファイル: getdatabounds.c プロジェクト: tkorhon1/FDS-SMVgit
void adjustpartbounds(const float *pdata, int particle_type, int droplet_type, const unsigned char *isprink, 
                      int local_skip, int ndataloop, int setpmin, float *pmin, int setpmax, float *pmax)
{
    int nsmall, nbig, *buckets=NULL, n, level, total, alpha05;
    float dp, pmin2, pmax2;
    int ndata;

    if(setpmin==PERCENTILE_MIN||setpmax==PERCENTILE_MAX){
      dp = (*pmax - *pmin)/NBUCKETS;
      nsmall=0;
      nbig=NBUCKETS;
      if(NewMemory((void **)&buckets,NBUCKETS*sizeof(int))==0){
        fprintf(stderr,"*** Error: Unable to allocate memory in getdatabounds\n");
        return;
      }

      for (n=0;n<NBUCKETS;n++){
        buckets[n]=0;
      }
      ndata=0;
      for (n=local_skip;n<ndataloop;n++){
        level=0;
        if(isprink[n]==1){
          if(droplet_type==0)continue;
        }
        else{
          if(particle_type==0)continue;
        }
        if(dp!=0.0f)level = CLAMP((int)((pdata[n] - *pmin)/dp),0,NBUCKETS-1);
        ndata++;
        buckets[level]++;
      }
      alpha05 = (int)(percentile_level*ndata);
      total = 0;
      for (n=0;n<NBUCKETS;n++){
        total += buckets[n];
        if(total>alpha05){
          nsmall=n;
          break;
        }
      }
      total = 0;
      for (n=NBUCKETS;n>0;n--){
        total += buckets[n-1];
        if(total>alpha05){
          nbig=n;
          break;
        }
      }
      pmin2 = *pmin + (nsmall-1)*dp;
      pmax2 = *pmin + (nbig+1)*dp;
      if(setpmin==PERCENTILE_MIN)*pmin = pmin2; 
      if(setpmax==PERCENTILE_MAX)*pmax = pmax2;
      FreeMemory(buckets);
    }
    if(axislabels_smooth==1){
      smoothlabel(pmin,pmax,nrgb);
    }
}
コード例 #11
0
ファイル: SmartSpace.cpp プロジェクト: wangjian790/code
	void SmartSpace::NewMemoryOnWrite(void)
	{
		if (sharedtimes == nullptr)
		{
			NewMemory();
			sharedtimes = new integer;
			*sharedtimes = 1;
		}
		else
			if ((*sharedtimes) > 1)
			{
				NewMemory();
				(*sharedtimes)--;
				sharedtimes = new integer;
				*sharedtimes = 1;
			}
	};
コード例 #12
0
ファイル: startup.c プロジェクト: tkorhon1/FDS-SMVgit
void init_texturedir(void){
  char *texture_buffer;
  size_t texture_len;

  if(texturedir!=NULL)return;

  texture_buffer=getenv("texturedir");
  if(texture_buffer!=NULL){
    texture_len=strlen(texture_buffer);
    NewMemory((void **)&texturedir,texture_len+1);
    strcpy(texturedir,texture_buffer);
  }
  if(texturedir==NULL&&smokeview_bindir!=NULL){
    texture_len=strlen(smokeview_bindir)+strlen("textures");
    NewMemory((void **)&texturedir,texture_len+2);
    strcpy(texturedir,smokeview_bindir);
    strcat(texturedir,"textures");
  }
}
コード例 #13
0
ファイル: SmartSpace.cpp プロジェクト: wangjian790/code
	void SmartSpace::CopyOnWrite(void)
	{
		if (sharedtimes == nullptr)
		{
			NewMemory();
			sharedtimes = new integer;
			*sharedtimes = 1;
		}
		else
			if ((*sharedtimes) > 1)
			{
				double *ptr = Space;
				NewMemory();
				(*sharedtimes)--;
				sharedtimes = new integer;
				*sharedtimes = 1;

				integer N = length, inc = 1;
				// Space <- ptr, details: http://www.netlib.org/lapack/explore-html/da/d6c/dcopy_8f.html
				dcopy_(&N, ptr, &inc, Space, &inc);
			}
	};
コード例 #14
0
ファイル: CNVslice.c プロジェクト: tkorhon1/FDS-SMVgit
void mt_update_slice_hist(void) {
    pthread_t *thread_ids;
    int i;

    NewMemory((void **)&thread_ids,mt_nthreads*sizeof(pthread_t));

    for(i=0; i<mt_nthreads; i++) {
        pthread_create(&thread_ids[i],NULL,MT_update_slice_hist,NULL);
    }

    for(i=0; i<mt_nthreads; i++) {
        pthread_join(thread_ids[i],NULL);
    }
    FREEMEMORY(thread_ids);
}
コード例 #15
0
ファイル: scontour2d.c プロジェクト: tkorhon1/FDS-SMVgit
void initcontour(contour *ci, float **rgbptr, int nlevels){
  int n;

  ci->nlevels=nlevels;
  ci->rgbptr=rgbptr;
  NewMemory((void **)&ci->levels,(nlevels+1)*sizeof(float));
  NewMemory((void **)&ci->areas,nlevels*sizeof(float));
  NewMemory((void **)&ci->nnodes,nlevels*sizeof(int));
  NewMemory((void **)&ci->npolys,nlevels*sizeof(int));
  NewMemory((void **)&ci->nlines,nlevels*sizeof(int));

  NewMemory((void **)&ci->polysize,nlevels*sizeof(int *));
  NewMemory((void **)&ci->xnode,nlevels*sizeof(float *));
  NewMemory((void **)&ci->ynode,nlevels*sizeof(float *));
  NewMemory((void **)&ci->xlines,nlevels*sizeof(float *));
  NewMemory((void **)&ci->ylines,nlevels*sizeof(float *));
  for(n=0;n<nlevels;n++){
    ci->polysize[n]=NULL;
    ci->xnode[n]=NULL;
    ci->ynode[n]=NULL;
    ci->xlines[n]=NULL;
    ci->ylines[n]=NULL;
  }
}
コード例 #16
0
ファイル: threader.c プロジェクト: tkorhon1/FDS-SMVgit
void mt_compress_all(void){
  int i;
  pthread_t *thread_ids;
  int *index;

  NewMemory((void **)&thread_ids,mt_nthreads*sizeof(pthread_t));
  NewMemory((void **)&index,mt_nthreads*sizeof(int));
  NewMemory((void **)&threadinfo,mt_nthreads*sizeof(threaddata));

  for(i=0;i<mt_nthreads;i++){
    index[i]=i;
    pthread_create(&thread_ids[i],NULL,compress_all,&index[i]);
    threadinfo[i].stat=-1;
  }

  for(i=0;i<mt_nthreads;i++){
    pthread_join(thread_ids[i],NULL);
  }

  print_summary();
  FREEMEMORY(thread_ids);
  FREEMEMORY(index);
  FREEMEMORY(threadinfo);
}
コード例 #17
0
ファイル: ChooseTaunt.c プロジェクト: X-Band/SegaOS
static long ChooseTauntSetup( ScreenParams *params )
{
ChooseTauntGlobals	*choose;
KeyboardEntryLayout *keyLayout;
segaCharRect		tbRect;
Point				boxLocation;
Rect				boxRect;

	DisableDefDialogs();

	choose = (ChooseTauntGlobals *)NewMemory( kTemp, sizeof(ChooseTauntGlobals) );
	
	EraseGDevice ( kScrollA );
	SetBackdropID ( kBlackBackground, true, 0 );

	GetScreenLayoutPoint( kChooseTauntScreen, kTauntEntryBoxLocation, &boxLocation );
	choose->typingBox = DrawDBGraphicAt( 0, kTauntEntryField, boxLocation.h>>3, 
		boxLocation.v>>3, kScrollB );

	SetCurrentDevice( kScrollA );
	SetCurFont( kXBandHeavy );
	SetFontColors( 0, 11, 10, 0 );
	choose->titlePatterns = DrawScreenLayoutString( kChooseTauntScreen, kTauntHeadlineString );

	SetCurFont( kXBandLight9Font );
	SetFontColors( 0, 9, 8, 0 );
	choose->descriptionPatterns = BoxScreenLayoutString( kChooseTauntScreen, kTauntDescriptionString,
		kTauntDescriptionRect, kJustLeft );	

	GetScreenLayoutCharRect( kChooseTauntScreen, kTauntJizzleRect, &tbRect );
	choose->tbRef = DrawTextBox( &tbRect, kGreenColor, kScrollA );
	StartTextBoxAnimation( choose->tbRef, 10 );
	
	keyLayout = SetupKeyboardEntryLayout( kChooseTauntKeyboardEntry );
	choose->keyRef = InitKeyboardEntry( keyLayout, 0 );
	choose->keyLayout = keyLayout;
	SetKeyboardEntryMeasureProc( choose->keyRef, TauntMeasureProc );
	
	/* Place the existing taunt in the entry field */
	{
		char *existingTaunt;
		
		existingTaunt = (char *)GetPersonificationPart( GetCurrentLocalUser()->userID, kPersonificationTauntText );
		StuffCurrentKeyboardField( choose->keyRef, existingTaunt );
	}

	return (long) choose;
}
コード例 #18
0
ファイル: CNVslice.c プロジェクト: tkorhon1/FDS-SMVgit
void update_slice_hist(void) {
    int i;

    for(i=0; i<nsliceinfo; i++) {
        slice *slicei;
        int unit1;
        FILE_SIZE lenfile;
        int error1;
        float slicetime1, *sliceframe;
        int sliceframesize;
        int is1, is2, js1, js2, ks1, ks2;
        int testslice;

        slicei = sliceinfo + i;

        LOCK_SLICE_BOUND;
        if(slicei->inuse_getbounds==1) {
            UNLOCK_SLICE_BOUND;
            continue;
        }
        slicei->inuse_getbounds=1;
        UNLOCK_SLICE_BOUND;
        PRINTF("  Examining %s\n",slicei->file);

        lenfile=strlen(slicei->file);

        LOCK_COMPRESS;
        FORTget_file_unit(&unit1,&slicei->unit_start);
        FORTopenslice(slicei->file,&unit1,&is1,&is2,&js1,&js2,&ks1,&ks2,&error1,lenfile);
        UNLOCK_COMPRESS;

        sliceframesize=(is2+1-is1)*(js2+1-js1)*(ks2+1-ks1);
        NewMemory((void **)&sliceframe,sliceframesize*sizeof(float));
        init_histogram(slicei->histogram);
        testslice=0;
        while(error1==0) {
            FORTgetsliceframe(&unit1, &is1, &is2, &js1, &js2, &ks1, &ks2, &slicetime1, sliceframe, &testslice,&error1);
            update_histogram(sliceframe,sliceframesize,slicei->histogram);
        }
        FREEMEMORY(sliceframe);

        LOCK_COMPRESS;
        FORTclosefortranfile(&unit1);
        UNLOCK_COMPRESS;
    }
}
コード例 #19
0
ファイル: skybox.c プロジェクト: tkorhon1/FDS-SMVgit
void loadskytexture(char *filebase, texturedata *texti){
  char *filebuffer=NULL;
  int texwid, texht;
  int errorcode;
  unsigned char *floortex;

  trim(filebase);
  texti->name=0;
  texti->loaded=0;
  if(strcmp(filebase,"NULL")==0)return;
  NewMemory((void **)&filebuffer,strlen(filebase)+1);
  STRCPY(filebuffer,filebase);

  glGenTextures(1,&texti->name);
  glBindTexture(GL_TEXTURE_2D,texti->name);
  floortex=readpicture(filebuffer,&texwid,&texht,0);
  if(floortex==NULL){
    FREEMEMORY(filebuffer);
    return;
  }
  errorcode=gluBuild2DMipmaps(GL_TEXTURE_2D,4, texwid, texht, GL_RGBA, GL_UNSIGNED_BYTE, floortex);
  if(errorcode!=0){
    FREEMEMORY(floortex);
    FREEMEMORY(filebuffer);
    return;
  }
  FREEMEMORY(floortex);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  #ifdef pp_GPU
  if(gpuactive==1){
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  }
  else{
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  }
  #else
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  #endif
  texti->file=filebuffer;
  texti->loaded=1;
  return;
}
コード例 #20
0
ファイル: ChoosePassword.c プロジェクト: X-Band/SegaOS
static long ChoosePasswordSetup( ScreenParams *params )
{
ChoosePasswordGlobals	*choose;
Point					boxLocation;
segaCharRect			tbRect;

	choose = (ChoosePasswordGlobals *)NewMemory( kTemp, sizeof(ChoosePasswordGlobals));
	
	choose->addPWChar					= (ChoosePasswordProc) _AddPWChar;
	choose->doubleCheckAndSetPassword	= (ChoosePasswordProc) _DoubleCheckAndSetPassword;
	choose->resetEnteredPassword		= (ChoosePasswordProc) _ResetEnteredPassword;
	choose->setupPWChar					= (ChoosePasswordProc) _SetupPWChar;
		
	choose->charSprite = 0;		// zero allocations
	choose->textState = 0;
	
	EraseGDevice ( kScrollA );
	SetBackdropID ( kBlackBackground, true, 0 );
	SetCurrentDevice( kScrollA );
	
	GetScreenLayoutPoint( kChoosePasswordScreen, kLayoutBoxPoint, &boxLocation );
	choose->boxGraphic = DrawDBGraphicAt( 0, kPasswordBox, boxLocation.h>>3, 
		boxLocation.v>>3, kScrollA );

	SetCurrentDevice( kScrollA );
	SetCurFont( kXBandHeavy );
	SetFontColors( 0, 11, 10, 0 );
	choose->titlePatterns = DrawScreenLayoutString( kChoosePasswordScreen, kLayoutTitleString );

	SetCurFont( kXBandLight9Font );
	SetFontColors( 0, 9, 8, 0 );
	choose->descriptionPatterns = BoxScreenLayoutString( kChoosePasswordScreen, kLayoutDescriptionString,
		kLayoutDescriptionRect, kJustLeft );	

	SetFontColors( 0, kDarkPurpleColor, kPurpleColor, 0 );
	choose->donePatterns = DrawScreenLayoutString( kChoosePasswordScreen, kLayoutDoneString );

	GetScreenLayoutCharRect( kChoosePasswordScreen, kLayoutJizzleRect, &tbRect );
	choose->jizzleRef = DrawTextBox( &tbRect, kGreenColor, kScrollA );
	StartTextBoxAnimation( choose->jizzleRef, 10 );
	
	SetupPWChar( choose );

	return (long) choose;
}
コード例 #21
0
ファイル: renderfile.c プロジェクト: tkorhon1/FDS-SMVgit
unsigned char *readjpeg(const char *filename,int *width, int *height, int skip_local){

  FILE *file;
  gdImagePtr image;
  unsigned char *dataptr,*dptr;
  int i,j;
  unsigned int intrgb;
  int WIDTH, HEIGHT;
  int NEWWIDTH, NEWHEIGHT;
  int jump;

  file = fopen(filename, "rb");
  if(file == NULL)return NULL;
  image = gdImageCreateFromJpeg(file);
  fclose(file);
  if(image==NULL)return NULL;
  WIDTH=gdImageSX(image);
  HEIGHT=gdImageSY(image);
  if(skip_local<0)skip_local=0;
  jump = skip_local + 1;
  NEWWIDTH=WIDTH/jump;
  if(WIDTH%jump!=0)NEWWIDTH++;
  NEWHEIGHT=HEIGHT/jump;
  if(HEIGHT%jump!=0)NEWHEIGHT++;
  *width=NEWWIDTH;
  *height=NEWHEIGHT;
  if( NewMemory((void **)&dataptr,(unsigned int)(4*NEWWIDTH*NEWHEIGHT) )==0){
    gdImageDestroy(image);
    return NULL;
  }
  dptr=dataptr;
  for (i = 0; i<HEIGHT; i+=jump){
    for(j=0;j<WIDTH;j+=jump){
      intrgb=(unsigned int)gdImageGetPixel(image,j,(unsigned int)(HEIGHT-(1+i)));
      *dptr++ = (intrgb>>16)&255;
      *dptr++ = (intrgb>>8)&255;
      *dptr++ = intrgb&255;
      *dptr++=0xff;
    }
  }
  gdImageDestroy(image);
  return dataptr;

}
コード例 #22
0
ファイル: renderfile.c プロジェクト: tkorhon1/FDS-SMVgit
GLubyte *getscreenbuffer(void){

  GLubyte *OpenGLimage=NULL;

  int x=0, y=0;

  NewMemory((void **)&OpenGLimage,screenWidth * screenHeight * sizeof(GLubyte) * 3);

  if(OpenGLimage==NULL)return NULL;

  glPixelStorei(GL_PACK_ALIGNMENT, 1);

  /* get the image from the OpenGL frame buffer */

  glReadPixels(x, y, screenWidth, screenHeight, GL_RGB, GL_UNSIGNED_BYTE, OpenGLimage);

  return OpenGLimage;

}
コード例 #23
0
ファイル: main.c プロジェクト: tkorhon1/FDS-SMVgit
void makesvd(char *in_dir, char *smvfile){
  char *file_out=NULL,*svd;

  if(smvfile==NULL)return;
  svd=strrchr(smvfile,'.');
  if(svd==NULL)return;

  NewMemory((void **)&file_out,(svd-smvfile)+4+1);
  strcat(file_out,smvfile);
  strcpy(svd,".svd");

  if(in_dir==NULL){
    filecopy(".",smvfile,file_out);
  }
  else{
    filecopy(in_dir,smvfile,file_out);
  }

}
コード例 #24
0
ファイル: ChoosePassword.c プロジェクト: X-Band/SegaOS
Ptr GetChoosePasswordDispatchPtr( void )
{
long	size;
Ptr		data;
long	srcFunction;

	srcFunction = (*(long *) ((Ptr) ChoosePasswordDispatch + 2));
	size = (*(long *) ((Ptr) GetChoosePasswordDispatchPtr + 2)) - srcFunction;
	data = NewMemory ( kTemp, size );
	ASSERT_MESG( data, "Cannot allocate memory for choose icon proc" );
	
	if ( data )
		{
#ifdef SIMULATOR
		*(short *)data = kJmpLongOpcode;
		*(long *)((long)data+2) = (long) ChoosePasswordDispatch;
#else
		CheckCodeForJTRefs((void *)ChoosePasswordDispatch, size);
		BlockMove ( (Ptr) srcFunction, data, size );
#endif
		}
	
	return data;
}
コード例 #25
0
ファイル: IOhrr.c プロジェクト: tkorhon1/FDS-SMVgit
void readhrr(int flag, int *errorcode){
  FILE *HRRFILE;
  int ntimeshrr, nfirst;
  char buffer[LENBUFFER];
  float *hrrtime, *hrrval;
  int display=0;
  int ntimes_saved;

  *errorcode=0;
  if(hrrinfo!=NULL){
    display = hrrinfo->display;
    FREEMEMORY(hrrinfo->times_csv);
    FREEMEMORY(hrrinfo->times);
    FREEMEMORY(hrrinfo->hrrval_csv);
    FREEMEMORY(hrrinfo->hrrval);
    FREEMEMORY(hrrinfo->timeslist);
  }
  FREEMEMORY(hrrinfo);
  if(flag==UNLOAD)return;

  NewMemory((void **)&hrrinfo,sizeof(hrrdata));
  hrrinfo->file=hrr_csv_filename;
  hrrinfo->times_csv=NULL;
  hrrinfo->times=NULL;
  hrrinfo->timeslist=NULL;
  hrrinfo->hrrval_csv=NULL;
  hrrinfo->hrrval=NULL;
  hrrinfo->ntimes_csv=0;
  hrrinfo->loaded=1;
  hrrinfo->display=display;
  hrrinfo->itime=0;

  HRRFILE=fopen(hrrinfo->file,"r");
  if(HRRFILE==NULL){
    readhrr(UNLOAD,errorcode);
    return;
  }


// size data

  ntimeshrr=0;
  nfirst=-1;
  while(!feof(HRRFILE)){
    if(fgets(buffer,LENBUFFER,HRRFILE)==NULL)break;
    if(nfirst==-1&&strstr(buffer,".")!=NULL)nfirst=ntimeshrr;
    ntimeshrr++;
  }
  ntimes_saved=ntimeshrr;
  ntimeshrr-=nfirst;

  rewind(HRRFILE);
  NewMemory((void **)&hrrinfo->times_csv,ntimeshrr*sizeof(float));
  NewMemory((void **)&hrrinfo->hrrval_csv,ntimeshrr*sizeof(float));

// read data
  
  hrrtime=hrrinfo->times_csv;
  hrrval=hrrinfo->hrrval_csv;
  ntimeshrr=0;

// read no more than the number of lines found during first pass

  while(ntimeshrr<ntimes_saved&&!feof(HRRFILE)){
    if(fgets(buffer,LENBUFFER,HRRFILE)==NULL)break;
    if(ntimeshrr<nfirst){
      ntimeshrr++;
      continue;
    }
    stripcommas(buffer);
    sscanf(buffer,"%f %f",hrrtime,hrrval);
    hrrtime++;
    hrrval++;
    ntimeshrr++;
  }
  hrrinfo->ntimes_csv=ntimeshrr-nfirst;
  fclose(HRRFILE);
}
コード例 #26
0
ファイル: CNVslice.c プロジェクト: tkorhon1/FDS-SMVgit
int convert_slice(slice *slicei, int *thread_index) {

    char slicefile_svz[1024], slicesizefile_svz[1024];
    int fileversion, one, zero;
    char *slice_file;
    int version_local;
    char filetype[1024];
    char *shortlabel, *unit;
    char units[256];
    int ijkbar[6];
    uLong framesize;
    float *sliceframe_data=NULL;
    unsigned char *sliceframe_compressed=NULL, *sliceframe_uncompressed=NULL;
    unsigned char *sliceframe_compressed_rle=NULL, *sliceframe_uncompressed_rle=NULL;
    char cval[256];
    int sizebefore, sizeafter;
    int returncode;
    float minmax[2];
    float time_local;
    LINT data_loc;
    int percent_done;
    int percent_next=10;
    float valmin, valmax, denom;
    int chop_min, chop_max;
    uLongf ncompressed_zlib;
    int ncompressed_save;
#ifndef pp_THREAD
    int count=0;
#endif
    int ncol, nrow, idir;
    float time_max;
    int itime;
    LINT file_loc;

    FILE *SLICEFILE;
    FILE *slicestream,*slicesizestream;

#ifdef pp_THREAD
    if(GLOBcleanfiles==0) {
        int fileindex;

        fileindex = slicei + 1 - sliceinfo;
        sprintf(threadinfo[*thread_index].label,"sf %i",fileindex);
    }
#endif

    slice_file=slicei->file;
    version_local=slicei->version;

    fileversion = 1;
    one = 1;
    zero=0;

    // check if slice file is accessible

    strcpy(filetype,"");
    shortlabel=slicei->label.shortlabel;
    if(strlen(shortlabel)>0)strcat(filetype,shortlabel);
    trim(filetype);

    if(getfileinfo(slice_file,NULL,NULL)!=0) {
        fprintf(stderr,"*** Warning: The file %s does not exist\n",slice_file);
        return 0;
    }

    SLICEFILE=fopen(slice_file,"rb");
    if(SLICEFILE==NULL) {
        fprintf(stderr,"*** Warning: The file %s could not be opened\n",slice_file);
        return 0;
    }

    // set up slice compressed file

    if(GLOBdestdir!=NULL) {
        strcpy(slicefile_svz,GLOBdestdir);
        strcat(slicefile_svz,slicei->filebase);
    }
    else {
        strcpy(slicefile_svz,slicei->file);
    }
    {

        char *ext;
        int lensvz;

        lensvz = strlen(slicefile_svz);

        if(lensvz>4) {
            ext = slicefile_svz + lensvz - 4;
            if(strcmp(ext,".rle")==0) {
                slicefile_svz[lensvz-4]=0;
            }
            strcat(slicefile_svz,".svz");
        }
    }

    if(GLOBdestdir!=NULL) {
        strcpy(slicesizefile_svz,GLOBdestdir);
        strcat(slicesizefile_svz,slicei->filebase);
    }
    else {
        strcpy(slicesizefile_svz,slicei->file);
    }
    {

        char *ext;
        int lensvz;

        lensvz = strlen(slicesizefile_svz);

        if(lensvz>4) {
            ext = slicesizefile_svz + lensvz - 4;
            if(strcmp(ext,".rle")==0) {
                slicesizefile_svz[lensvz-4]=0;
            }
            strcat(slicesizefile_svz,".sz");
        }
    }

    if(GLOBcleanfiles==1) {
        slicestream=fopen(slicefile_svz,"rb");
        if(slicestream!=NULL) {
            fclose(slicestream);
            PRINTF("  Removing %s\n",slicefile_svz);
            UNLINK(slicefile_svz);
            LOCK_COMPRESS;
            GLOBfilesremoved++;
            UNLOCK_COMPRESS;
        }
        slicesizestream=fopen(slicesizefile_svz,"rb");
        if(slicesizestream!=NULL) {
            fclose(slicesizestream);
            PRINTF("  Removing %s\n",slicesizefile_svz);
            UNLINK(slicesizefile_svz);
            LOCK_COMPRESS;
            GLOBfilesremoved++;
            UNLOCK_COMPRESS;
        }
        return 0;
    }

    if(GLOBoverwrite_slice==0) {
        slicestream=fopen(slicefile_svz,"rb");
        if(slicestream!=NULL) {
            fclose(slicestream);
            fprintf(stderr,"*** Warning:  %s exists.\n",slicefile_svz);
            fprintf(stderr,"     Use the -f option to overwrite smokezip compressed files\n");
            return 0;
        }
    }

    slicestream=fopen(slicefile_svz,"wb");
    slicesizestream=fopen(slicesizefile_svz,"w");
    if(slicestream==NULL||slicesizestream==NULL) {
        if(slicestream==NULL) {
            fprintf(stderr,"*** Warning: The file %s could not be opened for writing\n",slicefile_svz);
        }
        if(slicesizestream==NULL) {
            fprintf(stderr,"  %s could not be opened for writing\n",slicesizefile_svz);
        }
        if(slicestream!=NULL)fclose(slicestream);
        if(slicesizestream!=NULL)fclose(slicesizestream);
        fclose(SLICEFILE);
        return 0;
    }

    // read and write slice header

    strcpy(units,"");
    unit=slicei->label.unit;
    if(strlen(unit)>0)strcat(units,unit);
    trim(units);
    sprintf(cval,"%f",slicei->valmin);
    trimzeros(cval);
#ifndef pp_THREAD
    if(GLOBcleanfiles==0) {
        PRINTF("Compressing %s (%s)\n",slice_file,filetype);
        PRINTF("  using min=%s %s",cval,units);
    }
#endif
    sprintf(cval,"%f",slicei->valmax);
    trimzeros(cval);
#ifndef pp_THREAD
    if(GLOBcleanfiles==0) {
        PRINTF(" max=%s %s\n",cval,units);
        PRINTF(" ");
    }
#endif
    valmin=slicei->valmin;
    valmax=slicei->valmax;
    denom = valmax-valmin;
    if(denom==0.0)denom=1.0;

    chop_min=0;
    chop_max=255;
    if(GLOBno_chop==0) {
        if(slicei->setchopvalmax==1) {
            chop_max = 255*(slicei->chopvalmax-valmin)/denom;
            if(chop_max<0)chop_max=0;
            if(chop_max>255)chop_max=255;
        }
        if(slicei->setchopvalmin==1) {
            chop_min = 255*(slicei->chopvalmin-valmin)/denom;
            if(chop_min<0)chop_min=0;
            if(chop_min>255)chop_min=255;
        }
    }


    fwrite(&one,4,1,slicestream);           // write out a 1 to determine "endianness" when file is read in later
    fwrite(&zero,4,1,slicestream);          // write out a zero now, then a one just before file is closed
    fwrite(&fileversion,4,1,slicestream);   // write out compressed fileversion in case file format changes later
    fwrite(&version_local,4,1,slicestream);       // fds slice file version
    sizeafter=16;

    //*** SLICE FILE FORMATS

    //*** FDS FORMAT (FORTRAN - each FORTRAN record has a 4 byte header and a 4 byte trailer surrounding the data)

    // 30 byte long label
    // 30 byte short label
    // 30 byte unit
    // i1,i2,j1,j2,k1,k2

    // for each time step:

    // time, compressed frame size
    // qq(1,nbuffer)              where nbuffer = (i2+1-i1)*(j2+1-j1)*(k2+1-k1)



    //*** ZLIB format (C - no extra bytes surrounding data)

    //*** header
    // endian
    // completion (0/1)
    // fileversion (compressed format)
    // version_local  (slicef version)
    // global min max (used to perform conversion)
    // i1,i2,j1,j2,k1,k2


    //*** frame
    // time, compressed frame size                        for each frame
    // compressed buffer


    //*** RLE format (FORTRAN)

    //*** header
    // endian
    // fileversion, slice version
    // global min max (used to perform conversion)
    // i1,i2,j1,j2,k1,k2


    //*** frame
    // time
    // compressed frame size                        for each frame
    // compressed buffer

    {
        int skip;

        skip = 3*(4+30+4);  // skip over 3 records each containing a 30 byte FORTRAN character string
        returncode=FSEEK(SLICEFILE,skip,SEEK_CUR);
        sizebefore=skip;
    }

    FORTSLICEREAD(ijkbar,6);
    sizebefore+=8+6*4;

    framesize =  (ijkbar[1]+1-ijkbar[0]);
    framesize *= (ijkbar[3]+1-ijkbar[2]);
    framesize *= (ijkbar[5]+1-ijkbar[4]);

    minmax[0]=slicei->valmin;
    minmax[1]=slicei->valmax;
    fwrite(minmax,4,2,slicestream);    // min max vals
    fwrite(ijkbar,4,6,slicestream);
    sizeafter+=(8+24);


    ncompressed_save=1.02*framesize+600;
    if(NewMemory((void **)&sliceframe_data,ncompressed_save*sizeof(float))==0)goto wrapup;
    if(NewMemory((void **)&sliceframe_compressed,ncompressed_save*sizeof(unsigned char))==0)goto wrapup;
    if(NewMemory((void **)&sliceframe_uncompressed,ncompressed_save*sizeof(unsigned char))==0)goto wrapup;

    fprintf(slicesizestream,"%i %i %i %i %i %i\n",ijkbar[0],ijkbar[1],ijkbar[2],ijkbar[3],ijkbar[4],ijkbar[5]);
    fprintf(slicesizestream,"%f %f\n",minmax[0],minmax[1]);

    idir=0;
    if(ijkbar[0]==ijkbar[1]) {
        idir=1;
        ncol = ijkbar[3] + 1 - ijkbar[2];
        nrow = ijkbar[5] + 1 - ijkbar[4];
    }
    else if(ijkbar[2]==ijkbar[3]) {
        idir=2;
        ncol = ijkbar[1] + 1 - ijkbar[0];
        nrow = ijkbar[5] + 1 - ijkbar[4];
    }
    else if(ijkbar[4]==ijkbar[5]) {
        idir=3;
        ncol = ijkbar[1] + 1 - ijkbar[0];
        nrow = ijkbar[3] + 1 - ijkbar[2];
    }
    if(idir==0) {
        idir=1;
        ncol = ijkbar[3] + 1 - ijkbar[2];
        nrow = ijkbar[5] + 1 - ijkbar[4];
    }


    {
        int ni, nj, nk;

        ni = ijkbar[1]+1-ijkbar[0];
        nj = ijkbar[3]+1-ijkbar[2];
        nk = ijkbar[5]+1-ijkbar[4];

        time_max=-1000000.0;
        itime=-1;
        for(;;) {
            int i;

            FORTSLICEREAD(&time_local,1);
            sizebefore+=12;
            if(returncode==0)break;
            FORTSLICEREAD(sliceframe_data,framesize);    //---------------
            if(returncode==0)break;

            sizebefore+=(8+framesize*4);
            if(time_local<time_max)continue;
            time_max=time_local;

#ifndef pp_THREAD
            count++;
#endif

            data_loc=FTELL(SLICEFILE);
            percent_done=100.0*(float)data_loc/(float)slicei->filesize;
#ifdef pp_THREAD
            threadinfo[*thread_index].stat=percent_done;
            if(percent_done>percent_next) {
                LOCK_PRINT;
                print_thread_stats();
                UNLOCK_PRINT;
                percent_next+=10;
            }
#else
            if(percent_done>percent_next) {
                PRINTF(" %i%s",percent_next,GLOBpp);
                FFLUSH();
                percent_next+=10;
            }
#endif
            for(i=0; i<framesize; i++) {
                int ival;
                int icol, jrow, index2;
                int ii,jj,kk;

                // val_in(i,j,k) = i + j*ni + k*ni*nj

                if(framesize<=ncol*nrow) { // only one slice plane

                    // i = jrow*ncol + icol;

                    icol = i%ncol;
                    jrow = i/ncol;

                    index2 = icol*nrow + jrow;
                }
                else {
                    ii = i%ni;
                    jj = (i/ni)%nj;
                    kk = i/(ni*nj);

                    index2 = ii*nj*nk + jj*nk + kk;
                }

                {
                    float val;

                    val = sliceframe_data[i];
                    if(val<valmin) {
                        ival=0;
                    }
                    else if(val>valmax) {
                        ival=255;
                    }
                    else {
                        ival = 1 + 253*(val-valmin)/denom;
                    }
                    if(ival<chop_min)ival=0;
                    if(ival>chop_max)ival=255;
                    sliceframe_uncompressed[index2] = ival;
                }
            }
            itime++;
            if(itime%GLOBslicezipstep!=0)continue;

            //int compress (Bytef *dest,   uLongf *destLen, const Bytef *source, uLong sourceLen);
            ncompressed_zlib=ncompressed_save;
            returncode=compress(sliceframe_compressed,&ncompressed_zlib,sliceframe_uncompressed,framesize);

            file_loc=FTELL(slicestream);
            fwrite(&time_local,4,1,slicestream);
            fwrite(&ncompressed_zlib,4,1,slicestream);
            fwrite(sliceframe_compressed,1,ncompressed_zlib,slicestream);
            sizeafter+=(8+ncompressed_zlib);
            fprintf(slicesizestream,"%f %i, %li\n",time_local,(int)ncompressed_zlib,(long)file_loc);
        }
        if(returncode!=0) {
            fprintf(stderr,"*** Error: compress returncode=%i\n",returncode);
        }
    }

wrapup:
#ifndef pp_THREAD
    PRINTF(" 100%s completed\n",GLOBpp);
#endif
    FREEMEMORY(sliceframe_data);
    FREEMEMORY(sliceframe_compressed);
    FREEMEMORY(sliceframe_uncompressed);
    FREEMEMORY(sliceframe_compressed_rle);
    FREEMEMORY(sliceframe_uncompressed_rle);

    fclose(SLICEFILE);
    FSEEK(slicestream,4,SEEK_SET);
    fwrite(&one,4,1,slicestream);  // write completion code
    fclose(slicestream);
    fclose(slicesizestream);

    {
        char before_label[256],after_label[256];

        getfilesizelabel(sizebefore,before_label);
        getfilesizelabel(sizeafter,after_label);
#ifdef pp_THREAD
        slicei->compressed=1;
        sprintf(slicei->summary,"compressed from %s to %s (%4.1f%s reduction)",before_label,after_label,(float)sizebefore/(float)sizeafter,GLOBx);
        threadinfo[*thread_index].stat=-1;
#else
        PRINTF("  records=%i, ",count);
        PRINTF("Sizes: original=%s, ",before_label);
        PRINTF("compressed=%s (%4.1f%s reduction)\n\n",after_label,(float)sizebefore/(float)sizeafter,GLOBx);
#endif
    }

    return 1;
}
コード例 #27
0
ファイル: CNVslice.c プロジェクト: tkorhon1/FDS-SMVgit
int convert_volslice(slice *slicei, int *thread_index) {
    char slicefile_svz[1024];
    char *slice_file;
    char filetype[1024];
    char *shortlabel;
    int ijkbar[6];
    uLong framesize;
    float *sliceframe_data=NULL;
    int sizebefore, sizeafter;
    int returncode;
    LINT data_loc;
    int percent_done;
    int percent_next=10;
#ifndef pp_THREAD
    int count=0;
#endif
    FILE *SLICEFILE;
    FILE *slicestream;

#ifdef pp_THREAD
    if(GLOBcleanfiles==0) {
        int fileindex;

        fileindex = slicei + 1 - sliceinfo;
        sprintf(threadinfo[*thread_index].label,"vsf %i",fileindex);
    }
#endif

    slice_file=slicei->file;

    // check if slice file is accessible

    strcpy(filetype,"");
    shortlabel=slicei->label.shortlabel;
    if(strlen(shortlabel)>0)strcat(filetype,shortlabel);
    trim(filetype);

    if(getfileinfo(slice_file,NULL,NULL)!=0) {
        fprintf(stderr,"*** Warning: The file %s does not exist\n",slice_file);
        return 0;
    }

    SLICEFILE=fopen(slice_file,"rb");
    if(SLICEFILE==NULL) {
        fprintf(stderr,"*** Warning: The file %s could not be opened\n",slice_file);
        return 0;
    }

    // set up slice compressed file

    if(GLOBdestdir!=NULL) {
        strcpy(slicefile_svz,GLOBdestdir);
        strcat(slicefile_svz,slicei->filebase);
    }
    else {
        strcpy(slicefile_svz,slicei->file);
    }

    if(strlen(slicefile_svz)>4)strcat(slicefile_svz,".svv");

    if(GLOBcleanfiles==1) {
        slicestream=fopen(slicefile_svz,"rb");
        if(slicestream!=NULL) {
            fclose(slicestream);
            PRINTF("  Removing %s\n",slicefile_svz);
            UNLINK(slicefile_svz);
            LOCK_COMPRESS;
            GLOBfilesremoved++;
            UNLOCK_COMPRESS;
        }
        return 0;
    }

    if(GLOBoverwrite_slice==0) {
        slicestream=fopen(slicefile_svz,"rb");
        if(slicestream!=NULL) {
            fclose(slicestream);
            fprintf(stderr,"*** Warning: The file %s exists.\n",slicefile_svz);
            fprintf(stderr,"     Use the -f option to overwrite smokezip compressed files\n");
            return 0;
        }
    }

    slicestream=fopen(slicefile_svz,"wb");
    if(slicestream==NULL) {
        fprintf(stderr,"*** Warning: The file %s could not be opened for writing\n",slicefile_svz);
        return 0;
    }

    // read and write slice header

#ifndef pp_THREAD
    if(GLOBcleanfiles==0) {
        PRINTF("Compressing %s (%s)\n",slice_file,filetype);
    }
#endif


    {
        int skip;

        skip = 3*(4+30+4);  // skip over 3 records each containing a 30 byte FORTRAN character string
        returncode=FSEEK(SLICEFILE,skip,SEEK_CUR);
        sizebefore=skip;
    }

    FORTSLICEREAD(ijkbar,6);
    sizebefore+=4+6*4+4;
    sizeafter=0;

    {
        int one=1, version_local=0, completion=0;

        fwrite(&one,4,1,slicestream);
        fwrite(&version_local,4,1,slicestream);
        fwrite(&completion,4,1,slicestream);
    }


    {
        int ni, nj, nk;

        ni = ijkbar[1]+1-ijkbar[0];
        nj = ijkbar[3]+1-ijkbar[2];
        nk = ijkbar[5]+1-ijkbar[4];
        framesize = ni*nj*nk;
        NewMemory((void **)&sliceframe_data,framesize*sizeof(float));

        for(;;) {
            float vmin, vmax;
            float *valmin, *valmax;
            unsigned char *compressed_data_out;
            uLongf ncompressed_data_out;
            float time_local;

            FORTSLICEREAD(&time_local,1);
            if(returncode==0)break;
            CheckMemory;
            sizebefore+=12;

            FORTSLICEREAD(sliceframe_data,framesize);    //---------------
            if(returncode==0)break;
            CheckMemory;
            sizebefore+=(4+framesize*sizeof(float)+4);

            valmin=NULL;
            valmax=NULL;
            if(slicei->voltype==1) {
                vmin=0.0;
                valmin=&vmin;
            }
            else if(slicei->voltype==2) {
                vmin=20.0;
                valmin=&vmin;
                vmax=1400.0;
                valmax=&vmax;
            }
            else {
                ASSERT(0);
            }
            CheckMemory;
            compress_volsliceframe(sliceframe_data, framesize, time_local, valmin, valmax,
                                   &compressed_data_out, &ncompressed_data_out);
            CheckMemory;
            sizeafter+=ncompressed_data_out;
            if(ncompressed_data_out>0) {
                fwrite(compressed_data_out,1,ncompressed_data_out,slicestream);
            }
            CheckMemory;
            FREEMEMORY(compressed_data_out);

#ifndef pp_THREAD
            count++;
#endif

            data_loc=FTELL(SLICEFILE);
            percent_done=100.0*(float)data_loc/(float)slicei->filesize;
#ifdef pp_THREAD
            threadinfo[*thread_index].stat=percent_done;
            if(percent_done>percent_next) {
                LOCK_PRINT;
                print_thread_stats();
                UNLOCK_PRINT;
                percent_next+=10;
            }
#else
            if(percent_done>percent_next) {
                PRINTF(" %i%s",percent_next,GLOBpp);
                FFLUSH();
                percent_next+=10;
            }
#endif

        }
        if(returncode!=0) {
            fprintf(stderr,"*** Error: compress returncode=%i\n",returncode);
        }
        FREEMEMORY(sliceframe_data);
    }

#ifndef pp_THREAD
    PRINTF(" 100%s completed\n",GLOBpp);
#endif

    {
        int completion=1;

        FSEEK(slicestream,4,SEEK_SET);
        fwrite(&completion,4,1,slicestream);
    }
    fclose(SLICEFILE);
    fclose(slicestream);

    {
        char before_label[256],after_label[256];

        getfilesizelabel(sizebefore,before_label);
        getfilesizelabel(sizeafter,after_label);
#ifdef pp_THREAD
        slicei->vol_compressed=1;
        sprintf(slicei->volsummary,"compressed from %s to %s (%4.1f%s reduction)",before_label,after_label,(float)sizebefore/(float)sizeafter,GLOBx);
        threadinfo[*thread_index].stat=-1;
#else
        PRINTF("  records=%i, ",count);
        PRINTF("Sizes: original=%s, ",before_label);
        PRINTF("compressed=%s (%4.1f%s reduction)\n\n",after_label,(float)sizebefore/(float)sizeafter,GLOBx);
#endif
    }

    return 1;

}
コード例 #28
0
ファイル: CLUTDataAnimation.c プロジェクト: X-Band/SegaOS
static
long CLUTDataAnimatorProc ( short command, long * time, CLUTDataAnimatorData * data, long * ref )
{
long			returnVal;
short i;
CLUTDataState	*privData = (CLUTDataState *) *ref;

	returnVal = kAnimationOk;
	
		
	switch ( command )
		{
		case kInitAnimationProc:
			privData = (CLUTDataState *) NewMemory( kTemp, sizeof(CLUTDataState) );
			if (privData) {

				privData->vectors = (CLUTDataVector *) DBGetItem( kCLUTDataType, data->dataID );
				
				ASSERT_MESG(privData->vectors, "didn't receive data to animate CLUT");
			
				if ( privData->vectors ) {
					privData->clutNumber = data->clutNumber;
					privData->vectorIndex = 0;
					privData->framesLeft = 0;
					privData->frameDelay = data->frameDelay;
				
					*ref = (long) privData;
				} else {
					DisposeMemory( (Ptr) privData );
					*ref = 0;
					returnVal = kAnimationError;
				}
			} else {
				*ref = 0;
				returnVal = kAnimationError;
			}
			break;
		
		case kDisposeAnimationProc:
			if ( privData )
				{
				DisposeMemory ( (Ptr) privData );
				}
			*ref = 0L;
			break;
		
		case kStartAnimationProc:
			break;
		
		case kStopAnimationProc:
			break;
			
		case kSetAnimationGrayProc:
			break;
			
		case kClearAnimationGrayProc:
			break;
		
		case kDoAnimationEvent:
			if ( privData )
				{
				DoCLUTAnimation( privData );
				*time += privData->frameDelay;	
				}
				
			break;
		}
	
	return returnVal;
}
コード例 #29
0
ファイル: getdatabounds.c プロジェクト: tkorhon1/FDS-SMVgit
void adjustpart5bounds(partdata *parti){
  int i,j,k,m;
  part5data *datacopy;
  int alpha05;

  for(i=0;i<npart5prop;i++){
    part5prop *propi;
    int n;
    int *buckets;

    propi = part5propinfo + i;

    if(propi->set_global_bounds==1){
      propi->global_min =  1000000000.0;
      propi->global_max = -1000000000.0;
    }

    NewMemory((void **)&propi->buckets,NBUCKETS*sizeof(int));
    buckets = propi->buckets;
    for (n=0;n<NBUCKETS;n++){
      buckets[n]=0;
    }
  }

  // compute global min and max

  datacopy = parti->data5;
  for(i=0;i<parti->ntimes;i++){
    for(j=0;j<parti->nclasses;j++){
      part5class *partclassi;
      float *rvals;

      partclassi=parti->partclassptr[j];
      rvals = datacopy->rvals;

      for(k=2;k<partclassi->ntypes;k++){
        part5prop *prop_id;
        float *valmin, *valmax;

        prop_id = get_part5prop(partclassi->labels[k].longlabel);
        if(prop_id==NULL)continue;

        valmin = &prop_id->global_min;
        valmax = &prop_id->global_max;

        if(prop_id->set_global_bounds==1&&(valmin!=NULL||valmax!=NULL)){
          for(m=0;m<datacopy->npoints;m++){
            float val;

            val=*rvals++;
            if(valmin!=NULL)*valmin=MIN(*valmin,val);
            if(valmax!=NULL)*valmax=MAX(*valmax,val);
          }
        }
      }
      datacopy++;
    }
  }

  // generate data histogram (buckets) in order to determine percentile min and max

  datacopy = parti->data5;
  for(i=0;i<parti->ntimes;i++){
    for(j=0;j<parti->nclasses;j++){
      part5class *partclassi;
      float *rvals;

      partclassi = parti->partclassptr[j];
      rvals = datacopy->rvals;

      for(k=2;k<partclassi->ntypes;k++){
        part5prop *prop_id;
        float *valmin, *valmax, dg;
        int *buckets;

        prop_id = get_part5prop(partclassi->labels[k].longlabel);
        if(prop_id==NULL)continue;

        valmin = &prop_id->global_min;
        valmax = &prop_id->global_max;
        dg = (*valmax-*valmin)/(float)NBUCKETS;
        if(dg==0.0)dg=1.0;
        buckets=prop_id->buckets;

        for(m=0;m<datacopy->npoints;m++){
          float val;
          int ival;

          val=*rvals++;
          ival = CLAMP((val-*valmin)/dg,0,NBUCKETS-1);
          buckets[ival]++;
        }
      }
      datacopy++;
    }
  }

  // calculate percentile min and max

  for(i=0;i<npart5prop;i++){
    part5prop *propi;
    int total;
    int *buckets;
    int nsmall, nbig;
    int n;
    float gmin, gmax, dg;

    propi = part5propinfo + i;
    buckets = propi->buckets;

    if(propi->set_global_bounds==1){
      total = 0;
      for(n=0;n<NBUCKETS;n++){
        total+=buckets[n];
      }
      alpha05 = (int)(percentile_level*total);

      total = 0;
      nsmall=0;
      nbig = NBUCKETS-1;
      for (n=0;n<NBUCKETS;n++){
        total += buckets[n];
        if(total>alpha05){
          nsmall=n;
          break;
        }
      }
      total = 0;
      for (n=NBUCKETS;n>0;n--){
        total += buckets[n-1];
        if(total>alpha05){
          nbig=n-1;
          break;
        }
      }
      gmin = propi->global_min;
      gmax = propi->global_max;
      dg = (gmax-gmin)/(float)NBUCKETS;
      propi->percentile_min = gmin + nsmall*dg;
      propi->percentile_max = gmin + nbig*dg;
    }
    FREEMEMORY(propi->buckets);
  }
  for(i=0;i<npart5prop;i++){
    part5prop *propi;

    propi = part5propinfo + i;

    switch(propi->setvalmin){
    case PERCENTILE_MIN:
      propi->valmin=propi->percentile_min;
      break;
    case GLOBAL_MIN:
      propi->valmin=propi->global_min;
      break;
    case SET_MIN:
      propi->valmin=propi->user_min;
      break;
    default:
      ASSERT(FFALSE);
      break;
    }
    switch(propi->setvalmax){
    case PERCENTILE_MAX:
      propi->valmax=propi->percentile_max;
      break;
    case GLOBAL_MAX:
      propi->valmax=propi->global_max;
      break;
    case SET_MAX:
      propi->valmax=propi->user_max;
      break;
    default:
      ASSERT(FFALSE);
      break;
    }
  }
  adjustpart5chops(parti);
#ifdef _DEBUG
  print_part5prop();
#endif
}
コード例 #30
0
ファイル: getdatabounds.c プロジェクト: tkorhon1/FDS-SMVgit
void adjustPlot3Dbounds(int plot3dvar, int setpmin, float *pmin, int setpmax, float *pmax)
{
    int nsmall, nbig, *buckets=NULL, n, level, total, alpha05;
    float dp, pmin2, pmax2;
    plot3ddata *p;
    mesh *meshi;
    int i;
    char *iblank;
    float *q;
    int ndata=0;
    int ntotal;

    if(setpmin==PERCENTILE_MIN||setpmax==PERCENTILE_MAX){
      dp = (*pmax - *pmin)/NBUCKETS;
      nsmall=0;
      nbig=NBUCKETS;
      if(NewMemory((void **)&buckets,NBUCKETS*sizeof(int))==0){
        fprintf(stderr,"*** Error: Unable to allocate memory in getdatabounds\n");
        return;
      }

      for (n=0;n<NBUCKETS;n++){
        buckets[n]=0;
      }
      for(i=0;i<nplot3dinfo;i++){
        p = plot3dinfo+i;
        if(p->loaded==0||p->display==0)continue;
        meshi=meshinfo+p->blocknumber;
        ntotal=(meshi->ibar+1)*(meshi->jbar+1)*(meshi->kbar+1);
        ndata += ntotal;
        iblank=meshi->c_iblank_node;
        q=meshi->qdata+plot3dvar*ntotal;
        for(n=0;n<ntotal;n++){
          if(iblank==NULL||*iblank++==GAS){
            level=0;
            if(dp!=0.0f)level = CLAMP((int)((q[n] - *pmin)/dp),0,NBUCKETS-1);
            buckets[level]++;
          }
        }
      }
      alpha05 = (int)(percentile_level*ndata);
      total = 0;
      for (n=0;n<NBUCKETS;n++){
        total += buckets[n];
        if(total>alpha05){
          nsmall=n;
          break;
        }
      }
      total = 0;
      for (n=NBUCKETS;n>0;n--){
        total += buckets[n-1];
        if(total>alpha05){
          nbig=n;
          break;
        }
      }
      pmin2 = *pmin + (nsmall-1)*dp;
      pmax2 = *pmin + (nbig+1)*dp;
      if(setpmin==PERCENTILE_MIN)*pmin = pmin2; 
      if(setpmax==PERCENTILE_MAX)*pmax = pmax2;
      FreeMemory(buckets);
    }
    if(axislabels_smooth==1&&setpmin!=SET_MIN&&setpmax!=SET_MAX){
      smoothlabel(pmin,pmax,nrgb);
    }

}