319 INTEGER,
INTENT(in),
OPTIONAL :: diag_subset
320 INTEGER,
INTENT(out),
OPTIONAL,
TARGET :: istat
322 CHARACTER(len=*),
INTENT(out),
OPTIONAL :: err_msg
325 INTEGER,
PARAMETER :: dt_line_length = 256
327 INTEGER :: record_len
330 INTEGER :: commentstart
331 INTEGER :: diag_subset_output
332 INTEGER :: nfields, nfiles
334 INTEGER,
TARGET :: mystat
335 INTEGER,
POINTER :: pstat
337 CHARACTER(len=5) :: line_number
338 CHARACTER(len=256) :: record_line
339 CHARACTER(len=256) :: local_err_msg
340 CHARACTER(len=:),
DIMENSION(:),
ALLOCATABLE :: diag_table
341 integer :: base_time_int(6)
347 IF (
PRESENT(istat) )
THEN
355 IF (
PRESENT(diag_subset) )
THEN
356 diag_subset_output = diag_subset
358 diag_subset_output = diag_all
361 call ascii_read(
'diag_table', diag_table, num_lines=num_lines)
364 READ (unit=diag_table(1), fmt=*, iostat=mystat) global_descriptor
365 IF ( mystat /= 0 )
THEN
367 IF ( fms_error_handler(
'diag_table_mod::parse_diag_table', &
368 'Error reading the global descriptor from the diagnostic table.', err_msg) )
RETURN
372 READ (unit=diag_table(2), fmt=*, iostat=mystat) base_time_int
373 IF ( mystat /= 0 )
THEN
375 IF ( fms_error_handler(
'diag_manager_init',
'Error reading the base date from the diagnostic table.', &
383 pass:
DO npass = 1, 2
384 parser:
DO line_num=3, num_lines
388 READ (diag_table(line_num), fmt=
'(A)', iostat=mystat) record_line
390 WRITE (line_number,
'(I5)') line_num
392 IF ( mystat > 0 )
THEN
393 IF ( mpp_pe() == mpp_root_pe() ) &
394 &
CALL error_mesg(
"diag_table_mod::parse_diag_table",&
395 &
"Problem reading the diag_table (line:" //line_number//
").", fatal)
397 ELSE IF ( mystat < 0 )
THEN
402 record_len = len_trim(record_line)
405 commentstart = index(record_line,
'#')
406 IF ( commentstart .NE. 0 ) record_line = record_line(1:commentstart-1)
407 IF ( len_trim(record_line) == 0 .OR. record_len == 0 ) cycle parser
409 init:
IF ( npass == 1 )
THEN
411 temp_file =
parse_file_line(line=record_line, istat=mystat, err_msg=local_err_msg)
413 IF ( mystat > 0 )
THEN
414 CALL error_mesg(
"diag_table_mod::parse_diag_table",&
415 & trim(local_err_msg)//
" (line:" //trim(line_number)//
").", fatal)
416 ELSE IF ( mystat < 0 )
THEN
417 IF ( mpp_pe() == mpp_root_pe() )&
418 &
CALL error_mesg(
"diag_table_mod::parse_diag_table",&
419 & trim(local_err_msg)//
" (line: "//trim(line_number)//
").", warning)
421 ELSE IF ( (diag_subset_output == diag_other .AND. index(lowercase(temp_file%file_name),
"ocean").NE.0)&
422 & .OR. (diag_subset_output == diag_ocean .AND. index(lowercase(temp_file%file_name),
"ocean").EQ.0)&
425 ELSE IF ( temp_file%new_file_freq > 0 )
THEN
427 CALL init_file(temp_file%file_name, temp_file%output_freq, temp_file%iOutput_freq_units, &
428 & temp_file%file_format, temp_file%iTime_units, temp_file%long_name, 1, &
429 & temp_file%new_file_freq, temp_file%iNew_file_freq_units,&
430 & temp_file%start_time, temp_file%file_duration, temp_file%iFile_duration_units, &
431 & temp_file%filename_time_bounds)
433 CALL init_file(temp_file%file_name, temp_file%output_freq, temp_file%iOutput_freq_units, &
434 & temp_file%file_format, temp_file%iTime_units, temp_file%long_name, 1)
441 IF ( .NOT.
is_a_file(trim(record_line)) )
THEN
442 temp_field =
parse_field_line(line=record_line, istat=mystat, err_msg=local_err_msg)
445 IF ( mystat > 0 )
THEN
446 CALL error_mesg(
"diag_table_mod::parse_diag_table",&
447 & trim(local_err_msg)//
" (line: "//trim(line_number)//
").",fatal)
448 ELSE IF ( mystat < 0 )
THEN
449 IF ( mpp_pe() == mpp_root_pe() )&
450 &
CALL error_mesg(
"diag_table_mod::Parse_diag_table",&
451 & trim(local_err_msg)//
" (line: "//trim(line_number)//
").",warning)
453 ELSE IF ((diag_subset_output == diag_other .AND. index(lowercase(temp_field%file_name),
"ocean").NE.0)&
454 &.OR. (diag_subset_output == diag_ocean .AND. index(lowercase(temp_field%file_name),
"ocean").EQ.0)&
457 ELSE IF ( lowercase(trim(temp_field%spatial_ops)) ==
'none' )
THEN
459 CALL init_output_field(temp_field%module_name, temp_field%field_name, temp_field%output_name, &
460 & temp_field%file_name, temp_field%time_method, temp_field%pack, 1)
463 CALL init_output_field(temp_field%module_name, temp_field%field_name, temp_field%output_name, &
464 & temp_field%file_name, temp_field%time_method, temp_field%pack, 1, temp_field%regional_coords)
468 nfields = nfields + 1
475 DEALLOCATE(diag_table)
479 IF ( local_err_msg /=
'' )
THEN
481 IF ( fms_error_handler(
'diag_table_mod::parse_diag_table', trim(local_err_msg), err_msg) )
RETURN
492 CHARACTER(len=*),
INTENT(in) :: line
493 INTEGER,
INTENT(out),
OPTIONAL,
TARGET :: istat
497 CHARACTER(len=*),
INTENT(out),
OPTIONAL :: err_msg
500 INTEGER,
TARGET :: mystat
501 INTEGER,
POINTER :: pstat
502 INTEGER :: year, month, day, hour, minute, second
503 CHARACTER(len=256) :: local_err_msg
505 IF (
PRESENT(istat) )
THEN
526 IF ( mystat > 0 )
THEN
528 IF ( fms_error_handler(
'diag_table_mod::parse_file_line',
'Incorrect file description format in diag_table.', &
535 IF ( fms_error_handler(
'diag_table_mod::parse_file_line',&
536 &
'Unallowed character in file_name in the diag_table.', err_msg) )
RETURN
540 IF ( fms_error_handler(
'diag_table_mod::parse_file_line',&
541 &
'Unallowed character in output_freq_units in the diag_table.', err_msg) )
RETURN
545 IF ( fms_error_handler(
'diag_table_mod::parse_file_line',&
546 &
'Unallowed character in time_units in the diag_table.', err_msg) )
RETURN
550 IF ( fms_error_handler(
'diag_table_mod::parse_file_line',&
551 &
'Unallowed character in long_name in the diag_table.', err_msg) )
RETURN
553 IF ( scan(
parse_file_line%new_file_freq_units, unallowed_all) > 0 )
THEN
555 IF ( fms_error_handler(
'diag_table_mod::parse_file_line',&
556 &
'Unallowed character in new_file_freq_units in the diag_table.', err_msg) )
RETURN
560 IF ( fms_error_handler(
'diag_table_mod::parse_file_line',&
561 &
'Unallowed character in start_time_s in the diag_table.', err_msg) )
RETURN
563 IF ( scan(
parse_file_line%file_duration_units, unallowed_all) > 0 )
THEN
565 IF ( fms_error_handler(
'diag_table_mod::parse_file_line',&
566 &
'Unallowed character in file_duration_units in the diag_table.', err_msg) )
RETURN
576 IF ( fms_error_handler(
'diag_table_mod::parse_file_line', &
577 &
'Invalid file format for file description in the diag_table.',&
589 IF ( fms_error_handler(
'diag_table_mod::parse_file_line',
'Invalid time axis units in diag_table.', err_msg) )&
594 IF ( fms_error_handler(
'diag_table_mod::parse_file_line',
'Invalid output frequency units in diag_table.', &
599 IF ( fms_error_handler(
'diag_table_mod::parse_file_line',
'Invalid new file frequency units in diag_table.', &
604 IF (fms_error_handler(
'diag_table_mod::parse_file_line',
'Invalid file duration units in diag_table.',err_msg))&
616 READ (
parse_file_line%start_time_s, fmt=*, iostat=mystat) year, month, day, hour, minute, second
617 IF ( mystat /= 0 )
THEN
619 IF ( fms_error_handler(
'diag_table_mod::parse_file_line',&
620 &
'Invalid start time in the file description in diag_table.', err_msg) )
RETURN
623 IF ( local_err_msg /=
'' )
THEN
625 IF ( fms_error_handler(
'diag_table_mod::parse_file_line', local_err_msg, err_msg) )
RETURN
636 END IF new_file_freq_present
646 IF ( fms_error_handler(
'diag_table_mod::parse_file_line',&
647 &
'filename_time_bounds must be "begin", "middle", "end".', err_msg) )
RETURN
661 CHARACTER(len=*),
INTENT(in) :: line
662 INTEGER,
INTENT(out),
OPTIONAL,
TARGET :: istat
666 CHARACTER(len=*),
OPTIONAL,
INTENT(out) :: err_msg
669 INTEGER,
TARGET :: mystat
670 INTEGER,
POINTER :: pstat
672 IF (
PRESENT(istat) )
THEN
682 IF ( mystat /= 0 )
THEN
684 IF ( fms_error_handler(
'diag_table_mod::parse_field_line',&
685 &
'Field description format is incorrect in diag_table.', err_msg) )
RETURN
691 IF ( fms_error_handler(
'diag_table_mod::parse_field_line',&
692 &
'Unallowed character in module_name in the diag_table.', err_msg) )
RETURN
696 IF ( fms_error_handler(
'diag_table_mod::parse_field_line',&
697 &
'Unallowed character in field_name in the diag_table.', err_msg) )
RETURN
701 IF ( fms_error_handler(
'diag_table_mod::parse_field_line',&
702 &
'Unallowed character in output_name in the diag_table.', err_msg) )
RETURN
706 IF ( fms_error_handler(
'diag_table_mod::parse_field_line',&
707 &
'Unallowed character in file_name in the diag_table.', err_msg) )
RETURN
711 IF ( fms_error_handler(
'diag_table_mod::parse_field_line',&
712 &
'Unallowed character in time_sampling in the diag_table.', err_msg) )
RETURN
716 IF ( fms_error_handler(
'diag_table_mod::parse_field_line',&
717 &
'Unallowed character in time_method in the diag_table.', err_msg) )
RETURN
721 IF ( fms_error_handler(
'diag_table_mod::parse_field_line',&
722 &
'Unallowed character in spatial_ops in the diag_table.', err_msg) )
RETURN
731 IF ( fms_error_handler(
'diag_table_mod::parse_field_line',&
732 &
'Packing is out of range for the field description in diag_table.', err_msg) )
RETURN
737 IF ( mystat /= 0 )
THEN
738 IF ( fms_error_handler(
'diag_table_mod::parse_field_line',&
739 &
'Error in regional output description for field description in diag_table.', err_msg) )
RETURN
subroutine, public init_file(name, output_freq, output_units, format, time_units, long_name, tile_count, new_file_freq, new_file_freq_units, start_time, file_duration, file_duration_units, filename_time_bounds)
Initialize the output file.