My Project
ice_flux_in.f90
Go to the documentation of this file.
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 !/===========================================================================/
13 ! CVS VERSION INFORMATION
14 ! $Id$
15 ! $Name$
16 ! $Revision$
17 !/===========================================================================/
18 
19 !c=======================================================================
20 !
21 !BOP
22 !
23 ! !MODULE: ice_flux_in - reads and interpolates input forcing data
24 !
25 ! !DESCRIPTION:
26 !
27 ! Reads and interpolates forcing data for atmospheric and oceanic quantities.
28 !
29 ! !REVISION HISTORY:
30 !
31 ! authors Elizabeth C. Hunke, LANL
32 ! William H. Lipscomb, LANL
33 !
34 ! !INTERFACE:
35 !
36  module ice_flux_in
37 !
38 ! !USES:
39 !
40  use ice_kinds_mod
41  use ice_domain
42  use ice_constants
43  use ice_flux
44  use ice_calendar
45 ! use ice_read_write
46  use ice_fileunits
47  USE control, ONLY : ice_longwave_type
48 !
49 !EOP
50 !
51  implicit none
52  save
53 
54  integer (kind=int_kind) :: &
55  ycycle & ! number of years in forcing cycle
56  , fyear_init & ! first year of data in forcing cycle
57  , fyear_final & ! last year in cycle
58  , fyear ! current year in forcing cycle
59 
60 ! real (kind=dbl_kind), dimension(ilo:ihi,jlo:jhi) :: &
61  real (kind=dbl_kind), dimension(:,:),allocatable,save:: &
62  cldf ! cloud fraction
63 
64  character (char_len_long) :: & ! input data file names
65  height_file &
66  , uwind_file &
67  , vwind_file &
68  , pott_file &
69  , tair_file &
70  , humid_file &
71  , rhoa_file &
72  , fsw_file &
73  , flw_file &
74  , rain_file &
75  , sst_file &
76  , sss_file
77 
78  real (kind=dbl_kind) :: &
79  c1intp, c2intp & ! interpolation coefficients
80  , ftime ! forcing time (for restart)
81 
82  integer (kind=int_kind) :: &
83  oldrecnum = 0 ! old record number (save between steps)
84 
85 ! real (kind=dbl_kind), dimension(ilo:ihi,jlo:jhi,2) :: &
86  real (kind=dbl_kind), dimension(:,:,:),allocatable,save :: &
87  fsw_data & ! field values at 2 temporal data points
88  , cldf_data &
89  , fsnow_data &
90  , tair_data &
91  , uatm_data &
92  , vatm_data &
93  , qa_data &
94  , rhoa_data &
95  , pott_data &
96  , zlvl_data &
97  , flw_data &
98  , sst_data &
99  , sss_data
100 
101  character (char_len) :: &
102  atm_data_type & ! 'default', 'ncar' or 'LYq'
103  , sss_data_type & ! 'default', 'clim' or 'ncar'
104  , sst_data_type & ! 'default', 'clim' or 'ncar'
105  , precip_units ! 'mm_per_month', 'mm_per_sec', 'mks'
106 
107  character(char_len_long) :: &
108  atm_data_dir &! top directory for atmospheric data
109  , ocn_data_dir &! top directory for ocean data
110  , oceanmixed_file ! netCDF file name for ocean forcing data
111 
112  integer (kind=int_kind), parameter :: &
113  nfld = 8 ! number of fields to search for in netCDF file
114 
115 ! real (kind=dbl_kind) :: &
116 ! ocn_frc_m(ilo:ihi,jlo:jhi,nfld,12) ! ocn data for 12 months
117 
118  logical (kind=log_kind) :: &
119  restore_sst ! restore sst if true
120 
121  integer (kind=int_kind) :: &
122  trestore ! restoring time scale (days)
123 
124  real (kind=dbl_kind) :: &
125  trest ! restoring time scale (sec)
126 
127  logical (kind=log_kind) :: &
128  dbug ! prints debugging output if true
129 
130 !c=======================================================================
131 
132  contains
133 
134 !c=======================================================================
135 !
136 !BOP
137 !
138 ! !IROUTINE: init_getflux - initialize input forcing files
139 !
140 ! !INTERFACE:
141 !
142  subroutine init_getflux
143 !
144 ! !DESCRIPTION:
145 !
146 ! Determines the current and final years of the forcing cycle based on
147 ! namelist input, initializes the forcing data filenames, and initializes
148 ! surface temperature and salinity from data.
149 !
150 ! !REVISION HISTORY:
151 !
152 ! authors Elizabeth C. Hunke, LANL
153 !
154 ! !USES:
155 !
156 ! use ice_history, only: restart
157 ! use ice_therm_vertical, only: ustar_scale
158 !
159 ! !INPUT/OUTPUT PARAMETERS:
160 !
161 !EOP
162 !
163 ! fyear_final = fyear_init + ycycle - 1 ! last year in forcing cycle
164 ! fyear = fyear_init + mod(nyr-1,ycycle) ! current year
165 
166 ! if (trim(atm_data_type) /= 'default' .and. &
167 ! my_task == master_task) then
168 ! write (nu_diag,*) ' Initial forcing data year = ',fyear_init
169 ! write (nu_diag,*) ' Final forcing data year = ',fyear_final
170 ! endif
171 
172 ! if (restore_sst) then
173 ! if (trestore == 0) then
174 !! trest = dt ! use data instantaneously
175 ! trest = dtice ! use data instantaneously
176 ! else
177 ! trest = real(trestore,kind=dbl_kind) * secday ! seconds
178 ! endif
179 ! endif
180 
181  ! default forcing values from init_flux_atm
182 ! if (trim(atm_data_type) == 'ncar') then
183 ! call NCAR_files(fyear) ! data for individual years
184 ! elseif (trim(atm_data_type) == 'LYq') then
185 ! call LY_files(fyear) ! data for individual years
186 ! endif
187 
188  ! default forcing values from init_flux_ocn
189 ! if (trim(sss_data_type) == 'clim') then
190 ! call sss_clim ! climatology (12-month avg)
191 ! endif
192 ! if (trim(sst_data_type) == 'clim' .and. .not. (restart)) then
193 ! call sst_ic ! not interpolated but depends on sss
194 ! endif
195 ! if (trim(sst_data_type) == 'ncar' .or. &
196 ! trim(sss_data_type) == 'ncar') then
197 ! call getflux_ocn_ncar_init
198 ! endif
199 
200 ! default ustar_scale = c1i (for nonzero currents) set in init_thermo_vertical
201 ! if (trim(sst_data_type) /= 'ncar' .or. &
202 ! trim(sss_data_type) /= 'ncar') then
203 ! ustar_scale = c10i ! for zero currents
204 ! endif
205 
206  end subroutine init_getflux
207 
208 !c=======================================================================
209 !
210 !BOP
211 !
212 ! !IROUTINE: getflux - Get forcing data and interpolate as necessary
213 !
214 ! !INTERFACE:
215 !
216  subroutine getflux
217 !
218 ! !DESCRIPTION:
219 !
220 ! Get forcing data and interpolate as necessary!
221 !
222 ! !REVISION HISTORY:
223 !
224 ! authors: Elizabeth C. Hunke, LANL
225 !
226 ! !USES:
227 !
228 ! !INPUT/OUTPUT PARAMETERS:
229 !
230 !EOP
231 
232 !
233 ! fyear = fyear_init + mod(nyr-1,ycycle) ! current year
234 ! if (trim(atm_data_type) /= 'default' .and. istep <= 1 &
235 ! .and. my_task == master_task) then
236 ! write (nu_diag,*) ' Current forcing data year = ',fyear
237 ! endif
238 
239 ! ftime = time ! forcing time
240 ! time_forc = ftime ! for restarting
241 
242  !-------------------------------------------------------------------
243  ! Read and interpolate annual climatologies of SSS and SST.
244  ! Restore model SST to data.
245  ! Interpolate ocean fields to U grid.
246  !-------------------------------------------------------------------
247 
248 ! if (trim(sst_data_type) == 'clim' .or. &
249 ! trim(sss_data_type) == 'clim') then
250 ! call getflux_ocn_clim
251 ! elseif (trim(sst_data_type) == 'ncar' .or.&
252 ! trim(sss_data_type) == 'ncar') then
253 ! call getflux_ocn_ncar
254 ! endif
255 
256  !-------------------------------------------------------------------
257  ! Read and interpolate atmospheric data
258  !-------------------------------------------------------------------
259 
260 ! if (trim(atm_data_type) == 'ncar') then
261 ! call NCAR_bulk_data
262 ! elseif (trim(atm_data_type) == 'LYq') then
263 ! call LY_bulk_data
264 ! else ! default values set in init_flux*
265 ! endif
266 
267 ! call prepare_forcing
268 
269  end subroutine getflux
270 
271 !c=======================================================================
272 !
273 !BOP
274 !
275 ! !IROUTINE: read_data - Read data needed for interpolation
276 !
277 ! !INTERFACE:
278 !
279 ! subroutine read_data (flag, recd, yr, imx, ixx, ipx, &
280 ! maxrec, data_file, field_data)
281 !
282 ! !DESCRIPTION:
283 !
284 ! If data is at the beginning of a one-year record, get data from
285 ! the previous year.
286 ! If data is at the end of a one-year record, get data from the
287 ! following year.
288 ! If no earlier data exists (beginning of fyear\_init), then \! (1) For monthly data, get data from the end of fyear\_final. \! (2) For more frequent data, let the imx value equal the
289 ! first value of the year. \! If no later data exists (end of fyear\_final), then \! (1) For monthly data, get data from the beginning of fyear\_init. \! (2) For more frequent data, let the ipx
290 ! value equal the last value of the year. \! In other words, we assume persistence when daily or 6-hourly
291 ! data is missing, and we assume periodicity when monthly data
292 ! is missing. \!
293 ! !REVISION HISTORY:
294 !
295 ! authors: same as module
296 !
297 ! !USES:
298 !
299 ! use ice_diagnostics
300 !
301 ! !INPUT/OUTPUT PARAMETERS:
302 !
303 ! logical (kind=log_kind), intent(in) :: flag
304 !
305 ! integer (kind=int_kind), intent(in) :: &
306 ! recd &! baseline record number
307 ! , yr &! year of forcing data
308 ! , imx, ixx, ipx &! record numbers of 3 data values
309 ! ! relative to recd
310 ! , maxrec ! maximum record value
311 !
312 ! real (kind=dbl_kind), dimension(ilo:ihi,jlo:jhi,2), intent(out) :: &
313 ! field_data ! 2 values needed for interpolation
314 !!
315 !!EOP
316 !!
317 ! character (char_len_long) :: &
318 ! data_file ! data file to be read
319 !
320 ! integer (kind=int_kind) :: &
321 ! nbits & ! = 32 for single precision, 64 for double
322 ! , nrec & ! record number to read
323 ! , n2, n4 & ! like imx and ipx, but
324 ! ! adjusted at beginning and end of data
325 ! , arg ! value of time argument in field_data
326 
327 ! nbits = 64 ! double precision data
328 
329 ! if (istep1 > check_step) dbug = .true. !! debugging
330 ! if (my_task==master_task .and. (dbug)) &
331 ! write(nu_diag,*) ' ',data_file
332 
333 ! if (flag) then
334  !-----------------------------------------------------------------
335  ! Initialize record counters
336  ! (n2, n4 will change only at the very beginning or end of
337  ! a forcing cycle.)
338  !-----------------------------------------------------------------
339 ! n2 = imx
340 ! n4 = ipx
341 ! arg = 0
342 
343  !-----------------------------------------------------------------
344  ! read data
345  !-----------------------------------------------------------------
346 
347 ! if (imx /= 99) then
348 ! ! currently in first half of data interval
349 ! if (ixx<=1) then
350 ! if (yr > fyear_init) then ! get data from previous year
351 ! call file_year (data_file, yr-1)
352 ! else ! yr = fyear_init, no prior data exists
353 ! if (maxrec > 12) then ! extrapolate from first record
354 ! if (ixx==1) n2 = ixx
355 ! else ! go to end of fyear_final
356 ! call file_year (data_file, fyear_final)
357 ! endif
358 ! endif ! yr > fyear_init
359 ! endif ! ixx <= 1
360 ! call ice_open (nu_forcing, data_file, nbits)
361 
362 ! arg = 1
363 ! nrec = recd + n2
364 ! call ice_read (nu_forcing, nrec, field_data(:,:,arg), &
365 ! 'rda8', dbug)
366 !
367 ! if (ixx==1 .and. my_task==master_task) close(nu_forcing)
368 ! endif ! imx ne 99
369 
370 ! ! always read ixx data from data file for current year
371 ! call file_year (data_file, yr)
372 ! call ice_open (nu_forcing, data_file, nbits)
373 
374 ! arg = arg + 1
375 ! nrec = recd + ixx
376 ! call ice_read (nu_forcing, nrec, field_data(:,:,arg), &
377 ! 'rda8', dbug)
378 
379 ! if (ipx /= 99) then
380 ! ! currently in latter half of data interval
381 ! if (ixx==maxrec) then
382 ! if (yr < fyear_final) then ! get data from following year
383 ! if (my_task == master_task) close(nu_forcing)
384 ! call file_year (data_file, yr+1)
385 ! call ice_open (nu_forcing, data_file, nbits)
386 ! else ! yr = fyear_final, no more data exists
387 ! if (maxrec > 12) then ! extrapolate from ixx
388 ! n4 = ixx
389 ! else ! go to beginning of fyear_init
390 ! if (my_task == master_task) close(nu_forcing)
391 ! call file_year (data_file, fyear_init)
392 ! call ice_open (nu_forcing, data_file, nbits)
393 ! endif
394 ! endif ! yr < fyear_final
395 ! endif ! ixx = maxrec
396 
397 ! arg = arg + 1
398 ! nrec = recd + n4
399 ! call ice_read (nu_forcing, nrec, field_data(:,:,arg),&
400 ! 'rda8', dbug)
401 ! endif ! ipx ne 99
402 
403 ! if (my_task == master_task) close(nu_forcing)
404 ! endif ! flag
405 
406 ! end subroutine read_data
407 
408 !c=======================================================================
409 !
410 !BOP
411 !
412 ! !IROUTINE: read_clim_data - read annual climatological data
413 !
414 ! !INTERFACE:
415 !
416 ! subroutine read_clim_data (readflag, recd, imx, ixx, ipx,&
417 ! data_file, field_data)
418 !
419 ! !DESCRIPTION:
420 !
421 ! Read data needed for interpolation, as in read\_data.
422 ! Assume a one-year cycle of climatological data, so that there is
423 ! no need to get data from other years or to extrapolate data beyond
424 ! the forcing time period.
425 !
426 ! !REVISION HISTORY:
427 !
428 ! authors: same as module
429 !
430 ! !USES:
431 !
432 ! use ice_diagnostics !! debugging
433 !
434 ! !INPUT/OUTPUT PARAMETERS:
435 !!
436 ! logical (kind=log_kind),intent(in) :: readflag
437 !
438 ! integer (kind=int_kind), intent(in) :: &
439 ! recd & ! baseline record number
440 ! , imx,ixx,ipx ! record numbers of 3 data values
441 ! ! relative to recd
442 !
443 ! character (char_len_long), intent(in) :: data_file
444 !
445 ! real (kind=dbl_kind), dimension(ilo:ihi,jlo:jhi,2), intent(out) :: &
446 ! field_data ! 2 values needed for interpolation
447 !!
448 !!EOP
449 !!
450 ! integer (kind=int_kind) :: &
451 ! nbits & ! = 32 for single precision, 64 for double
452 ! , nrec & ! record number to read
453 ! , arg ! value of time argument in field_data
454 !
455 ! nbits = 64 ! double precision data
456 
457 ! if (istep1 > check_step) dbug = .true. !! debugging
458 
459 ! if (my_task==master_task .and. (dbug)) &
460 ! write(nu_diag,*) ' ', trim(data_file)
461 
462 ! if (readflag) then
463  !-----------------------------------------------------------------
464  ! read data
465  !-----------------------------------------------------------------
466 
467 ! call ice_open (nu_forcing, data_file, nbits)
468 
469 ! arg = 0
470 ! if (imx /= 99) then
471 ! arg = 1
472 ! nrec = recd + imx
473 ! call ice_read (nu_forcing, nrec, field_data(:,:,arg), &
474 ! 'rda8', dbug)
475 ! endif
476 
477 ! arg = arg + 1
478 ! nrec = recd + ixx
479 ! call ice_read (nu_forcing, nrec, field_data(:,:,arg), &
480 ! 'rda8', dbug)
481 
482 ! if (ipx /= 99) then
483 ! arg = arg + 1
484 ! nrec = recd + ipx
485 ! call ice_read (nu_forcing, nrec, field_data(:,:,arg), &
486 ! 'rda8', dbug)
487 ! endif
488 
489 ! if (my_task == master_task) close (nu_forcing)
490 ! endif ! readflag
491 
492 ! end subroutine read_clim_data
493 
494 !c=======================================================================
495 !
496 !BOP
497 !
498 ! !IROUTINE: interp_coeff_monthly - Compute monthly data interpolation coefficients
499 !
500 ! !INTERFACE:
501 !
502  subroutine interp_coeff_monthly (recslot)
503 !
504 ! !DESCRIPTION:
505 !
506 ! Compute coefficients for interpolating monthly data to current time step.
507 !
508 ! !REVISION HISTORY:
509 !
510 ! authors: same as module
511 !
512 ! !USES:
513 !
514 ! !INPUT/OUTPUT PARAMETERS:
515 !
516  integer (kind=int_kind), intent(in) :: &
517  recslot ! slot (1 or 2) for current record
518 !
519 !EOP
520 !
521  real (kind=dbl_kind) :: &
522  tt & ! seconds elapsed in current year
523  , t1, t2 ! seconds elapsed at month midpoint
524 
525  real (kind=dbl_kind) :: &
526  daymid(0:13) ! month mid-points
527 
528  daymid(1:13) = 14._dbl_kind ! time frame ends 0 sec into day 15
529  daymid(0) = -17._dbl_kind ! Dec 15, 0 sec
530 
531  ! make time cyclic
532  tt = mod(ftime/secday,c365)
533 
534  ! Find neighboring times
535 
536  if (recslot==2) then ! first half of month
537  t2 = daycal(month) + daymid(month) ! midpoint, current month
538  if (month == 1) then
539  t1 = daymid(0) ! Dec 15 (0 sec)
540  else
541  t1 = daycal(month-1) + daymid(month-1) ! midpoint, previous month
542  endif
543  else ! second half of month
544  t1 = daycal(month) + daymid(month) ! midpoint, current month
545  t2 = daycal(month+1) + daymid(month+1)! day 15 of next month (0 sec)
546  endif
547 
548  ! Compute coefficients
549  c1intp = (t2 - tt) / (t2 - t1)
550  c2intp = c1i - c1intp
551 
552  end subroutine interp_coeff_monthly
553 
554 !c=======================================================================
555 !
556 !BOP
557 !
558 ! !IROUTINE: interp_coeff
559 !
560 ! !INTERFACE:
561 !
562  subroutine interp_coeff (recnum, recslot, secint)
563 !
564 ! !DESCRIPTION:
565 !
566 ! Compute coefficients for interpolating data to current time step.
567 ! Works for any data interval that divides evenly into a 365-day
568 ! year (daily, 6-hourly, etc.)
569 ! Use interp\_coef\_monthly for monthly data.
570 !
571 ! !REVISION HISTORY:
572 !
573 ! authors: same as module
574 !
575 ! !USES:
576 !
577  integer (kind=int_kind), intent(in) :: &
578  recnum & ! record number for current data value
579  , recslot ! spline slot for current record
580 
581  real (kind=dbl_kind), intent(in) :: &
582  secint ! seconds in data interval
583 !
584 ! !INPUT/OUTPUT PARAMETERS:
585 !
586 !EOP
587 !
588  real (kind=dbl_kind), parameter :: &
589  secyr = c365 * secday ! seconds in a 365-day year
590 
591  real (kind=dbl_kind) :: &
592  tt & ! seconds elapsed in current year
593  , t1, t2 ! seconds elapsed at data points
594 
595 ! tt = mod(ftime,secyr)
596 
597  ! Find neighboring times
598 ! if (recslot==2) then ! current record goes in slot 2 (NCEP)
599 ! t2 = real(recnum,kind=dbl_kind)*secint
600 ! t1 = t2 - secint ! - 1 interval
601 ! else ! recslot = 1
602 ! t1 = real(recnum,kind=dbl_kind)*secint
603 ! t2 = t1 + secint ! + 1 interval
604 ! endif
605 
606  ! Compute coefficients
607 ! c1intp = abs((t2 - tt) / (t2 - t1))
608 ! c2intp = c1i - c1intp
609 
610  end subroutine interp_coeff
611 
612 !c=======================================================================
613 !
614 !BOP
615 !
616 ! !IROUTINE: file_year -
617 !
618 ! !INTERFACE:
619 !
620  subroutine file_year (data_file, yr)
621 !
622 ! !DESCRIPTION:
623 !
624 ! Construct the correct name of the atmospheric data file
625 ! to be read, given the year and assuming the naming convention
626 ! that filenames end with 'yyyy.dat'.
627 !
628 ! !REVISION HISTORY:
629 !
630 ! authors Elizabeth C. Hunke, LANL
631 !
632 ! !USES:
633 !
634 !
635 ! !INPUT/OUTPUT PARAMETERS:
636 !
637  character (char_len_long), intent(inout) :: data_file
638 !
639 !EOP
640 !
641  integer (kind=int_kind), intent(in) :: yr
642 
643  character (char_len_long) :: tmpname
644 
645  integer (kind=int_kind) :: i
646 
647  i = index(data_file,'.dat') - 5
648  tmpname = data_file
649  write(data_file,'(a,i4.4,a)') tmpname(1:i), yr, '.dat'
650 
651  end subroutine file_year
652 
653 !c=======================================================================
654 !
655 !BOP
656 !
657 ! !IROUTINE: NCAR_files - construct filenames for NCAR_bulk atmospheric data
658 !
659 ! !INTERFACE:
660 !
661  subroutine ncar_files (yr)
662 !
663 ! !DESCRIPTION:
664 !
665 ! This subroutine is based on the LANL file naming conventions.
666 ! Edit for other directory structures or filenames.
667 ! Note: The year number in these filenames does not matter, because
668 ! subroutine file\_year will insert the correct year.
669 !
670 !
671 ! !REVISION HISTORY:
672 !
673 ! authors Elizabeth C. Hunke, LANL
674 !
675 ! !USES:
676 !
677 !
678 ! !INPUT/OUTPUT PARAMETERS:
679 !
680  integer (kind=int_kind), intent(in) :: &
681  yr ! current forcing year
682 !
683 !EOP
684 !
685  fsw_file = &
686  trim(atm_data_dir)//'ISCCPM/MONTHLY/RADFLX/swdn.1996.dat'
687  call file_year(fsw_file,yr)
688 
689  flw_file = &
690  trim(atm_data_dir)//'ISCCPM/MONTHLY/RADFLX/cldf.1996.dat'
691  call file_year(flw_file,yr)
692 
693  rain_file = &
694  trim(atm_data_dir)//'MXA/MONTHLY/PRECIP/prec.1996.dat'
695  call file_year(rain_file,yr)
696 
697  uwind_file = &
698  trim(atm_data_dir)//'NCEP/4XDAILY/STATES/u_10.1996.dat'
699  call file_year(uwind_file,yr)
700 
701  vwind_file = &
702  trim(atm_data_dir)//'NCEP/4XDAILY/STATES/v_10.1996.dat'
703  call file_year(vwind_file,yr)
704 
705  tair_file = &
706  trim(atm_data_dir)//'NCEP/4XDAILY/STATES/t_10.1996.dat'
707  call file_year(tair_file,yr)
708 
709  humid_file = &
710  trim(atm_data_dir)//'NCEP/4XDAILY/STATES/q_10.1996.dat'
711  call file_year(humid_file,yr)
712 
713  rhoa_file = &
714  trim(atm_data_dir)//'NCEP/4XDAILY/STATES/dn10.1996.dat'
715  call file_year(rhoa_file,yr)
716 
717  if (my_task == master_task) then
718  write (nu_diag,*) ''
719  write (nu_diag,*) 'Initial atmospheric data files:'
720  write (nu_diag,*) trim(fsw_file)
721  write (nu_diag,*) trim(flw_file)
722  write (nu_diag,*) trim(rain_file)
723  write (nu_diag,*) trim(uwind_file)
724  write (nu_diag,*) trim(vwind_file)
725  write (nu_diag,*) trim(tair_file)
726  write (nu_diag,*) trim(humid_file)
727  write (nu_diag,*) trim(rhoa_file)
728  endif ! master_task
729 
730  end subroutine ncar_files
731 
732 !c=======================================================================
733 !
734 !BOP
735 !
736 ! !IROUTINE: LY_files - construct filenames for LY atmospheric data
737 !
738 ! !INTERFACE:
739 !
740  subroutine ly_files (yr)
741 !
742 ! !DESCRIPTION:
743 !
744 ! This subroutine is based on the LANL file naming conventions.
745 ! Edit for other directory structures or filenames.
746 ! Note: The year number in these filenames does not matter, because
747 ! subroutine file\_year will insert the correct year.
748 !
749 !
750 ! !REVISION HISTORY:
751 !
752 ! authors Elizabeth C. Hunke, LANL
753 !
754 ! !USES:
755 !
756 !
757 ! !INPUT/OUTPUT PARAMETERS:
758 !
759  integer (kind=int_kind), intent(in) :: &
760  yr ! current forcing year
761 !
762 !EOP
763 !
764  flw_file = &
765  trim(atm_data_dir)//'MONTHLY/cldf.omip.dat'
766 
767  rain_file = &
768  trim(atm_data_dir)//'MONTHLY/prec.nmyr.dat'
769 
770  uwind_file = &
771  trim(atm_data_dir)//'4XDAILY/u_10.1996.dat'
772  call file_year(uwind_file,yr)
773 
774  vwind_file = &
775  trim(atm_data_dir)//'4XDAILY/v_10.1996.dat'
776  call file_year(vwind_file,yr)
777 
778  tair_file = &
779  trim(atm_data_dir)//'4XDAILY/t_10.1996.dat'
780  call file_year(tair_file,yr)
781 
782  humid_file = &
783  trim(atm_data_dir)//'4XDAILY/q_10.1996.dat'
784  call file_year(humid_file,yr)
785 
786  if (my_task == master_task) then
787  write (nu_diag,*) ''
788  write (nu_diag,*) 'Forcing data year = ', fyear
789  write (nu_diag,*) 'Atmospheric data files:'
790  write (nu_diag,*) trim(flw_file)
791  write (nu_diag,*) trim(rain_file)
792  write (nu_diag,*) trim(uwind_file)
793  write (nu_diag,*) trim(vwind_file)
794  write (nu_diag,*) trim(tair_file)
795  write (nu_diag,*) trim(humid_file)
796  endif ! master_task
797 
798  end subroutine ly_files
799 
800 !c=======================================================================
801 !
802 !BOP
803 !
804 ! !IROUTINE: NCAR_bulk_data - read NCAR_bulk atmospheric data
805 !
806 ! !INTERFACE:
807 !
808  subroutine ncar_bulk_data
809 !
810 ! !DESCRIPTION:
811 !
812 ! !REVISION HISTORY:
813 !
814 ! authors: same as module
815 !
816 ! !USES:
817 !
818 ! !INPUT/OUTPUT PARAMETERS:
819 !
820 !EOP
821 !
822  integer (kind=int_kind) ::&
823  i, j &
824  , imx,ixx,ipx &! record numbers for neighboring months
825  , recnum &! record number
826  , maxrec &! maximum record number
827  , recslot &! spline slot for current record
828  , midmonth ! middle day of month
829 
830  real (kind=dbl_kind) :: &
831  sec6hr ! number of seconds in 6 hours
832 
833  logical (kind=log_kind) :: readm, read6
834 
835  !-------------------------------------------------------------------
836  ! monthly data
837  !
838  ! Assume that monthly data values are located in the middle of the
839  ! month.
840  !-------------------------------------------------------------------
841 
842  midmonth = 15 ! data is given on 15th of every month
843 ! midmonth = fix(p5 * real(daymo(month),kind=dbl_kind)) ! exact middle
844 
845  ! Compute record numbers for surrounding months
846  maxrec = 12
847  imx = mod(month+maxrec-2,maxrec) + 1
848  ipx = mod(month, maxrec) + 1
849  if (mday >= midmonth) imx = 99 ! other two points will be used
850  if (mday < midmonth) ipx = 99
851 
852  ! Determine whether interpolation will use values 1:2 or 2:3
853  ! recslot = 2 means we use values 1:2, with the current value (2)
854  ! in the second slot
855  ! recslot = 1 means we use values 2:3, with the current value (2)
856  ! in the first slot
857  recslot = 1 ! latter half of month
858  if (mday < midmonth) recslot = 2 ! first half of month
859 
860  ! Find interpolation coefficients
861  call interp_coeff_monthly (recslot)
862 
863  ! Read 2 monthly values
864  readm = .false.
865  if (istep==1 .or. (mday==midmonth .and. sec==0)) readm = .true.
866 
867 ! call read_data (readm, 0, fyear, imx, month, ipx, &
868 ! maxrec, fsw_file, fsw_data)
869 ! call read_data (readm, 0, fyear, imx, month, ipx, &
870 ! maxrec, flw_file, cldf_data)
871 ! call read_data (readm, 0, fyear, imx, month, ipx, &
872 ! maxrec, rain_file, fsnow_data)
873 
874 ! call interpolate_data (fsw_data, fsw)
875 ! call interpolate_data (cldf_data, cldf)
876 ! call interpolate_data (fsnow_data, fsnow)
877 
878  !-------------------------------------------------------------------
879  ! 6-hourly data
880  !
881  ! Assume that the 6-hourly value is located at the end of the
882  ! 6-hour period. This is the convention for NCEP reanalysis data.
883  ! E.g. record 1 gives conditions at 6 am GMT on 1 January.
884  !-------------------------------------------------------------------
885 
886  sec6hr = secday/c4i ! seconds in 6 hours
887  maxrec = 1460 ! 365*4
888 
889  ! current record number
890  recnum = 4*int(yday) - 3 + int(real(sec,kind=dbl_kind)/sec6hr)
891 
892  ! Compute record numbers for surrounding data (2 on each side)
893 
894  imx = mod(recnum+maxrec-2,maxrec) + 1
895  ixx = mod(recnum-1, maxrec) + 1
896 ! ipx = mod(recnum, maxrec) + 1
897 
898  ! Compute interpolation coefficients
899  ! If data is located at the end of the time interval, then the
900  ! data value for the current record goes in slot 2
901 
902  recslot = 2
903  ipx = 99
904  call interp_coeff (recnum, recslot, sec6hr)
905 
906  ! Read
907  read6 = .false.
908  if (istep==1 .or. oldrecnum /= recnum) read6 = .true.
909 
910 ! call read_data (read6, 0, fyear, imx, ixx, ipx, maxrec, &
911 ! tair_file, Tair_data)
912 ! call read_data (read6, 0, fyear, imx, ixx, ipx, maxrec, &
913 ! uwind_file, uatm_data)
914 ! call read_data (read6, 0, fyear, imx, ixx, ipx, maxrec, &
915 ! vwind_file, vatm_data)
916 ! call read_data (read6, 0, fyear, imx, ixx, ipx, maxrec, &
917 ! rhoa_file, rhoa_data)
918 ! call read_data (read6, 0, fyear, imx, ixx, ipx, maxrec, &
919 ! humid_file, Qa_data)
920 
921  ! Interpolate
922 ! call interpolate_data (Tair_data, Tair)
923 ! call interpolate_data (uatm_data, uatm)
924 ! call interpolate_data (vatm_data, vatm)
925 ! call interpolate_data (rhoa_data, rhoa)
926 ! call interpolate_data (Qa_data, Qa)
927 
928  ! Save record number
929  oldrecnum = recnum
930 
931  end subroutine ncar_bulk_data
932 
933 !c=======================================================================
934 !
935 !BOP
936 !
937 ! !IROUTINE: LY_bulk_data - read LY atmospheric data
938 !
939 ! !INTERFACE:
940 !
941  subroutine ly_bulk_data
942 !
943 ! !DESCRIPTION:
944 !
945 ! !REVISION HISTORY:
946 !
947 ! authors: Elizabeth C. Hunke, LANL
948 !
949 ! !USES:
950 !
951  use ice_grid
952 !
953 ! !INPUT/OUTPUT PARAMETERS:
954 !
955 !EOP
956 !
957  integer (kind=int_kind) :: &
958  i, j &
959  , imx,ixx,ipx & ! record numbers for neighboring months
960  , recnum & ! record number
961  , maxrec & ! maximum record number
962  , recslot & ! spline slot for current record
963  , midmonth & ! middle day of month
964  , ng
965 
966  real (kind=dbl_kind) :: &
967  sec6hr ! number of seconds in 6 hours
968 
969  logical (kind=log_kind) :: readm, read6
970 
971  !-------------------------------------------------------------------
972  ! monthly data
973  !
974  ! Assume that monthly data values are located in the middle of the
975  ! month.
976  !-------------------------------------------------------------------
977 
978  midmonth = 15 ! data is given on 15th of every month
979 ! midmonth = fix(p5 * real(daymo(month),kind=dbl_kind)) ! exact middle
980 
981  ! Compute record numbers for surrounding months
982  maxrec = 12
983  imx = mod(month+maxrec-2,maxrec) + 1
984  ipx = mod(month, maxrec) + 1
985  if (mday >= midmonth) imx = 99 ! other two points will be used
986  if (mday < midmonth) ipx = 99
987 
988  ! Determine whether interpolation will use values 1:2 or 2:3
989  ! recslot = 2 means we use values 1:2, with the current value (2)
990  ! in the second slot
991  ! recslot = 1 means we use values 2:3, with the current value (2)
992  ! in the first slot
993  recslot = 1 ! latter half of month
994  if (mday < midmonth) recslot = 2 ! first half of month
995 
996  ! Find interpolation coefficients
997  call interp_coeff_monthly (recslot)
998 
999  ! Read 2 monthly values
1000  readm = .false.
1001  if (istep==1 .or. (mday==midmonth .and. sec==0)) readm = .true.
1002 
1003 ! call read_clim_data (readm, 0, imx, month, ipx, &
1004 ! flw_file, cldf_data)
1005 ! call read_clim_data (readm, 0, imx, month, ipx, &
1006 ! rain_file, fsnow_data)
1007 !
1008 ! call interpolate_data (cldf_data, cldf)
1009 ! call interpolate_data (fsnow_data, fsnow) ! units mm/s = kg/m^2/s
1010 
1011  !-------------------------------------------------------------------
1012  ! 6-hourly data
1013  !
1014  ! Assume that the 6-hourly value is located at the end of the
1015  ! 6-hour period. This is the convention for NCEP reanalysis data.
1016  ! E.g. record 1 gives conditions at 6 am GMT on 1 January.
1017  !-------------------------------------------------------------------
1018 
1019  sec6hr = secday/c4i ! seconds in 6 hours
1020  maxrec = 1460 ! 365*4
1021 
1022  ! current record number
1023  recnum = 4*int(yday) - 3 + int(real(sec,kind=dbl_kind)/sec6hr)
1024 
1025  ! Compute record numbers for surrounding data (2 on each side)
1026 
1027  imx = mod(recnum+maxrec-2,maxrec) + 1
1028  ixx = mod(recnum-1, maxrec) + 1
1029 ! ipx = mod(recnum, maxrec) + 1
1030 
1031  ! Compute interpolation coefficients
1032  ! If data is located at the end of the time interval, then the
1033  ! data value for the current record goes in slot 2
1034 
1035  recslot = 2
1036  ipx = 99
1037  call interp_coeff (recnum, recslot, sec6hr)
1038 
1039  ! Read
1040  read6 = .false.
1041  if (istep==1 .or. oldrecnum /= recnum) read6 = .true.
1042 
1043 ! call read_data (read6, 0, fyear, imx, ixx, ipx, maxrec, &
1044 ! tair_file, Tair_data)
1045 ! call read_data (read6, 0, fyear, imx, ixx, ipx, maxrec, &
1046 ! uwind_file, uatm_data)
1047 ! call read_data (read6, 0, fyear, imx, ixx, ipx, maxrec, &
1048 ! vwind_file, vatm_data)
1049 ! call read_data (read6, 0, fyear, imx, ixx, ipx, maxrec, &
1050 ! humid_file, Qa_data)
1051 
1052  ! Interpolate
1053 ! call interpolate_data (Tair_data, Tair)
1054 ! call interpolate_data (uatm_data, uatm)
1055 ! call interpolate_data (vatm_data, vatm)
1056 ! call interpolate_data (Qa_data, Qa)
1057 
1058 ! call Qa_fixLY
1059 
1060  do j=jlo,jhi
1061  do i=ilo,ihi
1062  qa(i,j) = qa(i,j) * hm(i,j)
1063  tair(i,j) = tair(i,j) * hm(i,j)
1064  uatm(i,j) = uatm(i,j) * hm(i,j)
1065  vatm(i,j) = vatm(i,j) * hm(i,j)
1066  enddo
1067  enddo
1068 
1069  call compute_shortwave ! AOMIP
1070 
1071  ! Save record number
1072  oldrecnum = recnum
1073 
1074  if (dbug) then
1075  ! cice
1076  if (my_task == master_task) write (nu_diag,*) 'LY_bulk_dat'
1077  ng = (ihi-ilo+1)*(jhi-jlo+1)
1078 ! call ice_global_real_minmax(ng,Fsw,'A Fsw ')
1079 ! call ice_global_real_minmax(ng,cldf,'A cld ')
1080 ! call ice_global_real_minmax(ng,Fsnow,'A Fsnow ')
1081 ! call ice_global_real_minmax(ng,Tair,'A Tair ')
1082 ! call ice_global_real_minmax(ng,uatm,'A uatm ')
1083 ! call ice_global_real_minmax(ng,vatm,'A vatm ')
1084 ! call ice_global_real_minmax(ng,Qa,'A Qa ')
1085 ! call ice_global_real_minmax(ng,rhoa,'A rhoa ')
1086  endif
1087 
1088  end subroutine ly_bulk_data
1089 
1090 !c=======================================================================
1091 !
1092 !BOP
1093 !
1094 ! !IROUTINE: compute_shortwave - AOMIP shortwave forcing
1095 !
1096 ! !INTERFACE:
1097 !
1098  subroutine compute_shortwave
1100 ! !DESCRIPTION:
1101 !
1102 ! Computes downwelling shortwave radiation based on sun declination
1103 ! and cloud fraction, as in AOMIP, following Zillman (1972) and
1104 ! Parkinson and Washington (1979).
1105 !
1106 ! !REVISION HISTORY:
1107 !
1108 ! authors: Elizabeth C. Hunke, LANL
1109 !
1110 ! !USES:
1111 !
1112  use ice_grid
1113  use ice_albedo
1114  use ice_constants
1115 !
1116 ! !INPUT/OUTPUT PARAMETERS:
1117 !
1118 !EOP
1119 !
1120  real (kind=dbl_kind) :: &
1121  hour_angle &
1122  , solar_time &
1123  , declin &
1124  , cosz &
1125  , e_i, d_i &
1126  , sw0 &
1127  , deg2rad_i
1128 
1129  integer (kind=int_kind) :: i,j
1130 
1131  do j=jlo,jhi
1132  do i=ilo,ihi
1133  deg2rad_i = pi/180._dbl_kind
1134  solar_time = mod(real(sec,kind=dbl_kind),secday)/3600._dbl_kind &
1135  + c12*sin(p5*tlon(i,j))
1136  hour_angle = (c12 - solar_time)*pi/c12
1137  declin = 23.44_dbl_kind*cos((172._dbl_kind-yday) &
1138  * c2i*pi/c365)*deg2rad_i
1139  cosz = sin(tlat(i,j))*sin(declin) &
1140  + cos(tlat(i,j))*cos(declin)*cos(hour_angle)
1141  cosz = max(cosz,c0i)
1142  e_i = 1.e5_dbl_kind*qa(i,j) &
1143  /(0.622_dbl_kind + 0.378_dbl_kind*qa(i,j))
1144  d_i = (cosz+2.7_dbl_kind)*e_i*1.e-5_dbl_kind+1.085_dbl_kind*cosz+p1
1145  sw0 = 1353._dbl_kind*cosz**2/d_i
1146  sw0 = max(sw0,c0i)
1147 
1148  ! total downward shortwave for cice
1149  fsw(i,j) = sw0*(c1i-p6*cldf(i,j)**3)
1150  fsw(i,j) = fsw(i,j)*hm(i,j)
1151  enddo
1152  enddo
1153 
1154  end subroutine compute_shortwave
1155 
1156 !c=======================================================================
1157 !
1158 !BOP
1159 !
1160 ! !IROUTINE: Qa_fixLY
1161 !
1162 ! !INTERFACE:
1163 !
1164  subroutine qa_fixly
1166 ! !DESCRIPTION:
1167 !
1168 ! Limits relative humidity <= 100%
1169 !
1170 ! !REVISION HISTORY:
1171 !
1172 ! authors: Elizabeth C. Hunke, LANL
1173 !
1174 ! !USES:
1175 !
1176 ! !INPUT/OUTPUT PARAMETERS:
1177 !
1178 !EOP
1179 !
1180  real (kind=dbl_kind), &
1181  dimension(ilo:ihi,jlo:jhi) :: &
1182  work, slope
1183 
1184  work = tair - tffresh
1185  work = c2i + (0.7859_dbl_kind + 0.03477_dbl_kind*work) &
1186  /(c1i + 0.00412_dbl_kind*work) &! 2+ converts ea mb -> Pa
1187  + 0.00422_dbl_kind*work ! for ice
1188  ! vapor pressure
1189  work = (c10i**work) ! saturated
1190  work = max(work,puny) ! puny over land to prevent division by zero
1191  ! specific humidity
1192  work = 0.622_dbl_kind*work/(1.e5_dbl_kind - 0.378_dbl_kind*work)
1193 
1194  qa = min(qa, work)
1195 
1196  end subroutine qa_fixly
1197 
1198 !c=======================================================================
1199 !
1200 !BOP
1201 !
1202 ! !IROUTINE: prepare_forcing - finish manipulating forcing
1203 !
1204 ! !INTERFACE:
1205 !
1206  subroutine prepare_forcing
1208 ! !DESCRIPTION:
1209 !
1210 ! !REVISION HISTORY:
1211 !
1212 ! authors Elizabeth C. Hunke, LANL
1213 !
1214 ! !USES:
1215 !
1216  use ice_grid, only: anglet, t2ugrid, hm
1217  use ice_state
1218  use mod_utils, only: fatal_error
1219 !
1220 ! !INPUT/OUTPUT PARAMETERS:
1221 !
1222 !EOP
1223 !
1224  integer (kind=int_kind) :: i, j
1225  real (kind=dbl_kind) :: &
1226  workx, worky &
1227  , fcc,sstk,rtea,qlwm,ptem ! terms needed for lwdn computation
1228 
1229  do j=jlo,jhi
1230  do i=ilo,ihi
1231 
1232  !-----------------------------------------------------------------
1233  ! Fix interpolation errors
1234  !-----------------------------------------------------------------
1235  fsw(i,j) = max(fsw(i,j),c0i)
1236  cldf(i,j) = max(min(cldf(i,j),c1i),c0i)
1237  fsnow(i,j) = max(fsnow(i,j),c0i)
1238  rhoa(i,j) = max(rhoa(i,j),c0i)
1239  qa(i,j) = max(qa(i,j),c0i)
1240 
1241  enddo
1242  enddo
1243 
1244  !-----------------------------------------------------------------
1245  ! calculations specific to data sets
1246  !-----------------------------------------------------------------
1247 
1248  if (trim(atm_data_type) == 'ncar') then
1249 
1250  ! correct known biases in NCAR data (as in CCSM latm)
1251  do j=jlo,jhi
1252  do i=ilo,ihi
1253  qa(i,j) = qa(i,j) * 0.94_dbl_kind
1254  fsw(i,j) = fsw(i,j) * 0.92_dbl_kind
1255  enddo
1256  enddo
1257 
1258  endif ! atm_data_type
1259 
1260  !-----------------------------------------------------------------
1261  ! Compute other fields needed by model
1262  !-----------------------------------------------------------------
1263 
1264  if(trim(ice_longwave_type) == 'PW')then
1265 
1266  do j=jlo,jhi
1267  do i = ilo, ihi
1268 
1269  zlvl(i,j) = c10i
1270  !wind (i,j) = sqrt(uatm(i,j)**2 + vatm(i,j)**2) ! wind speed, m/s
1271  pott(i,j) = tair(i,j)
1272 
1273  ! divide shortwave into spectral bands
1274  swvdr(i,j) = fsw(i,j)*(.28_dbl_kind) ! visible direct
1275  swvdf(i,j) = fsw(i,j)*(.24_dbl_kind) ! visible diffuse
1276  swidr(i,j) = fsw(i,j)*(.31_dbl_kind) ! near IR direct
1277  swidf(i,j) = fsw(i,j)*(.17_dbl_kind) ! near IR diffuse
1278  ! as in the dummy atm (latm)
1279  ! longwave as in Parkinson and Washington (1979)
1280  flw(i,j) = stefan_boltzmann*tair(i,j)**4 &! downward longwave
1281  & * (c1i - 0.261_dbl_kind* &
1282  & exp(-7.77e-4_dbl_kind*(tffresh - tair(i,j))**2)) &
1283  & * (c1i + 0.275_dbl_kind*cldf(i,j))
1284 
1285 
1286  ! longwave, Rosati and Miyakoda, JPO 18, p. 1607 (1988) - sort of -
1287 ! fcc = c1i - 0.8_dbl_kind * cldf(i,j)
1288 ! sstk = (Tsfc(i,j) * aice(i,j) &
1289 ! + sst(i,j) * (c1i - aice(i,j))) + Tffresh
1290 ! rtea = sqrt(c1000*Qa(i,j) / (0.622_dbl_kind &
1291 ! + 0.378_dbl_kind*Qa(i,j)))
1292 ! ptem = Tair(i,j) ! get this from stability?
1293 ! qlwm = ptem * ptem * ptem * &
1294 ! ( ptem*(0.39_dbl_kind-0.05_dbl_kind*rtea)*fcc &
1295 ! + c4i*(sstk-ptem) )
1296 ! flw(i,j) = emissivity * stefan_boltzmann * ( sstk**4 - qlwm )
1297 
1298 ! flw(i,j) = flw(i,j) * hm(i,j) ! land mask
1299 
1300  ! determine whether precip is rain or snow
1301 ! if (trim(precip_units) == 'mm_per_month') then
1302 ! fsnow(i,j) = fsnow(i,j)/2.592e+06_dbl_kind ! mm/month -> kg/m^2 s
1303 ! elseif (trim(precip_units) == 'mm_per_sec' .or.
1304 ! trim(precip_units) == 'mks') then
1305 ! ! no change: mm/sec = kg/m^2 s
1306 ! endif
1307 ! frain(i,j) = c0i
1308 ! if (Tair(i,j) >= Tffresh) then
1309 ! frain(i,j) = fsnow(i,j)
1310 ! fsnow(i,j) = c0i
1311 ! endif
1312 
1313  !-----------------------------------------------------------------
1314  ! rotate zonal/meridional vectors to local coordinates
1315  ! Vector fields come in on T grid, but are oriented geographically
1316  ! need to rotate to pop-grid FIRST using ANGLET
1317  ! then interpolate to the U-cell centers (otherwise we
1318  ! interpolate across the pole)
1319  ! use ANGLET which is on the T grid !
1320  ! atmo variables are needed in T cell centers in subroutine stability,
1321  ! and are interpolated to the U grid later as necessary
1322  !-----------------------------------------------------------------
1323  !workx = uatm(i,j) ! wind velocity, m/s
1324  !worky = vatm(i,j)
1325  !uatm (i,j) = workx*cos(ANGLET(i,j)) & ! convert to POP grid
1326  ! + worky*sin(ANGLET(i,j)) ! note uatm, vatm, wind
1327  !vatm (i,j) = worky*cos(ANGLET(i,j)) & ! are on the T-grid here
1328  ! - workx*sin(ANGLET(i,j))
1329 
1330  enddo
1331  enddo
1332 
1333  else if(trim(ice_longwave_type) == 'RM')then
1334 
1335  do j=jlo,jhi
1336  do i = ilo, ihi
1337 
1338  zlvl(i,j) = c10i
1339  !wind (i,j) = sqrt(uatm(i,j)**2 + vatm(i,j)**2) ! wind speed, m/s
1340  pott(i,j) = tair(i,j)
1341 
1342  ! divide shortwave into spectral bands
1343  swvdr(i,j) = fsw(i,j)*(.28_dbl_kind) ! visible direct
1344  swvdf(i,j) = fsw(i,j)*(.24_dbl_kind) ! visible diffuse
1345  swidr(i,j) = fsw(i,j)*(.31_dbl_kind) ! near IR direct
1346  swidf(i,j) = fsw(i,j)*(.17_dbl_kind) ! near IR diffuse
1347  ! as in the dummy atm (latm)
1348 
1349  ! longwave, Rosati and Miyakoda, JPO 18, p. 1607 (1988) - sort of -
1350  fcc = c1i - 0.8_dbl_kind * cldf(i,j)
1351  sstk = (tsfc(i,j) * aice(i,j) &
1352  + sst(i,j) * (c1i - aice(i,j))) + tffresh
1353  rtea = sqrt(c1000*qa(i,j) / (0.622_dbl_kind &
1354  + 0.378_dbl_kind*qa(i,j)))
1355  ptem = tair(i,j) ! get this from stability?
1356  qlwm = ptem * ptem * ptem * &
1357  ( ptem*(0.39_dbl_kind-0.05_dbl_kind*rtea)*fcc &
1358  + c4i*(sstk-ptem) )
1359  flw(i,j) = emissivity * stefan_boltzmann * ( sstk**4 - qlwm )
1360 
1361  flw(i,j) = flw(i,j) * hm(i,j) ! land mask
1362 
1363  ! determine whether precip is rain or snow
1364 ! if (trim(precip_units) == 'mm_per_month') then
1365 ! fsnow(i,j) = fsnow(i,j)/2.592e+06_dbl_kind ! mm/month -> kg/m^2 s
1366 ! elseif (trim(precip_units) == 'mm_per_sec' .or.
1367 ! trim(precip_units) == 'mks') then
1368 ! ! no change: mm/sec = kg/m^2 s
1369 ! endif
1370 ! frain(i,j) = c0i
1371 ! if (Tair(i,j) >= Tffresh) then
1372 ! frain(i,j) = fsnow(i,j)
1373 ! fsnow(i,j) = c0i
1374 ! endif
1375 
1376  !-----------------------------------------------------------------
1377  ! rotate zonal/meridional vectors to local coordinates
1378  ! Vector fields come in on T grid, but are oriented geographically
1379  ! need to rotate to pop-grid FIRST using ANGLET
1380  ! then interpolate to the U-cell centers (otherwise we
1381  ! interpolate across the pole)
1382  ! use ANGLET which is on the T grid !
1383  ! atmo variables are needed in T cell centers in subroutine stability,
1384  ! and are interpolated to the U grid later as necessary
1385  !-----------------------------------------------------------------
1386  !workx = uatm(i,j) ! wind velocity, m/s
1387  !worky = vatm(i,j)
1388  !uatm (i,j) = workx*cos(ANGLET(i,j)) & ! convert to POP grid
1389  ! + worky*sin(ANGLET(i,j)) ! note uatm, vatm, wind
1390  !vatm (i,j) = worky*cos(ANGLET(i,j)) & ! are on the T-grid here
1391  ! - workx*sin(ANGLET(i,j))
1392 
1393  enddo
1394  enddo
1395 
1396  else
1397  CALL fatal_error("ICE_LONGWAVE_TYPE should be PW or RM")
1398  end if
1399 
1400  end subroutine prepare_forcing
1401 
1402 !c=======================================================================
1403 !
1404 !BOP
1405 !
1406 ! !IROUTINE: interpolate_data
1407 !
1408 ! !INTERFACE:
1409 !
1410  subroutine interpolate_data (field_data, field)
1412 ! !DESCRIPTION:
1413 !
1414 ! Linear interpolation
1415 !
1416 ! !REVISION HISTORY:
1417 !
1418 ! authors Elizabeth C. Hunke, LANL
1419 !
1420 ! !USES:
1421 !
1422 ! !INPUT/OUTPUT PARAMETERS:
1423 !
1424  real (kind=dbl_kind), dimension(ilo:ihi,jlo:jhi,2), intent(in) ::&
1425  field_data ! 2 values used for interpolation
1426 
1427  real (kind=dbl_kind), dimension(ilo:ihi,jlo:jhi), intent(out) ::&
1428  field ! interpolated field
1429 !
1430 !EOP
1431 !
1432  integer (kind=int_kind) :: i,j
1433 
1434  do j=jlo,jhi
1435  do i=ilo,ihi
1436  field(i,j) = c1intp * field_data(i,j,1) &
1437  + c2intp * field_data(i,j,2)
1438  enddo
1439  enddo
1440 
1441  end subroutine interpolate_data
1442 
1443 !c=======================================================================
1444 !
1445 !BOP
1446 !
1447 ! !IROUTINE: sss_clim - annual mean climatology for Levitus sss
1448 !
1449 ! !INTERFACE:
1450 !
1451 ! subroutine sss_clim
1452 !
1453 ! !DESCRIPTION:
1454 !
1455 ! Creates annual mean climatology for Levitus sss from 12-month climatology.
1456 !
1457 ! !REVISION HISTORY:
1458 !
1459 ! authors Elizabeth C. Hunke, LANL
1460 !
1461 ! !USES:
1462 !
1463 ! use ice_work, only: worka
1464 !
1465 ! !INPUT/OUTPUT PARAMETERS:
1466 !
1467 !EOP
1468 !
1469 ! integer (kind=int_kind) :: i, j, nbits, k
1470 !
1471 ! nbits = 64 ! double precision data
1472 !
1473 ! sss_file = trim(ocn_data_dir)//'sss_Lev.mm'
1474 !
1475 ! if (my_task == master_task) then
1476 ! write (nu_diag,*) ''
1477 ! write (nu_diag,*) 'SSS climatology computed from:'
1478 ! write (nu_diag,*) trim(sss_file)
1479 ! endif
1480 
1481 ! if (my_task == master_task) &
1482 ! call ice_open (nu_forcing, sss_file, nbits)
1483 !
1484 ! !-------------------------------------------------------------------
1485 ! ! create surface salinity climatology from monthly data
1486 ! !-------------------------------------------------------------------
1487 !
1488 ! do j = jlo,jhi
1489 ! do i = ilo,ihi
1490 ! worka(i,j) = c0i
1491 ! enddo
1492 ! enddo
1493 
1494 ! do k = 1,12 ! loop over 12 months
1495 !
1496 ! call ice_read (nu_forcing, k, worka, 'rda8', dbug)
1497 ! do j = jlo,jhi
1498 ! do i = ilo,ihi
1499 ! sss(i,j) = worka(i,j) + sss(i,j)
1500 ! enddo
1501 ! enddo
1502 
1503 ! enddo ! k
1504 
1505 ! do j = jlo,jhi
1506 ! do i = ilo,ihi
1507 ! sss(i,j) = sss(i,j) / c12 ! annual average salinity
1508 ! sss(i,j) = max(sss(i,j), c0i)
1509 ! Tf (i,j) = -depressT*sss(i,j) ! deg C
1510 ! enddo
1511 ! enddo
1512 
1513 ! ! close file
1514 ! if (my_task == master_task) close(nu_forcing)
1515 
1516 ! end subroutine sss_clim
1517 
1518 !c=======================================================================
1519 !
1520 !BOP
1521 !
1522 ! !IROUTINE: sst_ic - sst initial condition
1523 !
1524 ! !INTERFACE:
1525 !
1526  subroutine sst_ic
1528 ! !DESCRIPTION:
1529 !
1530 ! Reads sst data for current month, and adjusts sst based on freezing
1531 ! temperature. Does not interpolate.
1532 !
1533 ! !REVISION HISTORY:
1534 !
1535 ! authors Elizabeth C. Hunke, LANL
1536 !
1537 ! !USES:
1538 !
1539 ! !INPUT/OUTPUT PARAMETERS:
1540 !
1541 !EOP
1542 !
1543  integer (kind=int_kind) :: i, j, nbits, k
1544 
1545  nbits = 64 ! double precision data
1546 
1547 ! if (imt_global == 320) then ! gx1
1548 ! sst_file = trim(ocn_data_dir)//'sst_clim_hurrell.dat'
1549 ! else ! gx3
1550 ! sst_file = trim(ocn_data_dir)//'sst_Lev.mm'
1551 ! endif
1552 
1553 ! if (my_task == master_task) then
1554 ! write (nu_diag,*) ''
1555 ! write (nu_diag,*) 'SST initial condition:'
1556 ! write (nu_diag,*) trim(sst_file)
1557 ! endif
1558 
1559 ! if (my_task == master_task) &
1560 ! call ice_open (nu_forcing, sst_file, nbits)
1561 !
1562 ! call ice_read (nu_forcing, month, sst, 'rda8', dbug)
1563 !
1564 ! if (my_task == master_task) close(nu_forcing)
1565 !
1566 ! do j=jlo,jhi
1567 ! do i=ilo,ihi
1568 ! ! Make sure sst is not less than Tf
1569 ! sst(i,j) = max(sst(i,j),Tf(i,j))
1570 ! enddo
1571 ! enddo
1572 
1573  end subroutine sst_ic
1574 
1575 !c=======================================================================
1576 !
1577 !BOP
1578 !
1579 ! !IROUTINE: getflux_ocn_clim - interpolates sss, sst; restores sst
1580 !
1581 ! !INTERFACE:
1582 !
1583  subroutine getflux_ocn_clim
1585 ! !DESCRIPTION:
1586 !
1587 ! Interpolate monthly sss, sst data to timestep.
1588 ! Note: Restoring is done only if sss_data_type and/or
1589 ! sst_data_type are set (not default) in namelist.
1590 !
1591 ! !REVISION HISTORY:
1592 !
1593 ! authors: same as module
1594 !
1595 ! !USES:
1596 !
1597 ! use ice_ocean
1598 !
1599 ! !INPUT/OUTPUT PARAMETERS:
1600 !
1601 !EOP
1602 !
1603  integer (kind=int_kind) :: &
1604  i, j &
1605  , imx,ipx & ! record numbers for neighboring months
1606  , maxrec & ! maximum record number
1607  , recslot & ! spline slot for current record
1608  , midmonth ! middle day of month
1609 
1610  real (kind=dbl_kind), dimension(ilo:ihi,jlo:jhi) ::&
1611  sstdat ! data value toward which SST is restored
1612 
1613  logical (kind=log_kind) :: readm
1614 
1615 ! if (trim(sss_data_type) == 'clim') then
1616 ! sss_file = trim(ocn_data_dir)//'sss_Lev.mm'
1617 ! endif
1618 ! if (trim(sst_data_type) == 'clim') then
1619 ! sst_file = trim(ocn_data_dir)//'sst_clim_hurrell.dat'
1620 ! endif
1621 
1622 ! if (my_task == master_task .and. istep == 1) then
1623 ! write (nu_diag,*) ' '
1624 ! if (trim(sss_data_type) == 'clim') then
1625 ! write (nu_diag,*) 'SSS data interpolated to timestep:'
1626 ! write (nu_diag,*) trim(sss_file)
1627 ! endif
1628 ! if (trim(sst_data_type) == 'clim') then
1629 ! write (nu_diag,*) 'SST data interpolated to timestep:'
1630 ! write (nu_diag,*) trim(sst_file)
1631 ! if (restore_sst) write (nu_diag,*) &
1632 ! 'SST restoring timescale = ',trestore,' days'
1633 ! endif
1634 ! endif ! my_task, istep
1635 
1636  !-------------------------------------------------------------------
1637  ! monthly data
1638  !
1639  ! Assume that monthly data values are located in the middle of the
1640  ! month.
1641  !-------------------------------------------------------------------
1642 
1643  midmonth = 15 ! data is given on 15th of every month
1644 ! midmonth = fix(p5 * real(daymo(month),kind=dbl_kind)) ! exact middle
1645 
1646  ! Compute record numbers for surrounding months
1647  maxrec = 12
1648  imx = mod(month+maxrec-2,maxrec) + 1
1649  ipx = mod(month, maxrec) + 1
1650  if (mday >= midmonth) imx = 99 ! other two points will be used
1651  if (mday < midmonth) ipx = 99
1652 
1653  ! Determine whether interpolation will use values 1:2 or 2:3
1654  ! recslot = 2 means we use values 1:2, with the current value (2)
1655  ! in the second slot
1656  ! recslot = 1 means we use values 2:3, with the current value (2)
1657  ! in the first slot
1658 ! recslot = 1 ! latter half of month
1659 ! if (mday < midmonth) recslot = 2 ! first half of month
1660 
1661  ! Find interpolation coefficients
1662 ! call interp_coeff_monthly (recslot)
1663 
1664 ! readm = .false.
1665 ! if (istep==1 .or. (mday==midmonth .and. sec==0)) readm = .true.
1666 
1667  !-------------------------------------------------------------------
1668  ! Read two monthly SSS values and interpolate.
1669  ! Note: SSS is restored instantaneously to data.
1670  !-------------------------------------------------------------------
1671 
1672 ! if (trim(sss_data_type) == 'clim') then
1673 ! call read_clim_data (readm, 0, imx, month, ipx, &
1674 ! sss_file, sss_data)
1675 ! call interpolate_data (sss_data, sss)
1676 ! do j = jlo,jhi
1677 ! do i = ilo,ihi
1678 ! sss(i,j) = max(sss(i,j), c0i)
1679 ! Tf (i,j) = -depressT*sss(i,j) ! deg C
1680 ! enddo
1681 ! enddo
1682 ! endif
1683 
1684  !-------------------------------------------------------------------
1685  ! Read two monthly SST values and interpolate.
1686  ! Restore toward interpolated value.
1687  ! Make sure SST is not below Tf.
1688  !-------------------------------------------------------------------
1689 
1690 ! if (trim(sst_data_type) == 'clim') then
1691 ! call read_clim_data (readm, 0, imx, month, ipx, &
1692 ! sst_file, sst_data)
1693 ! call interpolate_data (sst_data, sstdat)
1694 
1695  !-------------------------------------------------------------------
1696  ! Restore sst to data
1697  !-------------------------------------------------------------------
1698 ! if (restore_sst) then
1699 ! do j = jlo,jhi
1700 ! do i = ilo,ihi
1701 ! sst(i,j) = sst(i,j) + (sstdat(i,j)-sst(i,j))*dt/trest
1702 ! enddo
1703 ! enddo
1704 ! endif
1705 ! endif
1706 
1707  end subroutine getflux_ocn_clim
1708 
1709 !c=======================================================================
1710 !
1711 !BOP
1712 !
1713 ! !IROUTINE: getflux_ocn_ncar_init - reads data set
1714 !
1715 ! !INTERFACE:
1716 !
1717  subroutine getflux_ocn_ncar_init
1719 ! !DESCRIPTION:
1720 !
1721 ! Reads NCAR pop ocean forcing data set 'pop_frc_gx1v3_010815.nc'
1722 !
1723 ! List of ocean forcing fields: Note that order is important!
1724 ! (order is determined by field list in vname).
1725 !
1726 ! For ocean mixed layer-----------------------------units
1727 !
1728 ! 1 sst------temperature---------------------------(C)
1729 ! 2 sss------salinity------------------------------(ppt)
1730 ! 3 hbl------depth---------------------------------(m)
1731 ! 4 u--------surface u current---------------------(m/s)
1732 ! 5 v--------surface v current---------------------(m/s)
1733 ! 6 dhdx-----surface tilt x direction--------------(m/m)
1734 ! 7 dhdy-----surface tilt y direction--------------(m/m)
1735 ! 8 qdp------ocean sub-mixed layer heat flux-------(W/m2)
1736 !
1737 ! Fields 4, 5, 6, 7 are on the U-grid; 1, 2, 3, and 8 are
1738 ! on the T-grid.
1739 !
1740 ! !REVISION HISTORY:
1741 !
1742 ! authors: Bruce Briegleb, NCAR
1743 ! Elizabeth Hunke, LANL
1744 !
1745 ! !USES:
1746 !
1747  use ice_grid, only: t2ugrid
1748 ! use ice_ocean
1749 ! use ice_mpi_internal
1750 ! use ice_exit
1751 ! use ice_history, only: restart
1752  use ice_work, only: work_g1
1753 !#ifdef CCSM
1754 ! use shr_sys_mod, only : shr_sys_flush
1755 !#endif
1756 ! include "netcdf.inc"
1757 !
1758 ! !INPUT/OUTPUT PARAMETERS:
1759 !
1760 !EOP
1761 !
1762  integer (kind=int_kind) :: &
1763  i, j &
1764  , ni &! field index
1765  , mi ! month index
1766 
1767  character(len=16) ::&
1768  vname(nfld) ! variable names to search for on netCDF file
1769  data vname / &
1770  'T', 'S', 'hblt', 'U', 'V', &
1771  'dhdx', 'dhdy', 'qdp' /
1772 
1773  integer (kind=int_kind) ::&
1774  fid &! file id for netCDF routines
1775  , dimid &! dimension id for netCDF file
1776  , varid(nfld) &! variable id for field in netCDF file
1777  , ntim ! number of times of data for netCDF file
1778 
1779  integer (kind=int_kind) :: &
1780  status &! status variable from netCDF routine
1781  , nlat &! number of longitudes of data for netCDF file
1782  , nlon &! number of latitudes of data for netCDF file
1783  , start(3) &! start location for netCDF data reads
1784  , count(3) ! number of data items to read in
1785 
1786 ! if (my_task == master_task) then
1787 
1788 ! write (nu_diag,*) 'WARNING: evp_prep calculates surface tilt'
1789 ! write (nu_diag,*) 'WARNING: stress from geostrophic currents,'
1790 ! write (nu_diag,*) 'WARNING: not data from ocean forcing file.'
1791 ! write (nu_diag,*) 'WARNING: Alter ice_dyn_evp.F if desired.'
1792 
1793 ! if (restore_sst) write (nu_diag,*) &
1794 ! 'SST restoring timescale = ',trestore,' days'
1795 
1796 ! sst_file = trim(ocn_data_dir)//oceanmixed_file ! not just sst
1797 
1798  !---------------------------------------------------------------
1799  ! Read in ocean forcing data from an existing local netCDF file
1800  !---------------------------------------------------------------
1801 ! write (nu_diag,*) 'ocean mixed layer forcing data file = ', &
1802 ! sst_file
1803 
1804 ! status = nf_open(sst_file, NF_NOWRITE, fid)
1805 ! if (status /= NF_NOERR) then
1806 ! call abort_ice ('ice: no netCDF file with ocn forcing data')
1807 ! endif
1808 ! write(nu_diag,*) 'Successful open of ocean forcing file'
1809 
1810 ! status = nf_inq_dimid(fid,'nlon',dimid)
1811 ! status = nf_inq_dimid(fid,'ni',dimid)
1812 ! status = nf_inq_dimlen(fid,dimid,nlon)
1813 
1814 ! status = nf_inq_dimid(fid,'nlat',dimid)
1815 ! status = nf_inq_dimid(fid,'nj',dimid)
1816 ! status = nf_inq_dimlen(fid,dimid,nlat)
1817 !
1818 ! if( nlon .ne. imt_global ) then
1819 ! call abort_ice ('ice: ocn frc file nlon ne imt_global')
1820 ! endif
1821 ! if( nlat .ne. jmt_global ) then
1822 ! call abort_ice ('ice: ocn frc file nlat ne jmt_global')
1823 ! endif
1824 !
1825 ! do ni=1,nfld
1826 ! status = nf_inq_varid(fid,vname(n),varid(n))
1827 ! if (status /= NF_NOERR ) then
1828 ! write(nu_diag,*) 'ice error- cannot find field ',vname(n)
1829 ! call abort_ice ('ice: cannot find ocn frc field')
1830 ! endif
1831 ! write (nu_diag,*) 'Ocean forcing field found = ',vname(n)
1832 ! enddo
1833 
1834 !#ifdef CCSM
1835 ! call shr_sys_flush(nu_diag)
1836 !#endif
1837 
1838 ! allocate (work_g1(imt_global,jmt_global))
1839 
1840 ! endif ! master_task
1841 
1842  ! Read in ocean forcing data for all 12 months
1843 ! do ni=1,nfld
1844 ! do mi=1,12
1845 
1846 ! if (my_task == master_task) then
1847 ! start(1) = 1
1848 ! start(2) = 1
1849 ! start(3) = mi
1850 ! count(1) = imt_global
1851 ! count(2) = jmt_global
1852 ! count(3) = 1
1853 
1854  ! Note: netCDF does single to double conversion if necessary
1855 ! status = nf_get_vara_double(fid,varid(n),start,count,work_g1)
1856 ! if (status /= NF_NOERR ) then
1857 ! write(nu_diag,*) 'could not read in ocn forcing field ',&
1858 ! vname(ni)
1859 ! call abort_ice ('ice read failed')
1860 ! endif
1861 
1862 ! endif ! master_task
1863 
1864 ! call global_scatter(work_g1,ocn_frc_m(:,:,ni,mi))
1865 
1866 ! enddo ! month loop
1867 ! enddo ! field loop
1868 
1869 ! if (my_task == master_task) then
1870 ! status = nf_close(fid)
1871 ! deallocate (work_g1)
1872 ! endif
1873 
1874  end subroutine getflux_ocn_ncar_init
1875 
1876 !c=======================================================================
1877 !
1878 !BOP
1879 !
1880 ! !IROUTINE: getflux_ocn_ncar - interpolates data to timestep
1881 !
1882 ! !INTERFACE:
1883 !
1884  subroutine getflux_ocn_ncar
1886 ! !DESCRIPTION:
1887 !
1888 ! Interpolate monthly ocean data to timestep.
1889 ! Restore sst if desired. sst is updated with surface fluxes in ice_ocean.F.
1890 !
1891 ! !REVISION HISTORY:
1892 !
1893 ! authors: same as module
1894 !
1895 ! !USES:
1896 !
1897 ! use ice_ocean
1898 ! use ice_history, only: restart
1899  use ice_grid, only: hm
1900  use ice_work, only: worka
1901 !
1902 ! !INPUT/OUTPUT PARAMETERS:
1903 !
1904 !EOP
1905 !
1906  integer (kind=int_kind) :: &
1907  i, j, ni &
1908  , imx,ipx &! record numbers for neighboring months
1909  , maxrec &! maximum record number
1910  , recslot &! spline slot for current record
1911  , midmonth &! middle day of month
1912  , ng
1913 
1914  real (kind=dbl_kind), dimension(ilo:ihi,jlo:jhi) :: &
1915  sstdat ! data value toward which SST is restored
1916 
1917  !-------------------------------------------------------------------
1918  ! monthly data
1919  !
1920  ! Assume that monthly data values are located in the middle of the
1921  ! month.
1922  !-------------------------------------------------------------------
1923 
1924  midmonth = 15 ! data is given on 15th of every month
1925 ! midmonth = fix(p5 * real(daymo(month),kind=dbl_kind)) ! exact middle
1926 
1927  ! Compute record numbers for surrounding months
1928  maxrec = 12
1929  imx = mod(month+maxrec-2,maxrec) + 1
1930  ipx = mod(month, maxrec) + 1
1931  if (mday >= midmonth) imx = 99 ! other two points will be used
1932  if (mday < midmonth) ipx = 99
1933 
1934  ! Determine whether interpolation will use values 1:2 or 2:3
1935  ! recslot = 2 means we use values 1:2, with the current value (2)
1936  ! in the second slot
1937  ! recslot = 1 means we use values 2:3, with the current value (2)
1938  ! in the first slot
1939 ! recslot = 1 ! latter half of month
1940 ! if (mday < midmonth) recslot = 2 ! first half of month
1941 
1942  ! Find interpolation coefficients
1943 ! call interp_coeff_monthly (recslot)
1944 
1945 ! do ni = nfld, 1, -1
1946  ! use sst_data arrays as temporary work space until n=1
1947 ! if (imx /= 99) then ! first half of month
1948 ! sst_data(:,:,1) = ocn_frc_m(:,:,n,imx)
1949 ! sst_data(:,:,2) = ocn_frc_m(:,:,n,month)
1950 ! else ! second half of month
1951 ! sst_data(:,:,1) = ocn_frc_m(:,:,n,month)
1952 ! sst_data(:,:,2) = ocn_frc_m(:,:,n,ipx)
1953 ! endif
1954 ! call interpolate_data (sst_data,worka)
1955  ! masking by hm is necessary due to NaNs in the data file
1956 ! do j = jlo,jhi
1957 ! do i = ilo,ihi
1958 ! if (ni == 2) sss (i,j) = c0i
1959 ! if (ni == 3) hmix (i,j) = c0i
1960 ! if (ni == 4) uocn (i,j) = c0i
1961 ! if (ni == 5) vocn (i,j) = c0i
1962 ! if (ni == 6) ss_tltx(i,j) = c0i
1963 ! if (ni == 7) ss_tlty(i,j) = c0i
1964 ! if (ni == 8) qdp (i,j) = c0i
1965 ! if (hm(i,j) == c1i) then
1966 ! if (ni == 2) sss (i,j) = worka(i,j)
1967 ! if (ni == 3) hmix (i,j) = worka(i,j)
1968 ! if (ni == 4) uocn (i,j) = worka(i,j)
1969 ! if (ni == 5) vocn (i,j) = worka(i,j)
1970 ! if (ni == 6) ss_tltx(i,j) = worka(i,j)
1971 ! if (ni == 7) ss_tlty(i,j) = worka(i,j)
1972 ! if (ni == 8) qdp (i,j) = worka(i,j)
1973 !
1974  ! debugging
1975 ! if (ni == 3 .and. hmix(i,j) == c0i) then
1976 ! print*,i,j,hm(i,j),hmix(i,j),sss(i,j),uocn(i,j),qdp(i,j)
1977 ! stop
1978 ! endif
1979 ! endif
1980 ! enddo
1981 ! enddo
1982 ! enddo
1983 
1984  do j = jlo,jhi
1985  do i = ilo,ihi
1986 ! sss (i,j) = max (sss(i,j), c0i)
1987 ! Tf (i,j) = -depressT*sss(i,j) ! deg C
1988 ! hmix(i,j) = max(hmix(i,j), c0i)
1989  enddo
1990  enddo
1991 
1992 ! if (restore_sst) then
1993 ! do j = jlo,jhi
1994 ! do i = ilo,ihi
1995 ! sst(i,j) = sst(i,j) + (sstdat(i,j)-worka(i,j))*dt/trest
1996 ! enddo
1997 ! enddo
1998 ! else sst is only updated in ice_ocean.F
1999 ! endif
2000 
2001  ! initialize sst properly on first step
2002 ! if (istep1 <= 1 .and. .not. (restart)) then
2003 ! call interpolate_data (sst_data,sst)
2004 ! do j = jlo,jhi
2005 ! do i = ilo,ihi
2006 ! if (hm(i,j) == c1i) then
2007 ! sst(i,j) = max (sst(i,j), Tf(i,j))
2008 ! else
2009 ! sst(i,j) = c0i
2010 ! endif
2011 ! enddo
2012 ! enddo
2013 ! endif
2014 
2015 ! if (dbug) then
2016 ! if (my_task == master_task) &
2017 ! write (nu_diag,*) 'getflux_ocn_ncar'
2018 ! ng = (ihi-ilo+1)*(jhi-jlo+1)
2019 ! call ice_global_real_minmax(ng,Tf, 'Tf ')
2020 ! call ice_global_real_minmax(ng,sst, 'sst ')
2021 ! call ice_global_real_minmax(ng,sss, 'sss ')
2022 ! call ice_global_real_minmax(ng,hmix, 'hmix ')
2023 ! call ice_global_real_minmax(ng,uocn, 'uocn ')
2024 ! call ice_global_real_minmax(ng,vocn, 'vocn ')
2025 ! call ice_global_real_minmax(ng,ss_tltx,'tltx ')
2026 ! call ice_global_real_minmax(ng,ss_tlty,'tlty ')
2027 ! call ice_global_real_minmax(ng,qdp, 'qdp ')
2028 ! endif
2029 
2030  end subroutine getflux_ocn_ncar
2031 
2032 !c=======================================================================
2033 
2034  end module ice_flux_in
2035 
2036 !c=======================================================================
character(char_len) sst_data_type
real(kind=dbl_kind), dimension(:,:,:), allocatable, save fsw_data
Definition: ice_flux_in.f90:86
real(kind=dbl_kind), parameter c1000
integer(kind=int_kind) ycycle
Definition: ice_flux_in.f90:54
character(char_len_long) sss_file
Definition: ice_flux_in.f90:64
real(kind=dbl_kind), parameter secday
real(kind=dbl_kind), dimension(:,:), allocatable, save cldf
Definition: ice_flux_in.f90:61
character(char_len) sss_data_type
subroutine interp_coeff(recnum, recslot, secint)
character(char_len_long) flw_file
Definition: ice_flux_in.f90:64
character(char_len_long) oceanmixed_file
subroutine t2ugrid(work)
Definition: ice_grid.f90:840
integer, parameter dbl_kind
integer(kind=int_kind) sec
logical(kind=log_kind) restore_sst
integer(kind=int_kind) month
character(char_len_long) rhoa_file
Definition: ice_flux_in.f90:64
subroutine qa_fixly
integer(kind=int_kind) ihi
Definition: ice_domain.f90:101
real(kind=dbl_kind), dimension(:,:), allocatable, save fsw
Definition: ice_flux.f90:164
real(kind=dbl_kind), parameter c0i
character(char_len) precip_units
character(len=80) ice_longwave_type
Definition: mod_main.f90:733
subroutine getflux_ocn_ncar
subroutine sst_ic
integer(kind=int_kind) oldrecnum
Definition: ice_flux_in.f90:82
character(char_len_long) atm_data_dir
real(kind=dbl_kind), dimension(:,:), allocatable tlat
Definition: ice_grid.f90:122
real(kind=dbl_kind), parameter c10i
real(kind=dbl_kind), dimension(:,:), allocatable, save swvdf
Definition: ice_flux.f90:91
real(kind=dbl_kind) c1intp
Definition: ice_flux_in.f90:78
character(char_len_long) vwind_file
Definition: ice_flux_in.f90:64
real(kind=dbl_kind) trest
real(kind=dbl_kind), dimension(:,:), allocatable, save rhoa
Definition: ice_flux.f90:91
real(kind=dbl_kind), dimension(:,:), allocatable, save pott
Definition: ice_flux.f90:91
logical(kind=log_kind) dbug
integer(kind=int_kind) mday
real(kind=dbl_kind), parameter stefan_boltzmann
integer(kind=int_kind) istep
character(char_len_long) humid_file
Definition: ice_flux_in.f90:64
character(char_len) atm_data_type
real(kind=dbl_kind) ftime
Definition: ice_flux_in.f90:78
real(kind=dbl_kind), dimension(:,:), allocatable anglet
Definition: ice_grid.f90:140
real(kind=dbl_kind), parameter c4i
real(kind=dbl_kind), dimension(:,:,:), allocatable, save tair_data
Definition: ice_flux_in.f90:86
subroutine interpolate_data(field_data, field)
real(kind=dbl_kind), dimension(:,:), allocatable, save flw
Definition: ice_flux.f90:91
subroutine interp_coeff_monthly(recslot)
real(kind=dbl_kind), dimension(:,:,:), allocatable, save cldf_data
Definition: ice_flux_in.f90:86
character(char_len_long) ocn_data_dir
integer(kind=int_kind) trestore
integer(kind=int_kind) fyear_final
Definition: ice_flux_in.f90:54
integer(kind=int_kind) jlo
Definition: ice_domain.f90:101
subroutine prepare_forcing
real(kind=dbl_kind), dimension(:,:), allocatable, save sst
Definition: ice_flux.f90:91
subroutine ncar_files(yr)
character(char_len_long) uwind_file
Definition: ice_flux_in.f90:64
character(char_len_long) height_file
Definition: ice_flux_in.f90:64
real(kind=dbl_kind), dimension(:,:), allocatable, save vatm
Definition: ice_flux.f90:91
real(kind=dbl_kind), parameter emissivity
integer(kind=int_kind) ilo
Definition: ice_domain.f90:101
real(kind=dbl_kind), parameter p5
real(kind=dbl_kind), parameter puny
real(kind=dbl_kind), parameter tffresh
integer(kind=int_kind), parameter nfld
integer(kind=int_kind) jhi
Definition: ice_domain.f90:101
real(kind=dbl_kind) c2intp
Definition: ice_flux_in.f90:78
real(kind=dbl_kind), parameter c12
integer(kind=int_kind) fyear_init
Definition: ice_flux_in.f90:54
real(kind=dbl_kind), dimension(:,:), allocatable worka
Definition: ice_work.f90:61
real(kind=dbl_kind), dimension(:,:), allocatable, target, save aice
Definition: ice_state.f90:82
real(kind=dbl_kind), dimension(:,:,:), allocatable, save vatm_data
Definition: ice_flux_in.f90:86
real(kind=dbl_kind), parameter c2i
real(kind=dbl_kind), dimension(:,:,:), allocatable, save sst_data
Definition: ice_flux_in.f90:86
real(kind=dbl_kind), dimension(:,:,:), allocatable, save uatm_data
Definition: ice_flux_in.f90:86
real(kind=dbl_kind), dimension(:,:), allocatable, save uatm
Definition: ice_flux.f90:91
integer(kind=int_kind), save my_task
Definition: ice_domain.f90:95
subroutine init_getflux
real(kind=dbl_kind), dimension(:,:), allocatable, save swvdr
Definition: ice_flux.f90:91
real(kind=dbl_kind), parameter p1
character(char_len_long) sst_file
Definition: ice_flux_in.f90:64
real(kind=dbl_kind), dimension(:,:,:), allocatable, save rhoa_data
Definition: ice_flux_in.f90:86
real(kind=dbl_kind), dimension(:,:), allocatable, save zlvl
Definition: ice_flux.f90:91
real(kind=dbl_kind) yday
subroutine ly_files(yr)
subroutine ly_bulk_data
subroutine compute_shortwave
real(kind=dbl_kind), dimension(:,:), allocatable hm
Definition: ice_grid.f90:158
real(kind=dbl_kind), dimension(:,:), allocatable, save fsnow
Definition: ice_flux.f90:91
character(char_len_long) tair_file
Definition: ice_flux_in.f90:64
real(kind=dbl_kind), parameter c1i
subroutine fatal_error(ER1, ER2, ER3, ER4)
Definition: mod_utils.f90:230
real(kind=dbl_kind), dimension(:,:), allocatable, save qa
Definition: ice_flux.f90:91
real(kind=dbl_kind), dimension(:,:), allocatable, save swidf
Definition: ice_flux.f90:91
real(kind=dbl_kind), parameter c365
real(kind=dbl_kind), dimension(:,:), allocatable work_g1
Definition: ice_work.f90:50
subroutine getflux
real(kind=dbl_kind), dimension(:,:,:), allocatable, save fsnow_data
Definition: ice_flux_in.f90:86
real(kind=dbl_kind), dimension(:,:,:), allocatable, save flw_data
Definition: ice_flux_in.f90:86
real(kind=dbl_kind), dimension(:,:,:), allocatable, save zlvl_data
Definition: ice_flux_in.f90:86
character(char_len_long) rain_file
Definition: ice_flux_in.f90:64
integer(kind=int_kind) fyear
Definition: ice_flux_in.f90:54
real(kind=dbl_kind), dimension(:,:), allocatable, save tair
Definition: ice_flux.f90:91
real(kind=dbl_kind), parameter p6
character(char_len_long) pott_file
Definition: ice_flux_in.f90:64
real(kind=dbl_kind), dimension(:,:), allocatable tlon
Definition: ice_grid.f90:122
real(kind=dbl_kind), dimension(:,:), allocatable, save swidr
Definition: ice_flux.f90:91
integer(kind=int_kind), save master_task
Definition: ice_domain.f90:95
real(kind=dbl_kind), dimension(:,:,:), allocatable, save pott_data
Definition: ice_flux_in.f90:86
subroutine getflux_ocn_clim
integer(kind=int_kind), dimension(13) daycal
subroutine file_year(data_file, yr)
real(kind=dbl_kind), dimension(:,:), allocatable, target, save tsfc
Definition: ice_state.f90:82
character(char_len_long) fsw_file
Definition: ice_flux_in.f90:64
real(kind=dbl_kind), dimension(:,:,:), allocatable, save qa_data
Definition: ice_flux_in.f90:86
subroutine ncar_bulk_data
real(kind=dbl_kind), dimension(:,:,:), allocatable, save sss_data
Definition: ice_flux_in.f90:86
subroutine getflux_ocn_ncar_init