FV3 Bundle
nc_diag_cat.F90
Go to the documentation of this file.
1 program nc_diag_cat
2  use ncd_kinds, only: r_double
6 
7 #ifdef USE_MPI
8  use ncdc_state, only: output_file, ncid_output, ierr, cur_proc, num_procs
9  use ncdc_data_mpi, only: nc_diag_cat_data_pass, nc_diag_cat_data_commit
10 #else
13 #endif
14 
17 
18  use netcdf, only: nf90_inq_libvers, nf90_create, nf90_close, &
19  nf90_netcdf4, nf90_clobber
20 
21  implicit none
22 
23 #ifdef USE_MPI
24  include "mpif.h"
25 #endif
26 
27  ! NCDC = Net CDF Diag Concatenation
28  character(len=300) :: info_str
29 
30  real(r_double) :: start_time, stop_time
31 
32 #ifdef USE_MPI
33  ! MPI is essentially a smarter fork()... but remember, we're still
34  ! forking! That means that there WILL be multiple processes!
35 
36  ! Do MPI things:
37  ! First, initialize it!
38  call mpi_init(ierr)
39 
40  ! Get the current processor (or really, the "PC") number
41  call mpi_comm_rank(mpi_comm_world, cur_proc, ierr)
42 
43  ! Get the total number of processors / PCs
44  call mpi_comm_size(mpi_comm_world, num_procs, ierr)
45 
46  if (num_procs < 2) &
47  call ncdc_error("At least 2 processors are required to use MPI features.")
48 
49  if (num_procs < 3) &
50  call ncdc_warning("3 processors or more is needed to best use MPI features.")
51 
52  if (cur_proc == 0) &
53  call ncdc_info("Using MPI for faster concatenation.")
54 #endif
55 
56  call ncdc_info('Initializing netcdf layer library, version ' // trim(nf90_inq_libvers()) // '...')
57 
58  ! nc_diag_cat steps:
59  ! 1) Do a quick pass to read metadata, then allocate space as
60  ! necessary.
61  ! 2) Define variables with metadata. Do NOT store attributes.
62  ! 3) Read all the files, and add data to the output file.
63 
65 
66 #ifdef USE_MPI
67  if (cur_proc == 0) then
68 #endif
69  call ncdc_info("Creating new NetCDF file: " // trim(output_file))
70  call ncdc_check( nf90_create(output_file, or(nf90_netcdf4, nf90_clobber), ncid_output, &
71  0) )
72 #ifdef USE_MPI
73  end if
74 #endif
75 
76  call cpu_time(start_time)
78  call cpu_time(stop_time)
79 
80  write (info_str, "(A, F0.3, A)") "Metadata read took ", stop_time - start_time, " seconds!"
81  call ncdc_info(trim(info_str))
82 
83 #ifdef USE_MPI
84  if (cur_proc == 0) then
85 #endif
87 
88 #ifdef DEBUG
89  print *, "MAIN: trigger data pass!"
90 #endif
91 
92  call cpu_time(start_time)
94  call cpu_time(stop_time)
95 
96  write (info_str, "(A, F0.3, A)") "Data preallocation took ", stop_time - start_time, " seconds!"
97  call ncdc_info(trim(info_str))
98 #ifdef USE_MPI
99  end if
100 #endif
101 
102  call cpu_time(start_time)
104  call cpu_time(stop_time)
105 
106  write (info_str, "(A, F0.3, A)") "Data read took ", stop_time - start_time, " seconds!"
107  call ncdc_info(trim(info_str))
108 
109 #ifdef USE_MPI
110  if (cur_proc == 0) then
111 #endif
112  call cpu_time(start_time)
114  call cpu_time(stop_time)
115 
116  write (info_str, "(A, F0.3, A)") "Data commit took ", stop_time - start_time, " seconds!"
117  call ncdc_info(trim(info_str))
118 
119 #ifdef DEBUG
120  print *, "ALL DONE!"
121 #endif
122 
123  call ncdc_info("All data queued, letting NetCDF take over (and actually write)!")
124 
125  call cpu_time(start_time)
126  call ncdc_check(nf90_close(ncid_output))
127  call cpu_time(stop_time)
128 
129  write (info_str, "(A, F0.3, A)") "Final data write took ", stop_time - start_time, " seconds!"
130  call ncdc_info(trim(info_str))
131 #ifdef USE_MPI
132  endif
133 
134  call mpi_finalize(ierr)
135 #endif
136 
137  call ncdc_info("All done!")
138 end program nc_diag_cat
character(len=10000000) output_file
Definition: ncdc_state.F90:11
subroutine nc_diag_cat_process_args
subroutine nc_diag_cat_metadata_pass
integer(i_long) ncid_output
Definition: ncdc_state.F90:14
subroutine ncdc_error(err)
Definition: ncdc_climsg.F90:29
subroutine ncdc_info(ifo)
Definition: ncdc_climsg.F90:72
subroutine ncdc_warning(warn)
Definition: ncdc_climsg.F90:58
subroutine nc_diag_cat_metadata_define
subroutine ncdc_check(status)
Definition: ncdc_climsg.F90:21
program nc_diag_cat
Definition: nc_diag_cat.F90:1
subroutine nc_diag_cat_data_commit
Definition: ncdc_data.F90:401
integer, parameter, public r_double
Definition: ncd_kinds.F90:80
subroutine nc_diag_cat_metadata_alloc
subroutine nc_diag_cat_data_pass
Definition: ncdc_data.F90:30