0
1

More than 3 years have passed since last update.

VERA当番日報で役に立ちそうなツール

Last updated at Posted at 2020-08-08

日報メールをより楽に

当番に入った観測兵は日報メールを出すことが義務である。しかし、日報メールの天候の欄がどうもめんどくさい。特に風向。これをなんとかしたい。
pythonの方が良いかなあと思いつつ、pythonを使うほどでもないか(スナネコ)ということでC原語で書いた。力技で書いているので適宜修正していくつもりである。
mac OSで動作確認済み。

追記:
大変ありがたいコメントによって曜日、風向がすっきりしました。
ありがとうございます。20/8/9
日付けを取得する部分で不備が見つかりました。修正してます。20/8/10

プログラムの構成は、日付け取得→データ入力→条件分岐(風向、曜日)→出力となっている。
入力のフォーマットは以下の通り。一番上の行(UT00:00)を丸々コピーすれば良い。

input_format
2020221000000      7.91      3.76      9.45      4.41    229.60     26.99     26.48     78.91     78.95    951.07      0.13     10.65     10.35

天候も自分で入力していただきたい。

以下ソースコード。

VERA_weather.c
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>

int main(){

    int DAYS;
    double SPDNOW, SPDAVE, SPDMAX1, SPDMAX2, DIRECT;
    double TEMP1, TEMP2;
    double HUMID1, HUMID2;
    double PRESS;
    double RAIN, DHUMID1, DHUMID2;

    char in[256];
    char weather[16];
    char windDirection[3] = "";

    time_t timer;
    struct tm *date;
    char week[16];

/*入力データ*/
    printf("input data.\n");
    fgets(in, 256, stdin);
    printf("today's weather?\n");
    fgets(weather, 16, stdin);
    printf("\ncopy under text\n");

/*今日の日付けを取得*/
    timer = time(NULL);
    date = localtime(&timer);

    printf("%d/%d", date->tm_mon+1, date->tm_mday);

    strftime(week, 15, "%a", date);

    const char DayOfWeekTable[] = "MonTueWedThuFriSatSun";
    const char* dayOfWeek = strstr(DayOfWeekTable, week);
    if (dayOfWeek) {
        printf("(%s)", (const char*[]){"月", "火", "水", "木", "金", "土", "日"}[(dayOfWeek - DayOfWeekTable) / 3]);
    }

    printf("UT00:00 ");

/*入力データの処理*/
    sscanf(in, "%d      %lf      %lf      %lf      %lf      %lf      %lf      %lf      %lf      %lf      %lf      %lf      %lf      %lf",&DAYS,&SPDNOW, &SPDAVE, &SPDMAX1, &SPDMAX2, &DIRECT, &TEMP1, &TEMP2, &HUMID1, &HUMID2, &PRESS, &RAIN, &DHUMID1, &DHUMID2);
    printf("気温 %.2lf °C 湿度 %.2lf % 気圧 %.2lf hPa 風速 %.2lf m/s 風向 ",TEMP2, HUMID2, PRESS, SPDAVE);

    strcpy(windDirection, (const char*[]){"N", "NE", "E", "SE", "S", "SW", "W", "NW"}[(int)(fmod(DIRECT + 22.5, 360) / 45.0)]);
    printf("%s %s\n",windDirection, weather);

    return 0;
}

出力はこのようになるはず。

output
8/8()UT00:00 気温 26.48 °C 湿度 78.95  気圧 951.07 hPa 風速 3.76 m/s 風向 SW [ここに入力した天候が入る]
0
1
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1