Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to solve this

Status
Not open for further replies.

milenko76

Technical User
Mar 26, 2010
100
PT
I have calculated some corections but now I have problem to add them to original values.
rewind(5)
do i=2,nc
read(5,*)icd,res(icd),ivar(icd)
if(ivar(icd).ne.0)then
ivarprd=ivarprd+1
ivarp(ivarprd)=icd
endif
I want to add 21 real values to res(icd)
res(icd)=res(icd)+cor(icd)
But it is not working.
icd-number of cell
res-resistivity of the cell
ivar-1 or 0
nc=58
How to tell computer to do this operation?
 
module newmodc


use constants
use settings
use params
use mt2dmod
use fdsystem
use mt2ddat
use mt2dsens

implicit none

contains

subroutine newmodel
integer*4 i,icd
real,dimension(21) :: res1

do i=2,nc
read(5,*)icd,res(icd),ivar(icd)
end do
read(103,*)(res1(i),i=1,21)
if (ivar(icd).eq.1) then
res(icd)=res1(i)
end if
write(200,454)icd,res(icd),ivar(icd)
454 format(i5,1x,f5.2,2x,i1)
end subroutine
end module
 
Which part doesn't work - what are you expecting it to return and what is it returning.
 
Ok,baciclly I have file like this.(57lines)
2 1.00 0
3 1.80 0
4 63.69 0
5 472.97 0
6 801.43 0
7 3.71 0
8 35.07 0
9 15.63 0
10 6.15 0
11 170.03 0
12 1.96 1
When ivar is 1,I want to rewrite res(resistivity) with 1.95 for example.The point in that I have 21 values of new resistivities.Now I am trying with select case to see if it can work.
 

I see one anomaly in your program :

- First of all nc is not clearly defined. I assume that it comes from a module but you should precise that in using the ONLY keyword at each USE statement.

- In the instruction "res(icd)=res1(i)", i is not defined... In fact, i is defined twice before that : in the DO loop (value nc+1 at the end of the explicit loop) and in the read statement "read(103,*)(res1(i),i=1,21)" but this instruction uses an implied do loop and FORTRAN says that "i" is undefined at the end of such loop.

François Jacq
 
ok,I have changed nc with 57,and made loop adjustments.
subroutine newmodel
integer*4 i,j,icd
real,dimension(21) :: res1

do j=1,57
read(5,*)icd,res(icd),ivar(icd)
end do
read(103,*)(res1(i),i=1,21)
if (ivar(icd).eq.1) then
res(icd)=res1(i)
end if
do i=1,57
write(200,454)icd,res(icd),ivar(icd)
454 format(i5,1x,f5.2,2x,i1)
end do
end subroutine
Compile it ,but it doesn,t work.So I want to tell him to pick res1 instead od res(icd),when ivar is 0.Later to just write it into new file.
 
subroutine newmodel
integer*4 i,j,icd,icd1,ivar
real :: res,res1
do i=1,57
read(5,*)icd,res,ivar
end do
do j=1,21
read(104,*)icd1,res1,ivar
end do
do i=1,57
select case(ivar)
case(1)
write(200,454)icd,res,ivar
454 format(i5,1x,f5.2,2x,i1)
case(0)
write(200,454)icd1,res1,ivar
end select
end do
It writes 57 identical values:
58 21.45 1
58 21.45 1
58 21.45 1
58 21.45 1
58 21.45 1
58 21.45 1
58 21.45 1
58 21.45 1
58 21.45 1
 
And what did you expect with your new version ? You are testing and printing 57 times the same thing !

In the "corrected" version, you did not correct the only mistake I indicated : the use of an undefined "i" variable...

So your two programs are simply wrong.

François Jacq
 
I don't want be impolite, but IMHO it's waste of time to answer this thread, when the OP cannot clearly formulate the problem and is not able to understand the basic mistakes he ha done in code above.
 
Do you want something like that ?

Code:
  subroutine newmodel(res)

    real   , intent(out) :: res(*)

    integer ::  icd,k,ivar
    real    :: res1(21)

    read(103,*) res1

    k=0
    do
      read(5,*,end=100) icd,res(icd),ivar
      if(ivar == 1) then
        k=k+1
        if(k > 21) stop "too many values to change"
        res(icd)=res1(k)
      endif
      write(*,*) icd,res(icd),ivar
    end do

    100 continue

  end subroutine

François Jacq
 
Well I have been occupied with some other stuff,but I still have problem here.When I read file I get this:
0.0000000E+00 1.000000 1.800000 63.69000 472.9700
801.4300 3.710000 35.07000 15.63000 6.150000
170.0300 1.938000 47.99000 55.85000 268.3500
59.74400 34.29000 426.4800 966.7300 150.8800
794.5800 7.790000 18.97000 499.7490 90.99000
506.3410 766.8510 3.245000 374.9400 525.4500
7.620000 643.8100 17.54000 8.269000 35.05000
15.36000 234.0700 116.7900 42.94000 59.87000
1.978000 67.37000 19.81000 62.90000 342.9200
30.00000 208.4700 1.936000 3.729000 5.399000
219.0620 1.879000 3.500000 70.81000 54.88300
165.1700 8.760000
So 0.0000000E+00 appears and I lack the last 57th value.I am using the same routine Francois gave me:
subroutine newmodel(r)

real:: r(57)
integer :: icd,k,ivar
real,dimension(21) :: res1

open(5,file='test_res1.dat',status='old')
open(103,file='res1.dat',status='old')
read(103,*) res1
k=0
do
read(5,*,end=100) icd,r(icd),ivar
if(ivar == 1) then
k=k+1
if(k > 21) stop "too many values to change"
r(icd)=res1(k)
endif
end do

100 continue
end subroutine
 
I think that this is due to the fact that the index icd=1 is never used. Indeed, your file starts at icd=2.

François Jacq
 
Yes,but if I compile it as a program not subroutine works fine.I think it is somehow related to dummy argument r.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top