;+ ; ; ======================= ; sst_correction_ncdf.pro ; ======================= ; ; .. function:: sst_correction_ncdf(yyyymmddb,yyyymmdde) ; ; DESCRIPTION ; =========== ; ; Correction of sst on OAFLUX grid ; ; :file:`${PROJECT_OD}/erai_sst_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc` ; containing ; ++ ; has been produced by ; :func:`interp_erai_sst`. ; ; Corrected sst on OAFLUX grid ; is written in ; :file:`${PROJECT_OD}/TropFlux_sst_{yyyymmdd}_{yyyymmdd}.nc` ; if this file not already exists. ; ; This output file ; :file:`${PROJECT_OD}/TropFlux_sst_{yyyymmdd}_{yyyymmdd}.nc` ; will be used by ; :func:`cronin_gustiness_ncdf` ; and ; :func:`tropflux`. ; ; This output file ; :file:`${PROJECT_OD}/TropFlux_sst_{yyyymmdd}_{yyyymmdd}.nc` ; is one of the deliverable of TropFlux. ; ; .. only:: man ; ; Figure is visible on PDF and HTML documents only. ; ; .. only:: html or latex ; ; .. graphviz:: ; ; digraph sst_correction_ncdf { ; ; file_in [shape=ellipse, ; fontname=Courier, ; label="${PROJECT_OD}/erai_sst_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"]; ; file_out [shape=ellipse, ; fontname=Courier, ; label="${PROJECT_OD}/TropFlux_sst_{yyyymmdd}_{yyyymmdd}.nc"]; ; ; sst_correction_ncdf [shape=box, ; fontname=Courier, ; color=blue, ; URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/sst_correction_ncdf.pro", ; label="${PROJECT}/src/sst_correction_ncdf.pro"]; ; ; {file_in} -> {sst_correction_ncdf} -> {file_out} ; ; } ; ; SEE ALSO ; ======== ; ; :ref:`mooring_corrections` ; ; Used by :ref:`tropflux.sh` ; ; :ref:`project_profile.sh` ; ; :func:`interp_erai_sst` ; ; :func:`initncdf ` ; :func:`read_ncdf ` ; :func:`grossemoyenne ` ; :func:`julday ` ; :func:`ncdf_quickwrite ` ; ; EXAMPLES ; ======== ; ; .. code-block:: idl ; ; yyyymmddb = 20000101L ; yyyymmdde = 20001231L ; result = sst_correction_ncdf(yyyymmddb, yyyymmdde) ; print, result ; ; TODO ; ==== ; ; make it work on loholt1 idl8: ; reach end without error but with bad values (9.96921e+36 on time and sst, ; nb timestep 5716 ; ; see commands: ; ; .. code-block:: bash ; ; ncks -v sst -d time,0,1 -d latitude,0,1 -d longitude,0,1 /homedata/pinsard/tropflux_d/TropFlux_sst_19890101_20091231.nc ; ; very strange value of time on loholt1 idl6 but not always and not always at ; the same indices !!: ; ; .. parsed-literal:: ; ; print, time[7080:7090] ; 2454607.5 2454608.5 2454609.5 9.9692100e+36 9.9692100e+36 ; 9.9692100e+36 9.9692100e+36 9.9692100e+36 9.9692100e+36 2454616.5 ; 2454617.5 ; ; while : ; ; .. code-block:: bash ; ; ncks -H -C -v time -d time,7080,7090 ${PROJECT_ID}/20c3m_erai_sstk_TROP_1989_2009.nc ; ; .. parsed-literal:: ; ; time[7080]=450432 ; time[7081]=450456 ; time[7082]=450480 ; time[7083]=450504 ; time[7084]=450528 ; time[7085]=450552 ; time[7086]=450576 ; time[7087]=450600 ; time[7088]=450624 ; time[7089]=450648 ; time[7090]=450672 ; ; and ; ; .. code-block:: bash ; ; ncks -H -C -v time -d time,7080,7090 ${PROJECT_OD}/erai_sst_19890101_20091231_oafluxgrid.nc ; ; .. parsed-literal:: ; ; time[7080]=21325 ; time[7081]=21326 ; time[7082]=21327 ; time[7083]=9.96920996839e+36 ; time[7084]=9.96920996839e+36 ; time[7085]=9.96920996839e+36 ; time[7086]=9.96920996839e+36 ; time[7087]=9.96920996839e+36 ; time[7088]=9.96920996839e+36 ; time[7089]=21334 ; time[7090]=21335 ; ; and : ; ; .. code-block:: bash ; ; fplod@cratos$ ncks -H -C -v time -d time,7080,7090 ${PROJECT_OD}/erai_sst_19890101_20091231_oafluxgrid.nc ; ; .. parsed-literal:: ; ; time[7080]=21325 ; time[7081]=21326 ; time[7082]=21327 ; time[7083]=21328 ; time[7084]=21329 ; time[7085]=21330 ; time[7086]=21331 ; time[7087]=21332 ; time[7088]=21333 ; time[7089]=21334 ; time[7090]=21335 ; ; coding rules ; ; temperature SI units = K : why + and - 273... ; ; hard coded coefficient correction. ; ; KNOWN ISSUES ; ============ ; ; test of existence of fullfilename_in not very efficient because ; MUST_EXIST keyword of :func:`isafile ` not yet implemented ; ; EVOLUTIONS ; ========== ; ; $Id: sst_correction_ncdf.pro 88 2011-08-19 15:40:14Z pinsard $ ; ; $URL$ ; ; - fplod 20120322 ; ; * taking project_overwrite into account ; * try to add compile_opt seems to be incompatible with ncdf_quickwrite ; * pro -> function ; * hard coded da1 and da2 replaced by yyyymmddb and yyyymmdde parameters ; * get rid of timegen ; ; - fplod 20110808T124236Z cratos (Linux) ; ; * usage of ${PROJECT_OD} ; * complete description ; * remove v20 in output filename ; ; - fplod 20101215T114224Z aedon.locean-ipsl.upmc.fr (Darwin) ; ; * add graph in header ; ; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin) ; ; * minimal header ; ; - pbk 2008 ; ; * creation ; ;- function sst_correction_ncdf $ , 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 = sst_correction_ncdf(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 data filename filename='erai_sst_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc' ; ; check if this file exists msg='iii : looking for ' + filename ras = report(msg) fullfilename = isafile(iodirout + filename, NEW=0, /MUST_EXIST) IF fullfilename[0] EQ '' THEN BEGIN msg = 'eee : the file ' + fullfilename + ' was not found.' ras = report(msg) return, result ENDIF ; ; build output filename filename_out = 'TropFlux_sst_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.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 sst=read_ncdf('sst',yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr) timein=24.d*(time-julday(1,1,1957,0,0,0)) jpt=n_elements(timein) da=jul2date(time[0]) cda0=string(da,format='(i8.8)') da=jul2date(time[jpt-1]) cda1=string(da,format='(i8.8)') print, 'sst in sst_correction_ncdf first date ', cda0 print, 'sst in sst_correction_ncdf last date ' , cda1 ; sst=sst-273.15 help, sst ; sst_mean=grossemoyenne(sst,'t',/nan) help, sst_mean ; jpt=n_elements(time) caldat, time,mon,day,yea ; ;++ debug to understand some time value 9.9692100e+36 on idl 6 loholt1 ; print, time[7080:7090] when working on [19890101,19891231] ; sst_m=sst*0. ; for jt=0,jpt-1 do begin jtt=(time[jt]-julday(1,1,yea[jt])) < 364 t=reform(sst_mean[*,*]) sst_m[*,*,jt]=t endfor help, sst_m ; sst_ano=sst-sst_m ; ; correction for mean based on scatter ;sst_m=sst_m+0.0521111 ; (2000-2008) sst_m=sst_m+0.0533692 ; (2000-2009) ; help, sst_ano ; ; applying the correction for variability based on the scatter ;sst_ano=sst_ano*(1/0.989889) ; (2000-2008) sst_ano=sst_ano*(1/0.986196) ; (2000-2009) ; sst_new=sst_m+sst_ano+273.15 help, sst_new ; ;writing field lat=reform(gphit[0,0:jpj-1]) lon=reform(glamt[0:jpi-1,0]) ; 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:'Basic data obtained from ERAI. Bias and variability correction are applied',timerange:cda0+' - '+cda1} sst_attr={units:'degK',missing_value:1.e20,long_name:'Sea Surface Temperature',short_name:'sst',axis:'TYX'} ; ncfields = 'sst[longitude,latitude,*time]=sst_new:sst_attr; ' $ + 'longitude[]=lon:lon_attr; ' $ + 'latitude[]=lat:lat_attr; ' $ + 'time[]=timein:time_attr ' $ + ' @ globattr' ; @ncdf_quickwrite ; result = 0 return, result ; end