Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Can we open *vtk files in fortran?
If yes,How?
I have written my code as below:
I keep getting error: bad real number in item 1 of list input
Please let me know my mistake
thanks
program work_file
implicit none
integer:: open_status,ln
real::x
open(UNIT=8,FILE="NSSAVE0001.vtk", IOSTAT=open_status, STATUS="old")
if(open_status >0) stop "problem opening the file"
do ln=10,100
read(8,*)x
enddo
close(8)
VTK files have a standard format. The first lines are usually something like
Code:
# vtk DataFile Version 1.0
vtk output
ASCII
ASCII indicates the format used for subsequent data. If it is BINARY, you have to open the file as UNFORMATTED. In any case, the fortran code must read the first lines as strings, whereas your code tries to read floating point data from the beginning. Check what are the first lines of your file, and see if the data are in ASCII or binary format:
Code:
od -c NSSAVE0001.vtk | head -20
or see if it is ASCII or binary using the file command:
VTK files have a standard format. The first lines are usually something like
Code:
# vtk DataFile Version 1.0
vtk output
ASCII
ASCII indicates the format used for subsequent data. If it is BINARY, you have to open the file as UNFORMATTED. In any case, the fortran code must read the first lines as strings, whereas your code tries to read floating point data from the beginning. Check what are the first lines of your file, and see if the data are in ASCII or binary format:
Code:
od -c NSSAVE0001.vtk | head -20
or see if it is ASCII or binary using the file command:
Code:
file NSSAVE0001.vtk
Many Thanks for reply
I am interested in getting the numerical values as shown below
But as you said fortran reads the first line as string. How do I go about it?
What modification are required in code?
NSSAVE0001.vtk: ASCII C program text
First Part of NSSAVE0001.vtk would be
# vtk DataFile Version 2.0
TEMPS = 0.2000000E+00 Corps RE=5000 (G8)
ASCII
DATASET STRUCTURED_POINTS
DIMENSIONS 960 320 1
ORIGIN 0.78125E-02 0.78125E-02 0
SPACING 0.15625E-01 0.15625E-01 1
POINT_DATA 307200
Well, you have to read the header lines one after one. When you get the DATA POINTS line, read in the number of data points to find out the number of subsequent lines to read. Here is a dummy example:
Code:
PROGRAM work_file
IMPLICIT NONE
CHARACTER(len=100) :: dummy
CHARACTER(len=6) :: dataformat
CHARACTER(len=20) :: dataset
INTEGER :: status, np, k, ln
INTEGER, DIMENSION(3) :: dimensions
REAL, DIMENSION(2) :: origin, spacing
REAL, DIMENSION(5) :: x
OPEN(UNIT=8, FILE='NSSAVE0001.vtk', IOSTAT=status, STATUS='old')
! First two lines contain the version number and a title
READ(8, '(A)') dummy
READ(8, '(A)') dummy
! The third line contains ASCII or BINARY
READ(8, '(A)') dataformat
! Fourth line contains the type of dataset
READ(8, '(A7,1X,A)') dummy, dataset
! Dimensions
READ(8, '(A10,1X,I3,1X,I3,1X,I)') dummy, dimensions
! Origin
READ(8, '(A6,1X,E11.5,1X,E11.5,1X,I)') dummy, origin, k
! Spacing
READ(8, '(A7,1X,E11.5,1X,E11.5,1X,I)') dummy, spacing, k
! Number of data points
READ(8, '(A10,1X,I)') dummy, np
READ(8, '(A)') dummy
! Scalars
READ(8, '(A)') dummy
! Lookup table
READ(8, '(A)') dummy
! Finally read data
DO ln = 1, np
READ(8, '(E11.5,4(1X,E11.5))' ) x
END DO
CLOSE(UNIT=8, IOSTAT=status)
END PROGRAM work_file
On the other hand if you want to skip a fixed number of lines (that is you're not interested in the header, except the number of data points) you can substitute the first READ statements with a loop:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.