CCL: Fortran question





On Fri, Aug 12, 2011 at 2:29 PM, Richard Leo Wood rwoodphd||msn.com <owner-chemistry..ccl.net> wrote:

Sent to CCL by: "Richard Leo Wood" [rwoodphd(_)msn.com]
Hi all,

I have a real simple Fortran question-however, I cna't seem to find the answer anywhere and I've looked everywhere.

I'm trying to write a Fortran program that will read in an external molecule file in dat format, manipulate it and then write the output to a new dat file.

I'm at the point where I am reading in the file and trying to write it out.

Here's my file:

00012  benzene
 002 00002 2 00006 1 00007 1 00000 0 00000 0 00000 0 -000.696800 -001.210000 -000.001000 0  10      000.00000000.00000
 002 00001 2 00003 1 00008 1 00000 0 00000 0 00000 0 0000.699600 -001.208900 0000.000000 0  10      000.00000000.00000
 002 00002 1 00004 2 00009 1 00000 0 00000 0 00000 0 0001.396500 0000.001200 0000.001000 0  10      000.00000000.00000
 002 00003 2 00005 1 00010 1 00000 0 00000 0 00000 0 0000.697000 0001.209900 0000.001000 0  10      000.00000000.00000
 002 00004 1 00006 2 00011 1 00000 0 00000 0 00000 0 -000.699400 0001.208600 0000.000000 0  10      000.00000000.00000
 002 00001 1 00005 2 00012 1 00000 0 00000 0 00000 0 -001.396500 -000.001400 -000.001000 0  10      000.00000000.00000
 041 00001 1 00000 0 00000 0 00000 0 00000 0 00000 0 -001.247600 -002.165800 -000.001800 0  21      000.00000000.00000
 041 00002 1 00000 0 00000 0 00000 0 00000 0 00000 0 0001.252000 -002.163700 0000.000000 0 21       000.00000000.00000
 041 00003 1 00000 0 00000 0 00000 0 00000 0 00000 0 0002.499600 0000.002400 0000.001800 0 21       000.00000000.00000
 041 00004 1 00000 0 00000 0 00000 0 00000 0 00000 0 0001.247700 0002.165800 0000.001800 0 21       000.00000000.00000
 041 00005 1 00000 0 00000 0 00000 0 00000 0 00000 0 -001.252000 0002.163400 0000.000000 0 21       000.00000000.00000
 041 00006 1 00000 0 00000 0 00000 0 00000 0 00000 0 -002.499600 -000.002600 -000.001800 0 21       000.00000000.00000

I read it in, and when I write it out to a new file, all I get is the 00012.

If you don't post any of the code you're trying, we have no idea where you went wrong.  You can try this:

read(unit_number, fmt='(i5,a)') my_num_1, molecule_name
read(unit_number, fmt='(INSERT FMT HERE)') (my_array_of_data(i), i=1, num_data)

You need to figure out what your format is.  See this website http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap05/format.html, for instance, that describes how to construct a fortran format string.  In the example I provided, it means a 5-digit integer followed by a string (of arbitrary length).  (If the molecule file you're reading was created by a fortran program and you have the source code, the format string used to create it should be in there and will be the same as the one you want to use).  Fortran is ideally set up for fixed format parsing if you know the format in advance.  As someone who has had to do the occasional free-format parsing in Fortran, I'll attest that it's clunky (especially compared to Python, Perl, or awk).

Then you want to write in essentially exactly the same way you read everything in (only use write instead of read, and the unit_number should correspond to your output file).

HTH,
Jason

--
Jason M. Swails
Quantum Theory Project,
University of Florida
Ph.D. Graduate Student
352-392-4032