Posted to tcl by jima at Sat May 06 20:47:02 GMT 2017view raw

  1. int NumArrayJTestCmd(
  2. ClientData dummy,
  3. Tcl_Interp *interp,
  4. int objc,
  5. Tcl_Obj *const *objv
  6. ) {
  7.  
  8.  
  9. if( objc != 2 ) {
  10. Tcl_WrongNumArgs( interp, 1, objv, "target" );
  11. return TCL_ERROR;
  12. }
  13.  
  14. Tcl_Obj *tgtNA;
  15. tgtNA = objv[1];
  16. if( SetNumArrayFromAny( interp, tgtNA ) != TCL_OK ) {
  17. return TCL_ERROR;
  18. }
  19.  
  20. NumArrayInfo *infoOftgtNA;
  21. infoOftgtNA = tgtNA->internalRep.twoPtrValue.ptr2;
  22.  
  23. /*printf( "nDim of tgtNA : %d\n", infoOftgtNA->nDim );*/
  24. if( infoOftgtNA->nDim == 1 && infoOftgtNA->dims[0] == 0 ) {
  25. Tcl_SetResult( interp, "NA(tgtNA) empty.", NULL );
  26. return TCL_ERROR;
  27. }
  28.  
  29. Tcl_Obj *resultObj;
  30.  
  31.  
  32.  
  33. switch( infoOftgtNA->type ) {
  34. case NumArray_Int: {
  35. /* BEGIN I CASE. */
  36.  
  37. NumArrayIterator itOftgtNA;
  38. NumArrayIteratorInitObj( NULL, tgtNA, &itOftgtNA );
  39. NaWideInt valOftgtNA;
  40.  
  41. for(;
  42. !NumArrayIteratorFinished( &itOftgtNA );
  43. NumArrayIteratorAdvance( &itOftgtNA )
  44. ) {
  45.  
  46. valOftgtNA = *((NaWideInt *) NumArrayIteratorDeRefPtr( &itOftgtNA ));
  47.  
  48.  
  49. printf( "==> %d\n" , valOftgtNA );
  50.  
  51. }
  52.  
  53. NumArrayIteratorFree( &itOftgtNA );
  54.  
  55. /* END I CASE. */
  56. break;
  57. }
  58. case NumArray_Float64: {
  59. /* BEGIN D CASE. */
  60.  
  61. NumArrayIterator itOftgtNA;
  62. NumArrayIteratorInitObj( NULL, tgtNA, &itOftgtNA );
  63. double valOftgtNA;
  64.  
  65. for(;
  66. !NumArrayIteratorFinished( &itOftgtNA );
  67. NumArrayIteratorAdvance( &itOftgtNA )
  68. ) {
  69.  
  70. valOftgtNA = *((double *) NumArrayIteratorDeRefPtr( &itOftgtNA ));
  71.  
  72.  
  73. printf( "==> %f\n" , valOftgtNA );
  74.  
  75. }
  76.  
  77. NumArrayIteratorFree( &itOftgtNA );
  78.  
  79. /* END D CASE. */
  80. break;
  81. }
  82. case NumArray_Complex128: {
  83. /* BEGIN C CASE. */
  84.  
  85. NumArrayIterator itOftgtNA;
  86. NumArrayIteratorInitObj( NULL, tgtNA, &itOftgtNA );
  87. NumArray_Complex valOftgtNA;
  88.  
  89. for(;
  90. !NumArrayIteratorFinished( &itOftgtNA );
  91. NumArrayIteratorAdvance( &itOftgtNA )
  92. ) {
  93.  
  94. valOftgtNA = *((NumArray_Complex *) NumArrayIteratorDeRefPtr( &itOftgtNA ));
  95.  
  96.  
  97. char cplxbuf7[NUMARRAY_COMPLEX_SPACE];
  98. NumArray_PrintComplex( valOftgtNA, cplxbuf7 );
  99. printf( "==> %s\n", cplxbuf7 );
  100.  
  101. }
  102.  
  103. NumArrayIteratorFree( &itOftgtNA );
  104.  
  105. /* END C CASE. */
  106. break;
  107. }
  108. default:
  109. resultObj = Tcl_ObjPrintf(
  110. "J_SWITCH_INFO_TYPE: undefined function for datatype %s",
  111. NumArray_typename[infoOftgtNA->type]
  112. );
  113. Tcl_SetObjResult( interp, resultObj );
  114. return TCL_ERROR;
  115. }
  116.  
  117.  
  118.  
  119. resultObj = Tcl_NewObj();
  120. Tcl_SetObjResult( interp, resultObj );
  121.  
  122. return TCL_OK;
  123. }
  124.