📄 input.c
字号:
fprintf(stderr, "%s: illegal option -- %s\n", argv[0], &(argv[i][1])); cmderr = TRUE; break; } } else { /* isn't an option, must be the input file */ *input_file = argv[i]; } } if(cmderr == TRUE) {#if CAPVEW == ON fprintf(stderr, "Usage: '%s [-o<expansion order>] [-d<partitioning depth>] [<input file>]\n [-p<permittivity factor>] [-rs<cond list>] [-ri<cond list>]\n [-] [-l<list file>] [-t<iter tol>] [-a<azimuth>] [-e<elevation>]\n [-r<rotation>] [-h<distance>] [-s<scale>] [-w<linewidth>]\n [-u<upaxis>] [-q<cond list>] [-rc<cond list>] [-x<axeslength>]\n [-b<.figfile>] [-m] [-rk] [-rd] [-dc] [-c] [-v] [-n] [-f] [-g]\n", argv[0]); fprintf(stderr, "DEFAULT VALUES:\n"); fprintf(stderr, " expansion order = %d\n", DEFORD); fprintf(stderr, " partitioning depth = set automatically\n"); fprintf(stderr, " permittivity factor = 1.0\n"); fprintf(stderr, " iterative loop ||r|| tolerance = %g\n", ABSTOL); fprintf(stderr, " azimuth = %g\n elevation = %g\n rotation = %g\n", DEFAZM, DEFELE, DEFROT); fprintf(stderr, " distance = %g (0 => 1 object radius away from center)\n", DEFDST); fprintf(stderr, " scale = %g\n linewidth = %g\n", DEFDST, DEFSCL, DEFWID); if(DEFUAX == XI) fprintf(stderr, " upaxis = x\n"); else if(DEFUAX == YI) fprintf(stderr, " upaxis = y\n"); else if(DEFUAX == ZI) fprintf(stderr, " upaxis = z\n"); fprintf(stderr, " axeslength = %g\n", DEFAXE); fprintf(stderr, "OPTIONS:\n"); fprintf(stderr, " - = force conductor surface file read from stdin\n"); fprintf(stderr, " -rs = remove conductors from solve list\n"); fprintf(stderr, " -ri = remove conductors from input\n"); fprintf(stderr, " -q = select conductors for at-1V charge distribution .ps pictures\n"); fprintf(stderr, " -rc = remove conductors from all charge distribution .ps pictures\n"); fprintf(stderr, " -b = superimpose lines, arrows and dots in .figfile on all .ps pictures\n"); fprintf(stderr, " -m = switch to dump-ps-picture-file-only mode\n"); fprintf(stderr, " -rk = remove key in shaded .ps picture file (use with -q option)\n"); fprintf(stderr, " -rd = remove DIELEC type surfaces from all .ps picture files\n"); fprintf(stderr, " -dc = display total charges in shaded .ps picture file (use with -q option)\n"); fprintf(stderr, " -c = print command line in .ps picture file\n"); fprintf(stderr, " -v = suppress showpage in all .ps picture files\n"); fprintf(stderr, " -n = number faces with input order numbers\n"); fprintf(stderr, " -f = do not fill in faces (don't rmv hidden lines)\n"); fprintf(stderr, " -g = dump depth graph and quit\n");#else fprintf(stderr, "Usage: '%s [-o<expansion order>] [-d<partitioning depth>] [<input file>]\n [-p<permittivity factor>] [-rs<cond list>] [-ri<cond list>]\n [-] [-l<list file>] [-t<iter tol>]\n", argv[0]); fprintf(stderr, "DEFAULT VALUES:\n"); fprintf(stderr, " expansion order = %d\n", DEFORD); fprintf(stderr, " partitioning depth = set automatically\n"); fprintf(stderr, " permittivity factor = 1.0\n"); fprintf(stderr, " iterative loop ||r|| tolerance = %g\n", ABSTOL); fprintf(stderr, "OPTIONS:\n"); fprintf(stderr, " - = force conductor surface file read from stdin\n"); fprintf(stderr, " -rs = remove conductors from solve list\n"); fprintf(stderr, " -ri = remove conductors from input\n");#endif fprintf(stderr, " <cond list> = [<name>],[<name>],...,[<name>]\n"); dumpConfig(stderr, argv[0]); exit(1); }}/* surface information input routine - panels are read by read_panels()*/surface *read_all_surfaces(input_file, surf_list_file, read_from_stdin, infile, relperm)int read_from_stdin;char *input_file, *surf_list_file, *infile;double relperm;{ int num_surf, i; char group_name[BUFSIZ]; surface *surf_list, *cur_surf; /* get the surfaces from stdin, the list file or the file on cmd line */ /* the `- ' option always forces the first cond surf read from stdin */ /* can also read from stdin if there's no list file and no cmd line file */ infile[0] = '\0'; num_surf = 0; surf_list = NULL; strcpy(group_name, "GROUP1"); if(read_from_stdin || (input_file == NULL && surf_list_file == NULL)) { CALLOC(surf_list, 1, surface, ON, AMSC); surf_list->type = CONDTR; /* only conductors can come in stdin */ CALLOC(surf_list->name, strlen("stdin")+1, char, ON, AMSC); strcpy(surf_list->name, "stdin"); surf_list->outer_perm = relperm; surf_list->end_of_chain = TRUE; /* set up group name */ CALLOC(surf_list->group_name, strlen(group_name)+1, char, ON, AMSC); strcpy(surf_list->group_name, group_name); strcpy(group_name, "GROUP2"); cur_surf = surf_list; strcpy(infile, "stdin"); num_surf++; } /* set up to read from command line file, if necessary */ if(input_file != NULL) { if(surf_list == NULL) { CALLOC(surf_list, 1, surface, ON, AMSC); cur_surf = surf_list; } else { CALLOC(cur_surf->next, 1, surface, ON, AMSC); cur_surf = cur_surf->next; } cur_surf->type = CONDTR; CALLOC(cur_surf->name, strlen(input_file)+1, char, ON, AMSC); strcpy(cur_surf->name, input_file); cur_surf->outer_perm = relperm; cur_surf->end_of_chain = TRUE; /* set up group name */ CALLOC(cur_surf->group_name, strlen(group_name)+1, char, ON, AMSC); strcpy(cur_surf->group_name, group_name); for(i = 0; infile[i] != '\0'; i++); if(infile[0] != '\0') sprintf(&(infile[i]), ", %s", input_file); else sprintf(&(infile[i]), "%s", input_file); num_surf++; read_from_stdin++; } /* read list file if present */ if(surf_list_file != NULL) { read_list_file(&surf_list, &num_surf, surf_list_file, read_from_stdin); for(i = 0; infile[i] != '\0'; i++); if(infile[0] != '\0') sprintf(&(infile[i]), ", %s", surf_list_file); else sprintf(&(infile[i]), "%s", surf_list_file); } return(surf_list);}/* surface input routine and command line parser - inputs surfaces (ie file names whose panels are read in read_panels) - sets parameters accordingly*/surface *input_surfaces(argv, argc, autmom, autlev, relperm, numMom, numLev, infile)int argc, *autmom, *autlev, *numMom, *numLev;double *relperm;char *argv[], *infile;{ int read_from_stdin, num_surf; surface *read_all_surfaces(); char *surf_list_file, *input_file; /* initialize defaults */ surf_list_file = input_file = NULL; read_from_stdin = FALSE; parse_command_line(argv, argc, autmom, autlev, relperm, numMom, numLev, &input_file, &surf_list_file, &read_from_stdin); return(read_all_surfaces(input_file, surf_list_file, read_from_stdin, infile, *relperm));}/* dump the data associated with the input surfaces*/void dumpSurfDat(surf_list)surface *surf_list;{ surface *cur_surf; char *hack_path(); fprintf(stdout, " Input surfaces:\n"); for(cur_surf = surf_list; cur_surf != NULL; cur_surf = cur_surf->next) { /* possibly write group name */ if(cur_surf == surf_list) fprintf(stdout, " %s\n", cur_surf->group_name); else if(cur_surf->prev->end_of_chain) fprintf(stdout, " %s\n", cur_surf->group_name); /* write file name */ fprintf(stdout, " %s", hack_path(cur_surf->name)); if(cur_surf->type == CONDTR) { fprintf(stdout, ", conductor\n"); fprintf(stdout, " title: `%s'\n", cur_surf->title); fprintf(stdout, " outer permittivity: %g\n", cur_surf->outer_perm); } else if(cur_surf->type == DIELEC) { fprintf(stdout, ", dielectric interface\n"); fprintf(stdout, " title: `%s'\n", cur_surf->title); fprintf(stdout, " permittivities: %g (inner) %g (outer)\n", cur_surf->inner_perm, cur_surf->outer_perm); } else if(cur_surf->type == BOTH) { fprintf(stdout, ", thin conductor on dielectric interface\n"); fprintf(stdout, " title: `%s'\n", cur_surf->title); fprintf(stdout, " permittivities: %g (inner) %g (outer)\n", cur_surf->inner_perm, cur_surf->outer_perm); } else { fprintf(stderr, "dumpSurfDat: bad surface type\n"); exit(1); } fprintf(stdout," number of panels: %d\n", cur_surf->num_panels - cur_surf->num_dummies); fprintf(stdout," number of extra evaluation points: %d\n", cur_surf->num_dummies); fprintf(stdout," translation: (%g %g %g)\n", cur_surf->trans[0], cur_surf->trans[1], cur_surf->trans[2]); }}/* replaces name (and all aliases) corresponding to "num" with unique string*/void remove_name(name_list, num)int num;Name **name_list;{ static char str[] = "%`_^#$REMOVED"; Name *cur_name, *cur_alias; int i, slen; slen = strlen(str); for(i = 1, cur_name = *name_list; cur_name != NULL; cur_name = cur_name->next, i++) { if(i == num) { /* overwrite name */ if(strlen(cur_name->name) < slen) { CALLOC(cur_name->name, slen+1, char, ON, AMSC); } strcpy(cur_name->name, str); /* overwrite aliases */ for(cur_alias = cur_name->alias_list; cur_alias != NULL; cur_alias = cur_alias->next) { if(strlen(cur_alias->name) < slen) { CALLOC(cur_alias->name, slen+1, char, ON, AMSC); } strcpy(cur_alias->name, str); } } }} /* removes (unlinks from linked list) panels that are on conductors to delete*/void remove_conds(panels, num_list, name_list)charge **panels;ITER *num_list;Name **name_list;{ ITER *cur_num; charge *cur_panel, *prev_panel; for(cur_panel = prev_panel = *panels; cur_panel != NULL; cur_panel = cur_panel->next) { if(cur_panel->dummy) continue; if(cur_panel->surf->type == CONDTR || cur_panel->surf->type == BOTH) { if(want_this_iter(num_list, cur_panel->cond)) { /* panel's conductor is to be removed, so unlink the panel */ /* - if panel to be removed is first panel, rewrite head pointer */ if(cur_panel == *panels) *panels = cur_panel->next; /* - otherwise bypass cur_panel with next pointers */ else prev_panel->next = cur_panel->next; } else prev_panel = cur_panel; } } /* remove all -ri'd conductor names from master name list - required to get rid of references in capsolve() - actually, name and all its aliases are replaced by ugly string (not the cleanest thing) */ for(cur_num = num_list; cur_num != NULL; cur_num = cur_num->next) { remove_name(name_list, cur_num->iter); }}/* checks for kill lists with inconsistent demands -rs list: can't remove a conductor physically removed from computation w/-ri -q list: can't dump q plot for cond physically rmed or rmed from comp -rc list: no restrictions -ri/-rs: can't exhaust all conductors with combination of these lists*/void resolve_kill_lists(rs_num_list, q_num_list, ri_num_list, num_cond)ITER *rs_num_list, *q_num_list, *ri_num_list;int num_cond;{ int i, lists_exhaustive; ITER *cur_num; extern int m_; /* check for anything in -rs list in -ri list */ for(cur_num = ri_num_list; cur_num != NULL; cur_num = cur_num->next) { if(want_this_iter(rs_num_list, cur_num->iter)) { fprintf(stderr, "resolve_kill_lists: a conductor removed with -ri is in the -rs list\n"); exit(1); } } /* check for anything in -q list in -ri or -rs list - recall that -q by itself means plot for all active, so null q_num_list always ok */ for(cur_num = q_num_list; cur_num != NULL; cur_num = cur_num->next) { if(want_this_iter(rs_num_list, cur_num->iter) || want_this_iter(ri_num_list, cur_num->iter)) { fprintf(stderr, "resolve_kill_lists: a conductor removed with -ri or -rs is in the -q list\n"); exit(1); } } /* check that -rs and -ri lists don't exhaust all conductors */ lists_exhaustive = TRUE; for(i = 1; i <= num_cond; i++) { if(!want_this_iter(rs_num_list, i) && !want_this_iter(ri_num_list, i)) { lists_exhaustive = FALSE; break; } } if(lists_exhaustive && !m_) { fprintf(stderr, "resolve_kill_lists: all conductors either in -ri or -rs list\n"); exit(1); }}/* main input routine, returns a list of panels in the problem*/charge *input_problem(argv, argc, autmom, autlev, relperm, numMom, numLev, name_list, num_cond)int argc, *autmom, *autlev, *numMom, *numLev, *num_cond;double *relperm;char *argv[];Name **name_list;{ surface *surf_list, *input_surfaces(); char infile[BUFSIZ], *ctime(), hostname[BUFSIZ]; charge *read_panels(), *chglist; long clock; extern ITER *kill_num_list, *qpic_num_list, *kinp_num_list, *kq_num_list; extern char *kill_name_list, *qpic_name_list, *kinp_name_list; extern char *kq_name_list; /* read the conductor and dielectric interface surface files, parse cmds */ surf_list = input_surfaces(argv, argc, autmom, autlev, relperm, numMom, numLev, infile); if(*autmom == ON) *numMom = DEFORD;#if DIRSOL == ON || EXPGCR == ON /*fprintf(stderr, "DIRSOL and EXPGCR compile options not implemented\n"); exit(1);*/ *numLev = 0; /* put all the charges in first cube */ *autlev = OFF;#endif strcpy(hostname, "18Sep92, mod 27Apr04"); fprintf(stdout, "Running %s %.1fwr (%s)\n Input: %s\n", argv[0], VERSION, hostname, infile); /* input the panels from the surface files */ *num_cond = 0; /* initialize conductor count */ chglist = read_panels(surf_list, name_list, num_cond); /* set up the lists of conductors to remove from solve list */ kill_num_list = get_kill_num_list(*name_list, kill_name_list); /* remove the panels on specified conductors from input list */ kinp_num_list = get_kill_num_list(*name_list, kinp_name_list); remove_conds(&chglist, kinp_num_list, name_list); /* set up the lists of conductors to dump shaded plots for */ qpic_num_list = get_kill_num_list(*name_list, qpic_name_list); /* set up the lists of conductors to eliminate from shaded plots */ kq_num_list = get_kill_num_list(*name_list, kq_name_list); /* check for inconsistencies in kill lists */ resolve_kill_lists(kill_num_list, qpic_num_list, kinp_num_list, *num_cond);#if DISSRF == ON dumpSurfDat(surf_list);#endif time(&clock); fprintf(stdout, " Date: %s", ctime(&clock));#ifndef NO_GETHOSTNAME if(gethostname(hostname, BUFSIZ) != -1) fprintf(stdout, " Host: %s\n", hostname); else fprintf(stdout, " Host: ? (gethostname() failure)\n");#endif#if CFGDAT == ON dumpConfig(stdout, argv[0]);#endif /* return the panels from the surface files */ return(chglist);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -