void gettab (char *name) { char line [LINESZ]; FILE *fd; int i, o, oe, n, ne; fd = fopen (name, "r"); if (! fd) { fprintf (stderr, "cannot open %s\n", name); exit (-1); } for (i=0; i<=255; ++i) tab[i] = i; while (fgets (line, sizeof (line), fd)) { if (! getvalues (line, &o, &oe, &n, &ne)) continue; if (ne == n) for (i=o; i<=oe; ++i) tab[i] = n; else for (i=o; i<=oe; ++i) tab[i] = n++; } fclose (fd); }
int generateRandom(char* filename,int* values) { Recipe* r=readRecipe(filename); //read files; int resul=getvalues(r, values); freeRecipe(r); return resul;// get list of int }
// getvalues(category, labeldict) -> list // returns list containing value of label for every frame in the label // if the label contains atoms from more than one molecule, only the first // molecule is cycled (this the behavior of GeometryMol). // XXX Note: this command is bad: the GeometryMol::calculate_all method // twiddles the frame of the molecule, so this command isn't read only as // its semantics would imply. But it should be possible to fix this // in GeometryMol. static PyObject *label_getvalues(PyObject *self, PyObject *args) { char *type; PyObject *labeldict; if (!PyArg_ParseTuple(args, (char *)"sO!:label.getvalues", &type, &PyDict_Type, &labeldict)) return NULL; VMDApp *app = get_vmdapp(); int cat = app->geometryList->geom_list_index(type); if (cat < 0) { PyErr_SetString(PyExc_ValueError, (char *)"Unknown label category"); return NULL; } GeomListPtr glist = app->geometryList->geom_list(cat); int gnum = glist->num(); for (int i=0; i<gnum; i++) { if (dict2geom(labeldict, (*glist)[i])) return getvalues((*glist)[i]); } PyErr_SetString(PyExc_ValueError, (char *)"Invalid label"); return NULL; }
static void lineparse() { char* tokn, *env, *envName, *tmp1, *tmp2; long l, in_template; varname[0] = '\0'; objname[0] = '\0'; if (!strcmp(tok1,"end")) {strcpy(curstruct,"--"); in_template = 0;} if (!strcmp(tok1,"structure")) {strcpy(curstruct,tok2);} if (!strcmp(tok1,"database")) ; if (!strcmp(tok1,"incname")) ; if (!strcmp(tok1,"index")) ; if (!strcmp(tok1,"provide")) ; if (!strcmp(tok1,"parent")) ; if (!strcmp(tok1,"child")) ; if (!strcmp(tok1,"dimension")) ; if (!strcmp(tok1,"template")) {in_template = 1; strcpy(curstruct,tok2); n_instance = 0;} if (!strcmp(tok1,"command")) {in_template = 1; strcpy(curstruct,tok2);} if (!strcmp(tok1,"include")) { /* switch input to specified file */ /* ** Commented out, we use absolute path name in the includes. ** This allows us to go to more than one directory.. */ /* strcpy(filename,dbpath); */ /* strcat(filename,tok2); */ /* ** We now implement translation of environmental variable ** */ if (tok2[0] == '$') { tmp1 = strchr(&tok2[1], '/'); if (tmp1 == NULL) { fprintf(stderr, "DBin error, Unkonw path %s\n", tok2); return; } envName = (char *) malloc(sizeof(char) * (strlen(tok2)+1)); strcpy(envName, &tok2[1]); tmp2 = strchr(envName, '/'); *tmp2 = '\0'; env = getenv(envName); free(envName); if (env == NULL) { fprintf(stderr, "DBin error, Unkonw path %s\n", tok2); return; } strcpy(filename,env); l = strlen(env); filename[l] = '/'; l++; strcpy(&filename[l], tmp1); } else strcpy(filename, tok2); inc_depth++; } if (!strcmp(tok1,"make")) { n_instance++; strcpy(varname,"TEMPLATE_"); strcat(varname,stlower(tok2)); } if (!strcmp(tok1,"define")) { /* get first token (name) from values list */ tokn = token(&values," \t"); strcpy(varname,"TEMPLATE_"); strcat(varname,tok2); strcpy(objname,tok2); strcat(objname,"_"); strcat(objname,tokn); } if (!strcmp(tok1,"call")) { /* get first token (name) from values list */ tokn = token(&values," \t"); strcpy(varname,"COMMAND_"); strcat(varname,tok2); } if (!strncmp(tok1,"int",3) || !strcmp(tok1,"real") || !strcmp(tok1,"double") || !strncmp(tok1,"char",4) || !strcmp(tok1,"material") ) { if ((! strncmp(curstruct,"--",2)) && (in_template == 0)) { fprintf(stdout,"dbin: Parameter \"%s\" not in structure; ignored:\n", tok2); fprintf(stdout," %s\n",line); } else { /* parse values */ strcpy(varname,curstruct); strcat(varname,"."); strcat(varname,tok2); getvalues(); } } }