!--------( EDEQS : preparation for inversion )-------- implicit none integer,parameter :: KVER = 2018 integer :: lwkdir, lrtrim; real :: calma real,allocatable :: t(:,:), f(:,:), tt(:,:), g(:,:) character(80) :: wdr, flog, fnam1, fnam2, fnam3, fnam4, buf character(72) :: out; character(20) :: sdtm character(8) :: area integer :: ldr, ndpt, idpt, i, j, nhx, nhy, nfx, nfy, ip, jp, k, IER integer :: nc, ncc, iorg, korg, ispa, ispb integer :: ixl, iyl, mszx, mszy, mx, my integer :: ixlm, iylm, mxm, mym, is, js, ic, jc, ki, kj real :: tnul, xl, yl, alt, smx, smy, amxy, vol, vd, hw, hwm, hhwm4, ss real :: xlm, ylm, x, y, rr, w, s, xp, yp, hp, z, ht, dip, dec, the, phi real(8) :: dfi, dfk, dxn, dye call premsg('EDEQS : preparation for inversion') call opnpin() ldr = lwkdir(50,wdr) + 1 flog = wdr; fnam1 = wdr; fnam2 = wdr; fnam3 = wdr; fnam4 = wdr call gparma('Enter LOG filename ==> ', 81-ldr, flog(ldr:80)) call gparma('Enter StdLIN data filename ==> ', 81-ldr, fnam1(ldr:80)) open(1,file=fnam1,status='old') call gparma('Enter Reduction Alt. filename ==> ', 81-ldr, fnam2(ldr:80)) open(2,file=fnam2,status='old') do read(2,'(a)') buf if (buf(1:1) /= '#') exit call premsg(' ' // buf(1:lrtrim(buf))) enddo if (buf(13:16) == ' ') then !-- v2005 read(buf,'(a8,i4,4x,4i8)') area, ncc, iorg, korg, ispa, ispb if ((ncc<0) .or. (ncc>=400)) call abendm('invalid coord.no.') nc = ncc if (ncc < 200) then nc = ncc; ncc = nc + 800 else ncc = ncc - 200; nc = ncc endif else !-- v2018 read(buf,'(a8,4x,i4,4i8)') area, ncc, iorg, korg, ispa, ispb nc = ncc if ((ncc >= 800) .and. (ncc < 1000)) nc = ncc - 800 endif if ((nc >= 1) .and. (nc <= 62)) then iorg = 0; ispa = 0; ispb = 0 korg = (nc-30)*360 - 180 if (nc > 60) korg = 0 if (nc == 61) iorg = +5400 if (nc == 62) iorg = -5400 endif read(2,'(a)') buf read(buf,*) ixl, iyl, mszx, mszy, mx, my, tnul xl = float(ixl)/1000.; yl = float(iyl)/1000. allocate(t(mx,my)) read(2,*) ((t(i,j),i=1,mx),j=1,my) close(2) call cvinit(ncc,float(iorg),float(korg),float(ispa),float(ispb)) ndpt = 0; idpt = 0 do read(1,'(a)',iostat=IER) buf if (IER < 0) exit if ((buf(1:1) == '&') .or. (buf(1:1) == '%') .or. (buf(1:1) == '#')) cycle ndpt = ndpt + 1 enddo rewind(1) allocate(f(3,ndpt)) do read(1,'(a)',iostat=IER) buf if (IER < 0) exit if ((buf(1:1) == '&') .or. (buf(1:1) == '%') .or. (buf(1:1) == '#')) cycle idpt = idpt + 1; if (idpt > ndpt) call abendm('Abnormal StdLIN data(1)') i = index(buf,'N'); if (i /= 0) buf(i:i) = ' ' i = index(buf,'E'); if (i /= 0) buf(i:i) = ' ' i = index(buf,'m'); if (i /= 0) buf(i:i) = ' ' read(buf,*) dfi, dfk, alt call cvdiken(dfi, dfk, dye, dxn) f(1,idpt) = real(dxn); f(2,idpt) = real(dye); f(3,idpt) = alt enddo if (idpt /= ndpt) call abendm('Abnormal StdLIN data(2)') close(1) write(out,'(a12,a8,6x,a6,i4,4x,4i8)') & '--- Area : ', area, 'Coord.', ncc, iorg,korg, ispa,ispb call premsg(out) write(out,'(a14,2a10,2x,2a8,2a6)') & '--- (mesh) ', 'xs', 'ys', 'msz-x', 'msz-y', 'mx', 'my' call premsg(out) write(out,'(a16,2f10.2,2i8,2i6)') & '--- reduc. alt. ', xl, yl, mszx, mszy, mx, my call premsg(out) smx = float(mszx); smy = float(mszy); amxy = smx * smy vol = amxy * sqrt(amxy) call premsg('') call premsg('Specify Equivalent Source Parameter') call premsg(' Vertical distance from reduction surface ?') call gparmf(' Downward (in m) : ', vd) if (vd <= 0.) call abendm('invalid value') call premsg(' Truncation of Source effect ?') call gparmf(' Half width of calc.window (in km) : ', hw) hwm = hw * 1000.; nhx = nint(hwm/smx); nhy = nint(hwm/smy) if ((nhx < 10) .or. (nhy < 10)) call abendm('truncation too short') nfx = nhx + nhx; nfy = nhy + nhy mxm = mx + nfx; mym = my + nfy ixlm = ixl - mszx*nhx; iylm = iyl - mszy*nhy xlm = float(ixlm)/1000.; ylm = float(iylm)/1000. allocate(tt(mxm,mym)); allocate(g(-nhx:+nhx,-nhy:+nhy)) call premsg('') call premsg('Specify Direction Parameters (in degrees)') call gparmf2(' Inclin., Declin. of Ambient field : ', dip, dec) if ((dip < -90.) .or. (dip > 90.) .or. & (dec < -180.) .or. (dec >= 360.)) call abendm('invalid value') call gparmf2(' Inclin., Declin. of Magnetization : ', the, phi) if ((the < -90.) .or. (the > 90.) .or. & (phi < -180.) .or. (phi >= 360.)) call abendm('invalid value') call premsg('') call gparma('Enter CFUPS matrix out filename ==> ', 81-ldr, fnam3(ldr:80)) open(20,file=fnam3,form='unformatted',status='new') call gparma('Enter ADEQS model out filename ==> ', 81-ldr, fnam4(ldr:80)) call clspin() call strdtm(sdtm) open(21,file=fnam4,status='new') write(6,'(a)') '----------------------------------------' write(6,'(a)') 'EDEQS : preparation for inversion' write(6,'(a,a)') ' StdLIN data infile : ', fnam1(1:lrtrim(fnam1)) write(6,'(a,a)') ' Reduc.Alt.data infile : ', fnam2(1:lrtrim(fnam2)) write(6,'(a,a)') ' CFUPS matrix outfile : ', fnam3(1:lrtrim(fnam3)) write(6,'(a,a)') ' ADEQS model outfile : ', fnam4(1:lrtrim(fnam4)) write(6,'(a12,a8,6x,a6,i4,4x,4i8)') & 'Areaname : ', area, 'Coord.', ncc, iorg, korg, ispa, ispb write(6,'(4x,a)') & ' (mesh) xs ys msz-x msz-y mx my alt ' write(6,'(4x,a12,2f10.2,2i8,2i6,a8)') & 'reduc. surf.', xl,yl, mszx,mszy, mx,my, ' --- ' write(6,'(4x,a12,2f10.2,2i8,2i6,a8)') & 'eq.src.mag. ', xlm,ylm, mszx,mszy, mxm,mym, ' var.' write(6,'(a,f6.2,a,i4,a,i4,a)') & ' Half width of calc.window :', hw, ' km (', nhx, ' *', nhy, ' mesh )' write(6,'(a,f8.1,a)') ' Equiv.Source :', vd, ' m below Reduction alt.' write(6,'(a,4x,a,f6.1,4x,a,f7.1)') & ' ambient field : ', 'dip=', dip, 'dec=', dec write(6,'(a,4x,a,f6.1,4x,a,f7.1)') & ' magnetization : ', 'dip=', the, 'dec=', phi call dpcini('... gen. Source alt. data : ') do jp=1,mym; do ip=1,mxm; tt(ip,jp) = tnul; enddo; enddo do j=1,my; do i=1,mx if (t(i,j) /= tnul) tt(i+nhx,j+nhy) = t(i,j) - vd enddo; enddo hhwm4 = hwm*hwm * 4. do jp=1,mym; do ip=1,mxm if (tt(ip,jp) == tnul) then ss = hhwm4 do js=-nhy,+nhy j = jp - nhy + js if ((j <= 0) .or. (j > my)) cycle y = float(js)*smy do is=-nhx,+nhx i = ip - nhx + is if ((i <= 0) .or. (i > mx)) cycle if (t(i,j) == tnul) cycle x = float(is)*smx rr = x*x + y*y if (rr < ss) ss = rr enddo enddo if (ss < hhwm4) then ss = ss + ss; w = 0.; s = 0. do js=-nfy,+nfy j = jp - nhy + js if ((j <= 0) .or. (j > my)) cycle y = float(js)*smy do is=-nfx,+nfx i = ip - nhx + is if ((i <= 0) .or. (i > mx)) cycle if (t(i,j) == tnul) cycle x = float(is)*smx rr = x*x + y*y if (rr < ss) then s = s + t(i,j)*(ss-rr) w = w + (ss-rr) endif enddo enddo tt(ip,jp) = s/w - vd endif endif call dpcent((jp-1)*mxm+ip, mxm*mym) enddo; enddo call dpcini('... gen. CFUPS matrix data: ') call magafd(the, phi, dip, dec) call mpoint(0.01, 0., 0., 0., vol) write(20) area, KVER, ncc, iorg,korg, ispa,ispb, & ixl, iyl, mszx, mszy, mx, my, & nhx, nhy, hw, vd do k=1,ndpt xp = (f(1,k)-xlm)*1000.; yp = (f(2,k)-ylm)*1000.; hp = f(3,k) ic = nint(xp/smx); jc = nint(yp/smy) do kj=-nhy,+nhy; do ki=-nhx,+nhx; g(ki,kj) = 0.; enddo; enddo do kj=-nhy,+nhy js = jc + kj if ((js < 0) .or. (js >= mym)) cycle y = float(js)*smy - yp do ki=-nhx,+nhx is = ic + ki if ((is < 0) .or. (is >= mxm)) cycle ht = tt(is+1,js+1) if (ht /= tnul) then x = float(is)*smx - xp; z = hp - ht g(ki,kj) = calma(x, y, z) endif enddo enddo write(20) k, ic, jc, ((g(ki,kj),ki=-nhx,+nhx),kj=-nhy,+nhy) call dpcent(k, ndpt) enddo close(20) write(21,'(a8,4x,i4,4i8)') area, ncc, iorg,korg, ispa,ispb write(21,'(2i12,4i6,1x,f7.1,1x,f7.0,i6)') & ixlm, iylm, mszx, mszy, mxm, mym, 9999.9, 0., 0 do j=1,mym write(21,'((f7.1,9(1x,f7.1)))') (0.,i=1,mxm) enddo write(21,'(a8,4x,i4,4i8)') area, ncc, iorg,korg, ispa,ispb write(21,'(2i12,4i6,1x,f7.1,1x,f7.0)') & ixlm, iylm, mszx, mszy, mxm, mym, tnul, -1. do j=1,mym write(21,'((f7.1,9(1x,f7.1)))') (tt(i,j),i=1,mxm) enddo write(21,'(a2,4(1x,f7.1))') '# ', dip, dec, the, phi close(21) if (flog(ldr:ldr) /= ' ') then open(99,file=flog,access='append') write(99,'(//a)') 'EDEQS : preparation for inversion' write(99,'(a,a)') ' StdLIN data infile : ', fnam1(1:lrtrim(fnam1)) write(99,'(a,a)') ' Reduc.Alt.data infile : ', fnam2(1:lrtrim(fnam2)) write(99,'(a,a)') ' CFUPS matrix outfile : ', fnam3(1:lrtrim(fnam3)) write(99,'(a,a)') ' ADEQS model outfile : ', fnam4(1:lrtrim(fnam4)) write(99,'(a,a,a)') '--------------- ', sdtm, '---------------' write(99,'(a12,a8,6x,a6,i4,4x,4i8)') & 'Areaname : ', area, 'Coord.', ncc, iorg, korg, ispa, ispb write(99,'(4x,a)') & ' (mesh) xs ys msz-x msz-y mx my alt ' write(99,'(4x,a12,2f10.2,2i8,2i6,a8)') & 'reduc. surf.', xl,yl, mszx,mszy, mx,my, ' --- ' write(99,'(4x,a12,2f10.2,2i8,2i6,a8)') & 'eq.src.mag. ', xlm,ylm, mszx,mszy, mxm,mym, ' var.' write(99,'(a,f6.2,a,i4,a,i4,a)') & ' Half width of calc.window :', hw, ' km (', nhx, ' *', nhy, ' mesh )' write(99,'(a,f8.1,a)') ' Equiv.Source :', vd, ' m below Reduction alt.' write(99,'(a,4x,a,f6.1,4x,a,f7.1)') & ' ambient field : ', 'dip=', dip, 'dec=', dec write(99,'(a,4x,a,f6.1,4x,a,f7.1)') & ' magnetization : ', 'dip=', the, 'dec=', phi call strdtm(sdtm) write(99,'(a,a,a)') '=============== ', sdtm, '===============' close(99) endif stop end