English 中文(简体)
部分:对阵列的初始化和分配价值
原标题:Fortran: initializing of and assigning value to arrays

在<>Fortran上,对阵列的初始化和分配价值如下:

<>Initializing:

real(kind=8):: r(3,4)
...
r(:,:) = 0.0_8

如果我们只使用

real(kind=8):: r(3,4)
...
r = 0.0_8

and what if we do as:

real(kind=8):: r(3,4)
...
r = 0

此外,情况如下:

real(kind=8):: r(3,4), q(3,4), p(30,40)
...
q = 0
r = q
r = p(1:3,21:24)

我们更愿意这样做:

real(kind=8):: r(3,4), q(3,4), p(30,40)
...
q = 0.0_8
r(:,:) = q(:,:)
r(:,:) = p(1:3,21:24)

我们确信,hope你为我们提供了你选择的每一个理由。

最佳回答

你们是否认为“实物=8”是指8个。 所有汇编者都是如此。 1. 最大可转移性是利用所选择的---------------------------------------------------------------------------------------------------------

integer, parameter :: DRK = selected_real_kind (14)

Of some of the options that you list, I prefer r = 0.0_8, or better r=0.0_DRK. This defines the entire array. There is no need to designate array sections in this case, since you are calling out the entire array: r (:, :). Steve Lionel has a discussion of why trying to make arrays obvious with ":" isn t a good idea -- there are differences between array 以及 array (:). As an argument, the first has it declared dimensions, while the second always begins at 1 -- see http://software.intel.com/en-us/blogs/2008/03/31/doctor-it-hurts-when-i-do-this/

由于r是真实的,r=0意味着转换。 对零值而言,这几乎肯定是偶然的,但它可能与其他价值发生重要变化。 例如,

r = 3.1415927654

以及

r = 3.141592654_8

将为<代码>r提供不同的数值,因为固定数值不同,第一个数值在转让前转换为单一精确度。

问题回答




相关问题
WordPress Data Storage Efficiency

I ve been asked to review a WordPress plugin of sorts and try to find ways of making it faster. The premise of this plugin is basically to store a bunch of users and shifts and appointments and ...

Convert a 2D array index into a 1D index

I have two arrays for a chess variant I am coding in java...I have a console version so far which represents the board as a 1D array (size is 32) but I am working on making a GUI for it and I want it ...

Convert an array of integers for use in a SQL "IN" clause

Surely there is a framework method that given an array of integers, strings etc converts them into a list that can be used in a SQL "IN" clause? e.g. int[] values = {1,2,3}; would go to "(1,2,3)"

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

C++ Array Sort Me

Stuck on an array sorter. Have to sort numbers from largest to smallest. I m trying two loops (one nested in the other). Here s the code: int counter=0; // inner counter int counter2=0; // outer ...

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

Best practice of big javascript objects

sry for this imprecise topic name. I am querying a dataset a lot of times so using ajax request would end up in tons of http requests. For this reason I decided to use the json encode method to ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

热门标签