text:
#pragma once

// v1.4 By Ook
//

#include <gsl/gsl>

#include "EnumConcepts.h"

// this enum is here to simplify debugging
enum class WindowMessages
	: DWORD
{
	eWM_NULL,
	eWM_CREATE,	// lParam = LPCREATESTRUCT
	eWM_DESTROY,
	eWM_MOVE,
	eWM_SIZEWAIT,
	eWM_SIZE,	// lParam = width/height
	eWM_ACTIVATE,
	eWM_SETFOCUS,
	eWM_KILLFOCUS,
	eWM_SETVISIBLE,
	eWM_ENABLE,
	eWM_SETREDRAW,
	eWM_SETTEXT,
	eWM_GETTEXT,
	eWM_GETTEXTLENGTH,
	eWM_PAINT,
	eWM_CLOSE,
	eWM_QUERYENDSESSION,
	eWM_QUIT,
	eWM_QUERYOPEN,
	eWM_ERASEBKGND,	// wParam = HDC
	eWM_SYSCOLORCHANGE,
	eWM_ENDSESSION,
	eWM_SYSTEMERROR,
	eWM_SHOWWINDOW,
	eWM_CTLCOLOR,
	eWM_WININICHANGE,
	eWM_DEVMODECHANGE,
	eWM_ACTIVATEAPP,
	eWM_FONTCHANGE,
	eWM_TIMECHANGE,
	eWM_CANCELMODE,
	eWM_SETCURSOR,
	eWM_MOUSEACTIVATE,
	eWM_CHILDACTIVATE,
	eWM_QUEUESYNC,
	eWM_GETMINMAXINFO,
	eWM_LOGOFF,
	eWM_PAINTICON,
	eWM_ICONERASEBKGND,
	eWM_NEXTDLGCTL,
	eWM_ALTTABACTIVE,
	eWM_SPOOLERSTATUS,
	eWM_DRAWITEM,
	eWM_MEASUREITEM,
	eWM_DELETEITEM,
	eWM_VKEYTOITEM,
	eWM_CHARTOITEM,
	eWM_SETFONT,
	eWM_GETFONT,
	eWM_SETHOTKEY,
	eWM_GETHOTKEY,
	eWM_SHELLNOTIFY,
	eWM_ISACTIVEICON,
	eWM_QUERYPARKICON,
	eWM_QUERYDRAGICON,
	eWM_WINHELP,
	eWM_COMPAREITEM,
	eWM_FULLSCREEN,
	eWM_CLIENTSHUTDOWN,
	eWM_DDEMLEVENT,
	eWM_GETOBJECT,
	eundefined_1,
	eundefined_2,
	eWM_TESTING,
	eWM_COMPACTING,
	eWM_OTHERWINDOWCREATED,
	eWM_OTHERWINDOWDESTROYED,
	eWM_COMMNOTIFY,
	eundefined_3,
	eWM_WINDOWPOSCHANGING,
	eWM_WINDOWPOSCHANGED,
	eWM_POWER,
	eWM_COPYGLOBALDATA,
	eWM_COPYDATA,
	eWM_CANCELJOURNAL,
	eundefined_4,
	eWM_KEYF1,
	eWM_NOTIFY,
	eWM_ACCESS_WINDOW,
	eWM_INPUTLANGCHANGEREQUEST,
	eWM_INPUTLANGCHANGE,
	eWM_TCARD,
	eWM_HELP,
	eWM_USERCHANGED,
	eWM_NOTIFYFORMAT,
	eundefined_5,
	eundefined_6,
	eundefined_7,
	eundefined_8,
	eundefined_9,
	eundefined_10,
	eundefined_11,
	eundefined_12,
	eundefined_13,
	eundefined_14,
	eundefined_15,
	eundefined_16,
	eundefined_17,
	eundefined_18,
	eundefined_19,
	eundefined_20,
	eundefined_21,
	eundefined_22,
	eundefined_23,
	eundefined_24,
	eundefined_25,
	eundefined_26,
	eundefined_27,
	eundefined_28,
	eundefined_29,
	eundefined_30,
	eWM_FINALDESTROY,
	eWM_MEASUREITEM_CLIENTDATA,
	eundefined_31,
	eundefined_32,
	eundefined_33,
	eundefined_34,
	eundefined_35,
	eundefined_36,
	eundefined_37,
	eundefined_38,
	eundefined_39,
	eWM_CONTEXTMENU,
	eWM_STYLECHANGING,
	eWM_STYLECHANGED,
	eWM_DISPLAYCHANGE,
	eWM_GETICON,
	eWM_SETICON,
	eWM_NCCREATE,	// lParam = LPCREATESTRUCT
	eWM_NCDESTROY,
	eWM_NCCALCSIZE,
	eWM_NCHITTEST,
	eWM_NCPAINT,
	eWM_NCACTIVATE,
	eWM_GETDLGCODE,
	eWM_SYNCPAINT,
	eWM_SYNCTASK,
	eundefined_40,
	eWM_KLUDGEMINRECT,
	eWM_LPKDRAWSWITCHWND,
	eundefined_41,
	eundefined_42,
	eundefined_43,
	eWM_UAHDESTROYWINDOW,
	eWM_UAHDRAWMENU,
	eWM_UAHDRAWMENUITEM,
	eWM_UAHINITMENU,
	eWM_UAHMEASUREMENUITEM,
	eWM_UAHNCPAINTMENUPOPUP,
	eWM_UAHUPDATE,
	eundefined_44,
	eundefined_45,
	eundefined_46,
	eundefined_47,
	eundefined_48,
	eundefined_49,
	eundefined_50,
	eundefined_51,
	eundefined_52,
	eWM_NCMOUSEMOVE,
	eWM_NCLBUTTONDOWN,
	eWM_NCLBUTTONUP,
	eWM_NCLBUTTONDBLCLK,
	eWM_NCRBUTTONDOWN,
	eWM_NCRBUTTONUP,
	eWM_NCRBUTTONDBLCLK,
	eWM_NCMBUTTONDOWN,
	eWM_NCMBUTTONUP,
	eWM_NCMBUTTONDBLCLK,
	eundefined_53,
	eWM_NCXBUTTONDOWN,
	eWM_NCXBUTTONUP,
	eWM_NCXBUTTONDBLCLK,
	eWM_NCUAHDRAWCAPTION,
	eWM_NCUAHDRAWFRAME,	// wParam = HDC
	eEM_GETSEL,
	eEM_SETSEL,
	eEM_GETRECT,
	eEM_SETRECT,
	eEM_SETRECTNP,
	eEM_SCROLL,
	eEM_LINESCROLL,
	eEM_SCROLLCARET,
	eEM_GETMODIFY,
	eEM_SETMODIFY,
	eEM_GETLINECOUNT,
	eEM_LINEINDEX,
	eEM_SETHANDLE,
	eEM_GETHANDLE,
	eEM_GETTHUMB,
	eundefined_54,
	eundefined_55,
	eEM_LINELENGTH,
	eEM_REPLACESEL,
	eEM_SETFONT,
	eEM_GETLINE,
	eEM_LIMITTEXT,
	eEM_CANUNDO,
	eEM_UNDO,
	eEM_FMTLINES,
	eEM_LINEFROMCHAR,
	eEM_SETWORDBREAK,
	eEM_SETTABSTOPS,
	eEM_SETPASSWORDCHAR,
	eEM_EMPTYUNDOBUFFER,
	eEM_GETFIRSTVISIBLELINE,
	eEM_SETREADONLY,
	eEM_SETWORDBREAKPROC,
	eEM_GETWORDBREAKPROC,
	eEM_GETPASSWORDCHAR,
	eEM_SETMARGINS,
	eEM_GETMARGINS,
	eEM_GETLIMITTEXT,
	eEM_POSFROMCHAR,
	eEM_CHARFROMPOS,
	eEM_SETIMESTATUS,
	eEM_GETIMESTATUS,
	eEM_MSGMAX,
	eundefined_56,
	eundefined_57,
	eundefined_58,
	eundefined_59,
	eundefined_60,
	eundefined_61,
	eundefined_62,
	eundefined_63,
	eundefined_64,
	eundefined_65,
	eundefined_66,
	eundefined_67,
	eundefined_68,
	eundefined_69,
	eundefined_70,
	eundefined_71,
	eundefined_72,
	eundefined_73,
	eundefined_74,
	eundefined_75,
	eundefined_76,
	eundefined_77,
	eundefined_78,
	eundefined_79,
	eundefined_80,
	eundefined_81,
	eundefined_82,
	eundefined_83,
	eundefined_84,
	eundefined_85,
	eundefined_86,
	eundefined_87,
	eundefined_88,
	eundefined_89,
	eundefined_90,
	eWM_INPUT_DEVICE_CHANGE,
	eWM_INPUT,
	eWM_KEYDOWN,
	eWM_KEYUP,
	eWM_CHAR,
	eWM_DEADCHAR,
	eWM_SYSKEYDOWN,
	eWM_SYSKEYUP,
	eWM_SYSCHAR,
	eWM_SYSDEADCHAR,
	eWM_YOMICHAR,
	eWM_UNICHAR,
	eWM_CONVERTREQUEST,
	eWM_CONVERTRESULT,
	eWM_INTERIM,
	eWM_IME_STARTCOMPOSITION,
	eWM_IME_ENDCOMPOSITION,
	eWM_IME_COMPOSITION,
	eWM_INITDIALOG,
	eWM_COMMAND,
	eWM_SYSCOMMAND,
	eWM_TIMER,
	eWM_HSCROLL,
	eWM_VSCROLL,
	eWM_INITMENU,
	eWM_INITMENUPOPUP,
	eWM_SYSTIMER,
	eWM_GESTURE,
	eWM_GESTURENOTIFY,
	eWM_GESTUREINPUT,
	eWM_GESTURENOTIFIED,
	eundefined_91,
	eundefined_92,
	eWM_MENUSELECT,
	eWM_MENUCHAR,
	eWM_ENTERIDLE,
	eWM_MENURBUTTONUP,
	eWM_MENUDRAG,
	eWM_MENUGETOBJECT,
	eWM_UNINITMENUPOPUP,
	eWM_MENUCOMMAND,
	eWM_CHANGEUISTATE,
	eWM_UPDATEUISTATE,
	eWM_QUERYUISTATE,
	eundefined_93,
	eundefined_94,
	eundefined_95,
	eundefined_96,
	eundefined_97,
	eundefined_98,
	eundefined_99,
	eWM_LBTRACKPOINT,
	eWM_CTLCOLORMSGBOX,
	eWM_CTLCOLOREDIT,
	eWM_CTLCOLORLISTBOX,
	eWM_CTLCOLORBTN,
	eWM_CTLCOLORDLG,
	eWM_CTLCOLORSCROLLBAR,
	eWM_CTLCOLORSTATIC,
	eundefined_100,
	eundefined_101,
	eundefined_102,
	eundefined_103,
	eundefined_104,
	eundefined_105,
	eundefined_106,
	eCB_GETEDITSEL,
	eCB_LIMITTEXT,
	eCB_SETEDITSEL,
	eCB_ADDSTRING,
	eCB_DELETESTRING,
	eCB_DIR,
	eCB_GETCOUNT,
	eCB_GETCURSEL,
	eCB_GETLBTEXT,
	eCB_GETLBTEXTLEN,
	eCB_INSERTSTRING,
	eCB_RESETCONTENT,
	eCB_FINDSTRING,
	eCB_SELECTSTRING,
	eCB_SETCURSEL,
	eCB_SHOWDROPDOWN,
	eCB_GETITEMDATA,
	eCB_SETITEMDATA,
	eCB_GETDROPPEDCONTROLRECT,
	eCB_SETITEMHEIGHT,
	eCB_GETITEMHEIGHT,
	eCB_SETEXTENDEDUI,
	eCB_GETEXTENDEDUI,
	eCB_GETDROPPEDSTATE,
	eCB_FINDSTRINGEXACT,
	eCB_SETLOCALE,
	eCB_GETLOCALE,
	eCB_GETTOPINDEX,
	eCB_SETTOPINDEX,
	eCB_GETHORIZONTALEXTENT,
	eCB_SETHORIZONTALEXTENT,
	eCB_GETDROPPEDWIDTH,
	eCB_SETDROPPEDWIDTH,
	eCB_INITSTORAGE,
	eCB_MSGMAX_OLD,
	eCB_MULTIPLEADDSTRING,
	eCB_GETCOMBOBOXINFO,
	eCB_MSGMAX,
	eCBEC_SETCOMBOFOCUS,
	eCBEC_KILLCOMBOFOCUS,
	eundefined_109,
	eundefined_110,
	eundefined_111,
	eundefined_112,
	eundefined_113,
	eundefined_114,
	eundefined_115,
	eundefined_116,
	eundefined_117,
	eundefined_118,
	eundefined_119,
	eundefined_120,
	eundefined_121,
	eundefined_122,
	eundefined_123,
	eundefined_124,
	eundefined_125,
	eundefined_126,
	eundefined_127,
	eundefined_128,
	eundefined_129,
	eundefined_130,
	eundefined_131,
	eundefined_132,
	eLB_ADDSTRING,
	eLB_INSERTSTRING,
	eLB_DELETESTRING,
	eLB_SELITEMRANGEEX,
	eLB_RESETCONTENT,
	eLB_SETSEL,
	eLB_SETCURSEL,
	eLB_GETSEL,
	eLB_GETCURSEL,
	eLB_GETTEXT,
	eLB_GETTEXTLEN,
	eLB_GETCOUNT,
	eLB_SELECTSTRING,
	eLB_DIR,
	eLB_GETTOPINDEX,
	eLB_FINDSTRING,
	eLB_GETSELCOUNT,
	eLB_GETSELITEMS,
	eLB_SETTABSTOPS,
	eLB_GETHORIZONTALEXTENT,
	eLB_SETHORIZONTALEXTENT,
	eLB_SETCOLUMNWIDTH,
	eLB_ADDFILE,
	eLB_SETTOPINDEX,
	eLB_GETITEMRECT,
	eLB_GETITEMDATA,
	eLB_SETITEMDATA,
	eLB_SELITEMRANGE,
	eLB_SETANCHORINDEX,
	eLB_GETANCHORINDEX,
	eLB_SETCARETINDEX,
	eLB_GETCARETINDEX,
	eLB_SETITEMHEIGHT,
	eLB_GETITEMHEIGHT,
	eLB_FINDSTRINGEXACT,
	eLBCB_CARETON,
	eLBCB_CARETOFF,
	eLB_SETLOCALE,
	eLB_GETLOCALE,
	eLB_SETCOUNT,
	eLB_INITSTORAGE,
	eLB_ITEMFROMPOINT,
	eLB_INSERTSTRINGUPPER,
	eLB_INSERTSTRINGLOWER,
	eLB_ADDSTRINGUPPER,
	eLB_ADDSTRINGLOWER,
	eLBCB_STARTTRACK,
	eLBCB_ENDTRACK,
	eLB_MSGMAX_OLD,
	eLB_MULTIPLEADDSTRING,
	eLB_GETLISTBOXINFO,
	eLB_MSGMAX,
	eundefined_133,
	eundefined_134,
	eundefined_135,
	eundefined_136,
	eundefined_137,
	eundefined_138,
	eundefined_139,
	eundefined_140,
	eundefined_141,
	eundefined_142,
	eundefined_143,
	eundefined_144,
	eundefined_145,
	eundefined_146,
	eundefined_147,
	eundefined_148,
	eundefined_149,
	eundefined_150,
	eundefined_151,
	eundefined_152,
	eundefined_153,
	eundefined_154,
	eundefined_155,
	eundefined_156,
	eundefined_157,
	eundefined_158,
	eundefined_159,
	eundefined_160,
	eundefined_161,
	eundefined_162,
	eundefined_163,
	eundefined_164,
	eundefined_165,
	eundefined_166,
	eundefined_167,
	eundefined_168,
	eundefined_169,
	eundefined_170,
	eundefined_171,
	eundefined_172,
	eundefined_173,
	eundefined_174,
	eundefined_175,
	eundefined_176,
	eMN_FIRST,
	eMN_GETHMENU,
	eMN_SIZEWINDOW,
	eMN_OPENHIERARCHY,
	eMN_CLOSEHIERARCHY,
	eMN_SELECTITEM,
	eMN_CANCELMENUS,
	eMN_SELECTFIRSTVALIDITEM,
	eundefined_183,
	eundefined_184,
	eMN_GETPPOPUPMENU,
	eMN_FINDMENUWINDOWFROMPOINT,	// returns HWND or zero
	eMN_SHOWPOPUPWINDOW,
	eMN_BUTTONDOWN,
	eMN_MOUSEMOVE,
	eMN_BUTTONUP,
	eMN_SETTIMERTOOPENHIERARCHY,
	eMN_DBLCLK,
	eundefined_193,
	eundefined_194,
	eundefined_195,
	eundefined_196,
	eundefined_197,
	eundefined_198,
	eundefined_199,
	eundefined_200,
	eundefined_201,
	eundefined_202,
	eundefined_203,
	eundefined_204,
	eundefined_205,
	eundefined_206,
	eWM_MOUSEMOVE,
	eWM_LBUTTONDOWN,
	eWM_LBUTTONUP,
	eWM_LBUTTONDBLCLK,
	eWM_RBUTTONDOWN,
	eWM_RBUTTONUP,
	eWM_RBUTTONDBLCLK,
	eWM_MBUTTONDOWN,
	eWM_MBUTTONUP,
	eWM_MBUTTONDBLCLK,
	eWM_MOUSEWHEEL,
	eWM_XBUTTONDOWN,
	eWM_XBUTTONUP,
	eWM_XBUTTONDBLCLK,
	eWM_MOUSEHWHEEL,
	eundefined_207,
	eWM_PARENTNOTIFY,
	eWM_ENTERMENULOOP,
	eWM_EXITMENULOOP,
	eWM_NEXTMENU,
	eWM_SIZING,
	eWM_CAPTURECHANGED,
	eWM_MOVING,
	eundefined_208,
	eWM_POWERBROADCAST,
	eWM_DEVICECHANGE,
	eundefined_209,
	eundefined_210,
	eundefined_211,
	eundefined_212,
	eundefined_213,
	eundefined_214,
	eWM_MDICREATE,
	eWM_MDIDESTROY,
	eWM_MDIACTIVATE,
	eWM_MDIRESTORE,
	eWM_MDINEXT,
	eWM_MDIMAXIMIZE,
	eWM_MDITILE,
	eWM_MDICASCADE,
	eWM_MDIICONARRANGE,
	eWM_MDIGETACTIVE,
	eWM_DROPOBJECT,
	eWM_QUERYDROPOBJECT,
	eWM_BEGINDRAG,
	eWM_DRAGLOOP,
	eWM_DRAGSELECT,
	eWM_DRAGMOVE,
	eWM_MDISETMENU,
	eWM_ENTERSIZEMOVE,
	eWM_EXITSIZEMOVE,
	eWM_DROPFILES,
	eWM_MDIREFRESHMENU,
	eundefined_215,
	eundefined_216,
	eundefined_217,
	eWM_POINTERDEVICECHANGE,
	eWM_POINTERDEVICEINRANGE,
	eWM_POINTERDEVICEOUTOFRANGE,
	eWM_STOPINERTIA,
	eWM_ENDINERTIA,
	eWM_EDGYINERTIA,
	eundefined_218,
	eundefined_219,
	eWM_TOUCH,
	eWM_NCPOINTERUPDATE,
	eWM_NCPOINTERDOWN,
	eWM_NCPOINTERUP,
	eWM_NCPOINTERLAST,
	eWM_POINTERUPDATE,
	eWM_POINTERDOWN,
	eWM_POINTERUP,
	eWM_POINTER_reserved_248,
	eWM_POINTERENTER,
	eWM_POINTERLEAVE,
	eWM_POINTERACTIVATE,
	eWM_POINTERCAPTURECHANGED,
	eWM_TOUCHHITTESTING,
	eWM_POINTERWHEEL,
	eWM_POINTERHWHEEL,
	eWM_POINTER_reserved_250,
	eWM_POINTER_reserved_251,
	eWM_POINTER_reserved_252,
	eWM_POINTER_reserved_253,
	eWM_POINTER_reserved_254,
	eWM_POINTER_reserved_255,
	eWM_POINTER_reserved_256,
	eWM_POINTERLAST,
	eundefined_220,
	eundefined_221,
	eundefined_222,
	eundefined_223,
	eundefined_224,
	eundefined_225,
	eundefined_226,
	eundefined_227,
	eundefined_228,
	eundefined_229,
	eundefined_230,
	eundefined_231,
	eundefined_232,
	eundefined_233,
	eundefined_234,
	eundefined_235,
	eundefined_236,
	eundefined_237,
	eundefined_238,
	eundefined_239,
	eundefined_240,
	eundefined_241,
	eundefined_242,
	eundefined_243,
	eWM_VISIBILITYCHANGED,
	eWM_VIEWSTATECHANGED,
	eWM_UNREGISTER_WINDOW_SERVICES,
	eWM_CONSOLIDATED,
	eundefined_244,
	eundefined_245,
	eundefined_246,
	eundefined_247,
	eundefined_248,
	eundefined_249,
	eundefined_250,
	eundefined_251,
	eundefined_252,
	eundefined_253,
	eundefined_254,
	eundefined_255,
	eWM_IME_REPORT,
	eWM_IME_SETCONTEXT,
	eWM_IME_NOTIFY,
	eWM_IME_CONTROL,
	eWM_IME_COMPOSITIONFULL,
	eWM_IME_SELECT,
	eWM_IME_CHAR,
	eWM_IME_SYSTEM,
	eWM_IME_REQUEST,
	eWM_KANJI_reserved_289,
	eWM_KANJI_reserved_28a,
	eWM_KANJI_reserved_28b,
	eWM_KANJI_reserved_28c,
	eWM_KANJI_reserved_28d,
	eWM_KANJI_reserved_28e,
	eWM_KANJI_reserved_28f,
	eWM_IME_KEYDOWN,
	eWM_IME_KEYUP,
	eWM_KANJI_reserved_292,
	eWM_KANJI_reserved_293,
	eWM_KANJI_reserved_294,
	eWM_KANJI_reserved_295,
	eWM_KANJI_reserved_296,
	eWM_KANJI_reserved_297,
	eWM_KANJI_reserved_298,
	eWM_KANJI_reserved_299,
	eWM_KANJI_reserved_29a,
	eWM_KANJI_reserved_29b,
	eWM_KANJI_reserved_29c,
	eWM_KANJI_reserved_29d,
	eWM_KANJI_reserved_29e,
	eWM_KANJILAST,
	eWM_NCMOUSEHOVER,
	eWM_MOUSEHOVER,
	eWM_NCMOUSELEAVE,
	eWM_MOUSELEAVE,
	eWM_TRACKMOUSEEVENT__reserved_2a4,
	eWM_TRACKMOUSEEVENT__reserved_2a5,
	eWM_TRACKMOUSEEVENT__reserved_2a6,
	eWM_TRACKMOUSEEVENT__reserved_2a7,
	eWM_TRACKMOUSEEVENT__reserved_2a8,
	eWM_TRACKMOUSEEVENT__reserved_2a9,
	eWM_TRACKMOUSEEVENT__reserved_2aa,
	eWM_TRACKMOUSEEVENT__reserved_2ab,
	eWM_TRACKMOUSEEVENT__reserved_2ac,
	eWM_TRACKMOUSEEVENT__reserved_2ad,
	eWM_TRACKMOUSEEVENT__reserved_2ae,
	eWM_TRACKMOUSEEVENT_LAST,
	eundefined_256,
	eWM_WTSSESSION_CHANGE,
	eundefined_257,
	eundefined_258,
	eundefined_259,
	eundefined_260,
	eundefined_261,
	eundefined_262,
	eundefined_263,
	eundefined_264,
	eundefined_265,
	eundefined_266,
	eundefined_267,
	eundefined_268,
	eundefined_269,
	eundefined_270,
	eWM_TABLET_FIRST,
	eWM_TABLET__reserved_2c1,
	eWM_TABLET__reserved_2c2,
	eWM_TABLET__reserved_2c3,
	eWM_TABLET__reserved_2c4,
	eWM_TABLET__reserved_2c5,
	eWM_TABLET__reserved_2c6,
	eWM_TABLET__reserved_2c7,
	eWM_POINTERDEVICEADDED,
	eWM_POINTERDEVICEDELETED,
	eWM_TABLET__reserved_2ca,
	eWM_FLICK,
	eWM_TABLET__reserved_2cc,
	eWM_FLICKINTERNAL,
	eWM_BRIGHTNESSCHANGED,
	eWM_TABLET__reserved_2cf,
	eWM_TABLET__reserved_2d0,
	eWM_TABLET__reserved_2d1,
	eWM_TABLET__reserved_2d2,
	eWM_TABLET__reserved_2d3,
	eWM_TABLET__reserved_2d4,
	eWM_TABLET__reserved_2d5,
	eWM_TABLET__reserved_2d6,
	eWM_TABLET__reserved_2d7,
	eWM_TABLET__reserved_2d8,
	eWM_TABLET__reserved_2d9,
	eWM_TABLET__reserved_2da,
	eWM_TABLET__reserved_2db,
	eWM_TABLET__reserved_2dc,
	eWM_TABLET__reserved_2dd,
	eWM_TABLET__reserved_2de,
	eWM_TABLET_LAST,
	eWM_DPICHANGED,
	eundefined_271,
	eundefined_272,
	eundefined_273,
	eundefined_274,
	eundefined_275,
	eundefined_276,
	eundefined_277,
	eundefined_278,
	eundefined_279,
	eundefined_280,
	eundefined_281,
	eundefined_282,
	eundefined_283,
	eundefined_284,
	eundefined_285,
	eundefined_286,
	eundefined_287,
	eundefined_288,
	eundefined_289,
	eundefined_290,
	eundefined_291,
	eundefined_292,
	eundefined_293,
	eundefined_294,
	eundefined_295,
	eundefined_296,
	eundefined_297,
	eundefined_298,
	eundefined_299,
	eundefined_300,
	eundefined_301,
	eWM_CUT,
	eWM_COPY,
	eWM_PASTE,
	eWM_CLEAR,
	eWM_UNDO,
	eWM_RENDERFORMAT,
	eWM_RENDERALLFORMATS,
	eWM_DESTROYCLIPBOARD,
	eWM_DRAWCLIPBOARD,
	eWM_PAINTCLIPBOARD,
	eWM_VSCROLLCLIPBOARD,
	eWM_SIZECLIPBOARD,
	eWM_ASKCBFORMATNAME,
	eWM_CHANGECBCHAIN,
	eWM_HSCROLLCLIPBOARD,
	eWM_QUERYNEWPALETTE,
	eWM_PALETTEISCHANGING,
	eWM_PALETTECHANGED,
	eWM_HOTKEY,
	eWM_SYSMENU,
	eWM_HOOKMSG,
	eWM_EXITPROCESS,
	eWM_WAKETHREAD,
	eWM_PRINT,
	eWM_PRINTCLIENT,
	eWM_APPCOMMAND,
	eWM_THEMECHANGED,
	eWM_UAHINIT,
	eWM_DESKTOPNOTIFY,
	eWM_CLIPBOARDUPDATE,
	eWM_DWMCOMPOSITIONCHANGED,
	eWM_DWMNCRENDERINGCHANGED,
	eWM_DWMCOLORIZATIONCOLORCHANGED,
	eWM_DWMWINDOWMAXIMIZEDCHANGE,
	eWM_DWMEXILEFRAME,
	eWM_DWMSENDICONICTHUMBNAIL,
	eWM_MAGNIFICATION_STARTED,
	eWM_MAGNIFICATION_ENDED,
	eWM_DWMSENDICONICLIVEPREVIEWBITMAP,
	eWM_DWMTHUMBNAILSIZECHANGED,
	eWM_MAGNIFICATION_OUTPUT,
	eWM_BSDRDATA,
	eWM_DWMTRANSITIONSTATECHANGED,
	eundefined_302,
	eWM_KEYBOARDCORRECTIONCALLOUT,
	eWM_KEYBOARDCORRECTIONACTION,
	eWM_UIACTION,
	eWM_ROUTED_UI_EVENT,
	eWM_MEASURECONTROL,
	eWM_GETACTIONTEXT,
	eWM_CE_ONLY__reserved_332,
	eWM_FORWARDKEYDOWN,
	eWM_FORWARDKEYUP,
	eWM_CE_ONLY__reserved_335,
	eWM_CE_ONLY__reserved_336,
	eWM_CE_ONLY__reserved_337,
	eWM_CE_ONLY__reserved_338,
	eWM_CE_ONLY__reserved_339,
	eWM_CE_ONLY__reserved_33a,
	eWM_CE_ONLY__reserved_33b,
	eWM_CE_ONLY__reserved_33c,
	eWM_CE_ONLY__reserved_33d,
	eWM_CE_ONLY_LAST,
	eWM_GETTITLEBARINFOEX,
	eWM_NOTIFYWOW,
	eundefined_303,
	eundefined_304,
	eundefined_305,
	eundefined_306,
	eundefined_307,
	eundefined_308,
	eundefined_309,
	eundefined_310,
	eundefined_311,
	eundefined_312,
	eundefined_313,
	eundefined_314,
	eundefined_315,
	eundefined_316,
	eundefined_317,
	eundefined_318,
	eundefined_319,
	eundefined_320,
	eundefined_321,
	eundefined_322,
	eundefined_323,
	eundefined_324,
	eundefined_325,
	eWM_HANDHELDFIRST,
	eWM_HANDHELD_reserved_359,
	eWM_HANDHELD_reserved_35a,
	eWM_HANDHELD_reserved_35b,
	eWM_HANDHELD_reserved_35c,
	eWM_HANDHELD_reserved_35d,
	eWM_HANDHELD_reserved_35e,
	eWM_HANDHELDLAST,
	eWM_AFXFIRST,
	eWM_AFX_reserved_361,
	eWM_AFX_reserved_362,
	eWM_AFX_reserved_363,
	eWM_AFX_reserved_364,
	eWM_AFX_reserved_365,
	eWM_AFX_reserved_366,
	eWM_AFX_reserved_367,
	eWM_AFX_reserved_368,
	eWM_AFX_reserved_369,
	eWM_AFX_reserved_36a,
	eWM_AFX_reserved_36b,
	eWM_AFX_reserved_36c,
	eWM_AFX_reserved_36d,
	eWM_AFX_reserved_36e,
	eWM_AFX_reserved_36f,
	eWM_AFX_reserved_370,
	eWM_AFX_reserved_371,
	eWM_AFX_reserved_372,
	eWM_AFX_reserved_373,
	eWM_AFX_reserved_374,
	eWM_AFX_reserved_375,
	eWM_AFX_reserved_376,
	eWM_AFX_reserved_377,
	eWM_AFX_reserved_378,
	eWM_AFX_reserved_379,
	eWM_AFX_reserved_37a,
	eWM_AFX_reserved_37b,
	eWM_AFX_reserved_37c,
	eWM_AFX_reserved_37d,
	eWM_AFX_reserved_37e,
	eWM_AFXLAST,
	eWM_PENWINFIRST,
	eWM_PENWIN_reserved_381,
	eWM_PENWIN_reserved_382,
	eWM_PENWIN_reserved_383,
	eWM_PENWIN_reserved_384,
	eWM_PENWIN_reserved_385,
	eWM_PENWIN_reserved_386,
	eWM_PENWIN_reserved_387,
	eWM_PENWIN_reserved_388,
	eWM_PENWIN_reserved_389,
	eWM_PENWIN_reserved_38a,
	eWM_PENWIN_reserved_38b,
	eWM_PENWIN_reserved_38c,
	eWM_PENWIN_reserved_38d,
	eWM_PENWIN_reserved_38e,
	eWM_PENWINLAST,
	eWM_COALESCE_FIRST,
	eWM_COALESCE__reserved_391,
	eWM_COALESCE__reserved_392,
	eWM_COALESCE__reserved_393,
	eWM_COALESCE__reserved_394,
	eWM_COALESCE__reserved_395,
	eWM_COALESCE__reserved_396,
	eWM_COALESCE__reserved_397,
	eWM_COALESCE__reserved_398,
	eWM_COALESCE__reserved_399,
	eWM_COALESCE__reserved_39a,
	eWM_COALESCE__reserved_39b,
	eWM_COALESCE__reserved_39c,
	eWM_COALESCE__reserved_39d,
	eWM_COALESCE__reserved_39e,
	eWM_COALESCE_LAST,
	eWM_MM_RESERVED_FIRST,
	eWM_MM_RESERVED__reserved_3a1,
	eWM_MM_RESERVED__reserved_3a2,
	eWM_MM_RESERVED__reserved_3a3,
	eWM_MM_RESERVED__reserved_3a4,
	eWM_MM_RESERVED__reserved_3a5,
	eWM_MM_RESERVED__reserved_3a6,
	eWM_MM_RESERVED__reserved_3a7,
	eWM_MM_RESERVED__reserved_3a8,
	eWM_MM_RESERVED__reserved_3a9,
	eWM_MM_RESERVED__reserved_3aa,
	eWM_MM_RESERVED__reserved_3ab,
	eWM_MM_RESERVED__reserved_3ac,
	eWM_MM_RESERVED__reserved_3ad,
	eWM_MM_RESERVED__reserved_3ae,
	eWM_MM_RESERVED__reserved_3af,
	eWM_MM_RESERVED__reserved_3b0,
	eWM_MM_RESERVED__reserved_3b1,
	eWM_MM_RESERVED__reserved_3b2,
	eWM_MM_RESERVED__reserved_3b3,
	eWM_MM_RESERVED__reserved_3b4,
	eWM_MM_RESERVED__reserved_3b5,
	eWM_MM_RESERVED__reserved_3b6,
	eWM_MM_RESERVED__reserved_3b7,
	eWM_MM_RESERVED__reserved_3b8,
	eWM_MM_RESERVED__reserved_3b9,
	eWM_MM_RESERVED__reserved_3ba,
	eWM_MM_RESERVED__reserved_3bb,
	eWM_MM_RESERVED__reserved_3bc,
	eWM_MM_RESERVED__reserved_3bd,
	eWM_MM_RESERVED__reserved_3be,
	eWM_MM_RESERVED__reserved_3bf,
	eWM_MM_RESERVED__reserved_3c0,
	eWM_MM_RESERVED__reserved_3c1,
	eWM_MM_RESERVED__reserved_3c2,
	eWM_MM_RESERVED__reserved_3c3,
	eWM_MM_RESERVED__reserved_3c4,
	eWM_MM_RESERVED__reserved_3c5,
	eWM_MM_RESERVED__reserved_3c6,
	eWM_MM_RESERVED__reserved_3c7,
	eWM_MM_RESERVED__reserved_3c8,
	eWM_MM_RESERVED__reserved_3c9,
	eWM_MM_RESERVED__reserved_3ca,
	eWM_MM_RESERVED__reserved_3cb,
	eWM_MM_RESERVED__reserved_3cc,
	eWM_MM_RESERVED__reserved_3cd,
	eWM_MM_RESERVED__reserved_3ce,
	eWM_MM_RESERVED__reserved_3cf,
	eWM_MM_RESERVED__reserved_3d0,
	eWM_MM_RESERVED__reserved_3d1,
	eWM_MM_RESERVED__reserved_3d2,
	eWM_MM_RESERVED__reserved_3d3,
	eWM_MM_RESERVED__reserved_3d4,
	eWM_MM_RESERVED__reserved_3d5,
	eWM_MM_RESERVED__reserved_3d6,
	eWM_MM_RESERVED__reserved_3d7,
	eWM_MM_RESERVED__reserved_3d8,
	eWM_MM_RESERVED__reserved_3d9,
	eWM_MM_RESERVED__reserved_3da,
	eWM_MM_RESERVED__reserved_3db,
	eWM_MM_RESERVED__reserved_3dc,
	eWM_MM_RESERVED__reserved_3dd,
	eWM_MM_RESERVED__reserved_3de,
	eWM_MM_RESERVED_LAST,
	eWM_INTERNAL_DDE_FIRST,
	eWM_INTERNAL_DDE__reserved_3e1,
	eWM_INTERNAL_DDE__reserved_3e2,
	eWM_INTERNAL_DDE__reserved_3e3,
	eWM_INTERNAL_DDE__reserved_3e4,
	eWM_INTERNAL_DDE__reserved_3e5,
	eWM_INTERNAL_DDE__reserved_3e6,
	eWM_INTERNAL_DDE__reserved_3e7,
	eWM_INTERNAL_DDE__reserved_3e8,
	eWM_INTERNAL_DDE__reserved_3e9,
	eWM_INTERNAL_DDE__reserved_3ea,
	eWM_INTERNAL_DDE__reserved_3eb,
	eWM_INTERNAL_DDE__reserved_3ec,
	eWM_INTERNAL_DDE__reserved_3ed,
	eWM_INTERNAL_DDE__reserved_3ee,
	eWM_INTERNAL_DDE_LAST,
	eWM_CBT_RESERVED_FIRST,
	eWM_CBT_RESERVED__reserved_3f1,
	eWM_CBT_RESERVED__reserved_3f2,
	eWM_CBT_RESERVED__reserved_3f3,
	eWM_CBT_RESERVED__reserved_3f4,
	eWM_CBT_RESERVED__reserved_3f5,
	eWM_CBT_RESERVED__reserved_3f6,
	eWM_CBT_RESERVED__reserved_3f7,
	eWM_CBT_RESERVED__reserved_3f8,
	eWM_CBT_RESERVED__reserved_3f9,
	eWM_CBT_RESERVED__reserved_3fa,
	eWM_CBT_RESERVED__reserved_3fb,
	eWM_CBT_RESERVED__reserved_3fc,
	eWM_CBT_RESERVED__reserved_3fd,
	eWM_CBT_RESERVED__reserved_3fe,
	eWM_CBT_RESERVED_LAST,
};

// Window Styles Helper enums.

enum class WindowStyle
	: DWORD
{
	None,
	Child = WS_CHILD,
	Border = WS_BORDER,
	Caption = WS_CAPTION,
	ClipChildren = WS_CLIPCHILDREN,
	TabStop = WS_TABSTOP,
	LBS_MultiSel = LBS_MULTIPLESEL,
	LBS_ExtendedSel = LBS_EXTENDEDSEL,
	LBS_UseTabStops = LBS_USETABSTOPS,
	BS_Bitmap = BS_BITMAP,
	BS_OwnerDraw = BS_OWNERDRAW,
	SS_EndEllipsis = SS_ENDELLIPSIS,
	SS_PathEllipsis = SS_PATHELLIPSIS,
	SS_NoPrefix = SS_NOPREFIX,
	SS_LeftNoWordWrap = SS_LEFTNOWORDWRAP,
	SS_Center = SS_CENTER,
	SS_Right = SS_RIGHT,
	ES_MultiLine = ES_MULTILINE,
	ES_Password = ES_PASSWORD,
	ES_ReadOnly = ES_READONLY,
	TVS_CheckBoxes = TVS_CHECKBOXES,
	CCS_NoParentAlign = CCS_NOPARENTALIGN,
	CCS_NoResize = CCS_NORESIZE,
	TCS_ForceLeftAlign = TCS_FORCELABELLEFT,
	PBS_Vertical = PBS_VERTICAL,
	MCS_MultiSelect = MCS_MULTISELECT,
	LVS_SingleSelect = LVS_SINGLESEL,
	LVS_ShowSelAlways = LVS_SHOWSELALWAYS,
	CBS_DropDown = CBS_DROPDOWN,
	CBS_Simple = CBS_SIMPLE,
	DTS_ShowNone = DTS_SHOWNONE
};

enum class WindowExStyle
	: DWORD
{
	None,
	DialogModalFrame = WS_EX_DLGMODALFRAME,
	ParentNotify = WS_EX_NOPARENTNOTIFY,
	TopMost = WS_EX_TOPMOST,
	AcceptFiles = WS_EX_ACCEPTFILES,
	Transparent = WS_EX_TRANSPARENT,
	MDIChild = WS_EX_MDICHILD,
	ToolWindow = WS_EX_TOOLWINDOW,
	WindowEdge = WS_EX_WINDOWEDGE,
	ControlParent = WS_EX_CONTROLPARENT,
	ClientEdge = WS_EX_CLIENTEDGE,
	Composited = WS_EX_COMPOSITED,
	Layered = WS_EX_LAYERED
};

enum class WindowAnimStyle
	: DWORD
{
	None
};

template <EnumConcepts::IsNumeric T>
constexpr WindowStyle to_WindowStyle(T other) noexcept
{
	return gsl::narrow_cast<WindowStyle>(other);
}
template <EnumConcepts::IsNumeric T>
constexpr WindowExStyle to_WindowExStyle(T other) noexcept
{
	return gsl::narrow_cast<WindowExStyle>(other);
}

inline WindowStyle dcxGetWindowStyle(HWND Hwnd) noexcept
{
	return to_WindowStyle(GetWindowLong(Hwnd, GWL_STYLE));
}

inline WindowExStyle dcxGetWindowExStyle(HWND Hwnd) noexcept
{
	return to_WindowExStyle(GetWindowLong(Hwnd, GWL_EXSTYLE));
}

inline WindowStyle dcxSetWindowStyle(HWND Hwnd, WindowStyle style) noexcept
{
	return to_WindowStyle(SetWindowLongPtr(Hwnd, GWL_STYLE, gsl::narrow_cast<LONG>(style)));
}

inline WindowExStyle dcxSetWindowExStyle(HWND Hwnd, WindowExStyle style) noexcept
{
	return to_WindowExStyle(SetWindowLongPtr(Hwnd, GWL_EXSTYLE, gsl::narrow_cast<LONG>(style)));
}

inline HWND dcxCreateWindow(const WindowExStyle ExStyles, const TCHAR* const szClass, const WindowStyle Styles, const RECT* const rc, HWND hParent, const UINT uID, const void* const pthis = nullptr) noexcept
{
	return CreateWindowEx(
		gsl::narrow_cast<DWORD>(ExStyles),
		szClass,
		nullptr,
		gsl::narrow_cast<DWORD>(Styles),
		rc->left, rc->top, rc->right - rc->left, rc->bottom - rc->top,
		hParent,
		(HMENU)uID,
		GetModuleHandle(nullptr),
		(LPVOID)pthis);
}

inline UINT dcxSetWindowID(HWND Hwnd, const UINT uID) noexcept
{
	return gsl::narrow_cast<UINT>(SetWindowLongPtr(Hwnd, GWLP_ID, gsl::narrow_cast<LONG>(uID)));
}

max_stars_repo_name: twig/dcxdll

max_issues_repo_name: twig/dcxdll

max_forks_repo_name: twig/dcxdll


text:
#ifndef _MATH_UTIL_EULER_H_
#define	_MATH_UTIL_EULER_H_

/* space group numbers for structures known by this program */
/* these are from the International Tables, allowed values are [1-230] */
/*
 * #define FCC 225
 * #define BCC 229
 * #define DIA 227
 * #define SIMPLE_CUBIC 221
 * #define HEX 194
 * #define SAPPHIRE 167
 * #define TRICLINIC 1
 */

#ifndef CHECK_FREE
#define CHECK_FREE(A)   { if(A) free(A); (A)=NULL;}
#endif

#ifdef _MSC_VER						/* identifies this as a Microsoft compiler */
#include <gsl/gsl_math.h>			/* added RX2011 for NaN handling */
#define round(A) ceil(A-0.5)		/* added RX2011 for round() function */
#define NAN gsl_nan()				/* added RX2011 */
#define isNAN(A) gsl_isnan(A)		/* added RX2011 */
#endif

#ifndef NAN							/* probably only needed for pcs */
#define NAN nan("")					/* probably only needed for cygwin on pc */
#endif

#ifndef isNAN						/* a good test for NAN  */
#define isNAN(A) ( (A) != (A) )
#endif

#define VECTOR_COPY3(A,B) {A[0]=B[0]; A[1]=B[1]; A[2]=B[2];}

void DeletePoints(size_t len, void *ptr, size_t pntLen, size_t numDel);

void EulerMatrix(double alpha,double beta,double gamma,double M_Euler[3][3]);
void rot2EulerAngles(double A[3][3], double *alpha, double *beta, double *gamma);
void MatrixRz(double Rz[3][3],double angle);
void MatrixRy(double Ry[3][3],double angle);

/* void lowestOrderHKL(int hkl[3]); */
/* void lowestAllowedHKL(int hkl[3], int structure); */
/* long allowedHKL(long h, long k, long l, int structure); */
int gcf(int n1, int n2, int n3);

double normalize3(double a[3]);
void cross(double a[3], double b[3], double c[3]);
void vector3cons(double a[3], double x);
double dot3(double a[3],double b[3]);
double determinant33(double a[3][3]);
void MatrixMultiply31(double a[3][3], double v[3], double c[3]);
void MatrixMultiply33(double a[3][3], double b[3][3], double c[3][3]);
void MatrixTranspose33(double A[3][3]);					/* transpose the 3x3 matrix A */
void MatrixCopy33(double dest[3][3], double source[3][3]);
double diff3(double a[3], double b[3]);
double matsDelta(double a[3][3], double b[3][3]);

char *num2sexigesmal(char str[40], double seconds, long places);

#endif

ext: h

max_stars_repo_name: carterbox/cold

max_issues_repo_name: carterbox/cold

max_forks_repo_name: carterbox/cold


text:
#ifndef __QBLAS_EXTEND__CD
#define __QBLAS_EXTEND__CD
#ifdef HAVE_CBLAS_H
#include <cblas.h>
#elif (defined HAVE_MKL_CBLAS_H)
#include <mkl_cblas.h>
#elif (defined HAVE_GSL_CBLAS_H)
#include <gsl_cblas.h>
#endif

/*
  some convenience functions for
  the case where all vectors are
  continguous in memory
*/
inline void cblas_daxpy(const int N,
                        const double alpha,
                        const double *X,
                        double *Y)
{ cblas_daxpy(N,alpha,X,1,Y,1); }

inline double cblas_dnrm2(const int N,
                          const double *X)
{ return cblas_dnrm2(N,X,1); }

inline void cblas_dcopy(const int N,
                        const double *X,
                        double *Y )
{ cblas_dcopy(N,X,1,Y,1); }

inline void cblas_dscal(const int N,
                        const double alpha,
                        double *X)
{ cblas_dscal(N,alpha,X,1); }

inline double cblas_ddot(const int N,
			 const double *X,
			 const double *Y )
{ return cblas_ddot(N,X,1,Y,1); }

inline double cblas_ddot(const int N, const double *X)
{ return cblas_ddot(N,X,1,X,1); }

inline void cblas_zdotc_sub(const int N, const double *X, const double *Y,
			  double* dot)
{ return cblas_zdotc_sub(N,X,1,Y,1, dot); }

//inline void cblas_cdotc_sub(const int N, const float *X, const float *Y,
//		  float* dot)
//{ return cblas_cdotc_sub(N,X,Y,dot); }

#endif

max_stars_repo_name: RBC-UKQCD/CPS

max_issues_repo_name: RBC-UKQCD/CPS

max_forks_repo_name: RBC-UKQCD/CPS


text:
#pragma once
#include <ntdll.h>
#include <gsl/span>
#include <gsl/span_ext>
#include "module.h"

namespace pe
{
  class module;

  class segment : public IMAGE_SECTION_HEADER
  {
  public:
    segment() = delete;

    const class module *module() const;
    class module *module();
    std::string_view name() const;
    gsl::span<uint8_t> as_bytes();
    gsl::span<const uint8_t> as_bytes() const;
    bool contains_code() const;
    bool contains_initialized_data() const;
    bool contains_uninitialized_data() const;
    uint32_t relocation_count() const;
    bool discardable() const;
    bool not_cached() const;
    bool not_paged() const;
    bool shared() const;
    bool executable() const;
    bool readable() const;
    bool writable() const;
  };
}

#include "segment.inl"

max_stars_repo_name: bnsmodpolice/loginhelper

max_issues_repo_name: bnsmodpolice/loginhelper

max_forks_repo_name: bnsmodpolice/loginhelper


text:
/* The VCL screen capture library is released under the MIT license.
 *
 * Copyright(c) 2018 Basil Fierz
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files(the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions :
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
#pragma once

// Abseil
#include <absl/strings/string_view.h>

// C++ standard library
#include <array>
#include <utility>

// GSL
#include <gsl/gsl>

#ifdef VCL_GRAPHICS_RECORDER_EXPORTS
#	define VCL_GRAPHICS_RECORDER_API __declspec(dllexport)
#else
#	define VCL_GRAPHICS_RECORDER_API __declspec(dllimport)
#endif

extern "C"
{
	struct AVCodec;
	struct AVCodecContext;
	struct AVCodecParameters;
	struct AVFormatContext;
	struct AVFrame;
	struct AVStream;
}

namespace Vcl { namespace Graphics { namespace Recorder
{
	enum class OutputFormat
	{
		Avi,
		Mkv,
		Mp4
	};

	enum class CodecType
	{
		H264
	};

	class VCL_GRAPHICS_RECORDER_API Recorder
	{
	public:
		Recorder(OutputFormat out_fmt, CodecType codec);
		~Recorder();

	public:
		void open(absl::string_view sink_name, unsigned int width, unsigned int height, unsigned int frame_rate);
		void close();

		bool write(gsl::span<const uint8_t> Y, gsl::span<const uint8_t> U, gsl::span<const uint8_t> V);
		bool write(gsl::span<const uint8_t> Y, gsl::span<const std::array<uint8_t, 2>> UV);
		bool write(gsl::span<const std::array<uint8_t, 3>> rgb, unsigned int w, unsigned int h);

	private:
		//! Create the output format
		//! \param fmt Format to create
		//! \param ctx Context to assign the output format to
		void createOutputFormat(OutputFormat fmt, gsl::not_null<AVFormatContext*> ctx) const;

		//! Prepare codec
		//! \param codec Codec to create
		std::pair<AVCodec*, AVCodecContext*> createCodec(CodecType codec_cfg) const;

		//! Configure specific H264 parameters
		void configureH264();

		//! Write a single frame to the output
		//! \param frame Frame to write out. Use 'nullptr' to flush the codec.
		//! \note Notes about internal API used:
		//! * https://blogs.gentoo.org/lu_zero/2016/03/29/new-avcodec-api/
		//! * https://www.ffmpeg.org/doxygen/3.4/group__lavc__encdec.html
		bool write(AVFrame* frame);

		//! Hold the formating of the IO container
		AVFormatContext* _fmtCtx{nullptr};

		//! Recording stream
		AVStream* _videoStream{nullptr};

		//! Actual codec
		AVCodec* _codec{nullptr};

		//! Codec context
		AVCodecContext* _codecCtx{nullptr};

		//! Is the output open
		bool _isOpen{false};

		//! Temporary frames for data processing
		AVFrame* _processing_frame{nullptr};

		//! Current frame count
		int64_t _frames{0};
	};
}}}


text:
// MILOS v2.0 (2020)
// Milne-Eddington inversion code (based on IDL MILOS code by D. Orozco)
// Manuel Cabrera, Juan P. Cobos, Luis Bellot (IAA-CSIC)
// For questions, please contact lbellot@iaa.es
//

/*
;      eta0 = line-to-continuum absorption coefficient ratio
;      B = magnetic field strength       [Gauss]
;      vlos = line-of-sight velocity     [km/s]
;      dopp = Doppler width              [Angstroms]
;      aa = damping parameter
;      gm = magnetic field inclination   [deg]
;      az = magnetic field azimuth       [deg]
;      S0 = source function constant
;      S1 = source function gradient
;      mac = macroturbulent velocity     [km/s]
;      alpha = filling factor of the magnetic component [0->1]

*/

#include <time.h>
#include "defines.h"
#include <string.h>
#include <stdio.h>
#include "/opt/local/cfitsio/cfitsio-3.350/include/fitsio.h" ///opt/local/cfitsio/cfitsio-3.350/include/
#include "utilsFits.h"
#include "milosUtils.h"
#include "lib.h"
#include "readConfig.h"
#include <unistd.h>
#include <complex.h>
#include <fftw3.h> //siempre a continuacion de complex.h
#include <gsl/gsl_spline.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_eigen.h>
#include <libgen.h>

int NTERMS = 11;
Cuantic *cuantic; // Variable global, está hecho así, de momento,para parecerse al original

PRECISION **PUNTEROS_CALCULOS_COMPARTIDOS;
int POSW_PUNTERO_CALCULOS_COMPARTIDOS;
int POSR_PUNTERO_CALCULOS_COMPARTIDOS;

REAL *dtaux, *etai_gp3, *ext1, *ext2, *ext3, *ext4;
REAL *gp1, *gp2, *dt, *dti, *gp3, *gp4, *gp5, *gp6, *etai_2;
REAL *gp4_gp2_rhoq, *gp5_gp2_rhou, *gp6_gp2_rhov;
REAL *dgp1, *dgp2, *dgp3, *dgp4, *dgp5, *dgp6, *d_dt;
REAL *d_ei, *d_eq, *d_eu, *d_ev, *d_rq, *d_ru, *d_rv;
REAL *dfi, *dshi;
REAL CC, CC_2, sin_gm, azi_2, sinis, cosis, cosis_2, cosi, sina, cosa, sinda, cosda, sindi, cosdi, sinis_cosa, sinis_sina;
REAL *fi_p, *fi_b, *fi_r, *shi_p, *shi_b, *shi_r;
REAL *etain, *etaqn, *etaun, *etavn, *rhoqn, *rhoun, *rhovn;
REAL *etai, *etaq, *etau, *etav, *rhoq, *rhou, *rhov;
REAL *parcial1, *parcial2, *parcial3;
REAL *nubB, *nupB, *nurB;
REAL **uuGlobalInicial;
REAL **HGlobalInicial;
REAL **FGlobalInicial;

PRECISION *GMAC,* GMAC_DERIV;
PRECISION * dirConvPar;
REAL *resultConv;
PRECISION * G = NULL;

REAL * opa;
int FGlobal, HGlobal, uuGlobal;

REAL *d_spectra, *spectra, *spectra_mac, *spectra_slight;

// GLOBAL variables to use for FFT calculation
fftw_complex * inSpectraFwPSF, *inSpectraBwPSF, *outSpectraFwPSF, *outSpectraBwPSF;
fftw_complex * inSpectraFwMAC, *inSpectraBwMAC, *outSpectraFwMAC, *outSpectraBwMAC;
fftw_plan planForwardPSF, planBackwardPSF;
fftw_plan planForwardMAC, planBackwardMAC;
fftw_complex * inFilterMAC, * inFilterMAC_DERIV, * outFilterMAC, * outFilterMAC_DERIV;
fftw_plan planFilterMAC, planFilterMAC_DERIV;

fftw_complex * fftw_G_PSF, * fftw_G_MAC_PSF, * fftw_G_MAC_DERIV_PSF;
fftw_complex * inPSF_MAC, * inMulMacPSF, * inPSF_MAC_DERIV, *inMulMacPSFDeriv, *outConvFilters, * outConvFiltersDeriv;
fftw_plan planForwardPSF_MAC, planForwardPSF_MAC_DERIV,planBackwardPSF_MAC, planBackwardPSF_MAC_DERIV;

//Convolutions values
int sizeG = 0;
PRECISION FWHM = 0;

ConfigControl configCrontrolFile;

// fvoigt memory consuption
 _Complex double *z,* zden, * zdiv;

gsl_vector *eval;
gsl_matrix *evec;
gsl_eigen_symmv_workspace * workspace;

int main(int argc, char **argv)
{
	int i; // for indexes
	PRECISION *wlines;
	int nlambda;
	Init_Model *vModels;
	float chisqrf, * vChisqrf;
	int * vNumIter; // to store the number of iterations used to converge for each pixel
	int indexLine, free_params; // index to identify central line to read it

	//*****
	Init_Model INITIAL_MODEL;
	PRECISION * deltaLambda, * PSF;
	PRECISION initialLambda, step, finalLambda;
	int N_SAMPLES_PSF;
	int posWL=0;
	//----------------------------------------------

	float * slight = NULL;
	int nl_straylight, ns_straylight, nx_straylight=0,ny_straylight=0;
	const char  * nameInputFileSpectra ;
	char nameOutputFilePerfiles [4096];
	const char	* nameInputFileLines;
	const char	* nameInputFilePSF ;
    FitsImage * fitsImage;
	PRECISION  dat[7];

	/********************* Read data input from file ******************************/

	/* Read data input from file */

	loadInitialValues(&configCrontrolFile);
	readTrolFile(argv[1],&configCrontrolFile,1);

	nameInputFileSpectra = configCrontrolFile.ObservedProfiles;
	nameInputFileLines = configCrontrolFile.AtomicParametersFile;

	nameInputFilePSF = configCrontrolFile.PSFFile;
	FWHM = configCrontrolFile.FWHM;

	/***************** READ INIT MODEL ********************************/
	if(configCrontrolFile.InitialGuessModel[0]!='\0' && !readInitialModel(&INITIAL_MODEL,configCrontrolFile.InitialGuessModel)){
		printf("\nERROR READING GUESS MODEL 1 FILE\n");
		exit(EXIT_FAILURE);
	}
	checkInitialModel(&INITIAL_MODEL);

	if(INITIAL_MODEL.alfa<1 && access(configCrontrolFile.StrayLightFile,F_OK)){
		printf("\nERROR. Filling factor in Initial model is less than 1 and Stray Light file  %s can not be accessed\n",configCrontrolFile.StrayLightFile);
		exit(EXIT_FAILURE);
	}

	if(configCrontrolFile.fix[10]==0) NTERMS--;
	if(INITIAL_MODEL.mac ==0 && configCrontrolFile.fix[9]==0){
		 NTERMS--;
	}

	// allocate memory for eigen values
	eval = gsl_vector_alloc (NTERMS);
  	evec = gsl_matrix_alloc (NTERMS, NTERMS);
	workspace = gsl_eigen_symmv_alloc (NTERMS);

	/***************** READ WAVELENGHT FROM GRID OR FITS ********************************/
	PRECISION * vLambda, *vOffsetsLambda;

	if(configCrontrolFile.useMallaGrid){ // read lambda from grid file
		printf("\n--------------------------------------------------------------------------------");
		printf("\nMALLA GRID FILE READ: %s",configCrontrolFile.MallaGrid);
		printf("\n--------------------------------------------------------------------------------");
		indexLine = readMallaGrid(configCrontrolFile.MallaGrid, &initialLambda, &step, &finalLambda, 1);
		printf("--------------------------------------------------------------------------------\n");
		nlambda = ((finalLambda-initialLambda)/step)+1;
		vOffsetsLambda = calloc(nlambda,sizeof(PRECISION));
		vOffsetsLambda[0] = initialLambda;
		for(i=1;i<nlambda;i++){
			vOffsetsLambda[i] = vOffsetsLambda[i-1]+step;
		}
		// pass to armstrong
		initialLambda = initialLambda/1000.0;
		step = step/1000.0;
		finalLambda = finalLambda/1000.0;
		vLambda = calloc(nlambda,sizeof(PRECISION));

		printf("Number of wavelengths in the wavelength grid: %d",nlambda);
		printf("\n--------------------------------------------------------------------------------\n");
		printf("\n--------------------------------------------------------------------------------");
		printf("\nATMOSPHERE LINES FILE READ: %s",nameInputFileLines);
		configCrontrolFile.CentralWaveLenght = readFileCuanticLines(nameInputFileLines,dat,indexLine,1);
		if(configCrontrolFile.CentralWaveLenght==0){
			printf("\n QUANTUM LINE NOT FOUND, REVIEW IT. INPUT CENTRAL WAVE LENGHT: %f",configCrontrolFile.CentralWaveLenght);
			exit(1);
		}
		vLambda[0]=configCrontrolFile.CentralWaveLenght+(initialLambda);
		for(i=1;i<nlambda;i++){
			vLambda[i]=vLambda[i-1]+step;
		}
		/******************* CREATE CUANTINC AND INITIALIZE DINAMYC MEMORY*******************/
		cuantic = create_cuantic(dat,1);

	}
	else{ // read lambda from fits file
		printf("\n--------------------------------------------------------------------------------");
		printf("\nWAVELENGTH FILE READ: %s",configCrontrolFile.WavelengthFile);
		vLambda = readFitsLambdaToArray(configCrontrolFile.WavelengthFile,&indexLine,&nlambda);
		if(vLambda==NULL){
			printf("\n FILE WITH WAVELENGHT HAS NOT BEEN READ PROPERLY, please check it.\n");
			free(vLambda);
			exit(EXIT_FAILURE);
		}
		printf("--------------------------------------------------------------------------------\n");
		printf("Number of wavelengths in the wavelength file: %d",nlambda);
		printf("\n--------------------------------------------------------------------------------\n");
		printf("\n--------------------------------------------------------------------------------");
		printf("\nATMOSPHERE LINES FILE READ: %s",nameInputFileLines);
		configCrontrolFile.CentralWaveLenght = readFileCuanticLines(nameInputFileLines,dat,indexLine,1);
		if(configCrontrolFile.CentralWaveLenght==0){
			printf("\n QUANTUM LINE NOT FOUND, REVIEW IT. INPUT CENTRAL WAVE LENGHT: %f",configCrontrolFile.CentralWaveLenght);
			exit(1);
		}
		/******************* CREATE CUANTINC AND INITIALIZE DINAMYC MEMORY*******************/
		cuantic = create_cuantic(dat,1);

	}

	/*********************************************** INITIALIZE VARIABLES  *********************************/
	REAL * vSigma = malloc((nlambda*NPARMS)*sizeof(REAL));
	for(i=0;i<nlambda*NPARMS;i++){
		vSigma[i] = configCrontrolFile.noise;
	}

	CC = PI / 180.0;
	CC_2 = CC * 2;

	wlines = (PRECISION *)calloc(2, sizeof(PRECISION));
	wlines[0] = 1;
	wlines[1] = configCrontrolFile.CentralWaveLenght;

	// count how many free param we have
	free_params=0;
	for(i=0;i<11;i++){
		if(configCrontrolFile.fix[i])
			free_params++;
	}

	/****************************************************************************************************/
	int numln=nlambda;
	// MACROTURBULENCE PLANS
	inFilterMAC = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
	outFilterMAC = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
	planFilterMAC = fftw_plan_dft_1d(numln, inFilterMAC, outFilterMAC, FFT_FORWARD, FFTW_MEASURE );
	inFilterMAC_DERIV = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
	outFilterMAC_DERIV = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
	planFilterMAC_DERIV = fftw_plan_dft_1d(numln, inFilterMAC_DERIV, outFilterMAC_DERIV, FFT_FORWARD, FFTW_MEASURE );

	inSpectraFwMAC = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
	outSpectraFwMAC = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
	planForwardMAC = fftw_plan_dft_1d(numln, inSpectraFwMAC, outSpectraFwMAC, FFT_FORWARD, FFTW_MEASURE );
	inSpectraBwMAC = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
	outSpectraBwMAC = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
	planBackwardMAC = fftw_plan_dft_1d(numln, inSpectraBwMAC, outSpectraBwMAC, FFT_BACKWARD, FFTW_MEASURE );

	// ********************************************* IF PSF HAS BEEN SELECTED IN TROL READ PSF FILE OR CREATE GAUSSIAN FILTER ***********//
	if(configCrontrolFile.ConvolveWithPSF){

		if(configCrontrolFile.FWHM > 0){
			G = fgauss_WL(FWHM,vLambda[1]-vLambda[0],vLambda[0],vLambda[nlambda/2],nlambda,&sizeG);
			//char nameAux [4096];
			//char obsAux [4096];
			//if(configCrontrolFile.ObservedProfiles[0]!='\0'){
			//	strcpy(obsAux,configCrontrolFile.ObservedProfiles);
			//	strcpy(nameAux,dirname(obsAux));
			//}
			//else{
			//	strcpy(obsAux,configCrontrolFile.InitialGuessModel);
			//	strcpy(nameAux,dirname(obsAux));
			//}
			//strcat(nameAux,"/gaussian.psf");
			//FILE *fptr = fopen(nameAux, "w");

			FILE *fptr = fopen("gaussian.psf", "w");

			if(fptr!=NULL){
			        printf("\n Gaussian PSF will be saved to file gaussian.psf");
				int kk;
				for (kk = 0; kk < nlambda; kk++)
				{
					fprintf(fptr,"\t%f\t%e\n", (vLambda[kk]-configCrontrolFile.CentralWaveLenght)*1000, G[kk]);
				}
				fclose(fptr);
			}
			else{
			  //	printf("\n ERROR !!! The output file cannot be opened: %s",nameAux);
				printf("\n ERROR !!! The output file cannot be opened: gaussian.psf");
			}
		}else{
			// read the number of lines
			FILE *fp;
			char ch;
			N_SAMPLES_PSF=0;
			//open file in read more
			fp=fopen(nameInputFilePSF,"r");
			if(fp==NULL)
			{
				printf("File \"%s\" does not exist!!!\n",nameInputFilePSF);
				return 0;
			}

			//read character by character and check for new line
			while((ch=fgetc(fp))!=EOF)
			{
				if(ch=='\n')
					N_SAMPLES_PSF++;
			}

			//close the file
			fclose(fp);
			if(N_SAMPLES_PSF>0){
				deltaLambda = calloc(N_SAMPLES_PSF,sizeof(PRECISION));
				PSF = calloc(N_SAMPLES_PSF,sizeof(PRECISION));
				readPSFFile(deltaLambda,PSF,nameInputFilePSF,configCrontrolFile.CentralWaveLenght);
				// CHECK if values of deltaLambda are in the same range of vLambda. For do that we truncate to 4 decimal places
				if( (trunc(vOffsetsLambda[0])) < (trunc(deltaLambda[0]))  || (trunc(vOffsetsLambda[nlambda-1])) > (trunc(deltaLambda[N_SAMPLES_PSF-1])) ){
					printf("\n\n ERROR: The wavelength range given in the PSF file is smaller than the range in the mesh file [%lf,%lf] [%lf,%lf]  \n\n",deltaLambda[0],vOffsetsLambda[0],deltaLambda[N_SAMPLES_PSF-1],vOffsetsLambda[nlambda-1]);
					exit(EXIT_FAILURE);
				}
				G = malloc(nlambda * sizeof(PRECISION));

				double offset=0;
				for(i=0;i<nlambda && !posWL;i++){
					if( fabs(trunc(vOffsetsLambda[i]))==0)
						posWL = i;
				}
				if(posWL!= (nlambda/2) ){ // move center to the middle of samples
					offset = ((  ((nlambda)/2) - posWL)*step)*1000;
				}

				interpolationLinearPSF(deltaLambda,  PSF, vOffsetsLambda ,N_SAMPLES_PSF, G, nlambda,offset);

				sizeG = nlambda;
			}
			else{
				printf("\n****************** ERROR THE PSF FILE is empty or damaged.******************\n");
				exit(EXIT_FAILURE);
			}
			printf("\n--------------------------------------------------------------------------------");
			printf("\nPSF FILE READ: %s", nameInputFilePSF);
			printf("\n--------------------------------------------------------------------------------\n");
		}

		//PSF FILTER PLANS
		inSpectraFwPSF = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
		outSpectraFwPSF = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
		planForwardPSF = fftw_plan_dft_1d(numln, inSpectraFwPSF, outSpectraFwPSF, FFT_FORWARD, FFTW_MEASURE );
		inSpectraBwPSF = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
		outSpectraBwPSF = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
		planBackwardPSF = fftw_plan_dft_1d(numln, inSpectraBwPSF, outSpectraBwPSF, FFT_BACKWARD, FFTW_MEASURE );

		fftw_complex * in = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * numln);
		int i;
		for (i = 0; i < numln; i++)
		{
			in[i] = G[i] + 0 * _Complex_I;
		}
		fftw_G_PSF = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * numln);
		fftw_plan p = fftw_plan_dft_1d(numln, in, fftw_G_PSF, FFT_FORWARD, FFTW_MEASURE );
		fftw_execute(p);
		for (i = 0; i < numln; i++)
		{
			fftw_G_PSF[i] = fftw_G_PSF[i] / numln;
		}
		fftw_destroy_plan(p);
		fftw_free(in);

		inPSF_MAC = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
		fftw_G_MAC_PSF = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
		planForwardPSF_MAC = fftw_plan_dft_1d(numln, inPSF_MAC, fftw_G_MAC_PSF, FFT_FORWARD, FFTW_MEASURE );
		inMulMacPSF = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
		outConvFilters = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
		planBackwardPSF_MAC = fftw_plan_dft_1d(numln, inMulMacPSF, outConvFilters, FFT_BACKWARD, FFTW_MEASURE );

		inPSF_MAC_DERIV = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
		fftw_G_MAC_DERIV_PSF = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
		planForwardPSF_MAC_DERIV = fftw_plan_dft_1d(numln, inPSF_MAC_DERIV, fftw_G_MAC_DERIV_PSF, FFT_FORWARD, FFTW_MEASURE );
		inMulMacPSFDeriv = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
		outConvFiltersDeriv = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * numln);
		planBackwardPSF_MAC_DERIV = fftw_plan_dft_1d(numln, inMulMacPSFDeriv, outConvFiltersDeriv, FFT_BACKWARD, FFTW_MEASURE );

	}
	/****************************************************************************************************/
	//  IF NUMBER OF CYCLES IS LES THAN 0 THEN --> WE USE CLASSICAL ESTIMATES
	//  IF NUMBER OF CYCLES IS 0 THEN -->  DO SYNTHESIS FROM THE INIT MODEL
	//  IF NUMBER OF CYCLES IS GREATER THAN 0 --> READ FITS FILE OR PER FILE AND PROCESS DO INVERSION WITH N CYCLES

	if(configCrontrolFile.NumberOfCycles<0){
		// read fits or per

		AllocateMemoryDerivedSynthesis(nlambda);
		if(strcmp(file_ext(configCrontrolFile.ObservedProfiles),PER_FILE)==0){ // invert only per file
			float * spectroPER = calloc(nlambda*NPARMS,sizeof(float));
			FILE * fReadSpectro;
			char * line = NULL;
			size_t len = 0;
			ssize_t read;
			fReadSpectro = fopen(configCrontrolFile.ObservedProfiles, "r");

			int contLine=0;
			if (fReadSpectro == NULL)
			{
				printf("Error opening the file of parameters, it's possible that the file doesn't exist. Please verify it. \n");
				printf("\n ******* THIS IS THE NAME OF THE FILE RECEVIED : %s \n", configCrontrolFile.ObservedProfiles);
				fclose(fReadSpectro);
				exit(EXIT_FAILURE);
			}
			float aux1, aux2,aux3,aux4,aux5,aux6;
			while ((read = getline(&line, &len, fReadSpectro)) != -1 && contLine<nlambda) {
				sscanf(line,"%e %e %e %e %e %e",&aux1,&aux2,&aux3,&aux4,&aux5,&aux6);
				spectroPER[contLine] = aux3;
				spectroPER[contLine + nlambda] = aux4;
				spectroPER[contLine + nlambda * 2] = aux5;
				spectroPER[contLine + nlambda * 3] = aux6;
				contLine++;
			}
			fclose(fReadSpectro);
			printf("\n--------------------------------------------------------------------------------");
			printf("\nOBSERVED PROFILES FILE READ: %s ", configCrontrolFile.ObservedProfiles);
			printf("\n--------------------------------------------------------------------------------\n");
			Init_Model initModel;
			initModel.eta0 = 0;
			initModel.mac = 0;
			initModel.dopp = 0;
			initModel.aa = 0;
			initModel.alfa = 0; //0.38; //stray light factor
			initModel.S1 = 0;
			//invert with classical estimates
			estimacionesClasicas(wlines[1], vLambda, nlambda, spectroPER, &initModel,0);
			// save model to file
			char nameAuxOutputModel [4096];
			if(configCrontrolFile.ObservedProfiles[0]!='\0')
				strcpy(nameAuxOutputModel,get_basefilename(configCrontrolFile.ObservedProfiles));
			else
				strcpy(nameAuxOutputModel,get_basefilename(configCrontrolFile.InitialGuessModel));

			strcat(nameAuxOutputModel,"_model_ce");
			strcat(nameAuxOutputModel,MOD_FILE);
			FILE * fptr = fopen(nameAuxOutputModel, "w");
			if(fptr!=NULL){
				fprintf(fptr,"eta_0               :%lf\n",initModel.eta0);
				fprintf(fptr,"magnetic field [G]  :%lf\n",initModel.B);
				fprintf(fptr,"LOS velocity[km/s]  :%lf\n",initModel.vlos);
				fprintf(fptr,"Doppler width [A]   :%lf\n",initModel.dopp);
				fprintf(fptr,"damping             :%lf\n",initModel.aa);
				fprintf(fptr,"gamma [deg]         :%lf\n",initModel.gm);
				fprintf(fptr,"phi  [deg]          :%lf\n",initModel.az);
				fprintf(fptr,"S_0                 :%lf\n",initModel.S0);
				fprintf(fptr,"S_1                 :%lf\n",initModel.S1);
				fprintf(fptr,"v_mac               :%lf\n",initModel.mac);
				fprintf(fptr,"filling factor      :%lf\n",initModel.alfa);
				fprintf(fptr,"# Iterations        :%d\n",0);
				fprintf(fptr,"chisqr              :%le\n",0.0);
				fprintf(fptr,"\n\n");
				fclose(fptr);
			}
			else{
				printf("\n ¡¡¡¡¡ ERROR: OUTPUT MODEL FILE CAN NOT BE OPENED: %s \n !!!!!",nameAuxOutputModel);
			}
			free(spectroPER);
		}
		else if(strcmp(file_ext(configCrontrolFile.ObservedProfiles),FITS_FILE)==0){ // invert image from fits file
			fitsImage = readFitsSpectroImage(configCrontrolFile.ObservedProfiles,0,nlambda);
			printf("\n--------------------------------------------------------------------------------");
			printf("\nOBSERVED PROFILES FILE READ: %s", configCrontrolFile.ObservedProfiles);
			printf("\n--------------------------------------------------------------------------------\n");
			// ALLOCATE MEMORY FOR STORE THE RESULTS
			int indexPixel = 0;
			vModels = calloc (fitsImage->numPixels , sizeof(Init_Model));
			vChisqrf = calloc (fitsImage->numPixels , sizeof(float));
			vNumIter = calloc (fitsImage->numPixels , sizeof(int));
			for(indexPixel = 0; indexPixel < fitsImage->numPixels; indexPixel++){

				//Initial Model
				Init_Model initModel;
				initModel.eta0 = INITIAL_MODEL.eta0;
				initModel.B = INITIAL_MODEL.B; //200 700
				initModel.gm = INITIAL_MODEL.gm;
				initModel.az = INITIAL_MODEL.az;
				initModel.vlos = INITIAL_MODEL.vlos; //km/s 0
				initModel.mac = INITIAL_MODEL.mac;
				initModel.dopp = INITIAL_MODEL.dopp;
				initModel.aa = INITIAL_MODEL.aa;
				initModel.alfa = INITIAL_MODEL.alfa; //0.38; //stray light factor
				initModel.S0 = INITIAL_MODEL.S0;
				initModel.S1 = INITIAL_MODEL.S1;
				estimacionesClasicas(wlines[1],vLambda, nlambda, fitsImage->pixels[indexPixel].spectro, &initModel,0);
				vModels[indexPixel] = initModel;

			}
			char nameAuxOutputModel [4096];
			if(configCrontrolFile.ObservedProfiles[0]!='\0')
				strcpy(nameAuxOutputModel,get_basefilename(configCrontrolFile.ObservedProfiles));
			else
				strcpy(nameAuxOutputModel,get_basefilename(configCrontrolFile.InitialGuessModel));
			strcat(nameAuxOutputModel,"_model_ce");
			strcat(nameAuxOutputModel,FITS_FILE);
			if(!writeFitsImageModels(nameAuxOutputModel,fitsImage->rows,fitsImage->cols,vModels,vChisqrf,vNumIter,configCrontrolFile.saveChisqr)){
					printf("\n ERROR WRITING FILE OF MODELS: %s",nameAuxOutputModel);
			}
			free(vModels);
			free(vChisqrf);
			free(vNumIter);
		}
		else{
			printf("\n OBSERVED PROFILES DOESN'T HAVE CORRECT EXTENSION  .PER or .FITS ");
			exit(EXIT_FAILURE);
		}
	}
	else if(configCrontrolFile.NumberOfCycles==0){ // synthesis

		if(access(configCrontrolFile.StrayLightFile,F_OK)!=-1){ //  IF NOT EMPTY READ stray light file
			if(strcmp(file_ext(configCrontrolFile.StrayLightFile),PER_FILE)==0){
				slight = readPerStrayLightFile(configCrontrolFile.StrayLightFile,nlambda,vOffsetsLambda);
				printf("\n--------------------------------------------------------------------------------");
				printf("\nSTRAY LIGHT FILE READ: %s ", configCrontrolFile.StrayLightFile);
				printf("\n--------------------------------------------------------------------------------\n");
			}
			else if(strcmp(file_ext(configCrontrolFile.StrayLightFile),FITS_FILE)==0){
				slight= readFitsStrayLightFile(&configCrontrolFile,&nl_straylight,&ns_straylight,&nx_straylight, &ny_straylight);
				if(nx_straylight!=0 || ny_straylight!=0){
					printf("\n Stray light file has 4 dimensions and for Synthesis only 2 dimensiones file is accepted, henceforth, stray light will not used for synthesis. \n");
					free(slight);
					slight= NULL;
				}
				if(nl_straylight!=nlambda){
					printf("\n The number of wavelengths is different in the stray light file: %d and malla grid file %d. \n. Stray light will not used for synthesis.", nl_straylight,nlambda);
					free(slight);
					slight= NULL;
				}
				printf("\n--------------------------------------------------------------------------------");
				printf("\nSTRAY LIGHT FILE READ: %s ", configCrontrolFile.StrayLightFile);
				printf("\n--------------------------------------------------------------------------------\n");
			}
			else{
				printf("\n Stray light file hasn't extension .PER or .FITS, review it. \n. Stray light will not used for synthesis.\n");
				free(slight);
				slight= NULL;
			}
		}

		Init_Model initModel;
		initModel.eta0 = INITIAL_MODEL.eta0;
		initModel.B = INITIAL_MODEL.B; //200 700
		initModel.gm = INITIAL_MODEL.gm;
		initModel.az = INITIAL_MODEL.az;
		initModel.vlos = INITIAL_MODEL.vlos; //km/s 0
		initModel.mac = INITIAL_MODEL.mac;
		initModel.dopp = INITIAL_MODEL.dopp;
		initModel.aa = INITIAL_MODEL.aa;
		initModel.alfa = INITIAL_MODEL.alfa; //0.38; //stray light factor
		initModel.S0 = INITIAL_MODEL.S0;
		initModel.S1 = INITIAL_MODEL.S1;
		printf("\n--------------------------------------------------------------------------------");
		printf("\nATMOSPHERE MODEL FILE READ: %s ",configCrontrolFile.InitialGuessModel);
		printf("\n--------------------------------------------------------------------------------");
		printf("\nINITAL MODEL ATMOSPHERE: \n\n");
		printf("eta_0               :%lf\n",initModel.eta0);
		printf("magnetic field [G]  :%lf\n",initModel.B);
		printf("LOS velocity[km/s]  :%lf\n",initModel.vlos);
		printf("Doppler width [A]   :%lf\n",initModel.dopp);
		printf("damping             :%lf\n",initModel.aa);
		printf("gamma [deg]         :%lf\n",initModel.gm);
		printf("phi   [deg]         :%lf\n",initModel.az);
		printf("S_0                 :%lf\n",initModel.S0);
		printf("S_1                 :%lf\n",initModel.S1);
		printf("v_mac [km/s]        :%lf\n",initModel.mac);
		printf("filling factor      :%lf\n",initModel.alfa);
		printf("--------------------------------------------------------------------------------\n");

		AllocateMemoryDerivedSynthesis(nlambda);

		if(configCrontrolFile.ConvolveWithPSF && initModel.mac>0){
			printf("\n--------------------------------------------------------------------------------");
			printf("\nThe program needs to use convolution. Filter PSF activated and macroturbulence greater than zero. ");
			printf("\n--------------------------------------------------------------------------------\n");
		}
		else if(configCrontrolFile.ConvolveWithPSF){
			printf("\n--------------------------------------------------------------------------------");
			printf("\nThe program needs to use convolution. Filter PSF activated. ");
			printf("\n--------------------------------------------------------------------------------\n");
		}
		else if(initModel.mac>0){
			printf("\n--------------------------------------------------------------------------------");
			printf("\nThe program needs to use convolution. Macroturbulence in initial atmosphere model greater than zero.");
			printf("\n--------------------------------------------------------------------------------\n");
		}
		// synthesis
		mil_sinrf(cuantic, &initModel, wlines, vLambda, nlambda, spectra, configCrontrolFile.mu, slight,spectra_mac,spectra_slight, configCrontrolFile.ConvolveWithPSF);
		me_der(cuantic, &initModel, wlines, vLambda, nlambda, d_spectra, spectra_mac, spectra_slight, configCrontrolFile.mu, slight, configCrontrolFile.ConvolveWithPSF,configCrontrolFile.fix);

		// in this case basenamefile is from initmodel
		char nameAux [4096];

		if(configCrontrolFile.ObservedProfiles[0]!='\0')
			strcpy(nameAux,get_basefilename(configCrontrolFile.ObservedProfiles));
		else
			strcpy(nameAux,get_basefilename(configCrontrolFile.InitialGuessModel));
		strcat(nameAux,PER_FILE);
		FILE *fptr = fopen(nameAux, "w");
		if(fptr!=NULL){
			int kk;
			for (kk = 0; kk < nlambda; kk++)
			{
				fprintf(fptr,"%d\t%f\t%e\t%e\t%e\t%e\n", indexLine, (vLambda[kk]-configCrontrolFile.CentralWaveLenght)*1000, spectra[kk], spectra[kk + nlambda], spectra[kk + nlambda * 2], spectra[kk + nlambda * 3]);
			}
			fclose(fptr);
			printf("\n--------------------------------------------------------------------------------");
			printf("\n------------------SYNTHESIS DONE: %s",nameAux);
			printf("\n--------------------------------------------------------------------------------\n");
		}
		else{
			printf("\n ERROR !!! The output file can not be open: %s",nameAux);
		}

		/*int number_parametros = 0;
		for (number_parametros = 0; number_parametros < NTERMS; number_parametros++)
		{
			strcpy(nameAux,get_basefilename(configCrontrolFile.InitialGuessModel));
			strcat(nameAux,"_C_");
			char extension[10];
			sprintf(extension, "%d%s", number_parametros,".per");
			strcat(nameAux,extension);
			FILE *fptr = fopen(nameAux, "w");
			//printf("\n FUNCION RESPUESTA: %d \n",number_parametros);
			int kk;
			for (kk = 0; kk < nlambda; kk++)
			{
			fprintf(fptr,"1\t%lf\t%le\t%le\t%le\t%le\n", vLambda[kk],
			d_spectra[kk + nlambda * number_parametros],
			d_spectra[kk + nlambda * number_parametros + nlambda * NTERMS],
			d_spectra[kk + nlambda * number_parametros + nlambda * NTERMS * 2],
			d_spectra[kk + nlambda * number_parametros + nlambda * NTERMS * 3]);
			}
			fclose(fptr);
		}
		printf("\n");*/

	}
	else{ // INVERT PIXEL FROM PER FILE OR IMAGE FROM FITS FILE

		if(strcmp(file_ext(configCrontrolFile.ObservedProfiles),PER_FILE)==0){ // invert only per file
			float * spectroPER = calloc(nlambda*NPARMS,sizeof(float));
			FILE * fReadSpectro;
			char * line = NULL;
			size_t len = 0;
			ssize_t read;
			fReadSpectro = fopen(configCrontrolFile.ObservedProfiles, "r");

			int contLine=0;
			if (fReadSpectro == NULL)
			{
				printf("Error opening the file of parameters, it's possible that the file doesn't exist. Please verify it. \n");
				printf("\n ******* THIS IS THE NAME OF THE FILE RECEVIED : %s \n", configCrontrolFile.ObservedProfiles);
				fclose(fReadSpectro);
				exit(EXIT_FAILURE);
			}

			float aux1, aux2, aux3, aux4, aux5, aux6;
			while ((read = getline(&line, &len, fReadSpectro)) != -1) {
				sscanf(line,"%e %e %e %e %e %e",&aux1,&aux2,&aux3,&aux4,&aux5,&aux6);
				if(contLine<nlambda){
					spectroPER[contLine] = aux3;
					spectroPER[contLine + nlambda] = aux4;
					spectroPER[contLine + nlambda * 2] = aux5;
					spectroPER[contLine + nlambda * 3] = aux6;
				}
				contLine++;
			}
			fclose(fReadSpectro);
			printf("\n--------------------------------------------------------------------------------");
			printf("\nOBSERVED PROFILES FILE READ: %s ", configCrontrolFile.ObservedProfiles);
			printf("\n--------------------------------------------------------------------------------");
			printf("\nNumber of wavelengths in the observed profiles: %d",contLine);
			printf("\n--------------------------------------------------------------------------------\n");
			if(nlambda!=contLine){
				printf("\n--------------------------------------------------------------------------------\n");
				printf("\nERROR: The number of wavelenghts in observed profiles file  %d is different to number of wavelengths in malla grid %d\n",contLine,nlambda);
				exit(EXIT_FAILURE);
			}
			if(configCrontrolFile.fix[10] &&  access(configCrontrolFile.StrayLightFile,F_OK)!=-1){ //  IF NOT EMPTY READ stray light file
				if(strcmp(file_ext(configCrontrolFile.StrayLightFile),PER_FILE)==0){
					slight = readPerStrayLightFile(configCrontrolFile.StrayLightFile,nlambda,vOffsetsLambda);
					printf("\n--------------------------------------------------------------------------------");
					printf("\nSTRAY LIGHT FILE READ: %s ", configCrontrolFile.StrayLightFile);
					printf("\n--------------------------------------------------------------------------------\n");
				}
				else if(strcmp(file_ext(configCrontrolFile.StrayLightFile),FITS_FILE)==0){
					slight= readFitsStrayLightFile(&configCrontrolFile,&nl_straylight,&ns_straylight,&nx_straylight, &ny_straylight);
					if(nx_straylight!=0 || ny_straylight!=0){
						printf("\n Stray light file has 4 dimensions and for Inversion pixel only 2 dimensiones file is accepted, henceforth, stray light will not used for inversion pixel. \n");
						free(slight);
						slight= NULL;
					}
					if(nl_straylight!=nlambda){
						printf("\n The number of wavelengths is different in the stray light file: %d and malla grid file %d. \n. Stray light will not used for inversion pixel.", nl_straylight,nlambda);
						free(slight);
						slight= NULL;
					}
					printf("\n--------------------------------------------------------------------------------");
					printf("\nSTRAY LIGHT FILE READ: %s ", configCrontrolFile.StrayLightFile);
					printf("\n--------------------------------------------------------------------------------\n");
				}
				else{
					printf("\n Stray light file hasn't extension .PER or .FITS, review it. \n. Stray light will not used for inversion pixel.\n");
					free(slight);
					slight= NULL;
				}
			}

			AllocateMemoryDerivedSynthesis(nlambda);
			Init_Model initModel;
			initModel.eta0 = INITIAL_MODEL.eta0;
			initModel.B = INITIAL_MODEL.B; //200 700
			initModel.gm = INITIAL_MODEL.gm;
			initModel.az = INITIAL_MODEL.az;
			initModel.vlos = INITIAL_MODEL.vlos; //km/s 0
			initModel.mac = INITIAL_MODEL.mac;
			initModel.dopp = INITIAL_MODEL.dopp;
			initModel.aa = INITIAL_MODEL.aa;
			initModel.alfa = INITIAL_MODEL.alfa; //0.38; //stray light factor
			initModel.S0 = INITIAL_MODEL.S0;
			initModel.S1 = INITIAL_MODEL.S1;
			printf("\n--------------------------------------------------------------------------------");
			printf("\nATMOSPHERE MODEL FILE READ: %s ",configCrontrolFile.InitialGuessModel);
			printf("\n--------------------------------------------------------------------------------");
			printf("\nINITAL MODEL ATMOSPHERE: \n\n");
			printf("eta_0               :%lf\n",initModel.eta0);
			printf("magnetic field [G]  :%lf\n",initModel.B);
			printf("LOS velocity[km/s]  :%lf\n",initModel.vlos);
			printf("Doppler width [A]   :%lf\n",initModel.dopp);
			printf("damping             :%lf\n",initModel.aa);
			printf("gamma [deg]         :%lf\n",initModel.gm);
			printf("phi   [deg]         :%lf\n",initModel.az);
			printf("S_0                 :%lf\n",initModel.S0);
			printf("S_1                 :%lf\n",initModel.S1);
			printf("v_mac [km/s]        :%lf\n",initModel.mac);
			printf("filling factor      :%lf\n",initModel.alfa);
			printf("--------------------------------------------------------------------------------\n");

			if(configCrontrolFile.ConvolveWithPSF && initModel.mac>0){
				printf("\n--------------------------------------------------------------------------------");
				printf("\nThe program needs to use convolution. Filter PSF activated and macroturbulence greater than zero. ");
				printf("\n--------------------------------------------------------------------------------\n");
			}
			else if(configCrontrolFile.ConvolveWithPSF){
				printf("\n--------------------------------------------------------------------------------");
				printf("\nThe program needs to use convolution. Filter PSF activated. ");
				printf("\n--------------------------------------------------------------------------------\n");
			}
			else if(initModel.mac>0){
				printf("\n--------------------------------------------------------------------------------");
				printf("\nThe program needs to use convolution. Macroturbulence in initial atmosphere model greater than zero.");
				printf("\n--------------------------------------------------------------------------------\n");
			}
      		int numIter =0;
			printf("\n--------------------------------------------------------------------------------");
			printf("\nNumber of free parameters for inversion: %d", free_params);
			printf("\n--------------------------------------------------------------------------------\n");
      		lm_mils(cuantic, wlines, vLambda, nlambda, spectroPER, nlambda, &initModel, spectra, &chisqrf, slight, configCrontrolFile.toplim, configCrontrolFile.NumberOfCycles,
               configCrontrolFile.WeightForStokes, configCrontrolFile.fix, vSigma, configCrontrolFile.noise, configCrontrolFile.InitialDiagonalElement,&configCrontrolFile.ConvolveWithPSF,&numIter,configCrontrolFile.mu, configCrontrolFile.logclambda);

			// SAVE OUTPUT MODEL
			char nameAuxOutputModel [4096];

			if(configCrontrolFile.ObservedProfiles[0]!='\0')
				strcpy(nameAuxOutputModel,get_basefilename(configCrontrolFile.ObservedProfiles));
			else
				strcpy(nameAuxOutputModel,get_basefilename(configCrontrolFile.InitialGuessModel));

			strcat(nameAuxOutputModel,"_model");
			strcat(nameAuxOutputModel,MOD_FILE);

			FILE *fptr = fopen(nameAuxOutputModel, "w");
			if(fptr!=NULL){
				fprintf(fptr,"eta_0               :%lf\n",initModel.eta0);
				fprintf(fptr,"magnetic field [G]  :%lf\n",initModel.B);
				fprintf(fptr,"LOS velocity[km/s]  :%lf\n",initModel.vlos);
				fprintf(fptr,"Doppler width [A]   :%lf\n",initModel.dopp);
				fprintf(fptr,"damping             :%lf\n",initModel.aa);
				fprintf(fptr,"gamma [deg]         :%lf\n",initModel.gm);
				fprintf(fptr,"phi   [deg]         :%lf\n",initModel.az);
				fprintf(fptr,"S_0                 :%lf\n",initModel.S0);
				fprintf(fptr,"S_1                 :%lf\n",initModel.S1);
				fprintf(fptr,"v_mac [km/s]        :%lf\n",initModel.mac);
				fprintf(fptr,"filling factor      :%lf\n",initModel.alfa);
				fprintf(fptr,"# Iterations        :%d\n",numIter);
				fprintf(fptr,"chisqr              :%le\n",chisqrf);
				fprintf(fptr,"\n\n");
				fclose(fptr);
				printf("\n\n--------------------------------------------------------------------------------");
				printf("\nINVERTED MODEL SAVED IN FILE: %s",nameAuxOutputModel);
				printf("\n--------------------------------------------------------------------------------\n");
			}
			else{
				printf("\n ¡¡¡¡¡ ERROR: OUTPUT MODEL FILE CAN NOT BE OPENED\n !!!!! ");
			}

			// SAVE OUTPUT ADJUST SYNTHESIS PROFILES
			if(configCrontrolFile.SaveSynthesisAdjusted){
				char nameAuxOutputStokes [4096];
				if(configCrontrolFile.ObservedProfiles[0]!='\0')
					strcpy(nameAuxOutputStokes,get_basefilename(configCrontrolFile.ObservedProfiles));
				else
					strcpy(nameAuxOutputStokes,get_basefilename(configCrontrolFile.InitialGuessModel));
				strcat(nameAuxOutputStokes,STOKES_PER_EXT);
				FILE *fptr = fopen(nameAuxOutputStokes, "w");
				if(fptr!=NULL){
			      //printf("\n valores de spectro sintetizado\n");
					int kk;
					for (kk = 0; kk < nlambda; kk++)
					{
						fprintf(fptr,"%d\t%f\t%e\t%e\t%e\t%e\n", indexLine, (vLambda[kk]-configCrontrolFile.CentralWaveLenght)*1000, spectra[kk], spectra[kk + nlambda], spectra[kk + nlambda * 2], spectra[kk + nlambda * 3]);
					}
					//printf("\nVALORES DE LAS FUNCIONES RESPUESTA \n");
					fclose(fptr);
					printf("\n--------------------------------------------------------------------------------");
					printf("\nOutput profiles: %s",nameAuxOutputStokes);
					printf("\n--------------------------------------------------------------------------------\n");
				}
				else{
					printf("\n ¡¡¡¡¡ ERROR: OUTPUT SYNTHESIS PROFILE ADJUSTED FILE CAN NOT BE OPENED\n !!!!! ");
				}
			}
			free(spectroPER);
		}
		else if(strcmp(file_ext(configCrontrolFile.ObservedProfiles),FITS_FILE)==0){ // invert image from fits file

			// check if read stray light
			if(configCrontrolFile.fix[10] && access(configCrontrolFile.StrayLightFile,F_OK)!=-1){ //  IF NOT EMPTY READ stray light file
				if(strcmp(file_ext(configCrontrolFile.StrayLightFile),PER_FILE)==0){
					slight = readPerStrayLightFile(configCrontrolFile.StrayLightFile,nlambda,vOffsetsLambda);
					printf("\n--------------------------------------------------------------------------------");
					printf("\nSTRAY LIGHT FILE READ: %s ", configCrontrolFile.StrayLightFile);
					printf("\n--------------------------------------------------------------------------------\n");
				}
				else if(strcmp(file_ext(configCrontrolFile.StrayLightFile),FITS_FILE)==0){
					slight = readFitsStrayLightFile(&configCrontrolFile,&nl_straylight,&ns_straylight,&nx_straylight, &ny_straylight);
					if(nl_straylight!=nlambda){
						printf("\n The number of wavelengths is different in the stray light file: %d and malla grid file %d. \n. Stray light will not used for inversion.", nl_straylight,nlambda);
						free(slight);
						slight= NULL;
						exit(EXIT_FAILURE);
					}
					printf("\n--------------------------------------------------------------------------------");
					printf("\nSTRAY LIGHT FILE READ: %s", configCrontrolFile.StrayLightFile);
					printf("\n--------------------------------------------------------------------------------\n");
				}
				else{
					printf("\n Stray light file hasn't extension .PER or .FITS, review it. \n. Stray light will not used for inversion.\n");
					free(slight);
					slight= NULL;
					exit(EXIT_FAILURE);
				}
			}
			// READ PIXELS FROM IMAGE
			PRECISION timeReadImage;
			clock_t t;
			t = clock();
			fitsImage = readFitsSpectroImage(nameInputFileSpectra,0,nlambda);
			t = clock() - t;
			timeReadImage = ((PRECISION)t)/CLOCKS_PER_SEC; // in seconds
			printf("\n--------------------------------------------------------------------------------");
			printf("\nOBSERVED PROFILES FILE READ: %s", nameInputFileSpectra);
			printf("\n--------------------------------------------------------------------------------");
			printf("\nTIME TO READ FITS IMAGE:  %f seconds to execute ", timeReadImage);
			printf("\n--------------------------------------------------------------------------------\n");

			if(fitsImage!=NULL){
				FitsImage * imageStokesAdjust = NULL;
				if(configCrontrolFile.SaveSynthesisAdjusted){
					imageStokesAdjust = malloc(sizeof(FitsImage));
					imageStokesAdjust->rows = fitsImage->rows;
					imageStokesAdjust->cols = fitsImage->cols;
					imageStokesAdjust->nLambdas = fitsImage->nLambdas;
					imageStokesAdjust->numStokes = fitsImage->numStokes;
					imageStokesAdjust->pos_col = fitsImage->pos_col;
					imageStokesAdjust->pos_row = fitsImage->pos_row;
					imageStokesAdjust->pos_lambda = fitsImage->pos_lambda;
					imageStokesAdjust->pos_stokes_parameters = fitsImage->pos_stokes_parameters;
					imageStokesAdjust->numPixels = fitsImage->numPixels;
					imageStokesAdjust->pixels = calloc(imageStokesAdjust->numPixels, sizeof(vpixels));
					imageStokesAdjust->naxes = fitsImage->naxes;
					imageStokesAdjust->vCard = fitsImage->vCard;
					imageStokesAdjust->vKeyname = fitsImage->vKeyname;
					imageStokesAdjust->nkeys = fitsImage->nkeys;
					imageStokesAdjust->naxis = fitsImage->naxis;
					imageStokesAdjust->bitpix = fitsImage->bitpix;
					for( i=0;i<imageStokesAdjust->numPixels;i++){
						imageStokesAdjust->pixels[i].spectro = calloc ((imageStokesAdjust->numStokes*imageStokesAdjust->nLambdas),sizeof(float));
					}
				}
				printf("\n--------------------------------------------------------------------------------");
				printf("\nATMOSPHERE MODEL FILE READ: %s ",configCrontrolFile.InitialGuessModel);
				printf("\n--------------------------------------------------------------------------------");
				printf("\nINITAL MODEL ATMOSPHERE: \n\n");
				printf("eta_0               :%lf\n",INITIAL_MODEL.eta0);
				printf("magnetic field [G]  :%lf\n",INITIAL_MODEL.B);
				printf("LOS velocity[km/s]  :%lf\n",INITIAL_MODEL.vlos);
				printf("Doppler width [A]   :%lf\n",INITIAL_MODEL.dopp);
				printf("damping             :%lf\n",INITIAL_MODEL.aa);
				printf("gamma [deg]         :%lf\n",INITIAL_MODEL.gm);
				printf("phi   [deg]         :%lf\n",INITIAL_MODEL.az);
				printf("S_0                 :%lf\n",INITIAL_MODEL.S0);
				printf("S_1                 :%lf\n",INITIAL_MODEL.S1);
				printf("v_mac [km/s]        :%lf\n",INITIAL_MODEL.mac);
				printf("filling factor      :%lf\n",INITIAL_MODEL.alfa);
				printf("--------------------------------------------------------------------------------\n");

				if(configCrontrolFile.ConvolveWithPSF && INITIAL_MODEL.mac>0){
					printf("\n--------------------------------------------------------------------------------");
					printf("\nThe program needs to use convolution. Filter PSF activated and macroturbulence greater than zero. ");
					printf("\n--------------------------------------------------------------------------------\n");
				}
				else if(configCrontrolFile.ConvolveWithPSF){
					printf("\n--------------------------------------------------------------------------------");
					printf("\nThe program needs to use convolution. Filter PSF activated. ");
					printf("\n--------------------------------------------------------------------------------\n");
				}
				else if(INITIAL_MODEL.mac>0){
					printf("\n--------------------------------------------------------------------------------");
					printf("\nThe program needs to use convolution. Macroturbulence in initial atmosphere model greater than zero.");
					printf("\n--------------------------------------------------------------------------------\n");
				}
				printf("\n--------------------------------------------------------------------------------");
				printf("\nNumber of free parameters for inversion: %d", free_params);
				printf("\n--------------------------------------------------------------------------------\n");
				//***************************************** INIT MEMORY WITH SIZE OF LAMBDA ****************************************************//
				AllocateMemoryDerivedSynthesis(nlambda);
				int indexPixel = 0;

				// ALLOCATE MEMORY FOR STORE THE RESULTS

				vModels = calloc (fitsImage->numPixels , sizeof(Init_Model));
				vChisqrf = calloc (fitsImage->numPixels , sizeof(float));
				vNumIter = calloc (fitsImage->numPixels , sizeof(int));
				t = clock();
				printf("\n--------------------------------------------------------------------------------");
				printf("\n----------------------- IMAGE INVERSION IN PROGRESS ----------------------------");
				printf("\n--------------------------------------------------------------------------------\n");

				for(indexPixel = 0; indexPixel < fitsImage->numPixels; indexPixel++){

					//Initial Model
					Init_Model initModel;
					initModel.eta0 = INITIAL_MODEL.eta0;
					initModel.B = INITIAL_MODEL.B; //200 700
					initModel.gm = INITIAL_MODEL.gm;
					initModel.az = INITIAL_MODEL.az;
					initModel.vlos = INITIAL_MODEL.vlos; //km/s 0
					initModel.mac = INITIAL_MODEL.mac;
					initModel.dopp = INITIAL_MODEL.dopp;
					initModel.aa = INITIAL_MODEL.aa;
					initModel.alfa = INITIAL_MODEL.alfa; //0.38; //stray light factor
					initModel.S0 = INITIAL_MODEL.S0;
					initModel.S1 = INITIAL_MODEL.S1;

					// CLASSICAL ESTIMATES TO GET B, GAMMA
					estimacionesClasicas(wlines[1], vLambda, nlambda, fitsImage->pixels[indexPixel].spectro, &initModel,1);
					if (isnan(initModel.B))
						initModel.B = 1;
					if (isnan(initModel.vlos))
						initModel.vlos = 1e-3;
					if (isnan(initModel.gm))
						initModel.gm = 1;
					if (isnan(initModel.az))
						initModel.az = 1;
					// INVERSION RTE

					float * slightPixel;
					if(slight==NULL)
						slightPixel = NULL;
					else{
						if(nx_straylight && ny_straylight){
							slightPixel = slight+ (nlambda*NPARMS*indexPixel);
						}
						else {
							slightPixel = slight;
						}
					}
					vNumIter[indexPixel] = indexPixel;
					lm_mils(cuantic, wlines, vLambda, nlambda, fitsImage->pixels[indexPixel].spectro, nlambda, &initModel, spectra, &vChisqrf[indexPixel], slightPixel, configCrontrolFile.toplim, configCrontrolFile.NumberOfCycles,
							configCrontrolFile.WeightForStokes, configCrontrolFile.fix, vSigma,  configCrontrolFile.noise,configCrontrolFile.InitialDiagonalElement,&configCrontrolFile.ConvolveWithPSF,&vNumIter[indexPixel],configCrontrolFile.mu,configCrontrolFile.logclambda);

					vModels[indexPixel] = initModel;
					if(configCrontrolFile.SaveSynthesisAdjusted){
						int kk;
						for (kk = 0; kk < (nlambda * NPARMS); kk++)
						{
							imageStokesAdjust->pixels[indexPixel].spectro[kk] = spectra[kk] ;
						}
					}
				}
				t = clock() - t;
				timeReadImage = ((PRECISION)t)/CLOCKS_PER_SEC; // in seconds
				printf("\n\n--------------------------------------------------------------------------------");
				printf("\nFINISH EXECUTION OF INVERSION: %f seconds to execute ", timeReadImage);
				printf("\n--------------------------------------------------------------------------------");

				char nameAuxOutputModel [4096];
				if(configCrontrolFile.ObservedProfiles[0]!='\0')
					strcpy(nameAuxOutputModel,get_basefilename(configCrontrolFile.ObservedProfiles));
				else
					strcpy(nameAuxOutputModel,get_basefilename(configCrontrolFile.InitialGuessModel));

				strcat(nameAuxOutputModel,MOD_FITS);
				if(!writeFitsImageModels(nameAuxOutputModel,fitsImage->rows,fitsImage->cols,vModels,vChisqrf,vNumIter,configCrontrolFile.saveChisqr)){
						printf("\n ERROR WRITING FILE OF MODELS: %s",nameAuxOutputModel);
				}
				// PROCESS FILE OF SYNTETIC PROFILES

				if(configCrontrolFile.SaveSynthesisAdjusted){
					// WRITE SINTHETIC PROFILES TO FITS FILE
					char nameAuxOutputStokes [4096];
					if(configCrontrolFile.ObservedProfiles[0]!='\0')
						strcpy(nameAuxOutputStokes,get_basefilename(configCrontrolFile.ObservedProfiles));
					else
						strcpy(nameAuxOutputStokes,get_basefilename(configCrontrolFile.InitialGuessModel));
					strcat(nameAuxOutputStokes,STOKES_FIT_EXT);
					if(!writeFitsImageProfiles(nameAuxOutputStokes,nameInputFileSpectra,imageStokesAdjust)){
						printf("\n ERROR WRITING FILE OF SINTHETIC PROFILES: %s",nameOutputFilePerfiles);
					}
				}
				if(configCrontrolFile.SaveSynthesisAdjusted)
					free(imageStokesAdjust);
				free(vModels);
				free(vChisqrf);
				free(vNumIter);
			}
			else{
				printf("\n\n ***************************** FITS FILE WITH THE SPECTRO IMAGE CAN NOT BE READ IT ******************************\n");
			}

			freeFitsImage(fitsImage);
		}
		else{
			printf("\n OBSERVED PROFILES DOESN'T HAVE CORRECT EXTENSION  .PER or .FITS ");
			exit(EXIT_FAILURE);
		}
	}

	fftw_free(inFilterMAC);
	fftw_free(outFilterMAC);
	fftw_destroy_plan(planFilterMAC);
	fftw_free(inFilterMAC_DERIV);
	fftw_free(outFilterMAC_DERIV);
	fftw_destroy_plan(planFilterMAC_DERIV);
	fftw_free(inSpectraFwMAC);
	fftw_free(outSpectraFwMAC);
	fftw_destroy_plan(planForwardMAC);
	fftw_free(inSpectraBwMAC);
	fftw_free(outSpectraBwMAC);
	fftw_destroy_plan(planBackwardMAC);

	if(configCrontrolFile.ConvolveWithPSF){
		fftw_free(inSpectraFwPSF);
		fftw_free(outSpectraFwPSF);
		fftw_destroy_plan(planForwardPSF);
		fftw_free(inSpectraBwPSF);
		fftw_free(outSpectraBwPSF);
		fftw_destroy_plan(planBackwardPSF);

		fftw_free(fftw_G_PSF);
		fftw_free(fftw_G_MAC_PSF);
		fftw_free(fftw_G_MAC_DERIV_PSF);

		fftw_free(inPSF_MAC);
		fftw_free(inMulMacPSF);
		fftw_free(inPSF_MAC_DERIV);
		fftw_free(inMulMacPSFDeriv);
		fftw_free(outConvFilters);
		fftw_free(outConvFiltersDeriv);

		fftw_destroy_plan(planForwardPSF_MAC);
		fftw_destroy_plan(planForwardPSF_MAC_DERIV);
		fftw_destroy_plan(planBackwardPSF_MAC);
		fftw_destroy_plan(planBackwardPSF_MAC_DERIV);
	}

	free(cuantic);
	free(wlines);
	free(vSigma);
	FreeMemoryDerivedSynthesis();
	if(G!=NULL) free(G);
	gsl_eigen_symmv_free (workspace);
	gsl_vector_free(eval);
	gsl_matrix_free(evec);

	return 0;
}

ext: c