Posted to tcl by jima at Sat May 06 20:47:02 GMT 2017view raw
- int NumArrayJTestCmd(
- ClientData dummy,
- Tcl_Interp *interp,
- int objc,
- Tcl_Obj *const *objv
- ) {
- if( objc != 2 ) {
- Tcl_WrongNumArgs( interp, 1, objv, "target" );
- return TCL_ERROR;
- }
- Tcl_Obj *tgtNA;
- tgtNA = objv[1];
- if( SetNumArrayFromAny( interp, tgtNA ) != TCL_OK ) {
- return TCL_ERROR;
- }
- NumArrayInfo *infoOftgtNA;
- infoOftgtNA = tgtNA->internalRep.twoPtrValue.ptr2;
- /*printf( "nDim of tgtNA : %d\n", infoOftgtNA->nDim );*/
- if( infoOftgtNA->nDim == 1 && infoOftgtNA->dims[0] == 0 ) {
- Tcl_SetResult( interp, "NA(tgtNA) empty.", NULL );
- return TCL_ERROR;
- }
- Tcl_Obj *resultObj;
- switch( infoOftgtNA->type ) {
- case NumArray_Int: {
- /* BEGIN I CASE. */
- NumArrayIterator itOftgtNA;
- NumArrayIteratorInitObj( NULL, tgtNA, &itOftgtNA );
- NaWideInt valOftgtNA;
- for(;
- !NumArrayIteratorFinished( &itOftgtNA );
- NumArrayIteratorAdvance( &itOftgtNA )
- ) {
- valOftgtNA = *((NaWideInt *) NumArrayIteratorDeRefPtr( &itOftgtNA ));
- printf( "==> %d\n" , valOftgtNA );
- }
- NumArrayIteratorFree( &itOftgtNA );
- /* END I CASE. */
- break;
- }
- case NumArray_Float64: {
- /* BEGIN D CASE. */
- NumArrayIterator itOftgtNA;
- NumArrayIteratorInitObj( NULL, tgtNA, &itOftgtNA );
- double valOftgtNA;
- for(;
- !NumArrayIteratorFinished( &itOftgtNA );
- NumArrayIteratorAdvance( &itOftgtNA )
- ) {
- valOftgtNA = *((double *) NumArrayIteratorDeRefPtr( &itOftgtNA ));
- printf( "==> %f\n" , valOftgtNA );
- }
- NumArrayIteratorFree( &itOftgtNA );
- /* END D CASE. */
- break;
- }
- case NumArray_Complex128: {
- /* BEGIN C CASE. */
- NumArrayIterator itOftgtNA;
- NumArrayIteratorInitObj( NULL, tgtNA, &itOftgtNA );
- NumArray_Complex valOftgtNA;
- for(;
- !NumArrayIteratorFinished( &itOftgtNA );
- NumArrayIteratorAdvance( &itOftgtNA )
- ) {
- valOftgtNA = *((NumArray_Complex *) NumArrayIteratorDeRefPtr( &itOftgtNA ));
- char cplxbuf7[NUMARRAY_COMPLEX_SPACE];
- NumArray_PrintComplex( valOftgtNA, cplxbuf7 );
- printf( "==> %s\n", cplxbuf7 );
- }
- NumArrayIteratorFree( &itOftgtNA );
- /* END C CASE. */
- break;
- }
- default:
- resultObj = Tcl_ObjPrintf(
- "J_SWITCH_INFO_TYPE: undefined function for datatype %s",
- NumArray_typename[infoOftgtNA->type]
- );
- Tcl_SetObjResult( interp, resultObj );
- return TCL_ERROR;
- }
- resultObj = Tcl_NewObj();
- Tcl_SetObjResult( interp, resultObj );
- return TCL_OK;
- }