Need Help Understanding a Line of Code Related to Strings

2 views (last 30 days)
Hello All,
I am reviewing some code written by an author and I am trying to understand why a line of code is coded in the way it is coded.
c.simcmd = 'set path=($path /cad/cadence/IC615.06.15.502.lnx/tools/bin); /cad/cadence/MMSIM13.ISR12.11.292.lnx86/tools/bin/spectre techsweep.scs >! techsweep.out';
I am trying to understand what this line of code is trying to accomplish. It has two different file paths but within the string it has a semicolon and then another file path after the semicolon.
Can someone give me some insight on why something like this might be used?
Thank you for taking the time to read my question.
Regards,
Melvin

Accepted Answer

Walter Roberson
Walter Roberson on 18 Jan 2022
c.simcmd = 'set path=($path /cad/cadence/IC615.06.15.502.lnx/tools/bin); /cad/cadence/MMSIM13.ISR12.11.292.lnx86/tools/bin/spectre techsweep.scs >! techsweep.out';
At the MATLAB level, this constructs a constant character vector, and nothing more. Something else would have to make use of it.
What is being constructed appears to be a small csh or tcsh script intended for use on a Linux system.
If that character vector were executed by csh or csh, then
  1. the directory /cad/cadence/IC615.06.15.502.lnx/tools/bin would be added to the local search path for programs ( not for libraries, only for programs ).
  2. The file techsweep.out in the current directory would be created if it does not exist, and emptied of all content if it already exists. The ! flag part of >! says that this is to be done even if the csh or tcsh "noclobber" protection is active, that would normally prevent existing files from being overwritten if just > were used. >! is "force" the file to be initialized as empty even if it already exists
  3. the program or script /cad/cadence/MMSIM13.ISR12.11.292.lnx86/tools/bin/spectre would be invoked
  4. the character vector techsweep.scs would be passed as the first parameter to the program
  5. any "standard" output that /cad/cadence/MMSIM13.ISR12.11.292.lnx86/tools/bin/spectre produces will be written to that file techsweep.out
  6. any "error" output that the program produces will be written to the terminal (or error stream of the invoking program, depending on exact configuration)
  7. typically the way that this small script would be invoked would be that a new process would have been created to run it. The change to the path would have been made within that new process, and the process would normally get deleted, so the context in which the path was changed would have gone away; there would be no permanent change to the path
  8. But even if this small script was invoked within a different csh / tcsh script, the details of how path was set are for local setting, and would not affect the calling script -- the form of set that was used is effectively only for local variables (that affect the current shell script and any programs and scripts called from the current shell script). If this had been implemented in ksh or a shell derived from ksh, the same bit about local variables would be true, but there would also be obscure circumstances under which the change could be inherited; I do not recall now whether that obscure inheritence possibility exists for csh / tcsh . (That obscure circumstances do not apply here... I am just indicating that the fact that the change to path would be local is not 100.000% of the time... just rare enough that you may never see the counter-example in your lifetime.
  2 Comments
Walter Roberson
Walter Roberson on 21 Jan 2022
As an analogy:
MATLAB is not just one executable. The documentation is a different program; the Symbolic Engine is a different program; Simulink is a different program (I think); Simscape is a different program (I think). Some components of MATLAB provide the lcc-64 C/C++ compiler, which includes programs for compiling, for optimizing, and for linking. Polyspace is a different program. MATLAB includes a copy of the perl programming language. MATLAB includes a copy of the Java programming language.
And so on. Complex programs often divide the work up into different tools.
In the case of a CAD tool, it would not, for example, be surprising if a tool to simulate a geometry (Simulator In The Loop, SIL) were a different program than a tool to optimize a geometry, and there might be a third tool to verify correctness of a geometry; and perhaps a different tool yet to convert a geometry into instructions for the equivalent of a CNC machine to automatically build the geometry.
"could the location of "/cad/cadence/MMSIM13.ISR12.11.292.lnx86/tools/bin/spectre" be a folder of many different .m files(such as a matlab toolbox"
NO. In context, /cad/cadence/MMSIM13.ISR12.11.292.lnx86/tools/bin/spectre must be a binary executable or a shell script, not a folder. In context, /cad/cadence/MMSIM13.ISR12.11.292.lnx86/tools/bin/spectre is to be executed, and you cannot execute a folder itself.

Sign in to comment.

More Answers (1)

Adam Danz
Adam Danz on 18 Jan 2022
Edited: Adam Danz on 22 Jan 2022
> I am trying to understand what this line of code is trying to accomplish
All it is is a character vector. That's all we know. It doesn't accomplish anything on its own.
A very similar character vector is referenced in this forum (search for "c.simcmd") for a 3rd party software that uses Matlab. The variable it is assigned to, c.simcmd, is an input to a function system() according to that forum thread. I have no idea what that function does or how that input is used but I can speculate that it adds access to shared libraries based on the paths specified in c.simcmd. This thread and this thread indicate that system() also runs a simulation.
Digging deeper into the first link above, this line appears to be part of a configuration file described in this design chart (pdf) which contains a link to this textbook on designing analog circuits.
  • $path specifies a set of directories where executable programs are located.
  • >! may indicated to overwrite an existing file named "techsweep.out" in the specified path.
  1 Comment
Melvin Edwards II
Melvin Edwards II on 21 Jan 2022
Thank you so much for your answer Adam, the extra threads here really helped me understand the issue much more. I appreciate the amount of time it takes to generate these responses.
Thanks,
Melvin

Sign in to comment.

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!