LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-13-2010, 02:18 PM   #1
teresevo1
LQ Newbie
 
Registered: Apr 2010
Posts: 11

Rep: Reputation: 0
fatal: division by zero attempted


I am just trying to run the script xyz2ecfg given at
http://www.jrkermode.co.uk/XYZScripts

But I am getting the error "fatal: division by zero attempted", even though I typed in exactly "xyz2ecfg.awk movie.xyz"

Please help!
Thanks!!
 
Old 06-13-2010, 04:05 PM   #2
fruttenboel
Member
 
Registered: Jul 2008
Location: Tilburg NL
Distribution: Slackware 14.2 ciurrent, kernel 3.18.11
Posts: 270

Rep: Reputation: 48
Quote:
Originally Posted by teresevo1 View Post
I am just trying to run the script xyz2ecfg given at
http://www.jrkermode.co.uk/XYZScripts

But I am getting the error "fatal: division by zero attempted", even though I typed in exactly "xyz2ecfg.awk movie.xyz"

Please help!
Thanks!!
Can you post the script, in a CODE block?
 
Old 06-13-2010, 04:46 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Usually awk shows the number of the line where the error occurred. Please show us the complete error message along with the relevant parts of the code. My suspect is that the file movie.xyz is not actually an Extended XYZ file.
 
Old 06-14-2010, 08:36 AM   #4
teresevo1
LQ Newbie
 
Registered: Apr 2010
Posts: 11

Original Poster
Rep: Reputation: 0
The division by zero error first occur at the line:
Code:
g[0,0] = ((r[1,1] * r[2,2]) -\
(r[1,2] * r[2,1]))/det;
Here is the code:

Code:
#!/bin/awk -f

function ceiling(x)
{
  return (x == int(x)) ? x : int(x)+1
}

BEGIN {
  command="basename " ARGV[1] " .xyz";
  command | getline cfgbase;
  frame=0;
  print "Counting frames..."
  command="grep -c Lattice " ARGV[1];
  command | getline nframes;
  print "Got " nframes " frames.";
  format=sprintf("%%0%dd",ceiling(log(nframes)/log(10.0)))
 
  mass["Si"] = 28.085500;
}

{
  if (nframes == 1) {
    cfgfile=cfgbase ".cfg";
  } else {
    cfgfile=cfgbase sprintf(format,frame) ".cfg";
  }

  natoms=$1;
  printf "Frame "frame": " natoms" atoms              \r";

  print "Number of particles = "natoms > cfgfile;

  getline comment;
  print "# "comment >> cfgfile;

  match(comment,/Lattice="([^"]*)/,a);
  lat=a[1];
  split(lat,lattice);
   

  for (x=0; x<3; x++)
    for (y=0; y<3; y++) {
      r[x,y]=lattice[x*3+y+1];
      print "H0("x+1","y+1") = "r[x,y] >> cfgfile;
    }

  det = r[0,0]*(r[1,1]*r[2,2] - r[2,1]*r[1,2]) \
    - r[1,0]*(r[0,1]*r[2,2] - r[2,1]*r[0,2]) \
  + r[2,0]*(r[0,1]*r[1,2] - r[1,1]*r[0,2]);

  g[0,0] = ((r[1,1] * r[2,2]) -\
	    (r[1,2] * r[2,1]))/det;
  g[1,0] = ((r[0,2] * r[2,1]) -\
	    (r[0,1] * r[2,2]))/det;
  g[2,0] = ((r[0,1] * r[1,2]) -\
	    (r[0,2] * r[1,1]))/det;
  g[0,1] = ((r[1,2] * r[2,0]) -\
	    (r[1,0] * r[2,2]))/det;
  g[1,1] = ((r[0,0] * r[2,2]) -\
	     (r[0,2] * r[2,0]))/det;
  g[2,1] = ((r[0,2] * r[1,0]) -\
	     (r[0,0] * r[1,2]))/det;
  g[0,2] = ((r[1,0] * r[2,1]) -\
	     (r[1,1] * r[2,0]))/det;
  g[1,2] = ((r[0,1] * r[2,0]) -\
	    (r[0,0] * r[2,1]))/det;
  g[2,2] = ((r[0,0] * r[1,1]) -\
	     (r[0,1] * r[1,0]))/det;

  print ".NO_VELOCITY." >> cfgfile;

  match(comment,/Properties=([a-zA-Z0-9._:]*)/,a);
  props=a[1];
  nfields = split(props,a,":");

  delete lines;
  p=0;
  for (i = 4; i <= nfields; i++) {
    if (i % 3 == 1) name=a[i];

    if (i % 3 == 0) {
      for (j=0; j<a[i]; j++) {
        lines[p]="auxiliary["p"] = "name;
	p=p+1;
      }
    }
  }

  print "entry_count = "p+3 >> cfgfile;

  for (i=0; i<p; i++)
    print lines[i] >> cfgfile

  for (i=0; i<natoms; i++) {
    getline;
    
    print $1 >> cfgfile;
    print mass[$1] >> cfgfile;

    s[0]=$2;
    s[1]=$3;
    s[2]=$4;

    t[0] = g[0,0]*s[0]+g[0,1]*s[1]+g[0,2]*s[2];
    t[1] = g[1,0]*s[0]+g[1,1]*s[1]+g[1,2]*s[2];
    t[2] = g[2,0]*s[0]+g[2,1]*s[1]+g[2,2]*s[2];

    printf "%16.8f%16.8f%16.8f",t[0],t[1],t[2] >> cfgfile;

    for (j=5;j<=NF;j++) printf "%16.8f",$j >> cfgfile;
    printf "\n" >> cfgfile;
  }     

  close(cfgfile);
  frame=frame+1;
}

END {
  print "Done "frame" frames.                  "
}
 
Old 06-14-2010, 09:21 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by teresevo1 View Post
The division by zero error first occur at the line:
Code:
g[0,0] = ((r[1,1] * r[2,2]) -\
(r[1,2] * r[2,1]))/det;
This means that 'det' is 0, 'r' is not assigned or it's 0 (see line 47), the same for 'lattice' (see line 43) and for 'lat' (see lines 36-38). I stay of my idea that the input file is not really an Extended XYZ.

You can easily verify by the following commands:
Code:
file movie.xyz
and if it is an ASCII text file:
Code:
head movie.xyz
You should see the line starting with Lattice with all the key/value pairs of an Extended XYZ.

Last edited by colucix; 06-14-2010 at 09:23 AM.
 
Old 06-14-2010, 12:23 PM   #6
teresevo1
LQ Newbie
 
Registered: Apr 2010
Posts: 11

Original Poster
Rep: Reputation: 0
I am very new to this. When I type in
Code:
file movie.xyz
I get movie.xyz: ASCII text.

How do I write an extended xyz file? I just do >> vi movie.xyz and copy and paste the data.

Thanks in advance.
 
Old 06-14-2010, 02:19 PM   #7
teresevo1
LQ Newbie
 
Registered: Apr 2010
Posts: 11

Original Poster
Rep: Reputation: 0
This is movie.xyz

Code:
8
Lattice="5.44 0.0 0.0 0.0 5.44 0.0 0.0 0.0 5.44" Properties=species:S:1:pos:R:3 Time=0.0
Si        0.00000000      0.00000000      0.00000000
Si        1.36000000      1.36000000      1.36000000
Si        2.72000000      2.72000000      0.00000000
Si        4.08000000      4.08000000      1.36000000
Si        2.72000000      0.00000000      2.72000000
Si        4.08000000      1.36000000      4.08000000
Si        0.00000000      2.72000000      2.72000000
Si        1.36000000      4.08000000      4.08000000
 
Old 06-14-2010, 04:58 PM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by teresevo1 View Post
I am very new to this. When I type in
Code:
file movie.xyz
I get movie.xyz: ASCII text.
This confirms that your file movie.xyz is an ASCII text file, as it should be. A general advice: if you're new to the linux command line, always (and I mean always) check the manual page of every command you're suggested to type. Don't trust commands blindly, since everyone could make a typo or a mistake of some kind. It's better you're sure about what you're doing.

But maybe you already did. This is ol' pedantic uncle colucix speaking!
 
Old 06-14-2010, 05:06 PM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by teresevo1 View Post
This is movie.xyz
Yes. It is an extended XYZ file. On the other hand it is the example from the developers site, isn't it? Just out of curiosity I tried the code you've posted on the example file and it works for me. Having GNU Awk 3.1.6, here.

At this point I can't explain the error anymore. I have some experience with awk, but I cannot see any mistake in the code.
 
Old 06-14-2010, 06:58 PM   #10
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
My suggestion would be to work from the "det" backwards. According to the code and the supplied example your "det" value should equal : (5.44)^3

So throw in a print statement just after "det" is set and see what value is stored?
If this is equal to zero then you need to check further up the chain.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Division by 0 error cat555 Linux - Newbie 8 01-22-2009 04:58 PM
bandwith division in squid jatender Linux - Server 1 10-16-2007 05:34 AM
file division using C fs11 Programming 46 08-17-2007 05:04 PM
C++ - Division by 0 and 'nan' Nightfox Programming 1 05-03-2006 11:58 AM
ip address class division emailssent Linux - Networking 3 10-08-2004 06:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration