static int freebuffers() /****************/ { int res; if(c_buffer>=0) /* release last used block */ if ( (res=D_release(D_PHASFILE,c_buffer)) ) { D_error(res); D_close(D_PHASFILE); return(ERROR); } return(COMPLETE); }
/*------------------------------- | | | rel_spec()/0 | | | +------------------------------*/ int rel_spec() { int res; if(c_buffer>=0) /* release last used block */ if ( (res=D_release(D_PHASFILE,c_buffer)) ) { D_error(res); D_close(D_PHASFILE); ABORT; } RETURN; }
/*--------------------------------------- | | | df2d() | | | | This function displays a 2D FID | | data set. | | | +--------------------------------------*/ int df2d(int argc, char *argv[], int retc, char *retv[]) { ftparInfo ftpar; dfilehead fidhead, datahead, phasehead; (void) retc; (void) retv; if ( i_ft(argc, argv, (S_DATA|S_FLOAT), 0, 1, &ftpar, &fidhead, &datahead, &phasehead) ) { ABORT; } acqflag = FALSE; ftpar.zeroflag = FALSE; if (ftpar.combineflag) { Werrprintf("%s(...) cannot combine fid's: too many arguments", argv[0]); ABORT; } if (convertfids(&ftpar, &fidhead)) { disp_index(0); ABORT; } D_close(D_USERFILE); disp_index(0); if (!Bnmr) { releasevarlist(); appendvarlist("dconi"); Wsetgraphicsdisplay("dconi"); /* activate the dconi program */ } RETURN; }
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; }
void draw_histogram(const char *map_name, int x0, int y0, int width, int height, int color, int flip, int horiz, int map_type, int is_fp, struct FPRange render_range) { int i, nsteps, ystep; long cell_count = 0; double max_width, width_mult, dx; double dy, y0_adjust; /* only needed for CELL maps */ struct stat_list dist_stats; struct stat_node *ptr; struct Range range; struct FPRange fprange; CELL c_map_min, c_map_max; DCELL d_map_min, d_map_max; double map_min, map_max, map_range, user_range; double crop_min_perc = 0.0, crop_max_perc = 1.0, pad_min_perc = 0.0; if (horiz) { max_width = height * 1.75; nsteps = width - 3; } else { max_width = width * 1.75; nsteps = height - 3; } if (render_range.first_time) { /* user specified range, can be either larger or smaller than actual map's range */ if (is_fp) { Rast_read_fp_range(map_name, "", &fprange); Rast_get_fp_range_min_max(&fprange, &d_map_min, &d_map_max); map_min = (double)d_map_min; map_max = (double)d_map_max; } else { Rast_read_range(map_name, "", &range); Rast_get_range_min_max(&range, &c_map_min, &c_map_max); map_min = (double)c_map_min; map_max = (double)c_map_max; } map_range = map_max - map_min; user_range = render_range.max - render_range.min; if (horiz) nsteps = (int)(0.5 + (map_range * (width - 3) / user_range)); else nsteps = (int)(0.5 + (map_range * (height - 3) / user_range)); G_debug(1, "number of steps for r.stats = %d, height-3=%d width-3=%d", nsteps, height - 3, width - 3); /* need to know the % of the MAP range where user range starts and stops. * note that MAP range can be fully inside user range, in which case * keep 0-100% aka 0,nsteps, i.e. the step number in the nsteps range */ if (render_range.min > map_min) { crop_min_perc = (render_range.min - map_min) / map_range; G_debug(3, "min: %.02f vs. %.02f (%.02f) ... %.02f%%", render_range.min, map_min, map_range, 100 * crop_min_perc); } if (render_range.max > map_max) { crop_max_perc = 1.0 - ((render_range.max - map_max) / user_range); G_debug(3, "max: %.02f vs. %.02f (%.02f) ... %.02f%%", map_max, render_range.max, map_range, 100 * crop_max_perc); } if (render_range.min < map_min) { pad_min_perc = (map_min - render_range.min) / user_range; G_debug(3, "Min: %.02f vs. %.02f (%.02f) ... %.02f%%", map_min, render_range.min, user_range, 100 * pad_min_perc); } #ifdef amplify_gain /* proportion of nsteps to width, use as mult factor to boost the 1.75x when spread out over more nsteps than we are displaying */ G_debug(0, "max_width was: %.2f (nsteps=%d)", max_width, nsteps); if (nsteps > ((horiz ? width : height) - 3.0)) max_width *= nsteps / ((horiz ? width : height) - 3.0); G_debug(0, "max_width now: %.2f", max_width); #endif } /* TODO */ if (!is_fp && render_range.first_time) { G_warning(_("Histogram constrained by range not yet implemented for " "categorical rasters")); return; } /* get the distribution statistics */ get_stats(map_name, &dist_stats, nsteps, map_type); width_mult = max_width / dist_stats.maxstat; D_use_color(color); D_begin(); ptr = dist_stats.ptr; if (!is_fp) { dy = (nsteps + 3.0) / (1 + dist_stats.maxcat - dist_stats.mincat); if (flip) dy *= -1; if (dist_stats.mincat == 0) y0_adjust = dy; else y0_adjust = 0; if (!flip) /* mmph */ y0_adjust += 0.5; } G_debug(3, "mincat=%ld maxcat=%ld", dist_stats.mincat, dist_stats.maxcat); for (i = dist_stats.mincat, ystep = 0; i <= dist_stats.maxcat; i++) { if (!ptr) break; /* jump out if user range cuts things shorter than the map's native range */ if ((horiz && ystep > width - 4) || (!horiz && ystep > height - 4)) break; /* jump out if user range goes beyond max of map data */ if (((double)ystep / ((horiz ? width : height) - 3.0)) > crop_max_perc) break; /* TODO if (!is_fp && i > render_range.max) break; */ /* haven't made it to the min of the user range yet */ if (((double)i / nsteps) < crop_min_perc) { continue; } /* now it's ok advance the plotter position */ ystep++; /* if user range is below the minimum real map value, we need to pad out the space */ if (render_range.first_time && render_range.min < map_min) { if ( ((double)ystep / ((horiz ? width : height) - 3.0)) < pad_min_perc) { i--; continue; } } if (ptr->cat == i) { /* AH-HA!! found the stat */ cell_count = ptr->stat; if (ptr->next != NULL) ptr = ptr->next; } else { /* we have to look for the stat */ /* loop until we find it, or pass where it should be */ while (ptr->cat < i && ptr->next != NULL) ptr = ptr->next; if (ptr->cat == i) { /* AH-HA!! found the stat */ cell_count = ptr->stat; if (ptr->next != NULL) ptr = ptr->next; } else /* stat cannot be found */ G_debug(5, "No matching stat found, i=%d", i); } G_debug(5, "i=%d ptr->cat=%ld cell_count=%ld", i, ptr->cat, cell_count); if (!cell_count) continue; dx = cell_count * width_mult; if (is_fp) { if (horiz) { if (flip) D_move_abs(x0 + width - ystep - 1, y0 - 1); else D_move_abs(x0 + ystep + 1, y0 - 1); D_cont_rel(0, -dx); } else { /* vertical */ if (flip) D_move_abs(x0 - 1, y0 - 1 + height - ystep); else D_move_abs(x0 - 1, y0 + 1 + ystep); D_cont_rel(-dx, 0); } } else { /* categorical */ if (horiz) { if (flip) D_box_abs(x0 + width + y0_adjust + ((i - 1) * dy), y0 - 1, x0 + width + y0_adjust + 1 + (i * dy), y0 - 1 - dx); else D_box_abs(x0 + y0_adjust + ((i - 1) * dy), y0 - 1, x0 - 1 + y0_adjust + (i * dy), y0 - 1 - dx); } else { /* vertical */ if (flip) /* GRASS_EPSILON fudge around D_box_abs() weirdness + PNG driver */ D_box_abs(x0 - 1 - GRASS_EPSILON * 10, y0 + height + y0_adjust + ((i - 1) * dy), x0 - 1 - dx, y0 + height + y0_adjust + 1 + (i * dy)); else D_box_abs(x0 - 1 - GRASS_EPSILON * 10, y0 + y0_adjust + ((i - 1) * dy), x0 - 1 - dx, y0 + y0_adjust - 1 + (i * dy)); } } } D_close(); D_end(); D_stroke(); }
/*----------------------------------------------- | | | checkblock()/3 | | | | This function checks the current phase | | file block to see it the data in that | | block must be re-calculated. | | | +----------------------------------------------*/ static int checkblock(int trace, int *ok, int file_id) { int block, block1, r, found, phasefile_mode, quad2=0, quad4=0; int mask; *ok = TRUE; /* initialize the OK flag */ /******************************************* * If the requested trace does not lie in * * the currently active phasefile block, * * get a new phasefile block. * *******************************************/ if ((trace > c_last) || (trace < c_first)) { block1 = block = trace/specperblock; if ((d2flag) && (!revflag)) block1 += nblocks; if (block != c_buffer) { /* must get access to proper data block */ if (c_buffer >= 0) /* release last used block */ { if ( (r = D_release(file_id, c_buffer)) ) { D_error(r); D_close(file_id); return(ERROR); } } if ( (r = D_getbuf(file_id, nblocks, block1, &c_block)) ) { if ( (r = D_allocbuf(file_id, block1, &c_block)) ) { D_error(r); return(ERROR); } c_block.head->status = 0; c_block.head->mode = 0; } c_buffer = block1; c_first = block * specperblock; c_last = c_first + specperblock - 1; } } /* COMMENTED OUT else { */ /******************************************* * If the requested trace does lie in the * * currently active phasefile block, it * * should be okay. NOTE: This has been * * made to be so for 1D data which has * * been interactively phased with the * * mouse. It does not work yet, however! * *******************************************/ /* COMMENTED OUT return(COMPLETE); } */ /************************************************* * Check to see if any data are already present * * in the currently active phasefile block. * *************************************************/ if ((~c_block.head->status) & S_DATA) { *ok = FALSE; } else if(checkS_BCbit(D_PHASFILE)) { *ok = TRUE; } /****************** * Generic tests * ******************/ else { /******************************************* * Determine "display mode" bit field for * * the requested display. * *******************************************/ phasefile_mode = get_mode(HORIZ); mask = 0xfff; if (d2flag) { quad2 = FALSE; quad4 = (datahead.status & S_HYPERCOMPLEX); if (!quad4) quad2 = (datahead.status & S_COMPLEX); phasefile_mode |= get_mode(VERT); } /********************************************** * Compare the bit field for the requested * * "display mode" with that currently stored * * in the phasefile block header. * **********************************************/ if ( (c_block.head->mode&mask) != phasefile_mode ) { *ok = FALSE; } else if ( d2flag && (quad4 || quad2) ) { int direction; double rp_val,lp_val; /************************************************** * If the 2D data are to be phased along either * * F1 or F2, switch certain parameters depending * * on "revflag." * **************************************************/ direction = get_direction(REVDIR); if ( (get_phase_mode(direction) || get_phaseangle_mode(direction)) && get_axis_freq(direction) ) { get_phase_pars(direction,&rp_val,&lp_val); *ok = nochange_in_phase(c_block.head->rpval, (float)rp_val, c_block.head->lpval, (float)lp_val ); } direction = get_direction(NORMDIR); if ( quad4 && (*ok) && (get_phase_mode(direction) || get_phaseangle_mode(direction)) && get_axis_freq(direction) ) { hycmplxhead *tmpblkhead; tmpblkhead = (hycmplxhead *) (c_block.head); found = FALSE; while (!found) { if ((~tmpblkhead->status) & MORE_BLOCKS) return(COMPLETE); tmpblkhead += 1; found = (tmpblkhead->status & U_HYPERCOMPLEX); } get_phase_pars(direction,&rp_val,&lp_val); *ok = nochange_in_phase(tmpblkhead->rpval1, (float)rp_val, tmpblkhead->lpval1, (float)lp_val); } } else if (!d2flag && (get_phase_mode(HORIZ) || get_phaseangle_mode(HORIZ))) { if(bph()>0) { *ok = FALSE; } else { *ok = nochange_in_phase(c_block.head->rpval, (float)rp, c_block.head->lpval, (float)lp); } } } return(COMPLETE); }
/*----------------------------------------------- | | | lpcmd() | | | | This function performs 1D LP on a single | | or arrayed FID data set. A new fid file | | is write to argv[1] or curexpdir/lp.fid | | if not specified. | | | +----------------------------------------------*/ int lpcmd(int argc, char *argv[], int retc, char *retv[]) { char filepath[MAXPATHL]; int status, res, cblock, lastcblock, blocksdone, lsfidx, fidnum = 0, arg_no, npx, npadj, ftflag, noreal, element_no, lastfid, first, last, step, i, ctcount, realt2data; float *outp; dpointers inblock; dpointers outblock; dfilehead fidhead, datahead, phasehead; lpstruct parLPinfo; ftparInfo ftpar; char newfidpath[MAXPATHL]; Wturnoff_buttons(); ftpar.procstatus = (CMPLX_t2|LP_F2PROC); /************************************ * Initialize all parameterizeable * * variables * ************************************/ arg_no = first = step = element_no = 1; ftpar.nblocks = MAXINT; last = MAXINT; noreal = ftflag = TRUE; ftpar.t2dc = -1; ftpar.zeroflag = FALSE; ftpar.sspar.lfsflag = ftpar.sspar.zfsflag = FALSE; ftpar.dspar.dsflag = FALSE; ftpar.dspar.fileflag = FALSE; ftpar.dspar.newpath[0] = '\0'; ftpar.ftarg.useFtargs = 0; // default newfidpath sprintf(newfidpath,"%s/lp.fid",curexpdir); /********************************* * Parse STRING arguments first * *********************************/ while ( (argc > arg_no) && (noreal = !isReal(argv[arg_no])) ) { if(strcmp(argv[arg_no],"rlp") == 0) { // e.g., lp('/tmp/lp.fid') ftpar.procstatus = (REAL_t2|LP_F2PROC); } else if(argv[arg_no][0] == '/') { // e.g., lp('/tmp/lp.fid') strcpy(newfidpath,argv[arg_no]); } else { sprintf(newfidpath,"%s/%s",curexpdir,argv[arg_no]); } arg_no++; } if(strcmp(newfidpath+strlen(newfidpath)-4,".fid") != 0 && strcmp(newfidpath+strlen(newfidpath)-5,".fid/") != 0) strcat(newfidpath,".fid"); /****************************** * Initialize data files and * * FT parameters. * ******************************/ if ( i_ft(argc, argv, (S_DATA | S_FLOAT), 0, 0, &ftpar, &fidhead, &datahead, &phasehead) ) { disp_status(" "); ABORT; } if ( (res = D_getbuf(D_USERFILE, fidhead.nblocks, 0, &inblock)) ) { ctcount=1; } else ctcount = inblock.head->ctcount; if(ctcount<1) ctcount=1; if (ftpar.t2dc == -1) { ftpar.t2dc = (fidhead.status & S_DDR) ? FALSE : TRUE; } disp_current_seq(); ftpar.cf = first; specIndex = first; /* tells interactive programs that new data exist */ /*************************************************** * np0 = total number of points in the fid * * npx = used number of points in the fid * * * * Adjust "npx" and "lsfidx". * ***************************************************/ lsfidx = ftpar.lsfid0; npx = ftpar.np0; npadj = npx - lsfidx; /* adjusted number of FID data points */ if (lsfidx < 0) { if (npx < 2) { Werrprintf("lsfid is too large in magnitude"); ABORT; } } else { if (lsfidx >= npx) { Werrprintf("lsfid is too large in magnitude"); ABORT; } } realt2data = (ftpar.procstatus & REAL_t2); fpointmult = getfpmult(S_NP, fidhead.status & S_DDR); // note, limit for forward LP is npadj (5th arg) if ( setlppar(&parLPinfo, S_NP, ftpar.procstatus, npadj/2, MAXINT, LPALLOC, "ft2d") ) { disp_status(" "); releaseAllWithId("ft2d"); Wsetgraphicsdisplay(""); /* TRY THIS! SF */ ABORT; } if (parLPinfo.sizeLP) { int maxlpnp, nptmp; if (realt2data) { Werrprintf("LP analysis is not supported for real t2 data"); releaseAllWithId("ft2d"); disp_status(" "); ABORT; } maxlpnp = npadj; for (i = 0; i < parLPinfo.sizeLP; i++) { lpparams = *(parLPinfo.parLP + i); if (lpparams.status & FORWARD) { nptmp = 2*(lpparams.startextpt + lpparams.ncextpt - 1); if (nptmp > maxlpnp) maxlpnp = nptmp; } } npadj = maxlpnp; } /************************** * Start loop over FIDs. * **************************/ lastfid = ftpar.ni0 * ftpar.ni1 * ftpar.arraydim; if (lastfid > ftpar.nblocks) lastfid = ftpar.nblocks; if (first > lastfid) { last = lastfid; } D_trash(D_DATAFILE); if(access(newfidpath,F_OK) != 0) { if(mkdir(newfidpath,0777)) { Winfoprintf("cannot create %s",newfidpath); ABORT; } } status = (S_DATA | S_FLOAT | S_COMPLEX | ftpar.D_cmplx); // now write out fid to newfidpath strcpy(filepath,newfidpath); strcat(filepath,"/fid"); datahead.status = fidhead.status; datahead.vers_id = fidhead.vers_id; datahead.nbheaders = fidhead.nbheaders; datahead.nblocks = fidhead.nblocks; datahead.ntraces = 1; datahead.np = npadj; datahead.ebytes = fidhead.ebytes; datahead.tbytes = npadj*fidhead.ebytes; datahead.bbytes = datahead.tbytes + sizeof(dblockhead);; if (D_newhead(D_DATAFILE, filepath, &datahead) ) { Werrprintf("cannot open file %s", filepath); ABORT; } /*********************************************** * Necessary until I can devise a function to * * read only the FID block header in order to * * determine if FID data exists in that block. * ***********************************************/ blocksdone = FALSE; lastcblock = ftpar.nblocks; cblock = 0; while ((cblock < lastcblock) && (!blocksdone)) { DPRINT1("block %d\n", cblock); if ( (res = D_allocbuf(D_DATAFILE, cblock, &outblock)) ) { D_error(res); releaseAllWithId("ft2d"); disp_status(" "); ABORT; } outblock.head->ctcount = ctcount; /* default setting */ outblock.head->scale = 0; /* default setting */ outp = (float *)outblock.data; /********************************************************** * Start filling at the start of the output data buffer. * * This facilitates the automatic array-like processing * * of 'cf' and 'nf' in 1D. * **********************************************************/ fidnum = cblock; if (interuption) { releaseAllWithId("ft2d"); D_trash(D_PHASFILE); D_trash(D_DATAFILE); disp_status(" "); ABORT; } if ((cblock + 1) == first) { if ( ! ((cblock+1) & 15) ) disp_index(cblock + 1); if ( getfid(fidnum, outp, &ftpar, &fidhead, &lastfid) ) { Werrprintf("Unable to get FID data"); releaseAllWithId("ft2d"); disp_index(0); disp_status(" "); ABORT; } if (lastfid == 0) { releaseAllWithId("ft2d"); disp_index(0); disp_status(" "); ABORT; } else if (cblock == lastfid) { status = 0; blocksdone = TRUE; if (last == MAXINT) { last = cblock; } } else { if (parLPinfo.sizeLP) { for (i = 0; i < parLPinfo.sizeLP; i++) { lpparams = *(parLPinfo.parLP + i); disp_status(lpparams.label); if (lpz(fidnum, outp, (npx - lsfidx)/2, lpparams)) { Werrprintf("LP analysis failed"); releaseAllWithId("ft2d"); disp_index(0); disp_status(" "); ABORT; } } } if (fpointmult != 1.0) { *outp *= fpointmult; *(outp + 1) *= fpointmult; } //zerofill(outp + npadj, ftpar.fn0 - npadj); last = cblock + 1; } // multiply outp by ctcount outp = (float *)outblock.data; outp += npadj; for(i = 0; i < npadj; i++) *(--outp) *= ctcount; setheader(&outblock, status, 0, cblock+1, ftpar.hypercomplex); first += step; } else { setheader(&outblock, 0, 0, cblock, ftpar.hypercomplex); } if ( (res = D_markupdated(D_DATAFILE, cblock)) ) { D_error(res); releaseAllWithId("ft2d"); disp_index(0); disp_status(" "); ABORT; } if ( (res = D_release(D_DATAFILE, cblock)) ) { D_error(res); releaseAllWithId("ft2d"); disp_index(0); disp_status(" "); ABORT; } cblock++; if (!blocksdone) blocksdone = (first > lastcblock); } if ( (last != ftpar.nblocks) && (last != MAXINT) ) { if ( (res = D_gethead(D_DATAFILE, &datahead)) ) { D_error(res); disp_index(0); disp_status(" "); ABORT; } datahead.nblocks = last; if ( (res = D_updatehead(D_DATAFILE, &datahead)) ) { D_error(res); disp_index(0); disp_status(" "); ABORT; } } releasevarlist(); releaseAllWithId("ft2d"); disp_index(0); disp_status(" "); D_close(D_USERFILE); D_flush(D_DATAFILE); D_trash(D_DATAFILE); D_trash(D_PHASFILE); // save procpar strcpy(filepath,newfidpath); strcat(filepath,"/procpar"); if(npx == npadj) { saveProcpar(filepath); } else { double sw,at, oldat; P_getreal(PROCESSED,"at", &oldat, 1); P_setreal(PROCESSED,"np",(double)npadj,1); if(!P_getreal(PROCESSED,"sw",&sw,1) && sw > 0) { at = npadj/(2*sw); P_setreal(PROCESSED,"at",at,1); } saveProcpar(filepath); P_setreal(PROCESSED,"np",(double)npx,1); P_setreal(PROCESSED,"at",oldat,1); } RETURN; }
int flush( int argc, char *argv[], int retc, char *retv[] ) { char parampath[MAXPATH]; int curexpnumber; int diskIsFull; int ival; extern int start_from_ft; static int flushed = -1; (void) argc; (void) argv; (void) retc; (void) retv; // flush global if VnmrJViewId == 1 or argc != 99 (almost always the case). // Note, flush(99,NULL,0,NULL) is called in nmr_exit to avoid repeatly // flush global by multiple viewports. int flushGlobal=(VnmrJViewId == 1 || argc != 99); if ((mode_of_vnmr == AUTOMATION) && (datadir[0] != '\0') && (flushed == -1)) { /* In automation, datadir[0] != '\0' means conditional processing is occurring. * The first time flush is called is during the bootup process when data is * being rt'ed from the .fid file into the automation experiment. * Therefore, no need to flush data. * Note that rt() always calls flush if in automation mode. */ flushed = 0; RETURN; } if (skipFlush && (mode_of_vnmr == AUTOMATION)) { skipFlush = 0; RETURN; } skipFlush = 0; curexpnumber = expdir_to_expnum(curexpdir); if (curexpnumber < 1) { if (!Bnmr) Werrprintf( "no current experiment, aborting save" ); RETURN; } Wturnoff_buttons(); if (showFlushDisp) disp_status("SVPAR "); /* save parameters in curexp/curpar file */ D_getparfilepath(CURRENT, parampath, curexpdir); if (P_save(CURRENT,parampath)) { ival = isDiskFullFile( curexpdir, parampath, &diskIsFull ); if (ival == 0 && diskIsFull) { Werrprintf("problem saving current parameters: disk is full"); } else Werrprintf("problem saving current parameters"); ABORT; } /* save parameters in curexp/procpar file */ if ((mode_of_vnmr == AUTOMATION) && (datadir[0] != '\0') && (flushed == 0)) { setfilepaths(0); /* reset file paths to main data files for automation */ P_copygroup(CURRENT,PROCESSED,G_DISPLAY); sprintf(parampath,"%s.fid",datadir); if (access(parampath,W_OK)) /* If .fid file is missing, assume it was deleted on purpose. */ { strcpy(parampath,curexpdir); } } else strcpy(parampath,curexpdir); D_getparfilepath(PROCESSED, parampath, parampath); if (P_save(PROCESSED,parampath)) { ival = isDiskFullFile( curexpdir, parampath, &diskIsFull ); if (ival == 0 && diskIsFull) { Werrprintf("problem saving processed parameters: disk is full"); } else { Werrprintf("problem saving processed parameters"); } ABORT; } if ((mode_of_vnmr == AUTOMATION) && (datadir[0] != '\0') && (flushed == 0)) flushed = 1; /* save parameters in global file except when doing automation or running in background */ if ( (mode_of_vnmr != AUTOMATION) && ! Bnmr) { #ifdef VNMRJ if (flushGlobal) // write shared and unshared #endif { strcpy(parampath,userdir); strcat(parampath,"/global"); if (P_save(GLOBAL,parampath)) { ival = isDiskFullFile( userdir, parampath, &diskIsFull ); if (ival == 0 && diskIsFull) Werrprintf("problem saving global parameters: disk is full"); else Werrprintf("problem saving global parameters"); ABORT; } } // always write un-shared globals sprintf(parampath,"%s/global%d",userdir,VnmrJViewId); if (P_saveUnsharedGlobal(parampath)) { ival = isDiskFullFile( userdir, parampath, &diskIsFull ); if (ival == 0 && diskIsFull) Werrprintf("problem saving unshared global parameters: disk is full"); else Werrprintf("problem saving unshared global parameters"); ABORT; } } p11_flush(); if (showFlushDisp) disp_status("SAVEDATA"); D_close(D_DATAFILE); D_close(D_PHASFILE); D_close(D_USERFILE); start_from_ft = 1; closexposebuf(); if (showFlushDisp) disp_status(" "); RETURN; }
/*----------------------------------------------- | | | get_one_fid()/3 | | | | This function returns a pointer to the | | requested FID in a 1D, arrayed, or 2D | | experiment. | | | +----------------------------------------------*/ float *get_one_fid(int curfid, int *np, dpointers *c_block, int dcflag) { char filepath[MAXPATHL], dcrmv[4]; int res, lastfid, force_getfid, headok; float *fidptr; int cftemp; int cttemp; double tmp; vInfo info; ftparInfo ftpar; dfilehead fidhead, phasehead; force_getfid = (*np < 0); if (force_getfid) *np = -(*np); acqflag = FALSE; ftpar.np0 = *np; ftpar.fn0 = *np; ftpar.hypercomplex = FALSE; /* ==> will not work for hypercomplex 2D interferograms */ D_allrelease(); if ( (res = D_gethead(D_PHASFILE, &phasehead)) ) { if (res == D_NOTOPEN) { if ( (res = D_getfilepath(D_PHASFILE, filepath, curexpdir)) ) { D_error(res); return(NULL); } res = D_open(D_PHASFILE, filepath, &phasehead); /* open the file */ } if (res) { if ( new_phasefile(&phasehead, 0, 0, 0, 0, 0, ftpar.hypercomplex) ) return(NULL); } } cftemp = 1; if (!P_getreal(CURRENT, "cf", &tmp, 1)) { if (!P_getVarInfo(CURRENT, "cf", &info)) { if (info.active) cftemp = (int) tmp; } } cttemp = 0; if (!P_getreal(PROCESSED, "ct", &tmp, 1)) cttemp = (int) (tmp + 0.5); ls_ph_fid("lsfid", &(ftpar.lsfid0), "phfid", &(ftpar.phfid0), "lsfrq", &(ftpar.lsfrq0)); headok = ( (phasehead.status == (S_DATA|S_FLOAT|S_COMPLEX)) && (phasehead.ntraces == 1) && (phasehead.np == ftpar.np0) ); if (headok) { /* if phase file does contain fid data, open the file */ res = D_getbuf(D_PHASFILE, phasehead.nblocks, curfid, c_block); if (!res) { if ( (c_block->head->status == (S_DATA|S_FLOAT|S_COMPLEX)) && (c_block->head->rpval == (float) (ftpar.phfid0)) && (c_block->head->lpval == (float) (ftpar.lsfid0/2)) && (c_block->head->lvl == (float) (cftemp)) && (c_block->head->tlt == (float) (cttemp)) && !force_getfid ) { long_event(); return((float *)c_block->data); } } } /******************************************** * If phasefile does not contain FID data, * * open phasefile with the data handler. * ********************************************/ ftpar.zeroflag = FALSE; ftpar.arraydim = dim1count(); lastfid = ftpar.arraydim; ftpar.fn0 = ftpar.np0; if ( i_fid(&fidhead, &ftpar) ) /* open fid file with data handler */ return(NULL); if (ftpar.fn0 != ftpar.np0) headok = 0; *np = ftpar.np0; ftpar.fn0 = ftpar.np0; if (!headok) { if (new_phasefile(&phasehead, 0, ftpar.arraydim, 2*ftpar.np0, 1, (S_DATA|S_FLOAT|S_COMPLEX), ftpar.hypercomplex)) { return(NULL); } } if ( (res = D_allocbuf(D_PHASFILE, curfid, c_block)) ) { D_error(res); return(NULL); } fidptr = (float *)c_block->data; /******************************************* * provision for baseline offset removal * * using numbers reported by noise check * *******************************************/ ftpar.offset_flag = FALSE; if (!P_getstring(CURRENT,"dcrmv",dcrmv,1,4)) { if (dcrmv[0] == 'y') { ftpar.offset_flag = TRUE; } } ftpar.t2dc = dcflag; if ( getfid(curfid, fidptr, &ftpar, &fidhead, &lastfid) || (lastfid <= curfid) ) { return(NULL); } if (ftpar.lsfid0 > 0) zerofill(fidptr + ftpar.np0 - ftpar.lsfid0, ftpar.lsfid0); D_close(D_USERFILE); setheader(c_block, (S_DATA|S_FLOAT|S_COMPLEX), NP_PHMODE, curfid, ftpar.hypercomplex); c_block->head->rpval = (float) (ftpar.phfid0); c_block->head->lpval = (float) (ftpar.lsfid0/2); c_block->head->lvl = (float) (ftpar.cf); c_block->head->tlt = (float) (ftpar.dspar.ctcount); if ( ftpar.cf != cftemp) { /* cf is misset or inactive - just set it = 1 */ Werrprintf("cf = %d is inconsistent with data",cftemp); P_setreal(CURRENT, "cf", 1.0, 0); P_setreal(PROCESSED,"cf", 1.0, 0); } if ( (res = D_markupdated(D_PHASFILE, curfid)) ) { D_error(res); return(NULL); } return(fidptr); }
/*--------------------------------------- | | | getfid()/5 | | | +--------------------------------------*/ int getfid(int curfid, float *outp, ftparInfo *ftpar, dfilehead *fidhead, int *lastfid) { short *data, *inp16; int *inp32; register int i, npx; int shift, res; register float *inpfloat, rmult; register float *tmp; dpointers inblock; static float xoff, yoff; int showMsg = 1; /* i_ft sets the correct values for cf and nf fields in ftpar */ if (curfid >= (*lastfid) || ftpar->cf > ftpar->nf) { zerofill(outp, ftpar->fn0); } else { if ( (res = D_getbuf(D_USERFILE, fidhead->nblocks, curfid, &inblock)) ) { *lastfid = curfid; if (ftpar->arraydim > 0) { if ( ftpar->np1 > 2*(curfid/ftpar->arraydim) ) ftpar->np1 = 2*(curfid/ftpar->arraydim); /* adjusts number of t1 points */ } zerofill(outp, ftpar->fn0); D_close(D_USERFILE); if (*lastfid == 0) { Werrprintf("No data in FID file"); } else { if (!acqflag) Winfoprintf("number of FID's used = %d", *lastfid); } return(COMPLETE); } /************************************************************ * Convert the data of each FID. Check to see if FID data * * are double precision or single precision and convert * * appropriately. Correct FID size for CT and scaling. * ************************************************************/ if (inblock.head->lpval != 0) ftpar->lpval = inblock.head->lpval; /* Save this so other programs like addsub and wti can get it */ oversamp_lp = inblock.head->lpval; ftpar->dspar.lvl = inblock.head->lvl; ftpar->dspar.tlt = inblock.head->tlt; ftpar->dspar.scale = inblock.head->scale; ftpar->dspar.ctcount = inblock.head->ctcount; data = (short *) (inblock.data); if (ftpar->cf > 1) { data += (ftpar->cf - 1)*ftpar->np0; if (ftpar->dpflag) data += (ftpar->cf - 1)*ftpar->np0; } if ( (ftpar->np0 - ftpar->lsfid0) > ftpar->fn0 ) ftpar->np0 = ftpar->fn0 + ftpar->lsfid0; if (inblock.head->status == (S_DATA|S_FLOAT|S_COMPLEX)) { inpfloat = (float *) (data); if (ftpar->lsfid0 < 0) { inpfloat += ftpar->np0; tmp = outp + ftpar->np0 - ftpar->lsfid0; npx = ftpar->np0; if ((inblock.head->ctcount > 1) || (inblock.head->scale) ) { shift = 1 << abs(inblock.head->scale); if (inblock.head->scale < 0) rmult = 1.0/(float)(shift); else rmult = (float) shift; rmult /= (float)(inblock.head->ctcount); for (i = 0; i < npx; i++) *(--tmp) = *(--inpfloat) * rmult; } else { for (i = 0; i < npx; i++) *(--tmp) = *(--inpfloat); } npx = (-1)*ftpar->lsfid0; for (i = 0; i < npx; i++) *(--tmp) = 0.0; } else { inpfloat += ftpar->lsfid0; tmp = outp; npx = ftpar->np0 - ftpar->lsfid0; if ((inblock.head->ctcount > 1) || (inblock.head->scale) ) { shift = 1 << abs(inblock.head->scale); if (inblock.head->scale < 0) rmult = 1.0/(float)(shift); else rmult = (float) shift; rmult /= (float)(inblock.head->ctcount); for (i = 0; i < npx; i++) *tmp++ = *inpfloat++ * rmult; } else { for (i = 0; i < npx; i++) *tmp++ = *inpfloat++; } } } else { if (inblock.head->ctcount == 0) { inblock.head->ctcount = 1; inblock.head->status = 0; *lastfid = curfid; if (ftpar->arraydim > 0) { if ( ftpar->np1 > 2*(curfid/ftpar->arraydim) ) ftpar->np1 = 2*(curfid/ftpar->arraydim); } if (!acqflag) { if ( *lastfid ) Winfoprintf("number of FID's used = %d", *lastfid); else Winfoprintf("No data in FID file"); showMsg = 0; } } inp16 = (short *) (inp32 = (int *) (data)); shift = 1 << abs(inblock.head->scale); if (inblock.head->scale < 0) rmult = 1.0/(float)(shift); else rmult = (float) shift; rmult /= (float)(inblock.head->ctcount); if (inblock.head->status == (S_DATA|S_32|S_COMPLEX)) { cnvrts32(rmult, inp32, outp, ftpar->np0, ftpar->lsfid0); } else if (inblock.head->status == (S_DATA|S_COMPLEX)) { cnvrts16(rmult, inp16, outp, ftpar->np0, ftpar->lsfid0); } else { if (inblock.head->status != 0) { Wscrprintf("status of FID %d incorrect, status = %d\n", curfid + 1, inblock.head->status); } zerofill(outp, ftpar->fn0); if (ftpar->arraydim > 0) { if ( ftpar->np1 > 2*(curfid/ftpar->arraydim) ) ftpar->np1 = 2*(curfid/ftpar->arraydim); } *lastfid = curfid; if ( !acqflag && showMsg ) { if ( *lastfid ) Winfoprintf("number of FID's used = %d", *lastfid); else Winfoprintf("No data in FID file"); } } } /*--------------------------------------------- | if requested remove the baseline | | supplied by noise check | ---------------------------------------------*/ if ( ftpar->offset_flag && (inblock.head->ctcount == 1) ) { if (curfid == 0) { xoff = inblock.head->lvl; yoff = inblock.head->tlt; } if (ftpar->lsfid0 < 0) { tmp = outp - ftpar->lsfid0; npx = ftpar->np0; } else { tmp = outp; npx = ftpar->np0 - ftpar->lsfid0; } i = 0; while (i < npx) { *tmp++ -= xoff; *tmp++ -= yoff; i += 2; } } /* end of prototype baseline removal */ #ifdef XXX if ( !P_getreal(CURRENT, "rlmult", &rlmult, 1) ) { if ( !P_getreal(CURRENT, "immult", &immult, 1) ) { if (ftpar->lsfid0 < 0) { tmp = outp - ftpar->lsfid0; npx = ftpar->np0; } else { tmp = outp; npx = ftpar->np0 - ftpar->lsfid0; } i = 0; while (i < npx) { *tmp++ *= rlmult; *tmp++ *= immult; i += 2; } } } #endif /* end of prototype differential channel scaling */ if (ftpar->t2dc) { driftcorrect_fid(outp, ftpar->np0/2, ftpar->lsfid0/2, COMPLEX); } if ( (fabs(ftpar->phfid0) > MINDEGREE) || (fabs(ftpar->lsfrq0) > 1e-20) ) { rotate_fid(outp, ftpar->phfid0, ftpar->lsfrq0, ftpar->np0 - ftpar->lsfid0, COMPLEX); } if (ftpar->zeroflag) { if (ftpar->zeroflag > 0) zeroimag(outp, ftpar->np0 - ftpar->lsfid0, TRUE); else negateimaginary(outp, (ftpar->np0 - ftpar->lsfid0) / 2, COMPLEX); } if ( (res = D_release(D_USERFILE, curfid)) ) { D_error(res); D_close(D_USERFILE); return(ERROR); } } long_event(); return(COMPLETE); }