时间系统的换算(一)太阳日和儒略日的转换

注:对于时间系统的概念如儒略日等的介绍,请参考时间系统一文时间系统介绍-CSDN博客

一、已知年月日,求儒略日

在1900年3月1日至2100年2月28间区间内,已会日期和时间求儒略日的公式为[1]:

式中,INT(x)——只保留x的整数部分(即向零取整),如INT(-3.9)=-3

二、已知儒略日,求年月日

寻找儒略日的过程在算法14中直接得到。但反之已知儒略日找到公历的日期也是必要的。第一步是通过确定一个时代的儒略年数来找到观测的年份。使用1900年作为起点(不是闰年),但是这个历元限制了算法有效的时间跨度(1900-2100)。算法如下[1]:

· Fortran程序

我这里使用vs code 里面的MinGW-w64带的gfortran编译器实现fortran代码的调试。详情可参见

VScode中配置使用fortran-CSDN博客以及https://www.cnblogs.com/luffeverne/p/14659752.html(这个参考的多)

注意:WIndows 选择这个版本 x86_64-win32-seh,Linux选择x86_64-posix-seh。

① main.f90函数(设置年月日时间等信息)
PROGRAM MainProgram
    IMPLICIT NONE
    INTEGER Year, Mon, Day, Hr, Min
    DOUBLE PRECISION Sec, JD

    Year = 1995      ! 设置相应的年月日时间值
    Mon = 6
    Day = 8
    Hr = 20
    Min = 18
    Sec = 3.7036800

    CALL JULIANDAY(Year, Mon, Day, Hr, Min, Sec, JD)  !调用函数JULIANDAY做运算

    ! 输出结果
    WRITE(*, *) "Calculation Result:"
    WRITE(*, *) "Year: ", Year
    WRITE(*, *) "Month: ", Mon
    WRITE(*, *) "Day: ", Day
    WRITE(*, *) "Hour: ", Hr
    WRITE(*, *) "Minute: ", Min
    WRITE(*, *) "Second: ", Sec
    WRITE(*, *) "Julian Day: ", JD

END PROGRAM MainProgram
②JulianDay.f90函数

该文件包含两个子函数JULIANDAY与JULIANDAYALL。JULIANDAY子程序使用了儒略日的基本计算公式。根据给定的年、月、日、小时、分钟和秒钟,它将计算儒略日的值并存储在JD变量中。JULIANDAYALL子程序根据日历类型(WhichType)的不同,采用不同的计算公式来计算儒略日。如果日历类型是 'J',则使用儒略历的计算公式;如果是其他值,则使用格里高利历的计算公式。

儒略历中的普通一年有 365 天,分为12个月。每四年为一次闰年,二月是一年中的最后一个月,闰日是 2 月 24 日。

      SUBROUTINE JULIANDAY   ( Year,Mon,Day,Hr,Min, Sec, JD )
        IMPLICIT NONE
        INTEGER Year, Mon, Day, Hr, Min
        DOUBLE PRECISION Sec , JD

! ------------------------  Implementation   --------------------------
        JD = 367.0D0 * Year - INT( (7* (Year+INT ( (Mon+9)/12) ) ) * 0.25D0 ) + &
             INT( 275*Mon / 9 ) + Day + 1721013.5D0 + ( (Sec/60.0D0 + Min ) / 60.0D0 + Hr 
             )/ 24.0D0
        RETURN
        END

      SUBROUTINE JULIANDAYALL( Year,Mon,Day,Hr,Min,Sec, WhichType, JD )
        IMPLICIT NONE
        INTEGER Year, Mon, Day, Hr, Min
        CHARACTER WhichType
        DOUBLE PRECISION Sec, JD
! ----------------------------  Locals  -------------------------------
        REAL*8 B  !声明双精度实数类型

! ------------------------  Implementation   --------------------------
        IF ( Mon .le. 2 ) THEN
            Year= Year - 1
            Mon = Mon + 12
          ENDIF
        IF ( WhichType .eq. 'J' ) THEN
! -------- Use for Julian calender, every 4 years ---------
            B= 0.0D0   !如果历法类型是儒略历,将变量 B 的值设为 0.0。
          ELSE
! --------------------- Use for Gregorian -----------------
            B= 2 - DINT(Year*0.01D0) + DINT(DINT(Year*0.01D0)*0.25D0)
          ENDIF
        JD= DINT( 365.25D0*(Year + 4716) ) + & 
            DINT( 30.6001D0*(Mon+1) ) + &
            Day + B - 1524.5D0 + &
            ( (Sec/60.0D0 + Min ) / 60.0D0 + Hr ) / 24.0D0
      RETURN
      END
③launch.json文件(vs code配置调试器,用于支持在 VS Code 中调试 Fortran 代码)
{
    "version": "0.0.1",
    "configurations": [
        
        {
            "name": "Fortran Launch (GDB)",
            "type": "cppdbg",
            "request": "launch",
            "targetArchitecture": "x86",
            "program": "${workspaceRoot}\\${fileBasenameNoExtension}.exe",
            "MIMode": "gdb",
            "miDebuggerPath": "C:/environment/mingw64/bin/gdb.exe",//结合自己的路径!
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "externalConsole": true,
            "preLaunchTask": "gfortran"
        },
        {
            "name": "Intel Debug Attach",
            "type": "cppvsdbg",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ] }
④tasks.json
{
    "version": "2.0.0",
    "command": "gfortran",
    "args": [
        "-g",
        "${workspaceFolder}\\*.f90", 
         // 编译命令将会编译所有 .f90 文件,并生成与当前打开文件同名的可执行文件。若是单个文件,则为 "${file}",
        "-o",
        "${workspaceFolder}\\${fileBasenameNoExtension}.exe"
    ],
    "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": false,
        "panel": "new",
        "showReuseMessage": true,
        "clear": false
    }
}
⑤输出结果

在终端中编译并运行程序,并将输出重定向到一个文本文件。执行以下命令:

gfortran -o main.exe main.f90 JulianDay.f90
./main.exe > output.txt

将程序的输出结果保存到名为 output.txt 的文本文件中。
在 Visual Studio Code 中,打开 output.txt 文件以查看计算结果。

结果图如下:

参考文献

[1] Vallado, D.A. Fundamentals of Astrodynamies and Applicntions (4th,Edition),Micyocosm Press,2013;(非常推荐)

[2]《深空探测轨道设计与分析》赵瑞安著,中国宇航出版社;

  • 16
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,下面是一个简单的 Android Studio 程序,实现美元和人民币之间的货币换算。程序包含一个文本框用于输入金额,两个单选按钮用于选择转换方向,以及一个按钮用于触发计算。代码中使用了汇率 1 美元 = 6.5 人民币,可以根据需要进行修改。 首先,在 layout 文件夹下的 activity_main.xml 中添加以下代码: ```xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <EditText android:id="@+id/editText" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="numberDecimal" android:hint="请输入金额"/> <RadioGroup android:id="@+id/radioGroup" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioButton android:id="@+id/radioButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="美元转人民币"/> <RadioButton android:id="@+id/radioButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="人民币转美元"/> </RadioGroup> <Button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="计算"/> <TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="20sp" android:textStyle="bold" android:textColor="#000000" android:textAlignment="center"/> </LinearLayout> ``` 然后,在 MainActivity.java 中添加以下代码: ```java import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { private EditText editText; private RadioButton radioButton1, radioButton2; private Button button; private TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); editText = findViewById(R.id.editText); radioButton1 = findViewById(R.id.radioButton1); radioButton2 = findViewById(R.id.radioButton2); button = findViewById(R.id.button); textView = findViewById(R.id.textView); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String input = editText.getText().toString(); if (input.isEmpty()) { textView.setText("请输入金额"); } else { double amount = Double.parseDouble(input); double result; if (radioButton1.isChecked()) { result = amount * 6.5; textView.setText(String.format("%.2f 美元", result)); } else if (radioButton2.isChecked()) { result = amount / 6.5; textView.setText(String.format("%.2f 人民币", result)); } else { textView.setText("请选择转换方向"); } } } }); } } ``` 以上程序实现了一个简单的美元和人民币之间的货币换算应用。启动程序后,用户输入金额并选择转换方向,点击计算按钮即可得到转换后的结果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值