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/q2m_correction_ncdf.pro

    r172 r175  
    11;+ 
    2 ; 
    3 ; .. _q2m_correction_ncdf.pro: 
    42; 
    53; ======================= 
     
    75; ======================= 
    86; 
     7; .. function:: q2m_correction_ncdf(yyyymmddb,yyyymmdde) 
     8; 
    99; DESCRIPTION 
    1010; =========== 
     
    1212; Correction of q2m on OAFLUX grid 
    1313; 
    14 ; :file:`${PROJECT_OD}/erai_q2m_19890101_20091231_oafluxgrid.nc` 
     14; :file:`${PROJECT_OD}/erai_q2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc` 
    1515; containing 
    1616; ++ 
     
    2020; Corrected q2m on OAFLUX grid 
    2121; is written in 
    22 ; :file:`${PROJECT_OD}/TropFlux_q2m_19890101_20091231.nc` 
     22; :file:`${PROJECT_OD}/TropFlux_q2m_{yyyymmdd}_{yyyymmdd}.nc` 
    2323; if this file not already exists. 
    2424; 
    2525; This file will be used by 
    26 ; :ref:`TropFlux_19890101_20091231.pro`. 
     26; :func:`tropflux`. 
    2727; 
    2828; .. only:: man 
     
    3636;        digraph q2m_correction_ncdf { 
    3737; 
    38 ;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_q2m_19890101_20091231_oafluxgrid.nc"]; 
    39 ;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_q2m_19890101_20091231.nc"]; 
     38;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_q2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"]; 
     39;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_q2m_{yyyymmdd}_{yyyymmdd}.nc"]; 
    4040; 
    4141;           q2m_correction_ncdf [shape=box, 
     
    5252; ======== 
    5353; 
     54; :ref:`mooring_corrections` 
     55; 
     56; Used by :ref:`tropflux.sh` 
     57; 
    5458; :ref:`project_profile.sh` 
    55 ; 
    56 ; :ref:`mooring_corrections` 
    5759; 
    5860; :func:`d2m_to_q2m_erai` 
     
    6971; :: 
    7072; 
    71 ;  IDL> q2m_correction_ncdf 
     73;  IDL> yyyymmddb = 20000101L 
     74;  IDL> yyyymmdde = 20001231L 
     75;  IDL> result = q2m_correction_ncdf(yyyymmddb, yyyymmdde) 
     76;  IDL> print, result 
    7277; 
    7378; TODO 
    7479; ==== 
    7580; 
    76 ; work on cratos idl7 even if NaNf values in erai_q2m_19890101_20091231_oafluxgrid.nc written by 
    77 ; d2m_to_q2m.pro. 
     81; make it work :: 
     82; 
     83;   Writing fields: 
     84;   q2m[longitude,latitude,time*]=q2m_new:q2m_attr; longitude[]=lon:lon_attr; latitude[]=lat:lat_attr; time[]=timein:time_attr  @ globattr 
     85;   % NCDF_DIMDEF: Unable to create dimension. (NC_ERROR=-59) 
     86;   % NCDF_VARDEF: Unable to define variable, bad dimension id . 
     87;   % NCDF_VARPUT: Variable Inquiry failed, -1 is not a valid variable id. 
     88;   % Stop encountered: Q2M_CORRECTION_NCDF    1 
     89;         /.autofs/lodyc/incas/fplod/tropflux/tropflux_ws/src/q2m_correction_ncdf.pro 
    7890; 
    7991; No way ... NaNf also in this output !! 
     
    88100; $URL$ 
    89101; 
     102; - fplod 20120322 
     103; 
     104;   * taking project_overwite into account 
     105;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite 
     106;   * pro -> function 
     107;   * hard coded da1 and da2 replaced by yyyymmddb and yyyymmdde parameters 
     108;   * get rid of timegen 
     109; 
    90110; - fplod 20110808T143129Z aedon.locean-ipsl.upmc.fr (Darwin) 
    91111; 
     
    106126; 
    107127;- 
    108 pro q2m_correction_ncdf 
     128function q2m_correction_ncdf $ 
     129         , yyyymmddb $ 
     130         , yyyymmdde 
     131; 
     132;++compile_opt idl2, strictarrsubs, logical_predicate 
    109133; 
    110134@cm_4cal 
     
    114138@cm_project 
    115139; 
     140; Return to caller if errors 
     141ON_ERROR, 2 
     142; 
     143result = -1 
     144; 
     145usage = 'result = q2m_correction_ncdf(yyyymmddb, yyyymmdde)' 
     146nparam = N_PARAMS() 
     147IF (nparam NE 2) THEN BEGIN 
     148    ras = report(['Incorrect number of arguments.' $ 
     149          + '!C' $ 
     150          + 'Usage : ' + usage]) 
     151    return, result 
     152ENDIF 
     153 
    116154; test if ${PROJECT_OD} defined 
    117155CASE project_od_env OF 
     
    119157         msg = 'eee : ${PROJECT_OD} is not defined' 
    120158         ras = report(msg) 
    121        STOP 
     159       return, result 
    122160       END 
    123161  ELSE: BEGIN 
     
    134172   msg = 'eee : the directory' + iodirout  + ' is not accessible.' 
    135173   ras = report(msg) 
    136    STOP 
     174   return, result 
    137175ENDIF 
    138176; 
     
    141179    msg = 'eee : the directory' + iodirout  + ' was not found.' 
    142180    ras = report(msg) 
    143     STOP 
    144 ENDIF 
    145 ; 
    146 da1=19880101 
    147 da2=20101231 
     181    return, result 
     182ENDIF 
    148183; 
    149184; build data filename 
    150 filename='erai_q2m_19890101_20091231_oafluxgrid.nc' 
     185filename='erai_q2m_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc' 
    151186; 
    152187; check if this file exists 
     
    157192   msg = 'eee : the file ' + fullfilename + ' was not found.' 
    158193   ras = report(msg) 
    159    STOP 
     194   return, result 
    160195ENDIF 
    161196; 
    162197; build output filename 
    163 filename_out = 'TropFlux_q2m_19890101_20091231.nc' 
     198filename_out = 'TropFlux_q2m_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc' 
    164199fullfilename_out = iodirout + filename_out 
    165200; in order to avoid unexpected overwritten 
    166 IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN 
     201IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN 
    167202   msg = 'eee : the file ' + fullfilename_out  + ' already exists.' 
    168203   ras = report(msg) 
    169    STOP 
     204   return, result 
    170205ENDIF 
    171206; 
    172207initncdf, fullfilename 
    173 q2m=read_ncdf('q2m',da1,da2,file=fullfilename,/nostr) 
     208q2m=read_ncdf('q2m',yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr) 
     209timein=24.d*(time-julday(1,1,1957,0,0,0)) 
     210jpt=n_elements(timein) 
     211da=jul2date(time[0]) 
     212cda0=string(da,format='(i8.8)') 
     213da=jul2date(time[jpt-1]) 
     214cda1=string(da,format='(i8.8)') 
     215print, 'q2m in q2m_correction_ncdf first date ', cda0 
     216print, 'q2m in q2m_correction_ncdf last date ' , cda1 
     217; 
    174218help, q2m 
    175219; 
     
    182226; 
    183227for jt=0,jpt-1 do begin 
    184   jtt=(time(jt)-julday(1,1,yea(jt))) < 364 
    185   q=reform(q2m_mean(*,*)) 
    186   q2m_m(*,*,jt)=q 
     228  jtt=(time[jt]-julday(1,1,yea[jt])) < 364 
     229  q=reform(q2m_mean[*,*]) 
     230  q2m_m[*,*,jt]=q 
    187231endfor 
    188232help, q2m_m 
     
    203247; 
    204248;writing field 
    205 lat=reform(gphit(0,0:jpj-1)) 
    206 lon=reform(glamt(0:jpi-1,0)) 
    207 time=timegen(7670, start=julday(1,1,1989,0), units='days') 
    208 jpt=n_elements(time) 
    209 ; 
    210 cda0=string(jul2date(time(0)),format='(i8.8)') 
    211 cda1=string(jul2date(time(jpt-1)),format='(i8.8)') 
    212 ; 
    213 time=time-julday(1,1,1950) 
    214 jpt=n_elements(time) 
     249lat=reform(gphit[0,0:jpj-1]) 
     250lon=reform(glamt[0:jpi-1,0]) 
    215251; 
    216252ncfile='!' + fullfilename_out 
     
    221257q2m_attr={units:'g/kg',missing_value:1.e20,long_name:'Specific humidity at 2m height',short_name:'q2m',axis:'TYX'} 
    222258; 
    223 ncfields = 'q2m[longitude,latitude,time]=q2m_new:q2m_attr; ' $ 
     259ncfields = 'q2m[longitude,latitude,time*]=q2m_new:q2m_attr; ' $ 
    224260                      + 'longitude[]=lon:lon_attr; ' $ 
    225261                      + 'latitude[]=lat:lat_attr; ' $ 
    226                       + 'time[*time]=time:time_attr ' $ 
     262                      + 'time[]=timein:time_attr ' $ 
    227263                      + ' @ globattr' 
    228264; 
    229265@ncdf_quickwrite 
    230266; 
     267result = 0 
     268return, result 
     269; 
    231270end 
Note: See TracChangeset for help on using the changeset viewer.