LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 03-28-2006, 08:56 AM   #1
Lordandmaker
Member
 
Registered: Sep 2005
Location: London, UK
Distribution: Debian
Posts: 258

Rep: Reputation: 39
number strings in fortran 95


I'm trying to manipulate a string of numbers in fortran.
Essentially, i need to get the mean of a set of numbers of a non-standard length (so i could get the mean of 5 or 50 numbers, for example, with the same program).

Does fortran support a way of reading a string of numbers, then allowing me to do things to the numbers inside it?
 
Old 03-31-2006, 03:28 PM   #2
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 490
Blog Entries: 4

Rep: Reputation: 238Reputation: 238Reputation: 238
When you say a 'string' of numbers, do you mean an array of numbers?

And, when you say 'non-standard length' (so you can manipulate 5 or 50 numbers), do you mean to say simply that you need to manipulate a variable quantity of numbers?

If so, reading and manipulating a one-dimensional array of variable length is rather easy in Fortran (or any language)

Here's a simple example:
Code:
    INTEGER N
    REAL SCORE(100),AVE
C (Assume old Fortran-compatible record layout, with 
C  header indicating number of records that follow)
    READ *,N
    READ *,(SCORE(J)J = 1,N)
C Variable N is the size of the array SCORE
C Pass it along with the array to the subroutine
    CALL MEAN(N,SCORE,AVE)
    PRINT *,AVE
    END

C This makes the subroutine quite straightforward
C Just total the numbers, and divide by the quantity
    SUBROUTINE MEAN(N,X,BAR)
    INTEGER N
    REAL   X(100),XBAR,SUM
    SUM = 0
    DO 10 J = 1,N
      SUM = SUM + X(J)
 10 CONTINUE
    XBAR = SUM/REAL(N)
    END
Of course, i may have completely misunderstood your question.
 
  


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
g77 in gcc 4.1.0 not found only gfortran fortran 95 compiler! I need fortran 77. TheBrick Linux - Software 3 07-04-2007 06:39 AM
Gnu Fortran versus Intel Fortran tomatoefish Linux - Software 3 02-20-2006 01:31 PM
how to find duplicate strings in vertical column of strings markhod Programming 7 11-02-2005 04:04 AM
does linux fortran compiler in fedora 4 support VAX FORTRAN? terrence Programming 17 08-31-2005 08:59 AM
why there is a need for minor number and major number for monitor/keyboard in pc? tripathi Solaris / OpenSolaris 1 11-07-2003 09:36 AM

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

All times are GMT -5. The time now is 01:55 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