void setGlobalPars() { char addr[MAXPATH]; vInfo info; int e; e=P_setstring(GLOBAL,"userdir",userdir,0); if (e==-2) { P_creatvar(GLOBAL,"userdir",ST_STRING); P_setlimits(GLOBAL,"userdir",(double)MAXPATH,0.0,0.0); P_setstring(GLOBAL,"userdir",userdir,0); P_setprot(GLOBAL,"userdir",0); } e=P_setstring(GLOBAL,"curexp",curexpdir,0); if (e==-2) { P_creatvar(GLOBAL,"curexp",ST_STRING); P_setlimits(GLOBAL,"curexp",(double)MAXPATH,0.0,0.0); P_setstring(GLOBAL,"curexp",curexpdir,0); P_setprot(GLOBAL,"curexp",0); } #ifdef VNMRJ jcurwin_setGlobalPars(); #endif e=P_setstring(GLOBAL,"systemdir",systemdir,0); if (e==-2) { P_creatvar(GLOBAL,"systemdir",ST_STRING); P_setlimits(GLOBAL,"systemdir",(double)MAXPATH,0.0,0.0); P_setstring(GLOBAL,"systemdir",systemdir,0); P_setprot(GLOBAL,"systemdir",0); } e=P_setstring(GLOBAL,"auto",(mode_of_vnmr == AUTOMATION) ? "y" : "n",0); if (e==-2) { P_creatvar(GLOBAL,"auto",ST_STRING); P_setlimits(GLOBAL,"auto",(double)STR64,0.0,0.0); P_setstring(GLOBAL,"auto",(mode_of_vnmr == AUTOMATION) ? "y" : "n",0); P_setprot(GLOBAL,"auto",7); /* do not allow any user change */ P_Esetstring(GLOBAL,"auto","n",1); P_Esetstring(GLOBAL,"auto","y",2); } if (mode_of_vnmr == AUTOMATION) { getAutoDir(addr, MAXPATH); e=P_setstring(GLOBAL,"autodir",addr,0); } else { e=P_getstring(GLOBAL,"autodir",addr,1,MAXPATH); } if (e==-2) { P_creatvar(GLOBAL,"autodir",ST_STRING); P_setlimits(GLOBAL,"autodir",(double)MAXPATH,0.0,0.0); if (mode_of_vnmr == AUTOMATION) P_setstring(GLOBAL,"autodir",addr,0); P_setprot(GLOBAL,"autodir",3); } GET_VNMR_ADDR(addr); e=P_setstring(GLOBAL,"vnmraddr",addr,0); if (e==-2) { P_creatvar(GLOBAL,"vnmraddr",ST_STRING); P_setlimits(GLOBAL,"vnmraddr",(double)STR128,0.0,0.0); P_setstring(GLOBAL,"vnmraddr",addr,0); P_setprot(GLOBAL,"vnmraddr",4); /* do not allow any user change */ } GET_ACQ_ADDR(addr); e=P_setstring(GLOBAL,"acqaddr",addr,0); if (e==-2) { P_creatvar(GLOBAL,"acqaddr",ST_STRING); P_setlimits(GLOBAL,"acqaddr",(double)STR128,0.0,0.0); P_setstring(GLOBAL,"acqaddr",addr,0); P_setprot(GLOBAL,"acqaddr",4); /* do not allow any user change */ } e=P_setstring(GLOBAL,"owner",UserName,0); if (e==-2) { P_creatvar(GLOBAL,"owner",ST_STRING); P_setlimits(GLOBAL,"owner",(double)STR128,0.0,0.0); P_setstring(GLOBAL,"owner",UserName,0); P_setprot(GLOBAL,"owner",P_VAL+P_GLO); /* do not allow any user change */ } e=P_setstring(GLOBAL,"operator",OperatorName,0); if (e==-2) { P_creatvar(GLOBAL,"operator",ST_STRING); P_setlimits(GLOBAL,"operator",(double)STR128,0.0,0.0); P_setstring(GLOBAL,"operator",UserName,0); P_setprot(GLOBAL,"operator",P_VAL+P_GLO); /* do not allow any user change */ } e=P_getVarInfo(GLOBAL,"department",&info); /* do not set value, read from file */ if (e==-2) { P_creatvar(GLOBAL,"department",ST_STRING); P_setlimits(GLOBAL,"department",(double)STR128,0.0,0.0); P_setstring(GLOBAL,"department","nmr",0); P_setprot(GLOBAL,"department",P_VAL+P_GLO); /* do not allow any user change */ } }
int autoq(int argc, char *argv[], int retc, char *retv[]) { char autodir[MAXPATH]; char lockPath[MAXPATH]; char idPath[MAXPATH]; char lockLogPath[MAXPATH]; char idLogPath[MAXPATH]; char logBasePath[MAXPATH]; char *blockname = "autoqBlock"; char *lockname = "lockEnterQ"; time_t lockSecs = 5; /* default lock timeout */ int res = 1; if (argc < 2) { Werrprintf("usage: %s requires add, get, lock, unlock, sendmsg, or recvmsg argument", argv[0]); ABORT; } if ( !strcmp(argv[1],"sendmsg") || !strcmp(argv[1],"recvmsg") ) { res = 4; } else { #ifdef VNMRJ if ( ! strcmp(argv[1],"add") ) P_getstring(GLOBAL,"autodir",autodir,1,MAXPATH); else #endif getAutoDir(autodir, MAXPATH); sprintf(lockPath,"%s/%s",autodir,lockname); sprintf(idPath,"%s/eq_%s_%s_%d",autodir,HostName,UserName,HostPid); } if ( ! strcmp(argv[1],"add") ) { char queuename[MAXPATH]; if (argc < 3) { Werrprintf("usage: %s('add',filename) requires a filename.",argv[0]); ABORT; } if (argc == 4) strcpy(queuename,argv[3]); else strcpy(queuename,"std"); /* Wait for get operations to complete first */ blockedByGet(autodir, blockname); if ( lockit(lockPath,idPath,lockSecs) ) { res = addQueueFile(autodir, argv[2], queuename); unlockit(lockPath,idPath); } else { res = -4; } } else if ( ! strcmp(argv[1],"get") ) { FILE *fd; char blockfile[MAXPATH]; if (argc < 3) { Werrprintf("usage: %s('get',filename) requires a filename.",argv[0]); ABORT; } /* The get operation will block add and lock from other processes */ sprintf(blockfile,"%s/%s",autodir,blockname); fd = fopen(blockfile,"w"); fclose(fd); if ( lockit(lockPath,idPath,lockSecs) ) { res = getQueueFile(autodir, argv[2]); unlockit(lockPath,idPath); } else { res = -4; } #ifdef TESTING if (argc == 4) sleepnano(atoi(argv[3])); #endif /* Allow access by add and lock from other processes */ unlink(blockfile); } else if ( ! strcmp(argv[1],"lock") ) { if (argc == 3) { lockSecs = atoi(argv[2]); if (lockSecs < 1) lockSecs = 1; else if (lockSecs > 15) lockSecs = 15; } /* Wait for get operations to complete first */ blockedByGet(autodir, blockname); DPRINT1("lock called with %ld timeout\n",lockSecs); res = lockit(lockPath,idPath,lockSecs); } else if ( ! strcmp(argv[1],"unlock") ) { unlockit(lockPath,idPath); res = 1; } else if ( ! strcmp(argv[1],"addAcct") ) { char accFile[MAXPATH]; char idFile[MAXPATH]; if (argc != 3) { Werrprintf("autoq('addAcct',filename) requires filename as the second argument"); ABORT; } if ( access(argv[2], R_OK|W_OK) ) { Werrprintf("autoq('addAcct',filename) filename does not exist or has wrong permissions"); ABORT; } res = 0; strcpy(lockPath, getenv("vnmrsystem") ); strcat(lockPath,"/adm/accounting/"); strcpy(accFile, lockPath); strcat(accFile,"acctLog.xml"); if ( !access(accFile,F_OK) ) { FILE *inputFd; int bufSize=4095; char buf[bufSize+1]; int size = 0; inputFd = fopen(argv[2],"r"); if (inputFd) { size = fread(buf, 1, bufSize, inputFd); /* Terminate the buffer */ buf[size] = 0; fclose(inputFd); } unlink(argv[2]); if (size) { lockSecs = 2; // Create filepaths for the lock files to lock acctLog strcpy(idPath, lockPath); strcat(lockPath, "acctLogLock"); sprintf(idFile, "acctLogLockId_%s_%d", HostName, HostPid); strcat(idPath, idFile); DPRINT1("lock called with %ld timeout\n",lockSecs); if ( lockit(lockPath,idPath,lockSecs) ) { const char root_end[]="</accounting>\n"; FILE *xmlFd; xmlFd = fopen(accFile,"r+"); if (xmlFd) { /* find the closing /> at the end and put log info above that */ fseek(xmlFd,-strlen(root_end),SEEK_END); /* Write to the log file */ fprintf(xmlFd,"%s",buf); fprintf(xmlFd,"%s",root_end); fflush(xmlFd); fclose(xmlFd); } unlockit(lockPath,idPath); res = 1; } } } } else if ( ! strcmp(argv[1],"locklog") ) { lockSecs = 15; // Create filepaths for the lock files to lock acctLog strcpy(logBasePath, (char *)getenv("vnmrsystem") ); strcat(logBasePath,"/adm/accounting/"); sprintf(lockLogPath, "%s%s", logBasePath, "acctLogLock"); sprintf(idLogPath, "%sacctLogLockId_%s_%d", logBasePath, HostName, HostPid); /* Wait for get operations to complete first */ blockedByGet(autodir, blockname); DPRINT1("lock called with %ld timeout\n",lockSecs); res = lockit(lockLogPath,idLogPath,lockSecs); } else if ( ! strcmp(argv[1],"unlocklog") ) { // Create filepaths for the lock files to lock acctLog strcpy(logBasePath, (char *)getenv("vnmrsystem") ); strcat(logBasePath,"/adm/accounting/"); sprintf(lockLogPath, "%s%s", logBasePath, "acctLogLock"); sprintf(idLogPath, "%sacctLogLockId_%s_%d", logBasePath, HostName, HostPid); unlockit(lockLogPath,idLogPath); res = 1; } else if (res == 4) /* ( !strcmp(argv[1],"sendmsg") || !strcmp(argv[1],"recvmsg") ) */ { if ( ! strcmp(argv[1],"recvmsg") ) { if ( (argc != 3) || ( strcmp(argv[2],"on") && strcmp(argv[2],"off")) ) { Werrprintf("autoq %s requires 'on' or 'off' as the second argument",argv[1]); ABORT; } } if (argc != 3) { Werrprintf("autoq %s requires another argument",argv[1]); ABORT; } res = 1; if (is_acqproc_active()) { char msg[MAXSTR]; sprintf(msg,"%s %s",argv[1],argv[2]); if (send2Acq(AUTOQMSG, msg) < 0) res = 0; if (res) receivingMsg = ( ! strcmp(argv[2],"on")); } } DPRINT1("operation returns %d\n",res); if (retc) { retv[0] = intString(res); } RETURN; }
void bootup(char *modeptr, int enumber) /*****************************/ { char autodir[MAXPATH]; char parampath[MAXPATH]; char plotname[STR64]; char mstr[MAXPATH]; char rtautocmd[2 * MAXPATH + 20]; char estring[5]; extern char PlotterName[]; extern char PrinterName[]; int do_rt = 0; int lval; endian_tester et; (void) modeptr; et.my_int = 0x0a0b0c0d; BigEndian = (et.my_bytes[0] == 0x0a) ? 1:0; psg_pid = 0; /* set pids to zero */ if ( !Bnmr ) disp_status("BOOTUP "); /* May 18, 1987. Addition to read the system global parameters. If a problem occurs, the program exits immediately, for this should not happen. The CONPAR file is on the distribution tape. */ strcpy(parampath,systemdir); #ifdef UNIX strcat(parampath,"/conpar"); #else strcat(parampath,"conpar"); #endif if (P_read(SYSTEMGLOBAL,parampath)) { fprintf(stderr,"problem loading system global parameters from %s\n", parampath); exit(1); } openVnmrInfo(systemdir); /* If automation mode, use value of autodir to establish path to experiment */ if (mode_of_vnmr == AUTOMATION) { getAutoDir(autodir, MAXPATH); if (strlen(autodir) == 0) { fprintf( stderr, "unable to access 'autodir' parameter\n" ); exit(1); } } /* setup signal handlers to catch these signals */ if (Wissun()) /* Only do this if using SUN console */ { set_acqi_signal(); } else if (mode_of_vnmr == FOREGROUND) /* Only creat a Vnmr socket if foreground */ { setupVnmrAsync(AcqSocketIsRead); } #ifndef VNMRJ if (Wishds()) last_line = 19; else #endif last_line = 20; /* load parameters in global file */ /* moved 9 lines to read GLOBAL before EXP, this way we can use curexpdir to restart Vnmr in the last exp used. May 17, 1997 */ strcpy(parampath,userdir); strcat(parampath,"/global"); if (P_read(GLOBAL,parampath)) Werrprintf("problem loading global parameters"); #ifdef VNMRJ // set curexpdir based on jcurwin of viewport 1 jcurwin_init(curexpdir); #endif // load unshared globalX for viewport X if foreground if (!Bnmr) { sprintf(parampath,"%s/global%d",userdir,VnmrJViewId); /* Don't complain if unshared globals are missing */ P_read(GLOBAL,parampath); } // set OperatorName if ( (P_getstring(GLOBAL,"operator",OperatorName,1,MAXSTR) != 0) || ( ! strcmp(OperatorName, "") ) ) strcpy(OperatorName, UserName); /* If lock fails, and program is running in foreground mode, set current experiment to be EXP0, which doesn't exist. The user can then join another experiment or use other techniques to unlock the desired experiment. If running in any other mode, exit immediately with an error message. */ /* May 19, 1997. Use curexpdir to set the enumber, check if directory still exists, if not make it exp1. Only done if FOREGROUND Vnmr. Acqproc, autoproc, and other procs determine enumber themselves. Note that curexpdir is overwritten below, when we read exp parameters */ #ifdef VNMRJ jviewport_init(); P_setstring(GLOBAL,"curexp",curexpdir,1); #else P_getstring(GLOBAL,"curexp",curexpdir,1,MAXPATH); #endif if (mode_of_vnmr == FOREGROUND) { enumber = expdir_to_expnum(curexpdir); if (enumber == 0) lval = -1; else if ( ! access(curexpdir,F_OK)) lval = lockExperiment( enumber, FOREGROUND); else lval = -1; } #ifdef SUN else if (mode_of_vnmr == ACQUISITION) lval = (enumber == 0) ? -2 :checkAcqLock( enumber ); else if ( Bnmr && (enumber == 0) ) lval = -2; else #endif lval = lockExperiment( enumber, mode_of_vnmr ); if (lval != 0) { if ((mode_of_vnmr != FOREGROUND) && (lval != -2) ) { fprintf( stderr, "unable to lock experiment %d\n", enumber); exit(1); } if (enumber == 0) { #ifdef VNMRJ if (VnmrJViewId != 1) { P_getstring(GLOBAL, "jviewportlabel", mstr, VnmrJViewId, MAXPATH); Werrprintf( "No experiment selected for the %s viewport.",mstr); } jcurwin_setexp( "0" , -1 ); #else if (lval != -2) Werrprintf( "No experiment selected."); #endif } else { #ifdef VNMRJ if (VnmrJViewId == 1) Werrprintf( "Unable to lock experiment %d", enumber ); else { P_getstring(GLOBAL, "jviewportlabel", mstr, VnmrJViewId, MAXPATH); Werrprintf( "Unable to lock experiment %d for the %s viewport.",enumber, mstr); } jcurwin_setexp( "0", -1 ); #else Werrprintf( "Unable to lock experiment %d", enumber ); #endif } strcpy( curexpdir, userdir ); #ifdef UNIX strcat( curexpdir, "/exp0" ); #else vms_fname_cat( curexpdir, "[.exp0]" ); #endif #ifdef VNMRJ if (mode_of_vnmr != AUTOMATION) { sprintf(mstr,"exp0 %s",curexpdir); writelineToVnmrJ("expn",mstr); } #endif } /* Only read in parameters if the target experiment was locked. */ else { if (mode_of_vnmr == AUTOMATION) strcpy( curexpdir, &autodir[ 0 ] ); else strcpy( curexpdir, userdir ); sprintf(estring, "%d", enumber); #ifdef UNIX strcat(curexpdir, "/exp"); strcat(curexpdir, estring); #else vms_fname_cat(curexpdir, "[.exp"); vms_fname_cat(curexpdir, estring); vms_fname_cat(curexpdir, "]"); #endif if (mode_of_vnmr == AUTOMATION) { lval = strlen( &datadir[ 0 ] ); if (lval > MAXPATH-8) { fprintf(stderr, "data pathname too long in automation mode"); exit(1); } else if (lval > 1) { int ex; sprintf(rtautocmd, "cp %s.fid/sampleinfo %s/sampleinfo", datadir,curexpdir); system(rtautocmd); ex = 0; /* Wait up to 0.5 secs for fid to appear */ while ( access(rtautocmd,R_OK) && (ex < 50) ) { struct timespec timer; timer.tv_sec=0; timer.tv_nsec = 10000000; /* 10 msec */ #ifdef __INTERIX usleep(timer.tv_nsec/1000); #else nanosleep( &timer, NULL); #endif ex++; } sprintf( &rtautocmd[ 0 ], "%s('%s','nodg')\n", (acqStartUseRtp) ? "RTP" : "RT", &datadir[ 0 ] ); do_rt = 1; /* do the rt command after reading global tree */ } else /* read curpar parameters only from the automation exp */ { D_getparfilepath(CURRENT, parampath, curexpdir); if (P_read(CURRENT,parampath)) { /* if no parameters in current experiment */ strcpy(parampath,systemdir); #ifdef UNIX strcat(parampath,"/stdpar/H1.par/procpar"); #else vms_fname_cat(parampath,"[.stdpar.H1_par]procpar"); #endif if (P_read(CURRENT,parampath)) Werrprintf("problem loading current parameters"); } P_copy(CURRENT,PROCESSED); } } else /* if (mode_of_vnmr != AUTOMATION) */ { /* load parameters in curexp/curpar file */ D_getparfilepath(CURRENT, parampath, curexpdir); if (P_read(CURRENT,parampath)) Werrprintf("problem loading current parameters from \"%s\"", parampath); /* load parameters in curexp/procpar file */ D_getparfilepath(PROCESSED, parampath, curexpdir); if (P_read(PROCESSED,parampath)) Werrprintf("problem loading processed parameters from \"%s\"", parampath); #ifdef VNMRJ sprintf(mstr,"exp%s %s",estring,curexpdir); writelineToVnmrJ("expn",mstr); #endif } } /* May 17, 1997. We read GLOBAL parameters earlier */ setGlobalPars(); #ifdef VNMRJ if (!Bnmr) saveViewPortAddr(); #endif bufferscale = getbufscale(); /* obtain the value for bufferscale */ finddatainfo(); DEBUGPRINT1("bufferscale set to %d\n", bufferscale); D_init(); /* initialize the data file handler; bufferscale must be known before D_init() is called. */ /* setAppdirs needs to happen after operator is set in setGlobalPars but before * any macros are called */ #ifdef VNMRJ if (VnmrJViewId == 1) #endif { setAppdirs(); } specIndex = 1; if (mode_of_vnmr == AUTOMATION) { if (do_rt) { turnOffFixpar(); execString( &rtautocmd[ 0 ] ); } else { Werrprintf( "Spectrometer in automation mode" ); } } else if (enumber || (mode_of_vnmr != BACKGROUND) ) { disp_expno(); } init_proc2d(); strcpy(dconi_runstring,"dcon\n"); /* Assign some function pointers for the */ /* graphics module */ set_bootup_gfcn_ptrs(); if (Bnmr) init_colors(); /* set default colors for graphics and plotters */ set_automount_dir(); /* Set up plotting parameters */ /* If there is trouble setting plottin parameters (ie plotting device doesn't exist or devicetable/devicenames is bad, set to "none" device */ if (P_getstring(GLOBAL,"plotter" ,plotname, 1,32)) { P_setstring(GLOBAL,"plotter","none",0); strcpy(PlotterName,"none"); } if (!setPlotterName(plotname)) { P_setstring(GLOBAL,"plotter","none",0); strcpy(PlotterName,"none"); } /* Set up printing parameters */ /* If there is trouble setting printing parameters (ie printing device doesn't exist or devicetable/devicenames is bad, set to "none" device */ if (P_getstring(GLOBAL,"printer" ,plotname, 1,32)) { P_setstring(GLOBAL,"printer","none",0); strcpy(PrinterName,"none"); } if (!setPrinterName(plotname)) { P_setstring(GLOBAL,"Printer","none",0); strcpy(PrinterName,"none"); } #ifdef SUN /* * Set up signal handler to exit VNMR * The function nmr_quit will be called when Vnmr exits */ set_nmr_quit_signal(); #endif check_datastation(); #ifdef VNMRJ writelineToVnmrJ("bootup",""); /* create a frame for graphics display */ frame_update("init", ""); #endif /* The extra space in the first Wscrprintf is essential for the scrollable text subwindow to work correctly. */ /* --- print revision ID and Date, Compiled within revdate.c --- */ P_setstring( SYSTEMGLOBAL, "rev", &RevID[ 0 ], 1); P_setstring( SYSTEMGLOBAL, "revdate", &RevDate[ 0 ], 1); if (!Bnmr) /* only execute the bootup macro if we are in forground */ { Wscrprintf("\n %s\n",RevID); Wscrprintf(" %s\n",RevDate); Wscrprintf(" %s\n\n",Copyright); if (strlen(PlotterName) > 0) Wscrprintf( " Plotting Device is set to %s\n",PlotterName); else Wscrprintf( " Plotting Device is set to ''\n"); if (strlen(PrinterName) > 0) Wscrprintf( " Printing Device is set to %s\n\n",PrinterName); else Wscrprintf( " Printing Device is set to ''\n\n"); disp_current_seq(); if (Wissun()) sendTripleEscToMaster( 'C',"bootup(0)"); else execString("bootup(0)\n"); disp_status(" "); } else if (enumber) { execString("bootup(1)\n"); } p11_init(); }