/***********************************************-*-C++-*-********/ /* tso 18.6.2009 */ /****************************************************************/ /* Short Description : Topshim with offset */ /****************************************************************/ /* Keywords : */ /* topshim, offset */ /****************************************************************/ /* Description/Usage : */ /* Executes topshim, but can add an additional z-Offset to */ /* compensate for a T-gradient in cryoprobes. Std z-offset */ /* applied is +15 units (variable z_offset). */ /* Options for this AU program: */ /* -zoff=: explicit offset (integer) added to z-shim after tsh */ /* -v: Displays a short report */ /* All other options and arguments supplied will be passed on */ /* to topshim (without checking their validity!) */ /* resides in the /.../exp/stan/nmr/au/src/user/ directory. */ /****************************************************************/ /* Author(s) : */ /* Name : PTO */ /* Organisation : Bruker BioSpin AG */ /* Email : pto@bruker-biospin.ch */ /****************************************************************/ /* Name Date Modification: */ /* PTO 090618 created */ /* */ /****************************************************************/ /* Name Date Modification: */ /* CL 160908 Simplified & added capability to read */ /* stored TSO values from a file */ /* (filename is probe dependent) */ /* */ /****************************************************************/ #include // for communication with BSMS #include // for PATH_MAX etc. int z_offset, z_initial, z_final; // various z-shims int i = 0; // argument counter int i_II; // internal counter int verbose = 0; // flag for verbose option int offset = 0; // flag for offset option char s_line[PATH_MAX], s_line2[PATH_MAX]; // help strings to extract offset char fName[PATH_MAX]; // string to store file name for tso file char topshim_command[PATH_MAX] = "topshim"; // command to be executed in TS = topshim char argverbose[]= "-v"; // definition of option "verbose" char argoffset[]= "-zoff="; // definition of option "explicit z offset" FILE* fptr; // file name for tso input file XAU("GetProbeName",""); // Determines probe "name" // The AUERR value determines the probe // File names storing corresponding tso values // are named tso.1, tso.2 etc where the extension // is specific to the probe "name" sprintf(fName,"/opt/tso/tso.%i",AUERR); // Read from file tso.1, tso.2 etc depending on installed probe fptr = fopen(fName,"r"); // Open tso.? file for reading if(fptr==0) { Proc_err(ERROR_OPT, "Cannot open file for reading: %s\n",fName); // Output error and abort if file is not readable ABORT } fscanf(fptr, "%i", &z_offset); // Read value into z_offset variable //sprintf(s_line2,"Read value is: %i",z_offset); // ***DEBUG*** //Proc_err(ERROR_OPT, "%s", s_line2); // ***DEBUG*** i = 3; // reconstruct the topshim command incl. all options supplied - cmd should not be used while (i <= i_argc) // loop is effective with >= 1 argument { if (strcmp(i_argv[i-1], argverbose) == 0) // option verbose detected { verbose = 1; } else if (strncmp(i_argv[i-1], argoffset, strlen(argoffset)) == 0) // explicit z_offset instruction { offset = 1; sprintf(s_line, i_argv[i-1]); // copy argument to help string s_line strncpy(s_line2, s_line + (strlen(argoffset)), ((strlen(s_line)) - (strlen(argoffset))) ); // extract offset for(i_II=(strlen(argoffset)); i_II strcat(topshim_command, i_argv[i-1]); // add option } i++; } // topshim_command contains now the full command for topspin if (verbose == 1) // print used topshim command { Proc_err(INFO_OPT, "%s\n\nis running now.", topshim_command); } CPR_exec(topshim_command, WAIT_TERM); // execute topshim now GETBSMSVAL(BSN_Z, z_initial); // read z-Shim from BSMS z_final= z_initial + z_offset; // add offset PUTBSMSVAL(BSN_Z, z_final); // setsh z-Shim increased by offset if (verbose == 1) // print the outcome of the z-correction using Proc_err { sprintf(s_line, "Topshim returned z = %d\nApplied ", z_initial); if (offset == 1) strcat(s_line, "user-specified"); else strcat(s_line, "default"); sprintf(s_line2, " z-offset = %d\n\nFinal z = %d\n", z_offset, z_final); strcat(s_line, s_line2); Proc_err(INFO_OPT, s_line); // display the results } QUIT // end of TSO