a
    9lh                     @   s   d dl Z dd Zdd ZdS )    Nc              
   C   s   t d|  d tj| s0t d|  d dS z\t| d>}t|D ]$\}}t d|d  d	|   qFW d   n1 s0    Y  W n2 ty } zt d
|  W Y d}~n
d}~0 0 dS )z
    Reads an ASCII file line by line and prints each line.
    Useful for simple text files or when processing each line individually.
    z
--- Reading 'z' line by line ---Error: File '' not found.NrzLine    : z.An error occurred while reading line by line: )printospathexistsopen	enumeratestrip	Exception)filenamefZline_numlinee r   e/share/grpeta/dsk001/dist/users/jorge/cicloneBapo/2015020200/Eta10km_Topo1hPa/python2Nc/EtaLibrary.pyread_ascii_line_by_line   s    @r   c                 C   sB  t d|  d tj| s0t d|  d dS i }g d}zt| dt}|D ]}|  }|st d| d	  W d   W dS z"|d
d  }t|||< W qR t	t
fy } z8t d| d| d|  W Y d}~ W d   W dS d}~0 0 qR|  }|  }	|r*|	sDt d W d   W dS zt||d< t|	|d< W nP t
y } z6t d| d|	 d|  W Y d}~W d   W dS d}~0 0 W d   n1 s0    Y  t d | D ]\}}
t d| d|
  q|W S  ty< } zt d|  W Y d}~dS d}~0 0 dS )z
    Reads specific grid information (west, east, north, south, res)
    and two subsequent integer values from an ASCII file.
    z-
--- Reading specific grid information from 'z' ---r   r   N)westeastnorthsouthresr   z-Error: Unexpected end of file while reading 'z'.=r   zError parsing line for 'z': 'z' - z;Error: Unexpected end of file while reading integer values.nlonsnlatszError parsing integer values: 'z', 'z
Parsed Grid Information:z  r   zAn unexpected error occurred: )r   r   r	   r
   r   readliner   splitfloat
IndexError
ValueErrorintitemsr   )r   Z	grid_infoZexpected_keysr   keyr   Z	value_strr   line1line2valuer   r   r   read_specific_grid_info   sJ    *Fr)   )r   r   r)   r   r   r   r   <module>   s   