preload

Math primitives 3 (WinRunner, TSL)

Posted by Albert Gareev on Apr 19, 2007 | Categories: MathSource code

Service Functions – Math / WinRunner

Convert matrix to text table

public function mx_array_2_table(inout mxTable[], inout dtTable[], in separator, in skip_empty) {
 auto col_count, row_count, i,j;
 auto row, s_value;

 if (skip_empty != TRUE) skip_empty = FALSE;
 if (separator == "") separator = "\t";
 
 col_count = mxTable[0, "sys", "colCount"];   
 row_count = mxTable[0, "sys", "rowCount"];   

 delete dtTable[];
 row = 0;
 for (i=1;i<=row_count;i++) {
  s_value = "";
  for (j=1;j<=col_count;j++) {
   if ((skip_empty) && (mxTable[i,j] == "")) continue;
   s_value = str_list_add(s_value, mxTable[i,j], separator);
   }
  if ((skip_empty) && (s_value == "")) continue;
  row++;
  dtTable[row] = s_value; 
  }
 
 dtTable[0] = row;  
 return(E_OK);
}

Find a row in matrix by key value

public function mx_find_regex_row(inout mxTable[], in item_regex, in col, out item, out item_row) {
 auto rc, i;
 auto col_count, row_count;
 
 col_count = mxTable[0, "sys", "colCount"];   
 row_count = mxTable[0, "sys", "rowCount"];   
 
 if (col > col_count) return(E_GENERAL_ERROR);
 
 for (i=1;i<=row_count;i++) {
  rc = match(mxTable[i,col], item_regex);
  if (rc>0) {
   item = mxTable[i,col];
   item_row = i;
   return(E_OK);
   }
  }

 return(E_NOT_FOUND);
}

Find a column in matrix by key value

public function mx_find_regex_col(inout mxTable[], in item_regex, in row, out item, out item_col) {
 auto rc, i;
 auto col_count, row_count;
 
 col_count = mxTable[0, "sys", "colCount"];   
 row_count = mxTable[0, "sys", "rowCount"];   
 
 if (row > row_count) return(E_GENERAL_ERROR);
 
 for (i=1;i<=col_count;i++) {
  rc = match(mxTable[row,i], item_regex);
  if (rc>0) {
   item = mxTable[row,i];
   item_col = i;
   return(E_OK);
   }
  }

 return(E_NOT_FOUND);
}


Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.