Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/fem/examples/iso_d2s/init.c
ViewVC logotype

View of /branches/fem/examples/iso_d2s/init.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3234 - (download) (as text) (annotate)
Fri Aug 14 13:35:44 2015 UTC (4 years ago) by cchiw
File size: 2431 byte(s)
updated examples
/*! \file init.c
 *
 * \author Charisee
 */

/*
 * COPYRIGHT (c) 2015 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 */

#include "iso_d2s.h"
#include <unistd.h>
#include "teem/air.h"



void Nrrd2(Nrrd *nData, float  stepSize)
{
    fprintf(stderr,"\n ******** Saving Results *********\n\n");
    FILE *fp;
    fp=fopen("a.txt","w");
    
    float *p = (float *)(nData->data);
    unsigned int iPoints = nData->axis[0].size;
    unsigned int jPoints = nData->axis[1].size;

    for (uint32_t i = 0;  i < iPoints;  i++) {
        for (uint32_t j = 0;  j < jPoints;  j++) {
       
                float pp1=p[i*iPoints+j];
                float pp2=p[i*iPoints+j+1];
                fprintf(fp,"\n F[%f][%f]=%f %f ",(i*stepSize),(j*stepSize),pp1,pp2);
            
        }
    }
    fprintf(stderr,"\n  %d-x-%d *****************\n",iPoints,jPoints);
    
}



void WriteOutput (Nrrd *nData)
{
    char *Outfile = "x.nrrd";
    if(nrrdSave(Outfile, nData, NULL)) {
        exit(1);
    }
    nrrdNuke(nData);
}

//struct Function;
void callDiderot2_iso(void *valM, int imgResU,int imgResV, int stepsMax,float isoval){
   // fprintf(stderr, "\n inside getiso\n");
    double t0 = airTime();
    iso_d2s_World_t *wrld = iso_d2s_New ();
    
    if (wrld == 0) {
	//fprintf (stderr, "Unable to create Diderot world\n");
	exit (1);
    }
    
    iso_d2s_Init (wrld);//initialize it.
    //initialize input vars
    iso_d2s_InVarSet_m (wrld, valM);
    iso_d2s_InVarSet_imgResU(wrld,imgResU);
    iso_d2s_InVarSet_imgResV(wrld,imgResV);
    iso_d2s_InVarSet_stepsMax(wrld,stepsMax);
    iso_d2s_InVarSet_isoval(wrld,isoval);
    
    // nrrd for getting computational state
    Nrrd *nData = nrrdNew();
    
    if (iso_d2s_Initially (wrld)) {//intialize set of strands
        // error
	fprintf(stderr, "Error initializing world: %s", iso_d2s_GetErrors(wrld));
	exit(1);
    }
    int nSteps = iso_d2s_Run (wrld, 0);
    //second paramter is the limit to # of steps.
    //0-to termination
     fprintf(stderr, "\n after running o\n");
    // change here for output var
    printf("%5.3f seconds\n",  airTime() - t0);
    if (iso_d2s_OutputGet_out(wrld, nData)) {
        // error
	fprintf(stderr, "Error getting nrrd data: %s", iso_d2s_GetErrors(wrld));
	exit(1);
    }
    // fprintf(stderr, "\n ipotst ouput n");
    Nrrd2(nData,1);
    WriteOutput(nData);
    iso_d2s_Shutdown (wrld);

}

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0