Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 22

Thread: a fortran environment

  1. #11
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152
    So far, I think Code::Blocks is pretty nice, Kent.

    I think it's fast.

    I know all about F, it was made by Walt Brainerd.

    Up to now, I don't need to worry about portability.

    -------------------------------------------------------------------------

    Below is from the Wikipedia Fortran link,

    http://en.wikipedia.org/wiki/Fortran

    Fortran 2003

    Fortran 2003 is a major revision introducing many new features. A comprehensive summary of the new features of Fortran 2003 is available at the Fortran Working Group (WG5) official Web site.[13]
    From that article, the major enhancements for this revision include:

    • Derived type enhancements: parameterized derived types, improved control of accessibility, improved structure constructors, and finalizers.
    • Object-oriented programming support: type extension and inheritance, polymorphism, dynamic type allocation, and type-bound procedures.
    • Data manipulation enhancements: allocatable components (incorporating TR 15581), deferred type parameters, VOLATILE attribute, explicit type specification in array constructors and allocate statements, pointer enhancements, extended initialization expressions, and enhanced intrinsic procedures.
    • Input/output enhancements: asynchronous transfer, stream access, user specified transfer operations for derived types, user specified control of rounding during format conversions, named constants for preconnected units, the FLUSH statement, regularization of keywords, and access to error messages.
    • Procedure pointers.
    • Support for IEEE floating-point arithmetic and floating pointexception handling (incorporating TR 15580).
    • Interoperability with the C programming language.
    • Support for international usage: access to ISO 10646 4-byte characters and choice of decimal or comma in numeric formatted input/output.
    • Enhanced integration with the host operating system: access to command line arguments, environment variables, and processor error messages.

    An important supplement to Fortran 2003 was the ISO technical report TR-19767: Enhanced module facilities in Fortran. This report provided submodules, which make Fortran modules more similar to Modula-2 modules. They are similar to Ada private child subunits. This allows the specification and implementation of a module to be expressed in separate program units, which improves packaging of large libraries, allows preservation of trade secrets while publishing definitive interfaces, and prevents compilation cascades.

    Notice, "Interoperability with the C programming language.".

    I think they worked on that.

    I have a book coming from Amazon, which has a chapter on that topic.

    -------------------------------------------------------------------------

    I looked a little at the ScriptBasic website.

    My impression is that there is no IDE. If so, then, I think that will scare away a lot of people. It could be the best interpreter in the world, but, without an IDE, many people will pass it by (my opinion).

    Under "Installation", for Windows, it only mentions up to WINME. Also, most or all of the web pages say, "Last updated May 22, 2006.". Those could give people the initial impression that development has been discontinued. In my opinion, if people think that, they leave.

    In the forum, you must talk about programming. I think the thinBasic forum gets a lot of traffic, partly because, people feel free to discuss almost anything.

    The thinBasic website does a lot better job of "selling" thinBasic. Relatively, the ScriptBasic website is bland.

    thinBasic has the SDK. This gives programmers the hope of being able to contribute to the project, to become part of it. But, I see that ScriptBasic supports the same idea.

    I see that ScriptBasic's documentation is available in multiple formats.

    So, I would absolutely say that ScriptBasic's major handicaps are the fact that people could get the immediate impression that it is no longer being developed, and, the lack of an IDE. Like I said above, it could be the best language on Earth, but, without an IDE, most people will never know it. I think the same thing originally happened to Perl, Python, and Ruby. They didn't grow really fast until IDEs appeared.


    Last edited by danbaron; 22-10-2011 at 07:59.
    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

  2. #12
    Thanks Dan for stopping by the ScriptBasic site.

    1. ScriptBasic isn't a standalone interpreter, it's an embeddable scripting API engine. The scriba command line interpreter is an example of embedding the API. (in C in this case)

    2. ScriptBasic has a debug preprocessor option that lets you step through a script line by line and display variable contents. IT also supports breakpoints and can even be run remotely over TCP with a telnet connection. I guess you could call that an IDE of sorts.

    3. It's open source (LGPL) and you can use it commercially with no strings attached. It's used in a router I know of and the University of Toronto used SB embedded in dedicated controllers to control over 6 million square ft of their campus environmental systems.

    What else can I say?
    Last edited by John Spikowski; 22-10-2011 at 07:42.
    ScriptBasic Project Manager
    Project Site
    support@scriptbasic.org

  3. #13
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152
    I can see that it being embeddable, and, commercially usable, for free, are good things.

    It just becomes a matter of how many people have use for them.

    And, maybe it is unfair, but we have to live with it.

    We don't have personalities that attract people, like, for instance, Eros does.

    If you could turn ScriptBasic into a thinBasic module, that would be something.

    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

  4. #14
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152
    Here is an example of telepathic communication in Fortran.

    I think it is a manifestation of the phenomenon of quantum entanglement.

    http://en.wikipedia.org/wiki/Quantum_entanglement
    ' code ----------------------------------------------------------------------------------------------------------------
      
    program magic
    
        implicit none
        integer::m,n
        common/one/m
        common/two/n
    
        call a()
        call b()
        call c()
        call d()
    
        print *, m
        print *, n
    
    end program
    
    subroutine a()
    integer::i
    common/one/i
    i = 1
    end subroutine
    
    subroutine b()
    integer::i
    common/two/i
    i = 3
    end subroutine
    
    subroutine c()
    integer::i
    common/one/i
    i = i + 1
    end subroutine
    
    subroutine d()
    integer::i
    common/two/i
    i = i + 1
    end subroutine
    
    ' output --------------------------------------------------------------------------------------------------------------
    
    2
    4
    
    Last edited by danbaron; 22-10-2011 at 08:50.
    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

  5. #15
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Dan,

    what does the slashed syntax mean, for example here:
    common/two/i
    

    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  6. #16
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152
    I forget this stuff somewhat, if I ever knew it, Petr.

    In Fortran, there are different types of program units - programs, external subroutines and functions, internal subroutines and functions, modules, module subroutines and functions, probably there are more - this is before they added OOP.

    A common block allows one program unit to share common data with another.

    If I am correct, common blocks are the Fortran equivalent of global variables. In other words, in Fortran, variables can only be declared inside a program unit.

    There are two types of common blocks, unnamed, and named.

    The syntax for the unnamed type is,

    common/i,j,k
    
    The syntax for the named type is,

    common/some_name/i,j,k
    
    There can only be one common block of the unnamed type.

    But, there can be many of the named type.

    Each program unit that declares the same common block has access to its particular data.

    It is not necessary that two program units sharing a common block use the same names for the common data, for instance,

    subroutine e()
    integer::m,n
    common/dog/m,n
    m = 1
    n = 2
    end subroutine
    
    subroutine f()
    integer::p,q
    common/dog/p,q
    p = p + 1
    q = q + 1
    end subroutine
    
    Here, m and p are the same variables, and so are n and q.

    I have read that beginning in Fortran 90, the use of common blocks is discouraged.

    The exact same sharing of data can be accomplished by declaring shared data within a module (which may contain only data declarations if one so desires),

    module boat
    integer(8):: apple
    real(10):: pear
    end module
    
    and then putting the statement,

    use boat
    
    within each program unit that needs to access the particular data.

    (Modules can be put into separate files, but, they don't have to be. Above, "integer(8 )", means, an integer type that uses 8 bytes. And, modules can "use" other modules.)

    There are advantages to instead doing it this way. For instance, then, I don't think you need to specify the types of the common data within the program units that use it. I guess there were a lot of hard to find errors when using common blocks.

    The people who made/make the various official Fortran specifications over the years, Fortran 66, Fortran 77, Fortran 90, Fortran 95, Fortran 03, Fortran 08 (the number indicates the year of the specification), were/are not dummies. They were/are mostly numerical guys at big universities.

    Last edited by danbaron; 22-10-2011 at 11:46.
    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

  7. #17
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    I have old Fortran textbook (from 1973) at home, but this syntax was not discussed in it.

    Thanks for the info!,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  8. #18
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404
    Quote Originally Posted by Petr Schreiber View Post
    I have old Fortran textbook (from 1973) at home, but this syntax was not discussed in it.

    Thanks for the info!,
    Petr
    I am glad you had that book Petr. I thought my mind was totally erased, as that code looked alien to me, from what I could remember

  9. #19
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152
    In modern fortran, the random number generator takes a seed which is an array of integers.

    You use the intrinsic command,

    call random_seed()
    
    The subroutine must be called with one of three values, "size", "put", "get".

    If you call it like this,

    integer::sz
    call random_seed(size=sz)
    
    sz will be set to the number of elements in the seed array, for the particular architecture.

    For win32, it is 8 (4 byte integers), i.e., 256 bits.

    If you call it like this,

    call random_seed(put=seedarray)
    
    the seed will be set to seedarray (so, for win32, seedarray should be an integer array of 8 elements).

    If you call it like this,

    call random_seed(get=seedarray)
    
    seedarray will be set to the current value of the seed, i.e., the value (array) used for the next random number in the sequence.

    You can get a random value like this,

    double precision::ranval
    call random_number(ranval)
    
    0 <= ranval < 1.

    ! code ---------------------------------------------------------------------------------------------------------------------------------
    
    module random
    
    integer(4),dimension(:),allocatable::defaultseed,randomseed
    integer::seedsize
    
    !----------------------------------------------------------------------------------------------------------
    
    contains
    
    !----------------------------------------------------------------------------------------------------------
    
    subroutine allocateseeds()
    call random_seed(size=seedsize)
    allocate(defaultseed(seedsize))
    allocate(randomseed(seedsize))
    endsubroutine
    
    !----------------------------------------------------------------------------------------------------------
    
    subroutine setdefaultseed()
    ! Seeds the random number generator to a constant value.
    integer::i
    do i= 1,seedsize
    defaultseed(i)=0
    enddo
    call random_seed(put=defaultseed)
    endsubroutine
    
    !----------------------------------------------------------------------------------------------------------
    
    subroutine setrandomseed()
    ! Seeds the random number generator to a random value.
    integer::cnt,cntrate,cntmax,i
    do i= 1,seedsize
    call system_clock(cnt,cntrate,cntmax)
    randomseed(i)=cnt
    enddo
    call random_seed(put=randomseed)
    endsubroutine
    
    !----------------------------------------------------------------------------------------------------------
    
    subroutine resetdefaultseed()
    call random_seed(put=defaultseed)
    endsubroutine
    
    !----------------------------------------------------------------------------------------------------------
    
    subroutine resetrandomseed()
    call random_seed(put=randomseed)
    endsubroutine
    
    !----------------------------------------------------------------------------------------------------------
    
    end module random
    
    !----------------------------------------------------------------------------------------------------------
    !----------------------------------------------------------------------------------------------------------
    
    subroutine printrandomvals()
    double precision::ranval
    integer::i
    do i=1,5
    call random_number(ranval)
    print *,ranval
    enddo
    print *
    endsubroutine
    
    !----------------------------------------------------------------------------------------------------------
    !----------------------------------------------------------------------------------------------------------
    
    program test
    use random
    implicit none
    integer::sz
    character::c
    
    call random_seed(size=sz)
    
    print *
    print '(a,i1,a)', 'The random number generator takes a seed array consisting of ', sz, ' elements.'
    print *
    print *
    
    call allocateseeds()
    
    call setdefaultseed()
    
    print *, 'The first 5 doubles in the default sequence.'
    print *
    
    call printrandomvals()
    
    call setrandomseed()
    
    print *, 'The first 5 doubles in a random sequence.'
    print *
    
    call printrandomvals()
    
    call resetrandomseed()
    
    print *, 'The first 5 doubles again in the same random sequence.'
    print *
    
    call printrandomvals()
    
    call setrandomseed()
    
    print *, 'The first 5 doubles in a new random sequence.'
    print *
    
    call printrandomvals()
    
    call resetdefaultseed()
    
    print *, 'The first 5 doubles in the default sequence again.'
    print *
    
    call printrandomvals()
    
    print *
    print *, 'Enter a character to quit.'
    print *
    read *, c
    
    end program test
    
    ! output -------------------------------------------------------------------------------------------------------------------------------
     
    The random number generator takes a seed array consisting of 8 elements.
    
    
     The first 5 doubles in the default sequence.
    
      0.30901699450542608
      0.80380552047952203
      0.35249806832347486
      0.99809236009560809
      0.55022038741740864
    
     The first 5 doubles in a random sequence.
    
      0.35368386010621311
      0.92495087746258120
      2.79358793357609159E-002
      0.43250869170195372
      0.79918821411338958
    
     The first 5 doubles again in the same random sequence.
    
      0.35368386010621311
      0.92495087746258120
      2.79358793357609159E-002
      0.43250869170195372
      0.79918821411338958
    
     The first 5 doubles in a new random sequence.
    
      0.85485606414247872
      0.22150034995476942
      0.86076915663017317
      0.17166310760556669
      0.48618469153662536
    
     The first 5 doubles in the default sequence again.
    
      0.30901699450542608
      0.80380552047952203
      0.35249806832347486
      0.99809236009560809
      0.55022038741740864
    
    
     Enter a character to quit.
    
    Last edited by danbaron; 03-11-2011 at 11:58.
    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

  10. #20
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152
    Here is a little program that numerically integrates the function,

    f(x) = x^2*cos(x)/4,

    from x = 0, to, x = 2*pi,

    by the repeated application of Simpson's Rule.

    It uses a function parameter.

    There's probably an easier way to implement the function parameter, but, this way works.

    ' code ----------------------------------------------------------------------------------------------------------------
    
    double precision function xsquaredcosxdiv4(x)
    double precision,intent(in)::x
    intrinsic cos
    xsquaredcosxdiv4=x*x*cos(x)/4
    end function
    
    !-----------------------------------------------------------------------------------------------------------
    
    double precision function simpsonintegrate(x1,x2,ndivisions,f)
    double precision,intent(in)::x1,x2
    integer, intent(in)::ndivisions
    interface
    double precision function f(x)
    double precision, intent(in)::x
    end function f
    end interface
    double precision::division,sum
    integer::i
    
    division=(x2-x1)/ndivisions
    sum=f(x1)+f(x2))/2
    
    do i=1,ndivisions-1
    sum=sum+f(x1+division*i)
    enddo
    simpsonintegrate=division*sum
    endfunction
    
    !-----------------------------------------------------------------------------------------------------------
    
    program test
    implicit none
    intrinsic atan
    double precision,external::simpsonintegrate,xsquaredcosxdiv4
    double precision::pi
    
    pi=4*atan(1.0d0)
    
    print*,'pi               = ',pi
    print*,'integral approx. = ',simpsonintegrate(0,2*pi,100000,xsquaredcosxdiv4)
    
    end program
    
    ' output --------------------------------------------------------------------------------------------------------------
    
     pi               =    3.1415926535897931
     integral approx. =    3.1415926546233215
    
    We can verify that the correct answer is pi.

    We start with the product rule of differentiation,

    d(uv) = udv + vdu.

    We integrate both sides and get,

    uv = integral(udv) + integral(vdu).

    Now, we re-arrange, to get the formula for integration by parts,

    integral(udv) = uv - integral(vdu).

    We apply integration by parts twice to the function,

    f(x) = x^2*cos(x)/4,

    and we get,

    integral(x^2*cos(x)/4) = (x^2*sin(x) + 2*x*cos(x) - 2*sin(x))/4.

    When we evaluate the formula at x = 2*pi, and then subtract the evaluation of the formula at x = 0, we get, pi.

    Last edited by danbaron; 08-11-2011 at 09:13.
    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Space environment creator by kryton9
    By kryton9 in forum User tools
    Replies: 36
    Last Post: 08-02-2010, 07:04

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •