Please how can i solve this task?
A call comes to Asterisk server, a random "x" number (1 - 100 is generated),
if the first two digits in the called number is small or equal to the number 50 from the generated number at that moment, let the Asterisk answer and play a file, if it is big from 50 (50 is the random generated number)
let the Asterisk drop the call.
Please who can help me?
Asterisk have function RAND
Asterisk func rand
Synopsis:
Choose a random number in a range
Description:
RAND([min][,max])
Choose a random number between min and max. Min defaults to 0, if not
specified, while max defaults to RAND_MAX (2147483647 on many systems).
Also you need read about asterisk dialplan and gotoIf function
GotoIf(condition?[label1]:label2)
Go to next step (or label1 if defined) if condition is true or to label2 if condition is false.
Either label1 or label2 may be omitted (in that case, we just don't take the particular branch), but not both.
condition is just a string. If the string is empty or "0", the condition is considered to be false. If it is anything else, the condition is true. This is designed to be used together with expression syntax.
http://www.voip-info.org/wiki/view/Asterisk+func+rand
http://www.voip-info.org/wiki/view/Asterisk+cmd+GotoIf
There are several ways to achieve what you want and the simplest way I can think is add the following line to your existing dialplan:
ExecIf($[ ${RAND(1,100)} < 50 ]?HangUp():Playback(youraudiofile))
Explaining further: This line will test the value returned from the function RAND, if it return 1 to 49 the ExecIf application will execute the command HangUp(), if the value is higher than 50 it will execute the command Playback to playback the given audio file name and then move on to the next dialplan line.
Don't forget to replace 'youraudiofile' with the name of your actual audio file that should be placed on your asterisk sound folder (tipically /var/lib/asterisk/sounds/).
Related
I have one column (im = 160648) and row (jm = 1). I want to transform that to a matrix with sizes (im = 344) and (jm=467)
my program code is
program matrix
parameter (im=160648, jm=1)
dimension h(im,jm)
integer::h
open (1,file="Hasil.txt", status='old')
open (2,file="HasilNN.txt", status='unknown')
do i=1,jm
read(1,*)(h(i,j)),j=1,jm)
end do
do i=1,im
write(2,33)(h(i,j),j=1,jm)
end do
33 format(1x, 344f10.6)
end program matrix
the error code that appears when read(1,*)(h(i,j)),j=1,jm)
the data type is floating data.
Your read loop is:
do i=1,jm
read(1,*)(h(i,j)),j=1,jm)
end do
Shouldn't do i=1,jm be do i=1,im ?
This would imply there are "im" records (lines) in the formatted text file Hasil.txt, which your question suggests.
read(1,*)(h(i,j)),j=1,jm) implies each record (line of text) has "jm" values, which is 1 value per line. Is this what the file looks like ? (An unknown number of blank lines will be skipped with this read (lu,*) ... statement.)
You appear to be wanting to write this information to another file; HasilNN.txt using 33 format (1x, 344f10.6) which suggests 3441 characters per line, although your write statement will write only 1 value per line (as jm=1). This would be a very long line for a text file and probably difficult to manage outside the program. If you did wish to do this, you could achieve this with an implied do loop, such as:
write(2,33) ((h(i,j),j=1,jm),I=1,im)
A few comments:
using jm = 1 implies each row has only one value, which could be equivalently represented as a 1d vector "dimension h(im)", negating the need for j
File unit numbers 1 and 2 are typically reserved unit numbers for screen/keyboard. You would be better using units 11 and 12.
When devising this code, you need to address the record structure in the 2 files, as a simple vector could be used. You can control the line length with the format. A format of (1x,8f10.6) would create a record of 81 characters, which would be much easier to manage.
Format descriptor f10.6 also limits the range of values you can manage in the files. Values >= 1000 or <= -100 will overflow this format, while values smaller than 1.e-6 will be zero.
As #francescalus has noted, you have declared "h" as integer, but use a real format descriptor. This will produce an "Error : format-data mismatch" and has to be changed to what is expected in the file.
You should consider what you wish to achieve and adjust the code.
How can I have different parameters value defined in .ini file for each repeat in omnet using cmdenv? I have repeat value as 4 and trying to have different value of accidentStart and accidentDuration.
You can't. And shouldn't. The whole point of repetition is that all parameters have the same value, just the RNGs are seeded differently. So you get a different sample of the same distribution for every result value.
What you're looking for are iteration variables.
Something like this:
**.accidentStart = ${100, 200, 350}s
This will generate 3 runs without repetition, and 12 runs with repeat=4.
and if you add
**.accidentDuration = ${duration=300, 450, 600..1800 step 600}s
this will multiply the number of runs by another factor of 5.
By default, iteration variables produce a Cartesian product of their respective assigned sets of values. But there are ways to change this, consult the manual for how.
i have a datatbase in Oracle with a table, whichs holds about 700.000 rows.
Now i have set indexes(Context) for columns i want to search for(First,Last and Other_Names).
If i run the Statement below, it takes about 45sec.
But if i change the OR to an AND then it takes just 0.187sec.
So what is happening here?
And how can i solve it (I need the or Operator)
Thx
SELECT score(1),FIRST_NAME,LAST_NAME,OTHER_NAMES
FROM VIEW_NAMEN
WHERE (CONTAINS(LAST_NAME,'Merkel',0) > 0
AND CONTAINS(FIRST_NAME,'Angela',1) >0)
OR (CONTAINS(OTHER_NAMES,'%Angela% AND %Merkel%',2)>0) ;
First of all, you should use parentheses when using ANDs and ORs to ensure that they are being performed as you expect. Your WHERE clause is equivalent to:
WHERE ( CONTAINS(LAST_NAME,'Merkel',0) > 0
AND CONTAINS(FIRST_NAME,'Angela',1) >0 )
OR (CONTAINS(OTHER_NAMES,'%Angela% AND %Merkel%',2)>0)
Which may or may not be what you want.
My guess is that the final condition CONTAINS(OTHER_NAMES,'%Angela% AND %Merkel%',2)>0 is much slower to process than the other two (it is more complex).
When you change the OR to AND (and so parentheses are not required) then first the query will look for people whose last name contains 'Merkel'. Maybe only a few hundred. Then it filters those 500 (say) for first name contains 'Angela'. Maybe there are only 10 of these. Finally it applies the other_names condition, just to those 10 rows. If that condition takes 0.00006 seconds per row to evaluate, then it will take 0.00006*10 = 0.0006 seconds.
But with the OR, you are now looking for people whose last name is Merkel and first name is Angela OR whose other names contains Angela and Merkel. So the last condition has to check all the people whose first name and last name isn't Angela Merkel, i.e. nearly 700,000. And this will take about 700,000*0.00006 = 42 seconds.
OK, that's what may be happening. As for how to make CONTAINS(OTHER_NAMES,'%Angela% AND %Merkel%',2)>0 go faster, I'm afraid I don't know!
I am trying to assign multiple codes to existing variables. I am using the syntax below, but it will only assign the first code entered for that hosp.id.number.
Syntax example:
Do if (hosp.id.number=9037) or (hosp.id.number=1058) or (hosp.id.number=11256).
Compute role_EM_communication=10.
Else if (hosp.id.number=9037.
Compute role_EM_communication=11.
End if.
Execute.
hosp.id.number needs to be coded 10 and 11, but it will only code it at 10. Anyway to rephrase so that SPSS will accept 2 or more codes for a variable such as hosp.id.number?
Your role_EM_communication variable is a single variable, but from what you are saying, I think you need it to be a set (for the same record, it could take on more than just one code). So you need to create n variables named role_EM_communication_1 to role_EM_communication_n, where n is the maximum number of codes you estimate will be possible for one record.
For your example, it would translate like this:
create the 2 variables:
vector role_EM_communication_ (2, f2.0).
do the first recode:
if any(hosp.id.number,9037,1058,11256) role_EM_communication_1=10.
very important - execute the recode
exe.
check if the first variable has data, and populate the second variable if true:
if miss(role_EM_communication_1) and any(hosp.id.number,9037) role_EM_communication_1=11.
if ~miss(role_EM_communication_1) and any(hosp.id.number,9037) role_EM_communication_2=11.
exe.
I am attempting to use fortran to write out a comma-delimited file for import into another commercial package. The issue is that I have an unknown number of data columns. My output needs to look like this:
a_string,a_float,a_different_float,float_array_elem1,float_array_elem2,...,float_array_elemn
which would result in something that might look like this:
L1080,546876.23,4325678.21,300.2,150.125,...,0.125
L1090,563245.1,2356345.21,27.1245,...,0.00983
I have three issues. One, I would prefer the elements to be tightly grouped (variable column width), two, I do not know how to define a variable number of array elements in the format statement, and three, the array elements can span a large range--maybe 12 orders of magnitude. The following code conceptually does what I want, but the variable 'n' and the lack of column-width definition throws an error (of course):
WRITE(50,900) linenames(ii),loc(ii,1:2),recon(ii,1:n)
900 FORMAT(A,',',F,',',F,n(',',F))
(I should note that n is fixed at run-time.) The write statement does what I want it to when I do WRITE(50,*), except that it's width-delimited.
I think this thread almost answered my question, but I got quite confused: SO. Right now I have a shell script with awk fixing the issue, but that solution is...inelegant. I could do some manipulation to make the output a string, and then just write it, but I would rather like to avoid that option if at all possible.
I'm doing this in Fortran 90 but I like to try to keep my code as backwards-compatible as possible.
the format close to what you want is f0.3, this will give no spaces and a fixed number of decimal places. I think if you want to also lop off trailing zeros you'll need to do a good bit of work.
The 'n' in your write statement can be larger than the number of data values, so one (old school) approach is to put a big number there, eg 100000. Modern fortran does have some syntax to specify indefinite repeat, i'm sure someone will offer that up.
----edit
the unlimited repeat is as you might guess an asterisk..and is evideltly "brand new" in f2008
In order to make sure that no space occurs between the entries in your line, you can write them separately in character variables and then print them out using theadjustl() function in fortran:
program csv
implicit none
integer, parameter :: dp = kind(1.0d0)
integer, parameter :: nn = 3
real(dp), parameter :: floatarray(nn) = [ -1.0_dp, -2.0_dp, -3.0_dp ]
integer :: ii
character(30) :: buffer(nn+2), myformat
! Create format string with appropriate number of fields.
write(myformat, "(A,I0,A)") "(A,", nn + 2, "(',',A))"
! You should execute the following lines in a loop for every line you want to output
write(buffer(1), "(F20.2)") 1.0_dp ! a_float
write(buffer(2), "(F20.2)") 2.0_dp ! a_different_float
do ii = 1, nn
write(buffer(2+ii), "(F20.3)") floatarray(ii)
end do
write(*, myformat) "a_string", (trim(adjustl(buffer(ii))), ii = 1, nn + 2)
end program csv
The demonstration above is only for one output line, but you can easily write a loop around the appropriate block to execute it for all your output lines. Also, you can choose different numerical format for the different entries, if you wish.