int readParameters( char* file, PARMOPTS* opts ) { FILE* f; char line[100]; char* parm; char* value; f = fopen( file, "rt" ); if( !f ) { return 0; } opts->seed = time(NULL); while( fgets( line, sizeof( line ), f ) != NULL ) { parm = getParm( line, &value ); if( parm == 0 ) { continue; } if( strcmp( parm, "x" ) == 0 ) { opts->width = atoi( value ); } else if( strcmp( parm, "y" ) == 0 ) { opts->height = atoi( value ); } else if( strcmp( parm, "z" ) == 0 ) { opts->depth = atoi( value ); } else if( strcmp( parm, "sparse" ) == 0 ) { opts->sparseness = atoi( value ); } else if( strcmp( parm, "deadends" ) == 0 ) { opts->deadends = atoi( value ); } else if( strcmp( parm, "randomness" ) == 0 ) { opts->randomness = atoi( value ); } else if( strcmp( parm, "startx" ) == 0 ) { opts->startx = atoi( value ); } else if( strcmp( parm, "starty" ) == 0 ) { opts->starty = atoi( value ); } else if( strcmp( parm, "startz" ) == 0 ) { opts->startz = atoi( value ); } else if( strcmp( parm, "endx" ) == 0 ) { opts->endx = atoi( value ); } else if( strcmp( parm, "endy" ) == 0 ) { opts->endy = atoi( value ); } else if( strcmp( parm, "endz" ) == 0 ) { opts->endz = atoi( value ); } else if( strcmp( parm, "mask" ) == 0 ) { strcpy( opts->maskFile, value ); } else if( strcmp( parm, "seed" ) == 0 ) { opts->seed = atol( value ); } else if( strcmp( parm, "border" ) == 0 ) { opts->ofs = atoi( value ); } else if( strcmp( parm, "wall" ) == 0 ) { opts->wallWid = atoi( value ); } else if( strcmp( parm, "path" ) == 0 ) { opts->pathWid = atoi( value ); } else if( strcmp( parm, "bgclr" ) == 0 ) { opts->bgColor = makeColor( value ); } else if( strcmp( parm, "wallclr" ) == 0 ) { opts->wallClr = makeColor( value ); } else if( strcmp( parm, "pathclr" ) == 0 ) { opts->pathClr = makeColor( value ); } else if( strcmp( parm, "boundclr" ) == 0 ) { opts->boundClr = makeColor( value ); } else if( strcmp( parm, "startclr" ) == 0 ) { opts->startClr = makeColor( value ); } else if( strcmp( parm, "endclr" ) == 0 ) { opts->endClr = makeColor( value ); } else if( strcmp( parm, "solution" ) == 0 ) { opts->showSolution = ( atoi( value ) != 0 ); } else if( strcmp( parm, "markers" ) == 0 ) { opts->showMarkers = ( atoi( value ) != 0 ); } else if( strcmp( parm, "include" ) == 0 ) { readParameters( value, opts ); } } return 1; }
int pipeRead(int argc, char *argv[], int retc, char *retv[]) /****************************/ { char path[MAXPATH]; int elem; float fdata[FDATASIZE]; int fd; int dimCount; int num; int xSize, ySize; int xFtSize, xCenter; int xDomain, yDomain, zDomain, aDomain; int xMode, yMode; int blockStat; int blocks2D, traces2D, np2D; int block2D; int totSize; int zeroTraces; int firstTrace; int r; float *ptr; float *start; float *dptr; float multRe, multIm; if (argc<2) { Werrprintf("usage - %s('filename'<,index>)",argv[0]); ABORT; } jeolFlag = (strcmp(argv[0],"jread")) ? 0 : 1; Wturnoff_buttons(); D_allrelease(); if (argv[1][0] == '/') strcpy(path,argv[1]); else sprintf(path,"%s/%s",curexpdir,argv[1]); elem = 1; if (jeolFlag) { multRe = multIm = 100.0; } else { multRe = multIm = FTNORM; } if (argc >= 3) { if (isReal(argv[2])) { elem = atoi(argv[2]); if (elem < 1) elem = 1; } else if ( ! strcmp(argv[2],"rev") ) { multIm = -multRe; } if (argc >= 4) { if (isReal(argv[3])) { elem = atoi(argv[3]); if (elem < 1) elem = 1; } else if ( ! strcmp(argv[3],"rev") ) { multIm = -multRe; } } } if ( access(path,R_OK) ) { Werrprintf("%s: cannot access %s",argv[0],path); ABORT; } if ( (fd = open(path,O_RDONLY)) < 0) { Werrprintf("%s: unable to open %s",argv[0],path); ABORT; } if ( read(fd, fdata, sizeof(float)*FDATASIZE) != sizeof(float)*FDATASIZE) { Werrprintf("%s: unable to read %s",argv[0],path); close(fd); ABORT; } /* 1D Data */ if ( (dimCount = (int) getParm( fdata, FDDIMCOUNT, 0 )) == 1) { int realOnly; realOnly = getParm( fdata, FDQUADFLAG, 0 ); xSize = (int) getParm( fdata, NDSIZE, CUR_XDIM ); if ( (r = checkFnSize(xSize, "1D")) ) { close(fd); ABORT; } if ( ! realOnly ) /* Complex counts complex pairs */ xSize *= 2; if (jeolFlag) { if ( (elem == 1) && setFidFile1D(xSize)) { close(fd); ABORT; } if ( (elem != 1) && getFidFile1D(xSize,elem)) { close(fd); ABORT; } } else { if ( (argc != 3) && setDataFile1D(xSize,realOnly)) { close(fd); ABORT; } if ( (argc == 3) && getDataFile1D(xSize,realOnly,elem)) { close(fd); ABORT; } } start = (float *) mmap(0,sizeof(float) * (xSize+FDATASIZE), PROT_READ, MAP_PRIVATE, fd, 0); ptr = start + FDATASIZE; dptr = data; if (realOnly) { num = xSize; while ( num-- ) { *dptr++ = *ptr++ * multRe; } } else { num = xSize / 2; while ( num-- ) { *dptr++ = *ptr * multRe; *dptr++ = *(ptr+xSize/2) * multIm; ptr++; } } munmap(start, sizeof(float) * (xSize+FDATASIZE) ); close(fd); if (jeolFlag) { if ( (r=D_markupdated(D_USERFILE,elem-1)) ) { D_error(r); ABORT; } if ( (r=D_flush(D_USERFILE)) ) { D_error(r); ABORT; } if ( (r=D_release(D_USERFILE,elem-1)) ) { D_error(r); ABORT; } D_close(D_USERFILE); Wsetgraphicsdisplay(""); /* activate the ds program */ } else { if ( (r=D_markupdated(D_DATAFILE,elem-1)) ) { D_error(r); ABORT; } if ( (r=D_release(D_DATAFILE,elem-1)) ) { D_error(r); ABORT; } if (!Bnmr) { releasevarlist(); appendvarlist("cr"); Wsetgraphicsdisplay("ds"); /* activate the ds program */ start_from_ft = 1; } } RETURN; } /* 2D data */ xDomain = (int) getParm( fdata, NDFTFLAG, CUR_XDIM ); yDomain = (int) getParm( fdata, NDFTFLAG, CUR_YDIM ); zDomain = (int) getParm( fdata, NDFTFLAG, CUR_ZDIM ); aDomain = (int) getParm( fdata, NDFTFLAG, CUR_ADIM ); #ifdef XXX /* For 4D testing only */ if ( strstr(path,".ft4") ) { aDomain=1; } #endif /* zDomain is the 3D flag; aDomain is 4D flag */ if ( (dimCount < 1) || (xDomain + yDomain != 2) ) { Winfoprintf("%s: file %s not 1D nor 2D data",argv[0], path); close(fd); RETURN; } xMode = (int) getParm( fdata, NDQUADFLAG, CUR_XDIM ); yMode = (int) getParm( fdata, NDQUADFLAG, CUR_YDIM ); xSize = (int) getParm( fdata, NDSIZE, CUR_XDIM ); ySize = (int) getParm( fdata, NDSIZE, CUR_YDIM ); xFtSize = (int) getParm( fdata, NDFTSIZE, CUR_XDIM ); xCenter = (int) getParm( fdata, NDCENTER, CUR_XDIM ); zeroTraces = 0; if (xSize != xFtSize) { zeroTraces = xFtSize/2 - xCenter + 1; } if ( (r = checkFnSize(xFtSize, "2D x")) ) { close(fd); ABORT; } if ( (r = checkFnSize(ySize, "2D y")) ) { close(fd); ABORT; } blocks2D = 0; totSize = 0; if (xMode && yMode) /* Real Real */ { if ( setDataFile2D3D(xFtSize, xMode, ySize, yMode, &blockStat, &blocks2D, &traces2D, &np2D, zDomain, aDomain) ) { close(fd); ABORT; } /* Winfoprintf("%s: Real Real 2D data from %s",argv[0], path); Winfoprintf("%s: blocks= %d traces= %d np= %d",argv[0], blocks2D, traces2D, np2D); */ totSize = traces2D * np2D; totSize = xSize * ySize; } else { Werrprintf("%s: Only Real Real 2D data is currently handled",argv[0]); close(fd); ABORT; } start = (float *) mmap(0,sizeof(float) * (totSize+FDATASIZE), PROT_READ, MAP_PRIVATE, fd, 0); ptr = start + FDATASIZE; close(fd); firstTrace = 0; for (block2D=0; block2D < blocks2D; block2D++) { int tracesPerBlk = traces2D / blocks2D; int trace = 0; int tracesDone = 0; int pt; if (getBuffer2D(block2D, blockStat)) { munmap(start, sizeof(float) * (totSize+FDATASIZE) ); ABORT; } dptr = data; if (zeroTraces) { tracesDone = (zeroTraces < tracesPerBlk) ? zeroTraces : tracesPerBlk; for (trace = 0; trace < tracesDone; trace++) { for (pt=0; pt < np2D; pt++) *dptr++ = 0.0; } zeroTraces -= tracesDone; } if ( !zeroTraces && (tracesDone < tracesPerBlk) ) { while ( (firstTrace < xSize) && (tracesDone < tracesPerBlk) ) { int toffset = firstTrace + (tracesPerBlk * block2D); for (pt=0; pt < np2D; pt++) *dptr++ = *(ptr + toffset + pt*xSize) * multRe; firstTrace++; tracesDone++; } while (tracesDone < tracesPerBlk) { for (pt=0; pt < np2D; pt++) *dptr++ = 0.0; tracesDone++; } } if ( (r=D_markupdated(D_DATAFILE,block2D)) ) { D_error(r); munmap(start, sizeof(float) * (totSize+FDATASIZE) ); ABORT; } if ( (r=D_release(D_DATAFILE,block2D)) ) { D_error(r); munmap(start, sizeof(float) * (totSize+FDATASIZE) ); ABORT; } } munmap(start, sizeof(float) * (totSize+FDATASIZE) ); RETURN; }