#!/bin/csh# =================================================================================================# Functions implemented:# - Download products from JAXA Himawari-8# Script Usage:# - ./download.csh 2018 03 27 2018 03 31 |& tee download.log# Author information:# - Created by ZHANG Hua (zhangh20011114@gmail.com), 2024/6/16.# =================================================================================================# >>> Set output directoryset OUT_HOME =../origin
# >>> Set ftp server informationset HOST = ftp.ptree.jaxa.jp
set PORT =21set USERNAME = *********** # Replace with your usernameset PASSWORD = *********** # Replace with your password# >>> Set product informationset level = L2
settype= ARP
set version = 030
set REMOTE_HOME = ftp://${USERNAME}:${PASSWORD}@${HOST}:${PORT}/pub/himawari/${level}/${type}/${version}# >>> Set start date and end dateset year_start =$argv[1]# 2024set month_start =$argv[2]# 02set day_start =$argv[3]# 01set year_end =$argv[4]# 2024set month_end =$argv[5]# 02set day_end =$argv[6]# 29# >>> Set the hours and minutes for daily downloadsset hour_start =9# This can be changed according to personal demandset hour_end =18# This can be changed according to personal demandset minutes =(00 1020304050)# This can be changed according to personal demand# >>> Transform local time to UTC whether or notset doTimeTrans =1if(${doTimeTrans})thenset HOUR_TRANS =-8# CST to UTCelseset HOUR_TRANS =0
endif
# DAY_MAX can be changed, and it serves to prevent# the entry of many days by mistake.set DAY_MAX =31# >>> Echo start date and end dateset date_start =${year_start}-${month_start}-${day_start}set date_end =${year_end}-${month_end}-${day_end}echo"Start date: ${date_start}"echo"End date: ${date_end}"# >>> Test the number of days to be processed
@ DAY_NUM =(`date-ud ${date_end} +%s` - `date-ud ${date_start} +%s`) / 86400 + 1if(${DAY_NUM}>${DAY_MAX}||${DAY_NUM}<0)thenecho"Error: The date is illegal."if(${DAY_NUM}>${DAY_MAX})thenecho"Error: The number of days to be processed exceeds ${DAY_MAX}."exit1elseecho"Error: The end date precedes the start date."exit1
endif
endif
# >>> Download file daily cycleset day_second_start =`date-ud ${date_start} +%s`set day_second_end =`date-ud ${date_end} +%s`set day_second_now =${day_second_start}while(${day_second_now}<=${day_second_end})set date_now =`date-ud @${day_second_now} +%Y-%m-%d`echo"Working date: ${date_now}"set hour_now =${hour_start}while(${hour_now}<=${hour_end})
foreach MM (${minutes})
@ minute_second_now_loc =${day_second_now} + ${hour_now} * 3600 + ${MM} * 60
@ minute_second_now_utc =${minute_second_now_loc} + ${HOUR_TRANS} * 3600set yyyymm =`date-ud @${minute_second_now_utc} +%Y%m`set yyyymmdd_hhmm =`date-ud @${minute_second_now_utc} +%Y%m%d_%H%M`setdd=`date-ud @${minute_second_now_utc} +%d`set hh =`date-ud @${minute_second_now_utc} +%H`set out_path =${OUT_HOME}/${level}/${type}/${version}/${yyyymm}if(!-d${out_path})thenmkdir-p${out_path}
endif
set remote_path =${REMOTE_HOME}/${yyyymm}/${dd}/${hh}set filename = NC_H08_${yyyymmdd_hhmm}_${level}${type}${version}_FLDK.02401_02401.nc
set syscmd ="wget -P ${out_path}${remote_path}/${filename}"echo"${syscmd}"${syscmd}&# Multiprocess parallelismsleep0.5# Don't delete it! # Wait to connect to ftp server
end
@ hour_now ++
end
@ day_second_now =${day_second_now} + 24 * 3600
end
wait# Wait for all process to completeecho"Successfully download all files!"