#pragma TextEncoding = "UTF-8" #pragma rtGlobals=3 // Use modern global access method and strict wave access. // // - String containing full unix style path to folder where the calculations should be performed. // All input & ouput files should be considered as temporary. Next execution of this (or similar) // function will overwrite them. // StrConstant folderStr = "Macintosh HD/Users/joe/Documents/Current\ Work/Kairos/V\&V/Pressure_Drop" Function RunTests(code, test, vin) String code // "PH" or "SAM" String test // "TAMU"... Variable vin // superficial inlet velocity (m/s) DFREF saveDFR = GetDataFolderDFR() // - set KeyWords that are used in input file template Make/T/FREE keyWords = { "<>"} Variable numKeys = numpnts(keyWords) // - set input values corresponding to key words (order is VERY IMPORTANT!) Make/T/FREE/N=(numKeys) keyValues keyValues[0] = num2str(vin) // - set path to the test folder where cases will be run // -> used as path to open input file & template String pathStr = folderStr pathStr = ReplaceString("\\", pathStr, "") pathStr = ReplaceString("/", pathStr, ":") NewPath/O/Q path, pathStr // - set path string to the test folder in POSIX format // -> used as part of unix shell command pathStr = folderStr Variable indx = strsearch(pathStr, "/", 0) // get rid of prepended "Macintosh HD" Variable last = strlen(pathStr) pathStr = pathStr[indx,last] // - open input file template (code_test.tmp) & input file (test.i) String tmpName = code + "_" + test + ".tmp" Variable tmpFile // refNum of input template (read only) Variable inFile // refNum of input file to be written Open/Z /P=path inFile as "test.i" // will be overwritten (if exists) Open/Z/R /P=path tmpFile as tmpName if (V_flag) print "ERROR: input model template test.tmp not found!" PathInfo path print " -> path was: " + S_path print " -> run will be aborted!" Abort endif // // - modify input file for this run using input parameters // String line // the line to be read/modified Variable i // loop indices do FReadLine tmpFile, line // - read input file template line-by-line if (strlen(line) == 0) // EOF reached? break endif if (StringMatch( line, "*<<*")) // does line contain a key word? for (i=0; i -1) // match found -> substitute value line = ReplaceString( keyWords[i], line, keyValues[i]) endif if (StringMatch( line, "!*<<*")) // any more keywords in this line? break endif endfor endif line = ReplaceString("\r\n", line, "\n") // line = RemoveLineEnding(line, "\r\n") // line += "\n" fprintf inFile, "%s", line // echo line from template to input file while (1) Close tmpFile Close inFile // - execute code via AppleScript command String exec = "mpiexec -n 6 /Users/joe/projects/pronghorn/pronghorn-opt -i " String arg = "test.i" // cmd line input file name String cmd = "cd " + pathStr // go to working directory cmd += ";" + exec + arg // append execute cmd & arg list ExecuteUnixShellCommand(cmd, 1, 0) SetDataFolder saveDFR End Function/S ExecuteUnixShellCommand(uCommand, printCommandInHistory, printResultInHistory) String uCommand // Unix command to execute Variable printCommandInHistory Variable printResultInHistory if (printCommandInHistory) printf "Unix command: %s\r", uCommand endif String cmd sprintf cmd, "do shell script \"%s\"", uCommand ExecuteScriptText cmd if (printResultInHistory) Print S_value endif return S_value End