LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-07-2013, 12:27 AM   #1
nouss
LQ Newbie
 
Registered: Feb 2013
Posts: 6

Rep: Reputation: Disabled
programming in fortran


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
 
Old 02-07-2013, 03:32 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Hi and welcome to LinuxQuestions!

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.
 
1 members found this post helpful.
Old 02-07-2013, 07:33 AM   #3
nouss
LQ Newbie
 
Registered: Feb 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
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)

open(10,file="input.dat")
open(20,file="output.dat")

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.

test1.obj - 1 error(s), 0 warning(s)


thank you very much for your help
 
Old 02-07-2013, 09:09 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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.
 
Old 02-07-2013, 07:38 PM   #5
nouss
LQ Newbie
 
Registered: Feb 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
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:

1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 11m 12m 13m 14m 15m 16m 17m 18m 19m 20m 21m 22m 23m 24m 25m 26m 27m 28m 29m 30m
39945.5000 20.698 20.603 20.507 20.317 20.031 17.986 17.106 16.892 16.868 16.582 16.534 16.487 16.177 16.106 16.034 16.034 15.724 15.533 15.39 15.294 15.175 14.888 14.433 14.409 14.122 14.194 14.026 13.762 13.642 13.594
39945.5100 20.531 20.365 20.198 20.031 19.912 17.368 16.844 16.63 16.558 16.201 16.082 16.082 15.867 15.796 15.748 15.652 15.366 15.27 15.055 14.912 14.768 14.553 14.194 14.098 13.834 13.858 13.738 13.401 13.257 13.185
39945.5100 20.507 20.341 20.174 20.007 19.888 17.415 16.82 16.606 16.558 16.177 16.034 16.01 15.819 15.772 15.724 15.629 15.438 15.27 15.103 14.912 14.697 14.505 14.098 14.002 13.762 13.762 13.594 13.353 13.209 13.112


table(1,1) empty
line 1 : depth from 1 to 30
Colunm1 : time


thank you very much for your help
 
Old 02-08-2013, 02:57 AM   #6
nouss
LQ Newbie
 
Registered: Feb 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
Hi again,
I tried with the program:

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).

please what's the problem.
Thanks again
 
Old 02-08-2013, 04:31 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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.
 
Old 02-08-2013, 04:33 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by nouss View Post
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.
 
Old 02-08-2013, 07:45 AM   #9
nouss
LQ Newbie
 
Registered: Feb 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
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
 
Old 02-08-2013, 07:53 AM   #10
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You're welcome! Here we go:
Code:
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).

Last edited by colucix; 02-08-2013 at 07:56 AM.
 
1 members found this post helpful.
Old 02-08-2013, 08:21 AM   #11
nouss
LQ Newbie
 
Registered: Feb 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
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" ?

thanks again
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MPI programming: running external program on same processor (Fortran, mpiexec) zugvogel Programming 2 03-03-2010 06:09 AM
fortran programming in linux saray Linux - Newbie 4 08-03-2009 04:24 AM
One fortran programming problems. ArthurHuang Programming 1 03-26-2006 09:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration