Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

numbers that can differentiate uniquely between the combinations

Status
Not open for further replies.

lehloks

Programmer
Jul 12, 2013
40
ZA
Hi forum users
I need a set of numbers that can differentiate uniquely between the combinations.I choose powers of 3. Starting with 1, that gives multiples of 1, 2 and 3 before I reach the next number, which is 3, with it having multiples of 3, 6, 9, etc. If I write out the combinations you can see what happens when you add them:

1 = 1 (eg. 1 Si)
2 = 1 + 1 (eg. 2 Si)
3 = 1 +
1 + 1 (e.g. 3 Si) or 3 (e.g. 1 Al) alone, and so now I have a problem, I can pick up 1 occurrence of the atom labelled 1, and two occurrences, but then one Al will give the same result as 3 Si. Since the Al atoms with their labels of 3 have multiples of 6, 9, etc, I'll never accidently find 4, 5 and/or 7/8, which I can only reach once I'm adding multiples of 1. With this set I can thus give a unique number to each possible combination of the two (but not three). I can pick any way forward, as long as you make sure that you get unique combinations every time.

Now Im stuck I want extend the assignment to 5 atoms : eg assigning a special number for other atoms like Mg,Ca, O and Na. Any one with a unique idea how can I do this. I want a code to be general so that It can be used for many things. I can assign atom name but my code wont be efficient and it will have many if statements.My assignments are shown in the code below.



[! Assign Si = 3**0 = 1, Al = 3**1 = 3 and unknown metals U = 3**2 = 9
! then we can identify pairs and triads easily without ordering
! [Si,Si] = 3**0 + 3**0 = 1 + 1 = 2
! [Si,Al] = [Al,Si] = 1 + 3 = 4
! [Al,Al] = 3 + 3 = 6
! [U,U] = 9 + 9 = 18
! [Al,U] = 3 + 9 = 12
! [Si,U] = 1 + 9 = 10
! [Si,Si,Si] = 1 + 1 + 1 = 3
! [Si,Si,Al] = 1 + 1 + 3 = 5
! [Si,Al,Al] = 1 + 3 + 3 = 7
! [Al,Al,Al] = 3 + 3 + 3 = 9
! [U,U,U] = 9 + 9 + 9 = 27
! [U,U,Si] = 9 + 9 + 1 = 19
! [U,U,Ai] = 9 + 9 + 3 = 21
! [U,Si,Si] = 9 + 1 + 1 = 11
! [U,Si,Al] = 9 + 1 + 4 = 14
! [U,Al,Al] = 9 + 3 + 3 = 15]

[do i = 1, natms
if (atmname(i) == silicon) then
id(i) = Si

elseif (atmname(i) == aluminium) then

id(i) = Al
else
id(i) = 9
endif
enddo

do i = 1, natms
do k = 1, nmetals
if (atmname(i) == metals(k)) then
do j = i, natms
if (atmname(j) == oxygen) then
bndtab(i,j) = mbonds(k)**2
bndtab(j,i) = bndtab(i,j)
endif
enddo
endif
enddo
enddo

endif
]

Then when I get the assignment correctly I want to use the code as this where I sect a correct or desired case as shown below.

[do i = 1, natms
if ((atmname(i) == oxygen) .and. (cnlist(i) .eq. 2)) then
select case ( id(blist(bindex(i))) + id(blist(bindex(i)+1)) )
case (2)
write(logfile,*)'[Si,Si] bridge'
nbo = nbo + 1
case (4)
write(logfile,*)'[Si,Al] bridge'
nbo = nbo + 1
case (6)
write(logfile,*)'[Al,Al] bridge'
nbo = nbo + 1
case (10)
write(logfile,*)'[Si,Ca/Mg] disconnect'
nnbo = nnbo + 1
case (12)
write(logfile,*)'[Al,Ca/Mg] disconnect'
nnbo = nnbo + 1
case (18)
write(logfile,*)'[Mg/Ca,Ca/Mg] disconnect'
end select
endif
]
 
Curious problem...and I think you already found a solution to it...I can see a pattern.

If you are interested in combining any two atoms at a time, you can assign them numbers that are powers of 2; with the limitation that every atom can only appear once in a combination.

If you are interested in combining any 3 atoms at a time, you can assign them numbers that are powers of 3; with the limitation that every atom can only appear 2 times in a combination.

If you are interested in combining any 4 atoms at a time, you can assign them numbers that are powers of 4; with the limitation that every atom can only appear 3 times in a combination.

...and so on.

I think this way, every combination will have a unique number and to find out which atoms are part of the combination, you just start dividing by the largest number that you have assigned, see how many times it fits and work your way down with the residual and the next assigned number down.

 
Thanks Salgerman

Can you illustrate with an example so that I can see your approach for example demonstrate using this statement.If you are interested in combining any 3 atoms at a time, you can assign them numbers that are powers of 3; with the limitation that every atom can only appear 2 times in a combination.

The combination that appears two times its interesting. In my initial thinking,I thought about read,write and execute permissions (rwx) where r or w can only appear once not repeated. But Im interested in a situation where an atom can appear twice only as you stated.

Regards
Lehloks
 
Powers of 2 are used extensively to put in a integer value a set of logical values (up to 32 in a 32bit integer), any combination becoming possible : for instance 7=2^0+2^1+2^2 means that the options 1 ,2 and 3 are all active (like read,write,execute for a file).

Depending on the number of atoms, you want to combine, I suggest to choose the highest possible value. For instance 10 !

Si=1
Al=10
U=100

5 => Si+Si+Si+Si+Si
11 => Al+Si
111 => U+Al+Si
...



François Jacq
 
And what about using of primes factorization?
See here:

For example there are these first 10 primes:
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

1. You can encode with it 10 chemical elements, e.g.:
Si = 2
Al = 3
U = 5
...
etc.

2. Then you can encode any combination of your elements, for example
4*Si, 1*Al, 2*U
into an integer number using the formula given in the link above:
N = 2**4 * 3**1 * 5**2 = 1200

3. You can decode the number using an factorization algorithm such like
and get back the primes - for example for N=1200 we get:
[2, 2, 2, 2, 3, 5, 5]
that is
4*2, 1*3, 2*5
looking at the encoding table above we have the combination
4*Si, 1*Al, 2*U

Here is my working prototype in Python - it could be possible to rewrite it in Fortran:

Code:
[COLOR=#0000ff]# Based on:[/color]
[COLOR=#0000ff]# [URL unfurl="true"]http://en.wikipedia.org/wiki/Trial_division[/URL][/color]
[COLOR=#804040][b]def[/b][/color] [COLOR=#008080]trial_division[/color](n):
    [COLOR=#ff00ff]"""Return a list of the prime factors for a natural number."""[/color]
    [COLOR=#804040][b]if[/b][/color] n == [COLOR=#ff00ff]1[/color]: [COLOR=#804040][b]return[/b][/color] [[COLOR=#ff00ff]1[/color]]
    primes = [[COLOR=#ff00ff]2[/color], [COLOR=#ff00ff]3[/color], [COLOR=#ff00ff]5[/color], [COLOR=#ff00ff]7[/color], [COLOR=#ff00ff]11[/color], [COLOR=#ff00ff]13[/color], [COLOR=#ff00ff]17[/color], [COLOR=#ff00ff]19[/color], [COLOR=#ff00ff]23[/color], [COLOR=#ff00ff]29[/color]]
    prime_factors = []
 
    [COLOR=#804040][b]for[/b][/color] p [COLOR=#804040][b]in[/b][/color] primes:
        [COLOR=#804040][b]if[/b][/color] p*p > n: [COLOR=#804040][b]break[/b][/color]
        [COLOR=#804040][b]while[/b][/color] n % p == [COLOR=#ff00ff]0[/color]:
            prime_factors.append(p)
            n /= p
    [COLOR=#804040][b]if[/b][/color] n > [COLOR=#ff00ff]1[/color]: prime_factors.append(n)

    [COLOR=#804040][b]return[/b][/color] prime_factors

[COLOR=#804040][b]if[/b][/color] __name__==[COLOR=#ff00ff]"__main__"[/color]:
   [COLOR=#0000ff]# create a number[/color]
   n = [COLOR=#ff00ff]2[/color]**[COLOR=#ff00ff]3[/color] * [COLOR=#ff00ff]3[/color] * [COLOR=#ff00ff]5[/color]**[COLOR=#ff00ff]2[/color]

   [COLOR=#0000ff]# factorize number[/color]
   primes=trial_division(n)
   [COLOR=#008080]print[/color] primes

   [COLOR=#0000ff]# create a number[/color]
   n = [COLOR=#ff00ff]2[/color]**[COLOR=#ff00ff]4[/color] * [COLOR=#ff00ff]3[/color]**[COLOR=#ff00ff]1[/color] * [COLOR=#ff00ff]5[/color]**[COLOR=#ff00ff]2[/color] [COLOR=#0000ff]# = 1200[/color]

   [COLOR=#0000ff]# factorize number[/color]
   primes=trial_division(n)
   [COLOR=#008080]print[/color] primes

Output:
Code:
$ python factorisation.py
[2, 2, 2, 3, 5, 5]
[2, 2, 2, 2, 3, 5, 5]
 
Thanks a lot guys

With these Ideas I can also be able to work out how long my Si and Al polymer chains. I like the most mikrom Idea.But one more question just for interest is it possible to work out the combination in advance because of systems with varrying number of atoms one of them is 2377 atoms = N

thanks a lot.
 
lehloks said:
just for interest is it possible to work out the combination in advance because of systems with varrying number of atoms one of them is 2377 atoms = N
I don't understand what you mean with 2377 atoms, please specify it.
I found out that there are only 118 chemical elements:

If you will have 118 chemical elements and want to use the prime factorizatione method, you will need the first 118 prime numbers - see
Then the resulting numbers for encoding your elements combination could be very huge, so maybe you will have technical problems using build in integer types ...

The factorization of huge numbers using the trial division method would be hard, because of its exponential complexity, so maybe you will have to search for more efficient method ...

I suggest to try the approach first on a smaller number of elements and see how it works and if it fullfil your expectations.
 
just for interest is it possible to work out the combination in advance because of systems with varrying number of atoms one of them is 2377 atoms = N"
Sorry for this!
I meant system size made up of 2377 atoms,with 5 atom types.
 
For encoding 5 elements, you only need first 5 prime numbers: [2, 3, 5, 7, 11]
IMO it will be OK.
 
That's bate and switch!...you first innocently talk about combining 3 atoms at a time and now you are talking a chain 2000 long! Not cool...you should have given a hint of your needs from the beginning :-(

Assigning unique ID for every atom using powers of (n+1) where n is the maximum number of times you want a given atom to be able to appear in the combination gets a bit crazy quick...now that you mention that an atom may have to appear hundreds or even a thousand times in a combination. For example, if you want an atom be able to appear 999 times in a combination, you would need to assign ID to atoms as powers of 1000...for 5 atoms involved in the combination, their IDs would be 1000, 1000000, 1000000000, 1000000000000, 1000000000000000. And the summation of these numbers hundreds of times will get very large. The main problem with this approach is the exponential growth of ID and, consequently, the large gap of unused IDs in between consecutive IDs...for a final combination ID being a very large number.

I too like the prime number approach. In that case, the gap between unused IDs is rather small, keeping all IDs also small...the only problem is that the final combination ID is no longer the summation of ID, but the multiplication of their exponentiation...this is going to get large, too, if any one of them needs to be raised to the 1000 power!

If you assign permanent IDs to each atom and you have 118 of them, possibly in the same order as the periodic table, some will necessarily get assigned a rather large prime number that when raised to a power of 800 it is going to be a rather large number. This approach allows you to have unique IDs for every combination, but the combination IDs will get unnecessarily large or impossible to store as numeric value.

One way to alleviate the problem above is to not limit yourself to specifying combinations via a single attribute (unique ID), instead, create a structure and include the list of atoms that are going to be part of the combination and assign to this atoms the first few prime numbers and that is it...combination numbers would be unique on a per set-of-atoms-involved basis....even 2**1000, though, is large.

Any particular reason why you are not simply using strings? : "(1602*H)(800*C)"
[ul]
[li]they can be put together easily and consistently...need to develop strategy of listing atoms in alphabetical or atomic-weight order or something.[/li]
[li]they can be easily compared[/li]
[li]they would be unique[/li]
[li]no need to worry about storage of very large numbers[/li]
[/ul]
gsal
 
One more thing...have you google or visited chemical-engineering forums? molecular-analysis forums? or something? I am thinking you are not the first looking into this problem and there may already exist some software out there for this kind of task...talk about Python...I think I have seen some molecular analysis module.
 
Hi gsal

Yes its combination of 3 atoms because im interested in bonding angles, bond lengths, and other short range order properties which takes place between 2 to 3 atoms. I raised the issue of chain because microm suggestion gave an idea that I can also look at how long the chains are, which is what im trying to do now from his suggested solution. What you saying its true I realised earlier that the no increases exponentially as you increase the no of atoms. Also the gap becomes too large and jump other atoms when you used too large numbers.
 
I thought that you mean the total number of combinations should be possible up to 2377.
But maybe you mean that one element may occur in one combination 2377 times? In this case if you want to encode the combination of 2377*Si, then you will get a very large number, i.e. 2**2377. Then you have to search for the specialized library for working with large numbers ... maybe something for cryptography.

Just for curiosity: why do you thing, that you need to encode the element combination into one number?

For example, a simple approach would be to define for every element an array which holds the occurence:
Code:
integer, dimension (maxN) :: Si, Al, Mg, Ca, U
then when you have for example these combinations
Code:
1. 4*Si, 1*Al, 2*U  
2. 2377*Si
...
your arrays will have following values:
Code:
Si(1)=4   , Al(1)=1, Mg(1)=0, Ca(1)=0, U(1)=2
Si(2)=2377, Al(2)=0, Mg(2)=0, Ca(2)=0, U(2)=0
...
 
Hi microm
I atoms which are not bonded,I put them in a box,then I run an MD simulation,they react and form bonds, I know the likes bonds. I have already observed them using my other code. I also abserved the formation of triads Si-Al-Mg forming in my system. Now there is a competion between Mg and Ca, I want to determine the number of Si-Al-Mg and Si-Al-Ca formed in the system. From this I can tell and use the available theory to confirm the most likely reaction to take place.

Instead of what you suggesting which I think its also a good idea 'integer, dimension (maxN) :: Si, Al, Mg, Ca, U ' I have used a verlet list to determine atoms which are closer to each other.



 
Here I have included bits of the code,In the first part I assign a unique number to the atoms, then combine them, then use the combination at a later part of the code. Now I want to assign unique numbers to Ca and Mg and use them as shown below in the code


[! Assign Si = 3**0 = 1, Al = 3**1 = 3 and unknown metals 3**2 = 9
! then we can identify pairs and triads easily without ordering
! [Si,Si] = 3**0 + 3**0 = 1 + 1 = 2
! [Si,Al] = [Al,Si] = 1 + 3 = 4
! [Al,Al] = 3 + 3 = 6
! [U,U] = 9 + 9 = 18
! [Al,U] = 3 + 9 = 12
! [Si,U] = 1 + 9 = 10
! [Si,Si,Si] = 1 + 1 + 1 = 3
! [Si,Si,Al] = 1 + 1 + 3 = 5
! [Si,Al,Al] = 1 + 3 + 3 = 7
! [Al,Al,Al] = 3 + 3 + 3 = 9
! [U,U,U] = 9 + 9 + 9 = 27
! [U,U,Si] = 9 + 9 + 1 = 19
! [U,U,Ai] = 9 + 9 + 3 = 21
! [U,Si,Si] = 9 + 1 + 1 = 11
! [U,Si,Al] = 9 + 1 + 4 = 14
! [U,Al,Al] = 9 + 3 + 3 = 15

do i = 1, natms
if (atmname(i) == silicon) then
id(i) = 1

elseif (atmname(i) == aluminium) then

id(i) = 3
else
id(i) = 9
endif
enddo

do i = 1, natms
do k = 1, nmetals
if (atmname(i) == metals(k)) then
do j = i, natms
if (atmname(j) == oxygen) then
bndtab(i,j) = mbonds(k)**2
bndtab(j,i) = bndtab(i,j)
bndtab(j,i) = bndtab(i,j)
endif
enddo
endif
enddo
enddo

endif
]



second part of the code:this where I use the

[ nbo = 0
nnbo = 0
ntbo = 0
call cpu_time(tstart)
! [Si,Si] = 3**0 + 3**0 = 1 + 1 = 2
! [Si,Al] = [Al,Si] = 1 + 3 = 4
! [Al,Al] = 3 + 3 = 6
! [U,U] = 9 + 9 = 18
! [Al,U] = 3 + 9 = 12
! [Si,U] = 1 + 9 = 10
do i = 1, natms
if ((atmname(i) == oxygen) .and. (cnlist(i) .eq. 2)) then
select case ( id(blist(bindex(i))) + id(blist(bindex(i)+1)) )
case (2)
write(logfile,*)'[Si,Si] bridge'
nbo = nbo + 1
case (4)
write(logfile,*)'[Si,Al] bridge'
nbo = nbo + 1
case (6)
write(logfile,*)'[Al,Al] bridge'
nbo = nbo + 1
case (10)
write(logfile,*)'[Si,Ca/Mg] disconnect'
nnbo = nnbo + 1
case (12)
write(logfile,*)'[Al,Ca/Mg] disconnect'
nnbo = nnbo + 1
case (18)
write(logfile,*)'[Mg/Ca,Ca/Mg] disconnect'
end select
endif
]
 
Use [pre]
Code:
 [/code ][/pre] tags for enclosing the code
 
[/[! Assign Si = 3**0 = 1, Al = 3**1 = 3 and unknown metals 3**2 = 9
! then we can identify pairs and triads easily without ordering
! [Si,Si] = 3**0 + 3**0 = 1 + 1 = 2
! [Si,Al] = [Al,Si] = 1 + 3 = 4
! [Al,Al] = 3 + 3 = 6
! [U,U] = 9 + 9 = 18
! [Al,U] = 3 + 9 = 12
! [Si,U] = 1 + 9 = 10
! [Si,Si,Si] = 1 + 1 + 1 = 3
! [Si,Si,Al] = 1 + 1 + 3 = 5
! [Si,Al,Al] = 1 + 3 + 3 = 7
! [Al,Al,Al] = 3 + 3 + 3 = 9
! [U,U,U] = 9 + 9 + 9 = 27
! [U,U,Si] = 9 + 9 + 1 = 19
! [U,U,Ai] = 9 + 9 + 3 = 21
! [U,Si,Si] = 9 + 1 + 1 = 11
! [U,Si,Al] = 9 + 1 + 4 = 14
! [U,Al,Al] = 9 + 3 + 3 = 15

do i = 1, natms
if (atmname(i) == silicon) then
id(i) = 1

elseif (atmname(i) == aluminium) then

id(i) = 3
else
id(i) = 9
endif
enddo

do i = 1, natms
do k = 1, nmetals
if (atmname(i) == metals(k)) then
do j = i, natms
if (atmname(j) == oxygen) then
bndtab(i,j) = mbonds(k)**2
bndtab(j,i) = bndtab(i,j)
bndtab(j,i) = bndtab(i,j)
endif
enddo
endif
enddo
enddo

endif]



[/second part of the code:this where I use the
nbo = 0
nnbo = 0
ntbo = 0
call cpu_time(tstart)
! [Si,Si] = 3**0 + 3**0 = 1 + 1 = 2
! [Si,Al] = [Al,Si] = 1 + 3 = 4
! [Al,Al] = 3 + 3 = 6
! [U,U] = 9 + 9 = 18
! [Al,U] = 3 + 9 = 12
! [Si,U] = 1 + 9 = 10
do i = 1, natms
if ((atmname(i) == oxygen) .and. (cnlist(i) .eq. 2)) then
select case ( id(blist(bindex(i))) + id(blist(bindex(i)+1)) )
case (2)
write(logfile,*)'[Si,Si] bridge'
nbo = nbo + 1
case (4)
write(logfile,*)'[Si,Al] bridge'
nbo = nbo + 1
case (6)
write(logfile,*)'[Al,Al] bridge'
nbo = nbo + 1
case (10)
write(logfile,*)'[Si,Ca/Mg] disconnect'
nnbo = nnbo + 1
case (12)
write(logfile,*)'[Al,Ca/Mg] disconnect'
nnbo = nnbo + 1
case (18)
write(logfile,*)'[Mg/Ca,Ca/Mg] disconnect'
end select
endif
]
 
No, lehloks, you need to write the entire sequence of left-bracket,the word 'code' (w/o apostrophies) and right-bracket BEFORE your source code; then, AFTER your source code you finalize it with a similar bracket-'code'-bracket, this time, though, you precede the word 'code' with a slash '/'.

OR

you can highlight your source code and then click on the "code formatting" icon in the bar along the top of the editing window...it is between the guy with a message box and the wrapped gift.
 
Code:
[/[! Assign Si = 3**0 = 1, Al = 3**1 = 3 and unknown metals 3**2 = 9
! then we can identify pairs and triads easily without ordering
! [Si,Si] = 3**0 + 3**0 = 1 + 1 = 2
! [Si,Al] = [Al,Si] = 1 + 3 = 4
! [Al,Al] = 3 + 3 = 6
! [U,U] = 9 + 9 = 18
! [Al,U] = 3 + 9 = 12
! [Si,U] = 1 + 9 = 10
! [Si,Si,Si] = 1 + 1 + 1 = 3
! [Si,Si,Al] = 1 + 1 + 3 = 5
! [Si,Al,Al] = 1 + 3 + 3 = 7
! [Al,Al,Al] = 3 + 3 + 3 = 9
! [U,U,U] = 9 + 9 + 9 = 27
! [U,U,Si] = 9 + 9 + 1 = 19
! [U,U,Ai] = 9 + 9 + 3 = 21
! [U,Si,Si] = 9 + 1 + 1 = 11
! [U,Si,Al] = 9 + 1 + 4 = 14
! [U,Al,Al] = 9 + 3 + 3 = 15

do i = 1, natms
if (atmname(i) == silicon) then
id(i) = 1

elseif (atmname(i) == aluminium) then

id(i) = 3
else
id(i) = 9
endif
enddo

do i = 1, natms
do k = 1, nmetals
if (atmname(i) == metals(k)) then
do j = i, natms
if (atmname(j) == oxygen) then
bndtab(i,j) = mbonds(k)**2
bndtab(j,i) = bndtab(i,j)
bndtab(j,i) = bndtab(i,j)
endif
enddo
endif
enddo
enddo

endif]



[/second part of the code:this where I use the
nbo = 0
nnbo = 0
ntbo = 0
call cpu_time(tstart)
! [Si,Si] = 3**0 + 3**0 = 1 + 1 = 2
! [Si,Al] = [Al,Si] = 1 + 3 = 4
! [Al,Al] = 3 + 3 = 6
! [U,U] = 9 + 9 = 18
! [Al,U] = 3 + 9 = 12
! [Si,U] = 1 + 9 = 10
do i = 1, natms
if ((atmname(i) == oxygen) .and. (cnlist(i) .eq. 2)) then
select case ( id(blist(bindex(i))) + id(blist(bindex(i)+1)) )
case (2)
write(logfile,*)'[Si,Si] bridge'
nbo = nbo + 1
case (4)
write(logfile,*)'[Si,Al] bridge'
nbo = nbo + 1
case (6)
write(logfile,*)'[Al,Al] bridge'
nbo = nbo + 1
case (10)
write(logfile,*)'[Si,Ca/Mg] disconnect'
nnbo = nnbo + 1
case (12)
write(logfile,*)'[Al,Ca/Mg] disconnect'
nnbo = nnbo + 1
case (18)
write(logfile,*)'[Mg/Ca,Ca/Mg] disconnect'
end select
endif
]
 
Another option is to consider bit patterns based on frequency. Say Si can occur up to 30 times, U up to 100 times, Al up to 50 times. You can use 8 byte integers which should take you up to 64 bits. Beyond that, you'll have to use a different technique.

First round up to the nearest multiple of 2

Si 30 => 32 - 5 bits - bits 0..4
U 100 => 128 - 7 bits - bits 5..11
Al 50 => 64 - 6 bits - bits 12..16

Code:
17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
<--     Al    --> <--      U       --> <--   Si   -->

The initial value will be the base value - 2 to the lowest bit number

Si 2**0 = 1
U 2**5 = 32
Al 2**12 = 4096

So U,Al,Al would be 32 + 2 * 4096.
To work out what a pattern has,
Code:
integer:: elem(3)
character*2:: mnem(3)
mnem(1) = 'Si'
elem(1) = 1 ! Si
mnem(2) = 'U '
elem(2) = 32 ! U
mnem(3) = 'Al'
elem(3) = 4096 ! Al
! working out what is in x
rem = x
do ii = 3, 1, -1
   if (rem .ge. elem(ii)) then
      ! Work out how many
      howmany = rem / elem(ii)
      rem = mod(rem, elem(ii))
      do jj = 1, howmany
         write(*, '(A,)', advance='no') mnem(ii)
      end do
   end if
end do
write(*,*)
Not sure if this is what you're looking for
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top