<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Okay, you want to stay with decimal coded, as in YYYYMM.  Your input times are YYYYMMDD.fffff where the fraction is non-zero.  This is a case of simple integer division and rounding down, except be careful of precision with this many digits.  The original time values are type double, so that should take care of the precision issue.</div><div><br></div>Remove YYYY = cd_calendar(TIME,-2)/100.  Then do this.  Note that converting double to integer will truncate (set to zero) the fractional part of the result.  Integer division will do the same thing.</div><div dir="ltr"><br></div><div dir="ltr">    YYYYMM = toint (TIME / 100)     ; divide in double precision, then truncate</div><div dir="ltr">    YYYY       = YYYYMM / 100        ; integer division and truncate</div><div dir="ltr"><br></div><div>To check the results, compare adjacent values.   For YYYYMM and sequential months, the difference should always be the numbers 1 or 89, e.g. 185101 - 185012.</div><div dir="ltr"><br></div><div dir="ltr"><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 14, 2021 at 1:31 AM Sri nandini <<a href="mailto:bax8609@uni-hamburg.de">bax8609@uni-hamburg.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
  
    
  
  <div>
    <p>Hello,</p>
    <p>The output is taken from ECMWF output from the atmospheric
      component of the MPI model.</p>
    <p>They were orginally in grib format (hence the daily component),
      and converted to .nc with cdo.</p>
    <p>At the moment they are appearing as YYYYMMDD and i would like to
      convert the time calendar to YYYYMM so instead of
      18500131.99444444 i wish to convert to 185001.</p>
    <p>Can someone help me with this?</p>
    <p>Sri<br>
    </p>
    <div>On 13.04.21 18:18, Dave Allured - NOAA
      Affiliate wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">
        <div dir="ltr">
          <div dir="ltr">
            <div dir="ltr">Sri, there is something wrong with the time
              coordinates in fslp->time.  You show values of
              [18500131.99444444..20051231.99444444], but units of
              "hours since 1850-01-31 23:15:00".  Time coordinates
              should either be offsets relative to the base time in the
              units string, or else they should be decimal coded
              numbers.  It looks like this file mixes the two
              approaches, resulting in your error.  Relative offsets is
              the conventional approach, but decimal coded may also be
              used with care.  Just don't mix the two.</div>
            <div dir="ltr"><br>
            </div>
            <div>Do you prefer to fix the input file, or try to use the
              decimal time values the way they are written now?  Please
              keep the conversation on the mailing list.</div>
            <div dir="ltr">
              <div dir="ltr"><br>
              </div>
              <br>
              <div class="gmail_quote">
                <div dir="ltr" class="gmail_attr">On Tue, Apr 13, 2021
                  at 9:43 AM Sri nandini via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>>
                  wrote:<br>
                </div>
                <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hello
                  dear ncl-users,<br>
                  <br>
                  I am trying to compute the model SOI index to draw a
                  timeseries plot. I <br>
                  have studies the examples on the ncl page for
                  indices_soi_1.ncl and <br>
                  indices_soi_2.ncl , and made my script as per the
                  methods here. But each <br>
                  time an error occurs when reading the time: fatal:An
                  error occurred <br>
                  reading YYYY<br>
                  <br>
                  Variable: TIME<br>
                  Type: double<br>
                  Total Size: 14976 bytes<br>
                               1872 values<br>
                  Number of Dimensions: 1<br>
                  Dimensions and sizes:    [time | 1872]<br>
                  Coordinates:<br>
                               time:
                  [18500131.99444444..20051231.99444444]<br>
                  Number Of Attributes: 4<br>
                     standard_name :    time<br>
                     units :    hours since 1850-01-31 23:15:00<br>
                     calendar :    standard<br>
                     axis :    T<br>
                  <br>
                  Variable: YYYY<br>
                  Type: integer<br>
                  Total Size: 7488 bytes<br>
                               1872 values<br>
                  Number of Dimensions: 1<br>
                  Dimensions and sizes:    [1872]<br>
                  <br>
                  Could someone reply to me offline, or help point me to
                  a query or <br>
                  ncl-talk which already solved this or i can also
                  transfer my datafile <br>
                  via ftp? Below is my script.<br>
                  <br>
                  ;
                  =============================================================<br>
                     latT    = -17.6         ; Tahiti<br>
                     lonT    = 210.75<br>
                     latD    = -12.5         ; Darwin<br>
                     lonD    = 130.83<br>
                  <br>
                     PLOT    = True<br>
                     pltType = "png"         ; send graphics to PNG file<br>
                     pltDir  = "./"          ; dir to which plots are
                  sent<br>
                  <br>
                     pltName = "indices_soi"<br>
                     yrStrt  = 1950          ; manually specify for
                  convenience<br>
                     yrLast  = 2010          ; 20th century ends 2010<br>
                  <br>
                     clStrt  = 1950          ; reference climatology for
                  SOI<br>
                     clLast  = 1979<br>
                  ; ======================End User <br>
                  Input=======================================<br>
                     nmos   = 12<br>
                     nyrs   = yrLast-yrStrt+1<br>
                  <br>
                     fslp   = addfile("<a href="http://hist_1850-2005_ens_1-100.slp.nc" rel="noreferrer" target="_blank">hist_1850-2005_ens_1-100.slp.nc</a>",
                  "r")<br>
                     slp    = fslp->slp<br>
                     printVarSummary(slp)<br>
                     TIME   = fslp->time<br>
                     printVarSummary(TIME)<br>
                     ;YYYYMM = cd_calendar(TIME, -1) ;error here<br>
                  <br>
                     YYYY   = cd_calendar(TIME,-2)/100<br>
                  <br>
                     tStrt  = ind(YYYY .eq. (yrStrt*100 +  1))       ;
                  indices 20th century<br>
                     tLast  = ind(YYYY .eq. (yrLast*100 + 12))       ;
                  relative to entire <br>
                  dataset<br>
                  <br>
                     yyyymm = YYYY(tStrt:tLast)<br>
                     tStrtP = ind(yyyymm .eq. (yrStrtP*100+  1))       ;
                  relative to <br>
                  yrStrt, yrLast<br>
                     tLastP = ind(yyyymm .eq. (yrLastP*100+ 12))<br>
                  <br>
                     T      =
                  short2flt(fslp->slp(1632:1871,:,{latT},{lonT}))<br>
                     D      =
                  short2flt(fslp->slp(1632:1871,:,{latD},{lonD}))<br>
                     printVarSummary(T)<br>
                     printVarSummary(D)<br>
                     T&time =
                  yyyymm                                   ; convenience<br>
                     D&time = yyyymm<br>
                  <br>
                     tClmStrt = ind(yyyymm.eq.(clStrt*100 +  1))       ;
                  index for clStrt<br>
                     tClmLast = ind(yyyymm.eq.(clLast*100 + 12))       ;
                  index for clStrt<br>
                     printVarSummary(tClmStrt)<br>
                     printVarSummary(tClmLast)<br>
                     TClm   = new ( nmos, typeof(T), T@_FillValue)     ;
                  monthly climatologies<br>
                     DClm   = new ( nmos, typeof(D), D@_FillValue)<br>
                  <br>
                     do nmo=0,nmos-1<br>
                      ;do n=0,99                                 ;
                  reference clm for each <br>
                  month and each ensemble member?<br>
                        TClm(nmo) = avg(T(tClmStrt+nmo:tClmLast:nmos))<br>
                        DClm(nmo) = avg(D(tClmStrt+nmo:tClmLast:nmos))<br>
                     end do<br>
                    end do<br>
                     printVarSummary(TClm)<br>
                     printVarSummary(DClm)<br>
                     TAnom    = T<br>
                     DAnom    = D<br>
                     do nmo=0,nmos-1                                   ;
                  anomalies <br>
                  reference clim<br>
                        TAnom(nmo::nmos) = T(nmo::nmos) - TClm(nmo)<br>
                        DAnom(nmo::nmos) = D(nmo::nmos) - DClm(nmo)<br>
                     end do<br>
                     printVarSummary(TAnom)<br>
                     printVarSummary(DAnom)<br>
                  <br>
                     TAnomStd   = stddev(TAnom(tClmStrt:tClmLast))     ;
                  stddev of <br>
                  anomalies over clStrt & clLast<br>
                     DAnomStd   = stddev(DAnom(tClmStrt:tClmLast))<br>
                     printVarSummary(TAnomStd)<br>
                  printVarSummary(DAnomStd) ; signal and noise<br>
                     soi_signal = (TAnom/TAnomStd) - (DAnom/DAnomStd)  ;
                  (ntim)<br>
                     copy_VarCoords(TAnom, soi_signal)<br>
                     soi_signal@long_name = "SOI: 20th Century
                  Reanalysis: "+yrStrt+"-"+yrLast<br>
                     printVarSummary(soi_signal)<br>
                  <br>
                  ;=======================================<br>
                  ; lag-0 correlation<br>
                  ;=======================================<br>
                  <br>
                     rslp  =
                  escorc(soi_signal,slp(lat|:,lon|:,ens:|,time|:))<br>
                     copy_VarCoords(slp(0,:,:,:), rslp)<br>
                     rslp@long_name = "Correlation: SOI-SLP:
                  "+yrStrt+"-"+yrLast<br>
                     printVarSummary(rslp)<br>
                  <br>
                  Best<br>
                  <br>
                  Sri<br>
                  <br>
                  -- <br>
                  Dr. Sri, Nandini-Weiss<br>
                  Research Associate<br>
                  <br>
                  Universität Hamburg<br>
                  Center for Earth System Research and Sustainability
                  (CEN)<br>
                  Cluster of Excellence 'Climate, Climatic Change, and
                  Society' (CLICCS)<br>
                  <br>
                  Bundesstrasse 53, 20146 Hamburg</blockquote></div></div></div></div></div></blockquote>
  </div>

</blockquote></div></div></div></div></div>