a
    hk                     @   s   d Z ddlZddlZddlmZ ddlmZ ddlZddlm	Z	m
Z
 ddlZddlZddlmZmZmZmZ eeedZdd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Z dd Z!dS )z$ Tests for fortran sequential files     N)path)iglob)assert_equalassert_allclose)FortranFile_test_fortranFortranEOFErrorFortranFormattingErrordatac                  C   s   t ttdD ]} td| tj}|s4td|  t|	dt|	dt|	df}|	d
dd	}t| d
d}|j|dj|dd}|  tt|||}t|| qd S )Nfortran-*-*x*x*.dat%fortran-([^-]+)-(\d+)x(\d+)x(\d+).dat#Couldn't match %s filename to regex            s<r<u4dtypeF)order)r   r   join	DATA_PATHresearchIRuntimeErrorintgroupreplacer   read_recordreshapeclosenparangeprodastyper   )filenamemdimsr   fr
   expected r/   W/var/www/html/assistant/venv/lib/python3.9/site-packages/scipy/io/tests/test_fortran.pytest_fortranfiles_read   s    (r1   c                  C   s   t td} t| dd}|d}W d    n1 s80    Y  t|d d d t|d d d	 t|d
 d d t|d d ddg d S )Nzfortran-mixed.datr   r   z<i4,<f4,<i8,2<f8Zf0r   r   f1gffffff@f2r   Zf3gffffff@g333333@)r   r   r   r   r#   r   r   )r*   r-   recordr/   r/   r0   test_fortranfiles_mixed_record(   s    (r5   c            
   
   C   s"  t ttdD ]
} td| tj}|s6td|  t|	dt|	dt|	df}|	d
dd	}tt|||}t }zzt|t| }t|d
d}||j |  t| d}t|d}	t| |	 | d |  |	  W t| qt| 0 qd S )Nr   r   r   r   r   r   r   r   r   wr   rb)err_msg)r   r   r   r   r   r   r   r   r    r!   r"   r&   r'   r(   r$   r)   tempfilemkdtempbasenamer   write_recordTr%   openr   readshutilrmtree)
r*   r+   r,   r   r
   tmpdirZtestFiler-   Zoriginalfilenewfiler/   r/   r0   test_fortranfiles_write3   s*    (


rD   c                  C   s   t td} t| dd}|dd}W d    n1 s:0    Y  tdddtj	}tj
dd	gtjd
}t|d |j t|d |j d S )Nzfortran-3x3d-2i.datr   r   z(3,3)<f8z2<i4	   r   r   r   r   )r   r   r   r   r#   r&   r'   r$   r)   float64arrayint32r   r=   )r*   r-   r4   axbxr/   r/   r0   "test_fortranfile_read_mixed_recordM   s    *rM   c              	   C   s6  t t| d}dtdtdtdff}dtjjddgd	tjtjjdddgd	tjtjjdd
gd	tjff}||g}|D ]\}}t	|d}|j
|  W d    n1 s0    Y  t	|d}|j| }W d    n1 s0    Y  tt|t| t||D ]\}	}
t|
|	 qqd S )Ntest.dat)f4rO   i4r   r   d   )Z4f4z(3,3)f4Z8i4   r   )size   r6   r   )r   r   strr&   Zfloat32rJ   randomrandintr)   r   r<   r#   r   lenzip)rB   tfr1r2recordsr   ar-   bZaaZbbr/   r/   r0   #test_fortranfile_write_mixed_recordd   s"     ((r`   c                 C   sf  t t| d}tjd d\}}}tj|||}t|d}||j	 W d    n1 sb0    Y  t
||||}t|d}|dj	}W d    n1 s0    Y  t|| t|| d\}}}tj|||tj}t|d}||j	 W d    n1 s0    Y  t
||||}t|d}|dj	}W d    n1 s^0    Y  t|| t|| d\}}}tj||}tj|tj}	t|d }||j	|	j	 W d    n1 s0    Y  t
||||\}}
t|d&}|dd	\}}|j	}W d    n1 s00    Y  t|| t|| t|
|	 t||	 d S )
NrN   r   )   r   r   r6   r   z	(2,3,5)f8z	(2,3,5)i4z(3,5)f8Z2i4)r   r   rU   r&   rV   seedrandnr   r<   r=   r   Zread_unformatted_doubler#   r   r)   rJ   Zread_unformatted_intZintcZread_unformatted_mixed)rB   r*   r+   nkr^   r-   Za2a3r_   b2Zb3r/   r/   r0   test_fortran_roundtrip{   sB    
**


,,


0&


rh   c              	   C   s   t t| d}tjd t|d4}|tjd |tjd W d    n1 s`0    Y  t|dj}t	|
 dksJ t	|
 dksJ tt |
  W d    n1 s0    Y  W d    n1 s0    Y  d S )Nscratchr   r6   ra   r   r   )r   r   rU   r&   rV   rb   r   r<   rc   rX   
read_realspytestraisesr   rB   r*   r-   r/   r/   r0   test_fortran_eof_ok   s    0rn   c              	   C   s(  t t| d}tjd t|d4}|tjd |tjd W d    n1 s`0    Y  t	|d}|
d W d    n1 s0    Y  t|dj}t| dksJ t| dksJ tt |  W d    n1 s0    Y  W d    n1 s0    Y  d S )	Nri   r   r6   ra   r   ab   r   )r   r   rU   r&   rV   rb   r   r<   rc   r>   writerX   rj   rk   rl   r	   rm   r/   r/   r0   test_fortran_eof_broken_size   s    0(rr   c              	   C   s   t t| d}tjd t|d4}|tjd |tjd W d    n1 s`0    Y  t	|d}|
d W d    n1 s0    Y  t|dB}tt |  W d    n1 s0    Y  W d    n1 s0    Y  d S )	Nri   r   r6   ra   r   zw+bs   r   )r   r   rU   r&   rV   rb   r   r<   rc   r>   rq   rk   rl   r	   rj   rm   r/   r/   r0   test_fortran_bogus_size   s    0(rs   c              	   C   s  t t| d}tjd t|d4}|tjd |tjd W d    n1 s`0    Y  t	|d$}|
t |d  W d    n1 s0    Y  t|dV}t| dksJ tt |  W d    n1 s0    Y  W d    n1 s0    Y  d S )	Nri   r   r6   ra   r   ro      r   )r   r   rU   r&   rV   rb   r   r<   rc   r>   truncategetsizerX   rj   rk   rl   r	   rm   r/   r/   r0   test_fortran_eof_broken_record   s    02rw   c              	   C   sd  t t| d}d\}}}tdtj||ffg}tj||d}t|d2}||d  || || W d    n1 s0    Y  t	|d$}|
t |d  W d    n1 s0    Y  t|d	z}t|j|dd
ksJ t|j|d|ksJ tt |j|d W d    n1 s60    Y  W d    n1 sV0    Y  d S )Nri   )r   ra      fieldr   r6   r   ro   rt   r   r   )r   r   rU   r&   r   rH   Zzerosr   r<   r>   ru   rv   rX   r#   rk   rl   r	   )rB   r*   rd   r+   qdtr^   r-   r/   r/   r0   !test_fortran_eof_multidimensional   s    

(2r|   )"__doc__r9   r@   osr   globr   r   Znumpy.testingr   r   numpyr&   rk   Zscipy.ior   r   r   r	   r   dirname__file__r   r1   r5   rD   rM   r`   rh   rn   rr   rs   rw   r|   r/   r/   r/   r0   <module>   s*   +