#!/usr/bin/env python
#
# Data Quality Checker also known as DQC
#
# Read the README.md for more detailed information
#
#       Barcelona Supercomputing Center - Centro Nacional de Supercomputacion
#       Earth Sciences Department - Computational Earth Sciences
#
#     Authors:
#       Joan Sala Calero (joan.sala@bsc.es)

import configparser
import glob
import os

config = configparser.RawConfigParser()
conf_dir = '/shared/QAR_dqc/results'
vars = []

for f in glob.glob(os.path.join(conf_dir, '*.ini')):

    # Read configuration
    config.read(f)

    # Only single levels
    if ('pressure-levels' in f) or ('postprocessed' in f):
        continue

    # Read test result (those with missing values)
    if (config['spatial_completeness_result']['res']) == 'err' and \
            config['spatial_completeness_result']['msg'] == 'Files contain missing values. Check log messages in the following pages':

        if 'reanalysis' in f:
            vars.append(os.path.basename(f).split('-')[-1].replace('.ini', ''))
        else:
            vars.append(os.path.basename(f).split('-')[-3])

for v in set(vars):
    print(v)