<commit_before># <NAME> 4/8/2013
"""
fort15_management handles the reading/writing of ``fort.15`` formatted files
"""

import numpy as np
import os, re, math
import polyadcirc.pyADCIRC.basic as basic

filetype = {'fort61':(True, 1), 'fort62':(True, 2), 'fort63':(False, 1),
            'tinun63':(False, 1), 'maxele63':(False, 1), 
            'maxvel63':(False, 1), 'nodeflag63':(False, 1),
            'rising63':(False, 1), 'elemaxdry63':(False, 1),
            'fort64':(False, 2), 'fort71':(True, 1), 'fort72':(True, 2),
            'fort73':(False, 1), 'fort74':(False, 2)}

def read_recording_data(data, path=None):
    """
    Reads in ``fort.15`` and stores the following in data as a
    :class:`~polyadcirc.pyADCIRC.basic.time` object
    (``DT``, ``STATIM``, ``RNDAY``, ``DRAMP``)

    Calulcates and stores:
        
        * recording[key] = (meas_locs, total_obs, irtype)
        * stations[key] = list() of locations

    :type data: :class:`~polyadcirc.run_framework.domain`
    :param data: object to store reference to
        :class:`~polyadcirc.pyADCIRC.basic.time` 
    :type path: string or None
    :param path: directory containing ``fort.15`` file 
    :return: reference to ``data.recording`` and ``data.stations``
    :rtype: :class:`~polyadcirc.pyADCIRC.basic.time`

    """
    if path == None:
        path = os.getcwd()

    file_name = path+'/fort.15'
        
    data.stations = {}
    data.recording = {}

    with open(file_name, 'r+') as fid:
        line = fid.readline()
        while line != '':
            if line.find('DT') >= 0:
                line = line.partition('!')
                dt = float(line[0].strip()) # pylint: disable=C0103
            elif line.find('STATIM') >= 0:
                line = line.partition('!')
                statim = float(line[0].strip())
            elif line.find('RNDAY') >= 0:
                line = line.partition('!')
                rnday = float(line[0].strip())
            elif line.find('DRAMP') >= 0:
                line = line.partition('!')
                dramp = np.fromstring(line[0].strip(), sep=' ')#float(line[0].strip())
                data.time = basic.time(dt, statim, rnday, dramp) 
            elif line.find('H0') >= 0:
                line = line.partition('!')[0]
                line = np.fromstring(line, sep=' ')
                data.h0 = np.fromstring(line[0])
            elif line.find('NOUTE') >= 0:
                line = line.partition('!')
                _read_record(fid, 'fort61', line, data)
            elif line.find('UNIT 62') >= 0:
                line = line.partition('!')
                _read_record(fid, 'fort62', line, data)
            elif line.find('NOUTC') >= 0:
                line = line.partition('!')
                #_read_record(fid, 'fort91', line, dt, data)
            elif line.find('UNIT 71/72') >= 0:
                line = line.partition('!')
                _read_record7(fid, 'fort71', 'fort72', line, data)
            elif line.find('NOUTGE') >= 0:
                line = line.partition('!')
                _read_record(fid, 'fort63', line, data)
            elif line.find('UNIT 64') >= 0:<commit_msg>h0 is a double not a array<commit_after># <NAME> 4/8/2013
"""
fort15_management handles the reading/writing of ``fort.15`` formatted files
"""

import numpy as np
import os, re, math
import polyadcirc.pyADCIRC.basic as basic

filetype = {'fort61':(True, 1), 'fort62':(True, 2), 'fort63':(False, 1),
            'tinun63':(False, 1), 'maxele63':(False, 1), 
            'maxvel63':(False, 1), 'nodeflag63':(False, 1),
            'rising63':(False, 1), 'elemaxdry63':(False, 1),
            'fort64':(False, 2), 'fort71':(True, 1), 'fort72':(True, 2),
            'fort73':(False, 1), 'fort74':(False, 2)}

def read_recording_data(data, path=None):
    """
    Reads in ``fort.15`` and stores the following in data as a
    :class:`~polyadcirc.pyADCIRC.basic.time` object
    (``DT``, ``STATIM``, ``RNDAY``, ``DRAMP``)

    Calulcates and stores:
        
        * recording[key] = (meas_locs, total_obs, irtype)
        * stations[key] = list() of locations

    :type data: :class:`~polyadcirc.run_framework.domain`
    :param data: object to store reference to
        :class:`~polyadcirc.pyADCIRC.basic.time` 
    :type path: string or None
    :param path: directory containing ``fort.15`` file 
    :return: reference to ``data.recording`` and ``data.stations``
    :rtype: :class:`~polyadcirc.pyADCIRC.basic.time`

    """
    if path == None:
        path = os.getcwd()

    file_name = path+'/fort.15'
        
    data.stations = {}
    data.recording = {}

    with open(file_name, 'r+') as fid:
        line = fid.readline()
        while line != '':
            if line.find('DT') >= 0:
                line = line.partition('!')
                dt = float(line[0].strip()) # pylint: disable=C0103
            elif line.find('STATIM') >= 0:
                line = line.partition('!')
                statim = float(line[0].strip())
            elif line.find('RNDAY') >= 0:
                line = line.partition('!')
                rnday = float(line[0].strip())
            elif line.find('DRAMP') >= 0:
                line = line.partition('!')
                dramp = np.fromstring(line[0].strip(), sep=' ')#float(line[0].strip())
                data.time = basic.time(dt, statim, rnday, dramp) 
            elif line.find('H0') >= 0:
                line = line.partition('!')[0]
                line = np.fromstring(line, sep=' ')
                data.h0 = np.fromstring(line[0])[0]
            elif line.find('NOUTE') >= 0:
                line = line.partition('!')
                _read_record(fid, 'fort61', line, data)
            elif line.find('UNIT 62') >= 0:
                line = line.partition('!')
                _read_record(fid, 'fort62', line, data)
            elif line.find('NOUTC') >= 0:
                line = line.partition('!')
                #_read_record(fid, 'fort91', line, dt, data)
            elif line.find('UNIT 71/72') >= 0:
                line = line.partition('!')
                _read_record7(fid, 'fort71', 'fort72', line, data)
            elif line.find('NOUTGE') >= 0:
                line = line.partition('!')
                _read_record(fid, 'fort63', line, data)
            elif line.find('UNIT 64') >= 0:
{'fraction_non_alphanumeric': 0.1717171717171717, 'fraction_numerical': 0.03282828282828283, 'mean_word_length': 2.068765133171913, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1873240', 'n_tokens_mistral': 2233, 'n_tokens_neox': 2036, 'n_words': 467}