Ejemplo n.º 1
0
/**
 * Implementation of the class function. Leaves the value of the variable on
 * the stack.
 */
void CGEN_PROTECTED CVar_Exec(CVar *_this)
{
  switch (_this->m_nType)
  {
    case T_BOOL:
      CDlpObject_MicPutB(BASEINST(_this),_this->m_bBVal);
      break;
    case T_DOUBLE:
    case T_COMPLEX:
      CDlpObject_MicPutN(BASEINST(_this),_this->m_nNVal);
      break;
    case T_STRING:
      CDlpObject_MicPutS(BASEINST(_this),_this->m_lpsSVal);
      break;
    case T_INSTANCE:
      CDlpObject_MicPutI(BASEINST(_this),BASEINST(_this)->m_iAliasInst);
      break;
    case T_RDOUBLE: {
      _this->m_nInd  = (INT32)(rand()/_this->m_nNorm);
      _this->m_nNVal = CMPLX(_this->m_nLow+_this->m_nInd*_this->m_nDelta);
      CDlpObject_MicPutN(BASEINST(_this),_this->m_nNVal);
      break; }
    case T_RDDATA:
      _this->m_nInd  = (INT32)(rand()/_this->m_nNorm);
      _this->m_nNVal = CData_Cfetch(AS(CData,_this->m_idRndSet),_this->m_nInd, _this->m_nIcomp);
      CDlpObject_MicPutN(BASEINST(_this),_this->m_nNVal);
      break;
    case T_RSDATA:
      _this->m_nInd = (INT32)(rand()/_this->m_nNorm);
      CVar_Sset(_this,(char*)CData_XAddr(AS(CData,_this->m_idRndSet),_this->m_nInd,_this->m_nIcomp));
      _this->m_nType = T_RSDATA;
      CDlpObject_MicPutS(BASEINST(_this),_this->m_lpsSVal);
      break;
    default: DLPASSERT(FMSG("Unknown variable type"));
  }
}
Ejemplo n.º 2
0
/**
 * Prints one block of the instance in vector mode (standard).
 */
INT32 CGEN_PRIVATE CData_PrintVectors_Block
(
  CData* _this,                                                                 /* Pointer to data instance          */
  INT32   nBlock                                                                 /* Block index (<0: ignore blocks)   */
)                                                                               /* Returns number of lines printed   */
{
  INT32 i      = 0;                                                              /* Universal loop counter            */
  INT32 nR     = 0;                                                              /* Current record                    */
  INT32 nR_    = 0;                                                              /* First record to be printed        */
  INT32 nR0    = 0;                                                              /* First record of current page      */
  INT32 nSR    = 0;                                                              /* Number of records of currenr page */
  INT32 nXR    = 0;                                                              /* Last record to print plus one     */
  INT32 nC     = 0;                                                              /* Current component                 */
  INT32 nXC    = 0;                                                              /* Number of components              */
  INT32 nWI    = 0;                                                              /* Component index column width      */
  INT32 nW0    = 0;                                                              /* Head column width                 */
  INT32 nW     = 0;                                                              /* Column width                      */
  INT32 nP     = 0;                                                              /* Current page                      */
  INT32 nPps   = 0;                                                              /* Pages per screen                  */
  INT32 nL     = 0;                                                              /* Line counter                      */
  BOOL bPur   = FALSE;                                                          /* Print physical record unit flag   */
  BOOL bPuc   = FALSE;                                                          /* Print physical component unit flg.*/
  FLOAT64 nBuf = 0.;                                                             /* Double buffer                     */
  char   sBuf[L_SSTR+1];                                                        /* String buffer                     */

  /* Validate */                                                                /* --------------------------------- */
  if (nBlock>=CData_GetNBlocks(_this)) return 0;                                /* Requested block does not exist    */

  /* Initialize */                                                              /* --------------------------------- */
  nR_ = nBlock>=0 ? CData_GetNRecsPerBlock(_this)*nBlock : 0;                   /* Get first record to print         */
  nXR = nBlock>=0 ? nR_+CData_GetNRecsPerBlock(_this) : CData_GetNRecs(_this);  /* Get number of records             */
  nXC = CData_GetNComps(_this);                                                 /* Get number of components          */
  bPur = _this->m_lpTable->m_fsr!=1. && _this->m_lpTable->m_fsr!=0.;            /* Displaying physical record units? */
  bPuc = _this->m_nCinc!=1. && _this->m_nCinc!=0.;                              /* Displaying physical comp. units?  */
  nPps = dlp_maxprintlines()/(nXC+4);                                           /* Compute no. of pages per sceeen   */

  /* Print vectors */                                                           /* --------------------------------- */
  if (nBlock>=0)                                                                /* Printing blockwise?               */
  {                                                                             /* >>                                */
    printf("\n   Block %ld (offset %ld)",(long)nBlock,(long)nR_);               /*   Show current block index        */
    dlp_inc_printlines(1);  nL++;                                               /*   Adjust number of printed lines  */
  }                                                                             /* <<                                */
  for (nR0=nR_; nR0<nXR; )                                                      /* Loop over records                 */
  {                                                                             /* >>                                */
    CData_PrintVectors_GetColWidth(_this,nR0,0,&nWI,&nW0,&nW);                  /*   Comp. head and data col. widths */
    nSR = (dlp_maxprintcols()-nWI-nW0-4)/(nW+1);                                /*   Number of columns to print      */
    if (nR0+nSR>nXR) nSR = nXR-nR0;                                             /*   No more than there are records! */

    /* Print record header */                                                   /*   - - - - - - - - - - - - - - - - */
    if (bPur)                                                                   /*   Display physical record units?  */
    {                                                                           /*   >>                              */
      printf("\n %s ->",__pad(strcpy(sBuf,_this->m_lpRunit),nW0+nWI,'r'));      /*     Print name of physical unit   */
      for (nR=nR0; nR<nR0+nSR; nR++)                                            /*     Loop over remaining records   */
      {                                                                         /*     >>                            */
        nBuf = _this->m_lpTable->m_ofs + (nR-nR_)*_this->m_lpTable->m_fsr;      /*       Compute abscissa value      */
        __sprintx(sBuf,&nBuf,T_DOUBLE,_this->m_bExact);                         /*       Print to a string           */
        printf("%s ",__pad(sBuf,nW,'r'));                                       /*       Format and print to screen  */
      }                                                                         /*     <<                            */
      dlp_inc_printlines(1); nL++;                                              /*     Adjust number of printed lines*/
    }                                                                           /*   <<                              */
    sBuf[0]='\0';                                                               /*   Clear string buffer             */
    if (bPuc) sprintf(sBuf,"%s| ",_this->m_lpCunit);                            /*   Print phys. comp. unit name...  */
    printf("\n %s",__pad(sBuf,nW0+nWI+3,'r'));                                  /*   ... or empty string             */
    for (nR=nR0; nR<nR0+nSR; nR++)                                              /*   Loop over remaining records     */
    {                                                                           /*   >>                              */
      i=nR-nR_; __sprintx(sBuf,&i,T_INT,_this->m_bExact);                       /*     Print record index to a str.  */
      printf("%s%c",__pad(sBuf,nW,'r'),CData_RecIsMarked(_this,nR)?'*':' ');    /*     Format and print to screen    */
    }                                                                           /*   <<                              */
    sBuf[0]='\0';                                                               /*   Clear string buffer             */
    if (bPuc) sprintf(sBuf,"%c ",bPuc?'v':' ');                                 /*   Print down arrow ...            */
    printf("\n %s",__pad(sBuf,nW0+nWI+3,'r'));                                  /*   ... or empty string             */
    sBuf[0]='\0'; for (i=0; i<nW; i++) sBuf[i]='.'; sBuf[i]='\0';               /*   Make horizonal delimiter        */
    for (nR=nR0; nR<nR0+nSR; nR++) printf("%s ",sBuf);                          /*   Print one per vector            */
    dlp_inc_printlines(2);  nL+=2;                                              /*   Adjust number of printed lines  */

    /* Print data */                                                            /*   - - - - - - - - - - - - - - - - */
    for (nC=0; nC<nXC; )                                                        /*   Loop over components            */
    {                                                                           /*   >>                              */
      __sprintx(sBuf,&nC,T_INT,_this->m_bExact);                                /*     Print comp. index to a string */
      printf("\n%c%s ",                                                         /*     Format and print to screen    */
        CData_CompIsMarked(_this,nC)?'*':' ',__pad(sBuf,nWI,'r'));              /*     | (incl. "*" for "marked")    */
      if (bPuc && dlp_is_numeric_type_code(CData_GetCompType(_this,nC)))        /*     Display ordinate value?       */
      {                                                                         /*     >>                            */
        nBuf = _this->m_nCofs + nC*_this->m_nCinc;                              /*       Compute it                  */
        __sprintx(sBuf,&nBuf,T_DOUBLE,_this->m_bExact);                         /*       Print it to a string        */
      }                                                                         /*     <<                            */
      else strcpy(sBuf,CData_GetCname(_this,nC));                               /*     else display component name   */
      printf("%s: ",__pad(dlp_strtrimleft(dlp_strtrimright(sBuf)),nW0,'r'));    /*     Format and print to screen    */
      for (nR=nR0; nR<nR0+nSR; nR++)                                            /*     Loop over remaining records   */
      {                                                                         /*     >>                            */
        __sprintx(sBuf,CData_XAddr(_this,nR,nC),                                /*       Print cell value to a str.  */
            CData_GetCompType(_this,nC),_this->m_bExact);                       /*         |                         */
        if (dlp_is_symbolic_type_code(CData_GetCompType(_this,nC)))             /*       Is string value             */
          if ((INT32)dlp_strlen(sBuf)>nW)                                        /*         Will not fit in column    */
            dlp_strabbrv(sBuf,sBuf,nW);                                         /*           Abbreviate it           */
        if (dlp_is_numeric_type_code(CData_GetCompType(_this,nC)))              /*       Is numeric value            */
          if (_this->m_bNz && CMPLX_EQUAL(CData_Cfetch(_this,nR,nC),CMPLX(0.)))
            dlp_strcpy(sBuf,"-");
        printf("%s%c",__pad(sBuf,nW,'r'),                                       /*       Format and print to screen  */
          CData_CellIsMarked(_this,nR*CData_GetNComps(_this)+nC)?'*':' ');      /*       | (incl. "*" for "marked")  */
      }                                                                         /*     <<                            */
      dlp_inc_printlines(1); nL++;                                              /*     Adjust number of printed lines*/

      /* Break component listing */                                             /*     - - - - - - - - - - - - - - - */
      if (nPps==0)                                                              /*     Not all comps. fit on screen  */
      {                                                                         /*     >>                            */
        sprintf(sBuf,"component (0..%ld), cancel -3",(long)nXC-1);              /*       Make user hint              */
        if ((nC=dlp_printstop_nix(nC,sBuf,NULL))==-1) break;                    /*       Break listing               */
        if (nC< -2 ) return -1;                                                 /*       Cancelled by user           */
        if (nC>=nXC) break;                                                     /*       No more components -> break */
      }                                                                         /*     <<                            */
      else nC++;                                                                /*     No breaking -> count comps.   */
    }                                                                           /*   <<                              */
    nR0+=nSR;                                                                   /*   First record on next page       */
    nP++;                                                                       /*   Count pages                     */
    if (nR0<nXR)                                                                /*   There are more records          */
    {                                                                           /*   >>                              */
      printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols());           /*     Print a separator             */
      dlp_inc_printlines(1); nL++;                                              /*     Adjust number of printed lines*/
    }                                                                           /*   <<                              */

    /* Break record listing */                                                  /*   - - - - - - - - - - - - - - - - */
    if (((nPps>0 && nP>=nPps) || nPps==0) && nR0<nXR)                           /*   Complicated break condition :)  */
    {                                                                           /*   >>                              */
      dlp_inc_printlines(dlp_maxprintlines());                                  /*     Do stop right here            */
        sprintf(sBuf,"record (%ld..%ld)%s",(long)nR_,(long)nXR-1,               /*     Make user hint                */
          nBlock>=0?", cancel -3":"");                                          /*     |                             */
      if ((nR0=dlp_printstop_nix(--nR0,sBuf,NULL))==-1) break;                  /*     Break listing                 */
      if (nR0< -2 ) return -1;                                                  /*     Cancelled by user             */
      if (nR0< nR_) nR0=nR_;                                                    /*     No previous blocks, please!   */
      if (nR0>=nXR) break;                                                      /*     No more records -> break      */
      nP=0;                                                                     /*     Reset page counter            */
    }                                                                           /*   <<                              */
  }                                                                             /* <<                                */

  return nL;                                                                    /* Return number of printed lines    */
}