I have a C function called "amortiss.c" and I want it to communicate with CLIPS (Expert System Tool).Infact, I want to pass the variable "result" returned by this function "amortiss.c" to CLIPS so that it compares it to 1 and then displays messages depending on the comparaison.
According to the Clips user guide I should define an external function called user-defined function.c. So I am thinking of putting this "result" in an Excel (.CSV file) and then the user defined function reads the "result" values from this .CSV file.
In bref,the .CSV file extracts the "result" from the "amortiss.c" function and then the "user defined.c" function reads it. is there any way to do this? I am really confused. All your suggestion and help will be appreciated.
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Unless the C function in the amortiss.c file is run as part of a separate program, you don't want to use a file to transfer data. Instead write a user-defined function that calls the C function in amortiss.c and return that result from the user-defined function.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for responding.
Question 1/ Infact, the "amortiss.c" is a part of a seperate program;It is a mex- function connected to matlab, but written in C. It calculates the quotient of two input numbers (x,y) than it transfers the output result (z) to Matlab workspace in order to get a plot of the output (z). At the same time, I want it to transfer the inputs (x,y) to an Excel file (a .CSV file) read by the CLIPS user function. Clips user function is going to calculate the output (z) and then compares it to 1; If (z ==1 then printout t "message1" crlf ); if (z < 1 then printout t "message2" crlf).. This is an idea of what I want to do.So any suggestion, please ?
Question 2/ I wanted to execute the User-define function example written in section 3.4 of the CLIPS Reference Manual but I did not understand steps 5, 6 and 7 (compile and link all object code files and execute new CLIPS executable) knowing that I have a CLIPSWIN.exe and CLIPSDOS.exe . I would like to have further explanation about this. Concerning steps 1, 2, 3 and 4, I should have in whole 3 files:
Construct.clp
Userfunction.c
*** Myfunction.c (which is called in the example TripleNumber)
is my understanding correct?
Thank you so much for all your help and advice. I do appreciate.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You don't need to write any code in C and then link it to CLIPS in order to read values from a file. Just use the build in functions for opening and reading values from a file. If there's just a single value in the file, use the read function. If you have multiple data entries separated by commas, then you may want to use the readline to read the entire line into CLIPS and then strip out the commas using some of the built-in string functions. In this regard, if there are multiple values, you'd probably want them tab delimited or one per line.
Hello,
Unfortunately this solution is not working with me. I typed this:
Clips> (open "calcul.csv" data "r")
TRUE
CLIPS> (read data)
and I got this message:
EOF
which means end of file (Clips should find two numbers in my calcul.csv file: 1,2, these two numbers are the output of a C function and put into.csv file). In other words, CLIPS has not got any access to my "calcul.csv" file. I tried even to add a new number 5 from CLIPS to my .csv file (I used "w" instead of "r"). I got TRUE as a message but in reality when I opened my "calcul.csv" file, nothing changed and the number 5 wasn't really added.
my "calcul.csv" file is saved in the follwing directory: C:\Program Files\CLIPS\calcul.csv
I would like to understand why it always gives me this "EOF" message instead of the numbers? and it seems there is no communication between my .csv file and CLIPS.
A last question, I would like to know if I can use the output (the numbers read by CLIPS) in defining rules? (for example: output == 1 then do action1; ouptut > 1 then do action2)
Thank you for responding these questions. All your help will be appreciated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
EOF indicates the end of file has been reached which would be returned if there were no data at all in the file or if all the data has been read. What happens when you do this:
CLIPS> (open "data.txt" data "w")
TRUE
CLIPS> (printout data 5)
CLIPS> (close data)
TRUE
CLIPS> (open "data.txt" data "r")
TRUE
CLIPS> (read data)
5
CLIPS> (close data)
TRUE
CLIPS>
Once you've successfully read the value, you can use the if or switch statement to conditionally execute code in the actions of the rules:
(bind ?result (read data))
(if (eq ?result 1) then ... else ...)
(switch ?result (case 1 then ...) (case 2 then ...) (default then ...)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello everybody,
I have a C function called "amortiss.c" and I want it to communicate with CLIPS (Expert System Tool).Infact, I want to pass the variable "result" returned by this function "amortiss.c" to CLIPS so that it compares it to 1 and then displays messages depending on the comparaison.
According to the Clips user guide I should define an external function called user-defined function.c. So I am thinking of putting this "result" in an Excel (.CSV file) and then the user defined function reads the "result" values from this .CSV file.
In bref,the .CSV file extracts the "result" from the "amortiss.c" function and then the "user defined.c" function reads it. is there any way to do this? I am really confused. All your suggestion and help will be appreciated.
Thanks.
Unless the C function in the amortiss.c file is run as part of a separate program, you don't want to use a file to transfer data. Instead write a user-defined function that calls the C function in amortiss.c and return that result from the user-defined function.
Thank you for responding.
Question 1/ Infact, the "amortiss.c" is a part of a seperate program;It is a mex- function connected to matlab, but written in C. It calculates the quotient of two input numbers (x,y) than it transfers the output result (z) to Matlab workspace in order to get a plot of the output (z). At the same time, I want it to transfer the inputs (x,y) to an Excel file (a .CSV file) read by the CLIPS user function. Clips user function is going to calculate the output (z) and then compares it to 1; If (z ==1 then printout t "message1" crlf ); if (z < 1 then printout t "message2" crlf).. This is an idea of what I want to do.So any suggestion, please ?
Question 2/ I wanted to execute the User-define function example written in section 3.4 of the CLIPS Reference Manual but I did not understand steps 5, 6 and 7 (compile and link all object code files and execute new CLIPS executable) knowing that I have a CLIPSWIN.exe and CLIPSDOS.exe . I would like to have further explanation about this. Concerning steps 1, 2, 3 and 4, I should have in whole 3 files:
Construct.clp
Userfunction.c
*** Myfunction.c (which is called in the example TripleNumber)
is my understanding correct?
Thank you so much for all your help and advice. I do appreciate.
You don't need to write any code in C and then link it to CLIPS in order to read values from a file. Just use the build in functions for opening and reading values from a file. If there's just a single value in the file, use the read function. If you have multiple data entries separated by commas, then you may want to use the readline to read the entire line into CLIPS and then strip out the commas using some of the built-in string functions. In this regard, if there are multiple values, you'd probably want them tab delimited or one per line.
Thank you very much for this suggestion.
I'm going to try this method and hope it works.
Hello,
Unfortunately this solution is not working with me. I typed this:
Clips> (open "calcul.csv" data "r")
TRUE
CLIPS> (read data)
and I got this message:
EOF
which means end of file (Clips should find two numbers in my calcul.csv file: 1,2, these two numbers are the output of a C function and put into.csv file). In other words, CLIPS has not got any access to my "calcul.csv" file. I tried even to add a new number 5 from CLIPS to my .csv file (I used "w" instead of "r"). I got TRUE as a message but in reality when I opened my "calcul.csv" file, nothing changed and the number 5 wasn't really added.
my "calcul.csv" file is saved in the follwing directory: C:\Program Files\CLIPS\calcul.csv
I would like to understand why it always gives me this "EOF" message instead of the numbers? and it seems there is no communication between my .csv file and CLIPS.
A last question, I would like to know if I can use the output (the numbers read by CLIPS) in defining rules? (for example: output == 1 then do action1; ouptut > 1 then do action2)
Thank you for responding these questions. All your help will be appreciated.
EOF indicates the end of file has been reached which would be returned if there were no data at all in the file or if all the data has been read. What happens when you do this:
Once you've successfully read the value, you can use the if or switch statement to conditionally execute code in the actions of the rules:
Sorry to divert from the topic. But it would be great if either one of you could tell me how to export the Clips result to an excel or a CSV file.