Ignore:
Timestamp:
03/22/12 14:40:17 (12 years ago)
Author:
pinsard
Message:

an other bunch of new functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/t2m_correction_ncdf.pro

    r155 r175  
    11;+ 
    2 ; 
    3 ; .. _t2m_correction_ncdf.pro: 
    42; 
    53; ======================= 
     
    75; ======================= 
    86; 
     7; .. function:: t2m_correction_ncdf(yyyymmddb,yyyymmdde) 
     8; 
     9; DESCRIPTION 
     10; =========== 
     11; 
    912; Mean correction for air temperature bias and correction for variability are 
    1013; applied. 
    1114; 
    12 ; :file:`${PROJECT_ID}/erai_t2m_19890101_20091231_oafluxgrid.nc` 
     15; :file:`${PROJECT_ID}/erai_t2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc` 
    1316; containing 
    1417; air temperature at 2 m height from ERA-I interpolated on OAFLUX grid 
     
    1821; Corrected air temperature at 2 m height 
    1922; is written in 
    20 ; :file:`${PROJECT_OD}/TropFlux_t2m_19890101_20091231.nc` 
     23; :file:`${PROJECT_OD}/TropFlux_t2m_{yyyymmdd}_{yyyymmdd}.nc` 
    2124; if this file not already exists. 
    2225; 
    2326; This output file 
    24 ; :file:`${PROJECT_OD}/TropFlux_t2m_19890101_20091231.nc` 
     27; :file:`${PROJECT_OD}/TropFlux_t2m_{yyyymmdd}_{yyyymmdd}.nc` 
    2528; will be used by 
    26 ; :ref:`TropFlux_19890101_20091231.pro`. 
     29; :func:`tropflux`. 
    2730; 
    2831; .. only:: man 
     
    3639;        digraph t2m_correction_ncdf { 
    3740; 
    38 ;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_t2m_19890101_20091231_oafluxgrid.nc"]; 
    39 ;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_t2m_19890101_20091231.nc"]; 
     41;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_t2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"]; 
     42;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_t2m_{yyyymmdd}_{yyyymmdd}.nc"]; 
    4043; 
    4144;           t2m_correction_ncdf [shape=box, 
     
    5255; ======== 
    5356; 
     57; :ref:`mooring_corrections` 
     58; 
     59; Used by :ref:`tropflux.sh` 
     60; 
    5461; :ref:`project_profile.sh` 
    55 ; 
    56 ; :ref:`mooring_corrections` 
    5762; 
    5863; :func:`interp_erai_t2m` 
     
    7277; :: 
    7378; 
    74 ;  IDL> t2m_correction_ncdf 
     79;  IDL> yyyymmddb = 20000101L 
     80;  IDL> yyyymmdde = 20001231L 
     81;  IDL> result = t2m_correction_ncdf(yyyymmddb, yyyymmdde) 
     82;  IDL> print, result 
    7583; 
    7684; TODO 
     
    97105; check time values 
    98106; 
    99 ; hard coded time in module name and in output filename 
    100 ; 
    101107; hard coded correction values 
    102108; 
     
    121127; 
    122128; $URL$ 
     129; 
     130; - fplod 20120322 
     131; 
     132;   * taking project_overwite into account 
     133;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite 
     134;   * pro -> function 
     135;   * hard coded da1 and da2 replaced by yyyymmddb and yyyymmdde parameters 
     136;   * replace t2m=ncdf_lec(... by a t2m=read_ncdf( 
    123137; 
    124138; - fplod 20110822T112525Z aedon.locean-ipsl.upmc.fr (Darwin) 
     
    156170; 
    157171;- 
    158 pro t2m_correction_ncdf 
     172function t2m_correction_ncdf $ 
     173         , yyyymmddb $ 
     174         , yyyymmdde 
     175; 
     176;++compile_opt idl2, strictarrsubs, logical_predicate 
    159177; 
    160178@cm_4cal 
     
    164182@cm_project 
    165183; 
     184; Return to caller if errors 
     185ON_ERROR, 2 
     186; 
     187result = -1 
     188; 
     189usage = 'result = sst_correction_ncdf(yyyymmddb, yyyymmdde)' 
     190nparam = N_PARAMS() 
     191IF (nparam NE 2) THEN BEGIN 
     192    ras = report(['Incorrect number of arguments.' $ 
     193          + '!C' $ 
     194          + 'Usage : ' + usage]) 
     195    return, result 
     196ENDIF 
     197 
    166198; test if ${PROJECT_OD} defined 
    167199CASE project_id_env OF 
     
    169201     msg = 'eee : ${PROJECT_OD} is not defined' 
    170202     ras = report(msg) 
    171      STOP 
     203     return, result 
    172204           END 
    173205 ELSE: BEGIN 
     
    184216   msg = 'eee : the directory' + iodirout  + ' is not accessible.' 
    185217   ras = report(msg) 
    186    STOP 
     218   return, result 
    187219ENDIF 
    188220; 
     
    191223    msg = 'eee : the directory' + iodirout  + ' was not found.' 
    192224    ras = report(msg) 
    193     STOP 
    194 ENDIF 
    195 ; 
    196 da1=19890101 
    197 da2=20091231 
     225    return, result 
     226ENDIF 
    198227; 
    199228; build uncorrected t2 filename 
    200229filename_t2_uncor = 'erai_t2m_' $ 
    201     + string(da1,format='(i8.8)') $ 
     230    + string(yyyymmddb,format='(i8.8)') $ 
    202231    + '_' $ 
    203     + string(da2,format='(i8.8)') $ 
     232    + string(yyyymmdde,format='(i8.8)') $ 
    204233    + '_oafluxgrid.nc' 
    205234; 
     
    211240   msg = 'eee : the file ' + fullfilename_t2_uncor + ' was not found.' 
    212241   ras = report(msg) 
    213    STOP 
     242   return, result 
    214243ENDIF 
    215244; 
    216245; build output filename 
    217246filename_out = 'TropFlux_t2m_' $ 
    218     + string(da1,format='(i8.8)') $ 
     247    + string(yyyymmddb,format='(i8.8)') $ 
    219248    + '_' $ 
    220     + string(da2,format='(i8.8)') $ 
     249    + string(yyyymmdde,format='(i8.8)') $ 
    221250    + '.nc' 
    222251; 
    223252fullfilename_out = iodirout + filename_out 
    224253; in order to avoid unexpected overwritten 
    225 IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN 
     254IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN 
    226255   msg = 'eee : the file ' + fullfilename_out  + ' already exists.' 
    227256   ras = report(msg) 
    228    STOP 
     257   return, result 
    229258ENDIF 
    230259; 
     
    239268; 
    240269; find first and last dates yyyymmdd 
    241 ; they will be written in global attributes of output file 
    242270da=jul2date(julday(01, 01, 1957,timein[0])) 
    243271cda0=string(da,format='(i8.8)') 
    244272da=jul2date(julday(01, 01, 1957,timein[jptin-1])) 
    245273cda1=string(da,format='(i8.8)') 
    246 print, 'first date ', cda0 
    247 print, 'last date ' , cda1 
     274print, 'for time checking first date ', cda0 
     275print, 'for time checking last date ' , cda1 
    248276; 
    249277; read t2 data 
    250 t2m=ncdf_lec(fullfilename_t2_uncor,var='t2m') 
     278initncdf, fullfilename_t2_uncor 
     279t2m=read_ncdf('t2m',yyyymmddb-.5d,yyyymmdde,file=fullfilename_t2_uncor,/nostr) 
     280timein=24.d*(time-julday(1,1,1957,0,0,0)) 
     281jpt=n_elements(timein) 
     282da=jul2date(time[0]) 
     283cda0=string(da,format='(i8.8)') 
     284da=jul2date(time[jpt-1]) 
     285cda1=string(da,format='(i8.8)') 
     286print, 't2m in t2m_correction_ncdf first date ', cda0 
     287print, 't2m in t2m_correction_ncdf last date ' , cda1 
    251288; 
    252289t2m=t2m-273.15 
     
    267304  ;++print,day 
    268305  jtt=(julday(01, 01, 1957,timein[jt])-julday(1,1,yea)) < 364 
    269   t=reform(t2m_mean(*,*)) 
    270   t2m_m(*,*,jt)=t 
    271   bias_cor(*,*,jt)=(((t-22.6)*0.4004896/(28-22.6)) > 0.) <0.4     ; (2000-2009) 
     306  t=reform(t2m_mean[*,*]) 
     307  t2m_m[*,*,jt]=t 
     308  bias_cor[*,*,jt]=(((t-22.6)*0.4004896/(28-22.6)) > 0.) <0.4     ; (2000-2009) 
    272309endfor 
    273310help, t2m_m,bias_cor 
     
    290327; 
    291328;writing field 
    292 lat=reform(gphit(0,0:jpj-1)) 
    293 lon=reform(glamt(0:jpi-1,0)) 
    294 cda0=string(da1) 
    295 cda1=string(da2) 
    296 ; 
    297 ; conversion for hours since 19570101 to days from 19500101 
    298 time=julday(01, 01, 1957,timein)-julday(1,1,1950) 
    299 jpt=n_elements(time) 
     329lat=reform(gphit[0,0:jpj-1]) 
     330lon=reform(glamt[0:jpi-1,0]) 
    300331; 
    301332ncfile='!' + fullfilename_out 
     
    313344t2m_attr={units:units,missing_value:1.e20,long_name:long_name,short_name:'t2m',axis:'TYX'} 
    314345; 
    315 ncfields = 't2m[longitude,latitude,time]=t2m_new:t2m_attr; ' $ 
     346ncfields = 't2m[longitude,latitude,*time]=t2m_new:t2m_attr; ' $ 
    316347                      + 'longitude[]=lon:lon_attr; ' $ 
    317348                      + 'latitude[]=lat:lat_attr; ' $ 
    318                       + 'time[*time]=time:time_attr ' $ 
     349                      + 'time[]=timein:time_attr ' $ 
    319350                      + ' @ globattr' 
    320351; 
    321352@ncdf_quickwrite 
    322353; 
     354result = 0 
     355return, result 
     356; 
    323357end 
Note: See TracChangeset for help on using the changeset viewer.