二十四節気とは
- 「国立国会図書館HP」より引用
今まで
- 2024年2月26日 二十四節気を追加
-
//======================================================================
// 今日が24節気かどうか調べる
// 引数 .... 計算対象となる年月日 year month day
// 戻り値 .... 24節気の名称
//======================================================================
func get24Sekki_bak(year:Double, month:Double,day:Double)-> (String ) {
let sekkiName = ["春分","清明","穀雨","立夏","小満","芒種","夏至","小暑","大暑","立秋","処暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至","小寒","大寒","立春","雨水","啓蟄"] // 24節気の定義
var JD: Double
var JD1: Double
var JD2: Double
var t: Double
var today: Int
//今日の太陽の黄経
JD = ymd2jd(yea: year, mont: month, ysDay: day) //ユリウス日の計算
JD1 = floor(JD) //時刻引数を分解する
JD2 = JD - JD1
JD2 -= 9.0 / 24.0
t = (JD2 + 0.5) / 36525.0
t = t + (JD1 - 2451545.0) / 36525.0
today = Int( LONGITUDE_SUN(t:t))
today = Int( 15.0 * floor( Double( today ) / 15.0 ))
return( sekkiName[ today/15 ] )
}
- 節気が変わるまで同じ節気を表示
-
改良
- 二十四節気の日は、節気名の頭に”*”を追加する。その後日からは、節気名のみとする
-
//======================================================================
// 今日が24節気かどうか調べる
// 引数 .... 計算対象となる年月日 year month day
// 戻り値 .... 24節気の名称
//======================================================================
func get24Sekki(year:Double, month:Double,day:Double)-> (String ) {
let sekkiName = ["春分","清明","穀雨","立夏","小満","芒種","夏至","小暑","大暑","立秋","処暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至","小寒","大寒","立春","雨水","啓蟄"] // 24節気の定義
var JD: Double
var JD1: Double
var JD2: Double
var t: Double
var today: Int
var tomorrow: Int
//今日の太陽の黄経
JD = ymd2jd(yea: year, mont: month, ysDay: day) //ユリウス日の計算
JD1 = floor(JD) //時刻引数を分解する
JD2 = JD - JD1
JD2 -= 9.0 / 24.0
t = (JD2 + 0.5) / 36525.0
t = t + (JD1 - 2451545.0) / 36525.0
today = Int( LONGITUDE_SUN(t:t))
//明日の太陽の黄経
JD += 1
JD1 = floor(JD) //時刻引数を分解する
JD2 = JD - JD1
JD2 -= 9.0 / 24.0
t = (JD2 + 0.5) / 36525.0
t = t + (JD1 - 2451545.0) / 36525.0
tomorrow = Int( LONGITUDE_SUN(t: t))
today = Int( 15.0 * floor( Double( today ) / 15.0 ))
tomorrow = Int( 15.0 * floor( Double( tomorrow) / 15.0))
if today != tomorrow {
return( "*" + sekkiName[ today/15 ] )
}else{
return( sekkiName[ today/15 ] )
}
}
-
改修(2024年7月6日)
- 返す値が間違えていました 誤:today 正:tomorrow
今日は「小暑」です。直りました
24節気のプログラムです
//=========================================================================
// 今日が24節気かどうか調べる
// 引数 .... 計算対象となる年月日 year month day
// 戻り値 .... 24節気の名称
//=========================================================================
func get24Sekki(year:Double, month:Double,day:Double)-> (String ) {
let sekkiName = ["春分","清明","穀雨","立夏","小満","芒種","夏至","小暑","大暑","立秋","処暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至","小寒","大寒","立春","雨水","啓蟄"] // 24節気の定義
var JD: Double
var JD1: Double
var JD2: Double
var t: Double
var today: Int
var tomorrow: Int
//今日の太陽の黄経
JD = ymd2jd(yea: year, mont: month, ysDay: day) //ユリウス日の計算
JD1 = floor(JD) //時刻引数を分解する
JD2 = JD - JD1
JD2 -= 9.0 / 24.0
t = (JD2 + 0.5) / 36525.0
t = t + (JD1 - 2451545.0) / 36525.0
today = Int( LONGITUDE_SUN(t:t))
//明日の太陽の黄経
JD += 1
JD1 = floor(JD) //時刻引数を分解する
JD2 = JD - JD1
JD2 -= 9.0 / 24.0
t = (JD2 + 0.5) / 36525.0
t = t + (JD1 - 2451545.0) / 36525.0
tomorrow = Int( LONGITUDE_SUN(t: t))
today = Int( 15.0 * floor( Double( today ) / 15.0 ))
tomorrow = Int( 15.0 * floor( Double( tomorrow) / 15.0))
if today != tomorrow {
return( "*" + sekkiName[ tomorrow/15] )
}else{
return( sekkiName[ tomorrow/15] )
}
}
//=========================================================================
// (1月または2月の場合は前年の13月、14月とみなして計算)
//=========================================================================
func ymd2jd(yea: Double, mont: Double, ysDay: Double) -> (Double){
var jd: Double
var year = yea
var month = mont
// var day = ysDay
if month < 3.0 {
year -= 1.0
month += 12.0
}
jd = floor( 365.25 * year );
jd += floor( year / 400.0 ); //うるう年補正
jd -= floor( year / 100.0 );
jd += floor( 30.59 * ( month - 2.0 ) );
jd += ysDay + 1721088;
return( jd );
}
//=========================================================================
// 太陽の黄経 λsun(t) を計算する(t は力学時)
//=========================================================================
func LONGITUDE_SUN( t: Double) -> (Double){
var ang: Double
var th: Double
let k = Double.pi / 180.0
//-----------------------------------------------------------------------
// 摂動項の計算
//-----------------------------------------------------------------------
th = 0.0004 * cos( k * NORMALIZATION_ANGLE( angle: 31557 * t + 161 ) )
th += 0.0004 * cos( k * NORMALIZATION_ANGLE( angle: 29930 * t + 48 ) )
th += 0.0005 * cos( k * NORMALIZATION_ANGLE( angle: 2281 * t + 221 ) )
th += 0.0005 * cos( k * NORMALIZATION_ANGLE( angle: 155 * t + 118 ) )
th += 0.0006 * cos( k * NORMALIZATION_ANGLE( angle: 33718 * t + 316 ) )
th += 0.0007 * cos( k * NORMALIZATION_ANGLE( angle: 9038 * t + 64 ) )
th += 0.0007 * cos( k * NORMALIZATION_ANGLE( angle: 3035 * t + 110 ) )
th += 0.0007 * cos( k * NORMALIZATION_ANGLE( angle: 65929 * t + 45 ) )
th += 0.0013 * cos( k * NORMALIZATION_ANGLE( angle: 22519 * t + 352 ) )
th += 0.0015 * cos( k * NORMALIZATION_ANGLE( angle: 45038 * t + 254 ) )
th += 0.0018 * cos( k * NORMALIZATION_ANGLE( angle: 445267 * t + 208 ) )
th += 0.0018 * cos( k * NORMALIZATION_ANGLE( angle: 19 * t + 159 ) )
th += 0.0020 * cos( k * NORMALIZATION_ANGLE( angle: 32964 * t + 158 ) )
th += 0.0200 * cos( k * NORMALIZATION_ANGLE( angle: 71998.1 * t + 265.1 ) )
ang = NORMALIZATION_ANGLE( angle: 35999.05 * t + 267.52 )
th = th - 0.0048 * t * cos( k * ang )
th += 1.9147 * cos( k * ang )
//-----------------------------------------------------------------------
// 比例項の計算
//-----------------------------------------------------------------------
ang = NORMALIZATION_ANGLE( angle: 36000.7695 * t )
ang = NORMALIZATION_ANGLE( angle: ang + 280.4659 )
th = NORMALIZATION_ANGLE( angle: th + ang )
return (th)
}
//#=========================================================================
//# 角度の正規化を行う。すなわち引数の範囲を 0≦θ<360 にする。
//#=========================================================================
func NORMALIZATION_ANGLE(angle: Double)-> (Double){
return (angle - 360.0 * floor(angle / 360.0))
}
ここまで読んでいただき、ありがとうございます