subroutine H_X_1d & (N_obs,iobs,i_loc,i_fguess,i1s,i1e, & H_obs,obs_err0,obs,obs_err) ! ********************************************************************** ! * . . . ! * PROGRAM: make obs in 1d ! * ! * PRGMMR: D. ZUPANSKI ORG: CIRA/CSU DATE: 2003-10-01 ! * ! * ABSTRACT: THIS PROGRAM READS FIRST GUESS VARIABLES AND ! * CREATES OBSERVATIONS AS PERTURBATIONS TO MODEL STATE ! * (KdVB model) ! * ! * PROGRAM LOG: ! * ! * 10/01/2003 ..... D. ZUPANSKI ! * ! ********************************************************************** integer Ndiff1,Ndiff2,Ndiff3 integer N1,N2,N3 parameter(Ndiff1=2,Ndiff2=4) !! interval (grid-pts) between obs parameter(N1=7,N2=3) !! 10 obs - (expected) number of obs in the interval !! parameter(N1=3,N2=2) !! 5 obs - (expected) number of obs in the interval !! parameter(N1=5,N2=0) !! 5 obs - (expected) number of obs in the interval character*9 :: fg_name,obs_name real :: obs_err0 real,dimension(1:N_obs) :: obs,obs_err real, dimension(:), allocatable :: fg1d real, dimension(:), allocatable :: u_obs,u real, dimension(:), allocatable :: random_x integer, dimension(:), allocatable :: y_loc integer, dimension(:), allocatable :: i1_loc integer :: imax character*3 :: H_obs real :: y1,y2 !============================================================== allocate(fg1d(i1s:i1e)) read(i_fguess) fg_name read(i_fguess) fg1d(i1s:i1e) !----- analytic solution used only for u_critical (can be avoided) ------------- u_max=-1.e10 imax=i1e-i1s+1 allocate(u(1:imax)) u(1:imax)=fg1d(i1s:i1e) LEFT: do i=1,imax ip1=i+1 if(ip1.gt.imax) ip1=ip1-imax im1=i-1 if(im1.le.0) im1=im1+imax d2u=u(ip1)+u(im1)-2.*u(i) write(*,*) "1st: i=",i," d2u=",d2u if(u(i).gt.u_max) then i_1=i u_max=u(i) end if end do LEFT write(*,*) "u_max=",u_max," i=",i_1 ip1=i_1+1 ip2=i_1+2 ip3=i_1+3 if(ip1.gt.imax) ip1=ip1-imax if(ip2.gt.imax) ip2=ip2-imax if(ip3.gt.imax) ip3=ip3-imax im1=i_1-1 im2=i_1-2 im3=i_1-3 if(im1.le.0) im1=im1+imax if(im2.le.0) im2=im2+imax if(im3.le.0) im3=im3+imax write(*,*) "ip1,2,3=",ip1,ip2,ip3 write(*,*) "im1,2,3=",im1,im2,im3 RIGHT: do i=1,imax if(i.ne.ip1.and.i.ne.ip2.and.i.ne.ip3.and.i.ne.i_1.and. & i.ne.im1.and.i.ne.im2.and.i.ne.im3.and.u(i).gt.0.5*u_max) then ipp1=i+1 if(ipp1.gt.imax) ipp1=ipp1-imax imm1=i-1 if(imm1.le.0) imm1=imm1+imax d2u=u(ipp1)+u(imm1)-2.*u(i) write(*,*) "2nd: i=",i," d2u=",d2u if(d2u.lt.0.) then i_2=i u_min=u(i) exit RIGHT end if end if end do RIGHT write(*,*) "u_min=",u_min," i=",i_2 if(i_1.gt.i_2) then i_min=i_2 i_max=i_1 else i_min=i_1 i_max=i_2 end if write(*,*) "i_min=",i_min," i_max=",i_max i_left=i_min-(N1/2)*NDIFF1 i_right=i_max+(N2/2)*NDIFF2 write(*,*) "i_left=",i_left," i_right=",i_right !---- observations --------------- N1st=i_left N2end=i_right N2st=N2end-(N2-1)*Ndiff2 N1end=N1st+(N1-1)*Ndiff1 write(*,*) "N1st=",N1st," N2st=",N2st write(*,*) "N1end=",N1end," N2end=",N2end NN=0 if(N1.gt.0) then do i=N1st,N1end,Ndiff1 NN=NN+1 end do end if if(N2.gt.0) then do i=N2st,N2end,Ndiff2 NN=NN+1 end do end if !-- define number of obs icount=NN write(102,*) "-------------------------------" write(102,*) "====== icount=",icount write(102,*) "-------------------------------" allocate(u_obs(1:icount)) allocate(y_loc(1:icount)) NN=0 if(N1.gt.0) then do i=N1st,N1end,Ndiff1 if(i.le.0) then ii=i+imax else if(i.gt.imax) then ii=i-imax else ii=i end if NN=NN+1 write(*,*) "1st loop: NN=",NN," i=",ii call Hx(H_obs,u(ii),u_obs(NN)) y_loc(NN)=ii end do endif if(N2.gt.0) then do i=N2st,N2end,Ndiff2 if(i.le.0) then ii=i+imax else if(i.gt.imax) then ii=i-imax else ii=i end if NN=NN+1 write(*,*) "2nd loop: NN=",NN," i=",ii call Hx(H_obs,u(ii),u_obs(NN)) y_loc(NN)=ii end do endif if(icount.ne.NN) then write(*,*) "!!!!-- PROBLEM --!!!!!" write(*,*) "assigned icount=",icount," actually used NN=",NN write(*,*) "!!!!-------------!!!!!" STOP 11 end if do i=1,icount write(*,*) "observation(",i,")=",u_obs(i)," at x=",y_loc(i) end do deallocate(u) !----- random perturbation ----------- allocate(random_x(1:icount)) allocate(i1_loc(1:icount)) i1_loc(1:icount)=y_loc(1:icount) deallocate(y_loc) !-- gauss random number generator N(0,1) ------------ mode2=MOD(icount,2) Nsave=icount/2 + mode2 do l=1,Nsave call Box_Muller_polar(y1,y2) ii_tot=0 do while (abs(y1).gt.3..or.abs(y2).gt.3.) ii_tot=ii_tot+1 if(ii_tot.gt.10) exit call Box_Muller_polar(yy1,yy2) if(abs(yy1).le.3.) then y1=yy1 end if if(abs(yy2).le.3.) then y2=yy2 end if end do random_x(l)=y1 random_x(Nsave+l-mode2)=y2 end do !-------------------------------------------- do i=1,icount iobs=iobs+1 obs(iobs)=u_obs(i)+ random_x(i) *obs_err0 obs_err(iobs)=obs_err0 write(*,*) i," obs=",obs(iobs)," random_x=",random_x(i) end do deallocate(u_obs) deallocate(fg1d) !------------------------------------ !-- write loc obs file write(i_loc) fg_name write(i_loc) icount write(i_loc) i1_loc(1:icount) end subroutine H_X_1d