How many bytes in DIMENSION? - A Fortran Question

In summary, the 'dimension' type in Fortran is used to declare arrays and the type of numbers stored in the array depends on how it was declared. The first letter of the variable name determines if it is a real or an integer, and the number of bytes occupied by the variable is determined by the size of a single element multiplied by the number of elements in the array. It is important to remember that integers in Fortran are denoted by I->N, not I->T.
  • #1
dimensionless
462
1
How many bytes in DIMENSION?? - A Fortran Question

I'm looking at some Fortran code. Some variables are of type dimension. How do I tell if these variables are integers or floating points numbers? How do I know if they are signed or unsigned? How do I tell the number of bytes occupied by the variable?:confused:
 
Technology news on Phys.org
  • #2
The 'dimension' type is an slightly out-dated way to declaring arrays (vectors, matrices, and higher dimensional arrays). What type of numbers are stored in the array depends on how the name of the array was declared. For example, if I type:

real A
dimension A(10)
real B
dimension B(2,2)

then A will be a vector of 10 reals. These 10 reals will be stored in 10 adjacent memory locations. B will be a 2-by-2 matrix of reals also stored in adjacent memory locations by column ( (1,1) then (2,1) then (1,2) then (2,2) ). And if there is no declaration like 'real A', then remember the fun FORTRAN protocol of automatic typing:

- If the first letter starts with A - J or U - Z, then it's a real
- If the first letter starts with I - T, then it's an integer.

The number of bytes occupied by the variable in memory will be the size of a single element of the array multiplied by the number of elements in the array.

- Jason
 
  • #3
Unless Fortran has changed since I last used it, intergers are I->N, not I->T.
 
  • #4
Jeff Reid said:
Unless Fortran has changed since I last used it, intergers are I->N, not I->T.

Good call :blushing: :blushing:

I always try to remember it from the letters in INteger...but occasionally when I'm not thinking (which is surprisingly often) I pick the wrong two letters in InTeger :tongue2:
 
Last edited:
  • #5
Note that the choice of I->N coincides with common mathematical usage (for example, usually i->n are used as subcripts for series).
 

1. How many bytes are in a dimension in Fortran?

The number of bytes in a dimension in Fortran depends on the data type being used. For example, a dimension of integers would take up 4 bytes per element, while a dimension of real numbers would take up 8 bytes per element.

2. How do I calculate the total number of bytes in a dimension?

To calculate the total number of bytes in a dimension in Fortran, you would need to multiply the number of elements in the dimension by the number of bytes per element. For example, if you have a dimension of 100 integers, the total number of bytes would be 400 bytes (100 elements x 4 bytes per element).

3. Can the number of bytes in a dimension vary?

Yes, the number of bytes in a dimension can vary based on the data type and the compiler being used. Some compilers may use different amounts of memory for certain data types, so it is important to check the documentation for your specific compiler.

4. Does the size of a dimension affect the performance of my Fortran code?

Yes, the size of a dimension can affect the performance of your Fortran code. Larger dimensions may require more memory and can result in slower execution times. It is important to consider the size of your dimensions when writing efficient code.

5. How can I optimize the number of bytes used in my Fortran code?

To optimize the number of bytes used in your Fortran code, you can use the "kind" parameter to specify the data type and size of your variables. This will ensure that the appropriate amount of memory is allocated for each variable and can help improve performance.

Similar threads

  • Programming and Computer Science
Replies
9
Views
1K
  • Programming and Computer Science
Replies
4
Views
601
  • Programming and Computer Science
Replies
32
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
5
Views
915
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
21
Views
2K
Back
Top