Skip to content

Commit cf38808

Browse files
committed
Next tirific
1 parent 9b14962 commit cf38808

File tree

1 file changed

+79
-33
lines changed

1 file changed

+79
-33
lines changed

src/tirific.c

+79-33
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ This was commented hdu stuff
433433
/*
434434
tirific.dc1
435435

436-
Program: TIRIFIC (Version 2.3.7)
436+
Program: TIRIFIC (Version 2.3.8)
437437

438438
Purpose: Fit a tilted-ring model to a datacube
439439

@@ -1049,6 +1049,9 @@ typedef struct startinf
10491049
/** @brief Indicator if this is the first run or a consecutive one */
10501050
int firstrun;
10511051

1052+
/** @brief Indicator of the restartid */
1053+
int restartid;
1054+
10521055
/** @brief time stamp for file */
10531056
time_t timestamp;
10541057

@@ -6338,7 +6341,7 @@ int main(int argc, char *argv[])
63386341

63396342
printf("\n");
63406343
printf("####################\n");
6341-
printf("# TIRIFIC v. 2.3.7 #\n");
6344+
printf("# TiRiFiC v. 2.3.8 #\n");
63426345
printf("####################\n");
63436346
printf("\n");
63446347

@@ -6843,8 +6846,8 @@ static startinf *create_startinf(void)
68436846
/* First set all pointers to 0 and initialise some pointers */
68446847
startinfv -> arel = NULL;
68456848
startinfv -> restartname = NULL;
6849+
startinfv -> restartid = 0;
68466850
startinfv -> firstrun = 1;
6847-
startinfv -> restartname = NULL;
68486851
/* if (!(startinfv -> restartname = getfcharray(200, NULL))) */
68496852
/* goto error; */
68506853
if (!((startinfv -> filestat) = (struct stat *) malloc(sizeof(struct stat)))) {
@@ -6904,7 +6907,9 @@ static startinf *get_startinf(int argc, char **argv)
69046907
char *buffer = NULL;
69056908
int nread, nreturned;
69066909
char *returnedc;
6907-
int *prompt;
6910+
int *prompt, *restartid;
6911+
int restartdef = 0;
6912+
int defrestartdef = 0;
69086913
int promptdef = 0;
69096914
int keypres;
69106915
char **varystr = NULL;
@@ -6948,10 +6953,19 @@ static startinf *get_startinf(int argc, char **argv)
69486953
if (!(startinfv -> arel = simparse_scn_arel_insert(NULL, "Command line", buffer, NULL)))
69496954
goto error;
69506955

6956+
/* An input of restartid != 0 on the command line is an error */
6957+
if (simparse_scn_arel_readval_int(startinfv -> arel, "RESTARTID", "ID of restart process [0]", 1, &restartdef, 1, 1, 0, 0, &keypres, &nread, &nreturned, &restartid))
6958+
goto error;
6959+
6960+
if (*restartid) {
6961+
fprintf(stderr, "Error: cannot define RESTARTID=%i, other than RESTARTID=0 on command line.\n(Would lead to an endless loop.)\n", *restartid);
6962+
goto error;
6963+
}
6964+
69516965
/* Read out the file name */
69526966
if (simparse_scn_arel_readval_string(startinfv -> arel, "DEFFILE", "Provide default file name (default: no file).", 0, NULL, 0, -1, 0, 0, &keypres, &nread, &nreturned, &returnedc))
69536967
goto error;
6954-
6968+
69556969
if ((returnedc[0]))
69566970
printf("Using default file with name: %s\n", returnedc);
69576971

@@ -7002,7 +7016,10 @@ static startinf *get_startinf(int argc, char **argv)
70027016
freeparsed(varystr);
70037017
varystr = NULL;
70047018

7005-
7019+
if (simparse_scn_arel_readval_int(startinfv -> arel, "RESTARTID", "ID of restart process [0]", 1, &restartdef, 1, 1, 0, 0, &keypres, &nread, &nreturned, &restartid))
7020+
goto error;
7021+
startinfv -> restartid = *restartid;
7022+
70067023
/* The startfile */
70077024
/* sprintf(mes, "Give restartfile name."); */
70087025
/* for (i = 0; i < 200; ++i) */
@@ -7016,13 +7033,14 @@ static startinf *get_startinf(int argc, char **argv)
70167033

70177034
free(buffer);
70187035

7019-
return startinfv;
7036+
return startinfv;
70207037

70217038
error:
70227039
if ((startinfv)) {
70237040
/* Stop the logfile io, also put ndisks = 1, is irrelevant */
70247041
destroy_startinf(startinfv);
70257042
}
7043+
70267044
if ((buffer))
70277045
free(buffer);
70287046
if ((startinfv -> arel))
@@ -7093,9 +7111,11 @@ static int loop_restart(startinf *startinfv)
70937111
/* char mes[81]; */
70947112
/* int def, nel, i; */
70957113
char **varystr = NULL;
7114+
int *restartid;
7115+
int restartdef = 0;
70967116
int keypres, nread, nreturned;
70977117
simparse_scn_keyvalli **keyvallifile;
7098-
7118+
70997119
/* If the function is called, this should be done */
71007120
startinfv -> firstrun = 0;
71017121

@@ -7104,38 +7124,57 @@ static int loop_restart(startinf *startinfv)
71047124

71057125
/* Check if file information can be acquired and fill stuff */
71067126
if (stat(startinfv -> restartname, startinfv -> filestat)) {
7127+
7128+
/* Notice that tirific will not wait until the restartfile is created */
71077129
return 0;
71087130
}
71097131
else {
7110-
fflush(NULL);
7111-
printf("Waiting for file %s to change.\n", startinfv -> restartname);
7112-
7132+
fflush(NULL);
7133+
printf("Waiting for file %s to change", startinfv -> restartname);
7134+
if (startinfv -> restartid) {
7135+
if ((keyvallifile = simparse_scn_keyvallilist_gfrfi(startinfv -> arel[2] -> orifilename))) {
7136+
printf(" and RESTARTID= %i to change in %s.\n", startinfv -> restartid, startinfv -> arel[2] -> orifilename);
7137+
}
7138+
}
7139+
else {
7140+
printf(".\n");
7141+
}
71137142

71147143
/* Run a loop until the timestamps are the same or the file becomes unreadable */
71157144
while (startinfv -> timestamp >= startinfv -> filestat -> st_mtime) {
71167145
if (stat(startinfv -> restartname, startinfv -> filestat)) {
71177146
break;
71187147
}
71197148
}
7149+
printf("File %s has changed.", startinfv -> restartname);
71207150

71217151
/* Now refresh the input name and read it in again (not sure if this works or if the .def file has to be reread into some buffer before */
71227152
/* Changed this here */
71237153
cancel_tir(startinfv -> arel, "RESTARTNAME=", 1);
7154+
7155+
/* Just make sure that the file is re-read */
71247156

7125-
/* Just make sure that the file is re-read */
7126-
if (startinfv -> arel && startinfv -> arel[1] && startinfv -> arel[2]) {
7127-
if ((keyvallifile = simparse_scn_keyvallilist_gfrfi(startinfv -> arel[2] -> orifilename))) {
7128-
simparse_scn_keyvallilist_dest(startinfv -> arel[2] -> keyvallifile);
7129-
startinfv -> arel[2] -> keyvallifile = keyvallifile;
7130-
}
7131-
else {
7132-
simparse_scn_arel_timestamp_early(startinfv -> arel[2]);
7133-
}
7134-
}
7135-
7157+
/* This may add an extra layer of security of sync */
7158+
do {
7159+
if (startinfv -> arel && startinfv -> arel[1] && startinfv -> arel[2]) {
7160+
if ((keyvallifile = simparse_scn_keyvallilist_gfrfi(startinfv -> arel[2] -> orifilename))) {
7161+
simparse_scn_keyvallilist_dest(startinfv -> arel[2] -> keyvallifile);
7162+
startinfv -> arel[2] -> keyvallifile = keyvallifile;
7163+
}
7164+
else {
7165+
simparse_scn_arel_timestamp_early(startinfv -> arel[2]);
7166+
}
7167+
}
7168+
if (simparse_scn_arel_readval_int(startinfv -> arel, "RESTARTID=", "ID of restart process [0]", 1, &startinfv -> restartid, 1, 1, 0, 0, &keypres, &nread, &nreturned, &restartid))
7169+
/* if (simparse_scn_arel_readval_int(startinfv -> arel, "RESTARTID=", "ID of restart process [0]", 1, &restartdef, 1, 1, 0, 0, &keypres, &nread, &nreturned, &restartid))*/
7170+
goto error;
7171+
} while ((*restartid == startinfv -> restartid) && (startinfv -> restartid != 0));
7172+
7173+
startinfv -> restartid = *restartid;
7174+
71367175
if ((startinfv -> restartname)) {
7137-
free(startinfv -> restartname);
7138-
startinfv -> restartname = NULL;
7176+
free(startinfv -> restartname);
7177+
startinfv -> restartname = NULL;
71397178
}
71407179

71417180
/* sprintf(mes, "Give restartfile name."); */
@@ -7437,11 +7476,11 @@ static loginf *get_loginf(startinf *startinfv, loginf *loginfv)
74377476

74387477
if (!startinfv -> firstrun)
74397478
return loginfv;
7440-
7479+
74417480
/* Try to allocate */
74427481
if (!(log = create_loginf()))
74437482
goto error;
7444-
7483+
74457484
#ifdef OPENMPTIR
74467485
/* The very first thing to do is to ask for the number of cores */
74477486
log -> ncores = 1;
@@ -7460,7 +7499,7 @@ static loginf *get_loginf(startinf *startinfv, loginf *loginfv)
74607499
#else
74617500
log -> ncores = 1;
74627501
#endif
7463-
7502+
74647503
/* First thing to do is the logfile and the text logfile */
74657504

74667505
/* The logfile */
@@ -7479,7 +7518,7 @@ static loginf *get_loginf(startinf *startinfv, loginf *loginfv)
74797518

74807519
/* This puts an \0 to the end of the text */
74817520
/* termsinglestr(log -> logname); */
7482-
7521+
74837522
/* The text logfile */
74847523
if (simparse_scn_arel_readval_string(startinfv -> arel, "TEXTLOG", "Provide text logfile name (default: no file).", 0, "", 0, -1, 0, 0, &keypres, &nread, &nreturned, &(log -> textlog)))
74857524
goto error;
@@ -7513,11 +7552,10 @@ static loginf *get_loginf(startinf *startinfv, loginf *loginfv)
75137552
/* termsinglestr(log -> progresslog); */
75147553
/* Kamphuis addition end */
75157554

7516-
75177555
/* The result name */
75187556
if (simparse_scn_arel_readval_string(startinfv -> arel, "TABLE", "Give output table name (default: no file).", 0, "", 0, -1, 0, 0, &keypres, &nread, &nreturned, &(log -> table)))
75197557
goto error;
7520-
7558+
75217559
/* for (i = 0; i < 200; ++i) */
75227560
/* log -> table[i] = ' '; */
75237561
/* log -> table[200] = '\0'; */
@@ -7537,7 +7575,6 @@ static loginf *get_loginf(startinf *startinfv, loginf *loginfv)
75377575
log -> distance = 10;
75387576
def = 2;
75397577

7540-
75417578
sprintf(mes,"Distance in Mpc [10]");
75427579
nel = 1;
75437580
userdble_tir(startinfv -> arel, &log -> distance, &nel, &def, "DISTANCE=", mes);
@@ -7549,7 +7586,7 @@ static loginf *get_loginf(startinf *startinfv, loginf *loginfv)
75497586
}
75507587

75517588
return log;
7552-
7589+
75537590
error:
75547591
if ((log)) {
75557592
/* Stop the logfile io, also put ndisks = 1, is irrelevant */
@@ -15597,6 +15634,13 @@ static int putgenresults(startinf *startinfv, loginf *log, hdrinf *hdr, ringparm
1559715634
anyout_tir(&dev, mes);
1559815635

1559915636
/* New Kamphuis */
15637+
if (startinfv -> restartid) {
15638+
length = strlen(mes);
15639+
sprintf(mes+length,
15640+
" R:%i ", /* current restart-id */
15641+
startinfv -> restartid /* size */
15642+
);
15643+
}
1560015644
progressout(startinfv, mes);
1560115645

1560215646
/* error source ? */
@@ -17671,7 +17715,9 @@ static int progressout(startinf *startinfv, char *message)
1767117715
fprintf(stream,"%s",message);
1767217716
fprintf(stream, "\n");
1767317717
/* and close again otherwise the file stays unreadable */
17674-
fclose(stream);
17718+
fflush(stream);
17719+
fclose(stream);
17720+
fflush(NULL);
1767517721
}
1767617722

1767717723
if ((progname))

0 commit comments

Comments
 (0)