def main():
    print("you are using", platform.system(), platform.release(), os.name)

    # creating the central shared dgsn-node-data for all programs on the nodes
    #######################################
    pathname = os.path.abspath(os.path.dirname(sys.argv[0]))
    pathname_all = ""
    for i in range(len(pathname.split(path_separator))-2): # creating the folders two folder levels above
        pathname_all = pathname_all + pathname.split(path_separator)[i] + path_separator
    pathname_save = pathname_all + "dgsn-node-data"
    pathname_config = pathname_all + "dgsn-hub-ops"

    # creating the dump folder for files and the needed data folders
    #######################################
    if not os.path.exists(pathname_save):
        os.makedirs(pathname_save)

    folder = pathname_save + path_separator + "rec"
    subfolders = ["iq", "sdr", "gapped", "coded", "monitor"]
    if not os.path.exists(folder):
        os.makedirs(folder)

    if os.path.exists(folder):
        for i in range(len(subfolders)):
            if not os.path.exists(folder + path_separator + subfolders[i]):
                os.makedirs(folder + path_separator + subfolders[i])

    if not os.path.exists(pathname_config):
        os.makedirs(pathname_config)

    pathname_config = pathname_config + path_separator + "io-radio"

    if not os.path.exists(pathname_config):
        os.makedirs(pathname_config)

    # setting the rtlsdr before the gain finding
    #####################################

    # getting one file to each node very simple via github, or via a local file copy
    data = loading_config_file(pathname_config)

    # getting the specific settings for the node itself. perhaps it cannot be as fast as others
    with open(pathname + path_separator +'node-config.json') as data_file:
        data_node = json.load(data_file)

    device_number = data["device_number"]
    center_frequency = data["center_frequency"]
    samplerate = data["samplerate"]

    # this will be necessary in case a full fledged pc is a node or in case a micro pc is used with less RAM
    secondsofrecording = min(data["secondsofrecording"], data_node["secondsofrecording_maximum"])
    print("record seconds commanded", data["secondsofrecording"], "record seconds maximum",
          data_node["secondsofrecording_maximum"], "and it is", secondsofrecording)

    nsamples = secondsofrecording * samplerate
    freq_correction = data["freq_correction"]
    user_hash = get_groundstationid()

    dt = datetime.datetime(data["recording_start"]["year"], data["recording_start"]["month"], data["recording_start"]["day"],
                           data["recording_start"]["hour"], data["recording_start"]["minute"], data["recording_start"]["second"])
    recording_start = time.mktime(dt.timetuple())

    dt = datetime.datetime(data["recording_end"]["year"], data["recording_end"]["month"], data["recording_end"]["day"],
                           data["recording_end"]["hour"], data["recording_end"]["minute"], data["recording_end"]["second"])
    recording_stop = time.mktime(dt.timetuple())

    # getting the data for calibration
    calibration_start = data["calibration_start"]
    gain_start = data["gain_start"]
    gain_end = data["gain_end"]
    gain_step = data["gain_step"]
    signal_threshold = data["signal_threshold"]
    print("gg", gain_start, gain_end)

    ##################################
    print("starting the fun...")

    if platform.system() == "Windows":
        print("detecting a windows")
        ##############
        device_count = librtlsdr.rtlsdr_get_device_count()
        print("number of rtl-sdr devices:", device_count)

        if device_count > 0:
            lock = Lock()
            jobs = []
            gain = 0
            calibration_finished = 0 # 1 means calibration is done

            while time.mktime(time.gmtime()) <= recording_start or calibration_finished == 0:
                # waiting for the time to be right :)
                time.sleep(10)
                print("still to wait", recording_start - time.mktime(time.gmtime()), "to record and",
                  recording_start - time.mktime(time.gmtime())- calibration_start, "to calibration")

                if time.mktime(time.gmtime()) > recording_start - calibration_start and calibration_finished == 0:
                    sdr = RtlSdr(device_index=device_number)
                    sdr.center_freq = center_frequency
                    sdr.sample_rate = samplerate
                    # sdr.freq_correction = 1   # PPM

                    # calibrating the dongle
                    if gain_start >= gain_end or gain_start >= 49.0:
                        print("fixed gain")
                        if gain_start==0 or gain_start > 49.0:
                            print("autogain")
                            gain = 'auto'
                        else:
                            gain = gain_start

                    else:
                        print("calibrated gain")
                        gain = calibrating_gain_with_windows(sdr, samplerate, gain_step, gain_start,
                                                             gain_end, signal_threshold)

                    print("used gain", gain)
                    sdr.gain = gain

                    sdr.close()
                    calibration_finished = 1

            utctime = time.mktime(time.gmtime())
            if utctime >= recording_start and utctime <= recording_stop:
                print("recording starts now...")
                for recs in range(2):
                    p = Process(target=storing_stream_with_windows, args=(lock, device_number, folder, subfolders,
                                                                          center_frequency, samplerate, gain, nsamples,
                                                                          freq_correction, user_hash))
                    jobs.append(p)
                    p.start()
                print("end")

                while time.mktime(time.gmtime()) <= recording_stop:
                    time.sleep(2)
                    for n, p in enumerate(jobs):
                        if not p.is_alive() and time.mktime(time.gmtime()) <= recording_stop:
                            jobs.pop(n)
                            recs += 1
                            p = Process(target=storing_stream_with_windows, args=(lock, device_number, folder,
                                                                                  subfolders, center_frequency,
                                                                                  samplerate, gain, nsamples,
                                                                                  freq_correction, user_hash))
                            jobs.append(p)
                            p.start()
                            print("rec number", recs, 'added')

            for job in jobs:
                job.join()

    elif platform.system() == "Linux" or platform.system() == "Linux2":
        print("detecting a linux")

        # getNumber_of_rtlsdrs_with_linux()

        gain = 0
        calibration_finished = 0

        while time.mktime(time.gmtime()) <= recording_start or calibration_finished == 0:
            # waiting for the time to be right :)
            time.sleep(10)
            print("still to wait", recording_start - time.mktime(time.gmtime()), "to record and",
                  recording_start - time.mktime(time.gmtime())- calibration_start, "to calibration")

            if time.mktime(time.gmtime()) > recording_start - calibration_start and calibration_finished == 0:
                if gain_start >= gain_end or gain_start >= 49.0:
                    print("fixed gain")
                    if gain_start==0 or gain_start > 49.0:
                        print("autogain")
                        gain = 0
                    else:
                        gain = gain_start

                else:
                    print("calibrated gain")
                    gain = calibrating_gain_with_linux(device_number, center_frequency, samplerate, gain_step,
                                                       gain_start, gain_end, signal_threshold)
                print("used gain", gain)
                calibration_finished = 1

        utctime = time.mktime(time.gmtime())
        if utctime >= recording_start and utctime <= recording_stop:
            print("recording starts now...")

            rtl_sdr_exe = "rtl_sdr"
            sdr = Popen([rtl_sdr_exe, "-d", str(device_number), "-f", str(center_frequency), "-s", str(samplerate),
                         "-g", str(gain), "-p", str(freq_correction), "-"],
                        stdout=PIPE, stderr=None)

            while time.mktime(time.gmtime()) <= recording_stop:
                stream_data = sdr.stdout.read(nsamples*2)
                storing_stream_with_linux(stream_data, device_number, folder, subfolders, center_frequency, samplerate,
                                          gain, nsamples, freq_correction, user_hash)

            sdr.kill()
    print("it's done. thank you, please come back again!")