Simple Example

The following C source code calls a Fortran function to multiply the input vector by 10.
/*
////////////////////////////////////////////////////////////////////
// File      : simple.c
// Date      : 7/14/98
// Copyright : Altair Software Development, Inc. 1998
//
// Calculate nothing and return the same vector that you were given.
// freeman
//////////////////////////////////////////////////////////////////////
//                                                                  //
// This source code intended to serve as an example of              //
// the external function capability of MotionView/MotionView.       //
// Neither Altair nor the authors assume any responsibility         //
// for the validity, accuracy, or applicability of any              //
// results obtained from this program. The user must verify         //
// the results on his/her own.                                      //
//                                                                  //
//////////////////////////////////////////////////////////////////////
// arg1 = dummy vector
// arg2 = vector to return
////////////////////////////////////////////////////////////////////
*/
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
/*
#include <sys/socket.h>
#include <unistd.h>
*/
#if defined(SGI_PLATFORM)
#include <strings.h>
#else
#include <string.h>
#endif

#include "../base/altair_ipc.h"

#if defined(_WINDOWS)
extern void __stdcall SIMPLE_S_(); 
#endif

int main(argc, argv)
        int argc;
        char *argv[];
{
    AltairIpcVectorList  vec_list;
    char                 msg_buff[1024];
    double              *return_vec;
    double              *in_vec1;
    double              *in_vec2;
    int                  nfp=1;
    int                  nlp;

    /*
    * You must do this before anything else...
    */
    if (AltairIpcParseCommandLine(argc, argv) != ALTAIR_IPC_SUCCESS)
    {
        AltairIpcPutError("Could not get data.");
    }
    if (AltairIpcGetVectorList(&vec_list) != ALTAIR_IPC_SUCCESS)
    {
        AltairIpcPutError("Could not get data.");
    }
    /*
    * Do some program/routine specific checking...
    */
    AltairIpcPutMessage("Checking for validity of data.");
    if (vec_list.num_vectors < 2)
    {
        sprintf(msg_buff, "Expecting two arguments, got %d.", vec_list.num_vectors);
        AltairIpcPutError(msg_buff);
    }
    else
    {
        AltairIpcPutMessage("Passed validity check.");
        in_vec1 = vec_list.vec_val[0];
        in_vec2 = vec_list.vec_val[1];
        nlp = vec_list.vec_cnt[0];
        sprintf(msg_buff, "delta for first vector = %f", ((in_vec1[(nlp-1)]-
        n_vec1[0])/(nlp-1)));
        AltairIpcPutMessage(msg_buff);
		/* get some memory for the return vector */
        return_vec = malloc(nlp*sizeof(double));
        if ( !return_vec )
        {
            AltairIpcPutError("'malloc(...)' failed");
        }
        /* call the FORTRAN subroutine simple_s from this C program */
#if defined(HP_PLATFORM) || defined(IBM_PLATFORM)
        simple_s( in_vec2, return_vec, &nfp, &nlp);
#elif defined(_WINDOWS)
        SIMPLE_S_( in_vec2, return_vec, &nfp, &nlp);
#else
		simple_s_( in_vec2, return_vec, &nfp, &nlp);
#endif
		AltairIpcPutVector(nlp, return_vec);
        free(return_vec);
    }
    return 0;
}

	SUBROUTINE SIMPLE_S( INVEC, OUTVEC, NFP, NLP)

	! Parameters ___________________________________________________________

	INTEGER NFP ! Index of first data point

	INTEGER NLP ! Index of last data point

	DOUBLEPRECISION INVEC(NFP:NLP)

	DOUBLEPRECISION OUTVEC(NFP:NLP) 
	

	! Variables 

	INTEGER I

	DO I=NFP,NLP,1
		OUTVEC(I) = INVEC(I)*10
	END DO

	RETURN
	END