Ejemplo n.º 1
0
void init()
{
	double run_time ;
	char f_name[32];
	long cflag;

	

	printf("Input run time "); 
	scanf("%lg",&run_time); //total time for the simulation

  	printf("Input grid size theta ");
    scanf("%ld",&num_of_meshpoint_theta);
    
    printf("Input grid size phi (only half of them) ");
    scanf("%ld",&num_of_meshpoint_phi);
    
    
    printf("Input iterations ");
  	scanf("%ld",&num_of_iteration);
    
    dtheta= PI/num_of_meshpoint_theta;
    dphi=PI/(num_of_meshpoint_phi);
    
    DT = run_time/num_of_iteration;

	printf("Choose integration method "); 
  	printf("\n");
  	printf("\n\t1. Euler");
  	printf("\n\t2. Runge-Kutta (2 steps)");
  	printf("\n\t3. Runge-Kutta (4 steps)");
  	printf("\n\n");
  	printf("Input flag ");
  	scanf("%ld",&method);
  
	printf("Input sigma "); 
  	scanf("%lg",&sigma);

	printf("Choose intial configuration "); 
  	printf("\n");
  	printf("\n\t1. Random");
	printf("\n\t2. Import");
	printf("\n\t3. Debug");
  	printf("\n\n");
  	printf("Input flag ");
  	scanf("%ld",&cflag);

  	switch(cflag){
  	case 1:
	    init_random();
	    break;
  	case 2:
		init_import();
		break;
	case 3:
		debug();
		break;
  	}
}
Ejemplo n.º 2
0
static void* import_binary (int argc, char **argv, void *data)
{
	Node *node = (Node *) data;
	char *filename = argc==2?argv[1]:"";
	import_state_t ist;
	int moredata=1;



	FILE *file;

	file = fopen (filename, "r");
	if (!file) {
		cli_outfunf ("binary import, unable to open \"%s\"", filename);
		return node;
	}

	{int header,version;
		fread(&header, sizeof(int), 1, file);
		fread(&version, sizeof(int), 1, file);
		if(header!=hnb_binary_header || version!=hnb_binary_version){
			cli_outfunf("binary import, header mismatch");
		}
	}

	init_import(&ist, node);
	
	while(moredata){
		int attributes;
		int level;
		moredata=fread(&level, sizeof(int), 1, file);
		if(!moredata) break;
		fread(&attributes, sizeof(int),1,file);
		if(!moredata) break;
		
		if(level || attributes){
			Node *temp_node=node_new();
			while(attributes){
				int len;
				char *att_name;
				char *att_data;
				fread(&len, sizeof(int),1,file);
				att_name=malloc(len+1);
				fread(att_name,1,len,file);
				att_name[len]='\0';
				fread(&len, sizeof(int),1,file);
				att_data=malloc(len+1);
				fread(att_data,1,len,file);
				att_data[len]='\0';
				node_set(temp_node, att_name, att_data);
				free(att_name);
				free(att_data);
				attributes--;
			}
			import_node(&ist,level,temp_node);
			temp_node=NULL;	
		}
	}

	if(node_getflag(node,F_temp))
		node=node_remove(node);
	cli_outfunf("binary import - imported \"%s\"",filename);
	
	return node;
}
Ejemplo n.º 3
0
  void Environment::init_ontology(State& S) {
    check(!top_);

    String* on = String::internalize(S, "Object");
    Class* o = new(S) Class(S, Class::Boot, 0, 0, on);

    String* cn = String::internalize(S, "Class");
    Class* c = new(S) Class(S, Class::Boot, 0, o, cn);

    String* mn = String::internalize(S, "MetaClass");
    Class* m = new(S) Class(S, Class::Boot, 0, 0, mn);

    Class* mco = new(S) Class(S, Class::Boot, m, c,
                              Class::metaclass_name(S, on));
    o->klass_ = mco;

    Class* mcc = new(S) Class(S, Class::Boot, m, mco,
                              Class::metaclass_name(S, cn));
    c->klass_ = mcc;

    Class* mcm = new(S) Class(S, Class::Boot, m, mco,
                              Class::metaclass_name(S, mn));
    m->klass_ = mcm;

    Class* mod = new(S) Class(S, o, String::internalize(S, "Module"));

    top_ = new(S) Module(S, mod, String::internalize(S, "lang"));

    bind(S, on, o);
    bind(S, cn, c);
    bind(S, mn, m);
    bind(S, String::internalize(S, "Module"), mod);

    Class::init(S, c);
    Object::init(S, o);

    Class* trait = Trait::init(S, this);

    Class* i = Integer::init(S, this);

    Class* n = new_class(S, "NilClass");

    Class* s = new_class(S, "String");

    Class* d = new_class(S, "Code");
    Class* mc = Method::init(S, this);

    Class* t = new_class(S, "TrueClass");
    t->add_method(S, "to_s", true_to_s, 0);

    Class* f = new_class(S, "FalseClass");
    f->add_method(S, "to_s", false_to_s, 0);

    Class* tuple = Tuple::init(S, this);

    Class* dict = new_class(S, "Dictionary");
    Class* list = new_class(S, "List");

    modules_ = new(S) Dictionary(S);
    args_ = new(S) List(S);

    sys_ = new(S) Dictionary(S);

    sys_->set(S, String::internalize(S, "modules"), modules_);
    sys_->set(S, String::internalize(S, "args"), args_);

    Class* exc = new_class(S, "Exception");

    Class* rte = new_class(S, "RuntimeError", exc);
    Class* arg_err = new_class(S, "ArgumentError", rte);
    new_class(S, "ImportError", rte);
    Class* nme = new_class(S, "NoMethodError", rte);

    exc->add_method(S, "message", exc_message, 0);
    exc->add_method(S, "show", exc_show, 0);

    Class** tbl = new(S) Class*[OOP::TotalTypes];

    tbl[OOP::eNil] = n;
    tbl[OOP::eClass] = c;
    tbl[OOP::eInteger] = i;
    tbl[OOP::eString] = s;
    tbl[OOP::eCode] = d;
    tbl[OOP::eUser] = 0;
    tbl[OOP::eTrue] = t;
    tbl[OOP::eFalse] = f;
    tbl[OOP::eUnwind] = new_class(S, "Unwind");
    tbl[OOP::eMethod] = mc;
    tbl[OOP::eTuple] = tuple;
    tbl[OOP::eDictionary] = dict;
    tbl[OOP::eList] = list;
    tbl[OOP::eTrait] = trait;

    Class::init_base(tbl);

    Module::init(S, *this);

    String* io_n = String::internalize(S, "io");

    Module* io = new(S) Module(S, mod, io_n);
    io->add_method(S, "puts", io_puts, 1);
    io->add_method(S, "print", io_print, 1);

    bind(S, io_n, io);

    Class* importer = init_import(S);

    String::init(S);

    Dictionary::init(S, dict);
    List::init(S, list);

    globals_ = new(S) Closure(14);
    globals_->set(0, o);
    globals_->set(1, io);
    globals_->set(2, c);
    globals_->set(3, importer);
    globals_->set(4, dict);
    globals_->set(5, i);
    globals_->set(6, sys_);
    globals_->set(7, trait);
    globals_->set(8, arg_err);
    globals_->set(9, nme);
    globals_->set(10, exc);
    globals_->set(11, list);

    Code* enum_code = 0;

    if(dev_) {
      FILE* file = fopen("kernel/enumerable.mr", "r");
      check(file);

      Compiler compiler;

      check(compiler.compile(S,
             String::internalize(S, "kernel/enumerable.mr"), file));

      enum_code = compiler.code();
      fclose(file);
    } else {
      enum_code = frozen_enumerable(S);
    }

    run_top_code(S, enum_code);
    Trait* enum_ = lookup(S, "Enumerable").as_trait();

    tuple->uses_trait(S, enum_);

    init_builtin_extensions(S);

    S.set_importer(new(S) User(S, lookup(S, "Importer").as_class()));

    run_top_code(S, frozen_dir(S));

    {
#include "kernel/moment.mrc"
      run_top_code(S, Code::load_raw(S, (unsigned char*)data, data_size));
    }

    globals_->set(12, lookup(S, "Dir"));
    globals_->set(13, lookup(S, "Moment"));
  }
Ejemplo n.º 4
0
static int insert_cal(int argc, char **argv, void *data){
	Node *pos=(void *)data;

	int year;
	int month;
	import_state_t ist;
	
	if( (argc!=3) || (atoi(argv[1])>12 )){
		cli_outfunf("usage: %s <month> <year>", argv[0]);
		return (int)data;
	}

	month=atoi(argv[1]);
	year=atoi(argv[2]);


	if(year<2000){  /* nasty,.. 2yk like fix,.. but,.. it's just here */
		year+=2000;
	}
	
	init_import(&ist, pos);
	{
		char tmpstr[40];
		sprintf(tmpstr,"%i %s", year, mname[month]);
		import_node_text(&ist, 0, tmpstr);
		{
			struct tm tdata;

			tdata.tm_year = year - 1900;
			tdata.tm_mon = month - 1;
			tdata.tm_mday = 1;
			tdata.tm_hour = 0;
			tdata.tm_min = 0;
			tdata.tm_sec = 1;
			tdata.tm_isdst = -1;

			mktime (&tdata);

			while(tdata.tm_mon==month-1){
				sprintf (tmpstr,"%s%c%02i\n", wday[tdata.tm_wday], (tdata.tm_wday==0 || tdata.tm_wday==6)?'_':' ', tdata.tm_mday);
				import_node_text(&ist, 1, tmpstr);
				
				/* I prefer not to plan on this level
				import_node_text(&ist, 2, "08:00");
				import_node_text(&ist, 2, "09:00");
				import_node_text(&ist, 2, "10:00");
				import_node_text(&ist, 2, "11:00");
				import_node_text(&ist, 2, "12:00");
				import_node_text(&ist, 2, "13:00");
				import_node_text(&ist, 2, "14:00");
				import_node_text(&ist, 2, "15:00");
				import_node_text(&ist, 2, "16:00");
				import_node_text(&ist, 2, "17:00");
				*/

				tdata.tm_mday++;
				mktime (&tdata);
			}
		}
	}	

	return (int)pos;
}