예제 #1
0
/*
=================
UI_LoadGame_Ownerdraw
=================
*/
static void UI_LoadGame_Ownerdraw( void *self )
{
	menuCommon_s	*item = (menuCommon_s *)self;

	if( item->type != QMTYPE_ACTION && item->id == ID_LEVELSHOT )
	{
		int	x, y, w, h;

		// draw the levelshot
		x = LEVELSHOT_X;
		y = LEVELSHOT_Y;
		w = LEVELSHOT_W;
		h = LEVELSHOT_H;
		
		UI_ScaleCoords( &x, &y, &w, &h );

		if( strlen( uiLoadGame.saveName[uiLoadGame.savesList.curItem] ))
		{
			char	saveshot[128];

			sprintf( saveshot, "save/%s.bmp", uiLoadGame.saveName[uiLoadGame.savesList.curItem] );
			if( !FILE_EXISTS( saveshot ))
				UI_DrawPicAdditive( x, y, w, h, uiColorWhite, "{GRAF001" );
			else UI_DrawPic( x, y, w, h, uiColorWhite, saveshot );
		}
		else UI_DrawPicAdditive( x, y, w, h, uiColorWhite, "{GRAF001" );

		// draw the rectangle
		UI_DrawRectangle( item->x, item->y, item->width, item->height, uiInputFgColor );
	}
}
예제 #2
0
void check_pidfile(){
	if (FILE_EXISTS(PIDFILE)) {
		/* We are expecting that the file DOES NOT exist */
		QUIT_DAEMON("PID file %s already exists, is the daemon running?", PIDFILE);
	}

	return;
}
예제 #3
0
파일: example.c 프로젝트: LukeMeszar/CAS
boolean
get_eg_file_list()
{
  /* On exit, "completion_list" specifies a list of extant files
   *   completion_list->identifier is the local name
   *   completion_list->data is the full path name
   */

  char ch, *cp;
  char localname[FILENAME_LEN], realname[FILENAME_LEN];
  size_t cmdp;

  /* Collect the library name */
  for (cmdp = nodebot + 2, cp = lib; (ch = info_file[cmdp]) != '\n'; cmdp++)
    *cp++ = ch;
  if (cp != lib) *cp = '\0';

  free_completion_list();

  /* collect the information about extant files */
  for (cmdp++; info_file[cmdp] != info_separator_char; cmdp++) {
    for (cp = localname;
	 ((ch = info_file[cmdp]) != '\n') && (ch != TAB) && (ch != SPACE);
	 cmdp++)
      *cp++ = ch;
    *cp = '\0';
    for ( ; info_file[cmdp] != '\n'; cmdp++ )
      ;

    /* If filename starts with a '/', filename must exist. */
    /* If lib starts with a '/', lib/filename must exist. */
    /* Otherwise, libname/lib/filename must exist. */
    if (FILE_EXISTS(localname)) strcpy(realname, localname);
    else if ((lib[0] == '/') || (libname == NULL) || (libname[0] == '\0'))
      (void)sprintf( realname, "%s/%s", lib, localname );
    else (void)sprintf( realname, "%s/%s/%s", libname, lib, localname );
    /* make sure that the library version exists */
    if (FILE_EXISTS( realname )) add_completion(localname, realname);
  }
  return(completion_list != NULL);
}
예제 #4
0
/* Main */
int main(int argc, char ** argv)
{
    herr_t num_fails;

    hid_t fid,sid,sid1,sid2;
    int   cnt, i;
    char * names[2];
    size_t * size;
    
    /* Delete the test file */
    if ( FILE_EXISTS(FILE) ) {
        danu_file_delete(FILE);
    }

    fid = danu_file_create(FILE);
    DANU_DEBUG_MESS("Create test file");

    if ( H5_ISA_VALID_ID(fid) ) {

        num_fails = simulations_create(fid,&sid,FALSE);
        DANU_DEBUG_MESS("Create Simulations groups");
        num_fails += simulation_add(fid,SIM1_NAME,&sid1,FALSE);
        DANU_DEBUG_MESS("Add a simulation");
        num_fails += simulation_add(fid,SIM2_NAME,&sid2,FALSE);
        DANU_DEBUG_MESS("Add another simulation");

        danu_group_close(sid2);
        danu_group_close(sid1);
        danu_group_close(sid);

        num_fails += simulation_count(fid,&cnt);
        printf("There are %d simulations in %s\n",cnt,FILE);
        size = DANU_MALLOC(size_t,2);
        for(i=0;i<2;i++) {
            size[i] = MAX_NAME_LEN;
            names[i] = DANU_MALLOC(char,MAX_NAME_LEN);
        }
        num_fails += simulation_list(fid,cnt,size,names);
        printf("The simulations are:\n");
        for(i=0;i<2;i++) 
            printf("\t%s\n",names[i]);

        DANU_FREE(size);
        for(i=0;i<2;i++) {
            DANU_FREE(names[i]);
        }
    }


    return num_fails;
}
예제 #5
0
static void UI_PlayerSetup_FindSprayDecals( void )
{
	char	**filenames;
	int	numFiles;

	uiPlayerSetup.num_sprays = 0;

	// Get file list
	filenames = FS_SEARCH( "logos/*.bmp", &numFiles, FALSE );

	// build the spray list
	for( int i = 0; i < numFiles; i++ )
	{
		if( !FILE_EXISTS( filenames[i] )) continue;

		strcpy( uiPlayerSetup.sprays[uiPlayerSetup.num_sprays], filenames[i] );
		uiPlayerSetup.num_sprays++;
	}
}
예제 #6
0
int ShellExecAsUser(const TCHAR *const pcOperation, const TCHAR *const pcFileName, const TCHAR *const pcParameters, const HWND &parentHwnd, const bool &threaded)
{
	//Make sure the destination file exists
	if(!FILE_EXISTS(pcFileName))
	{
		return SHELL_EXEC_AS_USER_NOT_FOUND;
	}

	int iSuccess = SHELL_EXEC_AS_USER_FAILED;

	OSVERSIONINFO osVersion;
	memset(&osVersion, 0, sizeof(OSVERSIONINFO));
	osVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

	//Use IShellDispatch2 on supported platforms
	if(GetVersionEx(&osVersion))
	{
		if((osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) && (osVersion.dwMajorVersion >= 6))
		{
			shell_exec_as_user_param_t params = { parentHwnd, pcOperation, pcFileName, pcParameters };
			iSuccess = MyShellDispatch(ShellExecAsUser_HandlerProc, &params, threaded);
		}
		else
		{
			iSuccess = SHELL_EXEC_AS_USER_UNSUPPORTED;
		}
	}

	//Fallback mode
	if((iSuccess == SHELL_EXEC_AS_USER_FAILED) || (iSuccess == SHELL_EXEC_AS_USER_UNSUPPORTED))
	{
		HINSTANCE hInst = ShellExecute(parentHwnd, pcOperation, pcFileName, pcParameters, NULL, SW_SHOWNORMAL);
		if(((int)hInst) > 32)
		{
			iSuccess = SHELL_EXEC_AS_USER_FALLBACK;
		}
	}

	return iSuccess;
}
예제 #7
0
/*
=================
UI_StartBackGroundMap
=================
*/
bool UI_StartBackGroundMap( void )
{
	static bool	first = TRUE;

	if( !first ) return FALSE;

	first = FALSE;

	// some map is already running
	if( !uiStatic.bgmapcount || CVAR_GET_FLOAT( "host_serverstate" ) || gpGlobals->demoplayback )
		return FALSE;

	int bgmapid = RANDOM_LONG( 0, uiStatic.bgmapcount - 1 );

	char cmd[128];
	sprintf( cmd, "maps/%s.bsp", uiStatic.bgmaps[bgmapid] );
	if( !FILE_EXISTS( cmd )) return FALSE; 

	sprintf( cmd, "map_background %s\n", uiStatic.bgmaps[bgmapid] );
	CLIENT_COMMAND( FALSE, cmd );

	return TRUE;
}
예제 #8
0
int main(int argc, char ** argv)
{
    hid_t  fid,id;

    unsigned  i;

    int        dim = 2;
    int        ncell = 8;
    int        num;
    hsize_t   *isize;
    int       *idata;

    int       data3[3] = { -1, -1, -1 };
    hsize_t   size[2] = { 3, 1 }; 


    const char  test_file[] = "deleteme.h5";
    const char  data_name[] = "Extend this data";

    /* Get rid of old copies of the test file */
    if ( FILE_EXISTS(test_file) ) {
        danu_file_delete(test_file);
    }

    /* Generate the data */
    isize = DANU_MALLOC(hsize_t, dim);
    num = 1;
    for(i=0;i<dim;i++) { 
        isize[i] = ncell;
        num*=ncell;
    }

    idata = DANU_MALLOC(int,num);
    danu_rand_data_int(0,num,num,idata);

    /* Simple file create */
    fid = danu_file_create(test_file);

    /* Create the dataset with the extend flag set to TRUE */
    id = danu_dataset_create(fid,data_name,H5T_NATIVE_INT,dim,isize,TRUE);

    if ( H5_ISA_INVALID_ID(id) ) {
        DANU_ERROR_MESS("Failed to create dataset");
        goto FAIL_EXIT;
    }

    /* First write ..... */
    if ( danu_dataset_write(id,NULL,H5T_NATIVE_INT,dim,isize,idata) < 0 ) {
        DANU_ERROR_MESS("Failed the first data write");
        goto FAIL_EXIT;
    }

    /* Now the second ..... */
    if ( danu_dataset_append(id,H5T_NATIVE_INT,isize,idata) < 0 ) {
        DANU_ERROR_MESS("Failed to write the second dataset");
        goto FAIL_EXIT;
    }

    /* And the third .... */
    if ( danu_dataset_append(id,H5T_NATIVE_INT,size,data3) < 0 ) {
        DANU_ERROR_MESS("Failed to write the third dataset");
        goto FAIL_EXIT;
    }

    /* And try out the append_int call */
    if ( danu_data_append_int(fid,data_name,dim,size,data3) < 0 ) {
        DANU_ERROR_MESS("append_int call failed");
        goto FAIL_EXIT;
    }
    

    /* Close the objects */
    danu_dataset_close(id);
    danu_file_close(fid);

    /* Free Memory */
    DANU_FREE(isize);
    DANU_FREE(idata);

    printf("Test PASS\n");
    return 0;

    FAIL_EXIT:
             return DANU_FAIL;
}
예제 #9
0
/*
=================
UI_TouchOptions_Callback
=================
*/
static void UI_TouchOptions_Callback( void *self, int event )
{
	menuCommon_s	*item = (menuCommon_s *)self;

	switch( item->id )
	{
	case ID_ENABLE:
	case ID_GRID:
	case ID_IGNORE_MOUSE:
		if( event == QM_PRESSED )
			((menuCheckBox_s *)self)->focusPic = UI_CHECKBOX_PRESSED;
		else ((menuCheckBox_s *)self)->focusPic = UI_CHECKBOX_FOCUS;
		break;
	}

	if( event == QM_CHANGED )
	{
		// Update cvars based on controls
		UI_TouchOptions_SetConfig();

		if( item->id == ID_PROFILELIST )
		{
			char curprofile[256];
			int isCurrent;
			COM_FileBase( CVAR_GET_STRING( "touch_config_file" ), curprofile );
			isCurrent = !strcmp( curprofile, uiTouchOptions.profileDesc[ uiTouchOptions.profiles.curItem ]);

			// Scrolllist changed, update availiable options
			uiTouchOptions.remove.generic.flags |= QMF_GRAYED;
			if( ( uiTouchOptions.profiles.curItem > uiTouchOptions.firstProfile ) && !isCurrent )
				uiTouchOptions.remove.generic.flags &= ~QMF_GRAYED;

			uiTouchOptions.apply.generic.flags &= ~QMF_GRAYED;
			if( uiTouchOptions.profiles.curItem == 0 || uiTouchOptions.profiles.curItem == uiTouchOptions.firstProfile -1 )
				uiTouchOptions.profiles.curItem ++;
			if( isCurrent )
				uiTouchOptions.apply.generic.flags |= QMF_GRAYED;
		}
		return;
	}

	if( event != QM_ACTIVATED )
		return;

	switch( item->id )
	{
	case ID_DONE:
		UI_TouchOptions_SetConfig();
		UI_PopMenu();
		break;
	case ID_RESET:
		uiTouchOptions.save.generic.flags |= QMF_INACTIVE; 
		uiTouchOptions.remove.generic.flags |= QMF_INACTIVE;
		uiTouchOptions.enable.generic.flags |= QMF_INACTIVE;
		uiTouchOptions.profiles.generic.flags |= QMF_INACTIVE;
		uiTouchOptions.moveX.generic.flags |= QMF_INACTIVE;
		uiTouchOptions.moveY.generic.flags |= QMF_INACTIVE;
		uiTouchOptions.lookX.generic.flags |= QMF_INACTIVE;
		uiTouchOptions.lookY.generic.flags |= QMF_INACTIVE;
		uiTouchOptions.reset.generic.flags |= QMF_INACTIVE;
		uiTouchOptions.profilename.generic.flags |= QMF_INACTIVE;
		uiTouchOptions.done.generic.flags |= QMF_INACTIVE;


		uiTouchOptions.msgBox.generic.flags &= ~QMF_HIDDEN;
		uiTouchOptions.promptMessage.generic.flags &= ~QMF_HIDDEN;
		uiTouchOptions.no.generic.flags &= ~QMF_HIDDEN;
		uiTouchOptions.yes.generic.flags &= ~QMF_HIDDEN;
		strcpy( uiTouchOptions.dialogText, "Reset all buttons?" );
		uiTouchOptions.dialogAction = UI_ResetButtons;
		break;
	case ID_DELETE:
		uiTouchOptions.save.generic.flags |= QMF_INACTIVE; 
		uiTouchOptions.remove.generic.flags |= QMF_INACTIVE;
		uiTouchOptions.enable.generic.flags |= QMF_INACTIVE;
		uiTouchOptions.profiles.generic.flags |= QMF_INACTIVE;
		uiTouchOptions.moveX.generic.flags |= QMF_INACTIVE;
		uiTouchOptions.moveY.generic.flags |= QMF_INACTIVE;
		uiTouchOptions.lookX.generic.flags |= QMF_INACTIVE;
		uiTouchOptions.lookY.generic.flags |= QMF_INACTIVE;
		uiTouchOptions.reset.generic.flags |= QMF_INACTIVE;
		uiTouchOptions.profilename.generic.flags |= QMF_INACTIVE;
		uiTouchOptions.done.generic.flags |= QMF_INACTIVE;


		uiTouchOptions.msgBox.generic.flags &= ~QMF_HIDDEN;
		uiTouchOptions.promptMessage.generic.flags &= ~QMF_HIDDEN;
		uiTouchOptions.no.generic.flags &= ~QMF_HIDDEN;
		uiTouchOptions.yes.generic.flags &= ~QMF_HIDDEN;
		strcpy( uiTouchOptions.dialogText, "Delete selected profile?" );
		uiTouchOptions.dialogAction = UI_DeleteProfile;
		break;
	case ID_YES:
	if( uiTouchOptions.dialogAction )
		uiTouchOptions.dialogAction();
	case ID_NO:
		uiTouchOptions.save.generic.flags &= ~QMF_INACTIVE; 
		uiTouchOptions.remove.generic.flags &= ~QMF_INACTIVE;
		uiTouchOptions.enable.generic.flags &= ~QMF_INACTIVE;
		uiTouchOptions.profiles.generic.flags &= ~QMF_INACTIVE;
		uiTouchOptions.moveX.generic.flags &= ~QMF_INACTIVE;
		uiTouchOptions.moveY.generic.flags &= ~QMF_INACTIVE;
		uiTouchOptions.lookX.generic.flags &= ~QMF_INACTIVE;
		uiTouchOptions.lookY.generic.flags &= ~QMF_INACTIVE;
		uiTouchOptions.reset.generic.flags &= ~QMF_INACTIVE;
		uiTouchOptions.profilename.generic.flags &= ~QMF_INACTIVE;
		uiTouchOptions.done.generic.flags &= ~QMF_INACTIVE;

		uiTouchOptions.msgBox.generic.flags |= QMF_HIDDEN;
		uiTouchOptions.promptMessage.generic.flags |= QMF_HIDDEN;
		uiTouchOptions.no.generic.flags |= QMF_HIDDEN;
		uiTouchOptions.yes.generic.flags |= QMF_HIDDEN;
		break;
	case ID_SAVE:
		{
			char name[256];
			if( uiTouchOptions.profilename.buffer[0] )
			{
				snprintf( name, 256, "touch_profiles/%s.cfg", uiTouchOptions.profilename.buffer );
				CVAR_SET_STRING("touch_config_file", name );
			}
			CLIENT_COMMAND( 1, "touch_writeconfig\n" );
		}
		UI_TouchOptions_GetProfileList();
		uiTouchOptions.profilename.buffer[0] = 0;
		uiTouchOptions.profilename.cursor = uiTouchOptions.profilename.scroll = 0;
		break;
	case ID_APPLY:
		{

			int i = uiTouchOptions.profiles.curItem;

			// preset selected
			if( i > 0 && i < uiTouchOptions.firstProfile - 1 )
			{
				char command[256];
				char *curconfig = CVAR_GET_STRING( "touch_config_file" );
				snprintf( command, 256, "exec \"touch_presets/%s\"\n", uiTouchOptions.profileDesc[ i ] );
				CLIENT_COMMAND( 1,  command );

				while( FILE_EXISTS( curconfig ) )
				{
					char copystring[256];
					char filebase[256];

					COM_FileBase( curconfig, filebase );

					if( snprintf( copystring, 256, "touch_profiles/%s (new).cfg", filebase ) > 255 )
						break;

					CVAR_SET_STRING( "touch_config_file", copystring );
					curconfig = CVAR_GET_STRING( "touch_config_file" );
				}
			}
			else if( i == uiTouchOptions.firstProfile )
				CLIENT_COMMAND( 1,"exec touch.cfg\n" );
			else if( i > uiTouchOptions.firstProfile )
			{
				char command[256];
				snprintf( command, 256, "exec \"touch_profiles/%s\"\n", uiTouchOptions.profileDesc[ i ] );
				CLIENT_COMMAND( 1,  command );
			}

			// try save config
			CLIENT_COMMAND( 1,  "touch_writeconfig\n" );

			// check if it failed ant reset profile to default if it is
			if( !FILE_EXISTS( CVAR_GET_STRING( "touch_config_file" ) ))
			{
				CVAR_SET_STRING( "touch_config_file", "touch.cfg" );
				uiTouchOptions.profiles.curItem = uiTouchOptions.firstProfile;
			}
			UI_TouchOptions_GetProfileList();
			UI_TouchOptions_GetConfig();
		}
	}
}
예제 #10
0
int main(int argc, char ** argv)
{
    hid_t fid,gid;
    double dtest;
    int    itest;
    char   stest[STR_ATTR_LEN]; 
    int    i, num_found;

    char  **names;
    size_t  *size;
    char    group_name[] = "Group"; 

    /* Get rid of old copies of the test file */
    if ( FILE_EXISTS(TEST_FILE) ) {
        danu_file_delete(TEST_FILE);
    }

    /* Simple create */
    fid = danu_file_create(TEST_FILE);
    gid = danu_group_create(fid,group_name);

    if ( H5_ISA_INVALID_ID(fid) ) {
        DANU_ERROR_MESS("Failed to create a test file");
        goto FAIL_EXIT;
    }

    /* Now Write the attributes */
    if ( DANU_RETURN_FAIL(danu_attr_write_int(fid, INT_ATTR_NAME, INT_ATTR_VALUE) ) ){
        DANU_ERROR_MESS("Failed to write int attribute");
        goto FAIL_EXIT;
    }

    if ( DANU_RETURN_FAIL(danu_attr_write_double(fid, DOUBLE_ATTR_NAME, DOUBLE_ATTR_VALUE) ) ){
        DANU_ERROR_MESS("Failed to write double attribute");
        goto FAIL_EXIT;
    }

    
    if ( DANU_RETURN_FAIL(danu_attr_write_string(fid, STR_ATTR_NAME, STR_ATTR_VALUE) ) ){
        DANU_ERROR_MESS("Failed to write char attribute");
        goto FAIL_EXIT;
    }

    danu_file_close(fid); 

    /* Re-open file and read the attributes back */
    fid = danu_file_open(TEST_FILE,DANU_FILE_ACT_OPEN,DANU_FILE_ACC_RDONLY);

    /* Int attribute */
    if ( DANU_RETURN_FAIL(danu_attr_read_int(fid, INT_ATTR_NAME, &itest) ) ){
        DANU_ERROR_MESS("Failed to read int attribute");
        goto FAIL_EXIT;
    }

    /* Check the value */
    printf("INTEGER IN=%d OUT=%d\n", INT_ATTR_VALUE, itest);
    if ( itest != INT_ATTR_VALUE ) {
        danu_error_printf("Failed to read the correct value!\n");
        goto FAIL_EXIT;
    }
    
    /* Double attribute */
    if ( DANU_RETURN_FAIL(danu_attr_read_double(fid, DOUBLE_ATTR_NAME, &dtest) ) ){
        DANU_ERROR_MESS("Failed to read double attribute");
        goto FAIL_EXIT;
    }

    /* Check the value */
    printf("Double IN=%1.9e OUT=%1.9e\n", DOUBLE_ATTR_VALUE, dtest);
    if ( dtest != DOUBLE_ATTR_VALUE ) {
        danu_error_printf("Failed to read the correct value!\n");
        goto FAIL_EXIT;
    }


    /* String attribute */
    if ( DANU_RETURN_FAIL(danu_attr_read_string(fid, STR_ATTR_NAME, stest,STR_ATTR_LEN) ) ){
        DANU_ERROR_MESS("Failed to read string attribute");
        goto FAIL_EXIT;
    }

    /* Check the value */
    printf("string IN='%s' OUT='%s'\n", STR_ATTR_VALUE, stest);
    if ( strncmp(STR_ATTR_VALUE,stest,STR_ATTR_LEN) != 0 ) {
        danu_error_printf("Failed to read the correct value!\n");
        goto FAIL_EXIT;
    }

    /* Find the count n the file*/
    if ( DANU_RETURN_FAIL(danu_attr_count(fid,&num_found)) ) {
        DANU_ERROR_MESS("Failed to count the number of attributes");
        goto FAIL_EXIT;
    }
    printf("Found %d attributes in file\n",num_found);

    names = DANU_MALLOC(char *, num_found);
    size  = DANU_MALLOC(size_t, num_found);
    for(i=0;i<num_found;i++) {
        size[i] = 128;
        names[i] = DANU_MALLOC(char,128);
    }

    /* Grab the names */
    if ( DANU_RETURN_FAIL(danu_attr_names(fid,num_found,size,names)) ) {
        DANU_ERROR_MESS("Failed to read the attribute names");
        goto FAIL_EXIT;
    }
    else {
        printf("Found the attributes\n");
        for(i=0; i<num_found; i++) {
            printf("I=%d\tName=%s\n",i,names[i]);
        }
    }

    /* Find the count in the group*/
    gid = danu_group_open(fid,group_name);
    if ( DANU_RETURN_FAIL(danu_attr_count(gid,&num_found)) ) {
        DANU_ERROR_MESS("Failed to count the number of attributes");
        goto FAIL_EXIT;
    }
    printf("Found %d attributes in group\n",num_found);


    /* Free memory */
    DANU_FREE(size);
    for(i=0;i<3;i++) {
        DANU_FREE(names[i]);
    }
    DANU_FREE(names);


 
    goto SUCCESS_EXIT;



    FAIL_EXIT:
             DANU_ERROR_MESS("Test FAIL");
             return DANU_FAILURE;
    SUCCESS_EXIT:
             //danu_file_delete(TEST_FILE);
             return DANU_SUCCESS;
}
예제 #11
0
int main(int argc, char ** argv)
{
    hid_t  fid, gid;
    hid_t  data;

    hsize_t   *size;
    dsize_t    i,num;
    double    *double_data, *ref;
    int        value,vref;

    /* Get rid of old copies of the test file */
    if ( FILE_EXISTS(TEST_FILE) ) {
        danu_file_delete(TEST_FILE);
    }

    /* Generate the data */
    size = DANU_MALLOC(hsize_t, DATA_DOUBLE_DIM);
    num = 1;
    for(i=0;i<DATA_DOUBLE_DIM;i++) { 
        size[i] = DATA_DOUBLE_SIZE;
        num*=DATA_DOUBLE_SIZE;
    }

    double_data = DANU_MALLOC(double,num);
    ref      = DANU_MALLOC(double,num);
    danu_rand_data_double(-5.0,5.0,num,double_data);
    memcpy(ref,double_data,num*sizeof(double));

    /* Simple file and group create */
    fid = danu_file_create(TEST_FILE);
    gid = danu_group_create(fid,GROUP_NAME,FALSE);

    data = danu_dataset_create(gid,DATA_DOUBLE_NAME,H5T_IEEE_F64LE,DATA_DOUBLE_DIM,size,FALSE,FALSE);

    if ( H5_ISA_INVALID_ID(data) ) {
        DANU_ERROR_MESS("Failed to create the dataspace");
        goto FAIL_EXIT;
    }

    /* Write the data */
    if ( DANU_RETURN_FAIL(danu_dataset_write(data,NULL,H5T_NATIVE_DOUBLE,DATA_DOUBLE_DIM,size,double_data) ) ) {
        DANU_ERROR_MESS("Failed to write data to file");
        goto FAIL_EXIT;
    }

    /* Write data attribute */
    value = DATA_ATTR_VALUE; 
    danu_attr_write_int(data,DATA_ATTR_NAME,value);

    /* Close the file */
    danu_file_close(fid);

    /* Zero out the double_data array */
    for(i=0;i<num;i++)
        double_data[i] = 0;

    /*Open the file to read */
    fid = danu_file_open(TEST_FILE,DANU_FILE_ACT_OPEN,DANU_FILE_ACC_RDONLY);
    gid = danu_group_open(fid,GROUP_NAME);

    
    data = danu_dataset_open(gid,DATA_DOUBLE_NAME);
    if ( H5_ISA_INVALID_ID(data) ) {
        DANU_ERROR_MESS("Failed to open data set for reading");
        goto FAIL_EXIT;
    }

    if ( DANU_RETURN_FAIL(danu_dataset_read(data,NULL,H5T_NATIVE_DOUBLE,DATA_DOUBLE_DIM,size,double_data)) ) {
        DANU_ERROR_MESS("Failed to read data set");
        goto FAIL_EXIT;
    }

    /* Check the data */
    for(i=0;i<num;i++) {
        if ( ref[i] != double_data[i] ) {
            danu_error_printf("MISMATCH FOUND index=%d IN=0x%lX OUT=0x%lX",i,ref[i],double_data[i]);
            goto FAIL_EXIT;
        }
    }

    /* Read the attribute and check it */
    vref = value;
    value = 0;
    danu_attr_read_int(data,DATA_ATTR_NAME,&value);
    if ( vref != value ) {
        DANU_ERROR_MESS("Failed to read attribute");
        goto FAIL_EXIT;
    }

    /* Close the objects */
    danu_dataset_close(data);
    danu_group_close(gid);
    danu_file_close(fid);

    /* Free Memory */
    DANU_FREE(size);
    DANU_FREE(ref);
    DANU_FREE(double_data);

    return DANU_SUCCESS;

    FAIL_EXIT:
             printf("Test %s FAILED\n", argv[0]); 
             return DANU_FAIL;
}
예제 #12
0
int main(int argc, char ** argv)
{
    int num_errs;

    char root_file[] = FILE;
    char test_sim[]  = SIM_NAME;

    char data_name[128];
    char **names;

    int numpe;
    int i,dim, *size;
    size_t *nsizes;
    int ncnt;
    dsize_t num;
    double *data,*ref_data;
    hid_t fid, sid;


    if ( FILE_EXISTS(root_file) ) {
        danu_file_delete(root_file);
    }

    if ( H5_RETURN_FAIL(create_test_file(root_file) ) ) {
        DANU_ERROR_MESS("Failed to create the test file");
        num_errs++;
        goto EXIT_NOW;
    }

    fid = danu_file_open_append(root_file);
    if ( H5_RETURN_FAIL(simulation_add(fid,test_sim,&sid) ) ) {
        DANU_ERROR_MESS("Failed to add simulation");
        goto EXIT_NOW;
    }

    num_errs = 0;

    /* Arrays */
    size = DANU_MALLOC(int,DIM);

    /* Write the data */
    size[0] = 1;
    numpe = DUMMY_INT;
    sprintf(data_name,DATA_INT_NAME);
    if ( H5_RETURN_FAIL(data_write_int(sid,data_name,1,size,&numpe)) ) {
        DANU_ERROR_MESS("Failed to write int data");
        num_errs++;
        goto EXIT_NOW;
    }

    dim = DIM;
    num = 1;
    for(i=0;i<dim;i++) {
       size[i] = NUMCELLS;
       num*=NUMCELLS;
    }
    data = DANU_MALLOC(double,num);
    sprintf(data_name,DATA_DBL_NAME);
    danu_rand_data_double(-5.0,5.0,num,data);
    if ( H5_RETURN_FAIL(data_write_double(sid,data_name,dim,size,data)) ) {
        DANU_ERROR_MESS("Failed to write double data");
        num_errs++;
        goto EXIT_NOW;
    }
  
    /* Check data by reading */ 
    ref_data = DANU_MALLOC(double,num);
    if ( H5_RETURN_FAIL(data_read_double(sid,data_name,dim,size,ref_data) ) ) {
        num_errs++;
        goto EXIT_NOW;
    }
    for(i=0;i<num;i++) {
        if ( ref_data[i] != data[i] ) {
            num_errs++;
        }
    }

    /* Find the number of datasets */
    data_count(sid,&ncnt);
    printf("Found %d datasets\n",ncnt);
    names = DANU_MALLOC(char *,ncnt);
    nsizes = convert_int_to_size(ncnt,size);
    for(i=0;i<ncnt;i++) {
        size[i] = 128;
        names[i] = DANU_MALLOC(char,128);
    }
    data_list(sid,ncnt,nsizes,names);
    printf("Found the following datasets\n");
    for(i=0;i<ncnt;i++) {
        printf("\t<%s>\n",names[i]);
    }



    
    /* Free memory */
    for(i=0;i<ncnt;i++) {
        DANU_FREE(names[i]);
    }
    DANU_FREE(names);
    DANU_FREE(ref_data);
    DANU_FREE(data);    
    DANU_FREE(size);

    /* Free HDF5 resources */
    danu_group_close(sid);
    danu_file_close(fid);


EXIT_NOW:
    printf("Found %d errors\n",num_errs);
    return num_errs;

}