Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

Reading some matrices from file

chri
Beginner
139 Views

Hello!

I am pretty new to Fortran and fail since a few days to a initial problem.
I am not able to bring data given by a xml file to my Fortran program.(Matrices)

I have data provided in an XML file. 
It is structured something like:

<FIELDNAME>
    <ROWS>?</ROWS>
    <COLS>?</COLS>
    <DATA>?</DATA>

</FIELDNAME>
...then comes the next <FIELDNAME> ... ... ... ? represents a double(kind=8)

I have written a parser in vb.net and now i am able to create a *.dat file in every way i like it.
My newest attempt is simply structured like:

FIELDNAME as character(10)
NUMBER OF ROWS as character(10)
NUMBER OF COLUMNS as character(10)
?(1,1)
?(2,1)
... ... ... till the next FIELDNAME ... ... ... ? represents a double(kind=8)

In the file it looks like:

MATRIX1
3.0
3.0
1.0E-18
2.0
3
4.0E+5
5.0
6.0
7.0
8.0
9.0
MATRIX2
...
...

...

The FIELDNAMEs are always the same ~30 Fieldnames in the same order containing Martices.

I thought it would be easy to bring the data into my program cause i can format it as i wish in vb.net but i fail. I also fail when i try to do it with vb.net and try to pass the arrays to fortran as such(I don't want to do it this way anymore cause all description i found in the internet are done like kidding me.) Using FoX compiled under VisualStudio to read from the input.xml itself also was not possible. I've wastet several days to this.
 

Has someone an Code example or something similar for me how this, in this case "initial step" can be done?

 

I would be very glad if someone could help me!

0 Kudos
1 Solution
mecej4
Black Belt
139 Views

I will not bother to comment on XML data files or the use of VB programs to convert XML to simpler text files, but you may want to consult available XML libraries if you want to do this.

Assuming that you have the data in the format that you showed, we can do the following. First, show the matrix size using integers rather than real numbers. That is, your second and third lines should contain "3", not "3.0". Flesh out and run the Fortran program below, and make it read your formatted data file as standard input.

program readmat
implicit none
integer :: nrows,ncols
real, dimension(:,:), allocatable :: M1, M2
character(10) :: matname
!
read(*,'(A)')matname
read(*,*)nrows
read(*,*)ncols
!
allocate(M1(nrows,ncols))
read(*,*)M1
!

 

View solution in original post

2 Replies
mecej4
Black Belt
140 Views

I will not bother to comment on XML data files or the use of VB programs to convert XML to simpler text files, but you may want to consult available XML libraries if you want to do this.

Assuming that you have the data in the format that you showed, we can do the following. First, show the matrix size using integers rather than real numbers. That is, your second and third lines should contain "3", not "3.0". Flesh out and run the Fortran program below, and make it read your formatted data file as standard input.

program readmat
implicit none
integer :: nrows,ncols
real, dimension(:,:), allocatable :: M1, M2
character(10) :: matname
!
read(*,'(A)')matname
read(*,*)nrows
read(*,*)ncols
!
allocate(M1(nrows,ncols))
read(*,*)M1
!

 

View solution in original post

chri
Beginner
139 Views

Many Thanks! Now everything works. This looks so easy when you know how!

Reply