1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122 |
- #define TRACEBACK write (gol,'("in ",a," (",a,", line",i5,")")') rname, __FILE__, __LINE__; call goErr
- #define IF_NOTOK_RETURN(action) if (status/=0) then; TRACEBACK; action; return; end if
- #define IF_ERROR_RETURN(action) if (status> 0) then; TRACEBACK; action; return; end if
- #include "tmm.inc"
- module tmm_mf_tmpp
- use GO , only : gol, goErr, goPr, goBug
- use GO , only : TDate
- use file_hdf, only : THdfFile, TSds
- implicit none
-
-
-
- private
-
- public :: TMeteoFile_tmpp
- public :: Init, Done
- public :: Get
- public :: ReadRecord
- public :: WriteRecord
-
-
-
- character(len=*), parameter :: mname = 'tmm_mf_tmpp'
-
-
-
-
- character(len=*), parameter :: output_format = 'tmm-1.0'
-
-
- integer, parameter :: iknd = 4
- integer, parameter :: rknd = 8
- integer, parameter :: iknd_ds = 2
- integer, parameter :: rknd_ds = 4
-
- character(len=*), parameter :: compression = 'deflate'
- integer, parameter :: deflate_level = 6
-
-
- type TMeteoFile_tmpp
-
- character(len=1) :: io
-
-
-
- character(len=256) :: fname
- type(THdfFile) :: hdf
- character(len=256) :: paramkeys
- type(TDate) :: trange(2)
-
-
-
- type(TSds) :: sds
- logical :: selected
- character(len=16) :: paramkey
-
-
-
- logical :: mfw_redir
-
-
-
- logical :: sstr_to_ewss_nsss
-
-
-
- logical :: spm_load
- logical :: spm_selected
- type(TSds) :: spm_sds
- logical :: spm_incl
- logical :: spm_extr
- character(len=256) :: spm_fname
- type(THdfFile) :: spm_hdf
- logical :: spm_n_to_uv
-
-
-
- logical :: output_initialised
- integer :: output_nrec
- integer :: output_ntrec
- character(len=20) :: output_names(20)
- integer :: output_nname
-
-
- integer :: fixyear
- logical :: qad
- end type TMeteoFile_tmpp
-
-
-
-
- interface Init
- module procedure mf_Init
- end interface
- interface Done
- module procedure mf_Done
- end interface
- interface Get
- module procedure mf_Get
- end interface
- interface ReadRecord
- module procedure mf_ReadRecord
- end interface
- interface WriteRecord
- module procedure mf_WriteRecord_2d
- module procedure mf_WriteRecord_3d
- end interface
- contains
-
- subroutine mf_Init( mf, io, dir, archivekeys, paramkey, &
- tref, t1, t2, status )
-
- use GO, only : TDate, Set, Get, NewDate, AnyDate, IsAnyDate
- use GO, only : rTotal, operator(-), operator(>=)
- use GO, only : goVarValue, goWriteKeyNum
-
-
- type(TMeteoFile_tmpp), intent(out) :: mf
- character(len=1), intent(in) :: io
- character(len=*), intent(in) :: dir
- character(len=*), intent(in) :: archivekeys
- character(len=*), intent(in) :: paramkey
- type(TDate), intent(in) :: tref, t1, t2
- integer, intent(out) :: status
-
-
-
- character(len=*), parameter :: rname = mname//'/mf_Init'
-
-
-
- character(len=64) :: mf_mdir, mf_tres
- character(len=64) :: mf_class, mf_type, mf_grid, mf_levs
- character(len=1) :: mf_psep, mf_nsep
- character(len=64) :: mf_filekey
-
- character(len=4) :: mf_fckey
-
- type(TDate) :: tfile
- integer :: ccyy, mm, dd, dh
- type(TDate) :: tc
- logical :: exist
-
-
-
- mf%io = io
-
-
- mf%sstr_to_ewss_nsss = .false.
- mf%mfw_redir = .false.
-
-
-
-
- mf%fixyear = -1
- call goVarValue( archivekeys, ';', 'fixyear', '=', mf%fixyear, status )
- if (status>0) then; TRACEBACK; status=1; return; end if
- mf_tres = 'no_tres'
- call goVarValue( archivekeys, ';', 'tres', '=', mf_tres, status )
- if (status>0) then; TRACEBACK; status=1; return; end if
-
- mf_class = 'no_class'
- call goVarValue( archivekeys, ';', 'class', '=', mf_class, status )
- if (status>0) then; TRACEBACK; status=1; return; end if
-
- mf_type = 'no_type'
- call goVarValue( archivekeys, ';', 'type', '=', mf_type, status )
- if (status>0) then; TRACEBACK; status=1; return; end if
-
- mf_grid = 'no_grid'
- call goVarValue( archivekeys, ';', 'grid', '=', mf_grid, status )
- if (status>0) then; TRACEBACK; status=1; return; end if
-
- mf_levs = 'no_mlevs'
- call goVarValue( archivekeys, ';', 'levs', '=', mf_levs, status )
- if (status>0) then; TRACEBACK; status=1; return; end if
-
-
- mf_psep = '/'
- call goVarValue( archivekeys, ';', 'pathsep', '=', mf_psep, status )
- if (status>0) then; TRACEBACK; status=1; return; end if
-
-
- mf_nsep = '-'
- call goVarValue( archivekeys, ';', 'namesep', '=', mf_nsep, status )
- if (status>0) then; TRACEBACK; status=1; return; end if
-
-
- mf%qad = .false.
-
-
-
-
- mf%sstr_to_ewss_nsss = .false.
- call goVarValue( archivekeys, ';', 'sstr', '=', mf%sstr_to_ewss_nsss, status )
- if (status>0) then; TRACEBACK; status=1; return; end if
-
-
-
-
- mf%spm_load = .false.
- mf%spm_incl = .false.
- mf%spm_extr = .false.
- mf%spm_n_to_uv = .false.
-
- mf_tres = '_21p06'
-
- select case ( paramkey )
- case ( 'sp', 'pu', 'pv', 'mfu', 'mfv' )
- mf_filekey = 'uvsp'
- mf%paramkeys = '-sp-pu-pv-mfu-mfv-'
- mf%spm_load = .true.
- case ( 'pw', 'mfw' )
- mf_filekey = 'w'
- mf%paramkeys = '-pw-mfw-'
- mf%spm_load = .true.
- case ( 'T' )
- mf_filekey = 't'
- mf%paramkeys = '-T-'
- mf%spm_load = .true.
- case ( 'Q' )
- mf_filekey = 'q'
- mf%paramkeys = '-Q-'
- mf%spm_load = .true.
- case ( 'CLWC', 'CIWC', 'CC', 'CCO', 'CCU', &
- 'clwc', 'ciwc', 'cc', 'cco', 'ccu' )
- mf_filekey = 'cld'
- mf%paramkeys = '-CLWC-CIWC-CC-CCO-CCU-'
- mf%spm_load = .true.
- case ( 'eu', 'ed', 'du', 'dd', 'cloud_base', 'cloud_top', 'cloud_lfs' )
- mf_filekey = 'sub'
- mf%paramkeys = '-eu-ed-du-dd-cloud_base-cloud_top-cloud_lfs-'
- mf%spm_load = .true.
- case ( 'oro', 'lsm', 'sr', 'srols', 'srmer', &
- 'cvl', 'cvh', &
- 'tv01', 'tv02', 'tv03', 'tv04', 'tv05', &
- 'tv06', 'tv07', 'tv08', 'tv09', 'tv10', &
- 'tv11', 'tv12', 'tv13', 'tv14', 'tv15', &
- 'tv16', 'tv17', 'tv18', 'tv19', 'tv20', &
- 'swvl1', &
- 'albedo', 'lsrh', 'ci', 'g10m', 'u10m', 'v10m', 'sd', &
- 'lsp', 'cp', 'sf', 'sshf', 'slhf', 'blh', &
- 't2m', 'd2m', 'ssr', 'sstr', 'src', 'raero', 'ustar', &
- 'sst', 'sps', &
- 'ewss', 'nsss' )
- mf_levs = 'sfc'
- mf_grid = 'glb1x1'
- mf_filekey = 'surf'
- mf_tres = '_21p03'
- mf%paramkeys= '-'
- mf%paramkeys= trim(mf%paramkeys)//'oro-lsm-sr-srols-srmer-'
- mf%paramkeys= trim(mf%paramkeys)//'cvl-cvh-'
- mf%paramkeys= trim(mf%paramkeys)//'tv01-tv02-tv03-tv04-tv05-'
- mf%paramkeys= trim(mf%paramkeys)//'tv06-tv07-tv08-tv09-tv10-'
- mf%paramkeys= trim(mf%paramkeys)//'tv11-tv12-tv13-tv14-tv15-'
- mf%paramkeys= trim(mf%paramkeys)//'tv16-tv17-tv18-tv19-tv20-'
- mf%paramkeys= trim(mf%paramkeys)//'swvl1-'
- mf%paramkeys= trim(mf%paramkeys)//'albedo-lsrh-ci-10fg-u10m-v10m-sd-'
- mf%paramkeys= trim(mf%paramkeys)//'lsp-cp-sf-sshf-slhf-blh-'
- mf%paramkeys= trim(mf%paramkeys)//'t2m-d2m-ssr-sstr-src-raero-ustar-'
- mf%paramkeys= trim(mf%paramkeys)//'sst-sps-'
- mf%paramkeys= trim(mf%paramkeys)//'ewss-nsss-'
- case ( 'spm' )
- mf_levs = 'ml1'
- mf_filekey = 'spm'
- mf_tres = '_00p06'
- mf%paramkeys = '-spm-'
- case default
- write (gol,'("unsupported paramkey `",a,"`")') paramkey; call goErr
- TRACEBACK; status=1; return
- end select
-
- call GetTime( mf_filekey, mf_tres, tref, t1, t2, status, &
- tfile=tfile, trange=mf%trange )
- IF_NOTOK_RETURN(status=1)
-
- if ( mf%fixyear > 0 ) call Set( tfile, year=mf%fixyear )
-
- call Get( tfile, year=ccyy, month=mm, day=dd )
-
- write (mf%fname,'(a,a,a,a,a,a,i4.4,a,i2.2,a,a,a,a,a,a,"_",i4.4,2i2.2,a,a)') &
- trim(dir), mf_psep, &
- trim(mf_class), mf_nsep, trim(mf_type), mf_nsep, &
- ccyy, mf_nsep, mm, mf_nsep, trim(mf_levs), mf_nsep, trim(mf_grid), mf_nsep, &
- trim(mf_filekey), ccyy, mm, dd, trim(mf_tres), '.hdf'
-
- mf%mfw_redir = .true.
-
- if ( mf%spm_load ) then
-
- mf%spm_extr = .true.
- write (mf%spm_fname,'(a,a,a,a,a,a,i4.4,a,i2.2,a,a,a,a,a,a,"_",i4.4,2i2.2,a,a)') &
- trim(dir), mf_psep, &
- trim(mf_class), mf_nsep, trim(mf_type), mf_nsep, &
- ccyy, mf_nsep, mm, mf_nsep, 'ml1', mf_nsep, trim(mf_grid), mf_nsep, &
- 'spm', ccyy, mm, dd, '_00p06', '.hdf'
-
- mf%spm_n_to_uv = .true.
- end if
-
- status = 0
-
- end subroutine mf_Init
-
-
-
-
- subroutine mf_Done( mf, status )
-
-
-
-
- type(TMeteoFile_tmpp), intent(inout):: mf
- integer, intent(out) :: status
-
-
- character(len=*), parameter :: rname = mname//'/mf_Done'
-
-
-
-
-
-
- status = 0
-
- end subroutine mf_Done
-
-
-
- subroutine mf_Get( mf, status, trange1, trange2, paramkeys )
-
- use GO, only : TDate
-
-
-
- type(TMeteoFile_tmpp), intent(in) :: mf
- integer, intent(out) :: status
- type(TDate), intent(out), optional :: trange1, trange2
- character(len=*), intent(out), optional :: paramkeys
-
-
-
- character(len=*), parameter :: rname = mname//'/mf_Get'
-
-
-
-
-
- if ( present(trange1) ) trange1 = mf%trange(1)
- if ( present(trange2) ) trange2 = mf%trange(2)
-
-
- if ( present(paramkeys) ) paramkeys = mf%paramkeys
-
- status = 0
-
- end subroutine mf_Get
-
-
-
-
-
-
-
-
-
-
-
-
- subroutine GetTime( filekey, tres, tref, t1, t2, status, tfile, trange, nrec )
-
- use GO, only : TDate, NewDate, AnyDate, Get, Set, wrtgol, IncrDate, IsAnyDate
- use GO, only : operator(<), operator(+), operator(-), rTotal
-
-
-
- character(len=*), intent(in) :: filekey
- character(len=*), intent(in) :: tres
- type(TDate), intent(in) :: tref, t1, t2
- integer, intent(out) :: status
-
- type(TDate), intent(out), optional :: tfile
- type(TDate), intent(out), optional :: trange(2)
- integer, intent(out), optional :: nrec
-
-
-
- character(len=*), parameter :: rname = mname//'/GetTime'
-
-
- integer :: year, month
- integer :: hour1, time6(6)
- integer :: dd, hh, step
- logical :: interval
- real :: dhr
-
-
-
- select case ( tres )
-
-
-
-
- case ( '_21p06', '_21p03', '_av21' )
-
-
-
-
-
- if ( IsAnyDate(t1) ) then
- call Get( tref, hour=hour1 )
- interval = .false.
- else
- call Get( t1, hour=hour1 )
- interval = t1 < t2
- end if
-
-
-
- if ( present(tfile) ) then
- tfile = tref
- call Set( tfile, hour=0, min=0, sec=0 )
- if ( (hour1 > 21) .or. ((interval .or. filekey=='uvsp') .and. hour1==21) ) then
- tfile = tfile + IncrDate(day=1)
- end if
- end if
-
-
-
- if ( present(trange) ) then
- trange(1) = tref
- call Set( trange(1), hour=0, min=0, sec=0 )
- if ( (hour1 > 21) .or. ((interval .or. filekey=='uvsp') .and. hour1==21) ) then
- trange(1) = trange(1) + IncrDate(day=1)
- end if
- trange(1) = trange(1) - IncrDate(hour=3)
- trange(2) = trange(1) + IncrDate(day=1)
-
- if ( filekey /= 'uvsp' ) trange(1) = trange(1) + IncrDate(mili=1)
- end if
-
-
- if ( present(nrec) ) then
- select case ( tres )
- case ( '_21p06' ) ; nrec = 24/6
- case ( '_21p03' ) ; nrec = 24/3
- case ( '_av21' ) ; nrec = 24/24
- case default
- write (gol,'("unsupported tres for setting nrec : ",a)') tres; call goErr
- TRACEBACK; status=1; return
- end select
- end if
-
-
-
-
-
- case ( 'constant' )
-
-
- if ( present(tfile) ) tfile = AnyDate()
-
-
- if ( present(trange) ) then
- trange(1) = AnyDate()
- trange(2) = AnyDate()
- end if
-
-
- if ( present(nrec) ) nrec = 1
-
-
-
-
-
- case ( 'month' )
-
-
- if ( present(tfile) ) then
- call Get( t1, year=year, month=month )
- tfile = NewDate( year=year, month=month, day=1 )
- end if
-
-
- if ( present(trange) ) then
- call Get( t1, year=year, month=month )
- trange(1) = NewDate( year=year, month=month, day=1, hour=00 )
- month = month + 1
- if ( month > 12 ) then
- year = year + 1
- month = 1
- end if
- trange(2) = NewDate( year=year, month=month, day=1, hour=00 )
- end if
-
-
- if ( present(nrec) ) nrec = 1
-
-
-
-
-
- case ( '_00p06', '_00p03', '_an0tr6', '_fg006up4tr3', '_fc012up2tr3', '00p01' )
-
-
- if ( present(tfile) ) then
- tfile = t1
- call Set( tfile, hour=0, min=0, sec=0 )
- end if
-
-
- if ( present(trange) ) then
- trange(1) = t1
- call Set( trange(1), hour=0, min=0, sec=0 )
- trange(2) = trange(1) + IncrDate(hour=24) - IncrDate(mili=1)
- end if
-
-
- if ( present(nrec) ) then
- select case ( tres )
- case ( '_00p06' ) ; nrec = 24/6
- case ( '_an0tr6' ) ; nrec = 24/6
- case ( '_00p03', '_fg006up4tr3', '_fc012up2tr3' )
-
-
-
-
-
-
-
-
-
-
- dhr = rTotal( t1 - tref, 'hour' )
- if ( dhr < 72.0 ) then
- nrec = 8
- else if ( dhr < 96 ) then
- nrec = 6
- else if ( dhr < 216 ) then
- nrec = 4
- else
- nrec = 3
- end if
- case ( '_00p01' ) ; nrec = 24/24
- case default
- write (gol,'("unsupported tres for setting nrec : ",a)') tres; call goErr
- TRACEBACK; status=1; return
- end select
- end if
-
-
-
-
-
- case default
-
- write (gol,'("unsupported time resolution key:")'); call goErr
- write (gol,'(" ",a)') trim(tres); call goErr
- TRACEBACK; status=1; return
-
- end select
-
-
-
- status = 0
-
- end subroutine GetTime
-
-
-
-
-
-
- subroutine mf_SelectRecord( mf, paramkey, t1, t2, status )
-
- use GO, only : TDate, NewDate, IncrDate, wrtgol, Set, Get, rTotal
- use GO, only : operator(-), operator(+), operator(/), operator(==), operator(/=)
- use GO, only : operator(>=), operator(<=), operator(>)
- use file_hdf, only : GetInfo
- use file_hdf, only : TSds, Select, CheckInfo, CheckAttribute, ReadAttribute
-
-
- type(TMeteoFile_tmpp), intent(inout) :: mf
- character(len=*), intent(in) :: paramkey
- type(TDate), intent(in) :: t1, t2
- integer, intent(out) :: status
-
-
-
- character(len=*), parameter :: rname = mname//'/mf_SelectRecord'
-
-
-
- integer :: nsds, isds
- integer :: time1(6), time2(6)
- type(TDate) :: tmid, treq, thelp
- type(TDate) :: t_spm
- integer :: hour, dhour
- integer :: status1, status2
- integer :: time1s(6), time2s(6)
- type(TDate) :: tim1s, tim2s
-
- mf%selected = .false.
-
- status = 1
-
- call GetInfo( mf%hdf, status, num_datasets=nsds )
- if (status/=0) then; TRACEBACK; return; end if
-
- do isds = 1, nsds
- call Select( mf%sds, mf%hdf, isds-1, status )
- if (status/=0) then; TRACEBACK; return; end if
-
- status=-1; call CheckInfo( mf%sds, status, name=paramkey )
- if (status>0) then; TRACEBACK; status=1; return; end if
-
-
- if ( status < 0 ) then
- select case ( paramkey )
- case ( 'sp', 'spm' )
- status=-1; call CheckInfo( mf%sds, status, name='ps' )
- case ( 'sps' )
- status=-1; call CheckInfo( mf%sds, status, name='sp' )
- case ( 'mfu' )
- status=-1; call CheckInfo( mf%sds, status, name='pu' )
- case ( 'mfv' )
- status=-1; call CheckInfo( mf%sds, status, name='pv' )
- case ( 'mfw' )
- status=-1; call CheckInfo( mf%sds, status, name='pw' )
- case ( 'PVo' )
- status=-1; call CheckInfo( mf%sds, status, name='PV' )
- case ( 'sr' )
- status=-1; call CheckInfo( mf%sds, status, name='sr_ecm' )
- case ( 'srols' )
- status=-1; call CheckInfo( mf%sds, status, name='sr_ols' )
- case ( 'srmer' )
- status=-1; call CheckInfo( mf%sds, status, name='sr_mer' )
- case ( 'albedo' )
- status=-1; call CheckInfo( mf%sds, status, name='al' )
- case ( 'ewss', 'nsss' )
- if ( mf%sstr_to_ewss_nsss ) then
- status=-1; call CheckInfo( mf%sds, status, name='sstr' )
- end if
- end select
- if (status>0) then; TRACEBACK; status=1; return; end if
-
- if ( status < 0 ) cycle
- end if
-
-
- select case ( paramkey )
- case ( 'oro' )
-
- case ( 'srols' )
-
-
-
-
- call ReadAttribute( mf%sds, 'time2', time2s, status )
- if (status/=0) then; TRACEBACK; return; end if
- tim2s = NewDate( time6=time2s )
-
- if ( (t1 >= tim2s) .and. (tim2s <= t2) ) then
-
- status = 0
- end if
- case default
-
- call Get( t1, time6=time1 )
- call Get( t2, time6=time2 )
-
-
- if ( mf%fixyear > 0 ) then
-
-
- if ( t1 == t2 ) then
-
- thelp = NewDate( year=time1(1), month=12, day=31, hour=21 )
- if ( t1 > thelp ) then
- time1(1) = mf%fixyear - 1
- else
- time1(1) = mf%fixyear
- end if
- time2 = time1
- else
-
- thelp = NewDate( year=time1(1), month=12, day=31, hour=21 )
- if ( t1 >= thelp ) then
- time1(1) = mf%fixyear - 1
- else
- time1(1) = mf%fixyear
- end if
- thelp = NewDate( time6=time1 ) + (t2-t1)
- call Get( thelp, time6=time2 )
- endif
- end if
-
- if ( mf%qad ) then
-
- status1=-1 ; call CheckAttribute( mf%sds, 'time1', time1, status1 )
- if (status1>0) then; TRACEBACK; status=1; return; end if
- status2=-1 ; call CheckAttribute( mf%sds, 'time2', time2, status2 )
- if (status2>0) then; TRACEBACK; status=1; return; end if
- status = status1 + status2
-
- if ( status < 0 ) then
-
- call ReadAttribute( mf%sds, 'time1', time1s, status )
- if (status/=0) then; TRACEBACK; return; end if
- call ReadAttribute( mf%sds, 'time2', time2s, status )
- if (status/=0) then; TRACEBACK; return; end if
-
- if ( (time1s(4) /= time1(4)) .or. (time2s(4) /= time2(4)) ) then
- status = -1
- cycle
- end if
-
- write (gol,'("WARNING - weak time check passed:")'); call goPr
- write (gol,'("WARNING - parameter : ",a)') trim(paramkey); call goPr
- call wrtgol( 'WARNING - t1 : ', t1 ); call goPr
- call wrtgol( 'WARNING - t2 : ', t2 ); call goPr
- write (gol,'("WARNING - file : ",a)') trim(mf%fname); call goPr
-
- status = 0
- end if
-
- else
-
-
-
-
-
-
-
-
- status1=-1 ; call CheckAttribute( mf%sds, 'time1', time1, status1 )
- if (status1>0) then; TRACEBACK; status=1; return; end if
- status2=-1 ; call CheckAttribute( mf%sds, 'time2', time2, status2 )
- if (status2>0) then; TRACEBACK; status=1; return; end if
- status = status1 + status2
-
- if ( status < 0 ) then
- if ( t1 == t2 ) then
-
- call ReadAttribute( mf%sds, 'time1', time1s, status )
- IF_NOTOK_RETURN(status=1)
- tim1s = NewDate( time6=time1s )
- call ReadAttribute( mf%sds, 'time2', time2s, status )
- IF_NOTOK_RETURN(status=1)
- tim2s = NewDate( time6=time2s )
-
- tmid = tim1s + (tim2s-tim1s)/2
-
- treq = t1
- if ( mf%fixyear > 0 ) call Set( treq, year=mf%fixyear )
-
- if ( treq /= tmid ) then
- status = -1
- cycle
- end if
- else
-
- tmid = t1 + (t2-t1)/2
- if ( mf%fixyear > 0 ) call Set( tmid, year=mf%fixyear )
- call Get( tmid, time6=time1 )
- status1=-1 ; call CheckAttribute( mf%sds, 'time1', time1, status1 )
- if (status1>0) then; TRACEBACK; status=1; return; end if
- status2=-1 ; call CheckAttribute( mf%sds, 'time2', time1, status2 )
- if (status2>0) then; TRACEBACK; status=1; return; end if
- status = status1 + status2
- if ( status < 0 ) cycle
- end if
- end if
-
- end if
- end select
-
-
- exit
- end do
-
- if ( status /= 0 ) then
- write (gol,'("Unable to locate field in hdf file:")'); call goErr
- write (gol,'(" parameter : ",a)') trim(paramkey); call goErr
- call wrtgol( ' t1 : ', t1 ); call goErr
- call wrtgol( ' t2 : ', t2 ); call goErr
- call wrtgol( ' mf%tr(1) : ', mf%trange(1) ); call goErr
- call wrtgol( ' mf%tr(2) : ', mf%trange(2) ); call goErr
- write (gol,'(" file : ",a)') trim(mf%fname); call goErr
- TRACEBACK; status = 1; return
- end if
-
-
- mf%paramkey = paramkey
-
-
- mf%selected = .true.
-
-
-
-
- if ( mf%spm_load ) then
-
- mf%spm_selected = .false.
- if ( paramkey /= 'sp' ) then
-
- dhour = nint(rTotal(t2-t1,'hour'))
- select case ( dhour )
- case ( 0 )
- t_spm = t1
- case ( 3 )
- call Get( t1, hour=hour )
- if ( modulo(hour,6) == 0 ) then
- t_spm = t1
- else
- t_spm = t2
- end if
- case ( 6 )
- t_spm = t1 + IncrDate( hour=3 )
- case default
- write (gol,'("do not know how to form time for mid surface pressure:")'); call goErr
- call wrtgol( ' t1 : ', t1 ); call goErr
- call wrtgol( ' t2 : ', t2 ); call goErr
- TRACEBACK; status = 1; return
- end select
-
- if ( mf%fixyear > 0 ) then
- call Set( t_spm, year=mf%fixyear )
- end if
-
- status = 1
-
- if ( mf%spm_extr ) then
- call GetInfo( mf%spm_hdf, status, num_datasets=nsds )
- else
- call GetInfo( mf%hdf, status, num_datasets=nsds )
- end if
- if (status/=0) then; TRACEBACK; return; end if
-
- do isds = 1, nsds
-
-
- if ( mf%spm_extr ) then
- call Select( mf%spm_sds, mf%spm_hdf, isds-1, status )
- else
- call Select( mf%spm_sds, mf%hdf, isds-1, status )
- end if
- if (status/=0) then; TRACEBACK; return; end if
-
- status=-1; call CheckInfo( mf%spm_sds, status, name='ps' )
- if (status>0) then; TRACEBACK; status=1; return; end if
-
-
- if ( status < 0) then
- select case ( paramkey )
- case ( 'mfu', 'pu' )
- status=-1; call CheckInfo( mf%spm_sds, status, name='spu' )
- case ( 'mfv', 'pv' )
- status=-1; call CheckInfo( mf%spm_sds, status, name='spv' )
- case default
- status=-1; call CheckInfo( mf%spm_sds, status, name='sp' )
- end select
- if (status>0) then; TRACEBACK; status=1; return; end if
-
- if ( status < 0 ) cycle
- end if
-
- call Get( t1, time6=time1 )
- status=-1; call CheckAttribute( mf%spm_sds, 'time1', time1, status )
- if (status>0) then; TRACEBACK; status=1; return; end if
- if (status==0) then
- call Get( t2, time6=time1 )
- status=-1; call CheckAttribute( mf%spm_sds, 'time2', time2, status )
- if (status>0) then; TRACEBACK; status=1; return; end if
- else
-
- call Get( t_spm, time6=time1 )
- status=-1; call CheckAttribute( mf%spm_sds, 'time1', time1, status )
- if (status<0) cycle
- if (status>0) then; TRACEBACK; status=1; return; end if
-
- call Get( t_spm, time6=time2 )
- status=-1; call CheckAttribute( mf%spm_sds, 'time2', time2, status )
- if (status<0) cycle
- if (status>0) then; TRACEBACK; status=1; return; end if
- end if
-
- exit
- end do
-
- if ( status /= 0 ) then
- write (gol,'("Unable to locate surface pressure field in hdf file:")'); call goErr
- call wrtgol( ' t1 - t2 : ', t1, ' - ', t2 ); call goErr
- call wrtgol( ' t_spm : ', t_spm ); call goErr
- write (gol,'(" file : ",a)') trim(mf%spm_fname); call goErr
- TRACEBACK; status = 1; return
- end if
-
- mf%spm_selected = .true.
-
- end if
-
- end if
-
-
-
-
- status = 0
- end subroutine mf_SelectRecord
-
-
-
-
-
-
-
- subroutine lli_Init_mf( lli, nuv, mf, status )
-
- use file_hdf, only : ReadAttribute, CheckAttribute
- use Grid, only : TllGridInfo, Init
-
-
- type(TllGridInfo), intent(inout) :: lli
- character(len=1), intent(in) :: nuv
- type(TMeteoFile_tmpp), intent(in) :: mf
- integer, intent(out) :: status
-
-
-
- character(len=*), parameter :: rname = mname//'/lli_Init_mf'
-
-
-
- real :: lon_deg, dlon_deg
- integer :: nlon
- real :: lat_deg, dlat_deg
- integer :: nlat
- integer :: stat
-
-
-
- if ( .not. mf%selected ) then
- write (gol,'("no record selected ...")'); call goErr
- TRACEBACK; status = 1; return
- end if
-
-
- call CheckAttribute( mf%sds, 'gridtype' , 'll', status )
- if ( status /= 0 ) then
- write (gol,'("sds does not seem to contain ll grid")'); call goErr
- TRACEBACK; status=1; return
- end if
-
- call ReadAttribute( mf%sds, 'lon_first', lon_deg , status )
- if (status/=0) then; TRACEBACK; return; end if
- call ReadAttribute( mf%sds, 'lon_inc ', dlon_deg, status )
- if (status/=0) then; TRACEBACK; return; end if
- call ReadAttribute( mf%sds, 'lon_n ', nlon , status )
- if (status/=0) then; TRACEBACK; return; end if
- call ReadAttribute( mf%sds, 'lat_first', lat_deg , status )
- if (status/=0) then; TRACEBACK; return; end if
- call ReadAttribute( mf%sds, 'lat_inc ', dlat_deg, status )
- if (status/=0) then; TRACEBACK; return; end if
- call ReadAttribute( mf%sds, 'lat_n ', nlat , status )
- if (status/=0) then; TRACEBACK; return; end if
-
-
-
-
- select case ( nuv )
- case ( 'n' )
-
- call Init( lli, lon_deg, dlon_deg, nlon, &
- lat_deg, dlat_deg, nlat, status )
- if (status/=0) then; TRACEBACK; return; end if
- case ( 'u' )
-
- call Init( lli, lon_deg+0.5*dlon_deg, dlon_deg, nlon-1, &
- lat_deg , dlat_deg, nlat , status )
- if (status/=0) then; TRACEBACK; return; end if
- case ( 'v' )
-
- call Init( lli, lon_deg , dlon_deg, nlon , &
- lat_deg+0.5*dlat_deg, dlat_deg, nlat-1, status )
- if (status/=0) then; TRACEBACK; return; end if
- case default
- write (gol,'("unsupported nuv `",a,"`")') nuv; call goErr
- TRACEBACK; status=1; return
- end select
-
-
- status = 0
-
- end subroutine lli_Init_mf
-
-
-
-
-
-
-
-
- subroutine levi_Init_mf( levi, mf, status )
-
- use file_hdf, only : GetInfo, ReadAttribute
- use Grid, only : TLevelInfo, Init
-
-
- type(TLevelInfo), intent(out) :: levi
- type(TMeteoFile_tmpp), intent(in) :: mf
- integer, intent(out) :: status
-
-
-
- character(len=*), parameter :: rname = mname//'/levi_Init_mf'
-
-
-
- integer :: data_rank
- integer :: lm
- real, allocatable :: a(:), b(:)
-
-
-
-
- if ( .not. mf%selected ) then
- write (gol,'("no record selected ...")'); call goErr
- TRACEBACK; status = 1; return
- end if
-
-
- call GetInfo( mf%sds, status, data_rank=data_rank )
- if ( status/= 0 ) then; TRACEBACK; status=1; return; end if
-
-
- select case ( data_rank )
-
- case ( 2 )
-
-
- call Init( levi, 1, (/0.0,0.0/), (/0.0,0.0/), status )
- if ( status/= 0 ) then; TRACEBACK; status=1; return; end if
- case ( 3 )
-
-
- call ReadAttribute( mf%sds, 'lm', lm, status )
-
- allocate( a(lm+1), b(lm+1) )
- call ReadAttribute( mf%sds, 'at', a, status )
- if (status/=0) then; TRACEBACK; return; end if
- call ReadAttribute( mf%sds, 'bt', b, status )
- if (status/=0) then; TRACEBACK; return; end if
-
- call Init( levi, lm, a, b, status )
- if ( status/= 0 ) then; TRACEBACK; status=1; return; end if
-
- deallocate( a, b )
-
- case default
-
- write (gol,'("unsupported data rank : ",i6)') data_rank; call goErr
- TRACEBACK; status=1; return
- end select
-
-
- status = 0
-
- end subroutine levi_Init_mf
-
-
-
- subroutine mf_GetField( mf, status, gridtype, ll, spm )
-
- use PArray, only : pa_SetShape
- use file_hdf, only : GetInfo, ReadData, ReadAttribute
-
- type(TMeteoFile_tmpp), intent(inout) :: mf
- integer, intent(out) :: status
- character(len=*), intent(out), optional :: gridtype
- real, pointer, optional :: ll(:,:,:)
- real, pointer, optional :: spm(:,:)
-
-
-
- character(len=*), parameter :: rname = mname//'/mf_GetField'
-
-
-
- integer :: data_rank
- integer :: data_dims(3)
-
-
- if ( .not. mf%selected ) then
- write (gol,'("no record selected ...")'); call goErr
- TRACEBACK; status = 1; return
- end if
-
-
- status = 1
-
-
- if ( present(gridtype) ) then
- call ReadAttribute( mf%sds, 'gridtype', gridtype, status )
- if (status/=0) then; TRACEBACK; return; end if
- end if
-
-
- if ( present(ll) ) then
-
- call GetInfo( mf%sds, status, data_rank=data_rank, data_dims=data_dims )
- if (status/=0) then; TRACEBACK; return; end if
-
- select case ( data_rank )
- case ( 2 )
- data_dims(3) = 1
- call pa_SetShape( ll, data_dims )
- call ReadData( mf%sds, ll(:,:,1), status )
- if (status/=0) then; TRACEBACK; return; end if
- case ( 3 )
- call pa_SetShape( ll, data_dims )
- call ReadData( mf%sds, ll, status )
- if (status/=0) then; TRACEBACK; return; end if
- case default
- write (gol,'("unsupported data rank:",i6)') data_rank; call goErr
- TRACEBACK; status=1; return
- end select
-
- status = 0
- end if
-
- if ( present(spm) ) then
- if ( .not. mf%spm_selected ) then
- write (gol,'("no spm record selected ...")'); call goErr
- TRACEBACK; status = 1; return
- end if
-
- call GetInfo( mf%spm_sds, status, data_rank=data_rank, data_dims=data_dims )
- if (status/=0) then; TRACEBACK; return; end if
-
- select case ( data_rank )
- case ( 2 )
- call pa_SetShape( spm, data_dims(1:2) )
- call ReadData( mf%spm_sds, spm, status )
- if (status/=0) then; TRACEBACK; return; end if
- case default
- write (gol,'("unsupported data rank for spm:",i6)') data_rank; call goErr
- TRACEBACK; status=1; return
- end select
-
- status = 0
- end if
-
-
- if ( status /= 0 ) then
- write (gol,'("no arguments processed; wrong call ?")'); call goErr
- TRACEBACK; status = 1; return
- end if
-
-
- status = 0
- end subroutine mf_GetField
-
-
-
-
- subroutine mf_ReadRecord( mf, paramkey, t1, t2, nuv, nw, &
- gridtype, levi, &
- lli, ll, sp_ll, &
- status )
- use PArray, only : pa_Done
- use GO, only : TDate
- use Grid, only : TllGridInfo, TLevelInfo
- use file_hdf_base, only : Init, Done
-
-
- type(TMeteoFile_tmpp), intent(inout) :: mf
- character(len=*), intent(in) :: paramkey
- type(TDate), intent(in) :: t1, t2
- character(len=1), intent(in) :: nuv
- character(len=2), intent(out) :: gridtype
- type(TLevelInfo), intent(out) :: levi
- character(len=1), intent(in) :: nw
- type(TllGridInfo), intent(inout) :: lli
- real, pointer :: ll(:,:,:)
- real, pointer :: sp_ll(:,:)
- integer, intent(out) :: status
-
-
- character(len=*), parameter :: rname = mname//'/mf_ReadRecord'
-
-
-
- logical :: exist
-
- real, allocatable :: mfw_n(:,:,:)
-
- real, allocatable :: sp_ll_n(:,:)
- integer :: i, j
-
-
-
- if ( mf%io /= 'i' ) then
- write (gol,'("file should have been opened for input, but io=",a)') mf%io; call goErr
- TRACEBACK; status=1; return
- end if
-
-
-
- inquire( file=trim(mf%fname), exist=exist )
- if ( .not. exist ) then
- write (gol,'("main file does not exist:")'); call goErr
- write (gol,'(" ",a)') trim(mf%fname); call goErr
- TRACEBACK; status=1; return
- end if
-
- call Init( mf%hdf, trim(mf%fname), 'read', status )
- if (status/=0) then; TRACEBACK; return; end if
-
- call Init( mf%sds, status )
- if (status/=0) then; TRACEBACK; return; end if
-
- mf%selected = .false.
-
-
- if ( mf%spm_load ) then
-
- if ( mf%spm_extr ) then
-
- inquire( file=trim(mf%spm_fname), exist=exist )
- if ( .not. exist ) then
- write (gol,'("spm file does not exist:")'); call goErr
- write (gol,'(" ",a)') trim(mf%spm_fname); call goErr
- TRACEBACK; status=1; return
- end if
-
- call Init( mf%spm_hdf, trim(mf%spm_fname), 'read', status )
- if (status/=0) then; TRACEBACK; return; end if
-
- end if
-
- call Init( mf%spm_sds, status )
- if (status/=0) then; TRACEBACK; return; end if
-
- mf%spm_selected = .false.
- end if
-
- call mf_SelectRecord( mf, paramkey, t1, t2, status )
- if ( status/= 0 ) then; TRACEBACK; status=1; return; end if
-
- gridtype = 'll'
-
-
- call lli_Init_mf( lli, nuv, mf, status )
- if ( status/= 0 ) then; TRACEBACK; status=1; return; end if
-
-
- call levi_Init_mf( levi, mf, status )
- if ( status/= 0 ) then; TRACEBACK; status=1; return; end if
-
- call mf_GetField( mf, status, ll=ll )
- if ( status/= 0 ) then; TRACEBACK; status=1; return; end if
-
-
-
-
- if ( (paramkey == 'mfw') .or. (paramkey == 'pw') ) then
-
-
- if ( size(ll,3) == levi%nlev ) then
-
- allocate( mfw_n(lli%im,lli%jm,levi%nlev) )
- mfw_n = ll
-
- deallocate( ll )
- allocate( ll(lli%nlon,lli%nlat,levi%nlev+1) )
-
- ll(:,:,1:levi%nlev) = mfw_n
- ll(:,:,levi%nlev+1) = 0.0
-
- deallocate( mfw_n )
- end if
-
-
- if ( mf%mfw_redir ) ll = - ll
-
- end if
-
-
- if ( ((paramkey=='ewss') .or. (paramkey=='nsss')) .and. mf%sstr_to_ewss_nsss ) then
-
-
- ll = sqrt( (ll**2) / 2.0 )
- end if
-
-
-
-
- if ( mf%spm_load .and. mf%spm_selected ) then
-
- call mf_GetField( mf, status, spm=sp_ll )
- if ( status/= 0 ) then; TRACEBACK; status=1; return; end if
-
-
- if ( mf%spm_n_to_uv ) then
- select case ( nuv )
- case ( 'n' )
-
- case ( 'u' )
-
- allocate( sp_ll_n(lli%im,lli%jm) )
- sp_ll_n = sp_ll
-
- deallocate( sp_ll )
- allocate( sp_ll(0:lli%im,lli%jm) )
-
- sp_ll(0,:) = 1.5*sp_ll_n(1,:) - 0.5*sp_ll_n(2,:)
- do i = 1, lli%im-1
- sp_ll(i,:) = 1.5*sp_ll_n(i,:) + 0.5*sp_ll_n(i+1,:)
- end do
- sp_ll(lli%im,:) = -0.5*sp_ll_n(lli%im-1,:) + 1.5*sp_ll_n(lli%im,:)
-
- deallocate( sp_ll_n )
- case ( 'v' )
-
- allocate( sp_ll_n(lli%im,lli%jm) )
- sp_ll_n = sp_ll
-
- deallocate( sp_ll )
- allocate( sp_ll(lli%im,0:lli%jm) )
-
- sp_ll(:,0) = 1.5*sp_ll_n(:,1) - 0.5*sp_ll_n(:,2)
- do j = 1, lli%jm-1
- sp_ll(:,j) = 1.5*sp_ll_n(:,j) + 0.5*sp_ll_n(:,j+1)
- end do
- sp_ll(:,lli%jm) = -0.5*sp_ll_n(:,lli%jm-1) + 1.5*sp_ll_n(:,lli%jm)
-
- deallocate( sp_ll_n )
- case default
- write (gol,'("unsupported nuv `",a,"`")') nuv; call goErr
- TRACEBACK; status=1; return
- end select
- end if
-
- else
- call pa_Done( sp_ll )
- end if
-
-
- if ( mf%spm_load ) then
- call Done( mf%spm_sds, status )
- if (status/=0) then; TRACEBACK; return; end if
-
- if ( mf%spm_extr ) then
- call Done( mf%spm_hdf, status )
- if (status/=0) then; TRACEBACK; return; end if
- end if
- end if
-
- call Done( mf%sds, status )
- if (status/=0) then; TRACEBACK; return; end if
- call Done( mf%hdf, status )
- if (status/=0) then; TRACEBACK; return; end if
-
-
- status = 0
- end subroutine mf_ReadRecord
-
-
-
-
-
-
-
- subroutine WriteHeader( mf, lli, status, levi )
- use Binas, only : grav, ae
- use Grid, only : TllGridInfo, TLevelInfo
- use file_hdf, only : WriteAttribute
-
-
- type(TMeteoFile_tmpp), intent(inout) :: mf
- type(TllGridInfo), intent(in) :: lli
- integer, intent(out) :: status
- type(TLevelInfo), intent(in), optional :: levi
-
-
- character(len=*), parameter :: rname = mname//'/WriteHeader'
-
-
-
-
- call WriteAttribute( mf%hdf, 'fname' , trim(mf%fname), status )
- if (status/=0) then; TRACEBACK; return; end if
- call WriteAttribute( mf%hdf, 'format' , output_format, status )
- if (status/=0) then; TRACEBACK; return; end if
- call WriteAttribute( mf%hdf, 'gridtype', 'll' , status )
- if (status/=0) then; TRACEBACK; return; end if
-
- call WriteAttribute( mf%hdf, 'lonmin', lli%lon_deg(1) , status, knd=rknd )
- if (status/=0) then; TRACEBACK; return; end if
- call WriteAttribute( mf%hdf, 'lonmax', lli%lon_deg(lli%nlon), status, knd=rknd )
- if (status/=0) then; TRACEBACK; return; end if
- call WriteAttribute( mf%hdf, 'latmin', lli%lat_deg(1) , status, knd=rknd )
- if (status/=0) then; TRACEBACK; return; end if
- call WriteAttribute( mf%hdf, 'latmax', lli%lat_deg(lli%nlat), status, knd=rknd )
- if (status/=0) then; TRACEBACK; return; end if
-
- call WriteAttribute( mf%hdf, 'grav' , grav , status, knd=rknd )
- if (status/=0) then; TRACEBACK; return; end if
- call WriteAttribute( mf%hdf, 'ae' , ae , status, knd=rknd )
- if (status/=0) then; TRACEBACK; return; end if
- call WriteAttribute( mf%hdf, 'area_m2', lli%area_m2, status, knd=rknd )
- if (status/=0) then; TRACEBACK; return; end if
-
- if ( present(levi) ) then
- call WriteAttribute( mf%hdf, 'lm', levi%nlev, status, knd=iknd )
- if (status/=0) then; TRACEBACK; return; end if
- call WriteAttribute( mf%hdf, 'at', levi%a , status, knd=rknd )
- if (status/=0) then; TRACEBACK; return; end if
- call WriteAttribute( mf%hdf, 'bt', levi%b , status, knd=rknd )
- if (status/=0) then; TRACEBACK; return; end if
- end if
-
- status = 0
- end subroutine WriteHeader
-
-
-
- subroutine WriteSdsHeader( sds, tmi, unit, tref, t1, t2, lli, nuv, status, &
- levi, nw, nlev )
- use Binas , only : p_global
- use file_hdf, only : TSds
- use file_hdf, only : SetDim, WriteAttribute, Compress
- use GO , only : TDate, Get, rTotal, operator(-), IsAnyDate
- use Grid , only : TllGridInfo, TLevelInfo
- use tmm_info, only : TMeteoInfo
-
-
- type(TSds), intent(inout) :: sds
- type(TMeteoInfo), intent(in) :: tmi
- character(len=*), intent(in) :: unit
- type(TDate), intent(in) :: tref, t1, t2
- type(TllGridInfo), intent(in) :: lli
- character(len=1), intent(in) :: nuv
- integer, intent(out) :: status
- type(TLevelInfo), intent(in), optional :: levi
- character(len=1), intent(in), optional :: nw
- integer, intent(in), optional :: nlev
-
-
-
- character(len=*), parameter :: rname = mname//'/WriteSdsHeader'
-
-
-
- integer :: time6(6)
- integer :: dhour
-
-
-
-
-
- if ( len_trim(tmi%history) < 1 ) then
- call WriteAttribute( sds, 'history', '-', status )
- IF_NOTOK_RETURN(status=1)
- else
- call WriteAttribute( sds, 'history', trim(tmi%history), status )
- IF_NOTOK_RETURN(status=1)
- end if
-
-
-
-
- call WriteAttribute( sds, 'unit', unit, status )
- IF_NOTOK_RETURN(status=1)
-
-
-
- if ( IsAnyDate(t1) .or. IsAnyDate(t2) ) then
- dhour = 0
- else
- dhour = nint(rTotal( t2 - t2, 'hour' ))
- end if
-
-
- call Get( t1, time6=time6 )
- call WriteAttribute( sds, 'idate', time6, status, knd=iknd )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'dthrs', dhour, status, knd=iknd )
- IF_NOTOK_RETURN(status=1)
-
-
- call Get( tref, time6=time6 )
- call WriteAttribute( sds, 'tref', time6, status, knd=iknd )
- IF_NOTOK_RETURN(status=1)
- call Get( t1, time6=time6 )
- call WriteAttribute( sds, 'time1', time6, status, knd=iknd )
- IF_NOTOK_RETURN(status=1)
- call Get( t2, time6=time6 )
- call WriteAttribute( sds, 'time2', time6, status, knd=iknd )
- IF_NOTOK_RETURN(status=1)
- time6 = 0
- time6(4) = dhour
- call WriteAttribute( sds, 'dtime', time6, status, knd=iknd )
- IF_NOTOK_RETURN(status=1)
-
-
-
- select case ( nuv )
- case ( 'n' )
-
- call SetDim( sds, 1-1, 'LON' , 'deg', lli%lon_deg, status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- call SetDim( sds, 2-1, 'LAT' , 'deg', lli%lat_deg, status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
-
- call WriteAttribute( sds, 'gridtype' , 'll' , status )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'lon_first', lli%lon_deg(1), status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'lon_inc ', lli%dlon_deg , status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'lon_n ', lli%nlon , status, knd=iknd )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'lat_first', lli%lat_deg(1), status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'lat_inc ', lli%dlat_deg , status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'lat_n ', lli%nlat , status, knd=iknd )
- IF_NOTOK_RETURN(status=1)
- case ( 'u' )
-
- call SetDim( sds, 1-1, 'LONP1' , 'deg', lli%blon_deg, status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- call SetDim( sds, 2-1, 'LAT' , 'deg', lli%lat_deg , status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
-
- call WriteAttribute( sds, 'gridtype' , 'll', status )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'lon_first', lli%blon_deg(0), status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'lon_inc ', lli%dlon_deg , status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'lon_n ', lli%im+1 , status, knd=iknd )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'lat_first', lli%lat_deg(1) , status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'lat_inc ', lli%dlat_deg , status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'lat_n ', lli%nlat , status, knd=iknd )
- IF_NOTOK_RETURN(status=1)
- case ( 'v' )
-
- call SetDim( sds, 1-1, 'LON' , 'deg', lli%lon_deg , status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- call SetDim( sds, 2-1, 'LATP1' , 'deg', lli%blat_deg, status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
-
- call WriteAttribute( sds, 'gridtype' , 'll', status )
- call WriteAttribute( sds, 'lon_first', lli%lon_deg(1) , status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'lon_inc ', lli%dlon_deg , status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'lon_n ', lli%nlon , status, knd=iknd )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'lat_first', lli%blat_deg(0), status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'lat_inc ', lli%dlat_deg , status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'lat_n ', lli%jm+1 , status, knd=iknd )
- IF_NOTOK_RETURN(status=1)
- case default
- write (gol,'("unsupported nuv `",a,"`")') nuv; call goErr
- TRACEBACK; status=1; return
- end select
-
-
-
- if ( present(levi) ) then
- if ( .not. present(nw) ) then
- write (gol,'("optional levi requires nw")'); call goErr
- TRACEBACK; status=1; return
- end if
-
- select case ( nw )
- case ( '*' )
- if ( present(nlev) ) then
- call SetDim( sds, 3-1, 'HYBRID_SELECTED', 'Pa' , levi%fp0(1:nlev), status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- end if
- case ( 'n' )
- call SetDim( sds, 3-1, 'HYBRID', 'Pa' , levi%fp0, status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- case ( 'w' )
- call SetDim( sds, 3-1, 'HYBRIDh', 'Pa', levi%p0, status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- case default
- write (gol,'("unsupported nw `",a,"` xxx")') nw; call goErr
- TRACEBACK; status=1; return
- end select
-
- call WriteAttribute( sds, 'lm', levi%nlev, status, knd=iknd )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'at', levi%a , status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- call WriteAttribute( sds, 'bt', levi%b , status, knd=rknd )
- IF_NOTOK_RETURN(status=1)
- end if
-
-
-
- call Compress( sds, compression, status, deflate_level=deflate_level )
- IF_NOTOK_RETURN(status=1)
-
-
-
-
- status = 0
-
- end subroutine WriteSdsHeader
-
-
-
-
-
- subroutine WriteStatus( mf, msg, status )
-
-
- type(TMeteoFile_tmpp), intent(inout) :: mf
- character(len=*), intent(in) :: msg
- integer, intent(out) :: status
-
-
- character(len=*), parameter :: rname = mname//'/WriteStatus'
-
-
-
- integer :: fu
- logical :: opened
-
-
-
- fu = 1234
- do
- inquire( unit=fu, opened=opened )
- if ( .not. opened ) exit
- fu = fu + 1
- end do
-
- open( fu, file=trim(mf%fname)//'.status', form='formatted', iostat=status )
- if (status/=0) then
- write (gol,'("opening status file:")'); call goErr
- write (gol,'(" file : ",a)') trim(mf%fname); call goErr
- TRACEBACK; status=1; return
- end if
-
- write (fu,'(a)',iostat=status) msg
- if (status/=0) then
- write (gol,'("writing status:")'); call goErr
- write (gol,'(" file : ",a)') trim(mf%fname); call goErr
- write (gol,'(" msg : ",a)') msg; call goErr
- TRACEBACK; status=1; return
- end if
-
- close( fu, iostat=status )
- if (status/=0) then
- write (gol,'("closing status file:")'); call goErr
- write (gol,'(" file : ",a)') trim(mf%fname); call goErr
- TRACEBACK; status=1; return
- end if
-
- status = 0
- end subroutine WriteStatus
-
-
-
-
- subroutine AddOutputName( mf, name, status )
-
-
- type(TMeteoFile_tmpp), intent(inout) :: mf
- character(len=*), intent(in) :: name
- integer, intent(out) :: status
-
-
- character(len=*), parameter :: rname = mname//'/AddOuputName'
-
-
-
- integer :: iname
-
-
-
- iname = 1
- do
-
- if ( iname > mf%output_nname ) then
-
- if ( iname > size(mf%output_names) ) then
- write (gol,'("length of mf%output_names array too small:")'); call goErr
- do iname = 1, size(mf%output_names)
- write (gol,'(" ",i3," ",a)') iname, trim(mf%output_names(iname)); call goErr
- end do
- TRACEBACK; status=1; return
- end if
-
- if ( len(mf%output_names(iname)) < len(name) ) then
- write (gol,'("length of mf%output_names too small:")'); call goErr
- write (gol,'(" len(mf%output_names(i)) : ",i4)') len(mf%output_names(iname)); call goErr
- write (gol,'(" len(mname) : ",i4)') len(name); call goErr
- TRACEBACK; status=1; return
- end if
-
- mf%output_names(iname) = name
-
- mf%output_nname = iname
-
- exit
- end if
-
- if ( mf%output_names(iname) == name ) exit
-
- iname = iname + 1
- end do
-
- status = 0
- end subroutine AddOutputName
-
-
-
-
- subroutine mf_WriteRecord_2d( mf, tmi, paramkey, unit, tref, t1, t2, &
- lli, nuv, ll, status )
- use GO , only : TDate
- use Grid , only : TllGridInfo
- use file_hdf, only : TSds, WriteData
- use file_hdf_base, only : Init, Done
- use tmm_info, only : TMeteoInfo
-
-
- type(TMeteoFile_tmpp), intent(inout) :: mf
- type(TMeteoInfo), intent(in) :: tmi
- character(len=*), intent(in) :: paramkey, unit
- type(TDate), intent(in) :: tref, t1, t2
- type(TllGridInfo), intent(in) :: lli
- character(len=1), intent(in) :: nuv
- real, intent(in) :: ll(:,:)
- integer, intent(out) :: status
-
-
- character(len=*), parameter :: rname = mname//'/mf_WriteRecord_2d'
-
-
-
- type(TSds) :: sds
-
-
-
- if ( mf%io /= 'o' ) then
- write (gol,'("file should have been opened for output, but io=",a)') mf%io; call goErr
- TRACEBACK; status=1; return
- end if
-
-
- if ( .not. mf%output_initialised ) then
-
- call Init( mf%hdf, trim(mf%fname), 'create', status )
- IF_NOTOK_RETURN(status=1)
-
- call WriteHeader( mf, lli, status )
- IF_NOTOK_RETURN(status=1)
-
- call WriteStatus( mf, 'in-progress', status )
- IF_NOTOK_RETURN(status=1)
-
- mf%output_nrec = 0
-
- mf%output_initialised = .true.
- else
-
- call Init( mf%hdf, trim(mf%fname), 'write', status )
- IF_NOTOK_RETURN(status=1)
- endif
-
-
-
-
- call AddOutputName( mf, paramkey, status )
- IF_NOTOK_RETURN(status=1)
-
- call Init( sds, mf%hdf, paramkey, shape(ll), 'real', status, knd=rknd_ds )
- IF_NOTOK_RETURN(status=1)
-
- call WriteSdsHeader( sds, tmi, unit, tref, t1, t2, lli, nuv, status )
- IF_NOTOK_RETURN(status=1)
-
-
- call WriteData( sds, ll, status )
- IF_NOTOK_RETURN(status=1)
-
-
- call Done( sds, status )
- IF_NOTOK_RETURN(status=1)
-
-
-
-
- mf%output_nrec = mf%output_nrec + 1
-
-
- if ( mf%output_nrec == mf%output_ntrec*mf%output_nname ) then
- call WriteStatus( mf, 'completed', status )
- IF_NOTOK_RETURN(status=1)
- end if
-
-
- call Done( mf%hdf, status )
- IF_NOTOK_RETURN(status=1)
-
- status = 0
- end subroutine mf_WriteRecord_2d
-
-
-
-
- subroutine mf_WriteRecord_3d( mf, tmi, spname, paramkey, unit, tref, t1, t2, &
- lli, nuv, levi, nw, ps, ll, status )
- use GO , only : TDate
- use Grid , only : TllGridInfo, TLevelInfo
- use file_hdf, only : TSds, WriteData
- use file_hdf_base, only : Init, Done
- use tmm_info, only : TMeteoInfo
-
-
- type(TMeteoFile_tmpp), intent(inout) :: mf
- type(TMeteoInfo), intent(in) :: tmi
- character(len=*), intent(in) :: spname, paramkey, unit
- type(TDate), intent(in) :: tref, t1, t2
- type(TllGridInfo), intent(in) :: lli
- character(len=1), intent(in) :: nuv
- type(TLevelInfo), intent(in) :: levi
- character(len=1), intent(in) :: nw
- real, intent(in) :: ps(:,:)
- real, intent(in) :: ll(:,:,:)
- integer, intent(out) :: status
-
-
- character(len=*), parameter :: rname = mname//'/mf_WriteRecord_3d'
-
-
-
- type(TSds) :: sds
- integer :: iname
-
-
-
- if ( mf%io /= 'o' ) then
- write (gol,'("file should have been opened for output, but io=",a)') mf%io; call goErr
- TRACEBACK; status=1; return
- end if
-
-
- if ( .not. mf%output_initialised ) then
-
- call Init( mf%hdf, trim(mf%fname), 'create', status )
- IF_NOTOK_RETURN(status=1)
-
- call WriteHeader( mf, lli, status, levi )
- IF_NOTOK_RETURN(status=1)
-
- call WriteStatus( mf, 'in-progress', status )
- IF_NOTOK_RETURN(status=1)
-
- mf%output_nrec = 0
-
- mf%output_initialised = .true.
- else
-
- call Init( mf%hdf, trim(mf%fname), 'write', status )
- IF_NOTOK_RETURN(status=1)
- endif
-
-
-
-
- call AddOutputName( mf, paramkey, status )
- IF_NOTOK_RETURN(status=1)
-
- call Init( sds, mf%hdf, paramkey, shape(ll), 'real', status, knd=rknd_ds )
- IF_NOTOK_RETURN(status=1)
-
- call WriteSdsHeader( sds, tmi, unit, tref, t1, t2, lli, nuv, status, levi, nw )
- IF_NOTOK_RETURN(status=1)
-
-
- call WriteData( sds, ll, status )
- IF_NOTOK_RETURN(status=1)
-
-
- call Done( sds, status )
- IF_NOTOK_RETURN(status=1)
-
-
-
- call Init( sds, mf%hdf, spname, shape(ps), 'real', status, knd=rknd_ds )
- IF_NOTOK_RETURN(status=1)
-
- call WriteSdsHeader( sds, tmi, 'Pa', tref, t1, t2, lli, nuv, status )
- IF_NOTOK_RETURN(status=1)
-
-
- call WriteData( sds, ps, status )
- IF_NOTOK_RETURN(status=1)
-
-
- call Done( sds, status )
- IF_NOTOK_RETURN(status=1)
-
-
-
-
- mf%output_nrec = mf%output_nrec + 1
-
-
- if ( mf%output_nrec == mf%output_ntrec*mf%output_nname ) then
- call WriteStatus( mf, 'completed', status )
- IF_NOTOK_RETURN(status=1)
- end if
-
- call Done( mf%hdf, status )
- IF_NOTOK_RETURN(status=1)
-
- status = 0
- end subroutine mf_WriteRecord_3d
-
- end module tmm_mf_tmpp
|