Ejemplo n.º 1
0
int Program::run(int argc, char* argv[]) {
    int maxlev;
    if (read_parameter(argc, argv, "help")) {
        print_help();
        return 0;
    }
    if (read_parameter(argc, argv, "maxlev", &maxlev)) {
        if (MPI_rank() == 0) {
            printf("Maximum refinement level is %i\n", maxlev);
        }
    } else {
        if (MPI_rank() == 0) {
            printf("Missing maxlev argument\n");
            print_help();
        }
        return -1;
    }
    OctNode::set_max_level_allowed(maxlev);

    ProblemGrid* root = new ProblemGrid;
    root->init();
    ProblemGrid::run(argc, argv);
    delete root;
    return 0;
}
///////////////////////////////////////////////////////////////////////////////
/// Initialize the parameters 
///
///\param para Pointer to FFD parameters
///
///\return 0 if no error occurred
///////////////////////////////////////////////////////////////////////////////
int initialize(PARA_DATA *para) {
  // Define the default value for parameter
  set_default_parameter(para);

  // Overwrite the default values using user defined values
  if(read_parameter(para)) {
    ffd_log("initialize(): Failed to read paramter file.", FFD_ERROR);
    return 1;
  }

  /*---------------------------------------------------------------------------
  | Output the help information 
  ---------------------------------------------------------------------------*/
  if(para->outp->version==DEMO) {
    printf("\n\nHow to use this demo:\n\n" );
    printf("\t Switch Windows: \n");
    printf("\t\tVelocity: key '1'\n");
    printf("\t\tContaminant: key '2'\n");
    printf("\t\tTemperature: key '3'\n");
    printf("\t Add densities with the right mouse button\n");
    printf("\t Add velocities with the left mouse button\n");
    printf("\t Increase the inlet velocity with 'F' or 'f' key\n");
    printf("\t Decrease the inlet velocity with 'S' or 's' key\n");
    printf("\t Increase the BC temperature with 'H' or 'h' key\n");
    printf("\t Decrease the BC temperature with 'C' or 'c' key\n" );
    printf("\t Clear the simulation by pressing the '0' key\n" );
    printf("\t Quit by pressing the 'q' key\n" );
  }

  return 0;
} // End of initialize( )
Ejemplo n.º 3
0
void
Function::
read(const mkf::Node&  src, Memory&  mem, int  depth)
{
  mkf::Cursor  cur(src);

    while(!cur.test_ended())
    {
      auto&  nd = cur.get();

        if(nd == "parameter")
        {
          read_parameter(nd);
        }

      else
        if(nd == "&")
        {
          reference_sign = true;
        }

      else
        if(nd == "block")
        {
          Block::read(nd,mem,depth+1);
        }


      cur.advance();
    }
}
Ejemplo n.º 4
0
    /* Prints text code of the car MODEL table for the database.
     * Arguments:
     *              fp: This is the pointer to a FILE object that identifies the
     *                  stream.
     *              fd: file descriptor to write in.
     *              VIN: buffer for the VIN.
     * Return value:
     *              0 : Everything went as desired.
     *              -1 : Something went wrong. 
     */
    int model(FILE *fp, int fd, char *VIN) {
        int n, MCC = 1598, MWeight = 1286, MHP = 105;
        char MFuel = 'D', MEngine[20] = "4CILINDERS";
        char MVIN[MAX_ANSWER];
        int VINparameter = 17;
        OBD_value * value;

        value = obd_newvalue();
        if (value->next == NULL) {
            n = read_parameter(fd, VINparameter, MVIN, value);
            sleep(1); //TODO ver tiempo
            if (n < 0) { //If something went wrong or finished reading, reset OBD and close the file
                write_atmsg(fd, "Z");
                sleep(1);
                close(fd);
                return -1;
            } else {
                fprintf(fp, "INSERT INTO MODEL (MVIN, MCC, MFuel, MEngine, MHP, MWeight) VALUES (\"%s\", %d, \"%c\", \"%s\", %d, %d);\n", value->obdv_value.str, MCC, MFuel, MEngine, MHP, MWeight);
                strncpy(VIN, value->obdv_value.str, OBDV_MAXSTR);
            }
        }
        return 0;
    }
Ejemplo n.º 5
0
Archivo: train.cpp Proyecto: fgtlss/sol
//void copy_parameter(param_temp,&param)
//{
//	param_t
//}
// Interface function of matlab
// now assume prhs[0]: label prhs[1]: features
int main(int argc, char **argv)
{
	const char *error_msg;
	// fix random seed to have same results for each run
	// (for cross validation)
	srand(1);

	char input_file_name[1024];
	char model_file_name[1024];
	char param_file_name[1024];

    
	int n_flag = 0;
	parse_command_line(argc, argv, input_file_name, model_file_name,n_flag,param_file_name);
	char char_para;
	int length_param = 0;
	double *para_entry; // 
	//n_flag = 1;
	//int para_B[20] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 12,14,16, 18, 20, 25, 30,35,40,45,50};
	int para_B[40] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 24, 25, 26, 30,32, 35, 38, 40, 42, 45, 48, 50, 55, 60, 65,70,75,80, 85, 90, 95, 100, 105, 110, 115, 120};
	//int para_B[32] = { 20, 24, 25, 26, 30,32, 35, 38, 40, 42, 45, 48, 50, 55,  60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280};

	if (n_flag==1)
	{
		read_parameter(param_file_name, para_entry, char_para, length_param);
	}

	read_problem(input_file_name);
	


	error_msg = check_parameter(&prob,&param);
//parameter *param_temp = new parameter[1];
//copy_parameter(param_temp,&param);
	if(error_msg)
	{
		fprintf(stderr,"Error: %s\n",error_msg);
		exit(1);
	}

	if(cross_validation_flag)
	{
		do_cross_validation();
	}
	else
	{
		if(n_flag==0)
		{
			model_ = FGM_train(&prob, &param);
			printf("training is done!\n");
			save_model_poly(model_file_name, model_);
			printf("model is saved!\n");
			destroy_model(model_);
		}
		else
		{
			int i;
			if (char_para=='C')
			{
				length_param = length_param;
			}else
			{
				length_param = 40;
			}
			for (i=0;i<length_param;i++)
			{
				char param_char[1000];
			    char model_file[1024];
				strcpy(model_file,model_file_name);
				if (char_para=='C')
				{
					param.C = para_entry[i];
					sprintf(param_char, "%.10lf ", para_entry[i]); 
					strcat(model_file,".c.");
					strcat(model_file,param_char);
				    model_=FGM_train(&prob, &param);
				}
				else
				{
					int B = para_B[i];
					param.B = B;
					sprintf(param_char, "%d ", param.B); 
					printf("%d\n ", param.B); 
					strcat(model_file,".B.");
					strcat(model_file,param_char);
				    model_=FGM_train(&prob, &param);
				}
				
				printf("training is done!\n");
				save_model_poly(model_file, model_);
				printf("model is saved!\n");
				destroy_model(model_);
				if(model_->feature_pair>600)
				{
					break;
				}
			}
		}

	}
	if (n_flag==1)
	{
		delete []para_entry;
	}
	
	destroy_param(&param);
	free(prob.y);
	free(prob.x);
	free(x_space);

}