Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9148981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:24:54+00:00 2026-06-17T11:24:54+00:00

Trying to create an array from an xyz data file. The data file is

  • 0

Trying to create an array from an xyz data file. The data file is arranged so that x,y,z of each atom is on a new line and I want the array to reflect this.
Then to use this array to find find the distance from each atom in the list with all the others.

To do this the array has been copied such that atom1 & atom2 should be identical to the input file.

length is simply the number of atoms in the list.
The write statement: WRITE(20,'(3F12.9)’) atom1 actually gives the matrix wanted but when I try to find individual elements they’re all wrong!

Any help would be really appreciated!
Thanks guys.

DOUBLE PRECISION, DIMENSION(:,:), ALLOCATABLE ::atom1,atom2'
ALLOCATE(atom1(length,3),atom2(length,3))       
READ(10,*)  ((atom1(i,j), i=1,length), j=1,3)       
atom2=atom1                 
distn=0
distc=0                         

DO n=1,length
        x1=atom1(n,1)
        y1=atom1(n,2)               !1st atom
        z1=atom1(n,3)
        DO m=1,length
          x2=atom2(m,1)
          y2=atom2(m,2)         !2nd atom
          z2=atom2(m,3)`
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:24:54+00:00Added an answer on June 17, 2026 at 11:24 am

    Your READ statement reads all the x coordinates for all atoms from however many records, then all the y coordinates, then all the z coordinates. That’s inconsistent with your description of the input file. You have the nesting of the io-implied-do’s in the READ statement around the wrong way – it should be ((atom1(i,j),j=1,3),i=1,length).

    Similarly, as per the comment, your diagnostic write mislead you – you were outputting all x ordinates, followed by all y ordinates, etc. Array element order of a whole array reference varies the first (leftmost) dimension fastest (colloquially known as column major order).

    (There are various pitfalls associated with list directed formatting that mean I wouldn’t recommend it for production code (or perhaps for input specifically written with the knowledge of and defence against those pitfalls). One of those pitfalls is that the READ under list directed formatting will pull in as many records as it requires to satisfy the input list. You may have detected the problem earlier if you were using an explicit format that nominated the number of fields per record.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a 2D array from the data read from .txt file.
I am trying to create a UIImage from a byte array that is actually
I am trying to create a new array from two current arrays. Tried array_merge,
I am trying to create nested array's dynamically from a string that has been
I am trying to create an array, with the data coming from a text
I am trying to create an array from a json file using this: <script
I am new PHP question and I am trying to create an array from
I'm trying to update an array from a textArea, each line of which would
I'm trying to create an array from a file using PHP's unpack function. The
I'm trying to create an array from selected table rows so I can push

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.