9 REAL,
PARAMETER:: missing = -9.99e9
10 INTEGER,
PARAMETER:: imissing = -999999
12 INTEGER nargs, iargc, n,i
13 CHARACTER*256,
ALLOCATABLE :: arg(:)
15 INTEGER(i_kind),
PARAMETER :: max_name_length=56,max_vars=50
19 LOGICAL :: append_suffix
21 CHARACTER*256 infn, outfn
22 LOGICAL linfile, loutfile
24 INTEGER,
PARAMETER :: inlun = 51
25 INTEGER,
PARAMETER :: outlun= 52
29 LOGICAL,
DIMENSION(:),
ALLOCATABLE :: luse
32 CHARACTER(len=max_name_length),
DIMENSION(max_vars) :: varnames
34 INTEGER :: idate,nsig,nvars,naeros,nvarsphys,nsig_plus_one,nobs
36 REAL(r_single),
ALLOCATABLE,
DIMENSION(:) :: tvp,qvp,prsltmp
37 REAL(r_single),
ALLOCATABLE,
DIMENSION(:) :: prsitmp
38 REAL(r_single),
ALLOCATABLE,
DIMENSION(:,:) :: aeros
40 INTEGER,
DIMENSION(2) :: start,count_nsig,count_nsig_plus_one
42 INTEGER :: ncfileid,ncstatus,&
43 &dimid_nsig,dimid_nsig_plus_one,dimid_nobs
45 INTEGER,
DIMENSION(2) :: dimid_2d
47 INTEGER :: ncid_tvp,ncid_qvp,ncid_prsltmp,ncid_prsitmp
48 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: ncid_aeros
55 append_suffix = .false.
62 IF (trim(arg(n)).EQ.
'-debug' ) debug=.true.
63 IF (trim(arg(n)).EQ.
'-append_nc4') append_suffix=.true.
67 IF (debug)
WRITE(*,*)
'Debugging on - Verbose Printing' 70 CALL getarg(nargs, infn)
74 WRITE(*,*)
'Input bin diag: ',trim(infn)
75 INQUIRE(file=trim(infn), exist=linfile)
76 IF (.NOT. linfile)
THEN 77 WRITE(*,*)trim(infn) //
' does not exist - exiting' 81 IF (.NOT. append_suffix)
THEN 82 outfn = infn(1:
strlen-3) //
'nc4' 84 outfn = infn(1:
strlen) //
'.nc4' 88 WRITE(*,*)
'Output NC4 diag: ',trim(outfn)
89 INQUIRE(file=trim(outfn), exist=loutfile)
90 IF (loutfile)
WRITE(*,*)
'WARNING: ' // trim(outfn) //
' exists - overwriting' 94 OPEN(inlun,file=infn,form=
'unformatted',convert=
'big_endian')
95 ncstatus = nf90_create(trim(outfn),nf90_clobber,ncid=ncfileid)
101 nvarsphys=nvars-naeros
104 ncstatus = nf90_def_dim(ncfileid,
'nsig',nsig,dimid_nsig)
105 ncstatus = nf90_def_dim(ncfileid,
'nsig_plus_one',nsig_plus_one,&
106 &dimid_nsig_plus_one)
107 ncstatus = nf90_def_dim(ncfileid,
'nobs',nf90_unlimited, dimid_nobs)
109 ALLOCATE(ncid_aeros(naeros))
111 dimid_2d=(/dimid_nsig,dimid_nobs/)
113 ncstatus = nf90_def_var(ncfileid,
"temperature",nf90_double,dimid_2d,&
115 ncstatus = nf90_def_var(ncfileid,
"humidity_mixing_ratio",nf90_double,dimid_2d,&
117 ncstatus = nf90_def_var(ncfileid,
"air_pressure",nf90_double,dimid_2d,&
121 ncstatus = nf90_def_var(ncfileid,trim(varnames(nvarsphys+i)),&
122 &nf90_double,dimid_2d,ncid_aeros(i))
125 dimid_2d=(/dimid_nsig_plus_one,dimid_nobs/)
127 ncstatus = nf90_def_var(ncfileid,
"air_pressure_levels",nf90_double,dimid_2d,&
130 ncstatus = nf90_put_att(ncfileid, nf90_global,
'date_time', idate)
132 ncstatus = nf90_enddef(ncfileid)
136 nvarsphys=nvars-naeros
138 ALLOCATE(tvp(nsig),qvp(nsig),prsltmp(nsig),prsitmp(nsig+1),&
146 count_nsig=(/nsig,1/)
147 count_nsig_plus_one=(/nsig_plus_one,1/)
149 DO WHILE (iflag == 0)
152 &tvp,qvp,prsltmp,prsitmp,aeros,iflag,debug)
154 tvp(1:nsig)=tvp(nsig:1:-1)
155 qvp(1:nsig)=qvp(nsig:1:-1)*1000_r_single
156 prsltmp(1:nsig)=prsltmp(nsig:1:-1) * 10_r_single
157 prsitmp(1:nsig+1)=prsitmp(nsig+1:1:-1) *10_r_single
158 aeros(1:nsig,:)=aeros(nsig:1:-1,:)
164 ncstatus = nf90_put_var(ncfileid,ncid_tvp,tvp,start=start,&
166 ncstatus = nf90_put_var(ncfileid,ncid_qvp,qvp,start=start,&
168 ncstatus = nf90_put_var(ncfileid,ncid_prsltmp,prsltmp,&
169 &start=start,count=count_nsig)
171 ncstatus = nf90_put_var(ncfileid,ncid_prsitmp,prsitmp,&
172 &start=start,count=count_nsig_plus_one)
175 ncstatus = nf90_put_var(ncfileid,ncid_aeros(i),aeros(:,i),&
176 &start=start,count=count_nsig)
183 print *,
'There are ',n,
' observations' 185 ncstatus = nf90_close(ncfileid)
187 DEALLOCATE(ncid_aeros,tvp,qvp,prsltmp,prsitmp,aeros)
194 100
FORMAT(
"Usage: ",/,/ &
195 " convert_aod_diag.x <options> <filename>",/,/ &
197 " -debug : Set debug verbosity",/ &
198 " -append_txt : Append .txt suffix, instead of replace last three",/ &
199 " characters (default: replaced)",/ &
200 " Note: The GMAO diag files end with .bin or .nc4,",/ &
201 " which is where fixed 3-char truncation originates",/,/,/ &
203 " convert_aod_diag.x nc_4emily.diag_hirs4_n19_ges.20161202_00z.bin",/ &
205 " nc_4emily.diag_hirs4_n19_ges.20161202_00z.nc4",/ &
215 INTEGER,
INTENT(in) :: ftin
216 INTEGER,
INTENT(out) :: idate,nsig,nvars,naeros
217 CHARACTER(len=max_name_length),
DIMENSION(max_vars) :: &
219 INTEGER,
INTENT(out) :: iflag
220 LOGICAL,
OPTIONAL,
INTENT(in) :: lverbose
225 IF(
PRESENT(lverbose)) loutall=lverbose
229 READ(ftin,iostat=iflag) nsig,nvars,naeros,idate
230 READ(ftin,iostat=iflag) varnames(1:nvars)
235 &tvp,qvp,prsltmp,prsitmp,aeros,iflag,lverbose)
238 INTEGER,
INTENT(in) :: ftin
239 INTEGER,
INTENT(in) :: nsig,nvarsphys,naeros
240 REAL(r_single),
DIMENSION(nsig) :: tvp,qvp,prsltmp
241 REAL(r_single),
DIMENSION(nsig+1) :: prsitmp
242 REAL(r_single),
DIMENSION(nsig,naeros) :: aeros
243 INTEGER,
INTENT(out) :: iflag
244 LOGICAL,
OPTIONAL,
INTENT(in) :: lverbose
249 IF(
PRESENT(lverbose)) loutall=lverbose
251 READ(ftin,iostat=iflag) tvp,qvp,prsltmp,prsitmp
252 READ(ftin,iostat=iflag) aeros
subroutine read_profiles_header(ftin, idate, nsig, nvars, naeros, varnames, iflag, lverbose)
integer, parameter, public strlen
integer, parameter, public i_kind
program gsiprofiles_bin2nc4
subroutine read_profiles(ftin, nsig, nvarsphys, naeros, tvp, qvp, prsltmp, prsitmp, aeros, iflag, lverbose)
integer, parameter, public r_single
integer, parameter, public r_kind