ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Hi all,
It's my first time with fortran . I want to write a program that can transform table(n,m) on table(p,3)
I wrote this program:
program test
implicit none
real,dimension (33335,31)::table
integer::i
integer::j
i=1 , 33335
read(*,*)(table(i,j),j=1,31)
write(*,*)table(i+1,1),(table (1,j+1),table(i,j) j=1,31)
end
end
program test
but error messages are displayed such:
Compiling Fortran...
D:\Travaux de thèse\modeling\ April\tempj\test1.for
D:\Travaux de thèse\modeling\ April\tempj\test1.for(6) : Error: Syntax error, found ',' when expecting one of: <END-OF-STATEMENT> ;
i=1 , 33335
------------^
D:\Travaux de thèse\modeling\ April\tempj\test1.for(8) : Error: Syntax error, found IDENTIFIER 'J' when expecting one of: ( * :: , <END-OF-STATEMENT> ; : ) + . - % (/ [ ] /) ' . ** / > ...
write(*,*)table(i+1,1),(table (1,j+1),table(i,j) j=1,31)
-------------------------------------------------------^
D:\Travaux de thèse\modeling\ April\tempjo test1.for(11) : Error: Syntax error, found END-OF-FILE when expecting one of: <LABEL> <END-OF-STATEMENT> ; BLOCK BLOCKDATA PROGRAM TYPE COMPLEX BYTE CHARACTER ...
program test
-------------------^
Error executing df.exe.
program.exe - 3 error(s), 0 warning(s)
I need your help to understand what's the meanings of these messages and correct my program
Indeed, there are many syntax errors in your program. It's easier for me to show you a correct version of your code by highlighting in red the major changes:
Code:
PROGRAM test
IMPLICIT NONE
REAL, DIMENSION(33335,31) :: table
INTEGER :: i, j
DO i = 1,33335
READ(*,*) (table(i,j), j=1,31)
WRITE(*,*) table(i+1,1), (table(1,j+1), table(i,j), j=1,31)
END DO
END PROGRAM test
This is only from a syntax point of view. Anyway, I think this program doesn't fulfil your requirement. Specifically I don't understand what the WRITE statement is supposed to do, specifically because the dimension of the matrix is exceeded by the i+1 and j+1 indexes.
Hi,
thank you very much for your precious help. I want to explain my program. I have a table, first line is for the altitude,first colunm is for the time, and table (i,j) is about temperture. I want to rewrite the table to obtain only 3 columns: time, altitude, temperture
I tried with another program:
program test
implicit none
real,dimension temp(33337,31)
do 10 i=1,33337
read(10,*)time,(temp(i,j),j=1,31)
10 continue
do 20 i=1,33337
write(20,*)time,(i,temp(i,j),j=1,31)
20 continue
stop
end
But still have an error which is :
D:\Travaux de thèse\modeling\\tempj\test1.for(3) : Error: Syntax error, found ',' when expecting one of: ( * ( :: %FILL , TYPE COMPLEX BYTE CHARACTER DOUBLE DOUBLECOMPLEX ...
real,dimension temp(33337,31)
----------^
Error executing df.exe.
At first an advice: the code in your first post seems to follow the Fortran 90/95 standard, whereas the code posted above is more similar to the old Fortran 77 specification. If I were you I wouldn't mix them and I would stick with the most recent standard.
Said that, this error:
Code:
D:\Travaux de thèse\modeling\\tempj\test1.for(3) : Error: Syntax error, found ',' when expecting one of: ( * ( :: %FILL , TYPE COMPLEX BYTE CHARACTER DOUBLE DOUBLECOMPLEX ...
real,dimension temp(33337,31)
----------^
Error executing df.exe.
comes from the 3rd line of your code (see the number inside parentheses) and it starts where indicated by the ---^ symbol. Indeed, the line:
Code:
real,dimension temp(33337,31)
should be
Code:
real,dimension(33337,31) :: temp
or
Code:
real :: temp(33337,31)
that is the word "dimension" requires arguments or it can be omitted. Another issue is about the old Fortran 77 standard:
Code:
do 10 i=1,33337
read(10,*)time,(temp(i,j),j=1,31)
10 continue
This is correct, but you can avoid the label "10" and the (obsolete) "continue" statement using the new standard:
Code:
do i = 1,33337
read(10,*) time, (temp(i,j), j=1,31)
end do
Regarding the aim of this code, it is clear now (me too works on tables of temperature at different times and depths). I just wonder about the format of the first line and especially what appears in the first element of your table, that one with indices (1,1). Please, can you post the first three lines of your input file? Just out of curiosity.
Also please, use CODE tags to post the lines of code and a sample of the input, so that spaces and indentation are preserved and the code (or the data) are more readable. To use CODE tags write [CODE] before the text and [/CODE] after the text. In alternative you can switch to Advanced Mode, select the text you want to put inside code tags and click the button with the # symbol. Thanks.
Hi,
Thank you for your explanations. it helped me to see better things since this is my first time with fortran.
these are the first line of the input:
PROGRAM test
IMPLICIT NONE
REAL, DIMENSION(33335,31)::temp
INTEGER :: i, j
open(10,file="input.dat")
open(20,file="output.dat")
DO i = 1,33335
READ(*,*) temp(i,1),(temp(i,j),j=1,31)
END DO
DO i=1,33335
WRITE(20,*) temp(i,1),(i, temp(i,j), j=1,31)
END DO
END PROGRAM test[/I]
after compiling, no error appears:
Deleting intermediate files and output files for project 'tempprogram - Win32 Debug'.
--------------------Configuration: tempprogram - Win32 Debug--------------------
Compiling Fortran...
D:\Travaux de thèse\modeling\tempprogram\temp.f90
Linking...
tempprogram.exe - 0 error(s), 0 warning(s)
But after debugging, it seemes that there is a problem:
Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\kernel32.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\KernelBase.dll', no matching symbolic information found.
The program 'D:\TRAVAUX DE THÈSE\MODELING\tempprogram\Debug\tempprogram.exe' has exited with code 0 (0x0).
Given your input, I would read the first (header) line alone in order to skip it (or eventually to retrieve the depths and store them into an array). Then I would simply read the file line by line and write the output immediately thereafter. In this way you can ignore the number of lines in the input file and declare 1-D arrays instead of 2-D.
I might post a little code I've written for you as an example: if you think it can be useful to learn the Fortran syntax and how to correctly read/write your data, tell me and I will post it. Otherwise feel free to ask for further clarifications.
But after debugging, it seemes that there is a problem:
Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\kernel32.dll', no matching symbolic information found.
Loaded 'C:\Windows\System32\KernelBase.dll', no matching symbolic information found.
The program 'D:\TRAVAUX DE THÈSE\MODELING\tempprogram\Debug\tempprogram.exe' has exited with code 0 (0x0).
I'm sorry but I'm not used to the Windows programming environment and I've not a clue about what's going on here.
Hi,
Really I want to thank you again for your help.I will be grateful if you can post the code that you've written for me. I think it will be very useful for me.
Thank you again for your precious help
PROGRAM test
IMPLICIT NONE
INTEGER, PARAMETER :: NLEV = 30
REAL, DIMENSION(NLEV) :: temp, depth
DOUBLE PRECISION :: time
INTEGER :: status, i, p
CHARACTER(len=20) :: label
CHARACTER(len=20), DIMENSION(NLEV) :: labels
CHARACTER(len=100) :: infile, oufile
! ----------------------------------------------------------------------
! Get file names from command line arguments
! ----------------------------------------------------------------------
CALL getarg(1,infile)
CALL getarg(2,oufile)
! ----------------------------------------------------------------------
! Open input file for reading
! ----------------------------------------------------------------------
OPEN(10, FILE=trim(infile), STATUS = 'OLD', ACTION = 'READ', IOSTAT = status)
IF ( status /= 0 ) THEN
STOP 'Cannot open input file.'
END IF
! ----------------------------------------------------------------------
! Open ouput file for writing
! ----------------------------------------------------------------------
OPEN(20, FILE = trim(oufile), STATUS = 'NEW', ACTION = 'WRITE', IOSTAT = status)
IF ( status /= 0 ) THEN
STOP 'Cannot open output file.'
END IF
! ----------------------------------------------------------------------
! Read header and set depths
! ----------------------------------------------------------------------
READ(10,*) labels
DO i = 1, NLEV
label = labels(i)
!
! Find index of character 'm'
!
p = index(label,'m')
!
! Convert string to number
!
READ(label(1:p-1),*) depth(i)
END DO
! ----------------------------------------------------------------------
! Read data
! ----------------------------------------------------------------------
DO
READ(10,*,IOSTAT=status) time, temp
!
! If end-of-file is reached, exit from the loop
!
IF ( status /= 0 ) EXIT
!
! Write formatted output
!
DO i = 1, NLEV
WRITE(20,1000) time, depth(i), temp(i)
END DO
END DO
1000 FORMAT(F10.4,F8.1,F9.3)
! ----------------------------------------------------------------------
! Close files
! ----------------------------------------------------------------------
CLOSE(10, IOSTAT=status)
CLOSE(20, IOSTAT=status)
END PROGRAM test
Please, notice it retrieves the input and output file names from the command line. I don't know if it works in Windows (it should be dependent from the compiler). Also it retrieves the depths from the first line of input (formatted as in the sample data shown above).
great!!!!
If you don't mind, please I have some questions:
1- The program is written in fortran 90-95?
2- What about"double precision"
3-Please Can you explain this line " OPEN(10, FILE=trim(infile), STATUS = 'OLD', ACTION = 'READ', IOSTAT = status)"
is the words "STATUS, "Action" and 'iostat"are keywords that we can use in every progarm
4- the term "label" ?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.