;+ ; ; ==================== ; tropflux_swr_nrt.pro ; ==================== ; ; .. function:: tropflux_swr_nrt(yyyymmddb,yyyymmdde) ; ; DESCRIPTION ; =========== ; ; Correction of swr near real time on OAFLUX grid ; ; :file:`${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_DT.nc` ; containing ; Corrected swr delay on OAFLUX grid ; has been produced by ; :func:`tropflux_swr_dt`. ; ; :file:`${PROJECT_OD}/olr_oafluxgrid_30n30s_{yyyymmdd}_{yyyymmdd}.nc` ; have been produced ; :func:`interp_olr_30n30s`. ; ; Corrected swr near real time on OAFLUX grid ; ; is written in ; :file:`${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_NRT.nc` ; if this file not already exists. ; ; .. graphviz:: ; ; digraph tropflux_swr_nrt { ; ; file_swr_dt [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_DT.nc"]; ; file_olr [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/olr_oafluxgrid_30n30s_{yyyymmdd}_{yyyymmdd}.nc"]; ; file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_NRT.nc"]; ; ; tropflux_swr_nrt [shape=box, ; fontname=Courier, ; color=blue, ; URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/tropflux_swr_nrt.pro", ; label="${PROJECT}/src/tropflux_swr_nrt.pro"]; ; ; {file_swr_dt file_olr}-> {tropflux_swr_nrt} -> {file_out} ; } ; ; SEE ALSO ; ======== ; ; :ref:`mooring_corrections` ; ; :ref:`data_in_swr` ; :ref:`data_in_olr` ; ; Used by :ref:`tropflux.sh` ; ; :ref:`project_profile.sh` ; ; :func:`initncdf ` ; :func:`read_ncdf ` ; :func:`julday ` ; :func:`ncdf_quickwrite ` ; ; EXAMPLES ; ======== ; ; .. code-block:: idl ; ; yyyymmddb = 20000101L ; yyyymmdde = 20001231L ; result = tropflux_swr_nrt(yyyymmddb, yyyymmdde) ; print, result ; ; TODO ; ==== ; ; handle yyyymmdde > 20071231 ; ; remove NaNf values in output file (may be not because of this module) ; ; why two sequence initncdf et read_ndcf on olr file ? ; ; coding rules ; ; KNOWN ISSUES ; ============ ; ; test of existence of fullfilename not very efficient because ; MUST_EXIST keyword of :func:`isafile ` not yet implemented ; ; EVOLUTIONS ; ========== ; ; $Id: tropflux_swr_nrt.pro 88 2011-08-19 15:40:14Z pinsard $ ; ; $URL$ ; ; - fplod 20120321 ; ; * pro -> func ; * rename with lower case TropFlux_swr_NRT_19890101_20091231.pro become ; tropflux_swr_nrt.pro ; * taking project_overwrite into account ; * try to add compile_opt seems to be incompatible with ncdf_quickwrite ; ; - fplod 20110830T135938Z cratos (Linux) ; ; * replace tt by time ; * fill empty time_origin ; ; - fplod 20110812T075406Z aedon.locean-ipsl.upmc.fr (Darwin) ; ; * usage of ${PROJECT_OD} ; * complete description ; * remove v50 in filenames ; ; - fplod 20101215T092145Z aedon.locean-ipsl.upmc.fr (Darwin) ; ; * add graph in header ; ; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin) ; ; * minimal header ; ; - pbk 2008 ; ; * creation ; ;- function tropflux_swr_nrt $ , yyyymmddb $ , yyyymmdde ; compile_opt idl2, strictarrsubs, logical_predicate ; @cm_4cal @cm_4data @cm_4mesh @cm_4data @cm_project ; ; Return to caller if errors ON_ERROR, 2 ; result = -1 ; usage = 'result = tropflux_swr_nrt(yyyymmddb, yyyymmdde)' nparam = N_PARAMS() IF (nparam NE 2) THEN BEGIN ras = report(['Incorrect number of arguments.' $ + '!C' $ + 'Usage : ' + usage]) return, result ENDIF ; ; test if ${PROJECT_OD} defined CASE project_od_env OF '' : BEGIN msg = 'eee : ${PROJECT_OD} is not defined' ras = report(msg) return, result END ELSE : BEGIN msg = 'iii : ${PROJECT_OD} is ' + project_od_env ras = report(msg) END ENDCASE ; check if output data will be possible iodirout = isadirectory(project_od_env) ; ; existence and protection for reading IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN msg = 'eee : the directory' + iodirout + ' is not accessible.' ras = report(msg) return, result ENDIF ; ; existence and protection for writing IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN msg = 'eee : the directory' + iodirout + ' was not found.' ras = report(msg) return, result ENDIF ; ; build swr dt data filename filename_swr_dt='TropFlux_swr_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_DT.nc' ; ; check if this file exists msg='iii : looking for ' + filename_swr_dt ras = report(msg) fullfilename_swr_dt = isafile(iodirout + filename_swr_dt, NEW=0, /MUST_EXIST) IF fullfilename_swr_dt[0] EQ '' THEN BEGIN msg = 'eee : the file ' + fullfilename_swr_dt + ' was not found.' ras = report(msg) return, result ENDIF ; ; build olr data filename filename_olr='olr_oafluxgrid_30n30s_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc' ; ; check if this file exists msg='iii : looking for ' + filename_olr ras = report(msg) fullfilename_olr = isafile(iodirout + filename_olr, NEW=0, /MUST_EXIST) IF fullfilename_olr[0] EQ '' THEN BEGIN msg = 'eee : the file ' + fullfilename_olr + ' was not found.' ras = report(msg) return, result ENDIF ; ; build output filename filename_out = 'TropFlux_swr_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_NRT.nc' fullfilename_out = iodirout + filename_out ; in order to avoid unexpected overwritten IF ((FILE_TEST(fullfilename_out) EQ 1) AND (project_overwrite EQ 0)) THEN BEGIN msg = 'eee : the file ' + fullfilename_out + ' already exists.' ras = report(msg) return, result ENDIF ; initncdf, fullfilename_swr_dt sw=read_ncdf("swr", yyyymmddb-.5d, yyyymmdde, file=fullfilename_swr_dt,/nostr) swi=sw timein=24.d*(time-julday(1,1,1957,0,0,0)) jptin=n_elements(timein) da=jul2date(timein[0]) cda0=string(da,format='(i8.8)') da=jul2date(timein[jptin-1]) cda1=string(da,format='(i8.8)') print, 'swr_dt first date ', cda0 print, 'swr_dt last date ' , cda1 ; initncdf, fullfilename_olr olr=read_ncdf('olr', yyyymmddb-.5d, yyyymmdde, file=fullfilename_olr,/nost) timein=24.d*(time-julday(1,1,1957,0,0,0)) jptin=n_elements(timein) da=jul2date(timein[0]) cda0=string(da,format='(i8.8)') da=jul2date(timein[jptin-1]) cda1=string(da,format='(i8.8)') print, 'olr first date ', cda0 print, 'olr last date ' , cda1 ; help, sw, olr ; ;creating climatology ; ny=(2007-1989)+1 ;+++ nt=365*ny olri=total(reform(olr[*,*,0:nt-1],nxt,nyt,365,ny),4)/ny swi=total(reform(swi[*,*,0:nt-1],nxt,nyt,365,ny),4)/ny ; help, olri, swi ; ; applying smoothing nsmooth=45 ; swi=[[[swi]],[[swi]],[[swi]]] olri=[[[olri]],[[olri]],[[olri]]] si=size(sw) n1=si[1] n2=si[2] ; for j=0,n2-1 do begin for i=0,n1-1 do begin x=reform(swi[i,j,*]) y=reform(olri[i,j,*]) swi[i,j,*]=smooth(x,nsmooth) olri[i,j,*]=smooth(y,nsmooth) endfor endfor ; swi=swi[*,*,365:365+364] olri=olri[*,*,365:365+364] help, swi ; initncdf, fullfilename_olr olr=read_ncdf('olr', yyyymmddb-.5d,yyyymmdde, box=box, file=fullfilename_olr,/nostr) timein=24.d*(time-julday(1,1,1957,0,0,0)) jptin=n_elements(timein) da=jul2date(timein[0]) cda0=string(da,format='(i8.8)') da=jul2date(timein[jptin-1]) cda1=string(da,format='(i8.8)') print, 'olr 2 first date ', cda0 print, 'olr 2 last date ' , cda1 jpt=n_elements(time) caldat, time,mon,day,yea swm=olr*0. olrm=olr*0. for jt=0,jpt-1 do begin jtt=(time[jt]-julday(1,1,yea[jt])) < 364 swm[*,*,jt]=swi[*,*,jtt] olrm[*,*,jt]=olri[*,*,jtt] endfor ; help, swm, olrm ; olra=olr-olrm ; olr anomaly rec=swm+(olra/0.760364) ; reconstructed sw ; ; writing field time=timegen(7670, start=julday(1,1,1989,0), units='days') ;+++ cda0=string(jul2date(time[0]),format='(i8.8)') cda1=string(jul2date(time[jpt-1]),format='(i8.8)') ; lat=reform(gphit[0,0:jpj-1]) lon=reform(glamt[0:jpi-1,0]) time=time-julday(1,1,1950) jpt=n_elements(time) ; ncfile='!' + fullfilename_out lon_attr={units:'degrees_east',long_name:'Longitude'} lat_attr={units:'degrees_north',long_name:'Latitude'} time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'} globattr={source:'Reconstructed from corrected OLR anomalies and TropFlux mean SWR climatology',timerange:cda0+' - '+cda1} sw_attr={units:'w/m^2',missing_value:1.e20,long_name:'Net Shortwave Radiation',short_name:'swr',axis:'TYX'} ; ncfields = 'sw[longitude,latitude,time]=rec:sw_attr; ' $ + 'longitude[]=lon:lon_attr; ' $ + 'latitude[]=lat:lat_attr; ' $ + 'time[*time]=time:time_attr ' $ + ' @ globattr' ; @ncdf_quickwrite ; result = 0 return, result ; end