Running multiple files from with Scilab program - scilab

I'm new to Scilab. I have to run the same program with a dozen different input files. Currently I simply uncomment the line and then rerun the program, and change the output file to a new name
// Input data file
data_file = 'data1.txt';
//data_file = 'data2.txt';
//data_file = 'data3.txt';
//data_file = 'data4.txt';
//data_file = 'data5.txt';
//data_file = 'data6.txt';
etc. another 6 lines
// Output data file name
output_data = '/output_files/data1.csv';
Is there a way to read in each file (data1.txt, data2.txt...) execute the body of the program and then output a new output file (data1.csv, data2.csv ...) instead of what I'm doing now, which is running the program and then editing it to use the next file and run again?

Just do something like:
for i=1:6
// Input data file
data_file=msprintf("data%d.txt",i);
// Output data file name
output_data=msprintf("/output_files/data%d.csv",i);
// exec the body of your script
end

Related

Reading non structured log file as text file in RStudio

I have a log file that has one log entry per line. I want to read it into RStudio and go trough it line for line to look for IP adresses. However I dont know how to read a file and split in on new line.
What i want is to
Read file
Loop trough it line for line
RStudio The code I have now:
# Read data
data <- readLines("failed_jobs.ibd")
length(data)
data
In PHP I would do something like this:
$fh = fopen("failed_jobs.ibd", "r");
$data = fread($fh, filesize("failed_jobs.ibd"));
fclose($fh);
$array = explode("\n", $data);
for($x=0;$x<sizeof($array);$x++){
$line = $array[$x];
print("$line");
}
I guess this would be the basic structure of what you want, the only disadvantage is it will read all lines into memory but assuming the file is not endless that should be mostly fine
lines <- readLines("failed_jobs.ibd")
for(line in lines){
print(line)
# do other things per line here
}

Passing parameter as variable in Run function

as the title says, here is my code but its not working
; Get the parameter from open file dialog
GUICtrlSetData($locationtxt, FileOpenDialog("Select the program", '', "Supported files (*.exe;*.msi;*.reg;*.inf)|Executable Files (*.exe)|Microsoft Installer files (*.msi)|Registry files (*.reg)|Inf files (*.inf)", 3))
; store the value in a variable
$abc = GUICtrlRead($locationtxt)
; Run the program and pass the parameter value
Run("ussf.exe " & $abc )
; If i do it this way, its working but i want the parameter value from the open dialog not fixed
Run("ussf.exe C:\Users\project\ccsetup563.exe")
The second parameter for Run() is the working directory, not an argument for the program. I think you should be using ShellExecute(), or ShellExecuteWait() instead.

How can i fetch starting of file name from the path with different extensions using R

"/D/data_DataAnalysis/Progrm/datset1/set2/genus/Huttenhower_LC8_genus_reported.tsv"
"/c/bioinfoTools/data/mock/test/truth/file_sets/genus/Huttenhower_LC8_TRUTH.txt"
I want "Huttenhower_LC8" from two file name using R.
Similer to the python code
fileName_temp = a_file.split("/")[-1]
filename = a_file.split("/")[-1][:-9]
for another_file in all_slim_files:
a_filename = another_file.split("/")[-1][:-18]

Deleting text from .txt file from within R

I have some code which appends text over an existing .txt file , from within R as following :
write("puts 'hellow world '", file = "C:\\Ruby22-x64\\bin\\elt.rb",
append = TRUE, sep = " ")
setwd("C:/Ruby22-x64/bin/")
test<-system("ruby elt.rb",intern=TRUE) # this will return "hellow world" from ruby interpreter
My question is: after appending the .rb file and running it, how can i remove the "puts 'hellow world '" string from the .rb file, and return it to its initial state?
I tried to look for many functions, but couldn't find any function which can undo the write function.
Just found out a wonderful gist that does the Job : https://gist.github.com/mages/1544009
gist:1544009

MATLAB - Load data file with a string file name

I am writing a Matlab program that loads a data file created in another C++ program.
planet = input('What is the name of your planet? ', 's')
data_file = strcat(planet, '.dat')
load(data_file);
data_file;
x = data_file(:,1);
y = data_file(:,2);
plot (x,y,'r*')
The program takes the name of the planet as the user input, then concatenates ".dat" to the end of the planet name. This gives, for example, "earth.dat," which is the name of the file created by the other C++ program.
I have made sure that the data file being loaded is in the correct folder; however, MATLAB still gives an error when I run the program.
What is the correct command for loading this file?
Thank you!
try using this instead:
planet = input('What is the name of your planet? ', 's')
filename=[num2str(planet) '.dat'];
data_file=load(filename);
x = data_file(:,1);
y = data_file(:,2);
plot (x,y,'r*')

Resources