Commit a0d4d519 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

splitmon: added optional parameter to set the format string for the month

parent 593e5f16
......@@ -5,6 +5,7 @@
2013-10-21 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* splitmon: added optional parameter to set the format string for the month [Feature #4131]
* Sort: added support for multi level variables (bug fix) [report: Irina Fast]
2013-10-18 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
......
......@@ -6,6 +6,7 @@ Version 1.6.2 (27 September 2013):
New features:
* select: added support for key >timestep_of_year<
* mastrfu: added missing value support
* splitmon: added optional parameter to set the format string for the month
Fixed bugs:
* selyear: wrong result for negative years [Bug #3836]
......
......@@ -54,9 +54,9 @@ Operator catalog:
Split splittabnum Split parameter table numbers
Splittime splithour Split hours
Splittime splitday Split days
Splittime splitmon Split months
Splittime splitseas Split seasons
Splittime splityear Split years
Splittime splitmon Split months
Splitsel splitsel Split time selection
-------------------------------------------------------------
Selection
......
......@@ -5,7 +5,7 @@
@Section = File operations
@Class = File operation
@Arguments = ifile obase
@Operators = splithour splitday splitmon splitseas splityear
@Operators = splithour splitday splitseas splityear splitmon
@BeginDescription
This module splits @file{ifile} into timesteps pieces. The output files will be named
......@@ -37,6 +37,7 @@ Splits a file into pieces, one for each different day.
@BeginOperator_splitmon
@Title = Split months
@Parameter = [format]
@BeginDescription
Splits a file into pieces, one for each different month.
......@@ -65,6 +66,12 @@ Splits a file into pieces, one for each different year.
@EndOperator
@BeginParameter
@Item = format
STRING C-style format for strftime() (e.g. \%B for the full month name)
@EndParameter
@BeginEnvironment
@Item = CDO_FILE_SUFFIX
This environment variable can be used to set the default file suffix. This suffix will be
......
......@@ -30,9 +30,29 @@
#include "pstream.h"
#include "util.h"
#include <time.h>
#define MAX_STREAMS 32
struct tm datetime_to_tm(int date, int time)
{
int year, month, day, hour, minute, second;
cdiDecodeDate(date, &year, &month, &day);
cdiDecodeTime(time, &hour, &minute, &second);
struct tm stime;
memset(&stime, 0, sizeof(struct tm));
stime.tm_sec = second;
stime.tm_min = minute;
stime.tm_hour = hour;
stime.tm_mday = day;
stime.tm_mon = month-1;
stime.tm_year = year-1900;
return stime;
}
void *Splittime(void *argument)
{
int SPLITHOUR, SPLITDAY, SPLITMON, SPLITSEAS;
......@@ -62,6 +82,7 @@ void *Splittime(void *argument)
field_t **vars = NULL;
int season_start;
const char *seas_name[4];
const char *format = NULL;
cdoInitialize(argument);
......@@ -76,6 +97,11 @@ void *Splittime(void *argument)
if ( UNCHANGED_RECORD ) lcopy = TRUE;
if ( operatorID == SPLITMON )
{
if ( operatorArgc() == 1 ) format = operatorArgv()[0];
}
season_start = get_season_start();
get_season_name(seas_name);
......@@ -188,9 +214,22 @@ void *Splittime(void *argument)
}
else
{
sprintf(filename+nchars, "%02d", index);
char oformat[32];
strcpy(oformat, "%02d");
if ( operatorID == SPLITMON && format )
{
size_t slen;
char sbuf[32];
struct tm stime = datetime_to_tm(vdate, vtime);
slen = strftime(sbuf, 32, format, &stime);
if ( slen ) strcpy(oformat, sbuf);
}
sprintf(filename+nchars, oformat, index);
if ( filesuffix[0] )
sprintf(filename+nchars+2, "%s", filesuffix);
sprintf(filename+nchars+strlen(oformat), "%s", filesuffix);
}
if ( cdoVerbose ) cdoPrint("create file %s", filename);
......
......@@ -329,11 +329,12 @@ static char *SplitHelp[] = {
static char *SplittimeHelp[] = {
"NAME",
" splithour, splitday, splitmon, splitseas, splityear - ",
" splithour, splitday, splitseas, splityear, splitmon - ",
" Split timesteps of a dataset",
"",
"SYNOPSIS",
" <operator> ifile obase",
" splitmon[,format] ifile obase",
"",
"DESCRIPTION",
" This module splits ifile into timesteps pieces. The output files will be named",
......@@ -347,15 +348,18 @@ static char *SplittimeHelp[] = {
" splitday Split days",
" Splits a file into pieces, one for each different day.",
" xxx will have two digits with the day.",
" splitmon Split months",
" Splits a file into pieces, one for each different month.",
" xxx will have two digits with the month.",
" splitseas Split seasons",
" Splits a file into pieces, one for each different season.",
" xxx will have three characters with the season.",
" splityear Split years",
" Splits a file into pieces, one for each different year.",
" xxx will have four digits with the year.",
" splitmon Split months",
" Splits a file into pieces, one for each different month.",
" xxx will have two digits with the month.",
"",
"PARAMETER",
" format STRING C-style format for strftime() (e.g. %B for the full month name)",
"",
"ENVIRONMENT",
" CDO_FILE_SUFFIX",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment