y_season = np.empty((itime, 20, 72, 109))
    y_season[:] = np.nan

    for a, y in enumerate(ltime):

        data_all, seaccum, monaccum, seamean, monmean, \
        lats, lons = post.PostModel(fcst_month, ntrimetres[i], y,
                                    model='RSM97')

        # Faz o acumulado da estação
        r = 31 * len(ntrimetres[i])
        data_all = np.nansum(np.swapaxes(data_all, 1, 2) \
                   .reshape(r, 20, 72, 109), axis=0)

        y_season[a, :] = data_all[:]

    y_season = np.swapaxes(y_season, 0, 1)

    # Usado no hindcast
    # fname = 'pcp-seasonacc-rsm97-hind8110-{0}-8110-{1}.nc' \
    #         .format(fcst_month, tri.upper())
    # writenc4(y_season, lats, lons, fname, itime)

    # Usado no forecast
    fname = 'pcp-seasonacc-rsm97-hind8110-{0}{2}_{2}{1}.nc' \
            .format(fcst_month, tri.upper(), y)
    writenc4(y_season, lats, lons, fname, itime)

    # raw_input()

# -*- coding: utf-8 -*-

__author__ = "Marcelo Rodrigues"
__license__ = "GPL"
__version__ = "1.0"
__email__ = "*****@*****.**"
__date__ = "01/02/2016"

from nc4rsm97 import writenc4
from PyFuncemeClimateTools import PostPlevMonRSM97 as post
import numpy as np

namevar = "h"

t_mon = range(1, 9)

for y in range(1981, 2016):

    lat, lon, mydata = post.PostModel(fcst_month="jan", target_months=t_mon, fcst_years=y, nvar=namevar)

    mydata = np.swapaxes(mydata, 0, 1)

    print mydata.shape

    filename='{0}-1000hpa-mon-rsm97-hind8110-jan-{1}.nc'.format(namevar, y)

    writenc4(mydata[:, :, 0, :, :], lat, lon, filename, len(t_mon), namevar)


from PyFuncemeClimateTools import PostModels as post
from nc4rsm97 import writenc4

fcst_month = 'jan'               # MES DA PREVISAO
nyear      = range(1981, 2017)   # QTD DE ANOS
ntrimetres = range(1, 9)
itime      = 31 * len(ntrimetres)

for year in nyear:

    data_all, seaccum, monaccum, seamean, monmean, \
    lats, lons = post.PostModel(fcst_month, ntrimetres, year,
                                model='RSM97')

    # Faz o acumulado da estação
    data_all = np.swapaxes(data_all, 1, 2).reshape(itime, 20, 72, 109)

    # Remove valores nan
    daily = data_all[~np.isnan(data_all[:, 0, 0, 0]), :, :, :]

    daily = np.swapaxes(daily, 0, 1)

    print daily.shape

    # Usado no forecast
    fname = 'pcp.daily.rsm97.hind8110.{0}{1}.{1}01-{1}08.nc' \
        .format(fcst_month, year)

    writenc4(daily, lats, lons, fname, daily.shape[1], year)