xp_comm_proj/rd_cgns/structured.c
/* read cell data, fill-in FLD */
/* returns 0 if all OK, 1 otherwise */
/* sets cg_err_str to error string if cgns read error */
read cell data, fill-in FLD
returns 0 if all OK, 1 otherwise
sets cg_err_str to error string if cgns read error
read cell data fill - in FLD returns 0 if all OK 1 otherwise sets cg_err_str to error string if cgns read error
static int
add_str_cell_data(OMobj_id fld_id, int base, int zone, int index_dim,
	int *vertex_size, int *rind, int solution, int f_indx, char **cg_err_str)
{
	OMobj_id	cell_id, cell_data_id, cell_data_el_id, values_id;
	int		i, nFields;
	DataType_t	type;
	char		name[CGNS_NAME_MAX_LEN];
	int		i_min[3], i_max[3];
	int		size, junk;
	int		*i_arr;
	float		*f_arr;
	char		stat_str[100];
	int		stop;
	*cg_err_str = NULL;
	if(FLDget_cell_set(fld_id, 0, &cell_id) != 1)
	{
		ERRverror("DVread_cgns:add_str_cell_data",ERR_INFO,
			"failed to get cell_id\n");
		return (1);
	}
	if(cg_nfields(f_indx, base, zone, solution, &nFields))
	{
		*cg_err_str = cg_get_error();
		return (1);
	}
	if(OMset_name_int_val(cell_id, OMstr_to_name("ncell_data"), nFields) !=
		OM_STAT_SUCCESS)
	{
		ERRverror("DVread_cgns:add_str_cell_data",ERR_INFO,
			"failed to set ncell_data\n");
		return (1);
	}
	cell_data_id = OMfind_subobj(cell_id, OMstr_to_name("cell_data"),
		OM_OBJ_RW);
	if(OMis_null_obj(cell_data_id))
	{
		ERRverror("DVread_cgns:add_str_cell_data",ERR_INFO,
			"can't locate cell_data_id object\n");
		return (1);
	}
	for(i=0; i<nFields; ++i)
	{
		sprintf(stat_str,"rd_cgns: zone %d data\nfield %d",zone,i+1);
		OMstatus_check(i*100/nFields+1,stat_str,&stop);
		if(stop) return (1);
		if(cg_field_info(f_indx, base, zone, solution, i+1, &type, name))
		{
			*cg_err_str = cg_get_error();
			return (1);
		}
		if(OMget_array_val(cell_data_id, i, &cell_data_el_id, OM_OBJ_RW)
			!= OM_STAT_SUCCESS)
		{
			ERRverror("DVread_cgns:add_str_cell_data",ERR_INFO,
				"can't get cell_data_el_id element object\n");
			return (0);
		}
		if(OMis_null_obj(cell_data_el_id))
		{
			ERRverror("DVread_cgns:add_str_cell_data",ERR_INFO,
				"can't locate cell_data_el_id object\n");
			return (1);
		}
		if(OMset_name_int_val(cell_data_el_id, OMstr_to_name("veclen"), 1) !=
			OM_STAT_SUCCESS)
		{
			ERRverror("DVread_cgns:add_str_cell_data",ERR_INFO,
				"failed to set veclen\n");
			return (1);
		}
		if(OMset_name_str_val(cell_data_el_id, OMstr_to_name("labels"), name) !=
			OM_STAT_SUCCESS)
		{
			ERRverror("DVread_cgns:add_str_cell_data",ERR_INFO,
				"failed to set labels string\n");
			return (1);
		}
		i_min[0] = 1 + rind[0];
		i_max[0] = vertex_size[0] + rind[0] - 1;
		if(index_dim > 1)
		{
			i_min[1] = 1 + rind[2];
			i_max[1] = vertex_size[1] + rind[2] - 1;
		}
		if(index_dim > 2)
		{
			i_min[2] = 1 + rind[4];
			i_max[2] = vertex_size[2] + rind[4] - 1;
		}
		values_id = OMfind_subobj(cell_data_el_id, OMstr_to_name("values"),
			OM_OBJ_RW);
		if(OMis_null_obj(values_id))
		{
			ERRverror("DVread_cgns:add_str_cell_data",ERR_INFO,
				"can't locate values_id object\n");
			return (1);
		}
		switch(type)
		{
			case Integer:
				if(OMset_data_type(values_id, OM_TYPE_INT) != OM_STAT_SUCCESS)
				{
					ERRverror("DVread_cgns:add_str_cell_data",
						ERR_INFO,
						"failed to set data type for values\n");
					return (1);
				}
				i_arr = OMret_array_ptr(values_id, OM_GET_ARRAY_RW, &size, &junk);
				if(i_arr == NULL)
				{
					ERRverror("DVread_cgns:add_str_cell_data",
						ERR_INFO,
						"failed to get values array\n");
					return (1);
				}
				if(cg_field_read(f_indx, base, zone, solution, name, Integer,
					i_min, i_max, (void *)i_arr))
				{
					*cg_err_str = cg_get_error();
					ARRfree(i_arr);
					return (1);
				}
				ARRfree(i_arr);
				break;
			case RealSingle:
			case RealDouble:
				if(OMset_data_type(values_id, OM_TYPE_FLOAT) != OM_STAT_SUCCESS)
				{
					ERRverror("DVread_cgns:add_str_cell_data",
						ERR_INFO,
						"failed to set data type for values\n");
					return (1);
				}
				f_arr = OMret_array_ptr(values_id, OM_GET_ARRAY_RW, &size, &junk);
				if(f_arr == NULL)
				{
					ERRverror("DVread_cgns:add_str_cell_data",
						ERR_INFO,
						"failed to get values array\n");
					return (1);
				}
				if(cg_field_read(f_indx, base, zone, solution, name, RealSingle,
					i_min, i_max, (void *)f_arr))
				{
					*cg_err_str = cg_get_error();
					ARRfree(f_arr);
					return (1);
				}
				ARRfree(f_arr);
				break;
		}
	}
	return (0);
}
static int add_str_cell_data ( OMobj_id fld_id , int base , int zone , int index_dim , int * vertex_size , int * rind , int solution , int f_indx , char * * cg_err_str ) { OMobj_id cell_id , cell_data_id , cell_data_el_id , values_id ; int i , nFields ; DataType_t type ; char name [ CGNS_NAME_MAX_LEN ] ; int i_min [ 3 ] , i_max [ 3 ] ; int size , junk ; int * i_arr ; float * f_arr ; char stat_str [ 100 ] ; int stop ; * cg_err_str = NULL ; if ( FLDget_cell_set ( fld_id , 0 , & cell_id ) != 1 ) { ERRverror ( " " , ERR_INFO , " \n " ) ; return ( 1 ) ; } if ( cg_nfields ( f_indx , base , zone , solution , & nFields ) ) { * cg_err_str = cg_get_error ( ) ; return ( 1 ) ; } if ( OMset_name_int_val ( cell_id , OMstr_to_name ( " " ) , nFields ) != OM_STAT_SUCCESS ) { ERRverror ( " " , ERR_INFO , " \n " ) ; return ( 1 ) ; } cell_data_id = OMfind_subobj ( cell_id , OMstr_to_name ( " " ) , OM_OBJ_RW ) ; if ( OMis_null_obj ( cell_data_id ) ) { ERRverror ( " " , ERR_INFO , " \n " ) ; return ( 1 ) ; } for ( i = 0 ; i < nFields ; ++ i ) { sprintf ( stat_str , " \n " , zone , i + 1 ) ; OMstatus_check ( i * 100 / nFields + 1 , stat_str , & stop ) ; if ( stop ) return ( 1 ) ; if ( cg_field_info ( f_indx , base , zone , solution , i + 1 , & type , name ) ) { * cg_err_str = cg_get_error ( ) ; return ( 1 ) ; } if ( OMget_array_val ( cell_data_id , i , & cell_data_el_id , OM_OBJ_RW ) != OM_STAT_SUCCESS ) { ERRverror ( " " , ERR_INFO , " \n " ) ; return ( 0 ) ; } if ( OMis_null_obj ( cell_data_el_id ) ) { ERRverror ( " " , ERR_INFO , " \n " ) ; return ( 1 ) ; } if ( OMset_name_int_val ( cell_data_el_id , OMstr_to_name ( " " ) , 1 ) != OM_STAT_SUCCESS ) { ERRverror ( " " , ERR_INFO , " \n " ) ; return ( 1 ) ; } if ( OMset_name_str_val ( cell_data_el_id , OMstr_to_name ( " " ) , name ) != OM_STAT_SUCCESS ) { ERRverror ( " " , ERR_INFO , " \n " ) ; return ( 1 ) ; } i_min [ 0 ] = 1 + rind [ 0 ] ; i_max [ 0 ] = vertex_size [ 0 ] + rind [ 0 ] - 1 ; if ( index_dim > 1 ) { i_min [ 1 ] = 1 + rind [ 2 ] ; i_max [ 1 ] = vertex_size [ 1 ] + rind [ 2 ] - 1 ; } if ( index_dim > 2 ) { i_min [ 2 ] = 1 + rind [ 4 ] ; i_max [ 2 ] = vertex_size [ 2 ] + rind [ 4 ] - 1 ; } values_id = OMfind_subobj ( cell_data_el_id , OMstr_to_name ( " " ) , OM_OBJ_RW ) ; if ( OMis_null_obj ( values_id ) ) { ERRverror ( " " , ERR_INFO , " \n " ) ; return ( 1 ) ; } switch ( type ) { case Integer : if ( OMset_data_type ( values_id , OM_TYPE_INT ) != OM_STAT_SUCCESS ) { ERRverror ( " " , ERR_INFO , " \n " ) ; return ( 1 ) ; } i_arr = OMret_array_ptr ( values_id , OM_GET_ARRAY_RW , & size , & junk ) ; if ( i_arr == NULL ) { ERRverror ( " " , ERR_INFO , " \n " ) ; return ( 1 ) ; } if ( cg_field_read ( f_indx , base , zone , solution , name , Integer , i_min , i_max , ( void * ) i_arr ) ) { * cg_err_str = cg_get_error ( ) ; ARRfree ( i_arr ) ; return ( 1 ) ; } ARRfree ( i_arr ) ; break ; case RealSingle : case RealDouble : if ( OMset_data_type ( values_id , OM_TYPE_FLOAT ) != OM_STAT_SUCCESS ) { ERRverror ( " " , ERR_INFO , " \n " ) ; return ( 1 ) ; } f_arr = OMret_array_ptr ( values_id , OM_GET_ARRAY_RW , & size , & junk ) ; if ( f_arr == NULL ) { ERRverror ( " " , ERR_INFO , " \n " ) ; return ( 1 ) ; } if ( cg_field_read ( f_indx , base , zone , solution , name , RealSingle , i_min , i_max , ( void * ) f_arr ) ) { * cg_err_str = cg_get_error ( ) ; ARRfree ( f_arr ) ; return ( 1 ) ; } ARRfree ( f_arr ) ; break ; } } return ( 0 ) ; }
read cell data, fill-in FLD
returns 0 if all OK, 1 otherwise
sets cg_err_str to error string if cgns read error
read cell data fill - in FLD returns 0 if all OK 1 otherwise sets cg_err_str to error string if cgns read error
/* find the cell_data array object */ /* get field info */ /* get cell_data array subobject id*/ /* set veclen */ /* set label */ /* prepare the selection range */ /* find the values array object */ /* set values data type */ /* get values array */ /* get values array */