Re: to display large numbers

From: Jonathan Vigh <jvigh_at_nyahnyahspammersnyahnyah>
Date: Tue Apr 20 2010 - 12:52:32 MDT

Hi Hongyan,

    For date/time purposes, you could also use a string instead of an
integer:

yyyymmddhhmm_output = sprinti("%0.4i",year) + sprinti("%0.2i",month) +
sprinti("%0.2i",day) + sprinti("%0.2i",hour) + sprinti("%0.2i",minute)

where year, month, day, hour, and minute are integers.

Here are a couple example functions that convert back and forth between
an array of time offset (seconds since a base time like Jan 1, 1970) to
yyyymmddhhmm-type strings. They use udunits.

Cheers,
   Jonathan

;********************************************************
; Function: convert_timeoffset_to_yyyymmddhhmm
;
; This function takes an array of the time offset (seconds since basetime)
; and converts it to an array of nicely formatted string yyyymmddhhmm
;
; Author: Jonathan Vigh
;
;********************************************************
undef("convert_timeoffset_to_yyyymmddhhmm")
function convert_timeoffset_to_yyyymmddhhmm(time_offset[*]:integer)

local utc_date,year,month,day,hour,minute,yyyymmddhhmm_output,it

begin

  base_time_offset_units = "seconds since 1970-01-01 00:00:00.0 UTC"
  time_offset@units = base_time_offset_units

  utc_date = ut_calendar(time_offset,0)
 
 ; Store return information into more meaningful variables.
  year = floattointeger(utc_date(:,0)) ; Convert to integer for
  month = floattointeger(utc_date(:,1)) ; use sprinti
  day = floattointeger(utc_date(:,2))
  hour = floattointeger(utc_date(:,3))
  minute = floattointeger(utc_date(:,4))

 ; Write out date string in the format yyyymmddhhmm.
  yyyymmddhhmm_output = new(dimsizes(year),"string",string_FillValue)
 
  do it = 0, dimsizes(year)-1
     yyyymmddhhmm_output(it) = sprinti("%0.4i",year(it)) +
sprinti("%0.2i",month(it)) + sprinti("%0.2i",day(it)) +
sprinti("%0.2i",hour(it)) + sprinti("%0.2i",minute(it))
  end do
 
  return(yyyymmddhhmm_output)
end

;********************************************************
; Function: convert_yyyymmddhhmm_to_timeoffset
;
; This procedure takes an array of yyyymmddhhmm date/times and
; converts it to a time offset in seconds since basetime.
;
; Note that this function has been 'enlightened' to check to make
; sure the input values are not missing and contain just digits.
;
; This is the version used for converting the baseline times.
;
; Author: Jonathan Vigh
;
;********************************************************
undef("convert_yyyymmddhhmm_to_timeoffset")
function convert_yyyymmddhhmm_to_timeoffset(yyyymmddhhmm[*]:string)
            
local
ntimes,tChr,month,day,year,hour,minute,second,base_time_offset_units,time_offset_output

begin
  ntimes = dimsizes(yyyymmddhhmm)

  tChr = stringtochar(yyyymmddhhmm)

; use the udunits routine ut_inv_calendar
  base_time_offset_units = "seconds since 1970-01-01 00:00:00.0 UTC"

  timeoffset_output = new(ntimes,"integer",integer_FillValue)
  timeoffset_output@_FillValue = integer_FillValue
  timeoffset_output@units = base_time_offset_units

  do itime = 0, ntimes-1
     if (contains_just_digits(chartostring(tChr(itime,:)))) then
        year = stringtointeger(chartostring(tChr(itime,0:3)))
        month = stringtointeger(chartostring(tChr(itime,4:5)))
        day = stringtointeger(chartostring(tChr(itime,6:7)))
        hour = stringtointeger(chartostring(tChr(itime,8:9)))
        minute = stringtointeger(chartostring(tChr(itime,10:11)))
        second = 0

        if (.not.ismissing(year) .and. .not.ismissing(month) .and.
.not.ismissing(day) .and. .not.ismissing(hour) .and.
.not.ismissing(minute)) then
           timeoffset_output(itime) =
doubletointeger(ut_inv_calendar(year,month,day,hour,minute,second,base_time_offset_units,0))
        end if
 
        delete(year)
        delete(month)
        delete(day)
        delete(hour)
        delete(minute)
     end if
  end do
 
  return(timeoffset_output)
end

H.Dang wrote:
> Hello~
>
> I'm trying to use the following numbers as part of the file names,
> (year/month/day/hour/minute)
>
> 200707280000
>
> but the results are not correct. Just wondering if NCL can display
> such big values, or if I should put some specific line in my ncl file.
>
> Thanks!
> --
> Cordially,
> Hongyan
> 鸿雁
> ------------------------------------------------------------------------
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Apr 20 12:52:44 2010

This archive was generated by hypermail 2.1.8 : Fri Apr 23 2010 - 14:40:07 MDT