- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I need to know if a compiler directive exists that will let me do the following:
a$s%num_funds = a$s%num_funds + 1
call move_alloc(a$s%fund_label, t_fund_label)
allocate(a$s%fund_label(a$s%num_funds))
a$s%fund_label = t_fund_label
a$s%fund_label(a$s%num_funds) = 'Extra Added'
I increased the size of a$s%fund_labels plus 1, but when I copy the original data back it changes the allocation of a$s%fund_label. I believe that I found an article about compiler settings to change that, but I just cannot find those settings in my project.
Thanks.
Michael
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Why not keep the code in agreement with the standard, and write as follows?
a$s%fund_label(:a$s%num_funds-1) = t_fund_label
The array has been extended in size by 1, and you have saved the old contents in t_fund_label, so the two sides of this statement conform, and thus a$s%fundlabel will not be reallocated.
Something undesirable remains: you are copying the values twice: first from the old a$s%fund_label to t_fund_label, and then back to the new a$s%fund_label. The purpose of move_alloc, among other things, is to avoid such double copying. Try to rewrite the code to achieve that saving.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Another question. We do not use initialize variables to zero. I decided for this new application that I should. I also set initialize arrays as well as scalers. The array I am enlarging is a defined type and I am getting random numbers in all of the items that make up the type. I need them to initialize to 0. Is there a setting to do that? I have not seen one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
On your original question, you can't assign an array of one shape to an array with a different shape. You could prevent the reallocation by doing A(:)=B (see Doctor, it hurts when I do this! ) but if A and B have different numbers of elements, then that's invalid and the results unpredictable.
There is no option to initialize derived type values to zero. You can add an initial value to each component in the derived type declaration, and that will be used when variables of that type are created.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page