Re: Re: ut_inv_calendar

From: Carl J. Schreck, III <carl_at_nyahnyahspammersnyahnyah>
Date: Mon, 07 Jul 2008 19:00:27 -0400

As long as we're talking about the ut routines, I'd like to propose
another function to add to future builds. It takes a time variable and
converts it from one set of units to another. It only takes a couple
lines, but I've used it enough that it helped me to make a function for
it. I use it when I'm overlaying two different datasets that might have
different reference dates. The code is below in case anyone else would
find this useful.

        Cheers,
        Carl

function ut_convert( dateFrom:double, unitsFrom:string, unitsTo:string )
;******************************************************************************
; Converts a time variable from one units to another
;
; Input variables:
; dateFrom: the original date
; unitsFrom: the original date units
; unitsTo: the NEW date units
; Return Value:
; retVal: the date converted to its new units
;******************************************************************************

local retVal, tempDate, utcDate

begin
   tempDate = dateFrom
   tempDate_at_units = unitsFrom

   utcDate = ut_calendar( tempDate, 0 )

   retVal = ut_inv_calendar( utcDate(:,0), utcDate(:,1), utcDate(:,2), \\
                             utcDate(:,3), utcDate(:,4), utcDate(:,5), \\
                             unitsTo, 0 )

   return( retVal )
end
;******************************************************************************

Mary Haley wrote:
>
> The year, month, day, and hour values returned by the internal Udunits
> routine are all integers to start with, so there's no rounding or
> truncating going on at the NCL end of things. Only the "seconds"
> values are returned as float.
>
> Now that I think about it, maybe this option '5' should be '-5',
> since the other negative options return integers...
>
> --Mary
>
>
> On Mon, 7 Jul 2008, Dave Allured wrote:
>
>> Reading the documentation for ut_calendar, I see that there already
>> are several other options for specialized result formats. In light of
>> this and the symmetry issue with ut_inv_calendar, I think it's
>> reasonable to add option 5 for integers. I would use this option if
>> available. Thanks to NCL for adding this one.
>>
>> For options +2/-2 through +4/-4, YYYYMM etc. as type double or
>> integer, are the time values rounded or truncated? I suggest that
>> this be added to the documentation.
>>
>> --Dave
>>
>> Mary Haley wrote:
>>>
>>>
>>> On Fri, 4 Jul 2008, Mateus Teixeira wrote:
>>>
>>>> Thanks Dave,
>>>>
>>>> Maybe ut_calendar could have an option equivalent to 0 that returns
>>>> integers.
>>>
>>> In version 5.0.1, ut_calendar will have an "option=5" that is
>>> identical to option=0, except it returns integers. The seconds
>>> values will be truncated.
>>>
>>> --Mary
>>>
>>>> Regards,
>>>>
>>>>
>>>> 2008/7/3 Dave Allured <dave.allured_at_noaa.gov>:
>>>>
>>>>> Mateus,
>>>>>
>>>>> I think it is usually better to keep unencoded date information as
>>>>> integers
>>>>> rather than floats. You can do this in one line when calling
>>>>> ut_calendar:
>>>>>
>>>>> ymd_hms = floattoint (ut_calendar (time, 0))
>>>>>
>>>>> Then you do not have to do the multiple reverse conversions for
>>>>> ut_inv_calendar. HTH.
>>>>>
>>>>> Dave Allured
>>>>> CU/CIRES Climate Diagnostics Center (CDC)
>>>>> http://cires.colorado.edu/science/centers/cdc/
>>>>> NOAA/ESRL/PSD, Climate Analysis Branch (CAB)
>>>>> http://www.cdc.noaa.gov/
>>>>>
>>>>> Mateus Teixeira wrote:
>>>>>
>>>>>> Dear NCL developers,
>>>>>>
>>>>>> Is it possible modify ut_inv_calendar arguments to numerical type?
>>>>>>
>>>>>> Sometimes is necessary to convert a set of dates from one time
>>>>>> unit to
>>>>>> another time unit.
>>>>>> Since ut_calendar with 0 option returns float, it would avoid the
>>>>>> float to
>>>>>> integer conversion to put their information into ut_inv_calendar.
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> --
>>>>>> Mateus da Silva Teixeira
>>>>>> Meteorologista
>>>>>> Instituto de Pesquisas Meteorol?gicas - IPMET (www.ipmet.unesp.br <
>>>>>> http://www.ipmet.unesp.br>)
>>>>>> Universidade Estadual Paulista - UNESP (www.unesp.br
>>>>>> <http://www.unesp.br
>>>>>>> )
>>>>>> Bauru, SP
>>>>>>
>>>>>> Registered Linux User #466740
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk_at_ucar.edu
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Jul 07 2008 - 17:00:27 MDT

This archive was generated by hypermail 2.2.0 : Thu Jul 10 2008 - 06:04:07 MDT