read_workflow.c 2.71 KB
Newer Older
1
/*-----------------------------------------------------------------------------------------
2
 * Copyright (C) 2016  For the list of authors, see file AUTHORS.
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
 *
 * 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>.
 -----------------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------
 *  Read extern workflow                          
 *
 *  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"

31
void read_workflow(char file_in[STRING_SIZE],float *** workflow, int *workflow_lines, char header[STRING_SIZE]){
32 33 34 35 36 37
    
    /* workflow is a pointer to a pointer, keep care... */
    
    /* intern variables */
    int i, c;
    int nw=0,x,y;
38
    
39 40 41 42 43 44 45 46 47 48 49 50
    FILE *fwork;
    /* extern variables */
    extern FILE *FP;
    /* WORKFLOW_MAX_VAR is set in fd.h */
    
    fprintf(FP,"\n Reading Workflow from file: %s\n",file_in);
    
    /* Open Workflow file */
    fwork=fopen(file_in,"r");
    if (fwork==NULL) err(" Workflow file could no be opened !");
    
    /* Count how many lines the work flow file has */
51
    fgets(header, 200, fwork); /* Read header */
52 53 54 55
    while(!feof(fwork)) {
        c = fgetc(fwork);
        if(c == '\n'){nw++;}
    }
56 57
    fseek(fwork, SEEK_SET, 0); /* Reset */
    fgets(header, 200, fwork); /* Read header */
58 59 60 61 62 63 64 65
    
    fprintf(FP," Number of lines in workflow file: %i\n",nw);
    
    /* Allocate memory for workflow */
    (*workflow) = matrix(1,nw,1,WORKFLOW_MAX_VAR);
    if ((*workflow)==NULL) err(" Was not able to allocate memory for workflow file !");
    
    /* Read workflow */
66
    fprintf(FP,"\n %s",header);
67 68 69 70 71 72 73 74 75 76 77 78
    fprintf(FP," ");
    for(y=1;y<=nw;y++){
        for(x=1;x<=WORKFLOW_MAX_VAR;x++){
            (*workflow)[y][x]=0;
            fscanf(fwork,"%f",&(*workflow)[y][x]);
            fprintf(FP,"%.3f\t",(*workflow)[y][x]);
        }
    fprintf(FP,"\n ");
    }
    fclose(fwork);
    *workflow_lines=nw;
}