Пример #1
0
  int main(int argc, char *argv[])
  {
    printf("Starting\n");
	
    

    double dens=atof(argv[3]);
    int offset=atoi(argv[4]);
    printf("infile:%s\noutfile:%s\n\nDensity:%f\nofffset:%d\n",argv[1],argv[2],dens,offset);

    inFile.open(argv[1]);
    
    if (!inFile) {
        printf("Unable to open file");
        return 0; // terminate with error
    }
    else {
	printf("file loaded successfull\r\n");
    }
    
    ofstream outfile (argv[2]);
    //ofstream velfile ("vel.out");
    stringstream part2 (stringstream::in | stringstream::out);
   
    if (!outfile.is_open()) {
	printf("could not open outfile");
	return 0;
    }

   char line[512]; //increase to get more chars !

   double pos[3];
   pos[0]=pos[1]=pos[2]=0;
   double velx,vely,velz,omx,omy,omz=0;

   double D=0;
   double mass=0;
   float xlo,xhi,ylo,yhi,zlo,zhi;
   float ts=0;
   int atoms=0;
   int l = sizeof(line);

   inFile.getline(line,sizeof(line)); //z1=ITEM: TIMESTEP
   inFile.getline(line,sizeof(line)); //z2=1000
	ts=atof(line);
	cout<<"timestep:"<<ts<<endl;
   //inFile.getline(line,sizeof(line)); //z3=ITEM: LABEL
   //inFile.getline(line,sizeof(line)); //z4=rem_0.6_0.2_0_1e-06
   inFile.getline(line,sizeof(line)); //z5=ITEM: NUMBER OF ATOMS
   inFile.getline(line,sizeof(line)); //z6={N}
	atoms=atoi(line);
	cout<<"Atoms:"<<atoms<<endl;
   inFile.getline(line,sizeof(line)); //z7
   inFile.getline(line,sizeof(line)); //z8

	for (int i = 0; i < l; i++)
    		{
        		if (line[i] == ' ')
        		{
            		line[i] = '\0';
            	}
    	}    
        char* startp = line;
	xlo=atof(startp);
	startp += strlen(startp) + 1;
	xhi=atof(startp);
   
	inFile.getline(line,sizeof(line)); //z7
	for (int i = 0; i < l; i++)
    		{
        		if (line[i] == ' ')
        		{
            		line[i] = '\0';
            	}
    	}    
        startp = line;
	ylo=atof(startp);
	startp += strlen(startp) + 1;
	yhi=atof(startp);
   
	inFile.getline(line,sizeof(line)); //z8
	for (int i = 0; i < l; i++)
    		{
        		if (line[i] == ' ')
        		{
            		line[i] = '\0';
            	}
    	}    
        startp = line;
	zlo=atof(startp);
	startp += strlen(startp) + 1;
	zhi=atof(startp);
	

   inFile.getline(line,sizeof(line)); //z9
	cout<<"Line:"<<line<<endl; //header
   double d=0;

   int lc=0;
   int ac=offset;

   outfile <<"LIGGGHTS data file from restart file: timestep = "<<ts<<", procs = 12\r\n\r\n";
   outfile << atoms <<" atoms\r\n\r\n";
   outfile << "2 atom types\r\n\r\n";
   outfile << "20 extra bond per atom\r\n\r\n";

   outfile << xlo << " " << xhi << " xlo xhi\r\n";
   outfile << ylo << " " << yhi << " ylo yhi\r\n";
   outfile << zlo << " " << zhi << " zlo zhi\r\n";
   outfile<<"\r\n";
   outfile<<"Atoms\r\n";
   outfile<<"\r\n";

   int type=0;
   while ( inFile.getline(line,sizeof(line)) ) {
	lc++;
	//cout<<"Line:"<<lc<<endl;
	for (int i = 0; i < l; i++)
    		{
        		if (line[i] == ' ')
        		{
            		line[i] = '\0';
            	}
    	}
    
    startp = line;

//id type x y z vx vy vz fx fy fz omegax omegay omegaz radius 

//id    
	int id = atoi(startp);
	id+=offset;
	startp += strlen(startp) + 1;
//type
	type = atof(startp);
	startp += strlen(startp) + 1;
	//startp += strlen(startp) + 1; //type is 2x in dumpfile (don't know why)
//position    
    for (int i = 0; i <= 2; i++)
    {
        d = atof(startp);
	pos[i]=d;
	startp += strlen(startp) + 1;
    }

//velocity
        d = atof(startp);
	velx=d;
        startp += strlen(startp) + 1;
        d = atof(startp);
	vely=d;
        startp += strlen(startp) + 1;
        d = atof(startp);
	velz=d;
        startp += strlen(startp) + 1;

//forces
	for (int i = 0; i < 3; i++)
    {
        startp += strlen(startp) + 1;
    }
//omega	
	d = atof(startp);
	omx=d;
        startp += strlen(startp) + 1;
	d = atof(startp);
	omy=d;
        startp += strlen(startp) + 1;
	d = atof(startp);
	omz=d;
        startp += strlen(startp) + 1;
//radius	
	D = 2*atof(startp);
	startp += strlen(startp) + 1;
//calc mass 
	mass+=(1./6.)*M_PI*D*D*D*dens; 
	//printf("D=%f,m=%f\n",D,mass);   
	ac++;
	velx=vely=velz=omx=omy=omz=0;
	//for hybrid pair styles: id type x y z dens rad
	outfile << ac << " " << type << " " << pos[0] << " " << pos[1] << " " << pos[2] << " " << D << " " << dens << " " << "0" << endl;
	//part2 << ac <<" "<<velx<<" "<<vely<<" "<<velz<<" "<<omx<<" "<<omy<<" "<<omz<< endl;
     
   } //endwhile

//outfile << endl << "Velocities" << endl<<endl;
//outfile << part2.str();


    inFile.close();
    outfile.close();
    //velfile.close();
    printf("particle mass=%f\n",mass);
    printf("done (%d)\n",ac);
    return 0;
  }
Пример #2
0
void GrowRect::open( ifstream& fp)
{
  int		type;
  int 		end_found = 0;
  char		dummy[40];
  int		tmp;
  int		j;
  char		c;

  for (;;)
  {
    fp >> type;
    switch( type) {
      case glow_eSave_GrowRect: break;
      case glow_eSave_GrowRect_n_name:
        fp.get();
        fp.getline( n_name, sizeof(n_name));
        break;
      case glow_eSave_GrowRect_x_right: fp >> x_right; break;
      case glow_eSave_GrowRect_x_left: fp >> x_left; break;
      case glow_eSave_GrowRect_y_high: fp >> y_high; break;
      case glow_eSave_GrowRect_y_low: fp >> y_low; break;
      case glow_eSave_GrowRect_original_border_drawtype: fp >> 
		tmp; original_border_drawtype = (glow_eDrawType)tmp; break;
      case glow_eSave_GrowRect_original_fill_drawtype: fp >> 
		tmp; original_fill_drawtype = (glow_eDrawType)tmp; break;
      case glow_eSave_GrowRect_fill_drawtype: fp >> 
		tmp; fill_drawtype = (glow_eDrawType)tmp; break;
      case glow_eSave_GrowRect_border: fp >> border; break;
      case glow_eSave_GrowRect_shadow_width: fp >> shadow_width; break;
      case glow_eSave_GrowRect_shadow_contrast: fp >> shadow_contrast; break;
      case glow_eSave_GrowRect_shadow: fp >> shadow; break;
      case glow_eSave_GrowRect_relief: fp >> tmp; relief = (glow_eRelief)tmp; break;
      case glow_eSave_GrowRect_disable_shadow: fp >> disable_shadow; break;
      case glow_eSave_GrowRect_invisible: fp >> invisible; break;
      case glow_eSave_GrowRect_fixcolor: fp >> fixcolor; break;
      case glow_eSave_GrowRect_fixposition: fp >> fixposition; break;
      case glow_eSave_GrowRect_gradient: fp >> tmp; gradient = (glow_eGradient)tmp; break;
      case glow_eSave_GrowRect_gradient_contrast: fp >> gradient_contrast; break;
      case glow_eSave_GrowRect_disable_gradient: fp >> disable_gradient; break;
      case glow_eSave_GrowRect_dynamicsize: fp >> dynamicsize; break;
      case glow_eSave_GrowRect_dynamic:
        fp.getline( dummy, sizeof(dummy));
        if ( dynamicsize)
        {
          dynamic = (char *) calloc( 1, dynamicsize);
	  fp.get();
          for ( j = 0; j < dynamicsize; j++)
	  {
	    if ((c = fp.get()) == '"')
	    {
	      if ( dynamic[j-1] == '\\')
	        j--;
	      else
              {
	        dynamic[j] = 0;
                break;
              }
	    }
            dynamic[j] = c;
	  }
          fp.getline( dummy, sizeof(dummy));
        }
        break;
      case glow_eSave_GrowRect_rect_part: 
        GlowRect::open( fp);
        break;
      case glow_eSave_GrowRect_trf: trf.open( fp); break;
      case glow_eSave_End: end_found = 1; break;
      default:
        cout << "GrowRect:open syntax error" << endl;
        fp.getline( dummy, sizeof(dummy));
    }
    if ( end_found)
      break;

    if ( fp.fail()) {
      cout << "GrowRect:open syntax error (" << type << ")" << endl;
      fp.clear();
      fp.getline( dummy, sizeof(dummy));
    }
  }
}
Пример #3
0
void GrowText::open( ifstream& fp)
{
  int		type;
  int 		end_found = 0;
  char		dummy[40];
  int		tmp;
  int		j;
  char		c;
  char          *new_text;

  for (;;)
  {
    if ( !fp.good()) {
      fp.clear();
      fp.getline( dummy, sizeof(dummy));
      printf( "** Read error GrowText: \"%d %s\"\n", type, dummy);      
    }

    fp >> type;
    switch( type) {
      case glow_eSave_GrowText: break;
      case glow_eSave_GrowText_n_name:
        fp.get();
        fp.getline( n_name, sizeof(n_name));
        break;
      case glow_eSave_GrowText_x_right: fp >> x_right; break;
      case glow_eSave_GrowText_x_left: fp >> x_left; break;
      case glow_eSave_GrowText_y_high: fp >> y_high; break;
      case glow_eSave_GrowText_y_low: fp >> y_low; break;
      case glow_eSave_GrowText_original_color_drawtype: fp >> 
		tmp; original_color_drawtype = (glow_eDrawType)tmp; break;
      case glow_eSave_GrowText_font: fp >> tmp; font = (glow_eFont)tmp; break;
      case glow_eSave_GrowText_adjustment: fp >> tmp; adjustment = (glow_eAdjustment)tmp; break;
      case glow_eSave_GrowText_dynamicsize: fp >> dynamicsize; break;
      case glow_eSave_GrowText_dynamic:
        fp.getline( dummy, sizeof(dummy));
        if ( dynamicsize)
        {
          dynamic = (char *) calloc( 1, dynamicsize);
	  fp.get();
          for ( j = 0; j < dynamicsize; j++)
	  {
	    if ((c = fp.get()) == '"')
	    {
	      if ( dynamic[j-1] == '\\')
	        j--;
	      else
              {
	        dynamic[j] = 0;
                break;
              }
	    }
            dynamic[j] = c;
	  }
          fp.getline( dummy, sizeof(dummy));
        }
        break;
      case glow_eSave_GrowText_text_part: 
        GlowText::open( fp);
        break;
      case glow_eSave_GrowText_trf: trf.open( fp); break;
      case glow_eSave_End: end_found = 1; break;
      default:
        cout << "GrowText:open syntax error" << endl;
        fp.getline( dummy, sizeof(dummy));
    }
    if ( end_found)
      break;
  }

  // Translate the text to current language
  if ( ctx->translate_on && 
       ctx->event_callback[glow_eEvent_Translate]) {
    if ( ctx->translate_cb( this, text, &new_text))
      strcpy( text, new_text);
      get_node_borders();
  }
}
Пример #4
0
void GrowFolder::open( ifstream& fp)
{
  int		type;
  int 		end_found = 0;
  char		dummy[40];
  int		tmp;

  for (;;) {
    fp >> type;
    switch( type) {
      case glow_eSave_GrowFolder: break;
      case glow_eSave_GrowFolder_folders: fp >> folders; break;
      case glow_eSave_GrowFolder_text_size: fp >> text_size; break;
      case glow_eSave_GrowFolder_text_drawtype: fp >> tmp; text_drawtype = (glow_eDrawType)tmp; break;
      case glow_eSave_GrowFolder_text_color_drawtype: fp >> tmp; 
	text_color_drawtype = (glow_eDrawType)tmp; break;
      case glow_eSave_GrowFolder_header_height: fp >> header_height; break;
      case glow_eSave_GrowFolder_color_selected: fp >> tmp; color_selected = (glow_eDrawType)tmp; break;
      case glow_eSave_GrowFolder_color_unselected: fp >> tmp; color_unselected = (glow_eDrawType)tmp; break;
      case glow_eSave_GrowFolder_folder_file_names1: fp.get();
        fp.getline( folder_file_names[0], sizeof(folder_file_names[0])); break;
      case glow_eSave_GrowFolder_folder_text1: fp.get();
        fp.getline( folder_text[0], sizeof(folder_text[0])); break;
      case glow_eSave_GrowFolder_folder_scale1: fp >> folder_scale[0]; break;
      case glow_eSave_GrowFolder_folder_v_scrollbar1: fp >> folder_v_scrollbar[0]; break;
      case glow_eSave_GrowFolder_folder_h_scrollbar1: fp >> folder_h_scrollbar[0]; break;
      case glow_eSave_GrowFolder_folder_file_names2: fp.get();
        fp.getline( folder_file_names[1], sizeof(folder_file_names[0])); break;
      case glow_eSave_GrowFolder_folder_text2: fp.get();
        fp.getline( folder_text[1], sizeof(folder_text[0])); break;
      case glow_eSave_GrowFolder_folder_scale2: fp >> folder_scale[1]; break;
      case glow_eSave_GrowFolder_folder_v_scrollbar2: fp >> folder_v_scrollbar[1]; break;
      case glow_eSave_GrowFolder_folder_h_scrollbar2: fp >> folder_h_scrollbar[1]; break;
      case glow_eSave_GrowFolder_folder_file_names3: fp.get();
        fp.getline( folder_file_names[2], sizeof(folder_file_names[0])); break;
      case glow_eSave_GrowFolder_folder_text3: fp.get();
        fp.getline( folder_text[2], sizeof(folder_text[0])); break;
      case glow_eSave_GrowFolder_folder_scale3: fp >> folder_scale[2]; break;
      case glow_eSave_GrowFolder_folder_v_scrollbar3: fp >> folder_v_scrollbar[2]; break;
      case glow_eSave_GrowFolder_folder_h_scrollbar3: fp >> folder_h_scrollbar[2]; break;
      case glow_eSave_GrowFolder_folder_file_names4: fp.get();
        fp.getline( folder_file_names[3], sizeof(folder_file_names[0])); break;
      case glow_eSave_GrowFolder_folder_text4: fp.get();
        fp.getline( folder_text[3], sizeof(folder_text[0])); break;
      case glow_eSave_GrowFolder_folder_scale4: fp >> folder_scale[3]; break;
      case glow_eSave_GrowFolder_folder_v_scrollbar4: fp >> folder_v_scrollbar[3]; break;
      case glow_eSave_GrowFolder_folder_h_scrollbar4: fp >> folder_h_scrollbar[3]; break;
      case glow_eSave_GrowFolder_folder_file_names5: fp.get();
        fp.getline( folder_file_names[4], sizeof(folder_file_names[0])); break;
      case glow_eSave_GrowFolder_folder_text5: fp.get();
        fp.getline( folder_text[4], sizeof(folder_text[0])); break;
      case glow_eSave_GrowFolder_folder_scale5: fp >> folder_scale[4]; break;
      case glow_eSave_GrowFolder_folder_v_scrollbar5: fp >> folder_v_scrollbar[4]; break;
      case glow_eSave_GrowFolder_folder_h_scrollbar5: fp >> folder_h_scrollbar[4]; break;
      case glow_eSave_GrowFolder_folder_file_names6: fp.get();
        fp.getline( folder_file_names[5], sizeof(folder_file_names[0])); break;
      case glow_eSave_GrowFolder_folder_text6: fp.get();
        fp.getline( folder_text[5], sizeof(folder_text[0])); break;
      case glow_eSave_GrowFolder_folder_scale6: fp >> folder_scale[5]; break;
      case glow_eSave_GrowFolder_folder_v_scrollbar6: fp >> folder_v_scrollbar[5]; break;
      case glow_eSave_GrowFolder_folder_h_scrollbar6: fp >> folder_h_scrollbar[5]; break;
      case glow_eSave_GrowFolder_folder_file_names7: fp.get();
        fp.getline( folder_file_names[6], sizeof(folder_file_names[0])); break;
      case glow_eSave_GrowFolder_folder_text7: fp.get();
        fp.getline( folder_text[6], sizeof(folder_text[0])); break;
      case glow_eSave_GrowFolder_folder_scale7: fp >> folder_scale[6]; break;
      case glow_eSave_GrowFolder_folder_v_scrollbar7: fp >> folder_v_scrollbar[6]; break;
      case glow_eSave_GrowFolder_folder_h_scrollbar7: fp >> folder_h_scrollbar[6]; break;
      case glow_eSave_GrowFolder_folder_file_names8: fp.get();
        fp.getline( folder_file_names[7], sizeof(folder_file_names[0])); break;
      case glow_eSave_GrowFolder_folder_text8: fp.get();
        fp.getline( folder_text[7], sizeof(folder_text[0])); break;
      case glow_eSave_GrowFolder_folder_scale8: fp >> folder_scale[7]; break;
      case glow_eSave_GrowFolder_folder_v_scrollbar8: fp >> folder_v_scrollbar[7]; break;
      case glow_eSave_GrowFolder_folder_h_scrollbar8: fp >> folder_h_scrollbar[7]; break;
      case glow_eSave_GrowFolder_folder_file_names9: fp.get();
        fp.getline( folder_file_names[8], sizeof(folder_file_names[0])); break;
      case glow_eSave_GrowFolder_folder_text9: fp.get();
        fp.getline( folder_text[8], sizeof(folder_text[0])); break;
      case glow_eSave_GrowFolder_folder_scale9: fp >> folder_scale[8]; break;
      case glow_eSave_GrowFolder_folder_v_scrollbar9: fp >> folder_v_scrollbar[8]; break;
      case glow_eSave_GrowFolder_folder_h_scrollbar9: fp >> folder_h_scrollbar[8]; break;
      case glow_eSave_GrowFolder_folder_file_names10: fp.get();
        fp.getline( folder_file_names[9], sizeof(folder_file_names[0])); break;
      case glow_eSave_GrowFolder_folder_text10: fp.get();
        fp.getline( folder_text[9], sizeof(folder_text[0])); break;
      case glow_eSave_GrowFolder_folder_scale10: fp >> folder_scale[9]; break;
      case glow_eSave_GrowFolder_folder_v_scrollbar10: fp >> folder_v_scrollbar[9]; break;
      case glow_eSave_GrowFolder_folder_h_scrollbar10: fp >> folder_h_scrollbar[9]; break;
      case glow_eSave_GrowFolder_folder_file_names11: fp.get();
        fp.getline( folder_file_names[10], sizeof(folder_file_names[0])); break;
      case glow_eSave_GrowFolder_folder_text11: fp.get();
        fp.getline( folder_text[10], sizeof(folder_text[0])); break;
      case glow_eSave_GrowFolder_folder_scale11: fp >> folder_scale[10]; break;
      case glow_eSave_GrowFolder_folder_v_scrollbar11: fp >> folder_v_scrollbar[10]; break;
      case glow_eSave_GrowFolder_folder_h_scrollbar11: fp >> folder_h_scrollbar[10]; break;
      case glow_eSave_GrowFolder_folder_file_names12: fp.get();
        fp.getline( folder_file_names[11], sizeof(folder_file_names[0])); break;
      case glow_eSave_GrowFolder_folder_text12: fp.get();
        fp.getline( folder_text[11], sizeof(folder_text[0])); break;
      case glow_eSave_GrowFolder_folder_scale12: fp >> folder_scale[11]; break;
      case glow_eSave_GrowFolder_folder_v_scrollbar12: fp >> folder_v_scrollbar[11]; break;
      case glow_eSave_GrowFolder_folder_h_scrollbar12: fp >> folder_h_scrollbar[11]; break;
      case glow_eSave_GrowFolder_folder_owner1: fp.get();
        fp.getline( folder_owner[0], sizeof(folder_owner[0])); break;
      case glow_eSave_GrowFolder_folder_owner2: fp.get();
        fp.getline( folder_owner[1], sizeof(folder_owner[0])); break;
      case glow_eSave_GrowFolder_folder_owner3: fp.get();
        fp.getline( folder_owner[2], sizeof(folder_owner[0])); break;
      case glow_eSave_GrowFolder_folder_owner4: fp.get();
        fp.getline( folder_owner[3], sizeof(folder_owner[0])); break;
      case glow_eSave_GrowFolder_folder_owner5: fp.get();
        fp.getline( folder_owner[4], sizeof(folder_owner[0])); break;
      case glow_eSave_GrowFolder_folder_owner6: fp.get();
        fp.getline( folder_owner[5], sizeof(folder_owner[0])); break;
      case glow_eSave_GrowFolder_folder_owner7: fp.get();
        fp.getline( folder_owner[6], sizeof(folder_owner[0])); break;
      case glow_eSave_GrowFolder_folder_owner8: fp.get();
        fp.getline( folder_owner[7], sizeof(folder_owner[0])); break;
      case glow_eSave_GrowFolder_folder_owner9: fp.get();
        fp.getline( folder_owner[8], sizeof(folder_owner[0])); break;
      case glow_eSave_GrowFolder_folder_owner10: fp.get();
        fp.getline( folder_owner[9], sizeof(folder_owner[0])); break;
      case glow_eSave_GrowFolder_folder_owner11: fp.get();
        fp.getline( folder_owner[10], sizeof(folder_owner[0])); break;
      case glow_eSave_GrowFolder_folder_owner12: fp.get();
        fp.getline( folder_owner[11], sizeof(folder_owner[0])); break;
      case glow_eSave_GrowFolder_window_part: 
        GrowWindow::open( fp);
        break;
      case glow_eSave_End: end_found = 1; break;
      default:
        cout << "GrowFolder:open syntax error" << endl;
        fp.getline( dummy, sizeof(dummy));
    }
    if ( end_found)
      break;
  }
  y_low_offs = header_height;
  strcpy( input_file_name, folder_file_names[0]);
  window_scale = folder_scale[0];
  vertical_scrollbar = folder_v_scrollbar[0];
  horizontal_scrollbar = folder_h_scrollbar[0];
  strcpy( owner, folder_owner[0]);
  GrowWindow::update_attributes();
}
Пример #5
0
bool MlOperatorList::readOperatorList(ifstream& ifs)
{
	char buffer[1024];
	while (ifs.good() && ifs.getline(buffer,1024))
		if (ifs.gcount()>0 && buffer[0] != '#')
			break;

	size_t n=0;
	if (sscanf(buffer,"%d",&n) != 1)
		error("expected line with number of operaotrs");

	executionOrder_.clear();
	executionOrder_.reserve(n);
	drops_.clear();
	indicators_.clear();
	normalizations_.clear();
	functions_.clear();
	splits_.clear();
	conditionals_.clear();

	for (size_t i=0; i<n; i++)
	{
		if (! ifs.good())
			return false;

		ifs.getline(buffer,1024);
		if (ifs.gcount()<=0)
			return false;

		istringstream iss(buffer);

		char type=' ';
		iss >> type;
		switch (type) {
			case 'D':
				{
					size_t dropIdx=0;
					iss >> dropIdx;
					if (iss.fail())
						error("Error reading line:",buffer);

					executionOrder_.push_back(IdxPair(OT_DROP,drops_.size()));
					drops_.push_back(dropIdx);
				}
				break;

			case 'I':
				{
					IndicatorOperator iop;
					iss >> iop.sourceIdx >> iop.targetIdx;
					if (iss.fail())
						error("Error reading line:",buffer);
					executionOrder_.push_back(IdxPair(OT_INDICATOR,indicators_.size()));
					indicators_.push_back(iop);
					break;
				}

			case 'F':
				{
					FunctionOperator fop;
					iss >> fop.sourceIdx >> fop.targetIdx;
					string typeStr;
					iss >> typeStr;
					size_t i;
					for (i=0; i<numConditionalValueLabels; i++)
						if (! strcmp(typeStr.c_str(),conditionalValueLabels[i]))
							break;
					if (i == numConditionalValueLabels)
						error("Error reading line:",buffer);
					fop.type = i;
					executionOrder_.push_back(IdxPair(OT_FUNCTION,functions_.size()));
					functions_.push_back(fop);
				}

			case 'N':
				{
					NormalizationOperator nop;
					iss >> nop.sourceIdx >> nop.targetIdx >> nop.mu >> nop.sigma;
					if (iss.fail())
						error("Error reading line:",buffer);
					executionOrder_.push_back(IdxPair(OT_NORMALIZATION,normalizations_.size()));
					normalizations_.push_back(nop);
				}
				break;

			case 'S':
				{
					SplitOperator sop;
					iss >> sop.sourceIdx;

					size_t n;
					iss >> n;
					if (iss.fail())
						error("Error reading line:",buffer);
					sop.thresholds.resize(n);
					sop.indexesForBinValues.resize(n+1);
					sop.indexesForBinIndicators.resize(n+1);
					for (size_t i=0; i<n; i++)
						iss >> sop.thresholds[i];
					for (size_t i=0; i<=n; i++)
					{
						// a fix so the model file can use -1 for MAX_UINT (so it won't hurt my eyes...)
						int index;
						iss >> index;
						sop.indexesForBinValues[i] = (index>=0 ? static_cast<size_t>(index) : MAX_UINT);
					}
					for (size_t i=0; i<=n; i++)
					{
						// a fix so the model file can use -1 for MAX_UINT (so it won't hurt my eyes...)
						int index;
						iss >> index;
						sop.indexesForBinIndicators[i] = (index>=0 ? static_cast<size_t>(index) : MAX_UINT);
					}
					if (iss.fail())
						error("Error reading line:",buffer);
					executionOrder_.push_back(IdxPair(OT_SPLIT,splits_.size()));
					splits_.push_back(sop);
				}
				break;

			case 'C':
				{
					ConditionalOperator cod;
					size_t n;
					iss >> n;
					cod.sourceIdxs.resize(n);
					for (size_t i=0; i<n; i++)
						iss >> cod.sourceIdxs[i];
					iss >> cod.targetIdx;

					// a fix so the model file can use -1 for MAX_UINT (so it won't hurt my eyes...)
					int indexForBool;
					iss >> indexForBool;
					cod.indexForBool = (indexForBool>=0 ? static_cast<size_t>(indexForBool) : MAX_UINT);
					
					string resultStr, conditionStr;
					iss >> conditionStr >> resultStr;
					if (iss.fail())
						error("Error reading line:",buffer);
					size_t idxType, idxResult;
					for (idxType=0; idxType<numConditionalOperatorLabels; idxType++)
						if (! strcmp(conditionStr.c_str(),conditionalOperatorLabels[idxType]))
							break;
					if (idxType == numConditionalOperatorLabels)
						error("Error reading line:",buffer);
					for (idxResult=0; idxResult<numConditionalValueLabels; idxResult++)
						if (! strcmp(resultStr.c_str(),conditionalValueLabels[idxResult]))
							break;
					if (idxResult == numConditionalValueLabels)
						error("Error reading line:",buffer);
					cod.conditionType = idxType;
					cod.resultType    = idxResult;

					executionOrder_.push_back(IdxPair(OT_CONDITIONAL,conditionals_.size()));
					conditionals_.push_back(cod);
				}
				break;
		};
	}
	return true;
}
Пример #6
0
BOOL bIsModeMismatch( ifstream& omInReplayFile,
                      BOOL bReplayHexON,
                      WORD wLogReplayTimeMode)
{
    BOOL bFlag = FALSE;
    BOOL bLine = TRUE;
    CHAR Line[500] = { NULL };
    CString omStrLine;
    BOOL bLogModeChecked = FALSE;
    BOOL bReplayMsgTypeChecked = FALSE;
    if(omInReplayFile != NULL)
    {
        while( bLine &&  ! omInReplayFile.eof())
        {

            omInReplayFile.getline( Line, sizeof(Line));
            omStrLine = Line;

            if( omStrLine.Find(HEX_MODE) == 0)
            {
                bLogModeChecked = TRUE;

                if(bReplayHexON != TRUE)
                {
                    bFlag = TRUE;
                }
            }
            else if (omStrLine.Find(DEC_MODE) == 0)
            {
                bLogModeChecked = TRUE;

                if(bReplayHexON != FALSE)
                {
                    bFlag = TRUE;
                }
            }
            if( omStrLine.Find(SYSTEM_MODE) == 0)
            {
                bReplayMsgTypeChecked = TRUE;
                if( wLogReplayTimeMode != eSYSTEM_MODE)
                {
                    bFlag = TRUE;
                    bLine = FALSE;
                }
            }
            else if( omStrLine.Find(ABSOLUTE_MODE) == 0)
            {
                bReplayMsgTypeChecked = TRUE;
                if( wLogReplayTimeMode != eABSOLUTE_MODE)
                {
                    bFlag = TRUE;
                    bLine = FALSE;
                }
            }
            else if( omStrLine.Find(RELATIVE_MODE) == 0)
            {
                bReplayMsgTypeChecked = TRUE;
                if( wLogReplayTimeMode != eRELATIVE_MODE)
                {
                    bFlag = TRUE;
                    bLine = FALSE;
                }
            }
            if(bLogModeChecked == TRUE && bReplayMsgTypeChecked == TRUE)
            {
                bLine = FALSE;
            }
        }
    }
    return bFlag;
}
Пример #7
0
void GlowNodeClass::open( ifstream& fp)
{
  int		type;
  int 		end_found = 0;
  char		dummy[40];
  int		tmp;
  int		i, j;
  char		c;
  int		sts;

  for (;;)
  {
    if ( !fp.good()) {
      fp.clear();
      fp.getline( dummy, sizeof(dummy));
      printf( "** Read error GlowNodeClass: \"%d %s\"\n", type, dummy);      
    }

    fp >> type;
    switch( type) {
      case glow_eSave_NodeClass: break;
      case glow_eSave_NodeClass_nc_name:
        fp.get();
        fp.getline( nc_name, sizeof(nc_name));
        break;
      case glow_eSave_NodeClass_a: a.open( ctx, fp); break;
      case glow_eSave_NodeClass_group: fp >> tmp; group = (glow_eNodeGroup)tmp; break;
      case glow_eSave_NodeClass_dynamicsize: fp >> dynamicsize; break;
      case glow_eSave_NodeClass_dynamic:
        fp.getline( dummy, sizeof(dummy));
        if ( dynamicsize)
        {
          dynamic = (char *) calloc( 1, dynamicsize);
	  fp.get();
          for ( j = 0; j < dynamicsize; j++)
	  {
	    if ((c = fp.get()) == '"')
	    {
	      if ( dynamic[j-1] == '\\')
	        j--;
	      else
              {
	        dynamic[j] = 0;
                break;
              }
	    }
            dynamic[j] = c;
	  }
          fp.getline( dummy, sizeof(dummy));
        }
        break;
      case glow_eSave_NodeClass_arg_cnt: fp >> arg_cnt; break;
      case glow_eSave_NodeClass_argname:
        fp.get();
        for ( i = 0; i < arg_cnt; i++)
        {
          fp.getline( argname[i], sizeof(argname[0]));
        }
        break;
      case glow_eSave_NodeClass_argtype:
        for ( i = 0; i < arg_cnt; i++)
          fp >> argtype[i];
        break;
      case glow_eSave_NodeClass_dyn_type1: fp >> dyn_type1; break; 
      case glow_eSave_NodeClass_dyn_type2: fp >> dyn_type2; break; 
      case glow_eSave_NodeClass_dyn_action_type1: fp >> dyn_action_type1; break; 
      case glow_eSave_NodeClass_dyn_action_type2: fp >> dyn_action_type2; break; 
      case glow_eSave_NodeClass_dyn_color1:
        fp >> tmp;
	dyn_color[0] = (glow_eDrawType)tmp;
        break;
      case glow_eSave_NodeClass_dyn_color2:
        fp >> tmp;
	dyn_color[1] = (glow_eDrawType)tmp;
        break;
      case glow_eSave_NodeClass_dyn_color3:
        fp >> tmp;
	dyn_color[2] = (glow_eDrawType)tmp;
        break;
      case glow_eSave_NodeClass_dyn_color4:
        fp >> tmp;
	dyn_color[3] = (glow_eDrawType)tmp;
        break;
      case glow_eSave_NodeClass_dyn_attr1: fp >> dyn_attr[0]; break;
      case glow_eSave_NodeClass_dyn_attr2: fp >> dyn_attr[1]; break;
      case glow_eSave_NodeClass_dyn_attr3: fp >> dyn_attr[2]; break;
      case glow_eSave_NodeClass_dyn_attr4: fp >> dyn_attr[3]; break;
      case glow_eSave_NodeClass_no_con_obstacle: fp >> no_con_obstacle; break;
      case glow_eSave_NodeClass_slider: fp >> slider; break;
      case glow_eSave_NodeClass_java_name:
        fp.get();
        fp.getline( java_name, sizeof(java_name));
        break;
      case glow_eSave_NodeClass_next_nodeclass:
        fp.get();
        fp.getline( next_nodeclass, sizeof(next_nodeclass));
        break;
      case glow_eSave_NodeClass_animation_count: fp >> animation_count; break;
      case glow_eSave_NodeClass_cycle:
        fp >> tmp;
	cycle = (glow_eCycle)tmp;
        break;
      case glow_eSave_NodeClass_y0: fp >> y0; break;
      case glow_eSave_NodeClass_y1: fp >> y1; break;
      case glow_eSave_NodeClass_x0: fp >> x0; break;
      case glow_eSave_NodeClass_x1: fp >> x1; break;
      case glow_eSave_NodeClass_input_focus_mark:
        fp >> tmp;
	input_focus_mark = (glow_eInputFocusMark)tmp;
        break;
      case glow_eSave_NodeClass_recursive_trace: fp >> recursive_trace; break;
      case glow_eSave_NodeClass_userdata_cb:
	if ( ctx->userdata_open_callback)
	  (ctx->userdata_open_callback)(&fp, this, glow_eUserdataCbType_NodeClass);
	break;
      case glow_eSave_End: end_found = 1; break;
      default:
        cout << "GlowNodeClass:open syntax error" << endl;
        fp.getline( dummy, sizeof(dummy));
    }
    if ( end_found)
      break;
  }

  if ( strcmp( next_nodeclass, "") != 0)
  {
    next_nc = ctx->get_nodeclass_from_name( next_nodeclass);
    if ( !next_nc)
    {
      sts = ctx->open_subgraph_from_name( next_nodeclass, 
			glow_eSaveMode_SubGraph);
      if ( ODD(sts))
      {
        next_nc = ctx->get_nodeclass_from_name( next_nodeclass);
        if ( next_nc) 
          ((GlowNodeClass *)next_nc)->nc_extern = nc_extern;
      }
    }
    if ( !next_nc) 
      cout << "GlowNode:next_nodeclass not found: " << nc_name << " " <<
		next_nodeclass << endl;
    else if ( ((GlowNodeClass *)next_nc)->prev_nc)
    {
      next_nc = 0;
      cout << "GlowNode:next_nodeclass already chained: " << nc_name << " " <<
		next_nodeclass << endl;
    }
    else
      ((GlowNodeClass *)next_nc)->prev_nc = (GlowArrayElem *) this;
  }
}
Пример #8
0
void getData(){

	char line[500];
	string s;
	pair<long long, long long> pr;
	long long timestamp, user, item, rating;

	//getting the user-item-rating matrix
	fin.open("dataset/ua.base.txt");
	while(!fin.eof()){
		fin>>user;
		fin>>item;
		fin>>rating;
		fin>>timestamp;
		inputMatrix[user][item] = rating;
		pr = make_pair(item, rating);
		ratings[user].push_back(pr);
		dummy[item]++;	
	}
	fin.close();
	for(int i=0; i<2000; i++) mostRated.push_back(make_pair( dummy[i], i ));	
	//cout<<"Matrix built\n";

	/*cout<<"No of users = "<<ratings.size()<<endl;
	for(int i=0; i<5; i++){
		cout<<"User "<<i<<endl;
		for(int j=0; j<ratings[i].size(); j++){
			cout<<"\t"<<"item= "<<ratings[i][j].first<<", rating = "<<ratings[i][j].second;
		}
	}*/

	//getting the item-itemName mapping
	fin.open("dataset/u.item.txt");
	while(fin.getline(line, 500)){
		stringstream ss(line);
		getline(ss, s, '|');
		char str[100];
		for(int i=0; s[i]!='\0'; i++) str[i] = s[i];
		item = atoi(str);
		getline(ss, s, '|');
		itemDetails[item] = s;
		//Skipping over other values as not using them
	}
	fin.close();

	/*cout<<"No of items="<<itemDetails.size();
	for(int i=0; i<15; i++)
		cout<<i<<":"<<itemDetails[i]<<endl;*/

	//getting the top 30 user similarities
	fin.open("topNeighbours.txt");
	int user1, user2;
	float rat;
	while(!fin.eof()){
		fin>>user1;
		for(int i=0; i<300; i++){
			fin>>rat>>user2;
			if(user2<=1 || user2>944) continue;
			topNeighbours[user1].push_back(user2);
			userSimilarity[user1][user2] = rat;
		}
		cout<<user1<<" ";
	}
	fin.close();
	//cout<<"Similarity taken\n";

}
Пример #9
0
int main()
{
    int nr,i,n;
    char c;
    in.getline(s,1100);
    nr=-1;
    while(s[p])
    {
        if(s[p]==' ')
        {
            ++p;
            continue;
        }
        if(s[p]=='T' && s[p+1]=='R' && s[p+2]=='U' && s[p+3]=='E')
        {
            z[++nr]='1';
            p+=4;
            continue;
        }
        if(s[p]=='F' && s[p+1]=='A' && s[p+2]=='L' && s[p+3]=='S' && s[p+4]=='E')
        {
            z[++nr]='0';
            p+=5;
            continue;
        }
        if(s[p]=='(' || s[p]==')')
        {
            z[++nr]=s[p];
            ++p;
            continue;
        }
        if(s[p]=='A' && s[p+1]=='N' && s[p+2]=='D')
        {
            z[++nr]='&';
            p+=3;
            continue;
        }
        if(s[p]=='N' && s[p+1]=='O' && s[p+2]=='T')
        {
            z[++nr]='~';
            p+=3;
            continue;
        }
        if(s[p]=='O' && s[p+1]=='R')
        {
            z[++nr]='|';
            p+=2;
            continue;
        }
        if(s[p]>='A' && s[p]<='Z')
        {
            z[++nr]=s[p]-'A'+'a';
            p++;
            continue;
        }
    }
    //for(i=0;z[i];++i)
     //   out<<z[i];
    p=0;
    in>>n;
    in.getline(s,1000);
    for(i=1;i<=n;++i)
    {
        p=0;
        in>>c;
        v[c-'A']=(v[c-'A']+1)%2;
        out<<expresie();
    }
    return 0;
}
Пример #10
0
void ReadlnString(ifstream& f, CString& s)
{
	char buf[256];
	f.getline(buf,255,'\n');
	s = buf;
}
Пример #11
0
CurveToken
avtCurve2DFileFormat::GetPoint(ifstream &ifile, double &x, double &y, string &ln)
{
    char line[256];
    ifile.getline(line, 256, '\n');

    // Do an ASCII check.  We only support text files.
    if (GetStrictMode() && !StringHelpers::IsPureASCII(line,256))
        EXCEPTION2(InvalidFilesException, filename, "Not ASCII.");

    //
    // Parenthesis are special characters for variables names, etc, so just
    // change them to square brackets to "go with the flow"...
    //
    size_t i, nchars = strlen(line);
    for (i = 0 ; i < nchars ; i++)
    {
        if (line[i] == '(')
            line[i] = '<';
        else if (line[i] == ')')
            line[i] = '>';
    }
    ln = line;

    //
    // Pick out some of the harder to parse cases.
    //
    if (strstr(line, "#") != NULL)
    {
        return HEADER;
    }
    bool allSpace = true;
    size_t len = strlen(line);
    for (i = 0 ; i < len ; i++)
    {
        if (!isspace(line[i]))
        {
            allSpace = false;
        }
    }
    if (allSpace)
    {
        return WHITESPACE;
    }
    if (strncmp(line, "end", strlen("end")) == 0)
    {
        // We will infer that we have hit the end when we find a new token.
        // Just treat this as white space to make our parsing rules easier.
        return WHITESPACE;
    }

    //
    // We are assuming that we a number.  Fortran-style scientific notation
    // uses 'D' when we are used to seeing 'E'.  So just switch them out.
    //
    for (i = 0 ; i < len ; i++)
    {
        if (line[i] == 'D' || line[i] == 'd')
            line[i] = 'E';
        if (line[i] == '\t')
            line[i] = ' ';
    }

    char *ystr = NULL;

    errno = 0;
    x = strtod(line, &ystr);
    if (((x == 0.0) && (ystr == line)) || (errno == ERANGE))
    {
        return INVALID_POINT;
    }
    if (ystr == NULL)
    {
        return VALID_XVALUE;
    }
    ystr = strstr(ystr, " ");
    if (ystr == NULL || ystr == line)
    {
        return VALID_XVALUE;
    }
    
    // Get past the space.
    ystr++;

    char *tmpstr;
    errno = 0;
    y = strtod(ystr, &tmpstr);
    if (((y == 0.0) && (tmpstr == ystr)) || (errno == ERANGE))
    {
        return INVALID_POINT;
    }

    ln = "";
    return VALID_POINT;
}    
Пример #12
0
/************************************************************************
*									*
*  Load ROI polygon.  File format is described in "save" routine.
*  The name line in the file ("polygon") has already been read by the
*  routine that calls this one.
*									*/
void
Polygon::load(ifstream &infile)
{
    const int buflen=128;
    char buf[buflen];
    int ndata=0;
    int isclosed;
    Fpoint *temp;

    // Read the number of points to expect
    while ( infile.getline(buf, buflen) ){
	if (buf[0] == '#'){
	    continue;
	}else if (strspn(buf, "\t ") == strlen(buf)){	// Ignore blank lines
	    continue;
	}else{
	    if (sscanf(buf,"%d", &ndata) != 1){
		msgerr_print("ROI polygon: Missing number of vertices");
		return;
	    }else{
		break;
	    }
	}
    }
    if (ndata < 3){
	msgerr_print("ROI polygon. Number vertices must be at least 3");
	return;
    }
    temp = new Fpoint[ndata];

    // Read in the data
    int i = 0;
    while ((i != ndata) && infile.getline(buf, buflen)){
	if (buf[0] == '#'){
	    continue;
	}else if (strspn(buf, "\t ") == strlen(buf)){	// Ignore blank lines
	    continue;
	}else{
	    if (sscanf(buf,"%f %f", &(temp[i].x), &(temp[i].y)) != 2){
		msgerr_print("ROI polygon: Missing data input");
		return;
	    }
	    i++;
	}
    }

    if (ndata != i){
	msgerr_print("ROI polygon: Incomplete input data points");
	return;
    }

    // Check if polygon is closed
    if (temp[0].x == temp[ndata-1].x && temp[0].y == temp[ndata-1].y){
	ndata--;
	isclosed = TRUE;
    }else{
	isclosed = FALSE;
    }

    // Put new ROIs in the appropriate frames
    Gframe *gframe;
    Roitool *tool;
    i = 1;
    for (gframe=Frame_select::get_selected_frame(i);
	 gframe;
	 gframe = Frame_select::get_selected_frame(++i))
    {
	if (gframe->imginfo){
	    tool = new Polygon(ndata, temp, gframe, isclosed);
	    tool->select(ROI_NOREFRESH, TRUE);
	    //gframe->display_data();
	}
    }
    delete [] temp;
}
Пример #13
0
void FlowArray::open( void *ctx, ifstream& fp) 
{
  int		type;
  int 		end_found = 0;
  char		dummy[40];

  for (;;)
  {
    fp >> type;
    switch( type) {
      case flow_eSave_Array: break;
      case flow_eSave_Rect: 
      {
        FlowRect *n = new FlowRect( (FlowCtx *) ctx);
	n->open( fp);
        insert( n);
        break;
      }
      case flow_eSave_Line: 
      {
        FlowLine *n = new FlowLine( (FlowCtx *) ctx);
	n->open( fp);
        insert( n);
        break;
      }
      case flow_eSave_Arc: 
      {
        FlowArc *n = new FlowArc( (FlowCtx *) ctx);
	n->open( fp);
        insert( n);
        break;
      }
      case flow_eSave_Text: 
      {
        FlowText *n = new FlowText( (FlowCtx *) ctx, "");
	n->open( fp);
        insert( n);
        break;
      }
      case flow_eSave_Pixmap: 
      {
        FlowPixmap *n = new FlowPixmap( (FlowCtx *) ctx, 
		(flow_sPixmapData *) NULL);
	n->open( fp);
        insert( n);
        break;
      }
      case flow_eSave_AnnotPixmap: 
      {
        FlowAnnotPixmap *n = new FlowAnnotPixmap( (FlowCtx *) ctx, 0);
	n->open( fp);
        insert( n);
        break;
      }
      case flow_eSave_AnnotPixmapButton: 
      {
        FlowAnnotPixmapButton *n = new FlowAnnotPixmapButton( (FlowCtx *) ctx, 0);
	n->open( fp);
        insert( n);
        break;
      }
      case flow_eSave_Radiobutton: 
      {
        FlowRadiobutton *n = new FlowRadiobutton( (FlowCtx *) ctx);
	n->open( fp);
        insert( n);
        break;
      }
      case flow_eSave_NodeClass: 
      {
        FlowNodeClass *n = new FlowNodeClass( (FlowCtx *) ctx, "");
	n->open( fp);
        insert( n);
        break;
      }
      case flow_eSave_ConClass: 
      {
        FlowConClass *n = new FlowConClass( (FlowCtx *) ctx, "", 
		flow_eConType_Straight, flow_eCorner_Right, flow_eDrawType_Line, 
		1);
	n->open( fp);
        insert( n);
        break;
      }
      case flow_eSave_ConPoint: 
      {
        FlowConPoint *n = new FlowConPoint( (FlowCtx *) ctx);
	n->open( fp);
        insert( n);
        break;
      }
      case flow_eSave_Annot: 
      {
        FlowAnnot *n = new FlowAnnot( (FlowCtx *) ctx);
	n->open( fp);
        insert( n);
        break;
      }
      case flow_eSave_Arrow: 
      {
        FlowArrow *n = new FlowArrow( (FlowCtx *) ctx,0,0,0,0,0,0,flow_eDrawType_Line);
	n->open( fp);
        insert( n);
        break;
      }
      case flow_eSave_Node: 
      {
        FlowNode *n = new FlowNode( (FlowCtx *) ctx, "", 0, 0, 0);
	n->open( fp);
        insert( n);
        break;
      }
      case flow_eSave_Con: 
      {
	int sts;

        FlowCon *n = new FlowCon( (FlowCtx *) ctx, "", (FlowConClass *)0, 
 		(FlowNode *)0, (FlowNode *)0, 0, 0, &sts);
	n->open( fp);
        insert( n);
        break;
      }
      case flow_eSave_Point: 
      {
        FlowPoint *n = new FlowPoint( (FlowCtx *) ctx);
	n->open( fp);
        insert( n);
        break;
      }
      case flow_eSave_End: end_found = 1; break;
      default:
        cout << "FlowArray:open syntax error" << endl;
        fp.getline( dummy, sizeof(dummy));
    }
    if ( end_found)
      break;
  }
}
Пример #14
0
void GrowWindow::open( ifstream& fp)
{
    int		type;
    int 		end_found = 0;
    char		dummy[40];
    int		tmp;

    for (;;)
    {
        if ( !fp.good()) {
            fp.clear();
            fp.getline( dummy, sizeof(dummy));
            printf( "** Read error GrowWindow: \"%d %s\"\n", type, dummy);
        }

        fp >> type;
        switch( type) {
        case glow_eSave_GrowWindow:
            break;
        case glow_eSave_GrowWindow_file_name:
            fp >> file_name;
            break;
        case glow_eSave_GrowWindow_scrollbar_width:
            fp >> scrollbar_width;
            break;
        case glow_eSave_GrowWindow_scrollbar_color:
            fp >> tmp;
            scrollbar_color = (glow_eDrawType)tmp;
            break;
        case glow_eSave_GrowWindow_scrollbar_bg_color:
            fp >> tmp;
            scrollbar_bg_color = (glow_eDrawType)tmp;
            break;
        case glow_eSave_GrowWindow_vertical_scrollbar:
            fp >> vertical_scrollbar;
            break;
        case glow_eSave_GrowWindow_horizontal_scrollbar:
            fp >> horizontal_scrollbar;
            break;
        case glow_eSave_GrowWindow_window_scale:
            fp >> window_scale;
            break;
        case glow_eSave_GrowWindow_owner:
            fp.get();
            fp.getline( owner, sizeof(owner));
            break;
        case glow_eSave_GrowWindow_rect_part:
            GrowRect::open( fp);
            break;
        case glow_eSave_GrowWindow_userdata_cb:
            if ( ctx->userdata_open_callback)
                (ctx->userdata_open_callback)(&fp, this, glow_eUserdataCbType_Node);
            break;
        case glow_eSave_End:
            end_found = 1;
            break;
        default:
            cout << "GrowWindow:open syntax error" << endl;
            fp.getline( dummy, sizeof(dummy));
        }
        if ( end_found)
            break;
    }

    if ( strcmp( file_name, "") != 0)
        new_ctx();
    configure_scrollbars();
}
Пример #15
0
bool readAssoQua(ifstream & fin, deque<dtdclass *>&d_class, char * name, associate & basAsso, associate& toAsso){
    char filedetail[256];/*record the each line of file from the compiler*/
    char * tempChar;
    string temp, qualiClass;
    bool finishQualiAssoClass = false;
    bool haveQualification = false;
    bool haveAssociation = false;/*check the association have detail or not*/
    attribute tempattribute;
    deque<attribute *> tempQualification;
    
    deque<dtdclass*>::iterator first;/*recond the first position of the deque*/
    deque<dtdclass*>::iterator last;/*recond the last position of the deque*/
    do{
        fin.getline(filedetail,255);
        if(strcmp(filedetail, "")==0){continue;}/*if the line is empty, continue*/
        tempChar = strtok(filedetail,"<>");//cut front of "<"
        tempChar = strtok(NULL, "<>");/*get the detail between <> */
        temp = tempChar;
        if(temp=="/association_class" || temp =="/Link"){//check if is end of one association class
            finishQualiAssoClass=true;//is control while loop
        }
        else if(temp == "nameOfAssociationClass"){
            haveAssociation=true;
            tempChar = strtok(NULL, "<>");
            strcpy(name, tempChar);
            qualiClass = tempChar;
            if(!d_class.empty()){//check the deque is not empty
                    first = d_class.begin();//get the begin of the deque
                    last = d_class.end();//get the end of the deque
                    for (deque<dtdclass *>::iterator i=first; i !=last;i++){
                        if(qualiClass ==(*i)->getname()){//add association into class
                            (*i)->setlevel(1);
                            int tempMulti;
                            tempMulti = basAsso.to_multi;
                            basAsso.to_multi = 1;/*change the multi link of the association*/
                            (*i)->setassociation(basAsso);//add association
                            basAsso.to_multi = tempMulti;;/*get back the original multi link number of the association*/
                            tempMulti = toAsso.to_multi;
                            toAsso.to_multi =1;/*change the multi link of the association*/
                            (*i)->setassociation(toAsso);//add association
                            toAsso.to_multi = tempMulti;/*get back the original multi link number of the association*/
                            if(haveQualification == true){
                                if(!tempQualification.empty()){/*get the qualification attribute from the deque and add it into the class*/
                                    deque<attribute *>::iterator firstAttribute = tempQualification.begin();
                                    deque<attribute *>::iterator lastAttribute =  tempQualification.end();
                                    for(deque<attribute * >::iterator attributeI = firstAttribute; attributeI != lastAttribute; attributeI++){
                                        strcpy(tempattribute.att_name, (*attributeI)->att_name);
                                        tempattribute.isId = (*attributeI)->isId;
                                        tempattribute.ismulti= (*attributeI)->ismulti;
                                        (*i)->setattribute(tempattribute);//add the attribute into the class
                                    }
                                }
                            }/*finish add all qualification into the class*/
                        }
                    }
                }
        }
        else if(temp == "qualification"){
            haveAssociation = true;
            tempChar = strtok(NULL, "/<");
            temp = tempChar;
            if(temp !="<"){
                attribute * tempAttri = new attribute;
                strcpy(tempAttri->att_name,tempChar);
                tempAttri->isId = true;
                tempAttri->ismulti = false;
                haveQualification =true;
                tempQualification.push_back(tempAttri);
            }
        }
        
    }while(finishQualiAssoClass !=true);
    return haveAssociation;
}
Пример #16
0
int Index::deserialize(ifstream& ifs, map<string, SNode>& metadata, const Address* addr)
{
   vector<string> dirs;
   dirs.resize(1024);
   map<string, SNode>* currdir = &metadata;
   int currlevel = 1;

   while (!ifs.eof())
   {
      char tmp[4096];
      tmp[4095] = 0;
      char* buf = tmp;

      ifs.getline(buf, 4096);
      int len = strlen(buf);
      if ((len <= 0) || (len >= 4095))
         continue;

      for (int i = 0; i < len; ++ i)
      {
         if (buf[i] == ' ')
         {
            buf[i] = '\0';
            break;
         }
      }

      int level = atoi(buf);

      SNode sn;
      sn.deserialize(buf + strlen(buf) + 1);
      if ((!sn.m_bIsDir) && (NULL != addr))
      {
         sn.m_sLocation.clear();
         sn.m_sLocation.insert(*addr);
      }

      if (level == currlevel)
      {
         (*currdir)[sn.m_strName] = sn;
         dirs[level] = sn.m_strName;
      }
      else if (level == currlevel + 1)
      {
         map<string, SNode>::iterator s = currdir->find(dirs[currlevel]);
         currdir = &(s->second.m_mDirectory);
         currlevel = level;

         (*currdir)[sn.m_strName] = sn;
         dirs[level] = sn.m_strName;
      }
      else if (level < currlevel)
      {
         currdir = &metadata;

         for (int i = 1; i < level; ++ i)
         {
            map<string, SNode>::iterator s = currdir->find(dirs[i]);
            currdir = &(s->second.m_mDirectory);
         }
         currlevel = level;

         (*currdir)[sn.m_strName] = sn;
         dirs[level] = sn.m_strName;
      }
   }

   return 0;
}
Пример #17
0
string readline(ifstream &f)
{
	char buf[1024];
	f.getline(buf, 1024);
	return buf;
}
Пример #18
0
int main(int argv,char*argc[])
{
    int w,h;
    fin >> w >> h;
    vector<vector<char> > map;
    char tmp[200];
    fin.getline(tmp,200);
    for(int i=0;i<=2*h;++i)
    {
        vector<char> row;
        fin.getline(tmp,200);
        for(int j=0;j<=2*w;++j)
        {
            row.push_back(tmp[j]);
        }
        map.push_back(row);
    }
    int x,y;
    vector<int> node(w*h);
    vector< vector<int> > edge(w*h);
    vector<int> st;
    for(int i=0;i<=h;++i)
    {
        y=2*i;
        for(int j=0; j<w;++j)
        {
            x=2*j+1;
            if(map[y][x]==' ')
            {
                if(i==0)
                {
                    node[i*w+j] = 1;
                    st.push_back(i*w+j);
                }
                else if(i==h)
                {
                    node[(i-1)*w+j] = 1;
                    st.push_back(i*w-w+j);
                }
                else
                {
                    edge[i*w+j].push_back((i-1)*w+j);
                    edge[(i-1)*w+j].push_back(i*w+j);
                }
            }
        }
    }
    for(int i=0;i<h;++i)
    {
        y=2*i+1;
        for(int j=0;j<=w;++j)
        {
            x=2*j;
            if(map[y][x]==' ')
            {
                if(j==0)
                {
                    node[i*w+j] = 1;
                    st.push_back(i*w+j);
                }
                else if(j==w)
                {
                    node[i*w+j-1] = 1;
                    st.push_back(i*w+j-1);
                }
                else
                {
                    edge[i*w+j].push_back(i*w+j-1);
                    edge[i*w+j-1].push_back(i*w+j);
                }
            }
        }
    }
    int max=0;
    vector<int> vv[2];
    for(int ss=0;ss < 2;++ss)
    {
        int s=st[ss];
        vv[ss].resize(w*h);
        vector<int> abl(w*h);
        abl[s]=1;
        vv[ss][s] = 1;
        queue<pair<int,int> > que;
        que.push(make_pair(s,1));
        pair<int,int> top;
        int dist,num;
        while(!que.empty())
        {
            top = que.front();
            que.pop();
            num = top.first;
            dist = top.second;
            for(vector<int>::iterator it=edge[num].begin(); it != edge[num].end();++it)
            {
                if(abl[*it]==0)
                {
                    abl[*it]=1;
                    que.push(make_pair(*it,dist+1));
                    vv[ss][*it] = dist+1;
                }
            }
        }
    }
    int tmpp;
    for(int i=0;i<w*h;++i)
    {
        tmpp = min(vv[0][i],vv[1][i]);
        if(tmpp > max) max = tmpp;
    }
    fout << max<< endl;
    fin.close();
    fout.close();
    return 0;
}
// Calcula y Retorna el entero de la formula (info)
int BuscarValorEc(ifstream&lectura, ofstream &fina,char*info,int hoja)
{
    info++;
    char *suma [70];
    char * ptr ;
    char * formula= new char [500];
    char * col = new char [200];
    char * fil;
    int fila,j,columnaa,val=0,sum[70];
    ptr = strtok(info,"+");
    int i=0;
    while(ptr != NULL)
    {
        suma[i] = ptr;
        ptr = strtok(NULL, "+");
        i++;
    }
    for(int m=0; m<i; m++)
    {
        posicion(lectura,hoja);
        lectura.getline(formula,200);
        j=0;
        fil=col= suma[m];
        while(58< *(fil) ||*(fil)< 47)
        {
            fil++;
        }
        while( *(fil+j)!= '\0')
        {
            *(formula+j)= *(fil+j);
            j++;
        }
        *(formula+j)='\0';
        *fil='\0';
        fil=formula;
        fila=numero(fil);
        columnaa=columna(col);
        for(int k=1; k<fila; k++)
        {
            lectura.getline(formula,200);
        }
        for(int p=1; p<columnaa; p++)
        {
            lectura>>formula;
        }
        lectura>>formula;
        if(*formula!='=')
        {
            sum[m]=numero(formula);
        }
        else
        {
            sum[m]=BuscarValorEc(lectura,fina,formula,hoja);
        }
    }
    for(int o=0; o<i; o++)
    {
        val =val +sum[o];
    }
    delete []suma;
    delete []formula;
    delete []col;
    delete []ptr ;
    return val;

}
Пример #20
0
//========================setData=====================================
// Sets this Object's description to the line of characters extracted
// from the infile stream. If the description is longer than 
// MAX_SIZE the trailing data will be omitted. 
// 
// Preconditions: The give ifstream is open. 
//		
// Postconditions: my_desc is set to the first MAX_SIZE of chars in 
//		   the infile.
//====================================================================
void Object::setData (ifstream &infile)
{
	if (infile.is_open()) 
		infile.getline (my_desc, MAX_SIZE + 1);	
}	
Пример #21
0
int main()
{
    cin.getline(s, 100002);
    for(int i=0; s[i] ; )
    {
        if(isdigit(s[i]))
        {
            fac[++vf]=s[i]-'0';
            while(isdigit(s[++i]))
                    fac[vf]=fac[vf]*10+s[i]-'0';
            continue;
        }
        if(s[i]=='(')
            {
                op[++kp]=s[i];
                i++;
                continue;
            }
        if(s[i]=='*')
            {
                //equal priority
                if(op[kp]=='*')
                   {
                        kp--;
                        op1=fac[vf--];
                        fac[vf]*=op1;
                   }
                if(op[kp]=='/')
                    {
                        kp--;
                        op1=fac[vf--];
                        fac[vf]/=op1;
                    }
                else op[kp]=s[i];
            }
        if(s[i]=='/')
            {
                if(op[kp]=='*')
                   {
                        kp--;
                        op1=fac[vf--];
                        fac[vf]*=op1;
                   }
                if(op[kp]=='/')
                    {
                        kp--;
                        op1=fac[vf--];
                        fac[vf]/=op1;
                    }
                else op[kp]=s[i];
            }
        if(s[i]=='+')
            {
                if(op[kp]=='+')
                   {
                        kp--;
                        op1=fac[vf--];
                        fac[vf]+=op1;
                   }
                if(op[kp]=='-')
                    {
                        kp--;
                        op1=fac[vf--];
                        fac[vf]-=op1;
                    }
                if(op[kp]=='*')
                    {
                        op1=fac[vf--];
                        fac[vf]*=op1;
                    }
                else if(op[kp]=='/')
                    {
                        op1=fac[vf--];
                        fac[vf]/=op1;
                    }
                else op[kp]=s[i];
                i++ ;continue;
            }
        if(s[i]=='-')
            {
                if(op[kp]=='+')
                   {
                        kp--;
                        op1=fac[vf--];
                        fac[vf]+=op1;
                   }
                if(op[kp]=='-')
                    {
                        kp--;
                        op1=fac[vf--];
                        fac[vf]-=op1;
                    }
                if(op[kp]=='*')
                    {
                        op1=fac[vf--];
                        fac[vf]*=op1;
                    }
                else if(op[kp]=='/')
                    {
                        op1=fac[vf--];
                        fac[vf]/=op1;
                    }
                else op[kp]=s[i];
                i++ ;continue;
            }
        if(s[i]==')')
           {
                if(op[kp]=='(')
                    {
                        kp--;
                        ++i;
                        continue;
                    }
                else if(op[kp]=='*')
                    {
                        op1=fac[vf--];
                        fac[vf]*=op1;
                        --kp;
                    }
                else if(op[kp]=='/')
                    {
                        op1=fac[vf--];
                        fac[vf]/=op1;
                        --kp;
                    }
                else if(op[kp]=='+')
                    {
                        op1=fac[vf--];
                        fac[vf]+=op1;
                        --kp;
                    }
                else if(op[kp]=='-')
                    {
                        op1=fac[vf--];
                        fac[vf]-=op1;
                        --kp;
                    }
            }
        ++i;
    }
 // for(int i=1;i<=kp;++i)
  //      cout<<op[i];
    cout<<fac[1];
    cin.close();
    cout.close();
    return 0;
}
Пример #22
0
/*readFile: reads in the maze and stores it inside of a 2D array to be accessed for further use
Parameters: the file that contains the maze and a double pointer mazeArray(2D array)
returns: nothing
*/
void readFile(ifstream& input, char **mazeArray, int rows, int columns){
	for (int i = 0; i<rows; i++){
		input.getline(mazeArray[i], columns);
		cout << mazeArray[i] << endl;
	}
} 
Пример #23
0
void GrowArc::open( ifstream& fp)
{
  int		type;
  int 		end_found = 0;
  char		dummy[40];
  int		tmp;
  int		j;
  char		c;

  for (;;)
  {
    if ( !fp.good()) {
      fp.clear();
      fp.getline( dummy, sizeof(dummy));
      printf( "** Read error GrowArc: \"%d %s\"\n", type, dummy);      
    }

    fp >> type;
    switch( type) {
      case glow_eSave_GrowArc: break;
      case glow_eSave_GrowArc_n_name:
        fp.get();
        fp.getline( n_name, sizeof(n_name));
        break;
      case glow_eSave_GrowArc_x_right: fp >> x_right; break;
      case glow_eSave_GrowArc_x_left: fp >> x_left; break;
      case glow_eSave_GrowArc_y_high: fp >> y_high; break;
      case glow_eSave_GrowArc_y_low: fp >> y_low; break;
      case glow_eSave_GrowArc_original_border_drawtype: fp >> 
		tmp; original_border_drawtype = (glow_eDrawType)tmp; break;
      case glow_eSave_GrowArc_original_fill_drawtype: fp >> 
		tmp; original_fill_drawtype = (glow_eDrawType)tmp; break;
      case glow_eSave_GrowArc_fill_drawtype: fp >> 
		tmp; fill_drawtype = (glow_eDrawType)tmp; break;
      case glow_eSave_GrowArc_background_drawtype: fp >> 
		tmp; background_drawtype = (glow_eDrawType)tmp; break;
      case glow_eSave_GrowArc_border: fp >> border; break;
      case glow_eSave_GrowArc_shadow: fp >> shadow; break;
      case glow_eSave_GrowArc_shadow_width: fp >> shadow_width; break;
      case glow_eSave_GrowArc_shadow_contrast: fp >> shadow_contrast; break;
      case glow_eSave_GrowArc_relief: fp >> tmp; relief = (glow_eRelief)tmp; break;
      case glow_eSave_GrowArc_disable_shadow: fp >> disable_shadow; break;
      case glow_eSave_GrowArc_fixcolor: fp >> fixcolor; break;
      case glow_eSave_GrowArc_gradient: fp >> tmp; gradient = (glow_eGradient)tmp; break;
      case glow_eSave_GrowArc_gradient_contrast: fp >> gradient_contrast; break;
      case glow_eSave_GrowArc_disable_gradient: fp >> disable_gradient; break;
      case glow_eSave_GrowArc_fixposition: fp >> fixposition; break;
      case glow_eSave_GrowArc_fill_eq_background: fp >> fill_eq_background; break;
      case glow_eSave_GrowArc_dynamicsize: fp >> dynamicsize; break;
      case glow_eSave_GrowArc_dynamic:
        fp.getline( dummy, sizeof(dummy));
        if ( dynamicsize)
        {
          dynamic = (char *) calloc( 1, dynamicsize);
	  fp.get();
          for ( j = 0; j < dynamicsize; j++)
	  {
	    if ((c = fp.get()) == '"')
	    {
	      if ( dynamic[j-1] == '\\')
	        j--;
	      else
              {
	        dynamic[j] = 0;
                break;
              }
	    }
            dynamic[j] = c;
	  }
          fp.getline( dummy, sizeof(dummy));
        }
        break;
      case glow_eSave_GrowArc_arc_part: 
        GlowArc::open( fp);
        break;
      case glow_eSave_GrowArc_trf: trf.open( fp); break;
      case glow_eSave_End: end_found = 1; break;
      default:
        cout << "GrowArc:open syntax error" << endl;
        fp.getline( dummy, sizeof(dummy));
    }
    if ( end_found)
      break;
  }
}
Пример #24
0
//-----------------------------------------------------------------------------
// TemplateFileParsor::Tokenize
//-----------------------------------------------------------------------------
void TemplateFileParsor::Tokenize(ifstream &fs, int &iLine, TemplateToken::Type eEndBlockToken)
{
  while( !fs.eof() )
  {
    iLine++;
    fs.getline(g_acScratchBuf, g_iScratchLen);
    String strLine = g_acScratchBuf;
    Trim(&strLine);
    // Merge splitted lines (with '\')
    while( EndWith(strLine, '\\') )
    {
      iLine++;
      strLine.erase(strLine.size()-1);
      fs.getline(g_acScratchBuf, g_iScratchLen);
      String strPartLine = g_acScratchBuf;
      Trim(&strPartLine);
      strLine += strPartLine;
    }

    // Replace tabs with spaces
    strLine.Replace('\t', ' ');

    if( strLine.size() == 0 || strLine.StartWith("//") || strLine.StartWith("#") )
      // Empty line
      continue;

    int iTokenType = (int)GetLineToken(strLine);
    switch( iTokenType )
    {
      case TemplateToken::PRINT:
        ParsePrintData(&strLine, iLine);
        break;
      case TemplateToken::LOOP:
      {
        int iPos = ParseLoop(&strLine, iLine);
        Tokenize(fs, iLine, TemplateToken::END_LOOP);
        // Store end block position in token vector
        m_vecToken[iPos]->m_iEndBlockPos = m_vecToken.size() - 1;
        break;
      }
      case TemplateToken::IF:
      {
        int iPos = ParseIf(&strLine, iLine);
        Tokenize(fs, iLine, TemplateToken::END_IF);
        // Store end block position in token vector
        m_vecToken[iPos]->m_iEndBlockPos = m_vecToken.size() - 1;
        break;
      }
      case TemplateToken::BLOCK_START:
        {
          int iPos = ParseBlockStart(&strLine);
          Tokenize(fs, iLine, TemplateToken::BLOCK_END);
          // Store end block position in token vector
          m_vecToken[iPos]->m_iEndBlockPos = m_vecToken.size() - 1;
          break;
        }
      case TemplateToken::END_LOOP:
        ParseEndBlock(eEndBlockToken, TemplateToken::END_LOOP, iLine);
        return;
      case TemplateToken::END_IF:
        ParseEndBlock(eEndBlockToken, TemplateToken::END_IF, iLine);
        return;
      case TemplateToken::BLOCK_END:
        ParseEndBlock(eEndBlockToken, TemplateToken::BLOCK_END, iLine);
        return;
      case TemplateToken::SET:
        ParseSet(&strLine, iLine);
        break;
      case TemplateToken::OUTPUT:
        ParseOutput(&strLine, iLine, false);
        break;
      case TemplateToken::BINARY_OUTPUT:
        ParseOutput(&strLine, iLine, true);
        break;
      case TemplateToken::BINARY:
        ParseBinary(&strLine, iLine);
        break;
      case TemplateToken::PADDING:
        ParsePadding(&strLine, iLine);
        break;
      case TemplateToken::INCLUDE:
        ParsePreprocessorInclude(&strLine);
        break;
      default:
        cerr << "Error: Bad syntax at line " << iLine << " in file " << m_strCurrentTemplateFile << "." << endl;
        exit(1);
    }
  }

  if( eEndBlockToken != TemplateToken::NO_TYPE )
  {
    // End of file reached while parsing a 'loop' or 'if' block
    cerr << "Error : Unexpected end of template file (" << m_strCurrentTemplateFile << ")." << endl;
    exit(1);
  }
}
Пример #25
0
BOOL static getField(ifstream& fin, CString& marker, CString& contents)
{
	static BOOL bNextLineIsBlank=FALSE;
	if(bNextLineIsBlank)
	{
		bNextLineIsBlank=FALSE;
		marker = "BLANKLINE";
		contents ="";
		return TRUE;
	}

	ASSERTX(fin.is_open());

	const int kBuffSize = 5000;	// CURRENTLY MAX FIELD SIZE TOO!

	CString sField;
	LPTSTR buff = sField.GetBuffer(kBuffSize+2);
	LPTSTR start_buff = buff;

	fin.eatwhite();
	char* b = buff;
	BOOL bFoundBlank = FALSE;
	do
	{
		fin.getline(b, kBuffSize - (b-buff), '\n');
		b += fin.gcount();
		if(fin.gcount())
		{
			*(b-1) = '\n'; // put a carriage return in place of the null terminator
			*b = '\0';		// null terminate in case the next getline fails
		}
		while(fin.peek() == '\n') // keep swallowing blank lines until we see what's at the end of them
		{
			fin.get(); // swallow the \n;
			if(fin.peek() == '\\')	 // if the blanks are followed by a record, then this constitutes a true blank line
			{
				bFoundBlank=TRUE;
				break;
			}
		}
	} while (!bFoundBlank && fin.good() && fin.gcount() && fin.peek() != '\\');

	bNextLineIsBlank = bFoundBlank; // will be used on the next call

	if( (kBuffSize-1) <= (b-buff))	// to long (and thus fin.gcount() == 0)
	{
		CString s;
		s.Format("The interlinear file appears to have a line which is longer than the maximum of %d characters which csCleanITX can handle.\n",
					kBuffSize);
		throw(s);

	}

	if(!buff[0])	// end of file
	{	sField.ReleaseBuffer(-1);
		return FALSE;
	}

	// eat white space before the SFM Code (will always be there after a \dis)
	while(*buff && _ismbcspace(*buff))
	{
		*buff='~'; // a hack so that iSpaceLoc, below, isn't set to the space between the "\dis" and marker
		++buff;
	}


	int iSpaceLoc ;
	// figure out where the marker ends and field contents begin
	iSpaceLoc = sField.FindOneOf(" \t\n");
	if(iSpaceLoc <= 1)// [0] should be the slash, [1] at least one char
	{	sField.ReleaseBuffer(-1);
		return FALSE;
	}


	start_buff[iSpaceLoc] = '\0';
	marker = buff + 1; // +1 to skip the slash
	marker.TrimRight();

	contents = start_buff + iSpaceLoc+1;
	contents.TrimLeft();
	contents.TrimRight();

	sField.ReleaseBuffer(-1);
	return TRUE;
}
Пример #26
0
void readSingleClass(ifstream & fin, dtdclass * tempclass){/*read a single class detail*/
    bool classFinish=false, IDexist=false;
    char filedetail[256];/*record the each line of file from the compiler*/
    char * tempChar;
    string temp;
    do{
        fin.getline(filedetail,255);
        if(strcmp(filedetail, "")==0){continue;}/*if the line is empty, continue*/
        tempChar = strtok(filedetail,"<>");/*cut front of "<"*/
        temp = tempChar;
        if(temp=="/class"){/*check if is end of one class*/
            classFinish=true;/*is control while loop*/
        }
        else {
            tempChar = strtok(NULL, ">");/*get detail between < >*/
            temp = tempChar;
        }
        if(temp=="/class"){/*check if is end of one class*/
            classFinish=true;/*is control while loop*/
        }
        else if(temp == "class_name"){
            tempChar = strtok(NULL,"<>");//get the name of the class*/
            tempclass->setname(tempChar);
        }
        else if(temp=="attribute"){
            /*if it is attribute, get detail of the new attribute*/
            attribute tempattribute;
            do{
                fin.getline(filedetail,255);
                if(strcmp(filedetail, "")==0){continue;}/*if the line is empty, continue*/
                tempChar = strtok(filedetail,"<>");/*cut front of "<"*/
                tempChar = strtok(NULL, ">");/*get detail between < >*/
                temp = tempChar;
                if(temp=="attribute_name"){
                    tempChar=strtok(NULL,"<>");
                    strcpy(tempattribute.att_name, tempChar);
                }
                else if(temp=="identifier"){/*check the attribute is ID or not*/
                    tempChar = strtok(NULL,"<>");
                    temp = tempChar;
                    if(temp =="ID" || temp =="ID1"){/*check if the attribute is ID or not*/
                        if(IDexist == false){//if the class do not have ID exist, set ID.
                            IDexist =true;
                            tempattribute.isId = true;
                        }
                        else{tempattribute.isId= false;}//if the class have ID exist, do not set ID
                    }else{tempattribute.isId= false;}
                }
                else if(temp=="multiplicity"){
                    tempChar=strtok(NULL,"]<");
                    string tetemp = tempChar;
                    if((tetemp.compare("["))>0){/*the attribute is multi*/
                        tempattribute.ismulti = true;
                        findMaxMin(tetemp, tempattribute.max, tempattribute.min);//call the function to find the max and min
                        if(tempattribute.min <0){tempattribute.min=0;}
                    }else{tempattribute.ismulti = false;}
                }
            }while(temp !="/attribute");
            tempclass->setattribute(tempattribute);/*put attribute into the class*/
        }
    }while(classFinish != true );
}
Пример #27
0
void load(ifstream &f,mint &elementos, mdouble &nodos, mdouble &contorno){
	
	nodos.clear();
	elementos.clear();
	contorno.clear();
	/// VARIABLES
	int n,o,p;
	char t[100];
	double x;
	
	/// CARGAMOS LAS VARIABLES GENERALES DEL PROBLEMA
	f.getline(t,100);
	e = atof(t); /// TOLERANCIA
	f.getline(t,100);
	iteraciones = atoi(t); /// ITERACIONES MAXIMAS
	f.getline(t,100);
	dt = atof(t); /// PASO DE TIEMPO
	f.getline(t,100);
	Re = atof(t); /// NUMERO DE REYNOLDS
	
	/// LEEMOS LA CANTIDAD DE NODOS
	f.getline(t,100);
	n = atoi(t);
	/// ASIGNAMOS LOS NODOS
	for(int i=0;i<n;i++){
		vector<double> nod;
		/// COORDENADA X
		f.getline(t,100);
		x = atof(t);
		nod.push_back(x);
		/// COORDENADA Y
		f.getline(t,100);
		x = atof(t);
		nod.push_back(x);
		nodos.push_back(nod);
	}
	
	/// LEEMOS LA CANTIDAD DE ELEMENTOS
	f.getline(t,100);
	n = atoi(t);
	
	/// LEEMOS LA CANTIDAD DE NODOS POR ELEMENTO
	f.getline(t,100);
	o = atoi(t);
	
	/// LEEMOS LOS INDICES DE LOS ELEMENTOS
	for(int i=0;i<n;i++){
		vector<int> e;
		f.getline(t,100);
		char *ptr;
		/// LOS NUMEROS DE LOS NODOS ESTAN SEPARADOS POR UN ESPACIO
		ptr = strtok(t," ");
		p = atoi(ptr);
		e.push_back(p-1);
		for(int j=0;j<o-1;j++){
			// mandarle un null parece que hace que continue con el puntero del anterior strtok
			ptr = strtok(NULL," ");
			p = atoi(ptr);
			e.push_back(p-1);
		}
		elementos.push_back(e);
	}
	/// LEEMOS LAS CONDICIONES DE CONTORNO
	
	/// LA ORGANIZACION DEL CONTORNO ES
	/// NumNodo TipoFront Valores
	
	/// LEEMOS LA CANTIDAD DE NODOS CON WALL
	f.getline(t,100);
	n = atoi(t);
	for(int i=0;i<n;i++){
		vector<double> nContorno;
		/// NODO 1
		f.getline(t,100);
		nContorno.push_back(atoi(t)-1);
		/// NODO 2
		f.getline(t,100);
		nContorno.push_back(atoi(t)-1);
		/// TIPO DE CONTORNO
		nContorno.push_back(1.0);
		/// ASIGNAMOS u = v = 0 porque es wall
		nContorno.push_back(.0);
		nContorno.push_back(.0);
		contorno.push_back(nContorno);
	}
	
	/// LEEMOS LA CANTIDAD DE NODOS CON VELOCIDAD IMPUESTA
	f.getline(t,100);
	n = atoi(t);
	for(int i=0;i<n;i++){
		vector<double> nContorno;
		/// NODO 1
		f.getline(t,100);
		nContorno.push_back(atoi(t)-1);
		/// NODO 2
		f.getline(t,100);
		nContorno.push_back(atoi(t)-1);
		/// TIPO DE CONTORNO
		nContorno.push_back(1.0);
		/// LEEMOS u
		f.getline(t,100);
		nContorno.push_back(atof(t));
		/// LEEMOS v
		f.getline(t,100);
		nContorno.push_back(atof(t));
		contorno.push_back(nContorno);
	}
	
	/// LEEMOS LA CANTIDAD DE NODOS CON PRESION IMPUESTA
	f.getline(t,100);
	n = atoi(t);
	for(int i=0;i<n;i++){
		vector<double> nContorno;
		/// NODO 1
		f.getline(t,100);
		nContorno.push_back(atof(t)-1);
		/// NODO 2
		f.getline(t,100);
		nContorno.push_back(atof(t)-1);
		/// TIPO DE CONTORNO
		nContorno.push_back(2.0);
		/// LEEMOS LA PRESION
		f.getline(t,100);
		nContorno.push_back(atof(t));
		contorno.push_back(nContorno);
	}
	
	f.close();
}
Пример #28
0
void readSingleAssociation(ifstream &fin, deque<dtdclass *>&d_class){
   
    bool associationFinish=false;
    bool firstclass = true;
    string base_name, to_name;/*save the name and two class name of the association*/
    int baseLevel, toLevel;/*to save the level of both class of the association*/
    deque<attribute * > baseQualification, toQualification; /*save the list of qualification*/
    attribute basequali, toquali;/*save the name of the qualification*/
    associate basAsso, toAsso;
    bool haveBasequali = false;/*check if there have qualification in first class*/
    bool haveToquali = false;/*check if there have qualification in second class*/
    bool haveLink=false;/*check the association have link or not*/
    char filedetail[256];/*record the each line of file from the compiler*/
    char linker_name[64];
    string Slinker_name;
    char * tempChar;
    string temp;
    deque<dtdclass*>::iterator first;/*recond the first position of the deque*/
    deque<dtdclass*>::iterator last;/*recond the last position of the deque*/
    do{
        fin.getline(filedetail,255);
        if(strcmp(filedetail, "")==0){continue;}/*if the line is empty, continue*/
        tempChar = strtok(filedetail,"<>");//cut front of "<"
        temp = tempChar;
        if(temp=="/association"){//check if is end of one association
            associationFinish=true;//is control while loop
        }
        else {
            tempChar = strtok(NULL, ">");//get detail between < >
            temp = tempChar;
            if(temp=="/association"){//check if is end of one association
                associationFinish=true;//is control while loop
            }
            else if(temp == "nameOfAssociation"){
                tempChar = strtok(NULL,"<>");//get the name of the association
                strcpy(basAsso.ass_name, tempChar);
                strcpy(toAsso.ass_name , tempChar);
            }
            else if(temp =="class_name"){/*find the class name of the association of the class*/
                tempChar = strtok(NULL, "<>");/*get the class name*/
                if(firstclass ==true){
                    /*call function to read detail of the association of the first class*/
                    readAssoClass(fin, basAsso, toAsso, baseLevel,haveToquali,toQualification);
                    
                    firstclass = !firstclass;
                    strcpy(toAsso.tclass_name, tempChar);/*record the relation class*/
                    base_name = tempChar;
                    Slinker_name = base_name;/*record the name of first class*/
                    }
                else{
                    /*call function to read detail of the association of the second class*/
                    readAssoClass(fin, toAsso, basAsso, toLevel,haveBasequali, baseQualification );
                    
                    strcpy(basAsso.tclass_name , tempChar);/*record the relation class name */
                    to_name = tempChar;
                    Slinker_name = Slinker_name + to_name;/*record the name of the second class*/
                }
            }
            else if(temp =="Link"){
                fin.getline(filedetail,255);
                if(strcmp(filedetail, "")==0){continue;}/*if the line is empty, continue*/
                tempChar = strtok(filedetail,"<>");//cut front of "<"
                tempChar = strtok(NULL,"<>");/*get the detail in "<>" */
                temp = tempChar;
                if(temp=="/association"|| temp =="/Link"){//check if is end of one association
                    associationFinish=true;//is control while loop
                }
                else if(temp == "link_attribute"){
                    fin.getline(filedetail, 255);
                    if(strcmp(filedetail, "")==0){continue;}/*if the line is empty, continue*/
                    tempChar = strtok(filedetail,"<>");//cut front of "<"
                    tempChar = strtok(NULL, ">");//get detail between < >
                    tempChar = strtok(NULL, "<>");
                    temp = tempChar;
                    if(strcmp(toAsso.tclass_name, basAsso.tclass_name)!=0){//the two class name is not the same
                        haveLink = true;/*record the two class have link class*/
                        if(temp !="<"){
                            dtdclass * linkClass = new dtdclass();/*creast a linker class*/
                            linkClass->setname(Slinker_name);
                            linkClass->setlevel(1);
                            int tempMulti;
                            tempMulti = basAsso.to_multi;/*change the multi link of the association*/
                            basAsso.to_multi =1;
                            linkClass->setassociation(basAsso);/*set the association of the link class*/
                            /*get back the original multi link number of the association*/
                            basAsso.to_multi = tempMulti;
                            tempMulti = toAsso.to_multi;
                            toAsso.to_multi = 1;
                            linkClass->setassociation(toAsso);
                            toAsso.to_multi = tempMulti;

                            readLinkAttribute(tempChar, linkClass, fin);/*call the read attribute name*/
                            strcpy(linker_name, Slinker_name.c_str());
                            strcpy(basAsso.tclass_name, linker_name);/*change the relation class name*/
                            basAsso.base_multi =1;
                            strcpy(toAsso.tclass_name, linker_name);
                            toAsso.base_multi =1;
                            d_class.push_back(linkClass);//add link class into deque
                        }
                    }
                    else{
                        attribute base;
                        strcpy(base.att_name, tempChar);
                        base.isId = false;
                        base.ismulti = false;
                        base.max=1;
                        base.min=1;
                        first = d_class.begin();//get the begin of the deque
                        last = d_class.end();//get the end of the deque
                        for (deque<dtdclass *>::iterator i=first; i !=last;i++){
                            if(base_name ==(*i)->getname()){
                                (*i)->setattribute(base);
                            }
                        }
                    }
                    
                    
                }
                else if(temp == "association_class"){
                    bool haveAssociation;/*record the true or false have association class*/
                    //call read association qualification function
                    haveAssociation = readAssoQua(fin, d_class, linker_name, basAsso, toAsso);
                    if(haveAssociation == true){
                        haveLink = true;/*record the two class have link class*/
                        strcpy(basAsso.tclass_name, linker_name);/*change the relation class name*/
                        basAsso.base_multi =1;
                        strcpy(toAsso.tclass_name, linker_name);
                        toAsso.base_multi =1;
                    }
                }
                
            }
        }
    }while(associationFinish != true); //end of read the association
    //search correct class in the deque and put the association in it
    
    if(!d_class.empty()){//check the deque is not empty
        first = d_class.begin();//get the begin of the deque
        last = d_class.end();//get the end of the deque
        if(baseLevel==1 && toLevel ==3){baseLevel =2;}//if the relate is 1...*
        if(haveLink == true){//set the class level being 3, as a reference in DTD
            baseLevel =3;
            toLevel =3;
        }
        for (deque<dtdclass *>::iterator i=first; i !=last;i++){
            if(base_name ==(*i)->getname()){//add association into class
                (*i)->setassociation(basAsso);//add association
                (*i)->setlevel(baseLevel);
                if(haveBasequali == true){
                    if(!baseQualification.empty()){/*get the qualification attribute from the deque and add it into the class*/
                        deque<attribute *>::iterator firstAttribute = baseQualification.begin();
                        deque<attribute *>::iterator lastAttribute =   baseQualification.end();
                        for(deque<attribute * >::iterator attributeI = firstAttribute; attributeI != lastAttribute; attributeI++){
                            strcpy(basequali.att_name, (*attributeI)->att_name);
                            basequali.isId = (*attributeI)->isId;
                            basequali.ismulti= (*attributeI)->ismulti;
                            (*i)->setattribute(basequali);
                        }
                    }
                    
                }//add attribute if there any
            }
            else if(to_name==(*i)->getname()){
                (*i)->setassociation(toAsso);
                (*i)->setlevel(toLevel);
                if(haveToquali ==true){ 
                    if(!toQualification.empty()){/*get the qualification attribute from the deque and add it into the class*/
                        deque<attribute *>::iterator firstToAttribute = toQualification.begin();
                        deque<attribute *>::iterator lastToAttribute =   toQualification.end();
                        for(deque<attribute * >::iterator attributeI = firstToAttribute; attributeI != lastToAttribute; attributeI++){
                            strcpy(toquali.att_name, (*attributeI)->att_name);
                            toquali.isId = (*attributeI)->isId;
                            toquali.ismulti= (*attributeI)->ismulti;
                            (*i)->setattribute(toquali);
                        }
                    }
                        
                }
            }
        }//finish add association
    } 
}
Пример #29
0
main()
{
	int i, j, g;
	int a, b;
	char c, d;
	char S[100];

	infile >> H >> W;
	infile.getline(S, 100);

	N = 0;

	for (i = 0; i < 255; i++)
	{
		id[i] = -1;
		up[i] = -1;
		down[i] = -1;
	}

	for (i = 0; i < H; i++)
	{
		infile.getline(S, 100);

		for (j = 0; j < W; j++)
		{
			matrix[i][j] = S[j];
			if (S[j] != '.')
			{
			if (id[S[j]] == -1)
			{
				id[S[j]] = N;
				letter[N] = S[j];
				left[N] = j;
            right[N] = j;
				up[N] = i;
				N++;
			} else if (up[id[S[j]]] == i) {
				if (j > right[id[S[j]]])
				right[id[S[j]]] = j;
				if (j < left[id[S[j]]])
				left[id[S[j]]] = j;
			} else if (up[id[S[j]]] != i && up[id[S[j]]] != -1)
			{
				if (j > right[id[S[j]]])
					right[id[S[j]]] = j;
				if (j < left[id[S[j]]])
				left[id[S[j]]] = j;
				down[id[S[j]]] = i;



			}
			}
		}
	}

	for (i = 0; i < N; i++)
	{
		perm[i] =i;
		in[i] = 0;
		done[i] = 0;
	}



	for (i = 0; i < H; i++)
		for (j = 0; j < W; j++)
		{
			a = id[matrix[i][j]];

			for (b = 0; b < N; b++)
				if (a == b)
					top[a][a] = 0;
				else if (top[a][b] == 0) {
					if ( ((j == left[b] || j == right[b]) &&
						  (up[b] <= i && down[b] >= i)) ||
						((i == up[b] || i == down[b]) &&
						  (left[b] <= j && right[b] >= j)) )
						  {
						top[a][b] = 1;
						in[a]++;
						}
					else
						top[a][b] = 0;
				}
		}

	qsort(perm, N, sizeof(int), cmp);
	explore(0);


	return 0;
}
Пример #30
0
int ReadMifOneElement(ifstream& fMifFile, vector<pair<double, double> >& vCoorXYLst)
{
	int iLineLoop, iPntLoop;
	int iLineNum = 0;
	int iPntNum = 0;
	string strTok = " ";  
	string strPline = "Pline";
	string strLine = "Line";
	string strMultiple = "Multiple";
	double dX, dY;
	char  acLine[1024];
	vector<string> vFirstLineOfEle;

	vCoorXYLst.clear();

	do {
		memset(acLine, 0, 1024 );
		fMifFile.getline(acLine, 1024);
	} while( strcmp(acLine,"") == 0);

	vFirstLineOfEle.clear();
	vFirstLineOfEle = SplitString(acLine, strTok, "");   

	if( 0 == vFirstLineOfEle.size())
	{
		//log
		return RET_FAILED;
	}

	// 修改适应不同的mif样式表述 gaojian 2014-01-17
	while (vFirstLineOfEle[0] != strPline && vFirstLineOfEle[0] != strLine)
	{
		if (fMifFile.eof()) {
			return RET_FAILED;
		}

		do {
			memset(acLine, 0, 1024 );
			fMifFile.getline(acLine, 1024);
			if (fMifFile.eof()) {
				return RET_FAILED;
			}
		} while( strcmp(acLine,"") == 0);

		vFirstLineOfEle.clear();
		vFirstLineOfEle = SplitString(acLine, strTok, "");   

		if( 0 == vFirstLineOfEle.size())
		{
			//log
			return RET_FAILED;
		}
	}

	if( vFirstLineOfEle[0] == strPline )
	{
		if( vFirstLineOfEle[1] == strMultiple)
		{
			iLineNum = StringToInt(vFirstLineOfEle[2]);

			for( iLineLoop = 0; iLineLoop < iLineNum; iLineLoop++ )
			{
				memset(acLine, 0, 1024 );
				fMifFile.getline(acLine, 1024);

				vFirstLineOfEle.clear();
				vFirstLineOfEle = SplitString(acLine, strTok, "");
				iPntNum = StringToInt(vFirstLineOfEle[0]);
				for( iPntLoop = 0; iPntLoop < iPntNum; iPntLoop++ )
				{
					memset(acLine, 0, 1024 );
					fMifFile.getline(acLine, 1024);

					vFirstLineOfEle.clear();
					vFirstLineOfEle = SplitString(acLine, strTok, "");   

					dX = StringToDouble(vFirstLineOfEle[0]);
					dY = StringToDouble(vFirstLineOfEle[1]);
					vCoorXYLst.push_back(make_pair(dX,dY));				
				}
			}
		}
		else
		{
			iPntNum = StringToInt(vFirstLineOfEle[1]);

			for( iPntLoop = 0; iPntLoop < iPntNum; iPntLoop++ )
			{
				memset(acLine, 0, 1024 );
				fMifFile.getline(acLine, 1024);

				vFirstLineOfEle.clear();
				vFirstLineOfEle = SplitString(acLine, strTok, "");   

				dX = StringToDouble(vFirstLineOfEle[0]);
				dY = StringToDouble(vFirstLineOfEle[1]);
				vCoorXYLst.push_back(make_pair(dX,dY));				
			}
		}
	}
	else if( vFirstLineOfEle[0] == strLine )
	{
		dX = StringToDouble(vFirstLineOfEle[1]);
		dY = StringToDouble(vFirstLineOfEle[2]);
		vCoorXYLst.push_back(make_pair(dX,dY));

		dX = StringToDouble(vFirstLineOfEle[3]);
		dY = StringToDouble(vFirstLineOfEle[4]);
		vCoorXYLst.push_back(make_pair(dX,dY));
	}
	else
	{
		//log
		return RET_FAILED;
	}

	fMifFile.getline(acLine, 1024);


	return RET_SUCCESS;
}