Esempio n. 1
0
int main()
{
    int N;
    cin >> N;
    vector<string> vertex_names = input_string(N);
    vector<vector<int>> adjacency_matrix = input_matrix(N);
    
    Graph g(adjacency_matrix, vertex_names);
    cout << "Created graph object g" << endl;
    
    Graph h(g);
    cout << "Copy constructor h<-g" << endl;
    
    Graph i(move(h));
    cout << "Move constructor i<-h" << endl;
    
    Graph j = i;
    cout << "Copy Assignment j<-i" << endl;
    
    Graph k = move(j);
    cout << "Move assignment k<-j" << endl << endl;

    
    cout << "BFS : Belgaum -> Chennai : ";
    disp(g.begin_bfs("Belgaum"), g.end_bfs("Chennai"));
    
    cout << "DFS : Chennai -> *No destination : ";
    disp(g.begin_dfs("Chennai"), g.end_dfs());
    
    cout << "Topo sort : Belgaum -> Chennai : ";   
    vector<string> test= g.topo_sort(g.begin_dfs("Belgaum"), g.end_dfs("Chennai"));
    disp(test.begin(), test.end());
    
    
    cout << "Compare graph : (g('Belgaum') == i('Belgaum') -> " << comp_graphs(g.begin_dfs("Belgaum"), 
                                                          g.end_dfs(),
                                                          g.begin_dfs("Belgaum"),
                                                          g.end_dfs()
                                                         ) << endl ;

    cout << "Compare graph : (g('Belgaum') == i('Bangalore') -> " << comp_graphs(g.begin_dfs("Belgaum"), 
                                                          g.end_dfs(),
                                                          g.begin_dfs("Bangalore"),
                                                          g.end_dfs()
                                                         ) << endl << endl ;
   
    cout << "Dijkstra matrix " << endl;
    cin >> N;
    vertex_names = input_string(N);
    adjacency_matrix = input_matrix(N);
    Graph obj(adjacency_matrix, vertex_names);
	obj.djikstra("Mumbai",N);
    return 0;
}
Esempio n. 2
0
/* render find dialog */
int
render_find_dialog (WINDOW * main_win, GScroll * gscroll)
{
  int y, x, valid = 1;
  int w = FIND_DLG_WIDTH;
  int h = FIND_DLG_HEIGHT;
  char *query = NULL;
  WINDOW *win;

  getmaxyx (stdscr, y, x);

  win = newwin (h, w, (y - h) / 2, (x - w) / 2);
  keypad (win, TRUE);
  wborder (win, '|', '|', '-', '-', '+', '+', '+', '+');
  draw_header (win, FIND_HEAD, " %s", 1, 1, w - 2, 1, 0);
  draw_header (win, FIND_DESC, " %s", 2, 1, w - 2, 2, 0);

  find_t.icase = 0;
  query = input_string (win, 4, 2, w - 3, "", 1, &find_t.icase);
  if (query != NULL && *query != '\0') {
    reset_scroll_offsets (gscroll);
    reset_find ();
    find_t.pattern = xstrdup (query);
    valid = 0;
  }
  if (query != NULL)
    free (query);
  touchwin (main_win);
  close_win (win);
  wrefresh (main_win);

  return valid;
}
Esempio n. 3
0
	TEST(UtilDateTime, fixDateTimeString_missing_t)
	{
		std::string input_string("20150410345612");
		std::string expected_result("20150410T345612");

		std::string s = UTIL::MISC::fixDateTimeString(input_string.c_str());

		ASSERT_STREQ(expected_result.c_str(), s.c_str());
	}
Esempio n. 4
0
	TEST(UtilDateTime, fixDateTimeString_very_short_string)
	{
		std::string input_string("201007");
		std::string expected_result("");

		std::string s = UTIL::MISC::fixDateTimeString(input_string.c_str());

		ASSERT_STREQ(expected_result.c_str(), s.c_str());
	}
Esempio n. 5
0
	TEST(UtilDateTime, fixDateTimeString_valid_string)
	{
		std::string input_string("20131025T123456");
		std::string expected_result(input_string);

		std::string s = UTIL::MISC::fixDateTimeString(input_string.c_str());

		ASSERT_STREQ(expected_result.c_str(), s.c_str());
	}
Esempio n. 6
0
File: input.c Progetto: N-Thomas/sat
/*******************************************************************************************
 * NAME :             parse_comments
 *
 * DESCRIPTION :      Progresses the file pointer past the commentes.
 *
 *
 * INPUTS :
 *      PARAMETERS :   
 *          FILE*       fp            The pointer to the file.
 *          int         file size     The size of the file in bytes.
 *
 * OUTPUTS :
 *      RETURN :
 *          char*                     The line of the next line ("problem" line).
 */
char* parse_comments(FILE* fp, int file_size)
{
  char* line = input_string(fp, file_size);

  while(line != NULL && strcmp(line, ""))
  {
    if(line[0] == 'c') 
    { /* Ignore comments */ 
      free(line);
    }
    else
    {
      return line;
    }
    // Read next line. 
    line = input_string(fp, file_size);
  }
  return line;
}
Esempio n. 7
0
static void setup_wizard(void)
{
	int max_hosts = 0;
	char *input;
	int num;

	printf(_("Welcome to weex setup wizard!\n"));
	printf(_("You can configure weex by just answering some questions with this wizard.\n"));
	printf(_("If you want to write weexrc file by hand or just you specified wrong\n"
		 "configuration file, kill the process by Ctrl-C.\n\n"));

	for (;;) {
		if (max_hosts == 0) {
			max_hosts = configure_new_host(max_hosts);
		}

		input = input_string(_("\n"
				       "1) configure new host\n"
				       "2) reconfigure existing host\n"
				       "3) display current configuration\n"
				       "4) write weexrc and exit\n\n"));
		num = atoi(input);
		free(input);

		switch (num) {
		case 1:
			max_hosts = configure_new_host(max_hosts);
			break;
		case 2:
			reconfigure_existing_host(max_hosts);
			break;
		case 3:
			print_current_configuration(max_hosts);
			break;
		case 4:
			max_hosts = cfgAllocForNewSection(config_table, "default");
			cfgStoreValue(config_table, "IgnoreLocalFile", "*~", CFG_INI, max_hosts - 1);
			cfgStoreValue(config_table, "IgnoreLocalFile", "*.tmp", CFG_INI, max_hosts - 1);
			cfgStoreValue(config_table, "IgnoreLocalFile", "*.bak", CFG_INI, max_hosts - 1);
			cfgStoreValue(config_table, "AsciiFile", "*.htm", CFG_INI, max_hosts - 1);
			cfgStoreValue(config_table, "AsciiFile", "*.html", CFG_INI, max_hosts - 1);
			cfgStoreValue(config_table, "AsciiFile", "*.txt", CFG_INI, max_hosts - 1);
			
			if (cfgDump(command_line_option.config_file, config_table, CFG_INI, max_hosts) == 0) {
				printf(_("Configuration file `%s' has been created.\n"), command_line_option.config_file);
				return;
			} else {
				fprintf(stderr, _("An error has occured while writing configuration file `%s'.\n"), command_line_option.config_file);
				exit(1);
			}
		default:
			printf(_("Enter between 1 and 4.\n\n"));
		}
	}
}
Esempio n. 8
0
File: book.c Progetto: kou029w/work
// キーボードから本のデータを入力
void input_data(Bookdata *target){
	target->title = input_string("タイトル>", target->title);
	target->author = input_string("著者>", target->author);
	target->publisher = input_string("出版元>", target->publisher);
	target->year = input_string("発行年>", target->year);
	target->pages = input_string("ページ数>", target->pages);
	target->isbn = input_string("ISBN>", target->isbn);
	target->note = input_string("備考>", target->note);
}
Esempio n. 9
0
std::string input_string(const std::vector<T>& vec)
{
    typename std::vector<T>::const_iterator it=vec.begin(), end=vec.end();
    std::string out;
    while (it!=end) {
        out += input_string(*it);
        ++it;
        if (it!=end)  out+=",";
    }
    return out;
}
Esempio n. 10
0
static int configure_new_host(int max_hosts)
{
	char *input;

	input = input_string(_("Enter host identifier. (e.g., myhost)\n"));
	max_hosts = cfgAllocForNewSection(config_table, input);
	free(input);

	configure_host(max_hosts - 1, NO_DEFAULT);

	return (max_hosts);
}
Esempio n. 11
0
int main(int argc, char const *argv[]) {
    int t;
    scanf("%d\n", &t);
    char string_array[t][STR_MAX];
    char result_array[t][STR_MAX];

    for (int i = 0; i < t; ++i) {
        input_string(string_array[i], result_array[i]);
    }

    for (int i = 0; i < t; ++i) {
        printf("%s\n", result_array[i]);
    }

    return 0;
}
Esempio n. 12
0
	TEST(UtilDateTime, dateTimeToDisplay_simple_test)
	{
		// only do this for USA locales. Constructing locale here and using it to generate
		// expected string is what happens in code being tested so not a good unit test
		std::locale my_locale("");
		if (my_locale.name().find("United States") != std::string::npos)
		{
			std::string input_string("20110708T201530");
			std::string expected_result("07/08/11");

			std::string s = UTIL::MISC::dateTimeToDisplay(input_string.c_str());

			ASSERT_STREQ(expected_result.c_str(), s.c_str());
		}
		else
		{
			std::cerr << "Warning - locale not USA - dateTimeToDisplay_simple_test not executing" << std::endl;
		}
	}
Esempio n. 13
0
static void reconfigure_existing_host(int max_hosts)
{
	int i;
	int num;
	char *input;

	for (i = 0; i < max_hosts; i++) {
		printf(_("%d) HostIdentifier: %-10s    HostName: %s\n"), i + 1, cfgSectionNumberToName(i), config.host_name[i]);
	}
	printf("\n");
	input = input_string(_("Choose host you want to reconfigure.\n"));
	num = atoi(input);
	free(input);

	if (num < 1 || num > max_hosts) {
		printf(_("No such host.\n"));
		return;
	}

	configure_host(num - 1, DEFAULT_EXIST);
}
Esempio n. 14
0
/* render config log date/format dialog */
int
verify_format (GLog * logger, GSpinner * spinner)
{
  GMenu *menu;
  WINDOW *win;

  char *cstm_log, *cstm_date;
  int c, quit = 1;
  int invalid = 1;
  int y, x, h = CONF_WIN_H, w = CONF_WIN_W;
  int w2 = w - 2;
  size_t i, n, sel;

  /* conf dialog menu options */
  const char *choices[] = {
    "Common Log Format (CLF)",
    "Common Log Format (CLF) with Virtual Host",
    "NCSA Combined Log Format",
    "NCSA Combined Log Format with Virtual Host",
    "W3C",
    "CloudFront (Download Distribution)"
  };
  n = ARRAY_SIZE (choices);
  getmaxyx (stdscr, y, x);

  win = newwin (h, w, (y - h) / 2, (x - w) / 2);
  keypad (win, TRUE);
  wborder (win, '|', '|', '-', '-', '+', '+', '+', '+');

  /* create a new instance of GMenu and make it selectable */
  menu = new_gmenu (win, CONF_MENU_H, CONF_MENU_W, CONF_MENU_Y, CONF_MENU_X);
  menu->size = n;
  menu->selectable = 1;

  /* add items to GMenu */
  menu->items = (GItem *) xcalloc (n, sizeof (GItem));
  for (i = 0; i < n; ++i) {
    menu->items[i].name = alloc_string (choices[i]);
    sel = get_selected_format_idx ();
    menu->items[i].checked = sel == i ? 1 : 0;
  }
  post_gmenu (menu);

  draw_header (win, "Log Format Configuration", " %s", 1, 1, w2, 1, 0);
  mvwprintw (win, 2, 2, "[SPACE] to toggle - [ENTER] to proceed");

  /* set log format from goaccessrc if available */
  draw_header (win, "Log Format - [c] to add/edit format", " %s", 11, 1, w2, 1,
               0);
  if (conf.log_format) {
    log_format = escape_str (conf.log_format);
    mvwprintw (win, 12, 2, "%.*s", CONF_MENU_W, log_format);
    if (conf.log_format)
      free (conf.log_format);
  }

  /* set date format from goaccessrc if available */
  draw_header (win, "Date Format - [d] to add/edit format", " %s", 14, 1, w2, 1,
               0);
  if (conf.date_format) {
    date_format = escape_str (conf.date_format);
    mvwprintw (win, 15, 2, "%.*s", CONF_MENU_W, date_format);
    if (conf.date_format)
      free (conf.date_format);
  }

  wrefresh (win);
  while (quit) {
    c = wgetch (stdscr);
    switch (c) {
     case KEY_DOWN:
       gmenu_driver (menu, REQ_DOWN);
       draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0, 0);
       break;
     case KEY_UP:
       gmenu_driver (menu, REQ_UP);
       draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0, 0);
       break;
     case 32:  /* space */
       gmenu_driver (menu, REQ_SEL);

       if (date_format)
         free (date_format);
       if (log_format)
         free (log_format);

       for (i = 0; i < n; ++i) {
         if (menu->items[i].checked != 1)
           continue;

         date_format = get_selected_date_str (i);
         log_format = get_selected_format_str (i);
         draw_header (win, date_format, " %s", 15, 1, CONF_MENU_W, 0, 0);
         draw_header (win, log_format, " %s", 12, 1, CONF_MENU_W, 0, 0);
         break;
       }
       break;
     case 99:  /* c */
       /* clear top status bar */
       draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0, 0);
       wmove (win, 12, 2);

       /* get input string */
       cstm_log = input_string (win, 12, 2, 70, log_format, 0, 0);
       if (cstm_log != NULL && *cstm_log != '\0') {
         if (log_format)
           free (log_format);

         log_format = alloc_string (cstm_log);
         free (cstm_log);
       }
       /* did not set an input string */
       else {
         if (cstm_log)
           free (cstm_log);
         if (log_format) {
           free (log_format);
           log_format = NULL;
         }
       }
       break;
     case 100: /* d */
       /* clear top status bar */
       draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0, 0);
       wmove (win, 15, 0);

       /* get input string */
       cstm_date = input_string (win, 15, 2, 14, date_format, 0, 0);
       if (cstm_date != NULL && *cstm_date != '\0') {
         if (date_format)
           free (date_format);

         date_format = alloc_string (cstm_date);
         free (cstm_date);
       }
       /* did not set an input string */
       else {
         if (cstm_date)
           free (cstm_date);
         if (date_format) {
           free (date_format);
           date_format = NULL;
         }
       }
       break;
     case 274: /* F10 */
     case 0x0a:
     case 0x0d:
     case KEY_ENTER:
       /* display status bar error messages */
       if (date_format == NULL)
         draw_header (win, "Select a date format.", "%s", 3, 2, CONF_MENU_W,
                      WHITE_RED, 0);
       if (log_format == NULL)
         draw_header (win, "Select a log format.", "%s", 3, 2, CONF_MENU_W,
                      WHITE_RED, 0);

       if (date_format && log_format) {
         conf.date_format = unescape_str (date_format);
         conf.log_format = unescape_str (log_format);

         /* test log against selected settings */
         if (test_format (logger)) {
           invalid = 1;
           draw_header (win, "No valid hits.", "%s", 3, 2, CONF_MENU_W,
                        WHITE_RED, 0);

           free (conf.log_format);
           free (conf.date_format);
         }
         /* valid data, reset logger & start parsing */
         else {
           reset_struct (logger);
           /* start spinner thread */
           spinner->win = win;
           spinner->y = 3;
           spinner->x = 2;
           spinner->spin_x = CONF_MENU_W;
           spinner->w = CONF_MENU_W;
           spinner->color = BLACK_CYAN;
           ui_spinner_create (spinner);

           invalid = 0;
           quit = 0;
         }
       }
       break;
     case KEY_RESIZE:
     case 'q':
       quit = 0;
       break;
    }
    pthread_mutex_lock (&spinner->mutex);
    wrefresh (win);
    pthread_mutex_unlock (&spinner->mutex);
  }
  /* clean stuff up */
  for (i = 0; i < n; ++i)
    free (menu->items[i].name);
  free (menu->items);
  free (menu);

  return invalid ? 1 : 0;
}
int read_bc_from_file(
		      struct All_variables *E,
		      standard_precision * field,
		      unsigned int *flags,
		      char *name,
		      char *abbr,
		      unsigned int ON,
		      unsigned int OFF
		      )
{
    int input_string();

    standard_precision cross2d();

    char discard[5001];
    char * token;
 
    char *filename;
    char *input_token;
    FILE *fp;
    int fnodesx,fnodesz,fnodesy;
    int i,j,k,node2d,node3d,column,found;
    int interpolate=0;
    double value;

    standard_precision *T;
    standard_precision yloc;
    char instring[500];

    filename=(char *)Malloc0(500*sizeof(char));
    input_token=(char *)Malloc0(1000*sizeof(char));

    /* Define field name, read parameter file to determine file name and column number */

    sprintf(input_token,"%s_bc_file",name);
    if(!input_string(input_token,filename,"initialize")) {
	fprintf(E->fp,"No %s bc information found in input file\n",name);fflush(E->fp);
	return(0);   /* if not found, take no further action, return zero */
    }

    fprintf(E->fp,"%s bc information is in file %s\n",name,filename);fflush(E->fp);
 
    /* Try opening the file, fatal if this fails too */

    if((fp=fopen(filename,"r")) == NULL) {
	fprintf(E->fp,"Unable to open the required file `%s'\n",filename);fflush(E->fp);
	if(E->control.verbose)
	   	fprintf(stderr,"Unable to open the required file `%s'\n",filename);
	return(0);
    }

     /* Read header, get nodes xzy */

    fgets(discard,4999,fp);
    fgets(discard,4999,fp); 
    i=sscanf(discard,"# NODESX=%d NODESZ=%d NODESY=%d",&fnodesx,&fnodesz,&fnodesy);
    if(i<3) {
	fprintf(E->fp,"File %s is not in the correct format\n",filename);fflush(E->fp);
	return(0);
    }

    fgets(discard,4999,fp); /* largely irrelevant line */
    fgets(discard,4999,fp);
    
    /* This last line is the column headers, we need to search for the occurence of abbr to
       find out the column to be read in. */
    if(!strtok(discard,"|")) { 
	fprintf(E->fp,"Unable to decipher the columns in the input file");fflush(E->fp);
	return(0);
    }

    found=0;
    column=1;

    while(found==0 && (token=(char *)strtok(NULL,"|"))) {
	if(strstr(token,abbr)!=0) found=1;
	column++; 
    }

    if(found) {
	fprintf(E->fp,"\t%s (%s) found in column %d\n",name,abbr,column);fflush(E->fp);
    }    
    else {
	fprintf(E->fp,"\t%s (%s) not found in file: %s\n",name,abbr,filename);fflush(E->fp);
	return(0);
    }

    /* A fatal condition - file size is all wrong */
    if(fnodesx != E->mesh.nox || fnodesz != E->mesh.noz || fnodesy != E->mesh.noy ) {
	fprintf(E->fp,"Input data for file `%s' is not %d x %d x %d\n",
		filename,E->mesh.nox,E->mesh.noz,E->mesh.noy);
	fflush(E->fp);
	exit(1);
    }
  
   /* Format for reading the input file  */

    sprintf(input_token," %%d ");
    for(i=2;i<column;i++)
	strcat(input_token," %*s");
    strcat(input_token," %s");

    for(i=1;i<=fnodesx*fnodesz*fnodesy;i++) {
      if(fgets(discard,4999,fp)==NULL) /* EOF encountered */
	return(2);
      sscanf(discard,input_token,&j,instring); 

      if(j<1 || j > E->mesh.nno)
	fprintf(stderr,"Illegal node value in %s bc file line %d: %d\n",name,i+4,j);
	
      if(strcmp(instring,"U")!=0)  { /* This field is not unconstrained (U) at this node */
	sscanf(instring,"%lf",&value);
	/*fprintf(stderr,"Found %s bc at node %d value %g - %s,%s\n",name,j,value,instring,discard); */
	field[j] = (standard_precision) value;
	flags[j] = flags[j] | ON;
	flags[j] = flags[j] & (~OFF);
      }
    }
    fclose(fp); 
    free((void *)filename);
    free((void *)input_token);
    return(1);
}
Esempio n. 16
0
/* Render the config log date/format dialog.
 *
 * On error, or if the selected format is invalid, 1 is returned.
 * On success, 0 is returned. */
int
render_confdlg (GLog * glog, GSpinner * spinner)
{
  GMenu *menu;
  WINDOW *win;

  const char *log_err = NULL;
  char *date_format = NULL, *log_format = NULL, *time_format = NULL;
  char *cstm_log, *cstm_date, *cstm_time;
  int c, quit = 1, invalid = 1, y, x, h = CONF_WIN_H, w = CONF_WIN_W;
  int w2 = w - 2;
  size_t i, n, sel;

  /* conf dialog menu options */
  const char *choices[] = {
    "NCSA Combined Log Format",
    "NCSA Combined Log Format with Virtual Host",
    "Common Log Format (CLF)",
    "Common Log Format (CLF) with Virtual Host",
    "W3C",
    "Squid Native Format",
    "CloudFront (Download Distribution)",
    "Google Cloud Storage",
    "AWS Elastic Load Balancing (HTTP/S)",
    "AWS Simple Storage Service (S3)",
  };
  n = ARRAY_SIZE (choices);
  getmaxyx (stdscr, y, x);

  win = newwin (h, w, (y - h) / 2, (x - w) / 2);
  keypad (win, TRUE);
  wborder (win, '|', '|', '-', '-', '+', '+', '+', '+');

  /* create a new instance of GMenu and make it selectable */
  menu = new_gmenu (win, CONF_MENU_H, CONF_MENU_W, CONF_MENU_Y, CONF_MENU_X);
  menu->size = n;
  menu->selectable = 1;

  /* add items to GMenu */
  menu->items = (GItem *) xcalloc (n, sizeof (GItem));
  for (i = 0; i < n; ++i) {
    menu->items[i].name = alloc_string (choices[i]);
    sel = get_selected_format_idx ();
    menu->items[i].checked = sel == i ? 1 : 0;
  }
  post_gmenu (menu);
  draw_formats (win, w2);

  wrefresh (win);
  while (quit) {
    c = wgetch (stdscr);
    switch (c) {
    case KEY_DOWN:
      gmenu_driver (menu, REQ_DOWN);
      clear_confdlg_status_bar (win, 3, 2, CONF_MENU_W);
      break;
    case KEY_UP:
      gmenu_driver (menu, REQ_UP);
      clear_confdlg_status_bar (win, 3, 2, CONF_MENU_W);
      break;
    case 32:   /* space */
      gmenu_driver (menu, REQ_SEL);
      clear_confdlg_status_bar (win, 12, 1, CONF_MENU_W);
      clear_confdlg_status_bar (win, 15, 1, CONF_MENU_W);
      clear_confdlg_status_bar (win, 18, 1, CONF_MENU_W);

      if (time_format)
        free (time_format);
      if (date_format)
        free (date_format);
      if (log_format)
        free (log_format);

      for (i = 0; i < n; ++i) {
        if (menu->items[i].checked != 1)
          continue;

        date_format = get_selected_date_str (i);
        log_format = get_selected_format_str (i);
        time_format = get_selected_time_str (i);

        mvwprintw (win, 12, 1, " %s", log_format);
        mvwprintw (win, 15, 1, " %s", date_format);
        mvwprintw (win, 18, 1, " %s", time_format);
        break;
      }
      break;
    case 99:   /* c */
      /* clear top status bar */
      clear_confdlg_status_bar (win, 3, 2, CONF_MENU_W);
      wmove (win, 12, 2);

      /* get input string */
      if (!log_format)
        log_format = get_input_log_format ();

      cstm_log = input_string (win, 12, 2, 70, log_format, 0, 0);
      if (cstm_log != NULL && *cstm_log != '\0') {
        if (log_format)
          free (log_format);

        log_format = alloc_string (cstm_log);
        free (cstm_log);
      }
      /* did not set an input string */
      else {
        if (cstm_log)
          free (cstm_log);
        if (log_format) {
          free (log_format);
          log_format = NULL;
        }
      }
      break;
    case 100:  /* d */
      /* clear top status bar */
      clear_confdlg_status_bar (win, 3, 2, CONF_MENU_W);
      wmove (win, 15, 0);

      /* get input string */
      if (!date_format)
        date_format = get_input_date_format ();

      cstm_date = input_string (win, 15, 2, 14, date_format, 0, 0);
      if (cstm_date != NULL && *cstm_date != '\0') {
        if (date_format)
          free (date_format);

        date_format = alloc_string (cstm_date);
        free (cstm_date);
      }
      /* did not set an input string */
      else {
        if (cstm_date)
          free (cstm_date);
        if (date_format) {
          free (date_format);
          date_format = NULL;
        }
      }
      break;
    case 116:  /* t */
      /* clear top status bar */
      clear_confdlg_status_bar (win, 3, 2, CONF_MENU_W);
      wmove (win, 15, 0);

      /* get input string */
      if (!time_format)
        time_format = get_input_time_format ();

      cstm_time = input_string (win, 18, 2, 14, time_format, 0, 0);
      if (cstm_time != NULL && *cstm_time != '\0') {
        if (time_format)
          free (time_format);

        time_format = alloc_string (cstm_time);
        free (cstm_time);
      }
      /* did not set an input string */
      else {
        if (cstm_time)
          free (cstm_time);
        if (time_format) {
          free (time_format);
          time_format = NULL;
        }
      }
      break;
    case 274:  /* F10 */
    case 0x0a:
    case 0x0d:
    case KEY_ENTER:
      if ((log_err = set_formats (date_format, log_format, time_format)))
        draw_header (win, log_err, " %s", 3, 2, CONF_MENU_W, color_error);

      if (!log_err) {
        char **errors = NULL;
        int nerrors = 0;

        /* test log against selected settings */
        if ((errors = test_format (glog, &nerrors))) {
          invalid = 1;
          load_confdlg_error (win, errors, nerrors);
        }
        /* valid data, reset glog & start parsing */
        else {
          reset_struct (glog);
          /* start spinner thread */
          spinner->win = win;
          spinner->y = 3;
          spinner->x = 2;
          spinner->spin_x = CONF_MENU_W;
          spinner->w = CONF_MENU_W;
          spinner->color = color_progress;
          ui_spinner_create (spinner);

          invalid = 0;
          quit = 0;
        }
      }
      break;
    case KEY_RESIZE:
    case 'q':
      quit = 0;
      break;
    }

    pthread_mutex_lock (&spinner->mutex);
    wrefresh (win);
    pthread_mutex_unlock (&spinner->mutex);
  }

  free (time_format);
  free (date_format);
  free (log_format);

  /* clean stuff up */
  for (i = 0; i < n; ++i)
    free (menu->items[i].name);
  free (menu->items);
  free (menu);

  return invalid ? 1 : 0;
}
Esempio n. 17
0
void tic_input(struct All_variables *E)
{

  int m = E->parallel.me;
  int noz = E->lmesh.noz;
  int n;
#ifdef USE_GGRD
  int tmp;
#endif

  input_int("tic_method", &(E->convection.tic_method), "0,0,2", m);

#ifdef USE_GGRD			/* for backward capability */
  input_int("ggrd_tinit", &tmp, "0", m);
  if(tmp){
    E->convection.tic_method = 4; /*  */
    E->control.ggrd.use_temp = 1;
  }
#endif  
  /* When tic_method is 0 (default), the temperature is a linear profile +
     perturbation at some layers.

     When tic_method is -1, the temperature is read in from the
     [datafile_old].velo.[rank].[solution_cycles_init] files.

     When tic_method is 1, the temperature is isothermal (== bottom b.c.) +
     uniformly cold plate (thickness specified by 'half_space_age').

     When tic_method is 2, (tic_method==1) + a hot blob. A user can specify
     the location and radius of the blob, and also the amplitude of temperature
     change in the blob relative to the ambient mantle temperautre
     (E->control.mantle_temp).
        - blob_center: A comma-separated list of three float numbers.
        - blob_radius: A dmensionless length, typically a fraction
                       of the Earth's radius.
        - blob_dT    : Dimensionless temperature.

     When tic_method is 3, the temperature is a linear profile + perturbation
     for whole mantle.

     tic_method is 4: read in initial temperature distribution from a set of netcdf grd
                      files. this required the GGRD extension to be compiled in

  */

    /* This part put a temperature anomaly at depth where the global
       node number is equal to load_depth. The horizontal pattern of
       the anomaly is given by spherical harmonic ll & mm. */

    input_int("num_perturbations", &n, "0,0,PERTURB_MAX_LAYERS", m);

    if (n > 0) {
      E->convection.number_of_perturbations = n;

      if (! input_float_vector("perturbmag", n, E->convection.perturb_mag, m) ) {
	fprintf(stderr,"Missing input parameter: 'perturbmag'\n");
	parallel_process_termination();
      }
      if (! input_int_vector("perturbm", n, E->convection.perturb_mm, m) ) {
	fprintf(stderr,"Missing input parameter: 'perturbm'\n");
	parallel_process_termination();
      }
      if (! input_int_vector("perturbl", n, E->convection.perturb_ll, m) ) {
	fprintf(stderr,"Missing input parameter: 'perturbl'\n");
	parallel_process_termination();
      }
      if (! input_int_vector("perturblayer", n, E->convection.load_depth, m) ) {
	fprintf(stderr,"Missing input parameter: 'perturblayer'\n");
	parallel_process_termination();
      }
    }
    else {
      E->convection.number_of_perturbations = 1;
      E->convection.perturb_mag[0] = 1;
      E->convection.perturb_mm[0] = 2;
      E->convection.perturb_ll[0] = 2;
      E->convection.load_depth[0] = (noz+1)/2;
    }

    input_float("half_space_age", &(E->convection.half_space_age), "40.0,1e-3,nomax", m);
    input_float("mantle_temp",&(E->control.mantle_temp),"1.0",m);

    
    switch(E->convection.tic_method){
    case 2:			/* blob */
      if( ! input_float_vector("blob_center", 3, E->convection.blob_center, m)) {
	assert( E->sphere.caps == 12 || E->sphere.caps == 1 );
	if(E->sphere.caps == 12) { /* Full version: just quit here */
	  fprintf(stderr,"Missing input parameter: 'blob_center'.\n");
	  parallel_process_termination();
	}
	else if(E->sphere.caps == 1) { /* Regional version: put the blob at the center */
	  fprintf(stderr,"Missing input parameter: 'blob_center'. The blob will be placed at the center of the domain.\n");
	  E->convection.blob_center[0] = 0.5*(E->control.theta_min+E->control.theta_max);
	  E->convection.blob_center[1] = 0.5*(E->control.fi_min+E->control.fi_max);
	  E->convection.blob_center[2] = 0.5*(E->sphere.ri+E->sphere.ro);
	}
      }
      input_float("blob_radius", &(E->convection.blob_radius), "0.063,0.0,1.0", m);
      input_float("blob_dT", &(E->convection.blob_dT), "0.18,nomin,nomax", m);
      input_boolean("blob_bc_persist",&(E->convection.blob_bc_persist),"off",m);
      break;
    case 4:
      /*
	case 4: initial temp from grd files
      */
#ifdef USE_GGRD
      /* 
	 read in some more parameters 
	 
      */
      /* scale the anomalies with PREM densities */
      input_boolean("ggrd_tinit_scale_with_prem",
		    &(E->control.ggrd.temp.scale_with_prem),"off",E->parallel.me);
      /* limit T to 0...1 */
      input_boolean("ggrd_tinit_limit_trange",
		    &(E->control.ggrd.temp.limit_trange),"on",E->parallel.me);
      /* scaling factor for the grids */
      input_double("ggrd_tinit_scale",
		   &(E->control.ggrd.temp.scale),"1.0",E->parallel.me); /* scale */
      /* temperature offset factor */
      input_double("ggrd_tinit_offset",
		   &(E->control.ggrd.temp.offset),"0.0",E->parallel.me); /* offset */
      /* 
	 do we want a different scaling for the lower mantle?
      */
      input_float("ggrd_lower_depth_km",&(E->control.ggrd_lower_depth_km),"7000",
		  E->parallel.me); /* depth, in km, below which
				      different scaling applies */
      input_float("ggrd_lower_scale",&(E->control.ggrd_lower_scale),"1.0",E->parallel.me);
      input_float("ggrd_lower_offset",&(E->control.ggrd_lower_offset),"1.0",E->parallel.me);

      /* grid name, without the .i.grd suffix */
      input_string("ggrd_tinit_gfile",
		   E->control.ggrd.temp.gfile,"",E->parallel.me); /* grids */
      input_string("ggrd_tinit_dfile",
		   E->control.ggrd.temp.dfile,"",E->parallel.me); /* depth.dat layers of grids*/
      /* override temperature boundary condition? */
      input_boolean("ggrd_tinit_override_tbc",
		    &(E->control.ggrd.temp.override_tbc),"off",E->parallel.me);
      input_string("ggrd_tinit_prem_file",
		   E->control.ggrd.temp.prem.model_filename,"hc/prem/prem.dat", 
		   E->parallel.me); /* PREM model filename */

      /* non-linear scaling, downweighing negative anomalies? */
      input_boolean("ggrd_tinit_nl_scale",&(E->control.ggrd_tinit_nl_scale),"off",E->parallel.me);
    
#else
      fprintf(stderr,"tic_method 4 only works for USE_GGRD compiled code\n");
      parallel_process_termination();
#endif
      break;
    } /* no default needed */
    return;
}
Esempio n. 18
0
int user_input_file(char **input_filename)
{
  /****************************************************************************/
  /* Local Variables.                                                         */
  /****************************************************************************/
  char *user_input;
  int ret_code = FILE_INPUT_OK;
  int input_ret_code;
  FILE *temp_file_ptr;
  
  /****************************************************************************/
  /* As the user for input and flush the output buffer.                       */
  /****************************************************************************/
  printf("Please enter a filename:\n");
  fflush(stdout);
  
  /****************************************************************************/
  /* Call the input_string function to retrieve a user inputted string.       */
  /****************************************************************************/
  input_ret_code = input_string(MAX_FILENAME_LEN, &user_input);
  if (input_ret_code != STRING_INPUT_OK)
  {
    ret_code = FILE_INPUT_INVALID;
    goto EXIT_LABEL;
  }
  
  /****************************************************************************/
  /* Attempt to open the file. If this does not succeed then we do not return */
  /* the filename.                                                            */
  /****************************************************************************/
  temp_file_ptr = fopen(user_input, "r");
  if (temp_file_ptr == NULL)
  {
    printf("File could not be opened.\n");
    free(user_input);
    ret_code = FILE_INPUT_INVALID;
    goto EXIT_LABEL;
  }
  
  /****************************************************************************/
  /* If the file open succeeded then close the file.                          */
  /****************************************************************************/
  fclose(temp_file_ptr);
  
  /****************************************************************************/
  /* Set the output variable to the filename.                                 */
  /****************************************************************************/
  (*input_filename) = (char *) malloc(strlen(user_input) + 1);
  if ((*input_filename) == NULL)
  {
    printf("Failure allocating memory for output filename.\n");
    free(user_input);
    ret_code = FILE_INPUT_MEM_ERR;
    goto EXIT_LABEL;
  }
  strncpy((*input_filename), user_input, strlen(user_input) + 1);
  free(user_input);
  
EXIT_LABEL:
  
  return(ret_code);
}
Esempio n. 19
0
int user_input_word(int grp_max_generators,
                    int grp_max_word_len,
                    char **word)
{
  /****************************************************************************/
  /* Local variables.                                                         */
  /****************************************************************************/
  char subword[grp_max_word_len];
  int subword_index = 0;
  char *popped_word;
  int ii;
  int jj;
  int input_ret_code;
  int exponent;
  char exponent_string[grp_max_word_len];
  int exp_string_index = 0;
  char *user_input;
  int ret_code = WORD_INPUT_OK;
  bool parsing_exponent = false;
  bool hat_found = false;
  bool valid_exp = false;
  STRING_STACK_ELEMENT *top = NULL;
  int nest_depth = 0;
  
  /****************************************************************************/
  /* Check input parameters.                                                  */
  /****************************************************************************/
  assert(grp_max_word_len < MAX_WORD_LEN);
  assert(grp_max_generators < MAX_GENERATORS);
  
  /****************************************************************************/
  /* Ask the user for input and flush the output buffer to make sure the user */
  /* sees the request.                                                        */
  /****************************************************************************/
  printf("Enter a word for the group loaded.\n");
  fflush(stdout);
  
  /****************************************************************************/
  /* Call the input_string method to retrieve a string containing the word.   */
  /****************************************************************************/
  input_ret_code = input_string(MAX_WORD_LEN, &user_input);
  if (input_ret_code != STRING_INPUT_OK)
  {
    ret_code = WORD_INPUT_INVALID;
    goto EXIT_LABEL;
  }
  
  /****************************************************************************/
  /* If the input string is longer than the maximum word size then return.    */
  /****************************************************************************/
  if (strlen(user_input) > grp_max_word_len)
  {
    printf("The word inputted is too long.\n");
    free(user_input);
    ret_code = WORD_INPUT_TOO_LONG;
    goto EXIT_LABEL;
  }
  
  /****************************************************************************/
  /* Set the first character in the subword to be NULL to start. This means   */
  /* that even if there are no characters in the user input subword contains  */
  /* a well defined string.                                                   */
  /****************************************************************************/
  subword[0] = '\0';
  
  /****************************************************************************/
  /* Go through the word one character at a time parsing it.                  */
  /****************************************************************************/
  for (ii = 0; ii < strlen(user_input); ii++)
  {
    if (parsing_exponent)
    {
      if (((int) user_input[ii]) == (int) '^')
      {
        /**********************************************************************/
        /* The first time that ^ is found after a bracket we can start        */
        /* looking for digits.                                                */
        /**********************************************************************/
        hat_found = true;
      }
      else if ((((int) user_input[ii]) >= (int) '0') &&
               (((int) user_input[ii]) <= (int) '9'))
      {
        /**********************************************************************/
        /* Exponents must be of the form ^x where x is a digit. If the ^ is   */
        /* not found then it is not a valid exponent and the word fails.      */
        /**********************************************************************/
        if (!hat_found)
        {
          printf("The word was invalid as a close brack was not followed by ^.\n");
          ret_code = WORD_INPUT_INVALID;
          empty_string_stack(top);
          free(user_input);
          goto EXIT_LABEL;
        }
        
        /**********************************************************************/
        /* As soon as a digit is found after a ^ we have a valid exponent.    */
        /**********************************************************************/
        valid_exp = true;
        
        /**********************************************************************/
        /* We generate a substring which contains the exponent.               */
        /**********************************************************************/
        exponent_string[exp_string_index] = user_input[ii];
        exp_string_index++;
      }
      else if ((((int) user_input[ii]) >= (int)'a' && 
                ((int) user_input[ii]) <= (int)'a' + grp_max_generators - 1) ||
               (((int) user_input[ii]) == (int) '(') ||
               (((int) user_input[ii]) == (int) ')'))
      {
        /**********************************************************************/
        /* It is only valid that a non-exponent valid character was found if  */
        /* the exponent found so far is valid. If not then the word fails.    */
        /**********************************************************************/
        if (!valid_exp)
        {
          printf("A valid exponent was not found because there were no digits after a ^ character.\n");
          ret_code = WORD_INPUT_INVALID;
          empty_string_stack(top);
          free(user_input);
          goto EXIT_LABEL;
        }
        
        /**********************************************************************/
        /* At this point we know we have a valid exponent so we turn it into  */
        /* a number.                                                          */
        /**********************************************************************/
        exponent_string[exp_string_index] = '\0';
        exponent = atoi(exponent_string);
        popped_word = string_stack_pop(&top);
        
        /**********************************************************************/
        /* Add exponent many copies of the current subword to the word popped */
        /* off the stack.                                                     */
        /* The result is the new subword.                                     */
        /**********************************************************************/
        for (jj = 0; jj < exponent; jj++)
        {
          strncat(popped_word, subword, strlen(subword));
        }
        strncpy(subword, popped_word, strlen(popped_word));
        subword[strlen(popped_word)] = '\0';
        free(popped_word);
                
        /**********************************************************************/
        /* Return to parsing the word normally.                               */
        /**********************************************************************/
        parsing_exponent = false;
        hat_found = false;
        valid_exp = false;
        exp_string_index = 0;
        subword_index = strlen(subword);
      }
      else
      {
        printf("An invalid character was found (%c) whilst parsing exponent.\n",
               user_input[ii]);
      }
    }
    
    if (!parsing_exponent)
    {
      if (((int) user_input[ii]) >= (int)'a' && 
          ((int) user_input[ii]) <= (int)'a' + grp_max_generators - 1)
      {
        subword[subword_index] = user_input[ii];
        subword_index++;
        
        /**********************************************************************/
        /* The next character in the current subword should always be set to  */
        /* a null character in case there are no more brackets.               */
        /**********************************************************************/
        subword[subword_index] = '\0';
      }
      else if (((int) user_input[ii]) == (int) '(')
      {
        /**********************************************************************/
        /* When we hit an open bracket we put the current string onto the     */
        /* stack and start again with an empty string.                        */
        /**********************************************************************/
        string_stack_push(subword, &top);
        subword_index = 0;
        
        /**********************************************************************/
        /* To keep a track of the number of brackets opened we increment a    */
        /* depth counter.                                                     */
        /**********************************************************************/
        nest_depth++;
      }
      else if (((int) user_input[ii]) == (int) ')')
      {
        /**********************************************************************/
        /* If the nest depth counter is not greater than 0 then there are no  */
        /* brackets to be closed and the word is not valid.                   */
        /**********************************************************************/
        if (nest_depth <= 0)
        {
          printf("A bracket was closed without being opened.\n");
          ret_code = WORD_INPUT_INVALID;
          empty_string_stack(top);
          free(user_input);
          goto EXIT_LABEL;
        }
        
        /**********************************************************************/
        /* When a close bracket is hit we insist that the next few characters */
        /* are in a particular form. To force this we set a boolean which     */
        /* tells the program that it is parsing an exponent until it stops.   */
        /**********************************************************************/
        parsing_exponent = true;
        subword_index = 0;
        nest_depth--;
      }
      else
      {
        printf("There is an invalid character (%c) in the word.\n", 
               user_input[ii]);
        ret_code = WORD_INPUT_INVALID;
        empty_string_stack(top);
        free(user_input);
        goto EXIT_LABEL;
      }
    }
  }
  
  /****************************************************************************/
  /* After the end of the word has been found the nest depth should be zero   */
  /* indicating that all brackets have been closed.                           */
  /****************************************************************************/
  if (nest_depth != 0)
  {
    printf("More brackets were opened than were closed in the word.\n");
    ret_code = WORD_INPUT_INVALID;
    empty_string_stack(top);
    free(user_input);
    goto EXIT_LABEL;
  }
  
  /****************************************************************************/
  /* If the string ends whilst still parsing the exponent but without having  */
  /* finished then the exponent is not valid and therefore the word isn't.    */
  /* e.g. w = abd(ca)^ is not a valid word and will hit this branch.          */
  /****************************************************************************/
  if (parsing_exponent && !valid_exp)
  {
    printf("The word ended without a complete exponent.\n");
    ret_code = WORD_INPUT_INVALID;
    empty_string_stack(top);
    free(user_input);
    goto EXIT_LABEL;
  }
  
  /****************************************************************************/
  /* If the last character in the user input string was an exponent then we   */
  /* deal with it by popping the last string off the stack and adding the     */
  /* current subword as usual.                                                */
  /****************************************************************************/
  if (valid_exp)
  {
    exponent_string[exp_string_index] = '\0';
    exponent = atoi(exponent_string);
    popped_word = string_stack_pop(&top);
    
    /**************************************************************************/
    /* Add exponent many copies of the current subword to the word popped off */
    /* the stack.                                                             */
    /* The result is the new subword.                                         */
    /**************************************************************************/
    for (jj = 0; jj < exponent; jj++)
    {
      strncat(popped_word, subword, strlen(subword));
    }
    strncpy(subword, popped_word, strlen(popped_word) + 1);
    free(popped_word);
  }
  
  /****************************************************************************/
  /* Allocate the required amount of memory for the returned word. Then put   */
  /* the parsed word in to the new memory and return it.                      */
  /****************************************************************************/
  (*word) = (char *) malloc(sizeof(char) * strlen(subword) + 1);
  if (word == NULL)
  {
    printf("Memory allocation error creating word.");
    ret_code = WORD_INPUT_MEM_FAIL;
    goto EXIT_LABEL;
  }
  strncpy(*word, subword, strlen(subword) + 1);
  
  free(user_input);

EXIT_LABEL:
  
  return(ret_code);
}
Esempio n. 20
0
void Runtest(char *mode, int argc, char *argv[]) 
{
  FILE *fp,*fp0,*fp1,*fp2,*fp3;
  int Num_DatFiles,i,j,k,fp_OK;
  int Num_Atoms;
  int NGrid1_1,NGrid1_2,NGrid1_3;
  int NGrid2_1,NGrid2_2,NGrid2_3;
  double Utot1,Utot2,dU,dF;
  double Spread1,Spread2;
  double Omega1,Omega2;
  double gx,gy,gz,fx,fy,fz;
  double sum1,sum2;
  double time1,TotalTime;
  char fname[YOUSO10];
  char fname0[YOUSO10];
  char fname1[YOUSO10];
  char fname2[YOUSO10];
  char fname_dat[YOUSO10];
  char fname_dat2[YOUSO10];
  char fname_out1[YOUSO10];
  char fname_out2[YOUSO10];
  char ftmp[YOUSO10];
  fname_type *fndat;
  char operate[800];
  int numprocs,myid;

  char *dir;
  char *input_dir;
  char *output_file;
  DIR *dp;
  struct dirent *entry;

  MPI_Request request;
  MPI_Status  status;

  /* set up MPI */

  MPI_Comm_size(MPI_COMM_WORLD1, &numprocs);
  MPI_Comm_rank(MPI_COMM_WORLD1, &myid);

  if (strcasecmp(mode,"S")==0){  
    input_dir = "input_example";
    output_file = "runtest.result";
  }
  else if (strcasecmp(mode,"L")==0){  
    input_dir = "large_example";
    output_file = "runtestL.result";
  }
  else if (strcasecmp(mode,"L2")==0){  
    input_dir = "large2_example";
    output_file = "runtestL2.result";
  }
  else if (strcasecmp(mode,"G")==0){  
    input_dir = "geoopt_example";
    output_file = "runtestG.result";
  }
  else if (strcasecmp(mode,"WF")==0){  
    input_dir = "wf_example";
    output_file = "runtestWF.result";
  }
  else if (strcasecmp(mode,"NEGF")==0){  
    input_dir = "negf_example";
    output_file = "runtestNEGF.result";
  }

  /* set Runtest_flag */

  Runtest_flag = 1;

  /* initialize TotalTime */

  TotalTime = 0.0;

  /* print the header */

  if (myid==Host_ID){

    printf("\n*******************************************************\n");  fflush(stdout);
    printf("*******************************************************\n");    fflush(stdout);
    printf(" Welcome to OpenMX   Ver. %s                           \n",Version_OpenMX); fflush(stdout);
    printf(" Copyright (C), 2002-2013, T.Ozaki                     \n");    fflush(stdout);
    printf(" OpenMX comes with ABSOLUTELY NO WARRANTY.             \n");    fflush(stdout);
    printf(" This is free software, and you are welcome to         \n");    fflush(stdout);
    printf(" redistribute it under the constitution of the GNU-GPL.\n");    fflush(stdout);
    printf("*******************************************************\n");    fflush(stdout);
    printf("*******************************************************\n\n\n");fflush(stdout);  

    printf("\n");
    printf(" OpenMX is now in the mode to check whether OpenMX runs normally\n"); fflush(stdout);
    printf(" on your machine or not by comparing the stored *.out and\n");        fflush(stdout);
    printf(" generated *.out \n"); fflush(stdout);
    printf("\n");fflush(stdout);

    /* set dir */

    dir = input_dir;

    /* count the number of dat files */

    if(( dp = opendir(dir) ) == NULL ){
      printf("could not find the directry '%s'\n",input_dir);
      MPI_Finalize();
      exit(0);
    }

    Num_DatFiles = 0;
    while((entry = readdir(dp)) != NULL){

      if ( strstr(entry->d_name,".dat")!=NULL ){ 
          
        Num_DatFiles++;
      }
    }
    closedir(dp);

    fndat = (fname_type*)malloc(sizeof(fname_type)*Num_DatFiles);

    /* store the name of dat files */

    if(( dp = opendir(dir) ) == NULL ){
      printf("could not find the directry '%s'\n",input_dir);
      MPI_Finalize();
      exit(0);
    }

    Num_DatFiles = 0;
    while((entry = readdir(dp)) != NULL){
 
      if ( strstr(entry->d_name,".dat")!=NULL ){ 

        sprintf(fndat[Num_DatFiles].fn,"%s/%s",input_dir,entry->d_name);  
        Num_DatFiles++;
      }
    }
    closedir(dp);

    /* sorting fndat */

    qsort(fndat, Num_DatFiles, sizeof(fname_type), stringcomp);  

    /*
    for (i=0; i<Num_DatFiles; i++){
      printf("i=%2d %s\n",i,fndat[i].fn);
    } 
    */

  } /* if (myid==Host_ID) */

  sprintf(fname2,"%s",output_file);

  if (myid==Host_ID){
    fp = fopen(fname2, "r");   
    if (fp!=NULL){
      fclose(fp); 
      sprintf(operate,"%s",fname2);
      remove(operate);
    }
  }

  if (myid==Host_ID){
    printf(" %2d dat files are found in the directory '%s'.\n\n\n",Num_DatFiles,input_dir);
  }

  MPI_Bcast(&Num_DatFiles, 1, MPI_INT, Host_ID, MPI_COMM_WORLD1);

  /***********************************************************
                      start calculations
  ***********************************************************/

  for (i=0; i<Num_DatFiles; i++){

    if (myid==Host_ID){
      sprintf(fname_dat,"%s",fndat[i].fn);
    }  

    MPI_Bcast(&fname_dat, YOUSO10, MPI_CHAR, Host_ID, MPI_COMM_WORLD1);

    /* run openmx */

    argv[1] = fname_dat;
    run_main(argc, argv, numprocs, myid); 

    /***********************************************************
          comparison between two files and save the result               
    ***********************************************************/

    if (myid==Host_ID){

      input_open(fname_dat);
      input_string("System.Name",fname_dat2,"default");
      input_close();

      /* compare two out files */

      sprintf(fname_out1,"%s.out",fname_dat2);
      sprintf(fname_out2,"%s/%s.out",input_dir,fname_dat2);

      /* generated file */

      input_open(fname_out1);
      input_double("Utot.",&Utot1,(double)0.0);

      /* for Wannier functions */

      if (strcasecmp(mode,"WF")==0){  
        input_double("Sum.of.Spreads.",&Spread1,(double)0.0);
        input_double("Total.Omega.=",&Omega1,(double)0.0);
      }

      input_int("Num.Grid1.",&NGrid1_1,(int)0);
      input_int("Num.Grid2.",&NGrid1_2,(int)0);
      input_int("Num.Grid3.",&NGrid1_3,(int)0);

      input_double("Elapsed.Time.",&time1,(double)0.0);

      TotalTime += time1;

      if (fp3=input_find("<coordinates.forces")) {
          
	fscanf(fp3,"%d",&Num_Atoms);

	sum1 = 0.0;
	for (j=1; j<=Num_Atoms; j++){  
	  fscanf(fp3,"%d %s %lf %lf %lf %lf %lf %lf",
		 &k,ftmp,&gx,&gy,&gz,&fx,&fy,&fz);
	  sum1 += fx + fy + fz;
	}

	if ( ! input_last("coordinates.forces>") ) {
	  printf("Format error for coordinates.forces\n");
	}
      }
      else {
	sum1 = 1000.0;
      }

      input_close();

      /* stored file */

      input_open(fname_out2);

      /* Utot */

      input_double("Utot.",&Utot2,(double)0.0);

      /* for Wannier functions */

      if (strcasecmp(mode,"WF")==0){  
        input_double("Sum.of.Spreads.",&Spread2,(double)0.0);
        input_double("Total.Omega.=",&Omega2,(double)0.0);
      }

      /* grids */

      input_int("Num.Grid1.",&NGrid2_1,(int)0);
      input_int("Num.Grid2.",&NGrid2_2,(int)0);
      input_int("Num.Grid3.",&NGrid2_3,(int)0);

      /* coordinates and forces */

      if (fp3=input_find("<coordinates.forces")) {
          
	fscanf(fp3,"%d",&Num_Atoms);

	sum2 = 0.0;
	for (j=1; j<=Num_Atoms; j++){  
	  fscanf(fp3,"%d %s %lf %lf %lf %lf %lf %lf",
		 &k,ftmp,&gx,&gy,&gz,&fx,&fy,&fz);
	  sum2 += fx + fy + fz;
	}

	if ( ! input_last("coordinates.forces>") ) {
	  /* format error */
	  printf("Format error for coordinates.forces\n");
	}
      }
      else {
	sum2 = 100.0;
      }

      input_close();

      dU = fabs(Utot1 - Utot2);
      dF = fabs(sum1 - sum2);

      /* write the result to a file, runtest.result */

      if ( (fp2 = fopen(fname2,"a")) != NULL ){

	if (  (NGrid1_1!=NGrid2_1)
	      || (NGrid1_2!=NGrid2_2)
	      || (NGrid1_3!=NGrid2_3) )
	  {
	    fprintf(fp2,"  Invalid comparison due to the different number of grids.\n");
	    fprintf(fp2,"  You may use a different radix for FFT.\n");
	  }

        if (strcasecmp(mode,"WF")==0){  

	  fprintf(fp2,"%4d  %-32.30s Elapsed time(s)=%8.2f  diff spread=%15.12f  diff Omega=%15.12f\n",
		  i+1,fname_dat,time1,fabs(Spread1-Spread2),fabs(Omega1-Omega2));
	}
        else{

	  fprintf(fp2,"%4d  %-32.30s Elapsed time(s)=%8.2f  diff Utot=%15.12f  diff Force=%15.12f\n",
		i+1,fname_dat,time1,dU,dF);
	}

	if (i==(Num_DatFiles-1)){
	  fprintf(fp2,"\n\nTotal elapsed time (s) %11.2f\n",TotalTime);
	}

	fclose(fp2);
      }
    }

  }

  /* tell us the end of calculation */
  if (myid==Host_ID){
    printf("\n\n\n\n");
    printf("The comparison can be found in a file '%s'.\n\n\n",output_file);
  }

  if (myid==Host_ID){
    free(fndat);
  }


  MPI_Barrier(MPI_COMM_WORLD1);
  MPI_Finalize();
  exit(0);
}
Esempio n. 21
0
File: input.c Progetto: N-Thomas/sat
/*******************************************************************************************
 * NAME :             parse_clauses
 *
 * DESCRIPTION :      Progresses the file pointer past the commentes.
 *
 *
 * INPUTS :
 *      PARAMETERS :   
 *          FILE*       fp                      The pointer to the file.
 *          int         file size               The size of the file in bytes.
 *          int**       data                    The pointer to the set of pointers to the clauses.
 *          int*        nbclauses               The number of expected clauses.
 *          int*        clause_lengths          The array of clause lengths.
 *          int*        pos_val_sums            The array of values of units that are positive.
 *          int*        neg_val_sums            The array of values of units that are negative.
 *
 * OUTPUTS :
 *      RETURN :
 *          int*                     1 on success, -1 on failure/error.
 */
int parse_clauses(FILE* fp, int file_size, int** data, int* nbclauses, int* clause_lengths, int* pos_val_sums, int* neg_val_sums)
{
  int current_data_index, current_clause_index, clause_length, actual_clause_count, line_size, clause_value;
  char *end_ptr, *line, *line_copy, *split_clause;

  current_data_index = current_clause_index = clause_length = actual_clause_count = line_size = clause_value = 0;

  line = input_string(fp, file_size);
  while (line != NULL && strcmp(line, ""))
  {
    actual_clause_count++;

    if (actual_clause_count > *nbclauses) // Prevents over writing memory.
    {
      LOG("Actual clause count has exceeded expected clause count (nbclauses).", 3); 
      return -1; 
    }

    // Create copy of line because strtok() consumes line during count.
    line_size = (int) strlen(line);\
    line_copy = malloc(line_size + 1);
    line_copy[line_size] = '\0';

    memcpy(line_copy, line, line_size);
    split_clause = strtok(line, " ");

    // Count the number of values in a clause.
    while (split_clause != NULL)
    {
      clause_length++;
      split_clause = strtok (NULL, " "); // Increment to next value.
    }

    // Subtract 1 to account for clause terminating 0.
    clause_length -= 1;

    // Sets clause length in clause_lengths array.
    clause_lengths[current_data_index] = clause_length;
    int* clause = (int *)malloc(sizeof(int) * clause_length);
    split_clause = strtok(line_copy, " ");    

    // Read clause values from char* and place into clause[].
    while (split_clause != NULL)
    {
      // Tries to converts char* to int.
      clause_value = strtol(split_clause, &end_ptr, 0); 
      
      if (clause_value != 0)
      {
        clause[current_clause_index] = clause_value;

        if (clause_value < 0)
        { 
          neg_val_sums[abs(clause_value) - 1] += 1; 
        }
        else
        { 
          pos_val_sums[abs(clause_value) - 1] += 1; 
        }
      }

      if( *end_ptr != '\0' && clause_value != 0) { return -1; } // Verify int value.

      split_clause = strtok (NULL, " "); // Increment to next value.
      current_clause_index++; // Increment the clause index.
    }

    data[current_data_index] = clause; // Set clause in data.

    current_data_index++; // Increment the data index.
    current_clause_index = 0; // Reset the clause index.
    clause_length = 0;

    free(line_copy);
    free(line);

    line = input_string(fp, file_size);
  }

  if(actual_clause_count != *nbclauses)
  {
    LOG("Actual clause count != expected clause count (nbclauses).", 3);
    return -1;
  }

  free(line);
  return 1;
} 
Esempio n. 22
0
int main(int argc, char *argv[])
{
	struct sockaddr_in dest;
	char recv_buf[MAX_LINE];
	char recv_mail[MAX_LINE]="0";
	char *str = NULL;
	int n;
	int data_len;
	char *username = NULL;
	char *password = NULL;
	char *cmd_type = NULL;

	username = (char*)malloc(MAX_LINE*sizeof(char));
	password = (char*)malloc(MAX_LINE*sizeof(char));
	cmd_type = (char*)malloc(MAX_LINE*sizeof(char));

	loop = uv_default_loop();
	uv_tcp_t* socket = (uv_tcp_t*)malloc(sizeof(uv_tcp_t));
	if (socket == NULL) {
		printf("socket malloc failed.\n");	
	}

	uv_tcp_init(loop, socket);

	printf("Input username:\n");
	username = input_string(username);
	printf("Input password:\n");
	password= input_string(password);

	printf("Input cmd_type:\n");
	cmd_type = input_string(cmd_type);


	switch(interpret_mail_type(cmd_type))
	{
		case 0:
	
				uv_connect_t* connect = (uv_connect_t*)malloc(sizeof(uv_connect_t));
				if (connect == NULL) {
					printf("connect malloc failed.\n");	
				}

				uv_ip4_addr("127.0.0.1", DEFAULT_PORT, &sin);
				uv_tcp_connect(connect, socket, (struct sockaddr*)&dest, on_connect);

				data_len = strlen(username)+1;
			n = writen(s_fd, &data_len, sizeof(data_len));
			n = writen(s_fd, username, strlen(username)+1);

			data_len = strlen(password)+1;
			n = writen(s_fd, &data_len, sizeof(data_len));
			n = writen(s_fd, password, strlen(password)+1);
			
			struct buf *that = init_buf(1,MAX_MAIL_LEN);
			printf("input your mail like this:mail username mailcontent\n");
			fgets(that->data, MAX_MAIL_LEN, stdin);
			that->data[strlen(that->data)-1] = '\0';
			
			data_len = strlen(that->data)+1;
			n = writen(s_fd, &data_len, sizeof(data_len));
			n = writen(s_fd, that->data, strlen(that->data)+1);
				
			readn(s_fd, recv_buf, MAX_LINE);
			printf("receive mail from server:%s\n", recv_buf);
	
	}
	uv_run(loop, UV_RUN_DEFAULT);
		
	return 0;

}
Esempio n. 23
0
int main(void)
{

//retrieves the number if data entries in the file
int i = data_count();
int j;
FILE *fp1;
char fname[] = "user_info.txt";
	
//declares an array of srtucts, with number of elements
//equal to number data entries in the file,
//so an element in the array for each data entry
user_info users[i];
user_info *p; //declares pointer to struct of type user_info
p = &users[0]; //sets address of pointer to the first element of struct array

char tmp[3];//temp array used to read in user choices
char op;//char which user choice is processed and inserted into

//Asks user to enter their choice on what operation to perform.
printf("Would you like to read user data or write new information?\n");
printf("r - read data from file.\n");
printf("w - write new data to a new file, overwriting existing file.\n");
printf("a - write new data and append to current file.\n");
//using fgets() to read in choice and sscanf() to process and insert into "op"
fgets(tmp, 3, stdin);
sscanf(tmp, "%c", &op);


//if user wishes to read from file...
if (op == 'r' || op == 'R')
{
FILE *fp1;
char fname[] = "user_info.txt";
	
if ( (fp1 = fopen(fname, "r" )) == NULL )
{
	printf("cannot open file %s for reading\n", fname);
	exit(1);
}

//Number of data entries was counted at the beginning of the program.
//Loops through file, transferring each data entry into its own struct.
for(j=0;j<i;j++)
{
	//sets address of pointer to the address of current array element
	p = &users[j];
	//reads data from the file into the struct array element
	read_from_file(fp1, p);
}

fclose(fp1);
}//end of reading from file if condition


//If user wishes to write to file...
else if (op == 'a' || op == 'A' || op == 'w' || op == 'W')
{
//calls input function, passing the type of write operation
//to be performed as well as the struct
input_string(&op, p);
}

//if user enters wrong choice
else
{
printf("You did not specify a valid option.\n");
}

return 0;
}
Esempio n. 24
0
int LRParsing::parsetree_mfc(FILE *read_fp, CDC *pDC, CSize *size){
	top=-1;
	fseek(read_fp, 0, SEEK_SET);
	CString terminalString;
	LRParsing lex(read_fp);	//모든내용을 읽어들여 분석한다.
	grammer *X, a, *temp;
	int *S;
	int k;
	cell_action_tbl action;
	int cnt=0, cnt_s = 0, cnt_r = 0;

	int err = parsetable_mfc();
	if(err == -1)
		return -1;

	//상태0을 삽입.
	S = (int*) malloc(sizeof(int));
	*S = 0;
	push((void*)S);
	//처음 심볼을 읽음.
	a = input_string(lex);
	if(a.select == -1) return -4;
	do{
		cnt++;
		if(cnt == 95)
			cnt = 95;
		S = (int*)stack[top];				//stack의 탑의 상태를 읽는다. (popX)
		//각 액션테이블 값에 따른 행동
		action = Action_Table[*S][a.location];	//해당 상태와 심볼에 대한 Action_Table값
		switch (action.Kind){
		//읽어드린 토큰을 푸시. 상태도 푸시.
		case 's':
			cnt_s++;
			X = (grammer*) malloc(sizeof(grammer));
			linkinit(X);
			X->select = a.select; X->location = a.location;
			if(a.select == 0 && (a.location == 16 || a.location == 17 || a.location == 15))
				strcpy_s(X->str, a.str);
			push((void*)X);

			S = (int*)malloc(sizeof(int));
			*S = action.num;
			push((void*)S);
			//남은 input string의 첫 심볼을 읽고 다음심볼을 가리킴.
			a = input_string(lex);
			if(a.select == -1) return -4;				
			break;

		//팝해서 리듀스하고 다시 푸시. 상태도 푸시.
		case 'r':
			cnt_r++;
			X = (grammer*)malloc(sizeof(grammer));
			linkinit(X);
			X->select = rule_v[action.num].left.select;
			X->location = rule_v[action.num].left.location;

			//입실론을 리듀스할때, 팝하지말고 입실론을 추가로 링크.
			if(rule_v[action.num].rule_len == 1 && rule_v[action.num].right[0].select == 0 && rule_v[action.num].right[0].location == 22-1){
				temp = (grammer*)malloc(sizeof(grammer));
				linkinit(temp);
				temp->select = 0; temp->location = 22-1;
				X->link[0] = temp;
			}
			//다른기호에 대해선 정상적인 팝과 링크를 걸어준다.
			else{
				for(int i=rule_v[action.num].rule_len-1; i>=0; i--){
					free((int*)pop());
					X->link[i] = (grammer*)pop();
				}//상태와 심볼, 두배로 pop;
			}
			k = *(int*)stack[top];

			//룰의 왼쪽심볼을 푸시
			push((void*)X);
			//상태도 푸시.
			S = (int*)malloc(sizeof(int));
			*S = Goto_Table[k][rule_v[action.num].left.location];
			push((void*)S);
			break;

		//성공했으므로 파스트리를 그리는 함수 호출.
		case 'a':
			//상태는 팝해서 없애주고, 심볼은 루트에다 연결.
			free((int*)pop());
			root = (grammer*)pop();
			free((int*)pop());
			break;

		//에러이므로 음수 리턴값 출력
		case 'e':
			break;
		default:
			return -3;
			break;
		}
	}while(!(action.Kind == 'a' && a.select == 0 && a.location == 22-2));

	width = leafcount(root)*70;
	CRect rect(0,5,5+width,5+35);
	height = 5;
	this->parsedraw_mfc(pDC, root, rect);
	size->cx = width; size->cy = height;
	return 0;
}
Esempio n. 25
0
void TRAN_Input_std(
  MPI_Comm comm1, 
  int Solver,          /* input */
  int SpinP_switch,  
  char *filepath,
  double kBvalue,
  double TRAN_eV2Hartree,
  double Electronic_Temperature,
                      /* output */
  int *output_hks
)
{
  FILE *fp;
  int i,po;
  int i_vec[20],i_vec2[20];
  double r_vec[20];
  char *s_vec[20];
  char buf[MAXBUF];
  int myid;
  /* S MitsuakiKAWAMURA*/
  int TRAN_Analysis_Dummy;
  /* E MitsuakiKAWAMURA*/

  MPI_Comm_rank(comm1,&myid);

  /****************************************************
               parameters for TRANSPORT
  ****************************************************/

  input_logical("NEGF.Output_HKS",&TRAN_output_hks,0);
  *output_hks = TRAN_output_hks;

  /* printf("NEGF.OutputHKS=%d\n",TRAN_output_hks); */
  input_string("NEGF.filename.HKS",TRAN_hksoutfilename,"NEGF.hks");
  /* printf("TRAN_hksoutfilename=%s\n",TRAN_hksoutfilename); */

  input_logical("NEGF.Output.for.TranMain",&TRAN_output_TranMain,0);

  if ( Solver!=4 ) { return; }

  /**** show transport credit ****/
  TRAN_Credit(comm1);

  input_string("NEGF.filename.hks.l",TRAN_hksfilename[0],"NEGF.hks.l");
  input_string("NEGF.filename.hks.r",TRAN_hksfilename[1],"NEGF.hks.r");

  /* read data of leads */

  TRAN_RestartFile(comm1, "read","left", filepath,TRAN_hksfilename[0]);
  TRAN_RestartFile(comm1, "read","right",filepath,TRAN_hksfilename[1]);

  /* check b-, and c-axes of the unit cell of leads. */

  po = 0;
  for (i=2; i<=3; i++){
    if (1.0e-10<fabs(tv_e[0][i][1]-tv_e[1][i][1])) po = 1;
    if (1.0e-10<fabs(tv_e[0][i][2]-tv_e[1][i][2])) po = 1;
    if (1.0e-10<fabs(tv_e[0][i][3]-tv_e[1][i][3])) po = 1;
  }

  if (po==1){

    if (myid==Host_ID){
      printf("Warning: The b- or c-axis of the unit cell for the left lead is not same as that for the right lead.\n");
    }

    MPI_Finalize();
    exit(1);
  }

  /* show chemical potentials */

  if (myid==Host_ID){
    printf("\n");
    printf("Intrinsic chemical potential (eV) of the leads\n");
    printf("  Left lead:  %15.12f\n",ChemP_e[0]*TRAN_eV2Hartree);
    printf("  Right lead: %15.12f\n",ChemP_e[1]*TRAN_eV2Hartree);
  }

  /* check the conflict of SpinP_switch */

  if ( (SpinP_switch!=SpinP_switch_e[0]) || (SpinP_switch!=SpinP_switch_e[1]) ){

    if (myid==Host_ID){
      printf ("scf.SpinPolarization conflicts between leads or lead and center.\n");
    }

    MPI_Finalize();
    exit(0);
  }

  input_int(   "NEGF.Surfgreen.iterationmax", &tran_surfgreen_iteration_max, 600);
  input_double("NEGF.Surfgreen.convergeeps", &tran_surfgreen_eps, 1.0e-12); 

  /****  k-points parallel to the layer, which are used for the SCF calc. ****/

  i_vec2[0]=1;
  i_vec2[1]=1;
  input_intv("NEGF.scf.Kgrid",2,i_vec,i_vec2);
  TRAN_Kspace_grid2 = i_vec[0];
  TRAN_Kspace_grid3 = i_vec[1];

  if (TRAN_Kspace_grid2<=0){

    if (myid==Host_ID){
      printf("NEGF.scf.Kgrid should be over 1\n");
    }

    MPI_Finalize();
    exit(1);
  } 
  if (TRAN_Kspace_grid3<=0){

    if (myid==Host_ID){
      printf("NEGF.scf.Kgrid should be over 1\n");
    }

    MPI_Finalize();
    exit(1);
  } 

  /* Poisson solver */

  TRAN_Poisson_flag = 1;

  /* beginning added by mari 07.23.2014 */
  s_vec[0]="FD";  s_vec[1]="FFT";  s_vec[2]="FDG";
  i_vec[0]=1   ;  i_vec[1]=2    ;  i_vec[2]=3    ;

  input_string2int("NEGF.Poisson.Solver", &TRAN_Poisson_flag, 3, s_vec,i_vec);
  /* end added by mari 07.23.2014 */

  /* parameter to scale terms with Gpara=0 */

  input_double("NEGF.Poisson_Gparazero.scaling", &TRAN_Poisson_Gpara_Scaling, 1.0); 

  /* the number of buffer cells in FFTE */

  input_int("NEGF.FFTE.Num.Buffer.Cells", &TRAN_FFTE_CpyNum, 1); 

  /* the number of iterations by the Band calculation in the initial SCF iterations */

  input_int("NEGF.SCF.Iter.Band", &TRAN_SCF_Iter_Band, 3); 

  /* integration method */

  TRAN_integration = 0;

  s_vec[0]="CF"; s_vec[1]="OLD"; 
  i_vec[0]=0    ; i_vec[1]=1    ;
  input_string2int("NEGF.Integration", &TRAN_integration, 2, s_vec,i_vec);

  /* check whether analysis is made or not */

  input_logical("NEGF.tran.analysis",&TRAN_analysis,1);

  /* S MitsuakiKAWAMURA*/
  input_logical("NEGF.tran.channel", &TRAN_Analysis_Dummy, 1);
  if (TRAN_Analysis_Dummy == 1 && TRAN_analysis != 1){
    TRAN_analysis = 1;
    if (myid == Host_ID)
      printf("Since NEGF.tran.channel is on, NEGF.tran.analysis is automatically set to on.\n");
  }
  input_logical("NEGF.tran.CurrentDensity", &TRAN_Analysis_Dummy, 1);
  if (TRAN_Analysis_Dummy == 1 && TRAN_analysis != 1){
    TRAN_analysis = 1;
    if (myid == Host_ID)
      printf("Since NEGF.tran.CurrentDensity is on, NEGF.tran.analysis is automatically set to on.\n");
  }
  input_logical("NEGF.OffDiagonalCurrent", &TRAN_Analysis_Dummy, 0);
  if (TRAN_Analysis_Dummy == 1 && TRAN_analysis != 1) {
    TRAN_analysis = 1;
    if (myid == Host_ID)
      printf("Since NEGF.OffDiagonalCurrent is on, NEGF.tran.analysis is automatically set to on.\n");
  }
  /* E MitsuakiKAWAMURA*/

  /* check whether the SCF calcultion is skipped or not */

  i = 0;
  s_vec[i] = "OFF";         i_vec[i] = 0;  i++;
  s_vec[i] = "ON";          i_vec[i] = 1;  i++;
  s_vec[i] = "Periodic";  i_vec[i] = 2;  i++;

  input_string2int("NEGF.tran.SCF.skip", &TRAN_SCF_skip, i, s_vec, i_vec);

  /****  k-points parallel to the layer, which are used for the transmission calc. ****/
  
  i_vec2[0]=TRAN_Kspace_grid2;
  i_vec2[1]=TRAN_Kspace_grid3;
  input_intv("NEGF.tran.Kgrid",2,i_vec,i_vec2);
  TRAN_TKspace_grid2 = i_vec[0];
  TRAN_TKspace_grid3 = i_vec[1];

  if (TRAN_TKspace_grid2<=0){

    if (myid==Host_ID){
      printf("NEGF.tran.Kgrid should be over 1\n");
    }

    MPI_Finalize();
    exit(1);
  } 
  if (TRAN_TKspace_grid3<=0){

    if (myid==Host_ID){
      printf("NEGF.tran.Kgrid should be over 1\n");
    }

    MPI_Finalize();
    exit(1);
  } 

  /**** source and drain bias voltage ****/

  input_logical("NEGF.bias.apply",&tran_bias_apply,1); /* default=on */

  if ( tran_bias_apply ) {

    double tmp;

    tran_biasvoltage_e[0] = 0.0;
    input_double("NEGF.bias.voltage", &tmp, 0.0);  /* in eV */
    tran_biasvoltage_e[1] = tmp/TRAN_eV2Hartree; 

  }
  else {
    tran_biasvoltage_e[0]=0.0;
    tran_biasvoltage_e[1]=0.0;
  }

  if (tran_bias_apply) {

    int side;
    side=0;
    TRAN_Apply_Bias2e(comm1,  side, tran_biasvoltage_e[side], TRAN_eV2Hartree,
		      SpinP_switch_e[side], atomnum_e[side],
		      WhatSpecies_e[side], Spe_Total_CNO_e[side], FNAN_e[side], natn_e[side],
		      Ngrid1_e[side], Ngrid2_e[side], Ngrid3_e[side], OLP_e[side][0],
		      &ChemP_e[side],H_e[side], dVHart_Grid_e[side] ); /* output */
    side=1;
    TRAN_Apply_Bias2e(comm1,  side, tran_biasvoltage_e[side], TRAN_eV2Hartree,
		      SpinP_switch_e[side], atomnum_e[side],
		      WhatSpecies_e[side], Spe_Total_CNO_e[side], FNAN_e[side], natn_e[side],
		      Ngrid1_e[side], Ngrid2_e[side], Ngrid3_e[side], OLP_e[side][0],
		      &ChemP_e[side], H_e[side], dVHart_Grid_e[side] ); /* output */
  }

  /**** gate voltage ****/

  /* beginning added by mari 07.30.2014 */
  if(TRAN_Poisson_flag == 3) {
    r_vec[0] = 0.0;
    r_vec[1] = 0.0;
    input_doublev("NEGF.gate.voltage", 2, tran_gate_voltage, r_vec); 
    tran_gate_voltage[0] /= TRAN_eV2Hartree; 
    tran_gate_voltage[1] /= TRAN_eV2Hartree; 
  } else {
    r_vec[0] = 0.0;
    input_doublev("NEGF.gate.voltage", 1, tran_gate_voltage, r_vec); 
    tran_gate_voltage[0] /= TRAN_eV2Hartree; 
  }
  /* end added by mari 07.30.2014 */

  /******************************************************
            parameters for the DOS calculation         
  ******************************************************/
  
  i=0;
  r_vec[i++] = -10.0;
  r_vec[i++] =  10.0;
  r_vec[i++] = 5.0e-3;
  input_doublev("NEGF.Dos.energyrange",i, tran_dos_energyrange, r_vec); /* in eV */
  /* change the unit from eV to Hartree */
  tran_dos_energyrange[0] /= TRAN_eV2Hartree;
  tran_dos_energyrange[1] /= TRAN_eV2Hartree;
  tran_dos_energyrange[2] /= TRAN_eV2Hartree;

  input_int("NEGF.Dos.energy.div",&tran_dos_energydiv,200);
  
  i_vec2[0]=1;
  i_vec2[1]=1;
  input_intv("NEGF.Dos.Kgrid",2,i_vec,i_vec2);
  TRAN_dos_Kspace_grid2 = i_vec[0];
  TRAN_dos_Kspace_grid3 = i_vec[1];

  /********************************************************
    integration on real axis with a small imaginary part
    for the "non-equilibrium" region
  ********************************************************/

  input_double("NEGF.bias.neq.im.energy", &Tran_bias_neq_im_energy, 1.0e-2);  /* in eV */
  if (Tran_bias_neq_im_energy<0.0) {
    if (myid==Host_ID)  printf("NEGF.bias.neq.im.energy should be positive.\n");
    MPI_Finalize();
    exit(1);
  }
  /* change the unit from eV to Hartree */
  Tran_bias_neq_im_energy /= TRAN_eV2Hartree; 

  input_double("NEGF.bias.neq.energy.step", &Tran_bias_neq_energy_step, 0.02);  /* in eV */
  if (Tran_bias_neq_energy_step<0.0) {
    if (myid==Host_ID)  printf("NEGF.bias.neq.energy.step should be positive.\n");
    MPI_Finalize();
    exit(1);
  }
  /* change the unit from eV to Hartree */
  Tran_bias_neq_energy_step /= TRAN_eV2Hartree; 

  input_double("NEGF.bias.neq.cutoff", &Tran_bias_neq_cutoff, 1.0e-8);  /* dimensionless */

  /********************************************************
     contour integration based on a continued 
     fraction representation of the Fermi function 
  ********************************************************/

  input_int("NEGF.Num.Poles", &tran_num_poles,150);

  TRAN_Set_IntegPath( comm1, TRAN_eV2Hartree, kBvalue, Electronic_Temperature );
}