// ----------------------------------------------- Main -------------------------------------------- int main(int argc, char **argv){ Graph G; char filename[BUFFSIZE]; int source, destination; double elapsed_time; clock_t start, end; // Parsing arguments switch(argc){ case(4): if((sscanf(argv[2], "%d", &source) != 1) || (sscanf(argv[3], "%d", &destination) != 1)){ printf("Inputs must be integers.\n"); exit(1); } case(3): VERBOSE = 1; case(2): sscanf(argv[1], "%s", filename); break; default: printf("Wrong number of arguments.\n"); exit(1); } // Reading Graph G = readGraph(filename); // Printing graphs information printf("-------------------------------------------------------\n"); printf("There are %d nodes and %d edges!\n", G->V, G->E); printf("There are %d nodes and %d edges on the 'residual' network!\n", 2*G->V, 4*G->E + 2*G->V); printf("-------------------------------------------------------\n"); // If there is a defined pair of nodes only compute its path if(argc == 4){ if(EdmondsKarp(G, source, destination + NETSIZE)) findNodes(G, source, destination); // Else, compute all of them }else{ start = clock(); for(source = 0; source < NETSIZE; source++) for(destination = source + 1; destination < NETSIZE; destination++) if(source != destination) if(EdmondsKarp(G, source, destination + NETSIZE)) findNodes(G, source, destination); end = clock(); elapsed_time = (double)(end - start)/CLOCKS_PER_SEC; printResult(G); printf("Algorithm takes %f seconds\n", elapsed_time); printf("-------------------------------------------------------\n"); } // Free Memory allocated previously memoryCheck(G); exit(0); }
unsigned char * allocateCharVector(int n){ int i; unsigned char *vector; if((vector = (unsigned char *) calloc(n,sizeof(unsigned char)))==NULL) memoryCheck(); for (i=0;i<n;i++) vector[i]=0.0; return vector; }
long int * allocateLongVector(int n){ int i; long int *vector; if((vector = (long int *) calloc(n,sizeof(long int)))==NULL) memoryCheck(); for (i=0;i<n;i++) vector[i]=0.0; return vector; }
short int * allocateShortVector(int n){ int i; short int *vector; if((vector = (short int *) calloc(n,sizeof(short int)))==NULL) memoryCheck(); for (i=0;i<n;i++) vector[i]=0.0; return vector; }
float * allocateFloatVector(int n){ int i; float *vector; if((vector = (float *) calloc(n,sizeof(float)))==NULL) memoryCheck(); for (i=0;i<n;i++) vector[i]=0.0; return vector; }
double * allocateDoubleVector(int n){ int i; double *vector; if((vector = (double *) calloc(n,sizeof(double)))==NULL) memoryCheck(); for (i=0;i<n;i++) vector[i]=0.0; return vector; }
int Imginfo::memoryCheck(DDLSymbolTable *symtab, char *errmsg, int *mbytesShort) { int i; *mbytesShort = 0; // Amount of additional memory needed int rank; if ( ! symtab->GetValue("rank", rank) ) { sprintf(errmsg,"No \"rank\" FDF entry."); return FALSE; } int bits; if ( ! symtab->GetValue("bits", bits) ) { sprintf(errmsg,"No \"bits\" FDF entry."); return FALSE; } char *storage; if ( ! symtab->GetValue("storage", storage) ) { sprintf(errmsg,"No \"storage\" FDF entry."); return FALSE; } int side; double words = 1; for (i=0; i<rank; i++){ if ( ! symtab->GetValue("matrix", side, i) ) { sprintf(errmsg,"No \"matrix\" FDF entry for dimension %d.", i+1); return FALSE; } words *= side; } /* Do we have enough memory to read this in? */ double srcbytes = (bits / 8) * words; double totbytes = srcbytes; if (bits != 32 || (strcasecmp(storage,"float") != 0)) { /* Extra memory for dealing with data conversion */ totbytes += 2 * (srcbytes * 32 / bits); } int meg = 1 << 20; int mbytesReq = (int)((totbytes + (meg - 1) ) / meg); if (!memoryCheck(mbytesReq, errmsg, mbytesShort)){ return FALSE; } return TRUE; }
ex_immed() { int i, *ip, j; struct item *p; struct nlist *n; double f; char fname[64]; /* Array for filename */ char *cp, *vfname(); i = *pcp++; switch(i) { default: error("immed B"); case SCRIPT: if(protofile > 0) close(protofile); protofile = 0; cp = vfname(fname); if(equal(cp, "off")) return; if((protofile = open(cp, 1)) > 0){ lseek(protofile, 0L, 2); /* append to existing file */ printf("[appending]\n"); } else { /* * create new file */ protofile = opn(cp, 0644); printf("[new file]\n"); } write(protofile, "\t)script on\n", 12); return; case DEBUG: debug = ~debug; return; case MEMORY: memoryCheck(); return; case DIGITS: i = topfix(); if(i < 1 || i > 20) error("digits D"); printf("was %d\n",thread.digits); thread.digits = i; return; case TRACE: funtrace = 1; return; case UNTRACE: funtrace = 0; return; case WRITE: funwrite(0); return; case DEL: case EDITF: sp[0] = sp[-1]; /* duplicate top of stack */ sp++; funwrite(scr_file); funedit(scr_file, i); unlink(scr_file); return; case EDIT: funedit(0, i); return; case FUZZ: i = topfix(); if(i <= 0) { thread.fuzz = 0.; return; } f = i; thread.fuzz = exp(-f*2.3025851); return; case ORIGIN: printf("was %d\n",thread.iorg); thread.iorg = topfix(); return; case WIDTH: i = topfix(); if(i < 1) error("width D"); printf("was %d\n",thread.width); thread.width = i; return; case READ: funread(0); return; case ERASE: p = sp[-1]; sp--; erase(p); return; case CONTIN: i = opn("continue", 0644); wssave(i, 0); printf(" continue"); case OFF: term(0); case VARS: for(n=nlist; n->namep; n++) { if(n->itemp && n->use == DA && n->namep[0] != 'L') { if(column+8 >= thread.width) printf("\n\t"); printf(n->namep); putchar('\t'); } } putchar('\n'); return; case FNS: for(n=nlist; n->namep; n++) { if(n->use == DF || n->use == MF || n->use == NF) { if(column+8 >= thread.width) printf("\n\t"); printf(n->namep); putchar('\t'); } } putchar('\n'); return; case CODE: n = (struct nlist *)sp[-1]; sp--; switch(n->use){ default: error("not a fn"); case NF: case MF: case DF: if(n->itemp == 0) funcomp(n); ip = (int *)n->itemp; for(i=0; i <= *ip; i++){ printf(" [%d] ", i); dump(ip[i+1], 0); } putchar('\n'); } return; case RESET: while(gsip) ex_ibr0(); longjmp(reset_env, 0); case SICOM: tback(1); return; case CLEAR: clear(); printf("clear ws\n"); goto warp1; /* four lines down, or so... */ case LOAD: case PLOAD: j = opn(vfname(fname), 0); clear(); if (i == LOAD) wsload(j, 0); if (i == PLOAD) wsload(j, 1); printf(" %s\n", fname); evLlx(); /* possible latent expr evaluation */ warp1: /* * this garbage is necessary because clear() * does a brk(&end), and the normal return & cleanup * procedures are guaranteed to fail (miserably). * --jjb 1/78 */ sp = stack; longjmp(reset_env, 0); case LIB: listdir(); return; case COPY: if(gsip) error("si damage -- type ')reset'"); wsload(opn(vfname(fname),0), 0); printf(" copy %s\n", fname); return; case DROPC: cp = vfname(fname); if(unlink(cp) == -1) printf("[can't remove %s]\n", cp); return; case SAVE: case PSAVE: j = opn(vfname(fname), 0644); if (i == SAVE) wssave(j, 0); if (i == PSAVE) wssave(j, 1); printf(" saved %s\n", fname); return; case VSAVE: i = opn(vfname(fname), 0644); vsave(i); putchar('\n'); return; case SHELL: ex_shell(); return; case LIST: ex_list(); return; case PRWS: ex_prws(); return; } }
Imginfo* Imginfo::ddldata_load(char *filename, char *errmsg, DDLSymbolTable *ddlst) { if (ddlst){ st = ddlst; }else{ /* Create a DDL symbol table and parse the input file */ st = ParseDDLFile(filename);// Get header int mbytes; if (!memoryCheck(st, errmsg, &mbytes)){ return NULL; } if (!st->MallocData()){ // Get data msgerr_print("Cannot read data from %s.", filename); delete st; return NULL; } } if (filename){ st->SetValue("dirpath", "/"); st->SetValue("filename", filename); } /*st->PrintSymbols();/*CMP*/ int rank = 1; if ( ! st->GetValue("rank", rank) ) { sprintf(errmsg,"No \"rank\" FDF entry."); return NULL; } char *spatial_rank; if ( ! st->GetValue("spatial_rank", spatial_rank)){ if (st->GetValue("subrank", spatial_rank)){ st->SetValue("spatial_rank", spatial_rank); }else{ sprintf(errmsg,"No \"spatial_rank\" entry."); return NULL; } } int bits=0; st->GetValue("bits", bits); int pixelmax = G_Get_Sizecms2(Gframe::gdev); vs = 4200.0 * pixelmax / 127; // Default vscale value char* storage = ""; st->GetValue("storage", storage); if ((strcmp(storage, "float") == 0) && (bits == 32)) { type = TYPE_FLOAT; } else { if (bits < 8) { sprintf(errmsg,"Invalid \"bits\" field."); return NULL; } int datasize = st->DataLength() / (bits/8); float* dataptr = new float[datasize]; if (dataptr == 0) { sprintf(errmsg,"Unable to allocate memory."); return NULL; } if (strcmp(storage, "float") == 0) { if (bits == 64) { convertdata( (double *)st->GetData(), dataptr, datasize); } else { sprintf(errmsg,"Unsupported bits/storage parameters."); return NULL; } } else if (strcmp(storage, "char") == 0) { if (bits == 8) { vs = pixelmax / CHAR_MAX; convertdata( (unsigned char *)st->GetData(), dataptr, datasize); } else { sprintf(errmsg,"Unsupported bits/storage parameters."); return NULL; } } else if (strcmp(storage, "short") == 0) { if (bits == 16) { vs = pixelmax / SHORT_MAX; convertdata((unsigned short *)st->GetData(),dataptr,datasize); } else { sprintf(errmsg,"Unsupported bits/storage parameters."); return NULL; } } else if (strcmp(storage, "int") == 0) { if (bits == 8) { vs = pixelmax / CHAR_MAX; convertdata( (unsigned char *)st->GetData(),dataptr,datasize); } else if (bits == 16) { vs = pixelmax / SHORT_MAX; convertdata((unsigned short *)st->GetData(),dataptr,datasize); } else if (bits == 32) { vs = pixelmax / INT_MAX; convertdata( (int *)st->GetData(), dataptr, datasize); }else { sprintf(errmsg,"Unsupported bits/storage parameters."); return NULL; } } else if (strcmp(storage, "integer") == 0) { if (bits == 8) { vs = (float)pixelmax / CHAR_MAX; convertdata((unsigned char *)st->GetData(),dataptr,datasize); } else if (bits == 16) { vs = (float)pixelmax / SHORT_MAX; convertdata((unsigned short *)st->GetData(),dataptr,datasize); } else if (bits == 32) { vs = (float)pixelmax / INT_MAX; convertdata( (int *)st->GetData(), dataptr, datasize); }else { sprintf(errmsg,"Unsupported bits/storage parameters."); return NULL; } } else { sprintf(errmsg,"Unsupported bits/storage parameters."); return NULL; } type = TYPE_FLOAT; st->SetData( (char *)dataptr, datasize*(sizeof(float))); st->SetValue("bits", 32); st->SetValue("storage", "float"); delete [] dataptr; } AutoVscale();/*CMP*/ double vscale; // Not currently used st->GetValue("vs", vscale); //cout << "vs = " << vscale << endl; return this; }