Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Some Basic Questions
Hello,

I have just started to learn Fortran (mainly from the "Fortran 95/2003
Explained" book by Metcalf et al) and there are a couple of things
that seem really odd to me. It'd be great if someone could clarify the
following issues for me:

In case it matters: I am using the gfortran compiler and I am willing
to use whatever nonstandard extensions it may have.

1. Are there really no ++, +=, -= operators as shortcuts for i = i + 1
and i = i + n?

2. Is there really no loop control statement except "stop"? I am
missing statements do redo the loop (jump to the beginning and do
not update the loop variable) and to start the next iteration
(update loop variable and jump to beginning of loop).

3. Is there no command to simply print things like

"Position of particle 1 at t=23s: x_x=23, x_y=11"? It seems that

the only way to write this in Fortran seems to be using something like

print "(a,1x,i0,1x,a,f0,a,f0,a,f0)", "Pos..", i, "at t=", t, ....

(since the * format looks just awful). I would really like
something like the C printf statement so that I can just write

printf "Position of particle %d at t=%d s: x_x=%f, x_y=%f", &
i, t, x(0), x(1)

4. Are there any (free) modules that implement basic vector algebra,
like cross product, length etc in different coordinate systems?


Thanks in advance!

-Nikolaus

--
Nikolaus@rath.org | College Ring 6, 28759 Bremen, Germany
Class of 2008 - Physics | Jacobs University Bremen

»My opinions may have changed, but not the fact that I am right.«

Report this thread to moderator Post Follow-up to this message
Old Post
Nikolaus Rath
04-03-08 11:27 AM


Re: Some Basic Questions
Hi Nikolaus,

As if by magic, Nikolaus Rath appeared !

> Hello,
>
> I have just started to learn Fortran (mainly from the "Fortran 95/2003
> Explained" book by Metcalf et al) and there are a couple of things
> that seem really odd to me. It'd be great if someone could clarify the
> following issues for me:
>
> In case it matters: I am using the gfortran compiler and I am willing
> to use whatever nonstandard extensions it may have.
>

Personally I would avoid extensions, you are trying to learn the
language and it's much better to avoid being locked into "one true
compiler"

> 1. Are there really no ++, +=, -= operators as shortcuts for i = i + 1
>    and i = i + n?
>

Nope.

> 2. Is there really no loop control statement except "stop"? I am
>    missing statements do redo the loop (jump to the beginning and do
>    not update the loop variable) and to start the next iteration
>    (update loop variable and jump to beginning of loop).
>

Cycle will do the second of these, in fact in a more powerful
way than the C equivalent. You also want to look at Exit.

The first suggests that you don't quite understand fortran do loops,
at least those of the form

Do i = 1, n

End Do

Unlike C for loops you can always say in Fortran a priori the (maximum)
number of times the loop is executed (maximum because of the possibility
of exit or a go to). To do something like you are suggesting, and to be
honest
I can't think where I would want to do it, I would do something like

i = 0
Do
..
If( some_condition ) Then
Cycle
End If
..
i = i + 1
If( i > i_max ) Then
Exit
End If
End Do

> 3. Is there no command to simply print things like
>
>    "Position of particle 1 at t=23s: x_x=23, x_y=11"?

Yes - use free format ( i.e. the * format )

> It seems that
>
>    the only way to write this in Fortran seems to be using something like
>
>    print "(a,1x,i0,1x,a,f0,a,f0,a,f0)", "Pos..", i, "at t=", t, ....
>
>    (since the * format looks just awful).

Oh.

> I would really like
>    something like the C printf statement so that I can just write
>
>    printf "Position of particle %d at t=%d s: x_x=%f, x_y=%f", &
>           i, t, x(0), x(1)
>

To be honest ultimately I don't really see the difference, formatting
by its very nature is fiddly. However you might prefer

Write( *, "( 'Position of particle ', i0, ' at t =', f0, &
&'s: x_x=', f0, 'x_y=', f0 )" ) i, t, x( 0 ), x( 1 )

( untested - but I hope you get the drift )

> 4. Are there any (free) modules that implement basic vector algebra,
>    like cross product, length etc in different coordinate systems?
>

Don't know about this, nothing show up on google ?

Hope this helps,

Ian


Report this thread to moderator Post Follow-up to this message
Old Post
Ian Bush
04-03-08 11:27 AM


Re: Some Basic Questions
On 3 apr, 13:01, Ian Bush <I.J.B...@ku.ca.ld> wrote:
> 
> 
>
> Yes - use free format ( i.e. the * format )
>

That should be: list-directed.

It is a trifle unruly way of producing output,
but it works (you have no control over the formatting).

Note that Fortran's input and output statements are
actually statements, not functions/subroutines as in C.
As a consequence they are far more robust (in my opinion)
than C's printf() and scanf().

Regards,

Arjen

Report this thread to moderator Post Follow-up to this message
Old Post
Arjen Markus
04-03-08 01:42 PM


Re: Some Basic Questions
Ian Bush <I.J.Bush@ku.ca.ld> writes: 
>
> Cycle will do the second of these, in fact in a more powerful way
> than the C equivalent. You also want to look at Exit.

Actually, "exit" is what I wanted to write above - sorry for the
confusion. Cycle does indeed what I need and as it turns out it is
also described in my book. No idea how I overlooked it - thanks.
 
>
> To be honest ultimately I don't really see the difference, formatting
> by its very nature is fiddly. However you might prefer
>
> Write( *, "( 'Position of particle ', i0, ' at t =', f0, &
>             &'s: x_x=', f0, 'x_y=', f0 )" ) i, t, x( 0 ), x( 1 )
>
> ( untested - but I hope you get the drift )

Yes, that already looks better.
 
>
> Don't know about this, nothing show up on google ?

Not really. I only found some really basic module on
http://www.nag.co.uk/nagware/Examples.asp, but it only works in
cartesian coordinates.


Best,

-Nikolaus

--
Nikolaus@rath.org | College Ring 6, 28759 Bremen, Germany
Class of 2008 - Physics | Jacobs University Bremen

»My opinions may have changed, but not the fact that I am right.«

Report this thread to moderator Post Follow-up to this message
Old Post
Nikolaus Rath
04-03-08 01:42 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Fortran archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 02:15 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.