write_workflow.c 2.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
/*-----------------------------------------------------------------------------------------
 * Copyright (C) 2015  For the list of authors, see file AUTHORS.
 *
 * This file is part of DENISE.
 *
 * DENISE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2.0 of the License only.
 *
 * DENISE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with DENISE. See file COPYING and/or <http://www.gnu.org/licenses/gpl-2.0.html>.
 -----------------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------
 *  Write workflow after each iteration
 *
 *  Written by Wittkamp Oct 2015
 *
 *  If you want to adjust the workflow, I think it is not necessary to
 *  modify this file. Have a look at apply_workflow.c and adjust
 *  WORKFLOW_MAX_VAR in fd.h.
 *  ----------------------------------------------------------------------*/

#include "fd.h"

void write_workflow(float ** workflow, int iter, int workflow_lines){
    
    /* local variables */
    int i, c;
    int nw=0,x,y;
    int workflow_lines_remain;
    int  workflow_line_next;
    FILE *fwork;
    char workflow_out[STRING_SIZE];
    
    /* extern variables */
    extern char FILE_WORKFLOW[STRING_SIZE];
    extern FILE *FP;
    extern int VERBOSE;
    /* WORKFLOW_MAX_VAR is set in fd.h */
    
    sprintf(workflow_out,"%s.restart",FILE_WORKFLOW);
    
    if(VERBOSE) fprintf(FP,"\n Writing workflow to file %s\n",workflow_out);
    
    /* Open Workflow file */
    fwork=fopen(workflow_out,"w+");
    if (fwork==NULL) err(" Workflow output file could no be opened !");
    
    workflow_line_next=1;
    for(y=1;y<workflow_lines;y++){
        if(iter>workflow[y][1]){
            workflow_line_next=y;
        }
    }
    
    fprintf(fwork,"%i\n",iter);
    /* write workflow */
    for(y=workflow_line_next;y<=workflow_lines;y++){
        for(x=1;x<=WORKFLOW_MAX_VAR;x++){
            if(x>1)fprintf(fwork,"\t");
            fprintf(fwork,"%f",workflow[y][x]);
        }
        fprintf(fwork,"\n");
    }
    fclose(fwork);
}