198
199
200
201
202 integer, intent(in) :: ng, tile
203 integer, intent(in) :: LBi, UBi, LBj, UBj, LBij, UBij
204 integer, intent(in) :: IminS, ImaxS, JminS, JmaxS
205 integer, intent(in) :: Ladj, Lini
206
207# ifdef ASSUMED_SHAPE
208# ifdef MASKING
209 real(r8), intent(in) :: rmask(LBi:,LBj:)
210 real(r8), intent(in) :: umask(LBi:,LBj:)
211 real(r8), intent(in) :: vmask(LBi:,LBj:)
212# endif
213# ifdef ADJUST_BOUNDARY
214# ifdef SOLVE3D
215 real(r8), intent(inout) :: ad_t_obc(LBij:,:,:,:,:,:)
216 real(r8), intent(inout) :: ad_u_obc(LBij:,:,:,:,:)
217 real(r8), intent(inout) :: ad_v_obc(LBij:,:,:,:,:)
218# endif
219 real(r8), intent(inout) :: ad_ubar_obc(LBij:,:,:,:)
220 real(r8), intent(inout) :: ad_vbar_obc(LBij:,:,:,:)
221 real(r8), intent(inout) :: ad_zeta_obc(LBij:,:,:,:)
222# endif
223# ifdef ADJUST_WSTRESS
224 real(r8), intent(inout) :: ad_ustr(LBi:,LBj:,:,:)
225 real(r8), intent(inout) :: ad_vstr(LBi:,LBj:,:,:)
226# endif
227# if defined ADJUST_STFLUX && defined SOLVE3D
228 real(r8), intent(inout) :: ad_tflux(LBi:,LBj:,:,:,:)
229# endif
230# ifdef SOLVE3D
231 real(r8), intent(inout) :: ad_t(LBi:,LBj:,:,:,:)
232 real(r8), intent(inout) :: ad_u(LBi:,LBj:,:,:)
233 real(r8), intent(inout) :: ad_v(LBi:,LBj:,:,:)
234# else
235 real(r8), intent(inout) :: ad_ubar(LBi:,LBj:,:)
236 real(r8), intent(inout) :: ad_vbar(LBi:,LBj:,:)
237# endif
238 real(r8), intent(inout) :: ad_zeta(LBi:,LBj:,:)
239# ifdef ADJUST_BOUNDARY
240# ifdef SOLVE3D
241 real(r8), intent(inout) :: tl_t_obc(LBij:,:,:,:,:,:)
242 real(r8), intent(inout) :: tl_u_obc(LBij:,:,:,:,:)
243 real(r8), intent(inout) :: tl_v_obc(LBij:,:,:,:,:)
244# endif
245 real(r8), intent(inout) :: tl_ubar_obc(LBij:,:,:,:)
246 real(r8), intent(inout) :: tl_vbar_obc(LBij:,:,:,:)
247 real(r8), intent(inout) :: tl_zeta_obc(LBij:,:,:,:)
248# endif
249# ifdef ADJUST_WSTRESS
250 real(r8), intent(inout) :: tl_ustr(LBi:,LBj:,:,:)
251 real(r8), intent(inout) :: tl_vstr(LBi:,LBj:,:,:)
252# endif
253# if defined ADJUST_STFLUX && defined SOLVE3D
254 real(r8), intent(inout) :: tl_tflux(LBi:,LBj:,:,:,:)
255# endif
256# ifdef SOLVE3D
257 real(r8), intent(inout) :: tl_t(LBi:,LBj:,:,:,:)
258 real(r8), intent(inout) :: tl_u(LBi:,LBj:,:,:)
259 real(r8), intent(inout) :: tl_v(LBi:,LBj:,:,:)
260# else
261 real(r8), intent(inout) :: tl_ubar(LBi:,LBj:,:)
262 real(r8), intent(inout) :: tl_vbar(LBi:,LBj:,:)
263# endif
264 real(r8), intent(inout) :: tl_zeta(LBi:,LBj:,:)
265# else
266# ifdef MASKING
267 real(r8), intent(in) :: rmask(LBi:UBi,LBj:UBj)
268 real(r8), intent(in) :: umask(LBi:UBi,LBj:UBj)
269 real(r8), intent(in) :: vmask(LBi:UBi,LBj:UBj)
270# endif
271# ifdef ADJUST_BOUNDARY
272# ifdef SOLVE3D
273 real(r8), intent(inout) :: ad_t_obc(LBij:UBij,N(ng),4, &
274 & Nbrec(ng),2,NT(ng))
275 real(r8), intent(inout) :: ad_u_obc(LBij:UBij,N(ng),4,Nbrec(ng),2)
276 real(r8), intent(inout) :: ad_v_obc(LBij:UBij,N(ng),4,Nbrec(ng),2)
277# endif
278 real(r8), intent(inout) :: ad_ubar_obc(LBij:UBij,4,Nbrec(ng),2)
279 real(r8), intent(inout) :: ad_vbar_obc(LBij:UBij,4,Nbrec(ng),2)
280 real(r8), intent(inout) :: ad_zeta_obc(LBij:UBij,4,Nbrec(ng),2)
281# endif
282# ifdef ADJUST_WSTRESS
283 real(r8), intent(inout) :: ad_ustr(LBi:UBi,LBj:UBj,Nfrec(ng),2)
284 real(r8), intent(inout) :: ad_vstr(LBi:UBi,LBj:UBj,Nfrec(ng),2)
285# endif
286# if defined ADJUST_STFLUX && defined SOLVE3D
287 real(r8), intent(inout) :: ad_tflux(LBi:UBi,LBj:UBj, &
288 & Nfrec(ng),2,NT(ng))
289# endif
290# ifdef SOLVE3D
291 real(r8), intent(inout) :: ad_t(LBi:UBi,LBj:UBj,N(ng),3,NT(ng))
292 real(r8), intent(inout) :: ad_u(LBi:UBi,LBj:UBj,N(ng),2)
293 real(r8), intent(inout) :: ad_v(LBi:UBi,LBj:UBj,N(ng),2)
294# else
295 real(r8), intent(inout) :: ad_ubar(LBi:UBi,LBj:UBj,:)
296 real(r8), intent(inout) :: ad_vbar(LBi:UBi,LBj:UBj,:)
297# endif
298 real(r8), intent(inout) :: ad_zeta(LBi:UBi,LBj:UBj,:)
299# ifdef ADJUST_BOUNDARY
300# ifdef SOLVE3D
301 real(r8), intent(inout) :: tl_t_obc(LBij:UBij,N(ng),4, &
302 & Nbrec(ng),2,NT(ng))
303 real(r8), intent(inout) :: tl_u_obc(LBij:UBij,N(ng),4,Nbrec(ng),2)
304 real(r8), intent(inout) :: tl_v_obc(LBij:UBij,N(ng),4,Nbrec(ng),2)
305# endif
306 real(r8), intent(inout) :: tl_ubar_obc(LBij:UBij,4,Nbrec(ng),2)
307 real(r8), intent(inout) :: tl_vbar_obc(LBij:UBij,4,Nbrec(ng),2)
308 real(r8), intent(inout) :: tl_zeta_obc(LBij:UBij,4,Nbrec(ng),2)
309# endif
310# ifdef ADJUST_WSTRESS
311 real(r8), intent(inout) :: tl_ustr(LBi:UBi,LBj:UBj,Nfrec(ng),2)
312 real(r8), intent(inout) :: tl_vstr(LBi:UBi,LBj:UBj,Nfrec(ng),2)
313# endif
314# if defined ADJUST_STFLUX && defined SOLVE3D
315 real(r8), intent(inout) :: tl_tflux(LBi:UBi,LBj:UBj, &
316 & Nfrec(ng),2,NT(ng))
317# endif
318# ifdef SOLVE3D
319 real(r8), intent(inout) :: tl_t(LBi:UBi,LBj:UBj,N(ng),3,NT(ng))
320 real(r8), intent(inout) :: tl_u(LBi:UBi,LBj:UBj,N(ng),2)
321 real(r8), intent(inout) :: tl_v(LBi:UBi,LBj:UBj,N(ng),2)
322# else
323 real(r8), intent(inout) :: tl_ubar(LBi:UBi,LBj:UBj,:)
324 real(r8), intent(inout) :: tl_vbar(LBi:UBi,LBj:UBj,:)
325# endif
326 real(r8), intent(inout) :: tl_zeta(LBi:UBi,LBj:UBj,:)
327# endif
328
329
330
331 integer :: Lwrk, i, j, lstr, ndefLCZ, outLoop, rec
332# ifdef SOLVE3D
333 integer :: itrc, k
334# endif
335
336 real(r8) :: fac, fac1, fac2
337 real(r8) :: zbeta
338
339 real(r8), dimension(0:NstateVar(ng)) :: dot
340 real(r8), dimension(Ninner) :: DotProd
341 real(r8), dimension(Ninner) :: bvector
342 real(r8), dimension(Ninner) :: zgamma
343
344 character (len=256) :: ncname
345
346 character (len=*), parameter :: MyFile = &
347 & __FILE__//", ini_lanczos_tile"
348
349# include "set_bounds.h"
350
351 calledfrom=myfile
352 sourcefile=myfile
353
354
355
356
357
358
359
360
361 SELECT CASE (lcz(ng)%IOtype)
362 CASE (io_nf90)
363 CALL netcdf_get_ivar (ng, iadm, trim(lcz(ng)%name), &
364 & 'ndefADJ', ndeflcz)
365
366# if defined PIO_LIB && defined DISTRIBUTE
367 CASE (io_pio)
368 CALL pio_netcdf_get_ivar (ng, iadm, trim(lcz(ng)%name), &
369 & 'ndefADJ', ndeflcz)
370# endif
371 END SELECT
372 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
373
374 lwrk=1
375 DO inner=1,ninner
376
377
378
379
380
381
382
383
384 IF (ndeflcz.gt.0) THEN
385 lstr=len_trim(lcz(ng)%name)
386 WRITE (ncname,10) lcz(ng)%name(1:lstr-8), inner
387 10 FORMAT (a,'_',i4.4,'.nc')
388 ELSE
389 ncname=lcz(ng)%name
390 END IF
391
392
393
394
395
396 CALL state_read (ng, tile, itlm, lcz(ng)%IOtype, &
397 & lbi, ubi, lbj, ubj, lbij, ubij, &
398 & lwrk, inner, &
399 & ndeflcz, lcz(ng)%ncid, &
400# if defined PIO_LIB && defined DISTRIBUTE
401 & lcz(ng)%pioFile, &
402# endif
403 & trim(ncname), &
404# ifdef MASKING
405 & rmask, umask, vmask, &
406# endif
407# ifdef ADJUST_BOUNDARY
408# ifdef SOLVE3D
409 & tl_t_obc, tl_u_obc, tl_v_obc, &
410# endif
411 & tl_ubar_obc, tl_vbar_obc, &
412 & tl_zeta_obc, &
413# endif
414# ifdef ADJUST_WSTRESS
415 & tl_ustr, tl_vstr, &
416# endif
417# if defined ADJUST_STFLUX && defined SOLVE3D
418 & tl_tflux, &
419# endif
420# ifdef SOLVE3D
421 & tl_t, tl_u, tl_v, &
422# else
423 & tl_ubar, tl_vbar, &
424# endif
425 & tl_zeta)
426 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
427
428
429
430
431
432
433
434 CALL state_dotprod (ng, tile, itlm, &
435 & lbi, ubi, lbj, ubj, lbij, ubij, &
436 & nstatevar(ng), dot(0:), &
437# ifdef MASKING
438 & rmask, umask, vmask, &
439# endif
440# ifdef ADJUST_BOUNDARY
441# ifdef SOLVE3D
442 & ad_t_obc(:,:,:,:,ladj,:), &
443 & tl_t_obc(:,:,:,:,lwrk,:), &
444 & ad_u_obc(:,:,:,:,ladj), &
445 & tl_u_obc(:,:,:,:,lwrk), &
446 & ad_v_obc(:,:,:,:,ladj), &
447 & tl_v_obc(:,:,:,:,lwrk), &
448# endif
449 & ad_ubar_obc(:,:,:,ladj), &
450 & tl_ubar_obc(:,:,:,lwrk), &
451 & ad_vbar_obc(:,:,:,ladj), &
452 & tl_vbar_obc(:,:,:,lwrk), &
453 & ad_zeta_obc(:,:,:,ladj), &
454 & tl_zeta_obc(:,:,:,lwrk), &
455# endif
456# ifdef ADJUST_WSTRESS
457 & ad_ustr(:,:,:,ladj), tl_ustr(:,:,:,lwrk), &
458 & ad_vstr(:,:,:,ladj), tl_vstr(:,:,:,lwrk), &
459# endif
460# if defined ADJUST_STFLUX && defined SOLVE3D
461 & ad_tflux(:,:,:,ladj,:), &
462 & tl_tflux(:,:,:,lwrk,:), &
463# endif
464# ifdef SOLVE3D
465 & ad_t(:,:,:,ladj,:), tl_t(:,:,:,lwrk,:), &
466 & ad_u(:,:,:,ladj), tl_u(:,:,:,lwrk), &
467 & ad_v(:,:,:,ladj), tl_v(:,:,:,lwrk), &
468# else
469 & ad_ubar(:,:,ladj), tl_ubar(:,:,lwrk), &
470 & ad_vbar(:,:,ladj), tl_vbar(:,:,lwrk), &
471# endif
472 & ad_zeta(:,:,ladj), tl_zeta(:,:,lwrk))
473
474
475
476 dotprod(inner)=dot(0)
477 END DO
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493 outloop=1
494
495
496
497 zbeta=cg_delta(1,outloop)
498 bvector(1)=dotprod(1)/zbeta
499 DO i=2,ninner
500 zgamma(i)=cg_beta(i,outloop)/zbeta
501 zbeta=cg_delta(i,outloop)-cg_beta(i,outloop)*zgamma(i)
502 bvector(i)=(dotprod(i)-cg_beta(i,outloop)*bvector(i-1))/zbeta
503 END DO
504
505
506
507 DO i=ninner-1,1,-1
508 bvector(i)=bvector(i)-zgamma(i+1)*bvector(i+1)
509 END DO
510
511
512
513
514
515
516
517 fac=0.0_r8
518
519 CALL state_initialize (ng, tile, &
520 & lbi, ubi, lbj, ubj, lbij, ubij, &
521 & lini, fac, &
522# ifdef MASKING
523 & rmask, umask, vmask, &
524# endif
525# ifdef ADJUST_BOUNDARY
526# ifdef SOLVE3D
527 & tl_t_obc, tl_u_obc, tl_v_obc, &
528# endif
529 & tl_ubar_obc, tl_vbar_obc, &
530 & tl_zeta_obc, &
531# endif
532# ifdef ADJUST_WSTRESS
533 & tl_ustr, tl_vstr, &
534# endif
535# if defined ADJUST_STFLUX && defined SOLVE3D
536 & tl_tflux, &
537# endif
538# ifdef SOLVE3D
539 & tl_t, tl_u, tl_v, &
540# else
541 & tl_ubar, tl_vbar, &
542# endif
543 & tl_zeta)
544
545
546
547
548
549 IF (ladj.eq.3) THEN
550 lwrk=1
551 ELSE
552 lwrk=3-ladj
553 END IF
554 DO inner=1,ninner
555 IF (ndeflcz.gt.0) THEN
556 lstr=len_trim(lcz(ng)%name)
557 WRITE (ncname,10) lcz(ng)%name(1:lstr-8), inner
558 ELSE
559 ncname=lcz(ng)%name
560 END IF
561 CALL state_read (ng, tile, itlm, lcz(ng)%IOtype, &
562 & lbi, ubi, lbj, ubj, lbij, ubij, &
563 & lwrk, inner, &
564 & ndeflcz, lcz(ng)%ncid, &
565# if defined PIO_LIB && defined DISTRIBUTE
566 & lcz(ng)%pioFile, &
567# endif
568 & ncname, &
569# ifdef MASKING
570 & rmask, umask, vmask, &
571# endif
572# ifdef ADJUST_BOUNDARY
573# ifdef SOLVE3D
574 & ad_t_obc, ad_u_obc, ad_v_obc, &
575# endif
576 & ad_ubar_obc, ad_vbar_obc, &
577 & ad_zeta_obc, &
578# endif
579# ifdef ADJUST_WSTRESS
580 & ad_ustr, ad_vstr, &
581# endif
582# if defined ADJUST_STFLUX && defined SOLVE3D
583 & ad_tflux, &
584# endif
585# ifdef SOLVE3D
586 & ad_t, ad_u, ad_v, &
587# else
588 & ad_ubar, ad_vbar, &
589# endif
590 & ad_zeta)
591 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
592
593
594
595
596
597
598
599
600 fac1=1.0_r8
601 fac2=bvector(inner)
602
603 CALL state_addition (ng, tile, &
604 & lbi, ubi, lbj, ubj, lbij, ubij, &
605 & lini, lwrk, lini, fac1, fac2, &
606# ifdef MASKING
607 & rmask, umask, vmask, &
608# endif
609# ifdef ADJUST_BOUNDARY
610# ifdef SOLVE3D
611 & tl_t_obc, ad_t_obc, &
612 & tl_u_obc, ad_u_obc, &
613 & tl_v_obc, ad_v_obc, &
614# endif
615 & tl_ubar_obc, ad_ubar_obc, &
616 & tl_vbar_obc, ad_vbar_obc, &
617 & tl_zeta_obc, ad_zeta_obc, &
618# endif
619# ifdef ADJUST_WSTRESS
620 & tl_ustr, ad_ustr, &
621 & tl_vstr, ad_vstr, &
622# endif
623# if defined ADJUST_STFLUX && defined SOLVE3D
624 & tl_tflux, ad_tflux, &
625# endif
626# ifdef SOLVE3D
627 & tl_t, ad_t, &
628 & tl_u, ad_u, &
629 & tl_v, ad_v, &
630# else
631 & tl_ubar, ad_ubar, &
632 & tl_vbar, ad_vbar, &
633# endif
634 & tl_zeta, ad_zeta)
635 END DO
636
637 RETURN