修改在FORTRAN数组 [英] Modifying an array in fortran

查看:195
本文介绍了修改在FORTRAN数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题。我有一个文件,我必须:结果

I have the following problem. I have a file that I must:


  1. 鸿沟细胞创建一个 N×N的网​​格;

  2. 计数每个单元中的颗粒;

  3. 在一个特定的方式编写生成的数字。

  1. divide in cells to create an NxN grid;
  2. counts the particles in each cell;
  3. write the resulting numbers in a particular way.

问题是第三点:我必须写的N×N阵列中的每个数字重新present每个细胞颗粒的总数字,但我不知道如何写在文件中的 N×N的阵列。

The problem is the third point: I must write an NxN array each numbers represent the total numbers of particles in each cell, but I don't know how to write the file in an NxN array.

program eccen
    implicit none
    integer, parameter:: grid=200
    integer::i,j,k,n,m
    real*8,allocatable::f(:,:)
    real*8::xx(grid),yy(grid),mval,Mxval
    real*8,allocatable::x(:),y(:)

    open(10,file='coordXY.txt')
    n=0
    DO
       READ(10,*,END=100)
        n=n+1
    END DO

 100     continue
    rewind(10)

    allocate(x(n),y(n))

    do i=1, n
        read(10,*) x(i),y(i)
    end do

! create a grid
    mval=-15.
    Mxval=15.
    do i=1, grid
        xx(i) = mval + ((Mxval - mval)*(i-1))/(grid-1)
        yy(i) = mval + ((Mxval - mval)*(i-1))/(grid-1)
    end do

    open(20,file='fluxXY.dat')

! counts the paticles in each cell of the grid


    allocate(f(grid,grid))
    f=0
    do i=1,grid
        do j=1,grid
            m=0.
            do k=1, n
                if (x(k) > xx(i) .and. x(k) < xx(i+1) .and. &
                 & y(k) > yy(j) .and. y(k) < yy(j+1)) then  
                    m=m+1 ! CONTA IL NUMERO DI PARTICELLE
                end if
            end do
            f(i,j)=float(m+1)    
! THIS IS HOW I WRITE THE FILE BUT THIS SHOULD BE CHANGED
            write(20,*) f(i,:)

        end do
        write(20,*)
        print *,i
    end do    
end program eccen

非常感谢您的帮助!

Thanks a lot for Your help!

推荐答案

[解决]

我终于解决了我所有的问题:

I finally solve all my problems:


  1. 使用

    ifort -no-总结保证金! - >工作

使用 ifort 与@Stefan秘诀! - >工作

using ifort with @Stefan tips -> work!

使用 gfortran 单独! - >工作

use gfortran alone -> work !

不同的是在文件大小:用1)溶液中的文件是不是与2)溶液更大一点。 3)的情况下,再次,示出了在文件大小差异尊重其它情况下(比其他两个更高)。分别为:

The difference is in the file size: using the 1) solution the file is a bit larger than with the 2) solution. The 3) case, again, shows difference in file size respect the other cases (higher than the other two). Respectively:


  1. 60KB;

  2. 40KB;

  3. 65KB。

有关与格测试文件= 50和4001行和2行(132KB)的输入文件。

For a test file with grid=50 and an input file of 4001 lines and 2 rows (132kb).

感谢您的所有!!!!!

Thanks You all!!!!!

这篇关于修改在FORTRAN数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆