int decc_purge(int argc, char *argv[], int retc, char *retv[]) { char decclibpath[MAXSTR], fullpath[MAXSTR]; char tmpFln[MAXSTR], filename[MAXSTR], cmd[MAXSTR]; int j,version, biggest; FILE *fd; (void) retc; (void) retv; if (argc>2) debug=1; if (argc>2) debug=1; if (argc>2) debug=1; else debug=0; if (argc < 2) { Werrprintf("Usage -- decc_purge(filename)"); RETURN; } strcpy(filename,argv[1]); if (debug) Winfoprintf("decc_purge: inputfile='%s'\n",filename); // strip version if any getVersion(filename); if (debug) Winfoprintf("decc_purge: minus version='%s'\n",filename); // check decclib for highest version strcpy(decclibpath,systemdir); strcat(decclibpath,"/imaging/decclib/"); strcpy(fullpath,decclibpath); strcat(fullpath,filename); biggest = getBiggestVersion(fullpath); if (debug) Winfoprintf("decc_purgewhat: count=%d\n",bigCount); strcpy(cmd,"ls "); strcat(cmd,fullpath); strcat(cmd,".*"); // remove all-but-one or the-one if (bigCount != 1) { fd = popen(cmd, "r"); j = fscanf(fd,"%s",filename); while (j>0) { strcpy(tmpFln,filename); // don't loose version version = getVersion(filename); if (version != biggest) { if (debug) Winfoprintf("deleting '%s'",tmpFln); if (unlink(tmpFln) != 0) perror("decc_purge"); } j = fscanf(fd,"%s",filename); } pclose(fd); } else // the-one { sprintf(tmpFln,"%s.%d",fullpath,biggest); if (debug) Winfoprintf("deleting '%s'",tmpFln); if (unlink(tmpFln) != 0) perror("decc_purge"); } RETURN; }
void unixPathToWin(char *path,char *buff,int maxlength) { char *ptr; unixpath2win(path, 0, buff, maxlength); // c has issues with back-slashes in strings so convert them to forward slashes while ( (ptr = strchr(buff,'\\')) ) *ptr = '/'; #ifdef TEST_PATH Winfoprintf("unixPathToWin %s -> [%s]",path,buff); char tmpPath[MAXPATH]; winpath2unix(buff, 0, tmpPath, maxlength); Winfoprintf("winpath2unix %s -> [%s]",buff,tmpPath); #endif }
//#define TEST_PATH void winPathToUnix(char *path,char *buff, int maxlength) { winpath2unix(path, 0, buff, maxlength); #ifdef DEBUG_PATHS Winfoprintf("winpath2unix %s -> [%s]",path,buff); #endif }
static int getBiggestVersion(char *fullpath) { char filename[MAXSTR]; char cmd[MAXSTR]; int j,version, biggest; FILE *fd; strcpy(cmd,"ls "); strcat(cmd,fullpath); strcat(cmd,".*"); fd = popen(cmd, "r"); if (fd==0) { Werrprintf("decc_version: problem opening %s*",fullpath); return(-1); } version=-1; biggest=0; bigCount=0; j = fscanf(fd,"%s",filename); while (j>0) { version = getVersion(filename); if (version > biggest) biggest=version; if (debug) Winfoprintf("decc_version: fln='%s', version=%d biggest=%d", filename,version, biggest); j = fscanf(fd,"%s",filename); bigCount++; } pclose(fd); return(biggest); }
int decc_purgewhat(int argc, char*argv[], int retc, char *retv[]) { char decclibpath[MAXSTR], fullpath[MAXSTR]; char tmpStr[MAXSTR], filename[MAXSTR]; int biggest; if (argc>1) debug=2; else debug=0; if (argc < 2) { Werrprintf("Usage -- decc_purge(filename)"); RETURN; } strcpy(filename,argv[1]); if (debug) Winfoprintf("decc_purgewhat: inputfile='%s'\n",filename); // strip version if any getVersion(filename); if (debug) Winfoprintf("decc_purgewhat: minus version='%s'\n",filename); // check decclib for highest version strcpy(decclibpath,systemdir); strcat(decclibpath,"/imaging/decclib/"); strcpy(fullpath,decclibpath); strcat(fullpath,filename); biggest = getBiggestVersion(fullpath); if (debug) Winfoprintf("decc_purgewhat: count=%d\n",bigCount); if (bigCount != 1) { sprintf(tmpStr, "This will delete all versions of \"%s\" except the latest: version %d", filename,biggest); } else { sprintf(tmpStr, "This will delete the last and only version of \"%s\"", filename); } if (retc > 0) retv[0] = newString(tmpStr); else Winfoprintf("%s",tmpStr); RETURN; }
/** * This routine gets which mouse buttons are down. Similar functionality * is in gin(), but that routine does a lot of initialization, and beeps * if there is no transformed data. * * Returns: Bit mapped integer--a set bit means the corresponding mouse * button is down. E.g., return=5 means first and third buttons are * down, return=1 means first button is down. Return 0 if no buttons * are down. */ int getMouseButtons(int argc, char *argv[], int retc, char *retv[]) { if (retc > 0) { retv[0] = intString(buttonsDown); } else { Winfoprintf("mouseButtons = %d", buttonsDown); } RETURN; }
int bigendian( int argc, char *argv[], int retc, char *retv[] ) { (void) argc; (void) argv; if (retc > 0) retv[0] = intString( BigEndian ); else Winfoprintf("System architecture is %s Endian\n",(BigEndian) ? "Big" : "Little"); RETURN; }
// ind start from zero float *SpecData::getTrace(int ind, int npts) { float *data = specStruct->data; if(!data) { Winfoprintf("%s: No data!", key.c_str()); return NULL; } int ntraces = getNumTraces(); int np = specStruct->matrix[0]; if(ind > ntraces) { Winfoprintf("Index %d out of range (1-%d)!", ind, ntraces); return NULL; } if(np != npts) { Winfoprintf("Data size %d does not match %d!", npts, np); return NULL; } return &(data[(ind)*np]); }
int jcurwin_jexp(int expnum, int oldexpnum ) { int index, get1, get2, retval=1; double dval; vInfo info; /* int VnmrJViewId */ char path[MAXSTR]; struct stat stat_blk; (void) oldexpnum; if (mode_of_vnmr==AUTOMATION) /* || (mode_of_vnmr==BACKGROUND) */ return(retval); if (expnum > 0) { sprintf(path, "%s/lock_%d.primary", userdir, expnum); if (stat( path, &stat_blk ) != 0) return(retval); get1 = P_getVarInfo(GLOBAL, "jcurwin", &info); get2 = P_getreal(GLOBAL, "jviewports", &dval, 1); /* read number of viewports from jviewports[1] */ if (get1==0 && get2==0) { get2 = (int) (dval + 0.5); if ((get2 > 0) && (get2 <= info.size)) { for (index=0; index<get2; index++) { P_getreal(GLOBAL, "jcurwin", &dval, index+1); if (expnum == (int)dval) { char mstr[MAXPATH]; /* sprintf(mstr, "viewport %d", index+1); writelineToVnmrJ("vnmrjcmd",mstr); sprintf(mstr, "vplayout use %d", index+1); writelineToVnmrJ("vnmrjcmd",mstr); */ P_getstring(GLOBAL, "jviewportlabel", mstr, index+1, MAXPATH); Winfoprintf("Cannot join workspace exp%d - in use by %s viewport.\n",expnum,mstr); retval = 0; break; } } } } } return(retval); }
int readlk(int argc, char *argv[], int retc, char *retv[]) { int ival; double lockLevel; /* Check on interactive acquisition... */ if (interact_is_connected("")) { Werrprintf( "Cannot run %s, interactive acquisition in progress", argv[ 0 ] ); ABORT; } if (ACQOK(HostName) == 0) { disp_acq(""); Werrprintf("Acquisition is not available!"); ABORT; } if (GETACQSTATUS(HostName,UserName) < 0) { Werrprintf( "%s: failed to obtain acquisition status", argv[ 0 ] ); ABORT; } ival = getAcqStatusValue(LOCKLEVEL, &lockLevel); if (retc == 0) Winfoprintf( "readlk: current lock level = %g", lockLevel ); else if (retc > 0) { retv[ 0 ] = realString( lockLevel ); if (retc > 1) { ival = getAcqStatusValue(LOCKLEVEL+1, &lockLevel); retv[ 1 ] = realString( lockLevel ); } } RETURN; }
void AspFrame::addRoiFromCursors() { if(getCursorMode() != 2) { Winfoprintf("Try again after selecting second cursor with right mouse button."); return; } spAspDataInfo_t dataInfo = getDefaultDataInfo(); if(dataInfo->vaxis.rev) { // 1D band double c1,c2; P_getreal(CURRENT, "cr", &c1, 1); P_getreal(CURRENT, "delta", &c2, 1); c2 = c1 - c2; double reffrq = dataInfo->haxis.scale; if (reffrq>0) { c1 /= reffrq; c2 /= reffrq; } addRoiFromCursors(c1,c2); } else { // 2D box double c11,c12,c21,c22; P_getreal(CURRENT, "cr", &c11, 1); P_getreal(CURRENT, "delta", &c12, 1); c12 = c11 - c12; double reffrq = dataInfo->haxis.scale; if (reffrq>0) { c11 /= reffrq; c12 /= reffrq; } P_getreal(CURRENT, "cr1", &c21, 1); P_getreal(CURRENT, "delta1", &c22, 1); c22 = c21 - c22; double reffrq1 = dataInfo->vaxis.scale; if (reffrq1>0) { c21 /= reffrq1; c22 /= reffrq1; } addRoiFromCursors(c11,c12,c21,c22); } }
static int leader_top(int peak_x, int peak_y, int label_x, int ymax) /***************************************************/ { int newpeak_y; int dx,dy; int bottom; dx = label_x - peak_x; dy = abs(dx) / 2; newpeak_y = ymax - dy - (int) (3.0 * dispcalib); bottom = dfpnt2 + (int) (dispcalib * vp + 1.0); if (newpeak_y < bottom) { if (!plot) Winfoprintf("vp too large for dpf display"); return(0); } if (newpeak_y > peak_y) { amove(peak_x,peak_y); rdraw(0,newpeak_y - peak_y); } amove(peak_x,newpeak_y); rdraw(dx,dy); rdraw(0,(int) (3.0 * dispcalib)); /* re-use dx for logic */ dx = plot && ((raster == 0) || (raster > 2)); /* hpgl and postscript output */ if (dx) /* HP plotter */ rmove( CharSize/5,5); else if (plot) rmove(-CharSize/2,5); else rmove(-4*CharSize/5,5); return(1); }
int decc_save(int argc, char *argv[], int retc, char *retv[]) { char sysgcoil[MAXSTR]; char filename[MAXSTR]; char decclibpath[MAXSTR]; char fullpath[MAXSTR]; char cmd[MAXSTR]; char *tmpPtr, *tmpPtr2; char enabled[MAXSTR]; double taus,ampls,scales,limits; int done, biggest; int i, j,k; FILE *fd,*fd2; (void) retc; (void) retv; if (argc>2) debug=1; else debug=0; if (argc < 2) { Werrprintf("Usage -- decc_save(filename)"); RETURN; } if (P_getstring(SYSTEMGLOBAL,"sysgcoil", sysgcoil, 1, MAXSTR) < 0) { Werrprintf("decc_save: cannot find 'sysgcoil'"); RETURN; } strcpy(filename,argv[1]); if (debug) Winfoprintf("decc_save: inputfile='%s'\n",filename); if (filename[0] == '.') { Werrprintf("decc_save: filename cannot start with a '.'"); ABORT; } // strip version if any getVersion(filename); if (debug) Winfoprintf("decc_save: minus version='%s'\n",filename); // check decclib for highest version strcpy(decclibpath,systemdir); strcat(decclibpath,"/imaging/decclib/"); strcpy(fullpath,decclibpath); strcat(fullpath,filename); biggest = getBiggestVersion(fullpath); tmpPtr = tmpPtr2 = filename; sprintf(fullpath,"%s%s.%d",decclibpath,tmpPtr,biggest+1); done=0; while ( ! done) { Winfoprintf("decc_save: saving to '%s'",fullpath); // save to file fd = fopen(fullpath,"w"); if (fd==0) { Werrprintf("decc_save: problem opening %s",fullpath); RETURN; } fprintf(fd,"filename\t%s.%d\n",tmpPtr2,biggest+1); fd2 = popen("date","r"); fgets(cmd,MAXSTR,fd2); pclose(fd2); fprintf(fd,"date\t%s\n",cmd); i=1; j=0; k=0; while (j<13) { fprintf(fd,"%s",terms[j]); // "xx" etc. k += nterms[j]; while (i<=k) { fputc((int)'\t',fd); if (P_getstring(GLOBAL,"enabled",enabled,i,MAXSTR) < 0) { Werrprintf("decc_save: cannot find 'enabled'"); } if (enabled[0]=='n') fputc((int)'*',fd); if (P_getreal(GLOBAL,"taus",&taus,i) < 0) { Werrprintf("decc_save: cannot find 'taus'"); } if (P_getreal(GLOBAL,"ampls",&ls,i) < 0) { Werrprintf("decc_save: cannot find 'ampls'"); } fprintf(fd,"%g %g",taus/1000.0,ampls/100.0); i++; } fputc((int)'\n',fd); j++; } fprintf(fd,"eccscale"); for (i=1; i<5; i++) { if (P_getreal(GLOBAL,"scales",&scales,i) < 0) { Werrprintf("decc_save: cannot find 'scales'"); } fprintf(fd,"\t%g",scales); } fputc((int)'\n',fd); fprintf(fd,"shimscale"); for (i=5; i<8; i++) { if (P_getreal(GLOBAL,"scales",&scales,i) < 0) { Werrprintf("decc_save: cannot find 'scales'"); } fprintf(fd,"\t%g",scales); } fputc((int)'\n',fd); fprintf(fd,"totalscale"); for (i=8; i<11; i++) { if (P_getreal(GLOBAL,"scales",&scales,i) < 0) { Werrprintf("decc_save: cannot find 'scales'"); } fprintf(fd,"\t%g",scales); } fputc((int)'\n',fd); fprintf(fd,"slewlimit"); for (i=1; i<5; i++) { if (P_getreal(GLOBAL,"limits",&limits,i) < 0) { Werrprintf("decc_save: cannot find 'limits'"); } fprintf(fd,"\t%g",limits); } fputc((int)'\n',fd); fprintf(fd,"dutylimit"); for (i=5; i<9; i++) { if (P_getreal(GLOBAL,"limits",&limits,i) < 0) { Werrprintf("decc_save: cannot find 'limits'"); } fprintf(fd,"\t%g",limits); } fputc((int)'\n',fd); fclose(fd); // check if we need to save to .sysgcoil if (tmpPtr==sysgcoil) done=1; else { tmpPtr=sysgcoil; sprintf(fullpath,"%s.%s",decclibpath,tmpPtr); } } // Now all is saved, // deccflag[8]=biggest+1 (version) // set o_enabled=enabled, o_taus=taus, o_ampls=ampls // o_limits=limits, o_scales=scales // and deccflag[7]=1 (Unmodified). if (P_setreal(GLOBAL,"deccflag", (double)(biggest+1),8) < 0) { Werrprintf("decc_save: cannot set 'deccflag[8]'i to version"); } for (i=1; i< 53; i++) { if (P_getstring(GLOBAL,"enabled",enabled,i,MAXSTR) < 0) { Werrprintf("decc_save: cannot find 'enabled'"); break; } if (P_getreal(GLOBAL,"taus",&taus,i) < 0) { Werrprintf("decc_save: cannot find 'taus'"); break; } if (P_getreal(GLOBAL,"ampls",&ls,i) < 0) { Werrprintf("decc_save: cannot find 'ampls'"); break; } if (P_setstring(GLOBAL,"o_enabled", enabled, i) < 0) { Werrprintf("decc_save: cannot find 'o_enabled'"); break; } if (P_setreal(GLOBAL,"o_taus", taus, i) < 0) { Werrprintf("decc_save: cannot find 'o_taus'"); break; } if (P_setreal(GLOBAL,"o_ampls", ampls, i) < 0) { Werrprintf("decc_save: cannot find 'o_ampls'"); break; } } for (i=1; i<11; i++) { if (P_getreal(GLOBAL,"scales",&scales,i) < 0) { Werrprintf("decc_save: cannot find 'scales'"); break; } if (P_setreal(GLOBAL,"o_scales", scales, i) < 0) { Werrprintf("decc_save: cannot find 'o_scales'"); break; } } for (i=1; i<8; i++) { if (P_getreal(GLOBAL,"limits",&limits,i) < 0) { Werrprintf("decc_save: cannot find 'limits'"); break; } if (P_setreal(GLOBAL,"o_limits", limits, i) < 0) { Werrprintf("decc_save: cannot find 'o_limits'"); break; } } if (P_setreal(GLOBAL, "deccflag", 1.0, 7) < 0) // Unmodified { Werrprintf("decc_save: cannot set deccflag[7]"); } if (debug) Winfoprintf("decc_save: saved fln='%s',version=%d\n", filename,biggest+1); sprintf(fullpath,"%s.%d",filename,biggest+1); if (P_setstring(GLOBAL,"deccorig_fln", fullpath, 1) < 0) { Werrprintf("decc_load: cannot set 'deccorig_fln'"); } if (P_setstring(GLOBAL,"decctool_fln", fullpath, 1) < 0) { Werrprintf("decc_load: cannot set 'decctool_fln'"); } appendvarlist("deccflag deccorig_fln decctool_fln"); RETURN; }
int decc_load(int argc, char *argv[], int retc, char *retv[]) { char decclibpath[MAXSTR]; char filename[MAXSTR]; char fullpath[MAXSTR]; char oneline[MAXSTR]; char delimiters[10], yesno[10]; char cmd[MAXPATH]; char sysgcoil[MAXSTR]; #ifdef LINUX char *ptr,*ptr2; #else char *ptr,*ptr2, *strtok_r(); #endif double taus, ampls, scales, limits; int i,version; int param,first,last; int dotflag; FILE *fd; (void) retc; (void) retv; if (argc>2) debug=1; else debug=0; if (argc < 2) { Werrprintf("Usage -- decc_load(filename)"); RETURN; } version = first = last = 0; param = SKIP; strcpy(filename,argv[1]); strcpy(decclibpath,systemdir); strcat(decclibpath,"/imaging/decclib/"); strcpy(fullpath,decclibpath); if (filename[0] != '.') { dotflag=0; if ((version = getVersion(filename)) < 0) { // check decclib for highest version strcat(fullpath,filename); version = getBiggestVersion(fullpath); } if (version == 0) sprintf(fullpath,"%s%s",decclibpath,filename); else sprintf(fullpath,"%s%s.%d",decclibpath,filename,version); } else { dotflag=1; sprintf(fullpath,"%s%s", fullpath, filename); } Winfoprintf("decc_load: loading '%s'",fullpath); fd = fopen(fullpath, "r"); if (fd == NULL) { Werrprintf("decc_load: can not open %s",fullpath); RETURN; } strcpy(delimiters,"\n \t"); ptr = fgets(oneline,MAXSTR,fd); if (debug) Winfoprintf("dec_load: oneline='%s'",oneline); while (ptr != NULL) { ptr2 = strtok_r(ptr,delimiters,&ptr); if (ptr2 == 0) { ptr = fgets(oneline,MAXSTR,fd); continue; // skip blank lines } if (debug) Winfoprintf("decc_load: linetype='%s'",ptr2); if ( (strcmp(ptr2,"filename") == 0) && (dotflag==1) ) { ptr2 = strtok_r(ptr,delimiters,&ptr); strcpy(filename,ptr2); if (debug) Winfoprintf("decc_load: filename='%s'",filename); if (P_setstring(GLOBAL,"deccorig_fln", filename, 1) < 0) { Werrprintf("decc_load: cannot set 'deccorig_fln'"); } if (P_setstring(GLOBAL,"decctool_fln", filename, 1) < 0) { Werrprintf("decc_load: cannot set 'decctool_fln'"); } version = getVersion(filename); param=SKIP; } else if (strncmp(ptr2,"da",2) == 0) { param=SKIP; } else if (strncmp(ptr2,"xx",2) == 0) { param=TAUS; first=1; last=6; } else if (strncmp(ptr2,"yx",2) == 0) { param=TAUS; first=7; last=9; } else if (strncmp(ptr2,"zx",2) == 0) { param=TAUS; first=10; last=12; } else if (strncmp(ptr2,"xy",2) == 0) { param=TAUS; first=13; last=15; } else if (strncmp(ptr2,"yy",2) == 0) { param=TAUS; first=16; last=21; } else if (strncmp(ptr2,"zy",2) == 0) { param=TAUS; first=22; last=24; } else if (strncmp(ptr2,"xz",2) == 0) { param=TAUS; first=25; last=27; } else if (strncmp(ptr2,"yz",2) == 0) { param=TAUS; first=28; last=30; } else if (strncmp(ptr2,"zz",2) == 0) { param=TAUS; first=31; last=36; } else if (strncmp(ptr2,"xb",2) == 0) { param=TAUS; first=37; last=40; } else if (strncmp(ptr2,"yb",2) == 0) { param=TAUS; first=41; last=44; } else if (strncmp(ptr2,"zb",2) == 0) { param=TAUS; first=45; last=48; } else if (strncmp(ptr2,"b0",2) == 0) { param=TAUS; first=49; last=52; } else if (strncmp(ptr2,"ec",2) == 0) { param=SCALES; first=1; last=4; } else if (strncmp(ptr2,"sh",2) == 0) { param=SCALES; first=5; last=7; } else if (strncmp(ptr2,"to",2) == 0) { param=SCALES; first=8; last=10; } else if (strncmp(ptr2,"sl",2) == 0) { param=LIMITS; first=1; last=4; } else if (strncmp(ptr2,"du",2) == 0) { param=LIMITS; first=5; last=7; } switch(param) { case TAUS: for (i=first; i<=last; i++) { ptr2 = strtok_r(ptr,delimiters,&ptr); if (*ptr2 == '*') { strcpy(yesno,"n"); ptr2++; } else { strcpy(yesno,"y"); } if (P_setstring(GLOBAL,"enabled", yesno, i) < 0) { Werrprintf("decc_load: cannot set 'enabled'"); } if (P_setstring(GLOBAL,"o_enabled", yesno, i) < 0) { Werrprintf("decc_load: cannot set 'o_enabled'"); } taus = atof(ptr2) * 1000.0; if (P_setreal(GLOBAL,"taus",taus,i) < 0) { Werrprintf("decc_load: cannot set 'taus'"); } if (P_setreal(GLOBAL,"o_taus",taus,i) < 0) { Werrprintf("decc_load: cannot set 'o_taus'"); } ptr2 = strtok_r(ptr,delimiters,&ptr); ampls = atof(ptr2) * 100.0; if (P_setreal(GLOBAL,"ampls",ampls,i) < 0) { Werrprintf("decc_load: cannot set 'ampls'"); } if (P_setreal(GLOBAL,"o_ampls",ampls,i) < 0) { Werrprintf("decc_load: cannot set 'o_ampls'"); } if (debug) Winfoprintf("decc_load: i=%d e=%s t=%f a=%f", i,yesno, taus, ampls); } break; case SCALES: for (i=first; i<=last; i++) { ptr2 = strtok_r(ptr,delimiters,&ptr); if (ptr2 == 0) scales = 0.0; else scales = atof(ptr2); if (P_setreal(GLOBAL,"scales",scales,i) < 0) { Werrprintf("decc_load: cannot set 'scales'"); } if (P_setreal(GLOBAL,"o_scales",scales,i) < 0) { Werrprintf("decc_load: cannot set 'o_scales'"); } } break; case LIMITS: for (i=first; i<=last; i++) { ptr2 = strtok_r(ptr,delimiters,&ptr); if (ptr2 == 0) limits = 0.0; else limits = atof(ptr2); if (P_setreal(GLOBAL,"limits",limits,i) < 0) { Werrprintf("decc_load: cannot set 'limits'"); } if (P_setreal(GLOBAL,"o_limits",limits,i) < 0) { Werrprintf("decc_load: cannot set 'o_limits'"); } } break; } ptr = fgets(oneline,MAXSTR,fd); } if (P_setreal(GLOBAL, "deccflag", 1.0, 7) < 0) // Unmodified { Werrprintf("decc_load cannot set deccflag[7]"); } if (P_setreal(GLOBAL,"deccflag", (double)(version),8) < 0) { Werrprintf("decc_load: cannot set 'deccflag[8]' to version"); } appendvarlist("enabled,taus,ampls,scales,limits,deccflag,deccorig_fln,decctool_fln"); if (P_getstring(SYSTEMGLOBAL,"sysgcoil", sysgcoil, 1, MAXSTR) < 0) { Werrprintf("decc_load: cannot find 'sysgcoil'"); } else { strcpy(cmd,"cp "); // "cp " strcat(cmd,fullpath); // "cp /vnmr/imaging/decclib/new.3" strcat(cmd," "); // "cp /vnmr/imaging/decclib/new.3" strcat(cmd,decclibpath); // "cp .../new.3 /vnmr/imaging/decclib" strcat(cmd,"/."); // "cp .../new.3 .../." strcat(cmd,sysgcoil); // "cp .../new.3 .../.sysgcoil" system(cmd); } if (debug) Winfoprintf("decc_load: Done!"); fclose(fd); RETURN; }
int flashc (int argc, char *argv[], int retc, char *retv[] ) /* Purpose: ------- Routine flashc is the main routine for the "flash convert" function. It edits the fid file in the current experiment, as well as process parameters nf, ni, arraydim, arrayelemts, and cf to do the flash data format to standard format conversion. Arguments: --------- argc : ( ) Argument count. argv : ( ) Command line arguments. retc : ( ) Return argument count. Not used here. retv : ( ) Return arguments. Not used here. */ /* 9-4-92 A single argument is allowed at this time to specify the number of compressed traces to be left as a compressed nf block. The use for this is to allow compressed multislice or multiecho simultaneous with compressed phase encoding. 9-10-92 Argument list expanded to allow both compressed multi-slice, and compressed multi-image formats. The difference in format is: (numerical values indicate acquisition order of traces) pe 1 2 3 4 5 ns ==> || 6 7 8 9 10 || 11 12 13 14 15 \/ ... .......... XX where XX = phase encode * slices pe 1 pe+1 2pe+1 compressed images ==> || 2 pe+2 2pe+2 || 3 pe+3 2pe+3 \/ ... pe pe*2 ... XX where XX = phase encode * images "rare" type data acquisition. pe 1 ne+1 2ne+1 ns ==> || 2 ne+2 2ne+2 || 3 ne+3 2ne+3 || ... || ne ne*2 ... XX where XX = num echoes (ne) * slices (ns) || || ne*ns+1 ne*ns+ne+1 ne*ns+2ne+1 || ne*ns+2 ne*ns+ne+2 ne*ns+2ne+2 || ... || ne*ns+ne ne*ns+ne*2 ne*ns+ne*ns || . \/ 2(ne*ns)+ne 2(ne*ns)+ne*2 2(ne*ns)+ne*ns . ... XX where XX = nv/ne*(ne * ns) Examples of use from vnmr: flashc simple compressed phase-encode flashc('ms',ns) compressed phase-encode and compressed multi-slice flashc('mi',ns) compressed multi-image and compressed phase-encode flashc('rare',ns,ne) compressed echo-train, multi-slice, and phase-encode 'nf' argument added to reformat the data into the following: slice1 image, slice2 image, slice3 image,..., slicen image. flashc('nf') simple compressed phase-encode flashc('nf','ms',ns) compressed phase-encode and compressed multi-slice flashc('nf','mi',ns) compressed multi-image and compressed phase-encode flashc('nf','rare',ns,ne) compressed echo-train, multi-slice, and phase-encode */ { /* Begin function flashc */ /* Local Variables: --------------- default_fid : Complete file path to the fid file in the current experiment. temp_fid : Complete file path to a temporary version of the fid file in the current experiment. nf : The Vnmr process parameter of the same name. ni : Ditto. ncomp : Number of traces to keep in compressed nf form. arraydim : Value of Vnmr process parameter arraydim. arrayelemts : Value of Vnmr process parameter arrayelemts. r : Return value of a function. format : image compression format; 0 = multi-slice, 1 = multi-image. */ char default_fid[MAXPATHL], temp_fid[MAXPATHL]; int format, r, nfarg; double ncomp, necho, nf, ni, arraydim, arrayelemts; /* A convenience macro */ #define P_SETPAR(name,value) \ if (( r=P_setreal(PROCESSED,name,value,1))) \ { P_err(r,name,":"); \ ABORT; \ } \ if ( ( r=P_setreal(CURRENT,name,value,1)) ) \ { P_err(r,name,":"); \ ABORT; \ } /* Begin Executable Code: -------------------- */ /* Verify that the user has passed correct number of arguments */ if ( argc > 5 ) { Werrprintf ( "Flashc: wrong number of arguments." ); ABORT; } nfarg = 0; /* Look for 'nf' argument */ if (argc > 1) { if ( !strcmp(argv[1],"nf") ) { nfarg = 1; } } /* Look for any arguments */ if ( argc == 4+nfarg) { if ( !strcmp(argv[1+nfarg],"rare") ) { format = 2; ncomp = atof(argv[2+nfarg]); necho = atof(argv[3+nfarg]); /* necho= echo train of phase encode steps */ } else { Werrprintf ( "Flashc: unrecognized conversion type." ); ABORT; } } else if ( argc == 3+nfarg ) { ncomp = atof(argv[2+nfarg]); necho = 1.0; if ( !strcmp(argv[1+nfarg],"ms") ) if (nfarg) format = 1; else format = 0; else if ( !strcmp(argv[1+nfarg],"mi") ) if (nfarg) format = 0; else format = 1; else { Werrprintf ( "Flashc: unrecognized conversion type." ); ABORT; } } else { ncomp = 1.0; necho = 1.0; format = 0; } /* Do an "interlock" to insure that flashc is called only once */ if ( flash_interlock() != 0 ) RETURN; /* Generate paths to the fid file and a parallel, temporary file. */ (void)strcpy ( default_fid, curexpdir ); (void)strcpy ( temp_fid, curexpdir ); #ifdef UNIX (void)strcat ( default_fid, "/acqfil/fid" ); (void)strcat ( temp_fid, "/acqfil/flashc.temp" ); #else vms_fname_cat ( default_fid, "[.acqfil]fid" ); vms_fname_cat ( temp_fid, "[.acqfil]flashc.temp" ); #endif /* Obtain the values of the process parameters */ if ( get_flashc_parms ( &arraydim, &nf, &ni ) != 0 ) { P_deleteVar ( PROCESSED, "flash_converted" ); P_deleteVar ( CURRENT, "flash_converted" ); ABORT; } if (nfarg && (ncomp == 1.0)) ncomp = nf; /* Check nf to make sure it is divisible by ncomp */ if ( (int)floor(nf+0.5) % (int)floor(ncomp+0.5) > 0 ) { Werrprintf ( "Flashc: ncomp is not a factor of nf." ); P_deleteVar ( PROCESSED, "flash_converted" ); P_deleteVar ( CURRENT, "flash_converted" ); ABORT; } /* Display status on screen */ disp_status ( "FLASHC" ); if (nfarg) { /* Edit the fid file, may also revise parameters nf and ni. */ if ( nf_flash_convert ( default_fid, temp_fid, arraydim, format, ncomp, necho, nf, &ni ) != 0 ) { P_deleteVar ( PROCESSED, "flash_converted" ); P_deleteVar ( CURRENT, "flash_converted" ); disp_status ( " " ); ABORT; } } else { /* Edit the fid file, may also revise parameter ni. */ if ( flash_convert ( default_fid, temp_fid, arraydim, format, ncomp, necho, nf, &ni ) != 0 ) { P_deleteVar ( PROCESSED, "flash_converted" ); P_deleteVar ( CURRENT, "flash_converted" ); disp_status ( " " ); ABORT; } } disp_status ( " " ); /* Write out the new parameter values */ if (nfarg) { P_SETPAR ( "nf", floor (ni*(nf / ncomp)+0.5) ); P_SETPAR ( "ni", 1.0 ); } else { P_SETPAR ( "nf", ncomp ); P_SETPAR ( "ni", floor ((nf / ncomp)+0.5) ); } if ( arraydim > 1 ) arrayelemts = 2; else arrayelemts = 1; P_SETPAR ( "arrayelemts", arrayelemts ); if (nfarg) arraydim = floor(((arraydim/ni)*ncomp)+0.5); else arraydim *= floor ((nf / ncomp)+0.5); P_SETPAR ( "arraydim", arraydim ); if ( ( r = P_setreal ( CURRENT, "cf", (float)1, 1 ) ) ) { P_err ( r, "cf", ":" ); ABORT; } /* Display new parameters, and clear status on screen */ appendvarlist("nf,ni,arrayelemts,arraydim,cf"); Winfoprintf("Flash Convert reformatting completed."); /* Normal, successful return */ RETURN; /* Since this item was defined within this routine, get rid of it now */ #undef P_SETPAR } /* End function flashc */
int cmdHistory(int argc, char *argv[], int retc, char *retv[]) { char path[MAXPATH]; if (argc == 1) { if (globalCmdHistory) sprintf(path,"%s/cmdHistory",userdir); if (retc) { retv[0] = (globalCmdHistory) ? newString("") : newString(path); if (retc > 1) retv[1] = (localCmdHistory) ? newString("") : newString(localCmdHistoryPath); } else Winfoprintf("Global history is %s. Local history is %s", (globalCmdHistory) ? path : "off", (localCmdHistory) ? localCmdHistoryPath : "off"); doThisCmdHistory = 0; RETURN; } if (Bnmr) RETURN; if (argc == 2) /* This handles global cmdHistory and the 'skip' case */ { if ( ! strcmp(argv[1],"on") ) /* write to global cmdHistory */ { if (globalCmdHistory == NULL) { sprintf(path,"%s/cmdHistory",userdir); globalCmdHistory = fopen(path,"w"); } doCmdHistory = 1; doThisCmdHistory = 0; } else if ( ! strcmp(argv[1],"append") ) /* append to global cmdHistory */ { if (globalCmdHistory == NULL) { sprintf(path,"%s/cmdHistory",userdir); globalCmdHistory = fopen(path,"a"); } doCmdHistory = 1; doThisCmdHistory = 0; } else if ( ! strcmp(argv[1],"off") ) { if (globalCmdHistory) { fclose(globalCmdHistory); globalCmdHistory = NULL; } if ( ! localCmdHistory) doCmdHistory = 0; doThisCmdHistory = 0; } else if ( ! strcmp(argv[1],"skip") ) /* allow macros to avoid being added to the history */ { doThisCmdHistory = 0; } else { Wscrprintf("%s usage error: %s unknown argument",argv[0], argv[1]); } } else if (argc == 3) /* This handles local cmdHistory */ { if ( ! strcmp(argv[1],"on") ) { if ( localCmdHistory ) fclose(localCmdHistory); localCmdHistory = fopen(argv[2],"w"); if ( localCmdHistory ) { doCmdHistory = 1; doThisCmdHistory = 0; strcpy(localCmdHistoryPath,argv[2]); } else { Werrprintf("%s failed to open command history file %s",argv[0], argv[2]); } } else if ( ! strcmp(argv[1],"append") ) { if ( localCmdHistory ) fclose(localCmdHistory); localCmdHistory = fopen(argv[2],"a"); if ( localCmdHistory ) { doCmdHistory = 1; doThisCmdHistory = 0; strcpy(localCmdHistoryPath,argv[2]); } else { Werrprintf("%s failed to open command history file %s",argv[0], argv[2]); } } else if ( ! strcmp(argv[1],"off") ) { if (localCmdHistory) fclose(localCmdHistory); localCmdHistory = NULL; if ( ! globalCmdHistory) doCmdHistory = 0; doThisCmdHistory = 0; } else { Wscrprintf("%s usage error: %s unknown argument",argv[0], argv[1]); } } else { Wscrprintf("%s usage error: too many arguments",argv[0]); } RETURN; }
void setmaxminstep(varInfo *v, double *value, char *name ) { double temp, round; double cval, maxv, minv, stepv; int pindex; int error = 0; /* If P_MMS bit set, use maxVal, minVal, etc. fields as indicies into system global paramters "parmax", "parmin", etc. extracting the desired value from the appropriate array. */ cval = *value; if (v->prot & P_MMS) { pindex = (int) (v->minVal+0.1); if (P_getreal( SYSTEMGLOBAL, "parmin", &minv, pindex )) minv = -1.0e+30; pindex = (int) (v->maxVal+0.1); if (P_getreal( SYSTEMGLOBAL, "parmax", &maxv, pindex )) maxv = 1.0e+30; pindex = (int) (v->step+0.1); if (P_getreal( SYSTEMGLOBAL, "parstep", &stepv, pindex )) stepv = 0.0; } else { minv = v->minVal; maxv = v->maxVal; stepv = v->step; } if (cval > maxv) { /* Only report error if it is significant */ if ( !((cval > 1.0) && ((cval - maxv) < 1e-10)) ) error = 1; /* error for exceeding maximum */ *value = maxv; } else if (cval < minv) { error = 2; /* error for below minimum */ *value = minv; } /* Two very special cases follow */ if (stepv < -1.0) setfn( value ); /* fn */ else if (stepv < 0.0) setsw( value, -stepv ); /* sw */ else if (stepv != 0.0) { double minval; /* This section needs to handle the following cases: Case 1: setlimit('val',1,-1,2) val=0 => val=1 and val=-1 => val=-1 Case 2: setlimit('val',1e7,-1e7,0.1) val=0 => val=0, not some round-off value like 5.45e-15. Case 3: setlimit('val',1e7,-1e7,360/8192) should round-off correctly. For this case, if the step size if < 1.0, then don't try to offset the value from the minimum, as is required for case 1. Case 4: setlimit('val',64000,-64000,1) for an integer like lsfid. Without case 4, lsfid=-8 yields -9. This is also true for reals with a step of 1 */ if (stepv < 1.0) minval = 0.0; /* Case 3 */ else minval = minv; /* Case 1 */ if ( ((v->subtype == ST_INTEGER) && (stepv < 1.5) ) || (stepv == 1.0) ) minval = 0.0; /* Case 4 */ round = stepv / 2.0; if ( *value < 0.0) temp = ( (*value-minval) - round) / stepv; else temp = ( (*value-minval) + round) / stepv; if (fabs(temp) < MAXINT) *value = stepv * (double) ((int) temp) + minval; if (*value > maxv) *value -= stepv; else if (*value < minv) *value += stepv; if ( fabs(*value) < round ) /* handle Case 2 */ { *value = 0.0; } } if (v->subtype == ST_INTEGER) *value = (double) ((int) *value); if (error == 1) Winfoprintf("Parameter %s reset to maximum of %g",name, *value); else if (error == 2) Winfoprintf("Parameter %s reset to minimum of %g",name, *value); #ifdef VNMRJ if (cval != *value) appendvarlist(name); #endif }
/*-------------------------------------------------------------------------- | | macroLd | | This command loads a macro into cache memory. If the macro | of the same name already exists in the cache memory, it is first | deleted before the new macro is loaded. | /+--------------------------------------------------------------------------*/ int macroLd(int argc, char *argv[], int retc, char *retv[]) { int i; node *codeTree; int res; int ret = 0; if (argc == 1) { Werrprintf("Usage -- %s('macro1'[,'macro2',...])",argv[0]); ABORT; } else { if (retc > 1) WstoreMessageOn(); for (i=1;i<argc;i++) { TPRINT1("macroLd: removing macro \"%s\"\n",argv[i]); rmMacro(argv[i]); renameAllocation("newMacro","tmpSavenewMacro"); if (argv[i][0] == '/') { char *s; s = strrchr(argv[i],'/'); rmMacro(s+1); if ( (codeTree = loadMacro(argv[i],NOSEARCH, &res)) ) { TPRINT1("macroLd: saving macro \"%s\"\n",s+1); saveMacro(s+1,codeTree,PERMANENT); ret = 1; if (!retc) Winfoprintf("Loaded macro '%s'",s+1); else if (retc > 1) sprintf(storeMessage,"Loaded macro '%s'",s+1); } } else if ( (codeTree = loadMacro(argv[i],SEARCH, &res)) ) { TPRINT1("macroLd: saving macro \"%s\"\n",argv[i]); saveMacro(argv[i],codeTree,PERMANENT); ret = 1; if (!retc) Winfoprintf("Loaded macro '%s'",argv[i]); else if (retc > 1) sprintf(storeMessage,"Loaded macro '%s'",argv[i]); } releaseAllWithId("newMacro"); renameAllocation("tmpSavenewMacro","newMacro"); } if (retc) { retv[0] = intString( ret ); if (retc > 1) { retv[1] = newString(storeMessage); WstoreMessageOff(); } } } RETURN; }
int wrspec(int argc, char *argv[], int retc, char *retv[] ) { char *cmd_name, *outfile_name; char ow_prompt[ MAXPATHL + 20 ], ow_ans[ 4 ]; int elem1_num, elem2_num, elem3_num, elem4_num, i, ival, np_out; int proctype; /* proctype for processing function type */ float *vdata, /* output data */ epscale = 0.0, rms = 0.0; double swmagic, tmp; FILE *tfile=NULL; /* retv[0]=0 ok; retv[0]=1 failed */ cmd_name = argv[ 0 ]; if (argc < MINNEW_ARGS) /* compare MAXNEW_ARGS in wrspec_args */ { Werrprintf( "Usage: %s( 'file_name' <, trace number > )", cmd_name); if (retc>0) retv[0] = intString(1); return( 0 ); } outfile_name = argv[ WRFILE_ARG ]; /* address of (output) file name: argv[1] */ /* do avg_scale if asked for it */ if (strcmp(outfile_name, "expl_avg_scale")==0) { if (argc < 3) { if (retc>0) retv[0] = intString(1); return( 0 ); } if (calc_avg_scale( cmd_name, argv[2] ) != 0) { /* errors reported in function */ if (retc>0) retv[0] = intString(1); return( 0 ); } if (retc>0) retv[0] = intString(0); return( 0 ); } init2d(1,1); /* get data headers */ if ((datahead.status & S_SPEC) == 0) { Werrprintf("%s: data must be ft'd first", cmd_name); if (retc>0) retv[0] = intString(1); return( 0 ); } if (wrspec_args( argc, argv, &proctype, &elem1_num, &elem2_num, &elem3_num, &elem4_num ) != 0) { if (retc>0) retv[0] = intString(1); return( 0 ); /* `writefid_args' reports error */ /* depends on argc */ } EPRINT0(1,"calling wrspec...\n"); EPRINT1(1," wrspec: proctype %d, ", proctype); EPRINT2(1,"trace numbers %d %d ",elem1_num,elem2_num); EPRINT2(1,"%d %d\n",elem3_num,elem4_num); /* if (proctype == 8) { outfile_name="ds"; for dmg; use outfile_name="dmg" and proctype=2? } else { below; } */ vdata=(float *)malloc((fn/2) * sizeof(float)); if (!vdata) { Werrprintf( "ddph: memory allocation failure" ); if (retc>0) retv[0] = intString(1); return( 0 ); } if ( strcmp( outfile_name, "ds") != 0) { /* Handle situation where the output file is already present. */ if (access( outfile_name, F_OK ) == 0) { if (!Bnmr) { sprintf( &ow_prompt[ 0 ], "OK to overwrite %s? ", outfile_name); W_getInputCR( &ow_prompt[ 0 ], &ow_ans[ 0 ], sizeof( ow_ans ) - 1); if (ow_ans[ 0 ] != 'Y' && ow_ans[ 0 ] != 'y') { free((char*) vdata); Winfoprintf( "%s: operation aborted", cmd_name ); if (retc>0) retv[0] = intString(1); return( 0 ); } } ival = unlink( outfile_name ); if (ival != 0) { free((char*) vdata); Werrprintf( "%s: cannot remove %s", cmd_name, outfile_name ); if (retc>0) retv[0] = intString(1); return( 0 ); } } tfile = fopen( outfile_name, "w" ); /* open file */ if (tfile == NULL) { free((char*) vdata); Werrprintf( "%s: problem opening %s", cmd_name, outfile_name ); if (retc>0) retv[0] = intString(1); return( 0 ); } } /* end "not ds" mode */ if (proctype==2 || proctype==4 || proctype==5 || proctype==7) { if (wrspec_find_epscale( &epscale, proctype, elem1_num, elem2_num) != 0) { Werrprintf( "%s: find epscale failed", cmd_name); free((char*) vdata); if (retc>0) retv[0] = intString(1); return( 0 ); } } if (proctype != 5) { if (wrspec_calcdata(cmd_name, proctype, elem1_num, elem2_num, elem3_num, elem4_num, vdata) != 0) { free((char*) vdata); if (retc>0) retv[0] = intString(1); return( 0 ); /* calcdata reports error */ } if (wrspec_output( cmd_name, outfile_name, tfile, vdata, proctype, epscale, &rms) != 0) { if (retc>0) retv[0] = intString(1); return( 0 ); /* write output to file or 'ds' */ } } else { /* proctype == 5 */ if ( (ival=P_getreal(CURRENT, "gzwin", &swmagic, 1)) ) { swmagic = 100.0; } else { if (swmagic < 0.0) swmagic = -swmagic; tmp = 100.0 * 1.0/((float) (fn/2-1)); if (swmagic < tmp) swmagic = tmp; if (swmagic > 100.0) swmagic = 100.0; } swmagic /= 100.0; np_out = fn/2 - 2 * (int) ((1.0 - ((float) swmagic)) * ((float) (fn/4)) ); ival = ((datahead.nblocks + 1) / 2) - 2; /* ival is gzsize, number of z shims */ if ( epscale < NEW_AMP_TOL ) { fprintf( tfile, "exp 4\n %d %d\nFrequency (hz) vs Phase\n", ival, np_out ); } else { fprintf( tfile, "exp 4\n %d %d\nFrequency (hz) vs Field (hz)\n", ival, np_out ); } for (i=0; i<ival; i++) { fprintf( tfile, "\n%d 0 0 0\n", i+1 ); elem3_num = 2 * i + 3; elem4_num = 2 * i + 4; if (wrspec_calcdata(cmd_name, 4, elem1_num, elem2_num, elem3_num, elem4_num, vdata) != 0) { if (retc>0) retv[0] = intString(1); return( 0 ); /* calcdata reports error; use proctype=4 */ } rms = (float) elem3_num; if (wrspec_output( cmd_name, outfile_name, tfile, vdata, proctype, epscale, &rms) != 0) { if (retc>0) retv[0] = intString(1); return( 0 ); /* write output to file or 'ds' */ } } } if (strcmp( outfile_name, "ds") != 0) fclose( tfile ); free((char*) vdata); if (retc>0) retv[0] = intString(0); if (retc>1) retv[1] = realString( ((double)rms) ); EPRINT0(1,"wrspec done!\n"); return( 0 ); }
/*----------------------------------------------- | | | 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 appdir(int argc, char *argv[], int retc, char *retv[]) { static char resetCmd[MAXPATH]; static int sendCmd = 0; static int sendDirs = 1; if (argc > 1) { if ( ! strcmp(argv[1],"file")) { char filepath[MAXPATH]; char operator[MAXPATH]; /* Reset appdirs */ lastOperator[0] = '\0'; appdirRight = -1; getappdirPaths(); filepath[0] = '\0'; if (P_getstring(GLOBAL,"operator",operator,1,MAXPATH-1)) { strcpy(operator,UserName); } if (appdirRight) { sprintf(filepath,"%s/persistence/appdir_%s", userdir, operator); if ( access(filepath,R_OK) ) { filepath[0] = '\0'; } } if ( (filepath[0] == '\0') && strcmp(operator,UserName) ) { P_setstring(GLOBAL,"operator",UserName,1); appdirRight = rightsEval("caneditappdir"); if (appdirRight) { sprintf(filepath,"%s/persistence/appdir_%s", userdir, UserName); if ( access(filepath,R_OK) ) { filepath[0] = '\0'; } } P_setstring(GLOBAL,"operator",operator,1); appdirRight = rightsEval("caneditappdir"); } if (filepath[0] == '\0') { getAppdirTemplate(filepath); } if (retc >= 1) retv[0] = newString(filepath); else Winfoprintf("application directory file is %s",filepath); } else if ( ! strcmp(argv[1],"index")) { if (argc == 3) { int index; int res = 0; for (index=1; index <= appdirNumPaths; index++) { if ( ! strcmp(argv[2], appdirVal(appdirPaths,index) ) ) { res = index; break; } } if (retc >= 1) retv[0] = intString(res); else if (res == 0) Winfoprintf("%s is not an appdir",argv[2]); else Winfoprintf("%s is appdir number %d of %d",argv[2],res,appdirNumPaths); } else { Werrprintf("Usage: %s('index',directory)", argv[0]); ABORT; } } else if ( ! strcmp(argv[1],"info")) { if (argc == 2) { if (retc >= 1) retv[0] = intString(appdirNumPaths); else Winfoprintf("There are %d application directories",appdirNumPaths); } else { int index = atoi(argv[2]); if ( (index <= 0) || (index > appdirNumPaths) ) { Werrprintf("Application directory %s does not exist. Second argument must be between 1 and %d", argv[2],appdirNumPaths); ABORT; } if (retc) { retv[0] = newString( appdirVal(appdirLabels,index) ); if (retc >= 2) { retv[1] = newString( appdirVal(appdirPaths,index) ); } } else { Winfoprintf("Label for application directory %d is %s", index, appdirVal(appdirLabels,index)); } } } #ifdef TODO else if ( ! strcmp(argv[1],"infoall")) { /* Return onOff, path and label */ } #endif else if ( ! strcmp(argv[1],"reset")) { char *saveAppdirPaths; lastOperator[0] = '\0'; saveAppdirPaths = newStringId(appdirPaths,"apptmp"); if (argc > 2) { /* With more than 1 argument, it is called from the login panel */ P_setstring(GLOBAL,"operator",argv[2],1); #ifdef VNMRJ { int num, index; double dval; char msg[MAXSTR]; if (!P_getreal(GLOBAL, "jviewports", &dval, 1)) { num = (int) (dval+0.1); for (index=1; index <= num; index++) { if (index != VnmrJViewId) { sprintf(msg,"VP %d setvalue('operator', '%s', 'global') vnmrjcmd('pnew','operator') appdir('update')\n",index,argv[2]); writelineToVnmrJ("vnmrjcmd",msg); } } } } appendJvarlist("operator"); // writelineToVnmrJ("pnew","1 operator"); #endif appdirRight = -1; /* check rights on next call to appdirFind */ getappdirPaths(); sprintf(resetCmd,"operatorlogin('%s','%s')\n",argv[3],argv[4]); sendCmd = 1; } else { /* With only 1 argument, it is called from the appdir editor */ getappdirPaths(); } #ifdef VNMRJ if (strcmp(saveAppdirPaths, appdirPaths) ) { /* Only update VJ panels if the appdirs has changed * Java will send an appdir('send') when it is ready * for the new appdir directories */ writelineToVnmrJ("vnmrjcmd appdir", "0"); sendDirs = 1; } if (sendCmd && ! sendDirs) { execString(resetCmd); sendCmd = 0; } { /* Update other viewports */ int num, index; double dval; char msg[MAXSTR]; if (!P_getreal(GLOBAL, "jviewports", &dval, 1)) { num = (int) (dval+0.1); for (index=1; index <= num; index++) { if (index != VnmrJViewId) { sprintf(msg,"VP %d appdir('update')\n",index); writelineToVnmrJ("vnmrjcmd",msg); } } } } #endif releaseWithId("apptmp"); } #ifdef VNMRJ else if ( ! strcmp(argv[1],"send")) { /* VJ has requested the new appdirs */ if (sendDirs) { sendAppdirs(); appendJvarlist("operator"); sendDirs = 0; } // writelineToVnmrJ("pnew","1 operator"); if (sendCmd) { execString(resetCmd); sendCmd = 0; } } else if ( ! strcmp(argv[1],"update")) { /* get current appdirs */ lastOperator[0] = '\0'; getappdirPaths(); } #endif } RETURN; }
int AspFrame::testSession(char *path, int &ntraces, int &straces, int &dataok) { ntraces=straces=dataok=0; struct stat fstat; if(stat(path, &fstat) != 0) { Winfoprintf("Error: cannot find %s.",path); return 0; } FILE *fp; if(!(fp = fopen(path, "r"))) { Winfoprintf("Failed to open session file %s.",path); return 0; } char buf[MAXSTR2], words[MAXWORDNUM][MAXSTR2], *tokptr; int nw; int count=0; dataok=1; char str[MAXSTR2]; string root=""; spAspTrace_t trace; while (fgets(buf,sizeof(buf),fp)) { if(strlen(buf) < 1 || buf[0] == '#') continue; // break buf into tok of parameter names nw=0; tokptr = strtok(buf, ", :\n\r"); while(tokptr != NULL) { if(strlen(tokptr) > 0) { strcpy(words[nw], tokptr); nw++; } tokptr = strtok(NULL, ", :\n\r"); } if(nw < 2) continue; if(strcasecmp(words[0],"root")==0 && nw > 1) { root=string(words[1]); if(root.find_last_of("/") == root.length()-1) root=root.substr(0,root.length()-1); } else if(nw > 11 && strstr(words[0],"load") == words[0]) { if(root != "" && words[2][0] != '/') { strcpy(str,words[2]); sprintf(words[2],"%s/%s",root.c_str(),str); } trace = spAspTrace_t(new AspTrace(words,nw)); if(trace != nullAspTrace && trace->getData()) { ntraces++; count++; } else { Winfoprintf("Error to load %s",buf); dataok=0; } } else if(nw > 11 && (strstr(words[0],"add") == words[0] || strstr(words[0],"sub") == words[0])) { if(root != "" && words[2][0] != '/') { strcpy(str,words[2]); sprintf(words[2],"%s/%s",root.c_str(),str); } trace = spAspTrace_t(new AspTrace(words,nw)); if(trace != nullAspTrace && trace->getData()) { count++; } else { Winfoprintf("Error to load %s",buf); dataok=0; } } else if(strcasecmp(words[0],"displayed_traces")==0 && nw > 1) { //e.g. displayed_traces: 1 2 3 4 5 6 7 8 9 10 straces = nw-1; } } if(straces==0) straces=ntraces; fclose(fp); return count; }
int AspFrame::saveSession(char *path, bool full) { // path is a full path for session file, or the parent directory of session file. // path file or directory may not exist struct stat fstat; string dir = ""; char sessionFile[MAXSTR2]; if (stat(path, &fstat) != 0) { // path does not exist if(full) { dir = string(path); sprintf(sessionFile,"%s/aspSession",path); } else { string tmp = string(path); dir = tmp.substr(0,tmp.find_last_of("/")); sprintf(sessionFile,"%s",path); } // make sure dir exists struct stat dstat; if (stat(dir.c_str(), &dstat) != 0) { char str[MAXSTR2]; (void)sprintf(str, "mkdir -p %s \n", dir.c_str()); (void)system(str); } } else if(fstat.st_mode & S_IFDIR) { // is a directory dir = string(path); sprintf(sessionFile,"%s/aspSession",path); } else { string tmp = string(path); dir = tmp.substr(0,tmp.find_last_of("/")); sprintf(sessionFile,"%s",path); } FILE *fp; if(!(fp = fopen(sessionFile, "w"))) { Winfoprintf("Failed to create session file %s.",sessionFile); return 0; } time_t clock; char *tdate; char datetim[26]; clock = time(NULL); tdate = ctime(&clock); if (tdate != NULL) { strcpy(datetim,tdate); datetim[24] = '\0'; } else { strcpy(datetim,"???"); } spAspDataInfo_t dataInfo = getDefaultDataInfo(); fprintf(fp,"# Created by %s on %s at machine %s.\n",UserName,datetim,HostName); // save display flags fprintf(fp,"#disFlag,axisFlag,annoFlag,specFlag,peakFlag,integFalg\n"); fprintf(fp,"disFlags: %d %d %d %d %d %d\n",disFlag,axisFlag,annoFlag,specFlag,peakFlag,integFlag); // save traces in order of traceInd fprintf(fp,"#number_of_traces, n, vp, vo\n"); fprintf(fp,"number_of_traces: %d %f %f\n",traceList->getSize(), dataInfo->getVpos()-2,dataInfo->getVoff()); if(full) { // save trace data (full session) // save current parameters char procPath[MAXSTR2]; sprintf(procPath,"%s/procpar",dir.c_str()); saveProcpar(procPath); fprintf(fp,"procpar: %s\n",procPath); spAspTrace_t trace = traceList->getTraceByInd(0); string root = ""; if(trace != nullAspTrace) { trace->save(dir); root = trace->rootPath; if(root != "") fprintf(fp,"root: %s\n",root.c_str()); } fprintf(fp,"# traceInd,fdfpath,label,dataKey,dataInd,minX,maxX,scale,vp,color,labelFlag\n"); int i; for(i=0;i<traceList->getSize(); i++) { trace = traceList->getTraceByInd(i); if(trace != nullAspTrace) { if(i>0) trace->save(dir); fprintf(fp,"%s\n",trace->toString(root).c_str()); list<spAspTrace_t> *sumList = trace->getSumTraceList(); list<spAspTrace_t>::iterator itr; int ind = trace->traceInd+1; for(itr=sumList->begin(); itr != sumList->end(); ++itr) { string color = (*itr)->colorStr; double min = (*itr)->getMinX() + (*itr)->getShift(); double max = (*itr)->getMaxX() + (*itr)->getShift(); fprintf(fp,"color %d %s %f %f\n",ind,color.c_str(),min,max); } } } } else { spAspTrace_t trace = traceList->getTraceByInd(0); string root = ""; if(trace != nullAspTrace) { root = trace->rootPath; if(root != "") fprintf(fp,"root: %s\n",root.c_str()); } fprintf(fp,"# traceInd,fdfpath,label,dataKey,dataInd,minX,maxX,scale,vp,color,labelFlag\n"); int i; for(i=0;i<traceList->getSize(); i++) { trace = traceList->getTraceByInd(i); if(trace != nullAspTrace) { fprintf(fp,"%s\n",trace->toString(root).c_str()); list<spAspTrace_t> *sumList = trace->getSumTraceList(); list<spAspTrace_t>::iterator itr; int ind = trace->traceInd+1; for(itr=sumList->begin(); itr != sumList->end(); ++itr) { if((*itr)->path != "") { fprintf(fp,"%s\n",(*itr)->toString(root).c_str()); } else { string color = (*itr)->colorStr; double min = (*itr)->getMinX() + (*itr)->getShift(); double max = (*itr)->getMaxX() + (*itr)->getShift(); fprintf(fp,"color %d %s %f %f\n",ind,color.c_str(),min,max); } } } } } fprintf(fp,"#indexes for displayed_traces\n"); fprintf(fp,"displayed_traces: %s\n",selTraceList->getIndList().c_str()); fprintf(fp,"#\n"); char file[MAXSTR2]; spAspFrame_t frame = AspFrameMgr::get()->getFrame(this); if(annoFlag & ANN_ROIS) { // save Rois sprintf(file,"%s/Rois",dir.c_str()); fprintf(fp,"roiFile: Rois\n"); getRoiList()->saveRois(file); } if(annoFlag & ANN_ANNO) { // save annotations sprintf(file,"%s/annos",dir.c_str()); fprintf(fp,"annoFile: annos\n"); AspDisAnno::save(frame, file); } if(peakFlag) { // save peaks sprintf(file,"%s/peaks",dir.c_str()); fprintf(fp,"peakFile: peaks\n"); AspDisPeaks::save(frame, file); } if(integFlag) { // save integrals sprintf(file,"%s/integs",dir.c_str()); fprintf(fp,"integFile: integs\n"); AspDisInteg::save(frame, file); } fclose(fp); return 1; }
int vnmr_unlock(int argc, char *argv[], int retc, char *retv[] ) { char host_of_lock[ MAXPATHL ], jexpcmd[ 16 ], lock_file_name[ MAXPATHL ]; int expn, ival, mode_of_lock, pid_of_lock, force; expn = check_unlock_args( argc, argv, &force ); if (expn == expdir_to_expnum(curexpdir)) RETURN; if (expn < 1) ABORT; if (get_secondary_lock( expn, SEC_LOCK_COUNT ) != 0) { Werrprintf( "%s: cannot obtain secondary lock", argv[ 0 ] ); ABORT; } get_primary_lockfile( expn, userdir, &lock_file_name[ 0 ] ); ival = verify_primary_lock( &lock_file_name[ 0 ], &mode_of_lock, &host_of_lock[ 0 ], &pid_of_lock ); remove_secondary_lock( expn ); if (ival != 0) { if (access( &lock_file_name[ 0 ], F_OK ) == 0) unlink( &lock_file_name[ 0 ] ); sprintf( &jexpcmd[ 0 ], "jexp(%d)\n", expn ); execString( &jexpcmd[ 0 ] ); RETURN; } if (!force && (mode_of_lock == ACQUISITION)) { Werrprintf( "%s: cannot remove acquisition lock", argv[ 0 ] ); ABORT; } disp_status( "UNLOCK " ); if (!force && (strcmp( &host_of_lock[ 0 ], &HostName[ 0 ] ) != 0)) { Werrprintf( "%s: experiment locked by remote host %s", argv[ 0 ], &host_of_lock[ 0 ] ); disp_status( " " ); ABORT; } ival = find_pid( pid_of_lock, argv[ 0 ] ); if ( ival < 0) { disp_status( " " ); ABORT; } else if (!force && (ival > 0)) { Werrprintf( "%s: experiment locked by active process", argv[ 0 ] ); disp_status( " " ); ABORT; } ival = unlink( &lock_file_name[ 0 ] ); if (ival != 0) { Werrprintf( "%s: unable to remove lock file", argv[ 0 ] ); disp_status( " " ); ABORT; } Winfoprintf( "experiment %d unlocked", expn ); disp_status( " " ); sprintf( &jexpcmd[ 0 ], "jexp(%d)\n", expn ); execString( &jexpcmd[ 0 ] ); RETURN; }
/* rms rms average of data */ static int wrspec_output( char *cmd_name, char *outfile_name, FILE *tfile, float *vdata, int proctype, float epscale, float *rms ) { float phdiffdiff, swstep, swvalue, eps_tmp; double swmagic, phmagic, tmp; int ival, npstart, npfin, j, npxx, epscale_flag; float ph_cut, ph_int, ph_offset, ph_old, ph_cen; npxx = fn; if ( (ival=P_getreal(CURRENT, "gzwin", &swmagic, 1)) ) { swmagic = 100; } if (swmagic < 0) { swmagic = -swmagic; } tmp = 100.0 / ((float)(npxx/2-1)); if (swmagic < tmp) { swmagic = tmp; } if (swmagic > 100.0) { swmagic = 100; } swmagic /= 100.0; /* could keep gzwin, set everthing outside to zero */ phmagic = 270.0; if ( (P_getreal(CURRENT, "wrspec_phcut", &phmagic, 1)) ) { phmagic = 270; if ((proctype==1) && (ival != 0)) phmagic=361; /* do not use phmagic */ } ph_cut = (float) phmagic; if (ph_cut < 0) { ph_cut = -ph_cut; } if (ph_cut < 30) { ph_cut = 270; } EPRINT2(1," wrspec: gzwin %g, phcut %g\n", (float)(100 * swmagic), ph_cut); /* assume data is REAL_NUMBERS (float) */ swvalue = -(sw/2.0) * ((float) (npxx/2-1))/((float) (npxx/2)); swstep = sw / ((float) (npxx/2)); /* same denominator */ npstart = (int) ( (1.0 - ((float) swmagic)) * ((float) (npxx/4)) ); npfin = npxx/2 - npstart; swvalue += swstep * (0.5 + (float)(npstart)); /* if (proctype==0) swvalue += (rflrfp - sw/2); */ /* put in checks - $phcut related to $npts, may be too few points?? */ /* ph_cut = 270.0; see above */ ph_int = 0.0; ph_offset = 0.0; eps_tmp = epscale; if (eps_tmp < 0.0) { eps_tmp = -eps_tmp; } if (eps_tmp < NEW_AMP_TOL) { epscale_flag = 0; } else { epscale_flag = 1; } if ( strcmp( outfile_name, "ds") != 0) { /* using file mode */ if (proctype == 1) { fprintf( tfile, "exp 4\n 1 %d\nFrequency (hz) vs Phase\n\n1 0 0 0\n", (npfin - npstart) ); } else if (proctype == 2 || proctype == 7) { if ( epscale_flag != 0) { fprintf( tfile, "exp 4\n 1 %d\nFrequency (hz) vs Field (hz)\n\n1 0 0 0\n", (npfin - npstart) ); } else { fprintf( tfile, "exp 4\n 1 %d\nFrequency (hz) vs Phase\n\n1 0 0 0\n", (npfin - npstart) ); } } else if (proctype == 4) { if ( epscale_flag != 0) { fprintf( tfile, "exp 4\n 1 %d\nFrequency (hz) vs Field (hz)\n\n1 0 0 0\n", (npfin - npstart) ); } else { fprintf( tfile, "exp 4\n 1 %d\nFrequency (hz) vs Phase\n\n1 0 0 0\n", (npfin - npstart) ); } } else if (proctype != 5) { fprintf( tfile, "exp 4\n 1 %d\nFrequency (hz) vs Amplitude\n\n1 0 0 0\n", (npfin - npstart) ); } if ((proctype==1 || proctype==2 || proctype==4 || proctype==5) && ph_cut < 360.0) { ph_old = vdata[npstart]; for (j = npstart + 1; j < npfin; j++ ) { phdiffdiff = vdata[j] - ph_old; if (phdiffdiff < -ph_cut) { ph_offset += 360.0; } if (phdiffdiff > ph_cut) { ph_offset -= 360.0; } ph_old = vdata[j]; vdata[j] += ph_offset; ph_int += vdata[j]; } if (((float) phmagic >= 0.0) && ((float)swmagic < (1.0-tmp/100.0))) { if (proctype==4 || proctype==5) { ph_cen = 0.25 * (vdata[npxx/4-2] + vdata[npxx/4+1]); /* ph_cen += 0.25 * (vdata[npstart] + vdata[npfin-1]); */ /* ival = (int)( 0.01 * ((float)(npfin - npstart)) ); ph_cen = 0.25 * (vdata[npxx/4-2] + vdata[npxx/4+1]); ph_cen += 0.25 * (vdata[npstart + ival] + vdata[npfin - 1 - ival]); */ ph_cen += 0.05 * (vdata[npstart+0] + vdata[npfin-1]); ph_cen += 0.05 * (vdata[npstart+1] + vdata[npfin-2]); ph_cen += 0.05 * (vdata[npstart+2] + vdata[npfin-3]); ph_cen += 0.05 * (vdata[npstart+3] + vdata[npfin-4]); ph_cen += 0.05 * (vdata[npstart+4] + vdata[npfin-5]); } else { ph_cen = 0.25 * (vdata[npxx/4-3] + vdata[npxx/4-2] + vdata[npxx/4+1] + vdata[npxx/4+2]); } EPRINT1(1," wrspec: b0 recentered by %g degrees\n", ph_cen); for (j=npstart; j < npfin; j++ ) { vdata[j] -= ph_cen; } } else { EPRINT0(1," wrspec: b0 not recentered\n"); } if ((epscale_flag != 0) && (proctype==2 || proctype==4 || proctype==5)) { for (j = npstart; j < npfin; j++) vdata[j] *= epscale; } } /* end proctype == 1, 2, 4 */ if (proctype==7 && ph_cut < 360.0) for (j = npstart; j < npfin; j++) vdata[j] *= epscale; for (j=npstart; j < npfin; j++ ) { fprintf( tfile, "%g %g\n", swvalue, vdata[j] ); swvalue += swstep; } } /* end != "ds" */ else { Winfoprintf( "%s: using ds mode", cmd_name ); EPRINT0(1," wrspec: using ds mode"); ph_cen = 360.0; if ((proctype==1 || proctype==2 || proctype==4 || proctype==5) && ph_cut < 360.0) { ph_old = vdata[0]; for (j = 1; j < npxx/2; j++ ) { /* use all data */ phdiffdiff = vdata[j] - ph_old; if (phdiffdiff < -ph_cut) { ph_offset += 360.0; } if (phdiffdiff > ph_cut) { ph_offset -= 360.0; } ph_old = vdata[j]; vdata[j] += ph_offset; ph_int += vdata[j]; } if ((epscale_flag != 0) && (proctype==2 || proctype==4 || proctype==5)) { for (j = 0; j < npxx/2; j++) { vdata[j] *= epscale; } ph_cen *= epscale; /* min must be less than this */ } } for (j = npstart; j < npfin; j++) { /* use only points in window */ if (vdata[j] < ph_cen) { ph_cen = vdata[j]; } } for (j=0; j < npxx/2; j++ ) { vdata[j] -= ph_cen; } EPRINT1(1, " wrspec: b0 recentered by %g degrees\n", ph_cen ); /* if (proctype == 8) { write into dgm_spectrum[j]; } else { below } */ ival = 0; if (proctype==5) ival = ((int)(*rms+1.5))/2-2; if ((spectrum = calc_spec(ival,0,FALSE,TRUE,&updateflag))==0) /* set spectrum ival+1 */ { Werrprintf("%s: spectrum %d not found", cmd_name, ival+1 ); return(-1); } for (j=0; j<npxx/2; spectrum[j] = vdata[j], j++); /* output to ds spectrum dislay */ /* sent to last spectrum calculated */ } /* end "ds" mode */ *rms = 0.0; for (j=npstart; j < npfin; j++ ) *rms += vdata[j] * vdata[j]; *rms = sqrtf( *rms / (float)(npfin - npstart) ); return( 0 ); }
int decc_compare(int argc, char *argv[], int retc, char *retv[]) { int i, same; char oe[MAXSTR],e[MAXSTR]; double otaus, taus, oampls, ampls, olimits, limits, oscales, scales; (void)argv; if (argc>1) debug=1; else debug=0; if (debug) Winfoprintf("decc_compare started"); same=1; for (i=1; i<53; i++) { if (P_getstring(GLOBAL, "enabled", e, i, MAXSTR) < 0) { Werrprintf("decc_compare: cannot find 'enabled'"); same=0; break; } if (P_getstring(GLOBAL, "o_enabled", oe, i, MAXSTR) < 0) { Werrprintf("decc_compare: cannot find 'o_enabled'"); same=0; break; } if (e[0] != oe[0]) { same=0; break; } if (P_getreal(GLOBAL, "taus", &taus, i) < 0) { Werrprintf("decc_compare: cannot find 'taus'"); same=0; break; } if (P_getreal(GLOBAL, "o_taus", &otaus, i) < 0) { Werrprintf("decc_compare: cannot find 'o_taus'"); same=0; break; } if (fabs(taus-otaus) > 1e-6) { same=0; break; } if (P_getreal(GLOBAL, "ampls", &ls, i) < 0) { Werrprintf("decc_compare: cannot find 'ampls'"); same=0; break; } if (P_getreal(GLOBAL, "o_ampls", &oampls, i) < 0) { Werrprintf("decc_compare: cannot find 'o_ampls'"); same=0; break; } if (fabs(ampls-oampls) > 1e-6) { same=0; break; } } if (same != 0) { for (i=1; i<8; i++) { if (P_getreal(GLOBAL, "limits", &limits, i) < 0) { Werrprintf("decc_compare: cannot find 'limits'"); same=0; break; } if (P_getreal(GLOBAL, "o_limits", &olimits, i) < 0) { Werrprintf("decc_compare: cannot find 'o_limits'"); same=0; break; } if (fabs(limits-olimits) > 5e-9) { same=0; break; } } } if (same != 0) { for (i=1; i<11; i++) { if (P_getreal(GLOBAL, "scales", &scales, i) < 0) { Werrprintf("decc_compare: cannot find 'scales'"); same=0; break; } if (P_getreal(GLOBAL, "o_scales", &oscales, i) < 0) { Werrprintf("decc_compare: cannot find 'o_scales'"); same=0; break; } if (fabs(scales-oscales) > 5e-9) { same=0; break; } } } if (same != 0) { if (P_getstring(GLOBAL, "decctool_fln", e, 1, MAXSTR) < 0) { Werrprintf("decc_compare: cannot find 'decctool_fln'"); same=0; } if (P_getstring(GLOBAL, "deccorig_fln", oe, 1, MAXSTR) < 0) { Werrprintf("decc_compare: cannot find 'deccorig_fln'"); same=0; } if ( strcmp(e,oe) ) { Winfoprintf("decc_compare: '%s' '%s'\n",e,oe); same=0; } } if (P_setreal(GLOBAL, "deccflag", (double)same, 7) < 0) { Werrprintf("decc_compare: cannot set deccflag[7]"); } appendvarlist("deccflag"); if (retc > 0) retv[0] = realString((double) same); 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; }
int AspFrame::loadSession(char *path) { struct stat fstat; string dir=""; char sessionFile[MAXSTR2],file[MAXSTR2]; if(stat(path, &fstat) != 0) { Winfoprintf("Error: cannot find %s.",path); return 0; } else if(fstat.st_mode & S_IFDIR) { // is a directory dir = string(path); sprintf(sessionFile,"%s/aspSession",path); } else { string tmp = string(path); dir = tmp.substr(0,tmp.find_last_of("/")); sprintf(sessionFile,"%s",path); } FILE *fp; if(!(fp = fopen(sessionFile, "r"))) { Winfoprintf("Failed to open session file %s.",sessionFile); return 0; } traceList->clearList(); selTraceList->clearList(); peakList->clearList(); integList->clearList(); annoList->clearList(); char buf[MAXSTR2], words[MAXWORDNUM][MAXSTR2], *tokptr; int nw, count=0; int ntraces = 0; char str[MAXSTR2]; string root=""; while (fgets(buf,sizeof(buf),fp)) { if(strlen(buf) < 1 || buf[0] == '#') continue; // break buf into tok of parameter names nw=0; tokptr = strtok(buf, ", :\n\r"); while(tokptr != NULL) { if(strlen(tokptr) > 0) { strcpy(words[nw], tokptr); nw++; } tokptr = strtok(NULL, ", :\n\r"); } if(nw < 2) continue; if(strcasecmp(words[0],"disFlags")==0 && nw > 4) { //e.g. disFlags: 0 132096 0 256 disFlag = atoi(words[1]); axisFlag = atoi(words[2]); annoFlag = atoi(words[3]); specFlag = atoi(words[4]); if(nw > 5) peakFlag = atoi(words[5]); if(nw > 6) integFlag = atoi(words[6]); } else if(strcasecmp(words[0],"disParams")==0 && nw > 1) { //e.g. disParams: 22.000000 8.000000 if(nw > 2) { P_setreal(CURRENT, "vp", atof(words[1]), 1); P_setreal(CURRENT, "vo", atof(words[2]), 1); } } else if(strcasecmp(words[0],"root")==0 && nw > 1) { root=string(words[1]); if(root.find_last_of("/") == root.length()-1) root=root.substr(0,root.length()-1); } else if(strcasecmp(words[0],"procpar")==0 && nw > 1) { P_read(CURRENT,words[1]); } else if(nw > 11 && strstr(words[0],"load") == words[0]) { if(root != "" && words[2][0] != '/') { strcpy(str,words[2]); sprintf(words[2],"%s/%s",root.c_str(),str); } //e.g. load 1 /tmp/spec.fdf spec1 spec1 0 -2.022703 14.022636 1.000000 0.000000 11 0 //e.g. load 2 /tmp/spec.fdf spec1 spec1 1 -2.022703 14.022636 1.000000 0.000000 11 0 // each line corresponds to a AspTrace spAspTrace_t trace = spAspTrace_t(new AspTrace(words,nw)); trace->rootPath=string(root); sprintf(str,"%s:%d",trace->dataKey.c_str(),trace->dataInd); string newKey = string(str); traceList->addTrace(newKey, trace); selTraceList->maxInd= traceList->getSize(); ntraces++; count++; } else if(nw > 11 && (strstr(words[0],"add") == words[0] || strstr(words[0],"sub") == words[0] || strstr(words[0],"rep") == words[0])) { if(root != "" && words[2][0] != '/') { strcpy(str,words[2]); sprintf(words[2],"%s/%s",root.c_str(),str); } //e.g. add 1 /tmp/spec.fdf spec1 spec1 0 -2.022703 14.022636 1.000000 0.000000 11 0 //e.g. sub 1 /tmp/spec.fdf spec1 spec1 1 -2.022703 14.022636 1.000000 0.000000 11 0 // each line corresponds to a AspTrace to be add/sub to a specified trace spAspTrace_t trace = spAspTrace_t(new AspTrace(words,nw)); trace->rootPath=string(root); int flag = (strstr(words[0],"sub") == words[0]) ? SUB_TRACE:ADD_TRACE; if(strstr(words[0],"rep") == words[0]) flag = REP_TRACE; spAspTrace_t sumTrace = traceList->getTraceByInd(atoi(words[1])-1); if(sumTrace != nullAspTrace) sumTrace->sumTrace(trace,flag); else { sprintf(str,"%s:%d",trace->dataKey.c_str(),trace->dataInd); string newKey = string(str); traceList->addTrace(newKey, trace); selTraceList->maxInd= traceList->getSize(); } count++; } else if(strcasecmp(words[0],"color")==0 && nw > 4) { spAspTrace_t trace = traceList->getTraceByInd(atoi(words[1])-1); if(trace != nullAspTrace) { double min = atof(words[3]); double max = atof(words[4]); string str = string(""); spAspTrace_t sumTrace = spAspTrace_t(new AspTrace(0,str,str,0,0,min,max)); sumTrace->colorStr=string(words[2]); list<spAspTrace_t> *sumList = trace->getSumTraceList(); sumList->push_back(sumTrace); } } else if(strcasecmp(words[0],"displayed_traces")==0 && nw > 1) { //e.g. displayed_traces: 1 2 3 4 5 6 7 8 9 10 int i; for(i=1; i<nw;i++) { spAspTrace_t trace = traceList->getTraceByInd(atoi(words[i])-1); if(trace != nullAspTrace) { trace->selected=false; selTraceList->addTrace(trace->getKeyInd(), trace); } } selTraceList->maxInd= traceList->getSize(); } else if(strcasecmp(words[0],"roiFile")==0 && nw > 1) { sprintf(file,"%s/%s",dir.c_str(),words[1]); loadRois(file); } else if(strcasecmp(words[0],"annoFile")==0 && nw > 1) { spAspFrame_t frame = AspFrameMgr::get()->getFrame(this); sprintf(file,"%s/%s",dir.c_str(),words[1]); AspDisAnno::load(frame, file); } else if(strcasecmp(words[0],"peakFile")==0 && nw > 1) { sprintf(file,"%s/%s",dir.c_str(),words[1]); spAspFrame_t frame = AspFrameMgr::get()->getFrame(this); AspDisPeaks::load(frame, file); } else if(strcasecmp(words[0],"integFile")==0 && nw > 1) { sprintf(file,"%s/%s",dir.c_str(),words[1]); spAspFrame_t frame = AspFrameMgr::get()->getFrame(this); AspDisInteg::load(frame, file); } } // display all traces if displayed_traces: is missing if(selTraceList->getSize() < 1) { for(int i=0; i<traceList->getSize(); i++) { spAspTrace_t trace = traceList->getTraceByInd(i); if(trace != nullAspTrace) { trace->selected=false; selTraceList->addTrace(trace->getKeyInd(), trace); } } } fclose(fp); if(specFlag) { AspMouse::setState(AspMouse::cursor1); Wsetgraphicsdisplay(""); } else { AspMouse::setState(AspMouse::noState); } getDefaultDataInfo(true); draw(); return count; }
int autocmd(int argc, char *argv[], int retc, char *retv[]) { char autodir[ MAXPATH+2 ], autoinfofil[ MAXPATH ], inputstr[ MAXPATH ]; char *pathptr; int autodir_defined; int l, r; FILE *autoinfoptr; /* This process must be able to write to $vnmrsystem/conpar... */ disp_status( "AUTO " ); /* Establish current value of AUTODIR */ autodir[ 0 ] = '\0'; /* Start with 0-length string */ if (argc < 2) /* No arguments, just command */ { r = P_getstring( GLOBAL, "autodir", &autodir[ 0 ], 1, MAXPATH ); autodir_defined = (r == 0); if ( autodir_defined ) autodir_defined = !(strlen( &autodir[ 0 ] ) < 1); if ( !autodir_defined ) W_getInput( "Enter automation directory name: ", &inputstr[ 0 ], MAXPATH ); else { /* * Pass a separate string to W_getInput so as to avoid * overwriting AUTODIR if a <CR> gets typed. */ Winfoprintf( "Automation directory is '%s'", &autodir[ 0 ] ); W_getInput( "Enter new name, or <CR> to keep current: ", &inputstr[ 0 ], MAXPATH ); if (inputstr[ 0 ] == '\0') strcpy(&inputstr[ 0 ], &autodir[ 0 ]); } } else /* Argument is value for AUTODIR */ { strcpy( &inputstr[ 0 ], argv[ 1 ] ); } l = strlen( &inputstr[ 0 ] ); if ( l <= MAXPATH-1) { if (inputstr[ 0 ] != '/') { pathptr = get_cwd(); l += strlen( pathptr ) + 1; if (l < MAXPATH-1 ) { strcpy(&autodir[ 0 ], pathptr); strcat(&autodir[ 0 ], "/"); strcat(&autodir[ 0 ], &inputstr[ 0 ]); } } else strcpy( &autodir[ 0 ], &inputstr[ 0 ] ); } if ( l > MAXPATH-1) { Werrprintf( "Too many characters in full pathname of automation directory" ); disp_status( " " ); ABORT; } /* Verify that 'autodir' is not the 0-length string; verify it is an absolute UNIX path name */ else if (l < 1) { Werrprintf("Error: value of automation directory not defined" ); disp_status( " " ); ABORT; } /* Make the automation directory if not present. All users get full access, barring umask. Abort if a problem. If using the SUN console, the PERROR output will go to the (hidden or closed) shelltool window - too bad!! */ if (access( &autodir[ 0 ], 0 ) != 0) if ( (r = mkdir( &autodir[ 0 ], 0777 )) ) { Werrprintf( "Error creating automation directory" ); perror( "make automation directory" ); disp_status( " " ); ABORT; } /* Now this process must be able to read, write and execute (search) the automation directory. */ if (access( &autodir[ 0 ], R_OK | W_OK | X_OK )) { Werrprintf( "Insufficent access to automation directory" ); disp_status( " " ); ABORT; } /* Create special automation experiments, exp1 through exp4 */ if (create_autoexps( &autodir[ 0 ] ) != 0) ABORT; /* Displayed status may be changed by creating experiments. */ disp_status( "AUTO " ); strcpy( &autoinfofil[ 0 ], &autodir[ 0 ] ); strcat( &autoinfofil[ 0 ], "/autoinfo" ); autoinfoptr = fopen( &autoinfofil[ 0 ], "w+" ); if (autoinfoptr == NULL ) { Werrprintf( "Error creating %s", &autoinfofil[ 0 ] ); disp_status( " " ); ABORT; } fclose( autoinfoptr ); /* Someday this file will */ /* contain useful information */ /* Ignore error from setstring, for now. */ r = P_setstring( GLOBAL, "autodir", &autodir[ 0 ], 1 ); disp_status( " " ); RETURN; }
/* frqdimname; frequency dimension */ static int getspecparms(int dis_setup, int frqdimname) { char aig[5], dmg[5], dmg1[5]; int dim0,dim1; int r; double x0; // min, max sw values double minval, maxval; if(P_getmin(PROCESSED, "sw", &minval) ) minval = 200.0; if(P_getmax(PROCESSED, "sw", &maxval) ) maxval = 200.0; dim0 = FN0_DIM; dim1 = FN1_DIM; if (d2flag) { if (frqdimname == S_NP) { if (datahead.status & S_SPEC) { Werrprintf("Data file must first be re-initialized with FID data\n"); return(ERROR); } d2flag = FALSE; dim0 = FN0_DIM; dim1 = FN0_DIM; } else { if (ndflag == FOUR_D) { if (frqdimname & S_NP) { dim0 = FN0_DIM; if (frqdimname & S_NI) dim1 = FN1_DIM; else if (frqdimname & S_NI2) dim1 = FN2_DIM; else dim1 = FN3_DIM; } else if (frqdimname & S_NI) { dim0 = FN1_DIM; if (frqdimname & S_NI2) dim1 = FN2_DIM; else dim1 = FN3_DIM; } else { dim0 = FN2_DIM; dim1 = FN3_DIM; } } else if (frqdimname & S_NP) { dim0 = FN0_DIM; dim1 = ( (frqdimname & S_NI2) ? FN2_DIM : FN1_DIM ); } else if ( (~frqdimname) & S_NF ) { dim0 = FN2_DIM; dim1 = FN1_DIM; } else { Werrprintf("Invalid name for 2nd dimension\n"); return(ERROR); } } } /************************************************ * Set the normalization, processing mode, and * * display flags for either 1D or 2D data. * ************************************************/ if ( (r = P_getstring(CURRENT, "aig", aig, 1, 4)) ) { if ( expdir_to_expnum(curexpdir) > 0 ) P_err(r, "aig", ":"); return(ERROR); } if ( (r = P_getstring(CURRENT, "dmg", dmg, 1, 4)) ) { P_err(r, "dmg", ":"); return(ERROR); } normflag = (aig[0] == 'n'); dophase = doabsval = dopower = dophaseangle = dodbm = FALSE; dof1phase = dof1absval = dof1power = dof1phaseangle = FALSE; dophase = ((dmg[0] == 'p') && (dmg[1] == 'h')); if (!dophase) { doabsval = ((dmg[0] == 'a') && (dmg[1] == 'v')); if (!doabsval) { dopower = ((dmg[0] == 'p') && (dmg[1] == 'w')); if (!dopower) { dophaseangle = ((dmg[0] == 'p') && (dmg[1] == 'a')); if (!dophaseangle) { dodbm = ((dmg[0] == 'd') && (dmg[1] == 'b')); if (!dodbm) { Werrprintf("Invalid display mode for 1D spectral data"); return(ERROR); } } } } } if (d2flag) { r = P_getstring(CURRENT, "dmg1", dmg1, 1, 5); if (!r) { r = ( (strcmp(dmg1, "ph1") != 0) && (strcmp(dmg1, "av1") != 0) && (strcmp(dmg1, "pwr1") != 0) ); } if (r) { /* default to "dmg" */ if ( (r = P_getstring(CURRENT, "dmg", dmg1, 1, 4)) ) { P_err(r, "dmg", ":"); disp_status(" "); return(ERROR); } } dof1phase = ((dmg1[0] == 'p') && (dmg1[1] == 'h')); if (!dof1phase) { dof1absval = ((dmg1[0] == 'a') && (dmg1[1] == 'v')); if (!dof1absval) { dof1power = ((dmg1[0] == 'p') && (dmg1[1] == 'w')); if (!dof1power) { dof1phaseangle = ((dmg1[0] == 'p') && (dmg1[1] == 'a')); if (!dof1phaseangle) { Werrprintf("Invalid F1 display mode for 2D spectral data"); return(ERROR); } } } } } if (dis_setup) { /************************************ * Get current display parameters. * ************************************/ P_getreal(CURRENT,"vs",&vs,1); P_getreal(CURRENT,"vsproj",&vsproj,1); P_getreal(CURRENT,"vs2d",&vs2d,1); C_GETPAR("is", &is); C_GETPAR("io", &io); C_GETPAR("th", &th); C_GETPAR("vp", &vp); C_GETPAR("vo", &vo); C_GETPAR("ho", &ho); C_GETPAR("lvl", &lvl); C_GETPAR("tlt", &tlt); } if (d2flag) { /******************************************************* * Check whether the datafile contains FID's, half- * * transformed spectra, or fully transformed spectra. * *******************************************************/ if ( (~datahead.status) & S_SECND) { /* not fully transformed 2D spectrum */ dim1 = ( (datahead.status & S_NI2) ? SW2_DIM : SW1_DIM ); if ( (~datahead.status) & S_SPEC) dim0 = SW0_DIM; } } else { dim0 = FN0_DIM; dim1 = FN1_DIM; } if (d2flag && revflag) { set_spec_display(HORIZ,dim1,VERT,dim0); set_display_label(HORIZ,revchar,VERT,normchar); set_spec_proc(HORIZ,dim1,REVDIR, VERT,dim0,NORMDIR); } else { set_spec_display(HORIZ,dim0,VERT,dim1); set_display_label(HORIZ,normchar,VERT,revchar); set_spec_proc(HORIZ,dim0,NORMDIR, VERT,dim1,REVDIR); } get_sfrq(HORIZ,&sfrq); get_sfrq(VERT,&sfrq1); get_cursor_pars(HORIZ,&cr,&delta); get_phase_pars(HORIZ,&rp,&lp); get_ref_pars(HORIZ,&sw,&rflrfp,&fn); if(sw<=0 || sw>maxval) { Winfoprintf("Error sw out of bounds %f: 0 to %f",sw,maxval); return(ERROR); } get_scale_axis(HORIZ,&axisHoriz); get_scale_axis(VERT,&axisVert); { double axis_scl; int reversed; get_scale_pars(HORIZ,&sp,&wp,&axis_scl,&reversed); if (get_axis_freq(HORIZ)) set_sp_wp(&sp, &wp, sw, fn/2, rflrfp); else set_sf_wf(&sp, &wp, sw, fn/2); UpdateVal(HORIZ,WP_NAME,wp,NOSHOW); UpdateVal(HORIZ,SP_NAME,sp,NOSHOW); } if (d2flag) { get_phase_pars(VERT,&rp1,&lp1); get_ref_pars(VERT,&sw1,&rflrfp1,&fn1); if(dim1==FN1_DIM && (sw1<=0 || sw1>maxval)) { Winfoprintf("Error sw1 out of bounds %f: 0 to %f",sw1,maxval); return(ERROR); } { double axis_scl; int reversed; get_scale_pars(VERT,&sp1,&wp1,&axis_scl,&reversed); if (get_axis_freq(VERT)) set_sp_wp(&sp1, &wp1, sw1, fn1/2, rflrfp1); else set_sf_wf(&sp1, &wp1, sw1, fn1/2); UpdateVal(VERT,WP_NAME,wp1,NOSHOW); UpdateVal(VERT,SP_NAME,sp1,NOSHOW); } x0 = 1.0; if ( get_axis_freq(HORIZ) && get_axis_freq(VERT) ) { if (((axisHoriz == 'c') || (axisHoriz == 'm') || (axisHoriz == 'u')) && ((axisVert == 'c') || (axisVert == 'm') || (axisVert == 'u'))) { if (axisHoriz == 'c') x0 = 1.0; if (axisHoriz == 'm') x0 = 10.0; if (axisHoriz == 'u') x0 = 1e4; if (axisVert == 'c') x0 /= 1.0; if (axisVert == 'm') x0 /= 10.0; if (axisVert == 'u') x0 /= 1e4; } } aspect_ratio = (wp*sfrq1)/(x0*wp1*sfrq); } else { fn1 = fn; sw1 = 0.0; rflrfp1 = 0.0; aspect_ratio = 100.0; } normInt = 0; insval = 1.0; if (!P_getreal(CURRENT, "ins", &insval, 1)) { vInfo info; double tmp; if (!P_getreal(CURRENT, "insref", &tmp, 1)) { P_getVarInfo(CURRENT,"insref",&info); if (!info.active) normInt = 1; else if (tmp > 0.0) insval /= tmp; } } if (insval <= 0.0) insval = 1.0; if (!normInt) insval /= (double) fn; normInt2 = 0; ins2val = 1.0; if (!P_getreal(CURRENT, "ins2", &ins2val, 1)) { vInfo info; double tmp; if (!P_getreal(CURRENT, "ins2ref", &tmp, 1)) { P_getVarInfo(CURRENT,"ins2ref",&info); if (!info.active) normInt2 = 1; else if (tmp > 0.0) ins2val /= tmp; } } if (ins2val <= 0.0) ins2val = 1.0; if (!normInt2) ins2val /= ((double)fn * (double)fn1); return(COMPLETE); }