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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DATA_CONVERSION TO ANOTHER FORMAT

Status
Not open for further replies.

lehloks

Programmer
Jul 12, 2013
40
ZA
Dear users

I have this short code which is suppose to read 2 in put files i.e. bn_input and HISTORY file. I have placed a short version of a history file. My bn_input contains number of configurations starting from 1 to 10 (NCONFIGS) and NFRACT which can be 0 or 1. Now the problem when I read the data file, it does not read the data file but i get empty files of the 10 Configurations. Any one for help?



[bn_input contains 10 and 1] which are NCONFIGS,NFRACT

Code:
!c Converting DLPOLY Configuration Files to PotFit Format
!Fortran File: Convert_HISTORY_Configuration_2.f
PROGRAM CONVERT
!CASL Program to convert a DL-POLY2 HISTORY file (formatted) into a Configuration file for PotFit.
IMPLICIT DOUBLE PRECISION(A-H,O-Z)
CHARACTER*60 TITLE,TIMESTEP,ATITLE
open(5,file='bn_input')
OPEN (UNIT=7, FILE="Config_1")
OPEN (UNIT=8, FILE="Config_2")
OPEN (UNIT=9, FILE="Config_3")
OPEN (UNIT=10, FILE="Config_4")
OPEN (UNIT=11, FILE="Config_5")
OPEN (UNIT=12, FILE="Config_6")
OPEN (UNIT=13, FILE="Config_7")
OPEN (UNIT=14, FILE="Config_8")
OPEN (UNIT=15, FILE="Config_9")
OPEN (UNIT=16, FILE="Config_10")
!C Convert force to apprpriate units. DL-POLY uses forces is only J/mol.m
!C Conversion factor to eV involving the Faraday.
CONFACTOR = 10.0D0/96485.3415D0
!C Conversion factor when using kJ/mol.
!C CONFACTOR = 1.0D0/100.0D0
!C Now option to convert to fractional coords for QuantumEspresso in Bohr. If NFRACT=1 make conversion.
BOHR=0.52917720859D0
READ(5,*) NCONFIGS,NFRACT
READ(5,10) TITLE
WRITE(6,10) TITLE
10 FORMAT(A60)
READ(5,*) dum1,dum2,NA
DO 200 I=1,NCONFIGS
READ(5,10) TIMESTEP
READ(5,*) XCELL,dum3,dum4
READ(5,*) dum5,YCELL,dum6
READ(5,*) dum7,dum8,ZCELL
IUNIT = 6 + I
WRITE(IUNIT,*) '#N ',NA,' 1'
if (NFRACT.eq.1) then
WRITE(IUNIT,*) '#X ',XCELL/BOHR,' 0 0'
else
WRITE(IUNIT,*) '#X ',XCELL,' 0 0'
endif
WRITE(IUNIT,*) '#Y 0 ',YCELL,' 0'
WRITE(IUNIT,*) '#Z 0 0 ',ZCELL
WRITE(IUNIT,*) '#E Type ENERGY Here '
WRITE(IUNIT,*) '#F'
DO 100 J=1,NA
READ(5,10) ATITLE
READ(5,*) X,Y,Z
READ(5,*) VX,VY,VZ
READ(5,*) FX,FY,FZ
!C Convert to fractional coords if required.
IF (NFRACT.EQ.1) THEN
X = X/XCELL
Y = Y/YCELL
Z = Z/ZCELL
ENDIF
!C Convert forces as before to eV/A.
FX = FX*CONFACTOR
FY = FY*CONFACTOR
FZ = FZ*CONFACTOR
WRITE(IUNIT,20) X,Y,Z,FX,FY,FZ
20 FORMAT( 'AtomType ',6F16.8)
100 CONTINUE
200 CONTINUE
END

Data file:

Code:
Include your configuration title on this line
         1         1        39
timestep         5        39         1         1    0.001000
   20.00       0.000       0.000
   0.000       20.00       0.000
   0.000       0.000       20.00
Mg               1   24.305000    1.200000
 -1.1401E+01 -2.5403E+00  5.7628E-01
  1.7354E+01 -4.3158E+00 -7.3638E+00
Mg               2   24.305000    1.200000
 -2.1925E+00  4.5392E+00  1.6815E+00
 -6.5469E+00 -8.3314E-01 -2.4877E+00
Ca               3   40.078000    1.200000
 -8.3971E+00 -1.2057E+00  3.9914E+00
  2.4274E-01 -3.2322E+00  7.1844E+00
Ca               4   40.078000    1.200000
 -4.2609E+00  4.1574E+00 -2.5920E+00
 -1.0905E+00 -8.5761E+00  9.2583E-01
Si               5   28.085530    2.400000
 -3.8046E+00  1.4240E-01 -3.7758E-01
  6.3889E+00  3.0486E+00  2.4104E+00
Si               6   28.085530    2.400000
 -4.8083E+00  2.6713E+00  1.0118E+00
 -3.2319E+00  5.5193E+00 -1.6864E+00
Si               7   28.085530    2.400000
 -7.3510E+00 -4.2872E+00  3.7256E-01
  5.1959E+00 -2.6805E+00  5.3139E+00
Si               8   28.085530    2.400000
 -9.0337E+00 -2.5186E+00 -1.5394E+00
 -3.0317E+00  3.4081E-02 -1.3563E+01
Si               9   28.085530    2.400000
 -5.7629E+00  8.5090E-01 -2.7200E+00
 -1.6284E+01 -1.2259E+01 -8.2212E+00
Si              10   28.085530    2.400000
 -9.3391E+00 -4.3359E+00  2.6168E+00
  7.0208E+00 -9.4734E+00 -2.6539E+00
Si              11   28.085530    2.400000
  -7.2021E+00  1.4907E+00  2.0877E+00
 -5.9518E+00 -6.7745E+00 -9.6735E+00
Al              12   24.134000    1.800000
 -4.6944E+00 -2.5664E+00  9.5831E-01
  2.1424E+00  1.0655E+01  2.5700E+00
Al              13   24.134000    1.800000
 -8.0245E+00  3.9779E-01 -6.5472E-01
  5.3580E+00 -4.0641E+00  1.1313E+01
O               14   15.999000   -1.200000
 -2.4385E+00 -2.8109E-01 -6.3445E-01
 -1.9698E+01  1.3679E+00 -1.0267E+00
O               15   15.999000   -1.200000
 -4.5817E+00  1.3508E-01 -1.8079E+00
  4.3512E+00 -5.2582E-01 -3.5189E+00
O               16   15.999000   -1.200000
 -3.8631E+00  1.6031E+00  2.8373E-01
  8.2625E+00  1.3924E+01 -4.1380E-01
O               17   15.999000   -1.200000
 -4.5693E+00 -9.8735E-01  6.1943E-01
 -8.7478E+00  1.8566E-01  8.2963E+00
O               18   15.999000   -1.200000
 -4.5253E+00 -2.8771E+00  2.7122E+00
 -4.7723E+00  1.6894E+00 -7.6144E+00
O               19   15.999000   -1.200000
 -3.4818E+00 -3.5565E+00  1.1472E-01
 -6.7636E+00  1.0267E+01  1.7096E+01
O               20   15.999000   -1.200000
 -6.3217E+00 -3.1388E+00  4.8869E-01
 -1.1186E+01 -1.1464E+00  2.1496E+00
O               21   15.999000   -1.200000
 -5.6571E+00  1.9661E+00  2.3029E+00
 -1.9686E+00  9.3794E+00  1.9910E+01
O               22   15.999000   -1.200000
 -5.7392E+00  3.4073E+00 -8.3083E-02
  1.1550E+01  1.7056E+01 -8.9055E+00
 O               23   15.999000   -1.200000
 -3.7978E+00  3.8558E+00  1.6975E+00
  1.5591E+01  1.9482E+01  7.0538E+00
O               24   15.999000   -1.200000
 -6.6349E+00 -5.6135E+00 -2.3746E-01
  1.2387E+01 -1.0297E+00 -4.0111E+00
O               25   15.999000   -1.200000
 -8.4678E+00 -3.8450E+00 -7.5340E-01
 -6.5298E+00 -1.3694E+01 -8.2013E+00
O               26   15.999000   -1.200000
 -8.1052E+00 -4.5157E+00  1.7393E+00
 -4.6657E+00  5.1924E+00  7.1996E-01
O               27   15.999000   -1.200000
 -1.0535E+01 -2.3329E+00 -9.5494E-01
 -9.7807E+00 -8.1426E+00  1.3794E+00
O               28   15.999000   -1.200000
 -8.9757E+00 -2.7468E+00 -3.0800E+00
 -6.8758E+00  1.0849E+01 -8.7581E+00
O               29   15.999000   -1.200000
 -8.1346E+00 -1.2392E+00 -1.0775E+00
 -2.5152E+00 -5.8427E-01  8.8272E+00
O               30   15.999000   -1.200000
 -6.0481E+00 -5.7631E-02 -3.9124E+00
  4.3320E+00 -9.2925E+00  1.3973E+00
O               31   15.999000   -1.200000
 -5.1328E+00  2.3020E+00 -3.2077E+00
 -8.3946E+00  4.9347E+00 -4.5869E+00
O               32   15.999000   -1.200000
 -7.0213E+00  1.1780E+00 -1.7950E+00
 -5.2948E+00  2.3363E+00  2.0758E+00
O               33   15.999000   -1.200000
 -7.3195E+00  5.2562E-01  9.3873E-01
  2.3753E+01 -1.1083E+01  1.0997E+01
O               34   15.999000   -1.200000
 -9.7497E+00  1.1474E+00 -8.1712E-01
 -4.9306E+00 -7.6578E+00  3.0298E+00
O               35   15.999000   -1.200000
 -7.5247E+00  7.4743E-01  3.3439E+00
  2.8973E+00  5.7908E+00 -1.5732E+01
O               36   15.999000   -1.200000
 -8.1024E+00  2.8708E+00  2.0330E+00
 -1.2526E+00  9.2585E+00 -2.4542E+00
O               37   15.999000   -1.200000
 -9.0197E+00 -3.2904E+00  3.7940E+00
 -8.7468E-01 -9.9473E+00  7.1678E+00
O               38   15.999000   -1.200000
 -1.0549E+01 -3.7307E+00  1.6713E+00
  6.6851E+00  5.5737E+00 -1.2329E+01
O               39   15.999000   -1.200000
 -9.7717E+00 -5.5816E+00  3.3639E+00
  6.2020E+00  1.2925E+01  1.0442E+01
 
If you look at your read statements and your data, you have
Code:
READ(5,*) NCONFIGS,NFRACT
READ(5,10) TITLE
reading
Code:
Include your configuration title on this line
         1         1        39
It probably falls over on the first read statement.
 
In other words, the first things you are attempting to read are two numbers, follow by the title, which do not seem to appear in the input file.

Do us all a favor and please try a couple of "baby steps" before you give up on yourself...for your own sake, you really need to develop some debugging skills.

For example, test your program in stages; first, execute the very first read statement and immediately after echo the values just read...do they match what you expect? no? why?

OR

Maybe you got your files messed up or the unit numbers to read from them...in your post, you say you have 2 input files "bn_input" and "HISTORY" and that supposedly you have attached a sample HISTORY file...yet, you use "bn_input" name to open the file to read from and the read statement seem to match well with the file shown (which is the HISTORY file)...so, I am confused.

One last thing...please indent 4 spaces for every level...thanks...something like:
Code:
do i = 1, 200
    do j = 1,100
        ! do something
    end do
end do
[/cdoe]
 
oops...typo and don't know a way to go back and edit these pages! ( I guess I should have previewed)

Code:
do i = 1, 200
    do j = 1,100
        ! do something
    end do
end do
 
Hi salgerman,
It seems that you wrote instead of [pre][/code][/pre] this: [pre][/cdoe][/pre]
In the last time it happens regularly with me . maybe I'm getting old ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top