11#include "write.h"
22
33
4- void true_date (int relative_doy , int season , bands_t * bands , char formatted [], size_t size ){
5- int true_year , true_month , true_doy , true_day ;
4+ date_t true_date (int relative_doy , int season , bands_t * bands , char formatted [], size_t size ){
5+ date_t date ;
66int b ;
77
88
99 for (b = 0 ; b < bands -> n ; b ++ ){
10- if (bands -> seasons [b ] == season ){
11- true_year = bands -> years [b ];
12- break ;
10+ if (season >= 0 ){
11+ if (bands -> seasons [b ] == season ){
12+ date .year = bands -> years [b ];
13+ break ;
14+ }
15+ } else {
16+ if (bands -> seasons [b ] == season + 1 ){
17+ date .year = bands -> years [b ]- 1 ;
18+ break ;
19+ }
1320 }
1421 }
1522
16- true_doy = relative_doy + bands -> min_doy - 1 ;
17- if (true_doy >= 366 ){
18- true_doy -= 366 ;
19- true_year ++ ;
23+ date . doy = relative_doy + bands -> min_doy - 1 ;
24+ if (date . doy >= 366 ){
25+ date . doy -= 366 ;
26+ date . year ++ ;
2027 }
2128
22- true_month = doy2m (true_doy );
23- true_day = doy2d (true_doy );
24- compact_date (true_year , true_month , true_day , formatted , size );
29+ date . month = doy2m (date . doy );
30+ date . day = doy2d (date . doy );
31+ compact_date (date . year , date . month , date . day , formatted , size );
2532
26- return ;
33+ return date ;
2734}
2835
2936
@@ -49,6 +56,7 @@ OGRFeatureH feature;
4956OGRGeometryH point ;
5057double map_x , map_y , lon , lat ;
5158int id ;
59+ date_t date ;
5260char datestring [1024 ];
5361
5462
@@ -71,6 +79,10 @@ char datestring[1024];
7179 ogr_create_field ("season" , OFTInteger , 12 , & layer );
7280 ogr_create_field ("doy_relative" , OFTInteger , 12 , & layer );
7381 ogr_create_field ("date" , OFTString , 12 , & layer );
82+ ogr_create_field ("year" , OFTString , 12 , & layer );
83+ ogr_create_field ("month" , OFTString , 12 , & layer );
84+ ogr_create_field ("day" , OFTString , 12 , & layer );
85+ ogr_create_field ("doy" , OFTString , 12 , & layer );
7486 ogr_create_field ("area" , OFTInteger , 12 , & layer );
7587 ogr_create_field ("lifetime" , OFTInteger , 12 , & layer );
7688 ogr_create_field ("main_direction" , OFTString , 12 , & layer );
@@ -79,7 +91,7 @@ char datestring[1024];
7991
8092 if (FIRE_HIST [id ] == 0 ) continue ;
8193
82- true_date (OBJ_STARTTIME [id ], season , bands , datestring , 1024 );
94+ date = true_date (OBJ_STARTTIME [id ], season , bands , datestring , 1024 );
8395
8496 // create feature
8597 feature = OGR_F_Create (OGR_L_GetLayerDefn (layer ));
@@ -88,13 +100,17 @@ char datestring[1024];
88100 OGR_F_SetFieldInteger (feature , OGR_F_GetFieldIndex (feature , "ID" ), OBJ_ID [id ]);
89101 OGR_F_SetFieldInteger (feature , OGR_F_GetFieldIndex (feature , "season" ), season );
90102 OGR_F_SetFieldInteger (feature , OGR_F_GetFieldIndex (feature , "doy_relative" ), OBJ_STARTTIME [id ]);
91- OGR_F_SetFieldString (feature , OGR_F_GetFieldIndex (feature , "date" ), datestring );
103+ OGR_F_SetFieldString (feature , OGR_F_GetFieldIndex (feature , "date" ), datestring );
104+ OGR_F_SetFieldInteger (feature , OGR_F_GetFieldIndex (feature , "year" ), date .year );
105+ OGR_F_SetFieldInteger (feature , OGR_F_GetFieldIndex (feature , "month" ), date .month );
106+ OGR_F_SetFieldInteger (feature , OGR_F_GetFieldIndex (feature , "day" ), date .day );
107+ OGR_F_SetFieldInteger (feature , OGR_F_GetFieldIndex (feature , "doy" ), date .doy );
92108 OGR_F_SetFieldInteger (feature , OGR_F_GetFieldIndex (feature , "area" ), FIRE_HIST [id ]);
93109 OGR_F_SetFieldInteger (feature , OGR_F_GetFieldIndex (feature , "lifetime" ), OBJ_LIFETIME [id ]);
94- OGR_F_SetFieldString (feature , OGR_F_GetFieldIndex (feature , "main_direction" ), "TBD" );
110+ OGR_F_SetFieldString (feature , OGR_F_GetFieldIndex (feature , "main_direction" ), "TBD" );
95111
96112 map_x = geotran [0 ] + OBJ_SEED [0 ][id ]* geotran [1 ];
97- map_y = geotran [3 ] - OBJ_SEED [1 ][id ]* geotran [5 ];
113+ map_y = geotran [3 ] + OBJ_SEED [1 ][id ]* geotran [5 ];
98114
99115 //printf("map x/y: %f/%f\n", map_x, map_y);
100116 //printf("map proj: %s\n", proj);
@@ -128,6 +144,7 @@ OGRSpatialReferenceH srs;
128144FILE * fp = NULL ;
129145double map_x , map_y , lon , lat ;
130146int id ;
147+ date_t date ;
131148char datestring [1024 ];
132149
133150
@@ -136,13 +153,13 @@ char datestring[1024];
136153 srs = OSRNewSpatialReference (NULL );
137154 OSRImportFromEPSG (srs , 4326 );
138155
139- fprintf (fp , "ID,season,doy_relative,date,area,lifetime,main_direction,longitude,latitude\n" );
156+ fprintf (fp , "ID,season,doy_relative,date,year,month,day,doy, area,lifetime,main_direction,longitude,latitude\n" );
140157
141158 for (id = 0 ; id < nfire ; id ++ ){
142159
143160 if (FIRE_HIST [id ] == 0 ) continue ;
144161
145- true_date (OBJ_STARTTIME [id ], season , bands , datestring , 1024 );
162+ date = true_date (OBJ_STARTTIME [id ], season , bands , datestring , 1024 );
146163
147164 map_x = geotran [0 ] + OBJ_SEED [0 ][id ]* geotran [1 ];
148165 map_y = geotran [3 ] - OBJ_SEED [1 ][id ]* geotran [5 ];
@@ -153,11 +170,15 @@ char datestring[1024];
153170
154171 warp_any_to_geo (map_x , map_y , & lon , & lat , proj );
155172
156- fprintf (fp , "%d,%d,%d,%s,%d,%d,%s,%f,%f\n" ,
173+ fprintf (fp , "%d,%d,%d,%s,%d,%d,%d,%d,%d,%d,% s,%f,%f\n" ,
157174 OBJ_ID [id ],
158175 season ,
159176 OBJ_STARTTIME [id ],
160177 datestring ,
178+ date .year ,
179+ date .month ,
180+ date .day ,
181+ date .doy ,
161182 FIRE_HIST [id ],
162183 OBJ_LIFETIME [id ],
163184 "TBD" ,
@@ -175,14 +196,15 @@ char datestring[1024];
175196int extended_write (char * fname , double * geotran , char * proj , int season , bands_t * bands , int nfire , int * OBJ_ID , int * FIRE_HIST , int * * * OBJ_GAIN ){
176197FILE * fp = NULL ;
177198int id , t , d ;
199+ date_t date ;
178200char datestring [1024 ];
179201char directions [9 ][16 ] = { "IGN" , "N" , "NE" , "E" , "SE" , "S" , "SW" , "W" , "NW" };
180202bool ignited ;
181203
182204
183205 fp = fopen (fname , "w" );
184206
185- fprintf (fp , "ID,spread_date,spread_size,spread_direction\n" );
207+ fprintf (fp , "ID,spread_date,spread_year,spread_month,spread_day,spread_doy, spread_size,spread_direction\n" );
186208
187209
188210 for (id = 0 ; id < nfire ; id ++ ){
@@ -193,12 +215,16 @@ bool ignited;
193215
194216 for (t = 0 ; t < 365 ; t ++ ){
195217
196- true_date (t + 1 , season , bands , datestring , 1024 );
218+ date = true_date (t + 1 , season , bands , datestring , 1024 );
197219
198220 if (!ignited && OBJ_GAIN [t ][0 ][id ] > 0 ){
199- fprintf (fp , "%d,%s,%d,%s\n" ,
221+ fprintf (fp , "%d,%s,%d,%d,%d,%d,%d,% s\n" ,
200222 OBJ_ID [id ],
201223 datestring ,
224+ date .year ,
225+ date .month ,
226+ date .day ,
227+ date .doy ,
202228 OBJ_GAIN [t ][0 ][id ],
203229 directions [0 ]
204230 );
@@ -210,9 +236,13 @@ bool ignited;
210236
211237 if (OBJ_GAIN [t ][d ][id ] == 0 ) continue ;
212238
213- fprintf (fp , "%d,%s,%d,%s\n" ,
239+ fprintf (fp , "%d,%s,%d,%d,%d,%d,%d,% s\n" ,
214240 OBJ_ID [id ],
215241 datestring ,
242+ date .year ,
243+ date .month ,
244+ date .day ,
245+ date .doy ,
216246 OBJ_GAIN [t ][d ][id ],
217247 directions [d ]
218248 );
0 commit comments