Sponsored Content
Top Forums UNIX for Dummies Questions & Answers If statement between different file's arrays Post 302919081 by bakunin on Saturday 27th of September 2014 04:39:28 PM
Old 09-27-2014
Quote:
Originally Posted by saleheen
Code:
1280
Surfaces
Pt        0.00000000000000    0.00000000000000    0.00000000000000
Pt        2.81138845918055    0.00000000000000    0.00000000000000
Pt        5.62277691836110    0.00000000000000    0.00000000000000
Pt        8.43416537754165    0.00000000000000    0.00000000000000
Pt        1.40569422959028    2.43473382555675    0.00000000000000
Pt        4.21708268877083    2.43473382555675    0.00000000000000
Pt        7.02847114795138    2.43473382555675    0.00000000000000
Pt        0.00000000000000    1.62294556093176    2.30537603326937
Pt        2.81138845918055    1.62294556093176    2.30537603326937
Pt        5.62277691836110    1.62294556093176    2.30537603326937
Pt        8.43416537754165    1.62294556093176    2.30537603326937
Pt        1.40569422959028    4.05767938648850    2.30537603326937
Pt        4.21708268877083    4.05767938648850    2.30537603326937
Pt        7.02847114795138    4.05767938648850    2.30537603326937
Pt        9.83985960713193    4.05767938648850    2.30537603326937
Pt        0.00000000000000    6.49241321204525    2.30537603326937

It goes on for 1280 atoms. I'm trying to make a cluster out of it.
My algorithm for this problem goes as follows.
1. Delete the bottom two layers
2. Prompt for first pivot atom coordinates
3. For the first pivot atom, search for nearest neighbor atoms, put those in a new file.
4. Prompt for the second pivot atom
5. Search for it's nearest neighbors, look if they're already in the new file, if not copy those.
Do this for the next 2 pivot atoms too.
Please bear with me, but my Unix skills are better then my rudimentary knowledge of condensed matter physics.

1) What is - in terms of dsitinguishing text elements - a "bottom layer"? Can it be described in terms like all lines with "0.0000000" in the fourth field or something such?

2) In the same way of description: what is a "pivot atom"? I guess your table lists platinum atoms and their coordinates, but what makes an atom a "pivot atom"?

3) I guess "nearest neighbor" is probably the one where the absolute value of the sum of the 3 coordinate differences is minimal, yes? Something like

min( || a1 - a2 || + || b1 - b2 || + || c1 - c2 || )

How can there be more than one "nearest neighbors" and how should they be calculated?

Quote:
Originally Posted by saleheen
Code:
doom=($(grep Pt cluster.xyz | awk '{ print $4 }' | grep '[0]\.[0-9]\{14\}')); sed 's/"${doom[*]}"//g' cluster.xyz

I cannot even guess what you are trying to accomplish here. Let me tell you what this thing does:

You filter all the lines containing "Pt" from a file, the use awk to only output the fourth field of these lines. You end up with a stream of lines all consisting of one coordinate. This stream is piped into a another grep, which filters out all lines starting with "0.", followed by 14 other digits. You do nothing further with this result. Then you call "sed" and try to remove a double quote, followed by the lines end, followed (sic!) by the string '{doom[*]}"'. The "g" at the end has no significance because i promise there is only one line end in every line. Therefore the whole file comes out unchanged.

Finally you use "( ... )" to construct an array "doom" in which every word (separated by blanks) is one element. The first elements will be the filtered fourth columns from your first pipeline, then your input file is cut in separate words and these take the next places. Depending on the shell you use it might even run out of space, because i.e. ksh88 has a limitation of 1024 elements in an array.


Quote:
Originally Posted by saleheen
It's not working. And also I think I'm wrong here, I need to delete the whole line, if this line of code would work it'd delete only the z coordinates of the bottom layer.
No. It won't delete anything, just declare an array variable.

I am aware you had a few more questions, but please specify your requirements first. It makes sense to talk about implementation specifics only after this is covered.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading in data sets into arrays from an input file.

Hye all, I would like some help with reading in a file in which the data is seperated by commas. for instance: input.dat: 1,2,34,/test for the above case, the fn. will store the values into an array -> data as follows: data = 1 data = 2 data = 34 data = /test I am trying to write... (5 Replies)
Discussion started by: sidamin810
5 Replies

2. Shell Programming and Scripting

Arrays & File Reading

Ok; here is the code INCREMENT=0 #Final Count MATCH=0 #Treated as a Boolean declare -a LINEFOUR #Declared Array for FILE in $DIR; do # DIR was declared earlier test -f $FILE && ( TEMP=(sed -n '4p' $FILE) #How do I assign the fourth line of the file to TEMP? This doesn't... (1 Reply)
Discussion started by: Asylus
1 Replies

3. Shell Programming and Scripting

How to load different type of data in a file to two arrays

Hi, I have tried to find some sort of previous similar thread on this but not quite close to what I want to achieve. Basically I have two class of data in my file..e.g 1,1,1,1,1,2,yes 1,2,3,4,5,5,yes 2,3,4,5,5,5,no 1,2,3,4,4,2,no 1,1,3,4,5,2,no I wanted to read the "yes" entry to an... (5 Replies)
Discussion started by: ahjiefreak
5 Replies

4. Shell Programming and Scripting

Struggling with arrays and delimited file

Hi, I am trying to use arrays in my script but can not seem to get it to work. I have a file called sections, this contains headers from a tripwire log file, separated by "@" but could be "," if easier The headers will be used to cut sections from the log file into another to be mailed. ... (5 Replies)
Discussion started by: pobman
5 Replies

5. Shell Programming and Scripting

Reading a .dat file in to 2 different arrays

hi all, i have a data file that contains 2 columns, names and numbers. i need to read names in to a an array call names and numbers in to an array call numbers. i also have # and blank lines in my dat file and i need to skip those when i read the dat file. how do i do this? btw, my column 1 and... (3 Replies)
Discussion started by: usustarr
3 Replies

6. Shell Programming and Scripting

Saving file content in arrays using AWK

Hi, im new to shell scripting. i have a query for which i have searched your forums but coulndt get what i need. i have a file that has two records of exactly the same length and format and they are comma seperated. i need to save the first and the second columns of the input file to 2 different... (11 Replies)
Discussion started by: atikan
11 Replies

7. UNIX for Dummies Questions & Answers

File Field Replacement, Assigning Fields to Variables, Lists/Arrays?

Okay, I've made threads on extracting fields and comparing strings in separate files in .csv's. I've written the following code with intentions of learning more. I just want this one question answered: How can I assign fields from a file(comma separated) to variables? My goal is to check... (0 Replies)
Discussion started by: chickeneaterguy
0 Replies

8. Programming

question about int arrays and file pointer arrays

if i declare both but don't input any variables what values will the int array and file pointer array have on default, and if i want to reset any of the elements of both arrays to default, should i just set it to 0 or NULL or what? (1 Reply)
Discussion started by: omega666
1 Replies

9. UNIX for Dummies Questions & Answers

Using associative arrays with an if statement

I have this piece of code. The first if statement is not working, however the second if statement is working fine. I have set a value for Srcs to be file.srcs and want to print it. If no value for Rcvs is set, I get the print statement correctly hasValue="file.srcs" if ${hasValue}; then ... (0 Replies)
Discussion started by: kristinu
0 Replies

10. Shell Programming and Scripting

About arrays in file 1 matching with file 2

i have two files say a and b a has these lines 1 20 30 40 2 30 40 50 3 25 35 45 5 20 50 20 and b has these lines 20 30 30 40 25 35 20 50 the script reads FILENAME ( "a" ) { rec1=$2; rec2=$2; } (4 Replies)
Discussion started by: paresh n doshi
4 Replies
All times are GMT -4. The time now is 09:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy