@@ -51,7 +51,6 @@ PetscErrorCode
5151SOPFLOWReadScenarioData_LoadPQ_SinglePeriod (SOPFLOW sopflow,
5252 const char windgenprofile[]) {
5353
54- // printf("I am being called\n");
5554 PetscErrorCode ierr;
5655 FILE *fp;
5756 char line[MAXLINE ];
@@ -96,15 +95,6 @@ SOPFLOWReadScenarioData_LoadPQ_SinglePeriod(SOPFLOW sopflow,
9695 scen_num -= 1 ; /* Scenario numbers start with 1 in the file, convert to
9796 zero-based start */
9897
99- // printf("Parsing scenario number %d\n", scen_num);
100-
101- // tok2 = strsep(&tok, sep2_dash); // Bus Number
102-
103- // sscanf(tok2, "%d", &bus[nw]);
104- // tok3 = strsep(&tok, sep2_dash); // Wind
105- // tok4 = strsep(&tok, sep2_dash); // Gen ID
106- // tok5 = strsep(&tok, sep2_dash); // Value
107-
10898 if (scen_num < scenlist->Nscen || scen_num == sopflow->Ns ) {
10999 fclose (fp);
110100 PetscFunctionReturn (0 );
@@ -122,43 +112,28 @@ SOPFLOWReadScenarioData_LoadPQ_SinglePeriod(SOPFLOW sopflow,
122112 tok = strtok (NULL , sep_comma);
123113 sscanf (tok, " %lf" , &weight);
124114
125- // printf("Scenario weight = %lf\n", weight);
126-
127115 tok = strtok (NULL , sep_comma);
128116 while (tok != NULL ) {
129117
130- // printf("## tok = %s\n", tok);
131-
132118 GenData gd;
133119
134120 /* Parse generator info */
135121 tok2 = strsep (&tok, sep2_dash); // Bus Number
136122 sscanf (tok2, " %d" , &gd.busnum );
137- // printf("Bus number = %d\n", gd.busnum);
138123 tok3 = strsep (&tok, sep2_dash); // Type (Load or Gen)
139124 tok4 = strsep (&tok, sep2_dash); // CKT
140125 sscanf (tok4, " %d" , &genid);
141126 snprintf (gd.id , 3 , " %-2d" , genid);
142- // printf("Gen ID = %s\n", gd.id);
143127 tok5 = strsep (&tok, sep2_dash); // Value1
144128 sscanf (tok5, " %lf" , &gd.value1 );
145- // printf("Value1 = %lf\n", gd.value1);
146129 tok6 = strsep (&tok, sep2_dash); // Value2
147130 sscanf (tok6, " %lf" , &gd.value2 );
148- // printf("Value2 = %lf\n", gd.value2);
149131
150132 gendata.push_back (gd);
151133
152- // printf("## gd = %d, %s, %lf, %lf\n", gd.busnum, gd.id, gd.value1,
153- // gd.value2);
154-
155- // printf("!Token = %s\n", gendata.back());
156134 tok = strtok (NULL , sep_comma);
157-
158- // printf("## tok = %s\n", tok);
159135 }
160136
161- // printf("Done Parsing 1 line of Tokens\n");
162137 scenario = &scenlist->scen [scen_num];
163138 forecast = &scenario->forecastlist [scenario->nforecast ];
164139 forecast->num = scen_num;
@@ -177,135 +152,15 @@ SOPFLOWReadScenarioData_LoadPQ_SinglePeriod(SOPFLOW sopflow,
177152 ierr = PetscCalloc1 (forecast->nele , &forecast->val2 );
178153 CHKERRQ (ierr);
179154
180-
181- // tok = strtok(NULL, sep_comma);
182-
183155 for (i = 0 ; i < gendata.size (); i++) {
184156 forecast->buses [i] = gendata[i].busnum ;
185157 ierr = PetscStrcpy (forecast->id [i], gendata[i].id );
186158 CHKERRQ (ierr);
187- // sscanf(tok, "%lf", &pg);
188159 forecast->val1 [i] = gendata[i].value1 ;
189160 forecast->val2 [i] = gendata[i].value2 ;
190- // tok = strtok(NULL, sep_comma);
191161 }
192162
193163 // /* Read scenario weight */
194- // sscanf(tok, "%lf", &weight);
195- scenario->prob = weight;
196-
197- scenario->nforecast ++;
198- scenlist->Nscen ++;
199- }
200- PetscFunctionReturn (0 );
201- }
202-
203- /*
204- SOPFLOWReadScenarioData_Wind_SinglePeriod - Reads the wind data and populates
205- the scenario list Input Parameters
206- + sopflow - SOPFLOW object
207- . windgenprofile - wind generator profile file
208-
209- Note: This function reads the wind scenario data for "single period" format
210- files.
211- */
212- PetscErrorCode
213- SOPFLOWReadScenarioData_Wind_SinglePeriod_2 (SOPFLOW sopflow,
214- const char windgenprofile[]) {
215- PetscErrorCode ierr;
216- FILE *fp;
217- char line[MAXLINE ];
218- char *out;
219- PetscInt ngenwind, nw = 0 ;
220- char *tok, *tok2;
221- char sep[] = " ," , sep2[] = " _" ;
222- PetscReal pg, weight;
223- int scen_num = 0 ;
224- int genid;
225- int windgenbus[1000 ];
226- char windgenid[1000 ][3 ];
227- int i;
228- ScenarioList *scenlist = &sopflow->scenlist ;
229- Scenario *scenario;
230- Forecast *forecast;
231-
232- PetscFunctionBegin;
233-
234- ngenwind = 1000 ; // This should be increased for larger cases (?)
235- fp = fopen (windgenprofile, " r" );
236- if (fp == NULL ) {
237- SETERRQ (PETSC_COMM_SELF , PETSC_ERR_FILE_OPEN ,
238- " Cannot open wind generation profile file %s" , windgenprofile);
239- }
240-
241- /* First line -- has the bus numbers */
242- out = fgets (line, MAXLINE , fp);
243- /* Parse wind generator numbers */
244- tok = strtok (line, sep);
245- tok = strtok (NULL , sep); /* Skip first token */
246- while (tok != NULL ) {
247- if (strcmp (tok, " weight" ) == 0 || strcmp (tok, " weight\n " ) == 0 ||
248- strcmp (tok, " weight\r\n " ) == 0 ) {
249- tok = strtok (NULL , sep);
250- continue ;
251- }
252- /* Parse generator info */
253- tok2 = strsep (&tok, sep2);
254- sscanf (tok2, " %d" , &windgenbus[nw]);
255- tok2 = strsep (&tok, sep2);
256- tok2 = strsep (&tok, sep2); /* Skip string "Wind" */
257- sscanf (tok2, " %d" , &genid);
258- if (nw == ngenwind)
259- SETERRQ (PETSC_COMM_SELF , PETSC_ERR_SUP ,
260- " Exceeded max. number of wind generators=%d\n " , ngenwind);
261- snprintf (windgenid[nw], 3 , " %-2d" , genid);
262-
263- nw++;
264- tok = strtok (NULL , sep);
265- }
266-
267- while ((out = fgets (line, MAXLINE , fp)) != NULL ) {
268- if (strcmp (line, " \r\n " ) == 0 || strcmp (line, " \n " ) == 0 ) {
269- continue ; /* Skip blank lines */
270- }
271-
272- tok = strtok (line, sep);
273- sscanf (tok, " %d" , &scen_num); /* Scenario number */
274- scen_num -= 1 ; /* Scenario numbers start with 1 in the file, convert to
275- zero-based start */
276-
277- if (scen_num < scenlist->Nscen || scen_num == sopflow->Ns ) {
278- fclose (fp);
279- PetscFunctionReturn (0 );
280- }
281-
282- scenario = &scenlist->scen [scen_num];
283- forecast = &scenario->forecastlist [scenario->nforecast ];
284- forecast->num = scen_num;
285- forecast->type = FORECAST_WIND ;
286- forecast->nele = nw;
287- ierr = PetscCalloc1 (forecast->nele , &forecast->buses );
288- CHKERRQ (ierr);
289- ierr = PetscCalloc1 (forecast->nele , &forecast->id );
290- CHKERRQ (ierr);
291- for (i = 0 ; i < forecast->nele ; i++) {
292- ierr = PetscCalloc1 (3 , &forecast->id [i]);
293- }
294- ierr = PetscCalloc1 (forecast->nele , &forecast->val1 );
295- CHKERRQ (ierr);
296-
297- tok = strtok (NULL , sep);
298- for (i = 0 ; i < nw; i++) {
299- forecast->buses [i] = windgenbus[i];
300- ierr = PetscStrcpy (forecast->id [i], windgenid[i]);
301- CHKERRQ (ierr);
302- sscanf (tok, " %lf" , &pg);
303- forecast->val1 [i] = pg;
304- tok = strtok (NULL , sep);
305- }
306-
307- /* Read scenario weight */
308- sscanf (tok, " %lf" , &weight);
309164 scenario->prob = weight;
310165
311166 scenario->nforecast ++;
0 commit comments