Example #1
0
int TSOut::PutUInt(const uint& UInt){
  return PutStr(TUInt::GetStr(UInt));
}
Example #2
0
int TSOut::PutInt(const int& Int){
  return PutStr(TInt::GetStr(Int));
}
Example #3
0
int TSOut::PutInt(const int& Int, const char* FmtStr){
  return PutStr(TInt::GetStr(Int, FmtStr));
}
Example #4
0
void main( void )
{
	int Done = FALSE;
	ULONG sig;
	static STRPTR styleoptions[] = { "IRC", "Email", "HTML", NULL };
	if( !( MUIMasterBase = OpenLibrary( MUIMASTER_NAME, 19 ) ) )
		return;

	if( app = ApplicationObject,
		MUIA_Application_Title, "TextInputDemo",
		MUIA_Application_Version, "$VER: TextInput Demo 2.0",
		MUIA_Application_Copyright, "© 1997-99 by Oliver Wagner, All Rights Reserved",
		MUIA_Application_Author, "Oliver Wagner",
		MUIA_Application_Description, "Demo for Textinput.mcc",
		MUIA_Application_Base, "TEXTINPUT-DEMO",
		SubWindow, win = WindowObject,
			MUIA_Window_ID, 42,
			MUIA_Window_Title, "TextInput Demo",
			WindowContents, VGroup,
				Child, HGroup,
					Child, Label1( "Style:" ),
					Child, Cycle( styleoptions ),
				End,
				Child, HGroup, GroupFrameT( "Single line" ),
					Child, ColGroup( 2 ),
						Child, Label2( "Input:" ),
						Child, ti1 = TextinputObject, StringFrame, MUIA_CycleChain, 1,
							MUIA_ControlChar, 'a',
							MUIA_Textinput_Multiline, FALSE, 
							MUIA_Textinput_Contents, C1,
						End,
						Child, Label2( "NoInput:" ),
						Child, ti2 = TextinputObject, TextFrame, 
							MUIA_Background, MUII_TextBack,
							MUIA_Textinput_NoInput, TRUE,
							MUIA_Textinput_Contents, C1,
						End,
					End,
				End,
				Child, VGroup, GroupFrameT( "Multi line with scroll" ),
					Child, timl1 = TextinputscrollObject, StringFrame, MUIA_CycleChain, 1,
						MUIA_ControlChar, 'b',
						MUIA_Textinput_Multiline, TRUE, 
						MUIA_Textinput_Contents, C2,
					End,
					Child, bt_get = SimpleButton( "Get contents (to shell window)" ),
				End,
				Child, HGroup, GroupFrameT( "NoInput multi line with Scroll" ),
					Child, timl2 = TextinputscrollObject, TextFrame, MUIA_Background,MUII_TextBack,MUIA_CycleChain, 1,
						MUIA_ControlChar, 'c',
						MUIA_Textinput_NoInput, TRUE,
						MUIA_Textinput_Multiline, TRUE, 
						MUIA_Textinput_AutoExpand, TRUE,
						MUIA_Textinput_Contents, C2,
						MUIA_Textinput_MinVersion, 12,
						MUIA_Textinput_WordWrap, 60,
					End,
				End,
				Child, HGroup, GroupFrameT( "Old stringgadget" ),
					Child, String( C1, 256 ),
				End,
			End,
		End,
	End )
	{
		DoMethod( win, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
			app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit
		);
		DoMethod( bt_get, MUIM_Notify, MUIA_Pressed, FALSE,
			app, 2, MUIM_Application_ReturnID, 2
		);
		DoMethod( ti1, MUIM_Notify, MUIA_String_Contents, MUIV_EveryTime,
			ti2, 3, MUIM_Set, MUIA_Text_Contents, MUIV_TriggerValue
		);
		DoMethod( timl1, MUIM_Notify, MUIA_String_Contents, MUIV_EveryTime,
			timl2, 3, MUIM_Set, MUIA_Text_Contents, MUIV_TriggerValue
		);
		DoMethod( ti1, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
			ti1, 3, MUIM_Set, MUIA_Textinput_Contents, ""
		);
		set( win, MUIA_Window_Open, TRUE );
		while( !Done )
		{
			LONG id;
			id = DoMethod( app, MUIM_Application_Input, &sig );
			switch( id )
			{
				case MUIV_Application_ReturnID_Quit:
					Done = TRUE;
				case 2:
					{
						char *p;
						get( timl1, MUIA_Textinput_Contents, &p );
						PutStr( ">>>>>\n" );
						PutStr( p );
						PutStr( "<<<<<\n" );
					}
					break;
			}
			if( sig )
				if( Wait( sig | SIGBREAKF_CTRL_C ) & SIGBREAKF_CTRL_C )
					Done = TRUE;
		}
		MUI_DisposeObject( app );
	}
	CloseLibrary( MUIMasterBase );

}
Example #5
0
int TSOut::PutBool(const bool& Bool){
  return PutStr(TBool::GetStr(Bool));
}
Example #6
0
int TSOut::PutFlt(const double& Flt, const char* FmtStr){
  return PutStr(TFlt::GetStr(Flt, FmtStr));
}
Example #7
0
int TSOut::PutStr(const TStr& Str, const char* FmtStr){
  return PutStr(TStr::GetStr(Str, FmtStr));
}
Example #8
0
int TSOut::PutFlt(const double& Flt){
  return PutStr(TFlt::GetStr(Flt));
}
Example #9
0
int TSOut::PutUInt(const uint& UInt, const char* FmtStr){
  return PutStr(TUInt::GetStr(UInt, FmtStr));
}
int main(int argc, char **argv) {
  PutStr("Hello world!\n");
  return 0;
}
Example #11
0
bool CnsMgr::GetLine(std::string *str, uint8_t sx, uint8_t sy, uint16_t att, const Event& end, int8_t max, char show)
{
	if(!initialized)
		return false;
	if(sx > WND_W || sy >= WND_H) // > for sx, so that u can use it to get enter when at end of line
		return false;
	
	if(max == -1)
		max = WND_H - sx;
	Event my_end = end;
	if(my_end.type != EVT_KEY)
		my_end = KEY_EVENT_ENTER;
		
	std::string print = std::string(max, ' ');
	std::string read = "";	
	
	uint8_t xpos = sx;
	
	if(xpos < sx + print.size())
		Put(CHAR_BLOCK, xpos, sy, att);
	Flip();

	Event ev;
	while(true)
	{
		ZeroMemory(&ev, sizeof(ev));
		if(!GetNextEvent(ev))
			return false;
		
		if(ev.type != EVT_KEY)
			continue;
		if(ev.val == my_end.val && my_end.meta == (my_end.meta & ev.meta))
			break;
		if(!(ev.meta & EVM_KEY_DOWN || ev.meta & EVM_KEY_HOLD))
			continue;
		
		if(ev.val == EVV_KEY_BACKSPACE)
		{
			if(!read.empty())
			{
				read = read.substr(0, read.size()-1);
				print[xpos-sx] = ' ';
				xpos--;
				PutStr(print, sx, sy, att);
				if(xpos < sx + print.size())
					Put(CHAR_BLOCK, xpos, sy, att);
				Flip();
				continue;
			}
			continue;
		}
		
		if(xpos >= sx + print.size())
			continue;

		char ch = KeyEventToChar(ev);
		if(ch == 0 || ch == '\n' || ch == '\t')
			continue;
		read += ch;
		if(show == 0)
			print[xpos-sx] = ch;
		else
			print[xpos-sx] = show;
		xpos++;
		PutStr(print, sx, sy, att);
		if(xpos < sx + print.size())
			Put(CHAR_BLOCK, xpos, sy, att);
		Flip();
	}
	
	if(str != NULL)
		*str = read;
	return true;
}
Example #12
0
int main (int argc, char *argv[])
{
  char *oname = nullptr, *dot = nullptr, *filename = nullptr;
  char str[32];

  const char* ext=EXT;

  int
    n, n1,n2,err,
    num_axes,num_blocks,
    num_side_sets,num_node_sets,num_time_steps,
    num_info_lines,num_global_vars,
    num_nodal_vars,num_element_vars,num_nodeset_vars, num_sideset_vars;

  size_t num_nodes = 0;
  size_t num_elements = 0;

  int mat_version = 73;

  /* process arguments */
  for (int j=1; j< argc; j++){
    if ( strcmp(argv[j],"-t")==0){    /* write text file (*.m) */
      del_arg(&argc,argv,j);
      textfile=1;
      j--;
      continue;
    }
    if ( strcmp(argv[j],"-h")==0){    /* write help info */
      del_arg(&argc,argv,j);
      usage();
      exit(1);
    }
    if ( strcmp(argv[j],"-d")==0){    /* write help info */
      del_arg(&argc,argv,j);
      j--;
      debug = 1;
      continue;
    }
    if ( strcmp(argv[j],"-v73")==0){    /* Version 7.3 */
      del_arg(&argc,argv,j);
      mat_version = 73;
      j--;
      continue;
    }
    // This matches the option used in matlab
    if ( (strcmp(argv[j],"-v7.3")==0) || (strcmp(argv[j],"-V7.3")==0)){    /* Version 7.3 */
      del_arg(&argc,argv,j);
      mat_version = 73;
      j--;
      continue;
    }
    if ( strcmp(argv[j],"-v5")==0){    /* Version 5 (default) */
      del_arg(&argc,argv,j);
      mat_version = 50;
      j--;
      continue;
    }
    if ( strcmp(argv[j],"-o")==0){    /* specify output file name */
      del_arg(&argc,argv,j);
      if ( argv[j] ){
        oname=(char*)calloc(strlen(argv[j])+10,sizeof(char));
        strcpy(oname,argv[j]);
        del_arg(&argc,argv,j);
        std::cout << "output file: " << oname << "\n";
      }
      else {
        std::cerr << "ERROR: Invalid output file specification.\n";
        return 2;
      }
      j--;

      continue;
    }
  }

  /* QA Info */
  printf("%s: %s, %s\n", qainfo[0], qainfo[2], qainfo[1]);

  /* usage message*/
  if (argc != 2){
    usage();
    exit(1);
  }

  /* open output file */
  if ( textfile )
    ext=".m";

  if ( !oname ){
    filename = (char*)malloc( strlen(argv[1])+10);
    strcpy(filename,argv[1]);
    dot=strrchr(filename,'.');
    if ( dot ) *dot='\0';
    strcat(filename,ext);
  }
  else {
    filename=oname;
  }

  if ( textfile ){
    m_file = fopen(filename,"w");
    if (!m_file ){
      std::cerr << "ERROR: Unable to open " << filename << "\n";
      exit(1);
    }
  }
  else {
    if (mat_version == 50) {
      mat_file = Mat_CreateVer(filename, nullptr, MAT_FT_MAT5);
    }
    else if (mat_version == 73) {
      mat_file = Mat_CreateVer(filename, nullptr, MAT_FT_MAT73);
    }

    if (mat_file == nullptr) {
      std::cerr << "ERROR: Unable to create matlab file " << filename << "\n";
      exit(1);
    }
  }

  /* word sizes */
  int cpu_word_size=sizeof(double);
  int io_word_size=0;

  /* open exodus file */
  float exo_version;
  int exo_file=ex_open(argv[1],EX_READ,&cpu_word_size,&io_word_size,&exo_version);
  if (exo_file < 0){
    std::cerr << "ERROR: Cannot open " << argv[1] << "\n";
    exit(1);
  }

  /* print */
  std::cout << "\ttranslating " << argv[1] << " to " << filename << "...\n";

  /* read database paramters */
  char *line=(char *) calloc ((MAX_LINE_LENGTH+1),sizeof(char));
  ex_get_init(exo_file,line,
              &num_axes,&num_nodes,&num_elements,&num_blocks,
              &num_node_sets,&num_side_sets);
  num_info_lines = ex_inquire_int(exo_file,EX_INQ_INFO);
  num_time_steps = ex_inquire_int(exo_file,EX_INQ_TIME);
  ex_get_variable_param(exo_file,EX_GLOBAL,&num_global_vars);
  ex_get_variable_param(exo_file,EX_NODAL,&num_nodal_vars);
  ex_get_variable_param(exo_file,EX_ELEM_BLOCK,&num_element_vars);
  ex_get_variable_param(exo_file,EX_NODE_SET,&num_nodeset_vars);
  ex_get_variable_param(exo_file,EX_SIDE_SET,&num_sideset_vars);


  /* export paramters */
  PutInt("naxes",  num_axes);
  PutInt("nnodes", num_nodes);
  PutInt("nelems", num_elements);
  PutInt("nblks",  num_blocks);
  PutInt("nnsets", num_node_sets);
  PutInt("nssets", num_side_sets);
  PutInt("nsteps", num_time_steps);
  PutInt("ngvars", num_global_vars);
  PutInt("nnvars", num_nodal_vars);
  PutInt("nevars", num_element_vars);
  PutInt("nnsvars",num_nodeset_vars);
  PutInt("nssvars",num_sideset_vars);

  /* allocate -char- scratch space*/
  int nstr2 = num_info_lines;
  nstr2 = std::max(nstr2, num_blocks);
  nstr2 = std::max(nstr2, num_node_sets);
  nstr2 = std::max(nstr2, num_side_sets);
  char **str2 = get_exodus_names(nstr2, 512);

  /* title */
  PutStr("Title",line);

  /* information records */
  if (num_info_lines > 0 ){
    ex_get_info(exo_file,str2);
    std::string ostr;
    for (int i=0;i<num_info_lines;i++) {
      if (strlen(str2[i]) > 0) {
        ostr += str2[i];
        ostr += "\n";
      }
    }
    PutStr("info",ostr.c_str());
    ostr = "";
    for (int i=0;i<num_info_lines;i++) {
      if (strlen(str2[i]) > 0 && strncmp(str2[i],"cavi",4)==0) {
        ostr += str2[i];
        ostr += "\n";
      }
    }
    PutStr("cvxp",ostr.c_str());
  }

  /* nodal coordinates */
  {
    if (debug) {logger("Coordinates");}
    std::vector<double> x, y, z;
    x.resize(num_nodes);
    if (num_axes >= 2) y.resize(num_nodes);
    if (num_axes == 3) z.resize(num_nodes);
    ex_get_coord(exo_file,TOPTR(x), TOPTR(y), TOPTR(z));
    PutDbl("x0", num_nodes, 1, TOPTR(x));
    if (num_axes >= 2) {
      PutDbl("y0", num_nodes, 1, TOPTR(y));
    }
    if (num_axes == 3){
      PutDbl("z0",num_nodes,1, TOPTR(z));
    }
  }

  /* side sets */
  std::vector<int> num_sideset_sides(num_side_sets);
  std::vector<int> ids;
  if (num_side_sets > 0) {
    if (debug) {logger("Side Sets");}
    ids.resize(num_side_sets);
    ex_get_ids(exo_file,EX_SIDE_SET,TOPTR(ids));
    PutInt( "ssids",num_side_sets, 1,TOPTR(ids));
    std::vector<int> nssdfac(num_side_sets);
    std::vector<int> iscr;
    std::vector<int> jscr;
    std::vector<double> scr;
    std::vector<int> elem_list;
    std::vector<int> side_list;
    std::vector<int> junk;
    for (int i=0;i<num_side_sets;i++) {
      ex_get_set_param(exo_file,EX_SIDE_SET, ids[i],&n1,&n2);
      num_sideset_sides[i]=n1;
      nssdfac[i]=n2;
      /*
       * the following provision is from Version 1.6 when there are no
       * distribution factors in exodus file
       */
      bool has_ss_dfac = (n2 != 0);
      if (n2==0 || n1==n2){

        std::cerr << "WARNING: Exodus II file does not contain distribution factors.\n";

        /* n1=number of faces, n2=number of df */
        /* using distribution factors to determine number of nodes in the sideset
           causes a lot grief since some codes do not output distribution factors
           if they are all equal to 1. mkbhard: I am using the function call below
           to figure out the total number of nodes in this sideset. Some redundancy
           exists, but it works for now */

        junk.resize(n1);
        ex_get_side_set_node_count(exo_file,ids[i],TOPTR(junk));
        n2=0; /* n2 will be equal to the total number of nodes in the sideset */
        for (int j=0; j<n1; j++)
          n2+=junk[j];
      }

      iscr.resize(n1);
      jscr.resize(n2);
      ex_get_side_set_node_list(exo_file,ids[i],TOPTR(iscr),TOPTR(jscr));
      /* number-of-nodes-per-side list */
      sprintf(str,"ssnum%02d",i+1);
      PutInt(str,n1,1,TOPTR(iscr));
      /* nodes list */
      sprintf(str,"ssnod%02d",i+1);
      PutInt(str,n2,1,TOPTR(jscr));

      /* distribution-factors list */
      scr.resize(n2);
      if (has_ss_dfac) {
        ex_get_side_set_dist_fact(exo_file,ids[i], TOPTR(scr));
      } else {
        for (int j=0; j<n2; j++) {
          scr[j] = 1.0;
        }
      }
      sprintf(str,"ssfac%02d",i+1);
      PutDbl(str,n2,1,TOPTR(scr));

      /* element and side list for side sets (dgriffi) */
      elem_list.resize(n1);
      side_list.resize(n1);
      ex_get_set(exo_file,EX_SIDE_SET,ids[i],TOPTR(elem_list),TOPTR(side_list));
      sprintf(str,"ssside%02d",i+1);
      PutInt(str,n1,1,TOPTR(side_list));
      sprintf(str,"sselem%02d",i+1);
      PutInt(str,n1,1,TOPTR(elem_list));
    }
    /* Store # sides and # dis. factors per side set (dgriffi) */
    PutInt("nsssides",num_side_sets,1,TOPTR(num_sideset_sides));
    PutInt("nssdfac",num_side_sets,1,TOPTR(nssdfac));
  }

  /* node sets (section by dgriffi) */
  std::vector<int> num_nodeset_nodes(num_node_sets);
  if (num_node_sets > 0){
    if (debug) {logger("Node Sets");}
    std::vector<int> iscr;
    std::vector<double> scr;
    ids.resize(num_node_sets);
    ex_get_ids(exo_file,EX_NODE_SET, TOPTR(ids));
    PutInt( "nsids",num_node_sets, 1,TOPTR(ids));

    std::vector<int> num_nodeset_df(num_node_sets);
    for (int i=0;i<num_node_sets;i++){
      ex_get_set_param(exo_file,EX_NODE_SET,ids[i],&n1,&n2);
      iscr.resize(n1);
      ex_get_node_set(exo_file,ids[i],TOPTR(iscr));
      /* nodes list */
      sprintf(str,"nsnod%02d",i+1);
      PutInt(str,n1,1,TOPTR(iscr));
      {
        /* distribution-factors list */
        scr.resize(n2);
        ex_get_node_set_dist_fact(exo_file,ids[i],TOPTR(scr));
        sprintf(str,"nsfac%02d",i+1);
        PutDbl(str,n2,1,TOPTR(scr));
      }
      num_nodeset_nodes[i]=n1;
      num_nodeset_df[i]=n2;
    }

    /* Store # nodes and # dis. factors per node set */
    PutInt("nnsnodes",num_node_sets,1,TOPTR(num_nodeset_nodes));
    PutInt("nnsdfac",num_node_sets,1,TOPTR(num_nodeset_df));
  }

  /* element blocks */
  if (debug) {logger("Element Blocks");}
  std::vector<int> num_elem_in_block(num_blocks);
  {
    ids.resize(num_blocks);
    std::vector<int> iscr;
    ex_get_ids(exo_file,EX_ELEM_BLOCK,TOPTR(ids));
    PutInt( "blkids",num_blocks, 1,TOPTR(ids));
    for (int i=0;i<num_blocks;i++) {
      ex_get_elem_block(exo_file,ids[i],str2[i],&n,&n1,&n2);
      num_elem_in_block[i]=n;
      iscr.resize(n*n1);
      ex_get_conn(exo_file,EX_ELEM_BLOCK,ids[i],TOPTR(iscr), nullptr, nullptr);
      sprintf(str,"blk%02d",i+1);
      PutInt(str,n1,n,TOPTR(iscr));
    }
    str[0]='\0';
    for (int i=0;i<num_blocks;i++) {
      strcat(str, str2[i]);
      strcat(str, "\n");
    }
    PutStr("blknames",str);
  }

  /* time values */
  if (num_time_steps > 0 ) {
    if (debug) {logger("Time Steps");}
    std::vector<double> scr(num_time_steps);
    ex_get_all_times (exo_file, TOPTR(scr));
    PutDbl( "time", num_time_steps, 1, TOPTR(scr));
  }

  /* global variables */
  if (num_global_vars > 0 ) {
    if (debug) {logger("Global Variables");}
    get_put_names(exo_file, EX_GLOBAL, num_global_vars, "gnames");

    std::vector<double> scr(num_time_steps);
    for (int i=0;i<num_global_vars;i++){
      sprintf(str,"gvar%02d",i+1);
      ex_get_glob_var_time(exo_file,i+1,1,num_time_steps,TOPTR(scr));
      PutDbl(str,num_time_steps,1,TOPTR(scr));
    }
  }

  /* nodal variables */
  if (num_nodal_vars > 0 ) {
    if (debug) {logger("Nodal Variables");}
    if (debug) {logger("\tNames");}
    get_put_names(exo_file, EX_NODAL, num_nodal_vars, "nnames");

    std::vector<double> scr(num_nodes*num_time_steps);
    for (int i=0; i<num_nodal_vars; i++){
      sprintf(str,"nvar%02d",i+1);
      if (debug) {logger("\tReading");}
      for (int j=0; j<num_time_steps; j++) {
        ex_get_nodal_var(exo_file,j+1,i+1,num_nodes,
                         &scr[num_nodes*j]);
      }
      if (debug) {logger("\tWriting");}
      PutDbl(str,num_nodes,num_time_steps,TOPTR(scr));
    }
  }

  /* element variables */
  if (num_element_vars > 0 ) {
    if (debug) {logger("Element Variables");}
    get_put_names(exo_file, EX_ELEM_BLOCK, num_element_vars, "enames");

    get_put_vars(exo_file, EX_ELEM_BLOCK,
                 num_blocks, num_element_vars, num_time_steps, num_elem_in_block, "evar%02d");
  }

  /* nodeset variables */
  if (num_nodeset_vars > 0 ) {
    if (debug) {logger("Nodeset Variables");}
    get_put_names(exo_file, EX_NODE_SET, num_nodeset_vars, "nsnames");

    get_put_vars(exo_file, EX_NODE_SET,
                 num_node_sets, num_nodeset_vars, num_time_steps, num_nodeset_nodes, "nsvar%02d");
  }

  /* sideset variables */
  if (num_sideset_vars > 0 ) {
    if (debug) {logger("Sideset Variables");}
    get_put_names(exo_file, EX_SIDE_SET, num_sideset_vars, "ssnames");

    get_put_vars(exo_file, EX_SIDE_SET,
                 num_side_sets, num_sideset_vars, num_time_steps, num_sideset_sides, "ssvar%02d");
  }

  /* node and element number maps */
  if (debug) {logger("Node and Element Number Maps");}
  ex_opts(0);  /* turn off error reporting. It is not an error to have no map*/
  ids.resize(num_nodes);
  err = ex_get_node_num_map(exo_file,TOPTR(ids));
  if ( err==0 ){
    PutInt("node_num_map",num_nodes,1,TOPTR(ids));
  }

  ids.resize(num_elements);
  err = ex_get_elem_num_map(exo_file,TOPTR(ids));
  if ( err==0 ){
    PutInt("elem_num_map",num_elements,1,TOPTR(ids));
  }

  if (debug) {logger("Closing file");}
  ex_close(exo_file);

  if ( textfile )
    fclose(m_file);
  else
    Mat_Close(mat_file);

  std::cout << "done...\n";

  free(filename);
  free(line);

  delete_exodus_names(str2, nstr2);

  /* exit status */
  add_to_log("exo2mat", 0);
  return(0);
}