I am getting the Array subscript out of range error:
ERROR: Array subscript out of range at line 408 column 169.
SYM_ROOT=FSV DATE=. TIME_M=. BID=. BIDSIZ=. ASK=. ASKSIZ=. EXN=.
FIRST.SYM_ROOT=1 LAST.SYM_ROOT=1 FIRST.DATE=1 LAST.DATE=1 FIRST.TIME_M=1
LAST.TIME_M=1 nexb1=. nexb2=. nexb3=. nexb4=. nexb5=. nexb6=. nexb7=. nexb8=.
nexb9=. nexb10=. nexb11=. nexb12=. nexb13=. nexb14=. nexb15=. nexb16=. nexb17=.
nexo1=. nexo2=. nexo3=. nexo4=. nexo5=. nexo6=. nexo7=. nexo8=. nexo9=. nexo10=.
nexo11=. nexo12=. nexo13=. nexo14=. nexo15=. nexo16=. nexo17=. sexb1=. sexb2=.
sexb3=. sexb4=. sexb5=. sexb6=. sexb7=. sexb8=. sexb9=. sexb10=. sexb11=.
sexb12=. sexb13=. sexb14=. sexb15=. sexb16=. sexb17=. sexo1=. sexo2=. sexo3=.
sexo4=. sexo5=. sexo6=. sexo7=. sexo8=. sexo9=. sexo10=. sexo11=. sexo12=.
sexo13=. sexo14=. sexo15=. sexo16=. sexo17=. _I_=. i=18 BB=. BO=. MIDPRICE=.
BBSize=. BOSize=. NUMEX=. _ERROR_=1 _N_=6417740
However, I am not sure what happened, because the code has previously worked on a different dataset.
The only thing that I can think of is that, because the dataset I am having problem with is the subset of the original one (which worked), it might not have the complete range of exn (I am using a variable named exn as the index of the array).
I defined the array as:
array nexb nexb:; array nexo nexo:; array sexb sexb:; array sexo sexo:;
The variable I am talking about is called exn, and it is used to reference the array:
nexb(exn)=bid;nexo(exn)=ofr;sexb(exn)=bidsiz;sexo(exn)=ofrsiz;
The arrays are initialized in the following way:
do i=1 to 17;
nexb(i)=.; nexo(i)=.; sexb(i)=.; sexo(i)=.;
end;
Originally exn spans from 1 to 17. Now I think some of the numbers in between might be missing in the dataset. But why is that a problem? They are initialized anyways.
You cannot use a missing value as the index into an array. Your log shows that EXN is missing.
Related
I set up a string filled solely with numbers and using a for loop iterated through it in order to add them together mathematically (Wanted to see if the language would allow this), as a result I got some weird Numbers as the result. Can someone explain why this is happening?
int main()
{
std::string word = "2355412";
for (int i = 0; i<word.size(); i++){
int sum = word[i]+word[i+1];
std::cout << sum << std::endl;
}
return 0;
}
The code when run results in:
101
104
106
105
101
99
50
Due to the way I wrote my code I also believe that it should have resulted in an out of bounds error due word[i+1] on the final value resulting in the calling of a value that does not exist. Can someone explain why it did not throw an error?
The value you get is not what you expect because it is the sum of the ascii code corresponding to the characters you are summing, it's not converted into their value by default.
Also, as mentioned by other, string::operator[] doesn't check if you are trying to reach an out of bound value. In this case, you read 0 because you reached the string termination character \0 which happen to be 0.
it should have resulted in an out of bounds error
string::operator[] doesn't check bounds, it assumes you have. If you call it with an out of bounds index, the entire behaviour of your program is undefined, i.e. anything can happen.
It sounds like you want string::at, which does check bounds, and will throw std::out_of_range
I have two variables say x and y and both have around 60 points in them(basically values of the x and y axis of the plot). Now when I try to display it in the result file in form of a column or a table with the x value and the corresponding y value I end up with all the x values displayed in both the columns followed then by the y values. I am unable to get it out correctly.
This is a small part of the code
xpts = PIC1(1,6:NYPIX,1)
ypts = PIC1(2,6:NYPIX,1)
write(21,*), NYPIX
write(21,"(T2,F10.4: T60,F10.4)"), xpts, ypts
This is the output I get. the x values continue from the column 1 to 2 till all are displayed and then the y values are displayed.
128.7018 128.7042
128.7066 128.7089
128.7113 128.7137
128.7160 128.7184
128.7207 128.7231
128.7255 128.7278
128.7302 128.7325
128.7349 128.7373
128.7396 128.7420
128.7444 128.7467
128.7491 128.7514
128.7538 128.7562
128.7585 128.7609
128.7633 128.7656
128.7680 128.7703
128.7727 128.7751
128.7774 128.7798
128.7822 128.7845
128.7869 128.7892
128.7916 128.7940
128.7963 128.7987
128.8011 128.8034
86.7117 86.7036
86.6760 86.6946
86.6317 86.6467
86.6784 86.8192
86.8634 87.0909
87.2584 87.6427
88.1245 88.8343
89.5275 90.2652
91.0958 91.8668
92.6358 93.2986
93.8727 94.4631
You could use a do loop:
do i=1,size(xpts)
write(21,"(T2,F10.4: T60,F10.4)"), xpts(i), ypts(i)
enddo
There is already an answer saying how to get the output as wanted. It may be good, though, to explicitly say why the (unwanted) output as in the question comes about.
In the (generalized) statement
write(unit,fmt) xpts, ypts
the xpts, ypts is the output list. In the description of how the output list is treated we see (Fortran 2008 9.6.3)
If an array appears as an input/output list item, it is treated as if the elements, if any, were specified in array element order
That is, it shouldn't be too surprising that (assuming the lower bound of xpts and ypts are 1)
write(unit, fmt) xpts(1), xpts(2), xpts(3), ..., ypts(1), ypts(2), ...
gives the output seen.
Using a do loop expanded as
write(unit, fmt) xpts(1), ypts(1)
write(unit, fmt) xpts(2), ypts(2)
...
is indeed precisely what is wanted here. However, a more general "give me the elements of the arrays interleaved" could be done with an output implied-do:
write(unit, fmt) (xpts(i), ypts(i), i=LBOUND(xpts,1),UBOUND(xpts,1))
(assuming that the upper and lower bounds of ypts are the same as xpts).
This is equivalent to
write(unit, fmt) xpts(1), ypts(1), xpts(2), ypts(2), ...
(again, for convenience switching to the assumption about lower bounds).
This implied-do may be more natural in some cases. In particular note that the first explicit do loop writes one record for each pair of elements from xpts and ypts; for the implied-do the new record comes about from format reversion. The two for the format in the question are equivalent, but for some more exotic formats the former may not be what is wanted and it ties the structure of the do loop to the format.
This splitting of records holds even more so for unformatted output (which hasn't format reversion).
This is supposed to find pi to the kth digit, however my float seems to be off? Any suggestions?
for k in range (0,1000):
pi[k] = (16**(-1*k)) *((4/(8*k +1)) - (2/(8*k +4)) - (1/(8*k +5)) - (1/(8*k +6)))
print pi[2]
I don't know your requirement but it can be done with the help of floating type array
import array
arr1=array.array('f')
arr1.append(2.9)
arr1.append(30.4584)
print arr1
You can append any number element in it and i have tested it for 921600 element.
For more information regarding array please visit the below linkhttps://docs.python.org/2/library/array.html
float premios[20]={500.00, 700.00, 800.00, 900.00, 1200.00, 1500.00, 1800.00, 2000.00, 2100.00, 2300.00, 2800.00, 3000.00, 3200.00, 3500.00, 4000.00, 10,000.00, 100,000.00, 200,000.00, 500,000.00, 1,000,000.00 };
Look at the code, when i try to compile it, it gives me the error "[Error] too many initializers for 'float [20]' ", it has exactly 20 values, tried to correct it by setting it to 21 values but it didnt work. Then i set the array to an empty array and it worked, can anybody explain me why did it happen?
The "," between each value count as a value. so I think 1,000,000.00 for example count as 3 values. eg. [1, 0, 0]
I believe you were trying to do 1000000.00 instead of 1,000,000.00
Your initializer contains 26 elements.
Adds: Using > float premios[] = ... does not mean it's an empty array -- it means the number of elements in the array is deduced from the initializer, so it will turn out a float[26].
I am using spawn points but when it compiles I'm getting this error:
Array index out of bounds
On this line is the error
for(new i =0 ; i < 5 ;i++) {
SetPlayerPos(playerid, spawnpoints[i][0], spawnpoints[i][1], spawnpoints[i][2]);
}
Hoping somebody knows the solution to the error.
Your array spawnpoints has either less than 5 entries or one of the arrays (spawnpoints[0], spawnpoints[1], spawnpoints[2], spawnpoints[3], spawnpoints[4]) has less than 3 entries. Try debugging your code.
Replace 5 with sizeof(spawnpoints). If you still get the error after this, then your spawnpoints array doesn't contain an x, y and z coordinate (and so is incorrectly structured.)
SetPlayerPos(playerid, Float:x, Float:y, Float:z);
Are spawnpoints defined with Float?
new Float:OldPos[MAX_PLAYERS][3];
Try with this example:
new Float:OldPos[MAX_PLAYERS][3];
GetPlayerPos(i, OldPos[i][0], OldPos[i][1], OldPos[i][2]);