xp_comm_proj/rd_cgns/structured.c
/* read coordinate data, fill-in FLD */
/* returns 0 if all OK, 1 otherwise */
/* sets cg_err_str to error string if cgns read error */
read coordinate data, fill-in FLD
returns 0 if all OK, 1 otherwise
sets cg_err_str to error string if cgns read error
read coordinate 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_coords(OMobj_id fld_id, int base, int zone, int index_dim, int phys_dim,
	int *vertex_size, int *rind, int *XYZ, int f_indx, char **cg_err_str)
{
	float *coords, *tmp;
	int	i_min[3], i_max[3];
	int	i, n, size;
	int	indx;
	char	coord1_name[12], coord2_name[12], coord3_name[12];
	char	stat_str[100];
	int	stop;
	*cg_err_str = NULL;
	if(FLDset_nspace(fld_id, phys_dim) != 1)
	{
		ERRverror("DVread_cgns:add_str_coords",ERR_INFO,
			"can't set nspace\n");
		return (1);
	}
	if(FLDset_ndim(fld_id, index_dim) != 1)
	{
		ERRverror("DVread_cgns:add_str_coords",ERR_INFO,
			"can't set ndim\n");
		return (1);
	}
	if(FLDset_dims(fld_id, vertex_size) != 1)
	{
		ERRverror("DVread_cgns:add_str_coords",ERR_INFO,
			"can't set dims\n");
		return (1);
	}
	n = vertex_size[0];
	i_min[0] = 1 + rind[0];
	i_max[0] = vertex_size[0] + rind[0];
	if(index_dim > 1)
	{
		n *= vertex_size[1];
		i_min[1] = 1 + rind[2];
		i_max[1] = vertex_size[1] + rind[2];
	}
	if(index_dim > 2)
	{
		n *= vertex_size[2];
		i_min[2] = 1 + rind[4];
		i_max[2] = vertex_size[2] + rind[4];
	}
	switch(phys_dim)
	{
		case 3:
			sprintf(coord1_name,"CoordinateX");
			sprintf(coord2_name,"CoordinateY");
			sprintf(coord3_name,"CoordinateZ");
			break;
		case 2:
			if(XYZ[0])
			{
				sprintf(coord1_name,"CoordinateX");
				if(XYZ[1])
					sprintf(coord2_name,"CoordinateY");
				else
					sprintf(coord2_name,"CoordinateZ");
			}
			else
			{
				sprintf(coord1_name,"CoordinateY");
				sprintf(coord2_name,"CoordinateZ");
			}
			break;
		case 1:
			if(XYZ[0])
				sprintf(coord1_name,"CoordinateX");
			else
			if(XYZ[1])
				sprintf(coord1_name,"CoordinateY");
			else
				sprintf(coord1_name,"CoordinateZ");
			break;
	}
	sprintf(stat_str,"rd_cgns: zone %d\ncoord X",zone);
	OMstatus_check(0.1,stat_str,&stop);
	if(stop) return (1);
	tmp = (float *)ARRalloc(NULL, DTYPE_FLOAT, n, NULL);
	if(tmp == NULL)
	{
		ERRverror("DVread_cgns:add_str_coords",ERR_INFO,
			"failed to alloc mem for tmp\n");
		return (1);
	}
	if(FLDget_coord(fld_id, &coords, &size, OM_GET_ARRAY_WR) != 1)
	{
		ARRfree(tmp);
		ERRverror("DVread_cgns:add_str_coords",ERR_INFO,
			"failed to get coords\n");
		return (1);
	}
	if(cg_coord_read(f_indx, base, zone, coord1_name, RealSingle,
		i_min, i_max, tmp))
	{
		ARRfree(tmp);
		ARRfree(coords);
		*cg_err_str = cg_get_error();
		return (1);
	}
	for(i=0, indx=0; i<n; ++i, indx+=phys_dim)
		coords[indx] = tmp[i];
	sprintf(stat_str,"rd_cgns: zone %d\ncoord Y",zone);
	OMstatus_check(33.3,stat_str,&stop);
	if(stop) return (1);
	if(phys_dim > 1)
	{
		if(cg_coord_read(f_indx, base, zone, coord2_name, RealSingle,
			i_min, i_max, tmp))
		{
			ARRfree(tmp);
			ARRfree(coords);
			*cg_err_str = cg_get_error();
			return (1);
		}
		for(i=0, indx=1; i<n; ++i, indx+=phys_dim)
			coords[indx] = tmp[i];
	}
	sprintf(stat_str,"rd_cgns: zone %d\ncoord Z",zone);
	OMstatus_check(66.6,stat_str,&stop);
	if(stop) return (1);
	if(phys_dim > 2)
	{
		if(cg_coord_read(f_indx, base, zone, coord3_name, RealSingle,
			i_min, i_max, tmp))
		{
			ARRfree(tmp);
			ARRfree(coords);
			*cg_err_str = cg_get_error();
			return (1);
		}
		for(i=0, indx=2; i<n; ++i, indx+=phys_dim)
			coords[indx] = tmp[i];
	}
	ARRfree(tmp);
	ARRfree(coords);
	sprintf(stat_str,"rd_cgns: zone %d\ncoord Z",zone);
	OMstatus_check(100.0,stat_str,&stop);
	if(stop) return (1);
	return (0);
}
static int add_str_coords ( OMobj_id fld_id , int base , int zone , int index_dim , int phys_dim , int * vertex_size , int * rind , int * XYZ , int f_indx , char * * cg_err_str ) { float * coords , * tmp ; int i_min [ 3 ] , i_max [ 3 ] ; int i , n , size ; int indx ; char coord1_name [ 12 ] , coord2_name [ 12 ] , coord3_name [ 12 ] ; char stat_str [ 100 ] ; int stop ; * cg_err_str = NULL ; if ( FLDset_nspace ( fld_id , phys_dim ) != 1 ) { ERRverror ( " " , ERR_INFO , " \n " ) ; return ( 1 ) ; } if ( FLDset_ndim ( fld_id , index_dim ) != 1 ) { ERRverror ( " " , ERR_INFO , " \n " ) ; return ( 1 ) ; } if ( FLDset_dims ( fld_id , vertex_size ) != 1 ) { ERRverror ( " " , ERR_INFO , " \n " ) ; return ( 1 ) ; } n = vertex_size [ 0 ] ; i_min [ 0 ] = 1 + rind [ 0 ] ; i_max [ 0 ] = vertex_size [ 0 ] + rind [ 0 ] ; if ( index_dim > 1 ) { n *= vertex_size [ 1 ] ; i_min [ 1 ] = 1 + rind [ 2 ] ; i_max [ 1 ] = vertex_size [ 1 ] + rind [ 2 ] ; } if ( index_dim > 2 ) { n *= vertex_size [ 2 ] ; i_min [ 2 ] = 1 + rind [ 4 ] ; i_max [ 2 ] = vertex_size [ 2 ] + rind [ 4 ] ; } switch ( phys_dim ) { case 3 : sprintf ( coord1_name , " " ) ; sprintf ( coord2_name , " " ) ; sprintf ( coord3_name , " " ) ; break ; case 2 : if ( XYZ [ 0 ] ) { sprintf ( coord1_name , " " ) ; if ( XYZ [ 1 ] ) sprintf ( coord2_name , " " ) ; else sprintf ( coord2_name , " " ) ; } else { sprintf ( coord1_name , " " ) ; sprintf ( coord2_name , " " ) ; } break ; case 1 : if ( XYZ [ 0 ] ) sprintf ( coord1_name , " " ) ; else if ( XYZ [ 1 ] ) sprintf ( coord1_name , " " ) ; else sprintf ( coord1_name , " " ) ; break ; } sprintf ( stat_str , " \n " , zone ) ; OMstatus_check ( 0.1 , stat_str , & stop ) ; if ( stop ) return ( 1 ) ; tmp = ( float * ) ARRalloc ( NULL , DTYPE_FLOAT , n , NULL ) ; if ( tmp == NULL ) { ERRverror ( " " , ERR_INFO , " \n " ) ; return ( 1 ) ; } if ( FLDget_coord ( fld_id , & coords , & size , OM_GET_ARRAY_WR ) != 1 ) { ARRfree ( tmp ) ; ERRverror ( " " , ERR_INFO , " \n " ) ; return ( 1 ) ; } if ( cg_coord_read ( f_indx , base , zone , coord1_name , RealSingle , i_min , i_max , tmp ) ) { ARRfree ( tmp ) ; ARRfree ( coords ) ; * cg_err_str = cg_get_error ( ) ; return ( 1 ) ; } for ( i = 0 , indx = 0 ; i < n ; ++ i , indx += phys_dim ) coords [ indx ] = tmp [ i ] ; sprintf ( stat_str , " \n " , zone ) ; OMstatus_check ( 33.3 , stat_str , & stop ) ; if ( stop ) return ( 1 ) ; if ( phys_dim > 1 ) { if ( cg_coord_read ( f_indx , base , zone , coord2_name , RealSingle , i_min , i_max , tmp ) ) { ARRfree ( tmp ) ; ARRfree ( coords ) ; * cg_err_str = cg_get_error ( ) ; return ( 1 ) ; } for ( i = 0 , indx = 1 ; i < n ; ++ i , indx += phys_dim ) coords [ indx ] = tmp [ i ] ; } sprintf ( stat_str , " \n " , zone ) ; OMstatus_check ( 66.6 , stat_str , & stop ) ; if ( stop ) return ( 1 ) ; if ( phys_dim > 2 ) { if ( cg_coord_read ( f_indx , base , zone , coord3_name , RealSingle , i_min , i_max , tmp ) ) { ARRfree ( tmp ) ; ARRfree ( coords ) ; * cg_err_str = cg_get_error ( ) ; return ( 1 ) ; } for ( i = 0 , indx = 2 ; i < n ; ++ i , indx += phys_dim ) coords [ indx ] = tmp [ i ] ; } ARRfree ( tmp ) ; ARRfree ( coords ) ; sprintf ( stat_str , " \n " , zone ) ; OMstatus_check ( 100.0 , stat_str , & stop ) ; if ( stop ) return ( 1 ) ; return ( 0 ) ; }
read coordinate data, fill-in FLD
returns 0 if all OK, 1 otherwise
sets cg_err_str to error string if cgns read error
read coordinate data fill - in FLD returns 0 if all OK 1 otherwise sets cg_err_str to error string if cgns read error
/* set-up cgns coordinate names used in file */ /* alloc temp array */ /* read 1st coordinate - fill-out FLD */ /* if 2D read 2nd coordinate */ /* if 3D read 3rd coordinate */ /* do I need this ? -TODO */ /*	if(FLDset_coord(fld_id, coords, size, OM_SET_ARRAY_COPY) != 1)
	{
		ARRfree(coords);
		ERRverror("DVread_cgns:add_str_coords",ERR_INFO,
			"failed to set coords\n");
		return (1);
	}*/