login

cmonth.gsf

Top / GrADS / script / cmonth.gsf

Japanese / English

Name

cmonth() - Convert integer to alphabetical month or vice versa.

Synopsis

  • 1: Convert from integer to alphabetical month.
    ret = cmonth( m [, size] )
    ret = cmonth( "m1,m2,..." [, size] )
    ret = cmonth( MMM [, size] )
    
  • 2: Convert from alphabetical to integer month.
    ret = cmonth( str [, size] )
    

Description

Alphabetical month must be unique-interpretable. For example, "MA" as an input value is not appropriate, since interpretation of "March-April", "March", and "May" are possible.

Options and Return values

m
Integer month (1-12). e.g., '3' for March.
"m1,m2,..."
Set of integers separated with comma. e.g., '12,1,2' for Dec-Feb.
MMM
3-digit string. e.g., '678' for JJA and '212' for DJF.
(1) size
Maximum length of output string per month.
(2) size
Only output the end digit of month without comma if size='1' is specified.
str
Alphabetical month(s)。Separate with "-" when more than one month are specified ("-" is not necessary for the special words such as "DJF"). (e.g. Mar, JJA, Jun-Jul)
(1) ret
Alphabetical month(s) (e.g. January, DJF).
(2) ret
Integer(s) (e.g. '1', '12,1,2').

Examples

(1) Show English name of the month corresponding to the script variable m=10.

  • test.gs
    rc = gsfallow( 'on' )
    m = 10
    say cmonth( m )
    say cmonth( m, 3 )
    
  • console
    October
    Oct
    

(2) Convert from "6,7,8" to "Jun-Jul-Aug"

  • script
    rc = gsfallow( 'on' )
    m = '6,7,8'
    say cmonth( m, 3 )
    
  • console
    Jun-Jul-Aug
    

(3) Convert from "12,1,2" to "DJF"

  • script
    rc = gsfallow( 'on' )
    m = '12,1,2'
    say cmonth( m, 1 )
    
  • console
    DJF
    

(4) "March" を数字の月に変換する。

  • スクリプト
    rc = gsfallow( 'on' )
    say cmonth( 'March' )
    
  • console
    3
    

(5) Convert from "MAM" to an integer.

  • script
    rc = gsfallow( 'on' )
    say cmonth( 'MAM' )
    
  • console
    3,4,5
    

(6) Convert from "sep-oct-nov" to 3-digit integer.

  • script
    rc = gsfallow( 'on' )
    say cmonth( 'sep-oct-nov', 1 )
    
  • console
    901
    

Script source code