o ������e<+����������������������@���s:���d�dl�Z�d�dlZd�dlZd�dlZdd��ZG�dd��d�ZdS�)�����Nc�����������������C���s���|���||�r|��||�S�|S��N)� has_option�get)Zconfig�section�name�default��r����8/lfs/h1/ops/prod/packages/epoch.v1.0.5/ush/epochstate.py�getWithDefault���s���r ���c�������������������@���s&��e�Zd�Zdd��Zdd��Zdd��Zdd��Zd d ��Zdd��Zd d��Z dd��Z dd��Zdd��Zdd��Z dd��Zdd��Zdd��Zdd��Zdd ��Zd!d"��Zd#d$��Zd%d&��Zd'd(��Zd)d*��Zd+d,��Zd-d.��Zd/d0��Zd1d2��Zd3d4��Zd5d6��Zd7d8��Zd9d:��Zd;d<��Z d=d>��Z!d?d@��Z"dAdB��Z#dIdDdE�Z$dFdG��Z%dHS�)J� EpochStatec�����������������C���sv���d|�_�d|�_g�|�_g�|�_g�|�_g�|�_d|�_d|�_d|�_d|�_ d|�_ d|�_d|�_d|�_ d|�_d|�_d|�_d|�_d|�_d�S�)Nznot setF��)� _statefile�_ok�_gefs�_cmce�_threshGefs�_threshCmce�_currentPartial�_inProgress�_lastCompleted�_gfsPartial�_gfsLastDone�_gfsaLastGrib2toMdv�_gfsbLastGrib2toMdv�_lirPartial�_lirLastDone�_cmcePartial� _cmceLastDone�_gefsPartial� _gefsLastDone��selfr���r���r ����__init__���s&��� zEpochState.__init__c�����������������C���s��||�_�d|�_tj�|�r�tjtjdd�}|�|�j���t |ddg��}dd��|� ��D��|�_t |ddg��}d d��|� ��D��|�_t |dd g��}dd��|� ��D��|�_ t |ddg��}d d��|� ��D��|�_t |ddd�|�_t |ddd�|�_t |ddd�|�_t |ddd�|�_t |ddd�|�_t |ddd�|�_t |ddd�|�_t |ddd�|�_t |ddd�|�_t |ddd�|�_t |ddd�|�_t |ddd�|�_t |ddd�|�_dS�td��g�|�_g�|�_g�|�_ g�|�_d|�_d|�_d|�_d|�_d|�_d|�_d|�_d|�_d|�_d|�_d|�_d|�_d|�_dS�)NTF)�strictZproj�GEFSc�����������������S�������g�|�]}|�qS�r���r�����.0r���r���r���r ���� <listcomp>>��������z+EpochState.readOrCreate.<locals>.<listcomp>�CMCEc�����������������S���r%���r���r���r&���r���r���r ���r(���@���r)���ZTHRESH_CMCEc�����������������S���r%���r���r���r&���r���r���r ���r(���B���r)���ZTHRESH_GEFSc�����������������S���r%���r���r���r&���r���r���r ���r(���D���r)���ZCurrentPartialr���Z InProgressZ LastCompletedZ GFSPartialZGFSLastDoneZGFSALastGrib2toMdvZGFSBLastGrib2toMdvZ LIRPartialZLIRLastDoneZCMCEPartialZCMCELastDoneZGEFSPartialZGEFSLastDonezB----Epoch State file does not exist, initialize to empty state----)r ���r����os�path�exists�configparser�ConfigParser�environ�readr ����splitr���r���r���r���r���r���r���r���r���r���r���r���r���r���r���r���r����print)r!���Z statefile�parserZlstr���r���r ����readOrCreate7���s\���zEpochState.readOrCreatec�����������������C����0���|t�|�j�vr|rtd|��|�j�|��d�S�d�S�)NzADDING CMCE for )�strr���r3����append�r!���r����debugr���r���r ����addCMCEr���� ��� �zEpochState.addCMCEc�����������������C���r6���)NzADDING GEFS for )r7���r���r3���r8���r9���r���r���r ����addGEFSx���r<���zEpochState.addGEFSc�����������������C����"���|t�|�j�vr|�j�|��d�S�d�S�r���)r7���r���r8����r!���r���r���r���r ���� addThreshGEFS~��������zEpochState.addThreshGEFSc�����������������C���r>���r���)r7���r���r8���r?���r���r���r ���� addThreshCMCE����rA���zEpochState.addThreshCMCEc�����������������C���� ���||�j�v�S�r���)r���r?���r���r���r ����hasCmce�������� zEpochState.hasCmcec�����������������C���rC���r���)r���r?���r���r���r ����hasGefs����rE���zEpochState.hasGefsc�����������������C���rC���r���)r���r?���r���r���r ���� hasThreshCMCE����rE���zEpochState.hasThreshCMCEc�����������������C���rC���r���)r���r?���r���r���r ���� hasThreshGEFS����rE���zEpochState.hasThreshGEFSc�����������������C����D���|D�]}|rt�d|���z|�j�|��W�q���t�d|���Y�qd�S�)Nz"Remove from model state file CMCE:z6Warning: Not found in model state CMCE, cannot remove:)r3���r����remove�r!����namesr:���r���r���r���r ���� removeCMCE���������zEpochState.removeCMCEc�����������������C���rI���)Nz"Remove from model state file GEFS:z6Warning: Not found in model state GEFS, cannot remove:)r3���r���rJ���rK���r���r���r ���� removeGEFS����rN���zEpochState.removeGEFSc�����������������C���s���||�_�d|�_d|�_d�S��Nr���)r���r���r����r!����ymdhr���r���r ����start����s��� zEpochState.startc�����������������C���s$���||�_�|�jdkrtd|�j��d�S�d�S�)N�COMBINEz7WARNING expected completion status of COMBINE but got: )r���r���r3���rQ���r���r���r ����checkForComplete����s��� �zEpochState.checkForCompletec�����������������C���� ���|�j�|krdS�g�d�}|�j|v�S�)NF)�CMORPH2�GFS�LIRr*���r$���rT����r���r����r!���rR���Zgoodr���r���r ����hasCompletedCmorph2�������� zEpochState.hasCompletedCmorph2c�����������������C�������d|�_�d|�_d�S�)NrW���r����r���r���rQ���r���r���r ����setCmorph2Completed�������� zEpochState.setCmorph2Completedc�����������������C���rV���)NF)rX���rY���r*���r$���rT���rZ���r[���r���r���r ����hasCompletedGfs����r]���zEpochState.hasCompletedGfsc�����������������C���r^���)NrX���r���r_���rQ���r���r���r ����setGfsCompleted����ra���zEpochState.setGfsCompletedc�����������������C���rV���)NF)rY���r*���r$���rT���rZ���r[���r���r���r ����hasCompletedLir����r]���zEpochState.hasCompletedLirc�����������������C���r^���)NrY���r���r_���rQ���r���r���r ����setLirCompleted����ra���zEpochState.setLirCompletedc�����������������C���rV���)NF)r*���r$���rT���rZ���r[���r���r���r ����hasCompletedCmce����r]���zEpochState.hasCompletedCmcec�����������������C���r^���)Nr*���r���r_���rQ���r���r���r ����setCmceCompleted����ra���zEpochState.setCmceCompletedc�����������������C���s ���|�j�|krdS�ddg}|�j|v�S�)NFr$���rT���rZ���r[���r���r���r ����hasCompletedGefs����r]���zEpochState.hasCompletedGefsc�����������������C���r^���)Nr$���r���r_���rQ���r���r���r ����setGefsCompleted����ra���zEpochState.setGefsCompletedc�����������������C���s���|�j�|krdS�dg}|�j|v�S�)NFrT���rZ���r[���r���r���r ����hasCompletedCombine����s��� zEpochState.hasCompletedCombinec�����������������C���r^���)NrT���r���r_���rQ���r���r���r ����setCombineCompleted����ra���zEpochState.setCombineCompletedc�����������������C���� ���d|�_�d�S�)NrW����r���rQ���r���r���r ����setCmorph2InProgress����rE���zEpochState.setCmorph2InProgressc�����������������C���rl���)NrX���rm���rQ���r���r���r ����setGfsInProgress����rE���zEpochState.setGfsInProgressc�����������������C���rl���)NrY���rm���rQ���r���r���r ����setLirInProgress����rE���zEpochState.setLirInProgressc�����������������C���rl���)Nr*���rm���rQ���r���r���r ����setCmceInProgress����rE���zEpochState.setCmceInProgressc�����������������C���rl���)Nr$���rm���rQ���r���r���r ����setGefsInProgress����rE���zEpochState.setGefsInProgressc�����������������C���rl���)NrT���rm���rQ���r���r���r ����setCombineInProgress���rE���zEpochState.setCombineInProgressc�����������������C���sR���d|�_�d|�_d|�_d|�_d|�_d|�_d|�_d|�_d|�_d|�_ d|�_ d|�_d|�_d�S�rP���) r���r���r���r���r���r���r���r���r���r���r���r���r���r ���r���r���r ����clearPartial��s��� zEpochState.clearPartialFc�������������� ���C���s��t�j�|�\}}t�j�|�s@td|��zt��|��W�n%�ty?�}�z|jtjkr5td|d��W�Y�d�}~dS�W�Y�d�}~nd�}~ww�||�_ t |d�}|�d��|�d��|�jD�] }|�|d���qU|�d ��|�j D�] }|�|d���qg|�d ��|�jD�] }|�|d���qy|�d��|�jD�] }|�|d���q�|�d|�j���|�d |�j���|�d|�j���|�d|�j���|�d|�j���|�d|�j���|�d|�j���|�d|�j���|�d|�j���|�d|�j���|�d|�j���|�d|�j���|�d|�j���|����|�r td|�j ��dS�)Nz5Path for model state file nonexistant, try to create z2ERROR creating path when writing model state file z cannot writeF�wz[proj] zGEFS=z z CMCE=z THRESH_GEFS=z THRESH_CMCE=z CurrentPartial=z InProgress=z LastCompleted=z GFSpartial=z GFSLastDone=z GFSALastGrib2toMdv=z GFSBLastGrib2toMdv=z LIRpartial=z LIRLastDone=z CMCEpartial=z CMCELastDone=z GEFSpartial=z GEFSLastDone=zWrote state to file T)r+���r,���r2���r-���r3����makedirs�OSError�errno�EEXISTr ����open�writer���r���r���r���r���r���r���r���r���r���r���r���r���r���r���r���r����close)r!����filenamer:����head�tail� exception�fpr���r���r���r ���r{�����sX��� ��� zEpochState.writec����������� ������C���s&��g�}|�j�D�]}tj�|d�d�}||kr|�|��q|r!td|��qg�}|�jD�]}tj�|d�d�}||kr<|�|��q'|rCtd|��q'||�_g�}|�jD�]}tj�|d�d�}||kra|�|��qL|rhtd|��qL||�_g�} |�jD�]}tj�|d�d�}||kr�| �|��qq|r�td|��qq| |�_d�S�)N�0000z%Y%m%d%H%M%Sz*Aging off CMCE from Epoch main state file z*Aging off GEFS from Epoch main state file z0Aging off threshCMCE from Epoch main state file z0Aging off threshGEFS from Epoch main state file )r����datetime�strptimer8���r3���r���r���r���) r!���ZtminZ tminThreshr:����cmcerR����t�gefsZ threshCmceZ threshGefsr���r���r ����removeTooOldG��sF��� � � � � zEpochState.removeTooOldN)F)&�__name__� __module__�__qualname__r"���r5���r;���r=���r@���rB���rD���rF���rG���rH���rM���rO���rS���rU���r\���r`���rb���rc���rd���re���rf���rg���rh���ri���rj���rk���rn���ro���rp���rq���rr���rs���rt���r{���r����r���r���r���r ���r������sH����; 1r���)r.���r+���rx���r����r ���r���r���r���r���r ����<module>���s���