473,465 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Fortran95 Dynamic Array: Reducing the array size multiple times, is it possible?

61 New Member
Hi Guys,

I am currently making a serial algorithm for clustering. I start off with a dynamic array using "ALLOCATABLE" and prompt user for a size then use the ALLOCATE() function to allocate the size.

Now, problem is as this is a cluster algorithm, when I start off with say 12 data points and assuming that each 12 points are on their own cluster, after the first run, I will have 11 data points after I merge 2 of them (algorithm says to merge 2 closest data points by weighted average and you keep on doing that until you cant merge any more because remaining clusters have distance greater than the euclidean norm you chose earlier).

Thing is I now gotta update my array I declared earlier of 12 data points with 11 so I can overwrite one of the entry but gotta get rid of the other. So after every run I gotta now replace the existing n*2 array with (n-1)*2 array. Its a 2D array to store x-coordinate and y-coordinate of data points.

Is there anyway Fortran allows for this or any idea how to get around this?

I looked at DEALLOCATE() but that wipes out the entire array which isn't what I need.

Thanks for looking at this.

Cheers.
Mar 28 '09 #1
2 2372
JosAH
11,448 Recognized Expert MVP
ALLOCATE() a new array, copy over the elements from your old array (only the needed ones) and DEALLOCATE() your old array. I only know Fortran 77 (and it's more than rusty) so I wouldn't know if there's a REALLOCATE() function available; check your manuals.

kind regards,

Jos
Mar 28 '09 #2
Alien
61 New Member
@JosAH
Actually I misunderstood Deallocate(), It simply wipes it clean but not removes the array from memory.

So if I do this:

Expand|Select|Wrap|Line Numbers
  1. PROGRAM test
  2. REAL, DIMENSION(:,:), ALLOCATABLE :: input
  3. INTEGER :: n
  4.  
  5. ! First run
  6. allocate(input(5,5))
  7. n = size(input)
  8. deallocate(input)
  9.  
  10.  
  11. ! Second run
  12. allocate(input(3,2))
  13. n = size(input)
  14. WRITE(*,*) n
  15.  
  16.  
  17. END
  18.  
So on first run, i get 10 and on second run I get 6. So Array is still there. Initially I thought the array gets deleted and you had to created a new array and as you know Fortran, you have to create all your variables before executables which would have caused me problems had it really deleted instead of wiped clean.

So I still gotta do my copy and paste but at least I won't have to work with 50 arrays!

Thanks for looking at this.
Mar 29 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: meyousikmann | last post by:
I am having a little trouble with dynamic memory allocation. I am trying to read a text file and put the contents into a dynamic array. I know I can use vectors to make this easier, but it has to...
14
by: Sameer | last post by:
Hello, i wish to read a file of int and store into an array dynamically... the size of memory allocated finally, should just be sufficeient to store n integers. I do not know the number of...
6
by: Materialised | last post by:
Hi Everyone, I apologise if this is covered in the FAQ, I did look, but nothing actually stood out to me as being relative to my subject. I want to create a 2 dimensional array, a 'array of...
11
by: D | last post by:
hi, i would like to know how to calculate the size of a dynamic array created using a dereference declaration like int *numbers and allocating via malloc or calloc: numbers=(int...
6
by: Rich | last post by:
Hello, I want to simulate the dynamic thumbnail display of Windows Explorer (winxp) on a form or pannel container. If I place a picture box on my container form/pannel and dimension it to the...
60
by: Peter Olcott | last post by:
I need to know how to get the solution mentioned below to work. The solution is from gbayles Jan 29 2001, 12:50 pm, link is provided below: >...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
8
by: Jeff | last post by:
I have a db that has a couple of times closed Access completely when Saving work. So I usually compact and decompile and this seems to fix the problem. But not his time. It has come back again....
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.