Running nTop Command Line in Matlab scripts

Follow

This article explains how to run your nTop notebook using nTop Command Line (nTopCL) in Matlab scripts.

  • Prepare the nTop notebook and JSON input for running nTopCL
  • Matlab Struct data structure can be used to read, modify and write JSON input file.
  • Run (F5)!
  • Check if the return messages are printed as below.
[info] Logging Engine started
[info] Login successful[info] Parasolid started
[info] Parasolid started
[info] nTop successfully built.
[info] Logout successful

 Feel free to change this script to batch process your workflow by passing input lists in a for loop!

clc,clear,close all

%Provide file paths to nTopCL, nTop file, and output JSON file
%Assuming input and output JSON files as well as .ntop file in the same folder pathToExe = ['"' 'C:\\Program Files\\nTopology\\nTop Platform\\ntopcl.exe' '"']; FileToRun='SampleFile.ntop'; OutputFile='output.json'; %Provide a input JSON file InputFile='input.json'; Inputs = jsondecode(fileread(InputFile)); %Modify input variables Inputs(1).inputs{2,1}.values = 5; Inputs(1).inputs{3,1}.values = 3; Inputs(1).inputs{4,1}.values = 2; %Write JSON file JsonStr = jsonencode(Inputs); JsonStr = strrep(JsonStr, ',', sprintf(',\r')); JsonStr = strrep(JsonStr, '[{', sprintf('[\r{\r')); JsonStr = strrep(JsonStr, '}]', sprintf('\r}\r]')); fid = fopen(InputFile, 'w'); if fid == -1, error('Cannot create JSON file'); end fwrite(fid, JsonStr, 'char'); fclose(fid); %Compose a execution command Arguments=sprintf('%s -j %s -o %s %s', pathToExe,InputFile,OutputFile,FileToRun); %Run system(Arguments);

 

  Download the Example Files

Sample File
input.json
Script_JSON.m

Labels: ntopcl command line api script matlab 
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.