import os
import numpy as np
from Config import ReadConfig
from datetime import datetime

work_dir = "/public/home/fangyuedong/CSST/test/"
data_dir = "/data/simudata/CSSOSDataProductsSims/data/"

config_file = os.path.join(work_dir, "ObservationSim.cfg")
config = ReadConfig(config_file)

# Read Pointing list
pointing_file = os.path.join(data_dir, "pointing10_20210202.dat")
f = open(pointing_file, 'r')
for _ in range(1):
    header = f.readline()
iline = 0
pRA = []
pDEC = []
for line in f:
    line = line.strip()
    columns = line.split()
    pRA.append(float(columns[0]))
    pDEC.append(float(columns[1]))
f.close()
pRA = np.array(pRA)
pDEC = np.array(pDEC)

# Create calibration pointings
ncal = 1 # Define the number of calibration pointings
pointing_type = ['MS']*len(pRA)
pRA = np.append(pRA[:ncal], pRA)
pDEC = np.append(pDEC[:ncal], pDEC)
pointing_type = ['CAL']*ncal + pointing_type

# Calculate starting time(s)
t0 = datetime(2021, 5, 25, 12, 0, 0)
t = datetime.timestamp(t0)
timestamp_obs = []
for i in range(len(pointing_type)):
    timestamp_obs.append(t)
    if pointing_type[i] == 'CAL':
        t += 3 * 5 * 60 # 3 calibration exposure
    elif pointing_type[i] == 'MS':
        t += 5 * 60

# Define the range of pointing list
pRange = range(0, 2)