/* $Log: module.c,v $ * Revision 1.5 1995/03/20 14:55:27 martenl * *** empty log message *** * * Revision 1.4 1995/03/15 09:20:30 martenl * *** empty log message *** * * Revision 1.3 1995/03/11 13:53:16 martenl * fixed new state stuff for multiple modules * */ #include #include #include "libsx.h" #include "globals.h" #include "module.h" #include "kraftwerk.h" int positionFilePointer(FILE *stream, char *tag); void check(Widget w, void *d); void setModule(int id) { int i; Widget w; currentModule = 0; for(i = 0; i < numberOfModules; i++){ if(id == module[i].id) currentModule = i; } check(w, ¤tModule); state = module[currentModule].state; /* redisplay(w, hh, ww, NULL); */ } char *getNextWord(FILE *stream) { char word[100]; char dummy; fscanf(stream, "%[^;^\n]", word); fscanf(stream, "%c", &dummy); return word; } void xgetNextWord(FILE *stream, char *word) { char dummy; fscanf(stream, "%[^;^\n]", word); fscanf(stream, "%c", &dummy); } int getNextNumber(FILE *stream) { int n; char dummy; fscanf(stream, "%i ", &n); fscanf(stream, "%c ", &dummy); return n; } void printEqstruct(Data *data, int n) { int i, j, ncoeff; printf("Data for the equation\n"); printf("--------------------------------------------------\n"); for(i = 0; i < n; i++){ ncoeff = data[i].n; printf("n: %i\n", ncoeff); printf("File tag: %s\n", data[i].tag); printf("Group name: %s\n", data[i].groupName); printf("%s", "Item(s): "); for(j = 0; j < ncoeff; j++) printf("%s; ", data[i].item[j].name); printf("\n--------------------------------------------------\n"); } } void readBoundaryData(FILE *stream, int id) { int i, j; char dummy; positionFilePointer(stream, "BOUNDARY_CONDITIONS"); fscanf(stream, "%i ", &i); module[id].nbc = i; for(j = 0; j < module[id].nbc; j++){ xgetNextWord(stream, module[id].bc[j].name); xgetNextWord(stream, module[id].bc[j].format); } printf(" %i types of boundary conditions\n", module[id].nbc); positionFilePointer(stream, "BOUNDARY_TAGS"); for(j = 0; j < module[id].nbc; j++){ for(i = 0; i < module[id].nvar; i++){ fscanf(stream, "%c", &dummy); module[id].bc[j].tag[i] = dummy; fscanf(stream, "%c", &dummy); } } } void readModuleData(FILE *stream, int id) { int i; positionFilePointer(stream, "MODULE_NAME"); xgetNextWord(stream, module[id].name); /* sprintf(module[id].name, "%s", getNextWord(stream));*/ positionFilePointer(stream, "MODULE_ID"); fscanf(stream, "%i ", &i); module[id].id = i; module[id].state = HAVE_MESH; positionFilePointer(stream, "APPLICATION"); xgetNextWord(stream, module[id].application); positionFilePointer(stream, "VARIABLES"); fscanf(stream, "%i ", &i); module[id].nvar = i; for(i = 0; i < module[id].nvar; i++){ xgetNextWord(stream, module[id].variable[i].name); } printf("Loading module: %s (id = %i)\n", module[id].name, module[id].id); printf(" %i variables", module[id].nvar); for(i = 0; i < module[id].nvar; i++){ printf(", %s", module[id].variable[i].name); } printf(" \n"); printf(" application: %s\n", module[id].application); } void readProblemData(FILE *stream, Data *eqdata, int *n, int id) { int i, j, nitem; positionFilePointer(stream, "EQUATION_DATA"); fscanf(stream, "%i ", n); for(i = 0; i < *n; i++){ nitem = getNextNumber(stream); eqdata[i].n = nitem; xgetNextWord(stream, eqdata[i].tag); xgetNextWord(stream, eqdata[i].groupName); /* sprintf( eqdata[i].tag,"%s", getNextWord(stream)); sprintf( eqdata[i].groupName, "%s", getNextWord(stream)); */ /* printf("%s %s\n",eqdata[i].groupName, eqdata[i].tag); */ for( j = 0; j < nitem; j++){ xgetNextWord(stream, eqdata[i].item[j].name); /* sprintf(eqdata[i].item[j].name, "%s", getNextWord(stream));*/ xgetNextWord(stream,module[id].data[i].expr[j].text); /* printf("%s = %s\n", eqdata[i].item[j].name, module[id].data[i].expr[j].text); */ } } /* printEqstruct(eqdata, *n); */ } void xxreadProblemData(FILE *stream, Data *eqdata, int *n) { int i, j, nitem; positionFilePointer(stream, "EQUATION_DATA"); fscanf(stream, "%i ", n); for(i = 0; i < *n; i++){ nitem = getNextNumber(stream); eqdata[i].n = nitem; sprintf( eqdata[i].tag,"%s", getNextWord(stream)); sprintf( eqdata[i].groupName, "%s", getNextWord(stream)); for( j = 0; j < nitem; j++){ sprintf(eqdata[i].item[j].name, "%s", getNextWord(stream)); } } /* printEqstruct(eqdata, *n); */ } void readModules() { FILE *stream; int i, j, n; char *ptr; char file[100]; ptr = NULL; ptr = (char *) getenv("HOME"); sprintf(file, "%s/.femlab_modules", ptr); stream = fopen(file, "r"); if(stream == NULL){ ptr = (char *) getenv("FEMLAB_HOME"); if(ptr == NULL) errorHandler("FEMLAB_HOME environment variable not set"); else{ sprintf(file, "%s/config/modules", ptr); stream = fopen(file, "r"); } } if(stream != NULL){ printf("%s\n","--------------------------------------------------"); positionFilePointer(stream, "NUMBER_OF_MODULES"); fscanf(stream, "%i ", &numberOfModules); printf("Found %i module(s)\n", numberOfModules); for(i = 0; i < numberOfModules; i++){ readModuleData(stream, i); readProblemData(stream, module[i].dataGroup, &n, i); module[i].ngroups = n; readBoundaryData(stream, i); } for(j = 0; j < numberOfModules; j++){ for(i = 0; i < module[j].ngroups; i++) module[0].data[i].n = 0; } printf("%s\n","--------------------------------------------------"); } }